2008.11.21 16:50 "[Tiff] 24 bit Color to 8 bit Palettized Conversion Utility (tiffcp enhancement/variation?)", by Kevin Myers

2008.11.21 19:11 "Re: [Tiff] 24 bit Color to 8 bit Palettized Conversion Utility (tiffcp enhancement/variation?)", by Bob Friesenhahn

Did you try VIPS? VIPS is able to accomplish many things without loading the whole image into memory and it is usually quite fast. I don't know if its color reduction works without loading the whole image though since that would require a several-pass algorithm.

Actually, from looking at the VIPS documentation, I am not finding an algorithm for color reduction at all. Maybe it does not exist. :-( Still, a programmer could use the VIPS API to develop a muti-pass color reduction algorithm.

In order to color reduce you need to

  1. Build a color tree / histogram of the existing colors in the image. This requires reading all the image pixels.
  2. Evaluate the color tree and build a colormap which best approximates it.
  3. Re-read the image pixels and generate colormap indexes which best approximate the image given the colormap which was selected. This may include dithering.

So it can be seen that to color reduce an image using the color tree / histogram method requires reading the pixels at least twice. RAM is now about 10,000 times faster than disk so reading from disk multiple times is prohibitive unless the decoded image can not fit in RAM.

Bob
======================================
Bob Friesenhahn
bfriesen@simple.dallas.tx.us, http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer, http://www.GraphicsMagick.org/