<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
</style>
</head>
<body class='hmmessage'>
Thank you very very much Frank for your help.<br>With best regards.<br>Belaid Moa.<br>> Date: Thu, 9 Jul 2009 20:59:31 -0400<br>> From: warmerdam@pobox.com<br>> To: belaid_moa@hotmail.com<br>> CC: gdal-dev@lists.osgeo.org<br>> Subject: Re: [gdal-dev] The use of GDALColorTable<br>> <br>> Belaid MOA wrote:<br>> > Greetings everyone,<br>> > I noticed that some of the GTiff images I am working with are single <br>> > bands and have a ColorInterp=Palette (they are colored when viewed in <br>> > tiff viewer). So, I assume they are using a Color Table to achieve that. <br>> > Am I right? Where can I find some tutorials or C/C++ examples using <br>> > GDALColorTable to associate a color table with a single band image?<br>> <br>> Belaid,<br>> <br>> <br>> The following is an example of creating a color table:<br>> <br>> // Allocate memory for colour table and read it<br>> if ( poDS->sInfoHeader.iClrUsed )<br>> poDS->nColorTableSize = poDS->sInfoHeader.iClrUsed;<br>> else<br>> poDS->nColorTableSize = 1 << poDS->sInfoHeader.iBitCount;<br>> poDS->pabyColorTable =<br>> (GByte *)VSIMalloc2( poDS->nColorElems, poDS->nColorTableSize );<br>> if (poDS->pabyColorTable == NULL)<br>> {<br>> CPLError(CE_Failure, CPLE_OutOfMemory, "Color palette will be <br>> ignored");<br>> poDS->nColorTableSize = 0;<br>> break;<br>> }<br>> <br>> VSIFSeekL( poDS->fp, BFH_SIZE + poDS->sInfoHeader.iSize, SEEK_SET );<br>> VSIFReadL( poDS->pabyColorTable, poDS->nColorElems,<br>> poDS->nColorTableSize, poDS->fp );<br>> <br>> GDALColorEntry oEntry;<br>> poDS->poColorTable = new GDALColorTable();<br>> for( i = 0; i < poDS->nColorTableSize; i++ )<br>> {<br>> oEntry.c1 = poDS->pabyColorTable[i * poDS->nColorElems + 2]; <br>> // Red<br>> oEntry.c2 = poDS->pabyColorTable[i * poDS->nColorElems + 1]; <br>> // Green<br>> oEntry.c3 = poDS->pabyColorTable[i * poDS->nColorElems]; <br>> // Blue<br>> oEntry.c4 = 255;<br>> <br>> poDS->poColorTable->SetColorEntry( i, &oEntry );<br>> }<br>> <br>> The color table can be associated with a band using:<br>> <br>> GDALSetColorTable(GDALRasterBandH,GDALColorTableH);<br>> <br>> In the case of creating a GeoTIFF file, you may need to<br>> pass the creation option PHOTOMETRIC=PALETTE to ensure the<br>> created file has a palette.<br>> <br>> Best regards,<br>> -- <br>> ---------------------------------------+--------------------------------------<br>> I set the clouds in motion - turn up | Frank Warmerdam, warmerdam@pobox.com<br>> light and sound - activate the windows | http://pobox.com/~warmerdam<br>> and watch the world go round - Rush | Geospatial Programmer for Rent<br>> <br><br /><hr />Create a cool, new character for your Windows Live™ Messenger. <a href='http://go.microsoft.com/?linkid=9656621' target='_new'>Check it out</a></body>
</html>