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