[gdal-dev] 24bit RGB colors raster (PNG or JPEG) to 256 colormap
even.rouault at mines-paris.org
Thu Dec 27 13:27:30 EST 2007
Le Thursday 27 December 2007 12:19:48 Mateusz Loskot, vous avez écrit :
> marcello ferrero wrote:
> > I would like to know what GDAL "C" API function I have to use to convert
> > 24bit RGB colors PNG/JPG images to 256 colormap (8 bits) TIF files. I
> > understood this is possible with MapServer using IMAGEMODE=PC256
> > (converted using the color cube), but I need to do this from my "C"
> > program (a Win32 viewer ) that is already using the gdal lib.
> You can find all necessary instructions in the GDAL API Tutorial at
> Also, I'd suggest to take a look at sources of the gdal_translate
> program, especially at how CreateCopy is used:
I recently had to port rgb2pct.py into C. I've uploaded the source code at
There are 2 main interesting functions in GDAL API to convert from 24 bit to
- GDALComputeMedianCutPCT : to compute the optimal palette from the source
- GDALDitherRGB2PCT : to generate the new databand from the source data bands
and the optimal palette.
More information about the gdal-dev