[Gdal-dev] How to set a ColorTable from scratch?

Frank Warmerdam warmerdam at pobox.com
Thu Jun 22 15:25:40 EDT 2006


Joaquim Luis wrote:
> Frank,
> I had already came across similar code and I wanted to try it, though 
> expecting a crash as effectively
 >
> I just had.
> The point (that is what I think) is who initializes hColorTable? I mean 
> how do we allocate memory to it?
> Currently I just have
> GDALColorTableH    hColorTable;
> GDALColorEntry    sEntry;

Joaquim,

Sorry about that.  The color table should be allocate with
GDALCreateColorTable().

eg.

hColorTable = GDALCreateColorTable( GPI_RGB );

> 
> for (i = 0; i < nColors; i++) {
>                sEntry.c1 = (short)(ptr_d[i] * 255);
>                sEntry.c2 = (short)(ptr_d[i+nColors] * 255);
>                sEntry.c3 = (short)(ptr_d[i+2*nColors] * 255);
>                sEntry.c4 = (short)255;
>                GDALSetColorEntry( hColorTable, i, &sEntry );
> 
> }
> 
> but it crashes at the first call to
>    GDALSetColorEntry( hColorTable, i, &sEntry );
> 
> Joaquim Luis
> 
> 


-- 
---------------------------------------+--------------------------------------
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    | President OSGF, http://osgeo.org




More information about the Gdal-dev mailing list