I have a litho image (black & white pixels only) and I want to make all the 
white pixels transparent. I am using Quartz 2d to display the image and I have 
a Quartz composition containing a single .cikernel...

kernel vec4 whiteToTransparent(sampler source_image) 
{ 
   
vec4 pixValue;
pixValue = sample(source_image, samplerCoord(source_image));
return  (pixValue == vec4(1,1,1,1) ? vec4(1,1,1,0) : vec4(pixValue));
}

....it doesn't seem to work. Here is what I have...

- (void)drawRect:(NSRect)rect {
CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort];
NSString* imagePath =  [[NSBundle mainBundle] pathForResource:@"Richards Thres 
1 of 7" ofType:@"tif"];
NSImage *theImage = [[[NSImage alloc] 
initByReferencingFile:imagePath]autorelease];
[selfMyDrawTransparencyLayer:context:rect.size.width:rect.size.height:theImage];
}

- (void) MyDrawTransparencyLayer: (CGContextRef)myContext: (float)wd: 
(float)ht: (NSImage *)addThisImage//1     
{ 
[selfsetKeyCGImageRef:[selfCGImageRefFromNSImage:addThisImage]];
CGRect rect = CGRectMake(0, 0, CGImageGetWidth(keyCGImageRef), 
CGImageGetHeight(keyCGImageRef));
keyCGImageRef = ApplyWhiteToTransparentComposition([@"whiteToTransparent" 
UTF8String], keyCGImageRef);
CGContextBeginTransparencyLayer (myContext, NULL);
CGContextDrawImage (myContext, rect, keyCGImageRef);
CGContextEndTransparencyLayer (myContext);
}

- (CGImageRef) CGImageRefFromNSImage:(NSImage*)anImage
{ 
CFDataRef imgData = (CFDataRef)[anImage TIFFRepresentation];
CGImageSourceRef imageSourceRef = CGImageSourceCreateWithData(imgData, NULL);
return  CGImageSourceCreateImageAtIndex(imageSourceRef, 0, NULL);
}

CGImageRef ApplyWhiteToTransparentComposition(const char* compositionName, 
const CGImageRef srcImage)
{
CGImageRef resultImage = NULL;
NSAutoreleasePool* pool = [NSAutoreleasePool new];
NSString* compName = [NSString stringWithCString:compositionName];
NSString* compositionPath =  [[NSBundle mainBundle] pathForResource:compName 
ofType:@"qtz"];
NSOpenGLPixelFormatAttribute attributes[] = {NSOpenGLPFAAccelerated, 
NSOpenGLPFANoRecovery, (NSOpenGLPixelFormatAttribute)0};
NSOpenGLPixelFormat* format = [[NSOpenGLPixelFormat alloc] 
initWithAttributes:attributes];
NSOpenGLContext* context = [[NSOpenGLContext alloc] initWithFormat:format 
shareContext:nil];
@try
  {
   QCRenderer* renderer = [[QCRenderer alloc] initWithOpenGLContext:context 
pixelFormat:format file:compositionPath];
  [renderer setValue:(id)srcImage forInputKey:@"source_image"];
  [renderer renderAtTime:0.0 arguments:nil];
  NSImage* image = [renderer valueForOutputKey:@"output_image"];
  
  if (image)
{
CFDataRef imgData = (CFDataRef)[image TIFFRepresentation];
CGImageSourceRef imageSourceRef = CGImageSourceCreateWithData(imgData, NULL);
resultImage = CGImageSourceCreateImageAtIndex(imageSourceRef, 0, NULL);
}
  [renderer release];
  }
@catch(id exception)
  {
  NSLog(@"Error running Quartz Composition '%s': %@", compositionName, 
exception);
  }
// Done, clean up
[context release];
[format release];
[pool release];
return resultImage;
}

Any ideas?

Thanks
Rick


      
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to