[Gdal-dev] Can I manipulate the palette?

Frank Warmerdam warmerdam at pobox.com
Mon Nov 24 09:46:36 EST 2003


Kyler Laird wrote:
> I see that I can create a ColorTable and I can set it as part of
> ComputeMedianCutPCT(), but I haven't located a way to set individual
> entries.  Is this something that's hidden on purpose?  Is there a clean
> way to manipulate the palette?

Kyler,

The GDALComputeMedianCutPCT() produces a PCT that is good for a given RGB
image.  It doesn't provide any mechanism to "guide" the selection of colors
for the color table.  However, after the PCT is generated you can alter
it as you wish, adding, replacing or removing colors.

Hmm, actually, looking at the GDALColorTable methods there isn't really any
way to remove entries.  But in a pinch you could just create a new color
table and copy over only the entries you want to preserve.

The C level colortable functions are:

/* ==================================================================== */
/*      Color tables.                                                   */
/* ==================================================================== */
/** Color tuple */
typedef struct
{
     /*! gray, red, cyan or hue */
     short      c1;

     /*! green, magenta, or lightness */
     short      c2;

     /*! blue, yellow, or saturation */
     short      c3;

     /*! alpha or blackband */
     short      c4;
} GDALColorEntry;

GDALColorTableH CPL_DLL GDALCreateColorTable( GDALPaletteInterp );
void CPL_DLL            GDALDestroyColorTable( GDALColorTableH );
GDALColorTableH CPL_DLL GDALCloneColorTable( GDALColorTableH );
GDALPaletteInterp CPL_DLL GDALGetPaletteInterpretation( GDALColorTableH );
int CPL_DLL             GDALGetColorEntryCount( GDALColorTableH );
const GDALColorEntry CPL_DLL *GDALGetColorEntry( GDALColorTableH, int );
int CPL_DLL GDALGetColorEntryAsRGB( GDALColorTableH, int, GDALColorEntry *);
void CPL_DLL GDALSetColorEntry( GDALColorTableH, int, const GDALColorEntry * );


Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent





More information about the Gdal-dev mailing list