How to use kCGImagePropertyGIFImageColorMap or create a color table?
Solution 1:
Core Graphics does not allow for the setting of a global color table, just a local color table for a single-image GIF file. Multi-image gif files require individual properties of each image to be set, which means the kCGImagePropertyGIFImageColorMap
will have no effect when the source images are not themselves GIF files, and the code in the linked gist is wrong. Instead of trying to set a global color map, set the properties each one of the images you're trying to string together, which can be manipulated with Core Graphics by using an image context or by setting the properties of the image when you add them to the image destination ref.
If you're still wondering about GIF color tables, they're explained better than I ever could by the giflib library, which would probably be a much better avenue than Core Graphics for generating a gif and manipulating its color table. If you're going the Core Graphics route and still want to know how to instantiate 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's intensity grouped in 3's 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 }