[gdal-dev] The use of GDALColorTable

Belaid MOA belaid_moa at hotmail.com
Thu Jul 9 21:39:38 EDT 2009


Thank you very very much Frank for your help.
With best regards.
Belaid Moa.
> Date: Thu, 9 Jul 2009 20:59:31 -0400
> From: warmerdam at pobox.com
> To: belaid_moa at hotmail.com
> CC: gdal-dev at lists.osgeo.org
> Subject: Re: [gdal-dev] The use of GDALColorTable
> 
> Belaid MOA wrote:
> > Greetings everyone,
> >   I noticed that some of the GTiff images I am working with are single 
> > bands and have a ColorInterp=Palette (they are colored when viewed in 
> > tiff viewer). So, I assume they are using a Color Table to achieve that. 
> > Am I right? Where can I find some tutorials or C/C++ examples using 
> > GDALColorTable to associate a color table with a single band image?
> 
> Belaid,
> 
> 
> The following is an example of creating a color table:
> 
>              // Allocate memory for colour table and read it
>              if ( poDS->sInfoHeader.iClrUsed )
>                  poDS->nColorTableSize = poDS->sInfoHeader.iClrUsed;
>              else
>                  poDS->nColorTableSize = 1 << poDS->sInfoHeader.iBitCount;
>              poDS->pabyColorTable =
>                  (GByte *)VSIMalloc2( poDS->nColorElems, poDS->nColorTableSize );
>              if (poDS->pabyColorTable == NULL)
>              {
>                  CPLError(CE_Failure, CPLE_OutOfMemory, "Color palette will be 
> ignored");
>                  poDS->nColorTableSize = 0;
>                  break;
>              }
> 
>              VSIFSeekL( poDS->fp, BFH_SIZE + poDS->sInfoHeader.iSize, SEEK_SET );
>              VSIFReadL( poDS->pabyColorTable, poDS->nColorElems,
>                        poDS->nColorTableSize, poDS->fp );
> 
>              GDALColorEntry oEntry;
>              poDS->poColorTable = new GDALColorTable();
>              for( i = 0; i < poDS->nColorTableSize; i++ )
>              {
>                  oEntry.c1 = poDS->pabyColorTable[i * poDS->nColorElems + 2]; 
> // Red
>                  oEntry.c2 = poDS->pabyColorTable[i * poDS->nColorElems + 1]; 
> // Green
>                  oEntry.c3 = poDS->pabyColorTable[i * poDS->nColorElems]; 
> // Blue
>                  oEntry.c4 = 255;
> 
>                  poDS->poColorTable->SetColorEntry( i, &oEntry );
>              }
> 
> The color table can be associated with a band using:
> 
>    GDALSetColorTable(GDALRasterBandH,GDALColorTableH);
> 
> In the case of creating a GeoTIFF file, you may need to
> pass the creation option PHOTOMETRIC=PALETTE to ensure the
> created file has a palette.
> 
> 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
> 

_________________________________________________________________
Create a cool, new character for your Windows Live™ Messenger. 
http://go.microsoft.com/?linkid=9656621
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20090710/ef16e0c7/attachment-0001.html


More information about the gdal-dev mailing list