Custom Image unit works in CoreImage Funhouse but not in Quartz Composer
Custom Image unit works in CoreImage Funhouse but not in Quartz Composer
- Subject: Custom Image unit works in CoreImage Funhouse but not in Quartz Composer
- From: Louis Demers <email@hidden>
- Date: Wed, 11 Jul 2007 15:08:59 -0400
Hi,
in trying to build an image unit (based upon CIDemoImageUnit) to
compute algorithms that can't be done in a kernel, I coded the
following image unit. In Funhouse, I get to access pixels at will.
When the same unit is put in a Quartz Composition, either with a
static image or with a video input, the image filter is properly
displayed in the viewer and my unit gets called. However, when I draw
the output CIImage into my NSBitmapImageRep, the result is a dark or
0 everywhere as if the drawing does not occurs. By enabling the line
drawing and file dumping in the conditional code, I can confirm the
bitmap is properly setup.
Clues ? Do I need to do anything special to also work in the contact
of a quartz composition ?
//
________________________________________________________________________
______________________________________________
// called when setting up for fragment program and also calls
fragment program
- (CIImage *)outputImage
{
float radius;
CISampler *src;
CIImage *outImage;
unsigned char * pixels;
unsigned char * pixel;
int pixelOffset;
src = [CISampler samplerWithImage:inputImage];
radius = [inputWidth floatValue] * 0.5;
outImage = [self apply:_funHouseMirrorKernel,
src,
[NSNumber numberWithFloat:[inputCenter X]],
[NSNumber numberWithFloat:1.0 / radius],
[NSNumber numberWithFloat:radius],
[NSNumber numberWithFloat: 1.0 / pow(10.0, [inputAmount
floatValue])],
kCIApplyOptionDefinition,
[[src definition] insetByX:-radius Y:-radius],
kCIApplyOptionUserInfo,
[NSNumber numberWithFloat:radius],
nil
];
int width = [inputImage extent].size.width;
int height = [inputImage extent].size.height;
//Create a bitmap rep
NSBitmapImageRep* workingBitmapRep = [ [NSBitmapImageRep alloc]
initWithBitmapDataPlanes:NULL
pixelsWide:width
pixelsHigh:height
bitsPerSample:8
samplesPerPixel:4
hasAlpha:YES
isPlanar:NO
colorSpaceName:NSDeviceRGBColorSpace
bytesPerRow:0
bitsPerPixel:0
];
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext:[NSGraphicsContext
graphicsContextWithBitmapImageRep:workingBitmapRep]];
[outImage drawAtPoint: NSZeroPoint
fromRect: NSMakeRect(0.0, 0.0, width, height)
operation: NSCompositeCopy
fraction: 1.0
];
#if 0
// simply to check things are setup correctly and working
[NSBezierPath setDefaultLineWidth: 10.0];
[[NSColor redColor] set];
[NSBezierPath strokeLineFromPoint: NSMakePoint( 0, 0)
toPoint: NSMakePoint( 500, 500)];
#endif
[ [workingBitmapRep representationUsingType:NSJPEGFileType
properties:nil] writeToFile:@"/Users/louis_demers/Desktop/myFile.jpg"
atomically:YES];
[NSGraphicsContext restoreGraphicsState];
pixels = [workingBitmapRep bitmapData];
pixelOffset = ( ([workingBitmapRep bitsPerSample] * [inputCenter
X]) / 8) + ( [workingBitmapRep bytesPerRow] * (height - [inputCenter
Y]) );
pixel = pixels + pixelOffset;
NSLog(@"----------------------------------------[%f,%f]%d",
[inputCenter X] , [inputCenter Y] , *pixel );
Louis Demers eng.
www.obzerv.com
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden