[futurebasic] Re: [FB] PICT question

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : August 2006 : Group Archive : Group : All Groups

From: Robert Purves <robert.purves@...>
Date: Tue, 1 Aug 2006 18:30:23 +1200
Walter Lenk wrote:
> Your elegantly simple function 'LOCAL FN FlipGWorldHoriz( theGW as  
> CGrafPtr )' was just what I had hoped the solution might be. I do  
> have one question obout this function:   Would it not be prudent to  
> lock the handle 'pmHandle' during the swapping process?

(Walter's ISP blocks email from me, so I am replying via the list.)

No need to lock pmHandle because nothing in FlipGWorldHoriz can cause  
'memory to move' even under MacOS 8/9, and certainly not under OS X.

Robert P.


> '------------------------------------
> toolbox fn GetPixRowBytes( PixMapHandle pm ) = long
>
> local mode
> local fn FlipGWorldHoriz( theGW as CGrafPtr )
> '~'1
> dim as long      y, xR, xL, tempPixel, rowBytes
> dim as pointer   baseAddr, pixAddrL, pixAddrR
> dim as Rect      bounds
> dim pmHandle  as ^^PixMap
> dim as short     depth
>
> pmHandle = fn GetGWorldPixMap( theGW )
> rowBytes = fn GetPixRowBytes( pmHandle )
> depth    = pmHandle..pixelSize
> if ( depth != 32 ) then stop "FlipGWorldHoriz needs 32-bit depth"
> baseAddr = fn GetPixBaseAddr( pmHandle )
> bounds = pmHandle..bounds
> y = 0
> while ( y < bounds.bottom )
> xL = 0
> xR = bounds.right - 1
> while ( xL < xR )
> // swap pixels at xL and xR
> pixAddrL    = baseAddr + (xL << 2)
> pixAddrR    = baseAddr + (xR << 2)
> tempPixel   = pixAddrL.0&
> pixAddrL.0& = pixAddrR.0&
> pixAddrR.0& = tempPixel
> xL++
> xR--
> wend
> baseAddr += rowBytes
> y++
> wend
> end fn
> '------------------------------------