How to use kCGImagePropertyGIFImageColorMap or create a color table?

I am trying to redo a couple of GIF properties such as kCGImagePropertyGIFImageColorMap and kCGImagePropertyGIFHasGlobalColorMap ( reference ) in Core Graphics.

I am creating animated GIFs and I would like to see if I can improve the quality by playing with the number of colors. I found another example code , and I'm not sure if it works.

I tried using a couple of code examples above but it doesn't seem to work. It doesn't seem like the kCGImagePropertyGIFHasGlobalColorMap setting kCGImagePropertyGIFHasGlobalColorMap anything. Thanks

+48
objective-c cocoa core-graphics
Jun 09 '13 at 20:34 on
source share
1 answer

Core Graphics does not allow you to set a global color table, as well as a local color table for a single-image GIF file. For image files with multiple images, the individual properties of each image are required, which means that kCGImagePropertyGIFImageColorMap will have no effect if the original images are not GIF files themselves and the code in the associated gist is incorrect. Instead of trying to set a global color map, set the properties of each of the images that you are trying to combine and that can be manipulated using Core Graphics using the image context or by setting image properties when adding them to the image destination link.

If you're still interested in GIF color tables, they are better explained by the giflib library, which is likely to be much better than Core Graphics for generating gifs and manipulating its color table. If you go to the main graphic route and still want to know how to create a color table, the general format is as follows:

 // Color tables are arrays of 8-bit bytes from 0 (deepest black) to 255 (brightest white) // with each color intensity grouped in 3 for a total of 9 values. // The format is interpreted as hex values. const uint8_t colorTable[9] = { 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF }; // { White Bytes }, { Red Bytes }, { Blue Bytes } 
+4
03 Oct '13 at 23:57
source share



All Articles