[Gdal-dev] color table

Xiaodong Zhang zhang at aero.und.edu
Fri May 30 19:12:20 EDT 2003


Hi Frank,

I'm just wondering can I write a color table into a GeoTIFF file. I got 
an error message saying that
SetColorTable() not supported for existing TIFF files.

Thanks
Xiaodong

Frank Warmerdam wrote:

> Xiaodong Zhang wrote:
>
>> Hi,
>>
>> I want to use GDALRasterBand::SetColorTable(GDAL ColorTable * ctb) to 
>> attach a color table to the image I created. How can I define the 
>> color table or if I have a predefined color table (3 columns, each 
>> column for R, G, B respectively), how can import that color table. 
>> Thanks.
>
>
> Hi,
>
> This is example code for creating a GDALColorTable object in C++.  The 
> source
> data in this case uses normalized color values (0.0 to 1.0) so it has 
> to be
> scaled to 0 to 255.  If you don't have alpha (transparency) values 
> make sure
> you set all alpha values to 255 for opaque.
>
>         poCT = new GDALColorTable();
>         for( int iColor = 0; iColor < nColors; iColor++ )
>         {
>             GDALColorEntry   sEntry;
>
>             sEntry.c1 = (short) (padfRed[iColor]   * 255);
>             sEntry.c2 = (short) (padfGreen[iColor] * 255);
>             sEntry.c3 = (short) (padfBlue[iColor]  * 255);
>             sEntry.c4 = (short) (padfAlpha[iColor]  * 255);
>             poCT->SetColorEntry( iColor, &sEntry );
>         }
>
> Note that many drivers do not allow you to update a colortable in place.
>
> Good luck,
>





More information about the Gdal-dev mailing list