[gdal-dev] 24bit RGB colors raster (PNG or JPEG) to 256 colormap
TIF conversion
Even Rouault
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.
>
> Marcello,
>
> You can find all necessary instructions in the GDAL API Tutorial at
> http://www.gdal.org/gdal_tutorial.html
>
> Also, I'd suggest to take a look at sources of the gdal_translate
> program, especially at how CreateCopy is used:
>
> http://trac.osgeo.org/gdal/browser/trunk/gdal/apps/gdal_translate.cpp#L588
>
> Cheers
Hi,
I recently had to port rgb2pct.py into C. I've uploaded the source code at
http://trac.osgeo.org/gdal/attachment/wiki/CodeSnippets/rgb2pct.c.
There are 2 main interesting functions in GDAL API to convert from 24 bit to
colormap :
- GDALComputeMedianCutPCT : to compute the optimal palette from the source
data bands
- GDALDitherRGB2PCT : to generate the new databand from the source data bands
and the optimal palette.
Best regards,
Even
More information about the gdal-dev
mailing list