I'm trying to create a paletted (indexed) PNG using CoreGraphics.
The best I've found is that I can use:
CGColorSpaceRef colorSpace = CGColorSpaceCreateIndexed(CGImageGetColorSpace(maskedImage), 255, <#const unsigned char *colorTable#>);
Then:
CGImageRef palettedImage = CGImageCreateCopyWithColorSpace(maskedImage, colorSpace)
However I'm not sure what to put as the colorTable. I'd like to leverage some pre-made (fast) quantization algorithm - such as the one that is already built in to ImageIO when calling CGImageDestinationCreateWithURL(url, kUTTypeGIF , 1, NULL);
How do I create a palette for the PNG?
So the final solution was to do something like this:
My hope was to use the color table to create a CGContextRef. However, according to this article: http://developer.apple.com/library/mac/#qa/qa1037/_index.html that isn't possible in any case.