realbasic-games
[Top] [All Lists]

Re: Flipping a picture

To: REALbasic Games <realbasic-games at lists dot realsoftware dot com>
Subject: Re: Flipping a picture
From: Phil M <phil at mobleybros dot com>
Date: Mon, 27 Jun 2005 19:07:47 +0200
Delivered-to: realbasic-games at lists dot realsoftware dot com
References: <263AFD9E-BFBF-49F1-BF85-D5706AD19441 at gmail dot com> <a0620072dbee5d8d25316 at [10 dot 10 dot 13 dot 4]> <4CE76E7F-9F4A-43E0-85B4-8E5150676A5F at gmail dot com>
On Jun 27, 2005, at 6:39 PM, Joel Reymont wrote:

I don't want to do this beforehand to save space so any efficient code you can send will be appreciated!

You can loop through all of the pixels:

Function FlipHorizontal(source As Picture) As Picture

  Dim dest As Picture
  Dim rs, rd, rms, rmd As RGBSurface
  Dim x, xMax, y, yMax As Integer

  If source Is Nil Then Return Nil

  If source.Depth < 16 Then
    // have to fix the picture so that there is an RGBSurface
    // so temporarily use dest to hold the new source
    dest = NewPicture(source.Width, source.Height, 32)
    dest.Graphics.DrawPicture(source, 0, 0)
    source = dest
  End If

  dest = NewPicture(source.Width, source.Height, 32)

  rs = source.RGBSurface
  rd = dest.RGBSurface
  rms = source.Mask.RGBSurface    // RGBSurface for the Mask
  rmd = dest.Mask.RGBSurface      // RGBSurface for the Mask

  xMax = source.Width - 1
  yMax = source.Height - 1

  // now we flip the pixels

  For y = 0 To yMax
    For x = 0 To xMax
      rd.Pixel(xMax - x, y) = rs.Pixel(x, y)
      rmd.Pixel(xMax - x, y) = rms.Pixel(x, y)
    Next
  Next

  Return dest

End Function

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>