[futurebasic] Re: [FB] CIImage from GWorld

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : January 2012 : Group Archive : Group : All Groups

From: Robert Purves <listrp@...>
Date: Fri, 20 Jan 2012 16:17:25 +1300
Robert Covington wrote:

> I am attempting to see if CIPerspectiveTransform in CoreImage filters will work for my needs. Only other option is porting a Java filter, which might be the best approach since I read that these CoreImage filters like to not work on large images. Anyhow...
> I have the thing about repurposed from both web and PDF search and Steve V's GaussianBlur example in FB5.7 examples, Cocoa ...
> Last thing confused about though is I am not sure if I can go direct from a CGContextRef  to CIContext to  the filter somehow, or if I have to do double work and create a BitmapContext via something like this? I hope I've just missed a handy method or something.

Wrap a CGBitmapContext around the pixel data of a GWorld.
Caller must release the returned context if non-NULL.
local mode
local fn CreateCGBitmapContextFromGWorld( theGW as CGrafPtr ) as CGContextRef
dim as CGColorSpaceRef  cs
dim as CGContextRef     ctx : ctx = NULL
dim as long             rowBytes     
dim as ^^PixMap         pmHandle     
dim as pointer          imageBuf     
dim as Rect             bounds

pmHandle = fn GetGWorldPixMap( theGW )
if ( pmHandle..pixelSize != 32 ) then exit fn
rowBytes = fn GetPixRowBytes( pmHandle )
imageBuf = fn GetPixBaseAddr( pmHandle )
bounds = pmHandle..bounds
cs = fn CGColorSpaceCreateDeviceRGB()
ctx = fn CGBitmapContextCreate( imageBuf, bounds.right, bounds.bottom, 8, rowBytes, cs, _kCGImageAlphaPremultipliedFirst )
CGColorSpaceRelease( cs )
end fn = ctx

dim as CGrafPtr      theGW
..create theGW and draw into it..
dim as CGContextRef  ctx
ctx = fn CreateCGBitmapContextFromGWorld( theGW )
dim as CGImageRef    image
image = fn CGBitmapContextCreateImage( ctx ) 
CIImage *sourceCIImage = [CIImage imageWithCGImage:image];
CFRelease( image )
CIImage *result = ... // filtered version of sourceCIImage
..draw result in ctx to replace the original GWorld contents..
CFRelease( ctx )