• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Transparency Help
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Transparency Help


  • Subject: Transparency Help
  • From: R T <email@hidden>
  • Date: Mon, 23 Nov 2009 08:12:53 -0800 (PST)

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 (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

  • Follow-Ups:
    • Re: Transparency Help
      • From: Kyle Sluder <email@hidden>
    • Re: Transparency Help
      • From: glenn andreas <email@hidden>
  • Prev by Date: How can I not block hotkey from other apps
  • Next by Date: NIB/XIB created objects, should they be released in -[dealloc]?
  • Previous by thread: Re: How can I not block hotkey from other apps
  • Next by thread: Re: Transparency Help
  • Index(es):
    • Date
    • Thread