• 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
Puzzling CGBitmapImageCreate problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Puzzling CGBitmapImageCreate problem


  • Subject: Puzzling CGBitmapImageCreate problem
  • From: Florent Pillet <email@hidden>
  • Date: Tue, 12 Aug 2003 11:07:54 +0200

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.

  • Follow-Ups:
    • Re: Puzzling CGBitmapImageCreate problem
      • From: David Hill <email@hidden>
  • Prev by Date: Re: ScreenSaver with a subview won't preview
  • Next by Date: Re: very simple NSRange q
  • Previous by thread: Re: ScreenSaver with a subview won't preview
  • Next by thread: Re: Puzzling CGBitmapImageCreate problem
  • Index(es):
    • Date
    • Thread