Re: Puzzling CGBitmapImageCreate problem
Re: Puzzling CGBitmapImageCreate problem
- Subject: Re: Puzzling CGBitmapImageCreate problem
- From: David Hill <email@hidden>
- Date: Tue, 12 Aug 2003 08:40:25 -0700
From Q&A 1037 "CGBitmapContextCreate Supported Colorspaces"
<
http://developer.apple.com/qa/qa2001/qa1037.html>, it looks like you
can't use indexed colorspaces with bitmap contexts.
Feel free to file an enhancement request.
Dave
On Tuesday, August 12, 2003, at 2:07 AM, Florent Pillet wrote:
I'm trying to recolor a NSImage using a fixed palette. Nothing fancy,
just recoloring. For that matter, I use a CGBitmapContext with the
intent of using an indexed color space, so that CoreGraphics performs
the recolorization for me (am I lazy or what? ;-))
The problem is that CGBitmapContextCreate returns NULL when created
with a CGColorSpaceRef which is an indexed palette. Here is what
fails:
// create a CGColorSpace which uses the given palette
CGColorSpaceRef rgbCS = CGColorSpaceCreateDeviceRGB();
CGColorSpaceRef paletteCS = CGColorSpaceCreateIndexed(rgbCS,
numColors-1, colorTable);
// prepare the buffer holding the image in the CGContext
unsigned char *bmpData = malloc(width * height * 4);
memset(bmpData, 0xff, width * height * 4); // all white and alpha
channel set
// create a CGContext into which we will draw the image
CGContextRef bmpContext = CGBitmapContextCreate(bmpData, width,
height, 8, width * 4, paletteCS, kCGImageAlphaPremultipliedLast);
Here, bmpContext is NULL. If I replace paletteCS with rgbCS, the
context is properly created and my subsequent operations work fine.
Any hint at what the trouble is? The docs don't say that you
can't/shouldn't use an indexed color space to create a bitmap
context...
Thanks for any help,
Florent.
--
Florent Pillet, Code Segment email@hidden
Developer tools and end-user products for Palm OS & Mac OS X
ICQ: 117292463 http://perso.wanadoo.fr/fpillet
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.