00001 /****************************************************************************** 00002 * $Id: gdalcolortable_cpp-source.html,v 1.13 2002/12/21 19:13:12 warmerda Exp $ 00003 * 00004 * Project: GDAL Core 00005 * Purpose: Color table implementation. 00006 * Author: Frank Warmerdam, warmerda@home.com 00007 * 00008 ********************************************************************** 00009 * Copyright (c) 2000, Frank Warmerdam 00010 * 00011 * Permission is hereby granted, free of charge, to any person obtaining a 00012 * copy of this software and associated documentation files (the "Software"), 00013 * to deal in the Software without restriction, including without limitation 00014 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00015 * and/or sell copies of the Software, and to permit persons to whom the 00016 * Software is furnished to do so, subject to the following conditions: 00017 * 00018 * The above copyright notice and this permission notice shall be included 00019 * in all copies or substantial portions of the Software. 00020 * 00021 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00022 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00023 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 00024 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00025 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 00026 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 00027 * DEALINGS IN THE SOFTWARE. 00028 ****************************************************************************** 00029 * $Log: gdalcolortable_cpp-source.html,v $ 00029 * Revision 1.13 2002/12/21 19:13:12 warmerda 00029 * updated 00029 * 00030 * Revision 1.2 2001/07/18 04:04:30 warmerda 00031 * added CPL_CVSID 00032 * 00033 * Revision 1.1 2000/03/06 02:26:00 warmerda 00034 * New 00035 * 00036 */ 00037 00038 #include "gdal_priv.h" 00039 00040 CPL_CVSID("$Id: gdalcolortable_cpp-source.html,v 1.13 2002/12/21 19:13:12 warmerda Exp $"); 00041 00042 /************************************************************************/ 00043 /* GDALColorTable() */ 00044 /************************************************************************/ 00045 00055 GDALColorTable::GDALColorTable( GDALPaletteInterp eInterpIn ) 00056 00057 { 00058 eInterp = eInterpIn; 00059 00060 nEntryCount = 0; 00061 paoEntries = NULL; 00062 } 00063 00064 /************************************************************************/ 00065 /* GDALCreateColorTable() */ 00066 /************************************************************************/ 00067 00068 GDALColorTableH GDALCreateColorTable( GDALPaletteInterp eInterp ) 00069 00070 { 00071 return (GDALColorTableH) (new GDALColorTable( eInterp )); 00072 } 00073 00074 00075 /************************************************************************/ 00076 /* ~GDALColorTable() */ 00077 /************************************************************************/ 00078 00085 GDALColorTable::~GDALColorTable() 00086 00087 { 00088 CPLFree( paoEntries ); 00089 paoEntries = NULL; 00090 } 00091 00092 /************************************************************************/ 00093 /* GDALDestroyColorTable() */ 00094 /************************************************************************/ 00095 00096 void GDALDestroyColorTable( GDALColorTableH hTable ) 00097 00098 { 00099 delete (GDALColorTable *) hTable; 00100 } 00101 00102 /************************************************************************/ 00103 /* GetColorEntry() */ 00104 /************************************************************************/ 00105 00116 const GDALColorEntry *GDALColorTable::GetColorEntry( int i ) const 00117 00118 { 00119 if( i < 0 || i >= nEntryCount ) 00120 return NULL; 00121 else 00122 return paoEntries + i; 00123 } 00124 00125 /************************************************************************/ 00126 /* GDALGetColorEntry() */ 00127 /************************************************************************/ 00128 00129 const GDALColorEntry *GDALGetColorEntry( GDALColorTableH hTable, int i ) 00130 00131 { 00132 return ((GDALColorTable *) hTable)->GetColorEntry( i ); 00133 } 00134 00135 00136 /************************************************************************/ 00137 /* GetColorEntryAsRGB() */ 00138 /************************************************************************/ 00139 00157 int GDALColorTable::GetColorEntryAsRGB( int i, GDALColorEntry *poEntry ) const 00158 00159 { 00160 if( eInterp != GPI_RGB || i < 0 || i >= nEntryCount ) 00161 return FALSE; 00162 00163 *poEntry = paoEntries[i]; 00164 return TRUE; 00165 } 00166 00167 /************************************************************************/ 00168 /* GDALGetColorEntryAsRGB() */ 00169 /************************************************************************/ 00170 00171 int GDALGetColorEntryAsRGB( GDALColorTableH hTable, int i, 00172 GDALColorEntry *poEntry ) 00173 00174 { 00175 return ((GDALColorTable *) hTable)->GetColorEntryAsRGB( i, poEntry ); 00176 } 00177 00178 /************************************************************************/ 00179 /* SetColorEntry() */ 00180 /************************************************************************/ 00181 00197 void GDALColorTable::SetColorEntry( int i, const GDALColorEntry * poEntry ) 00198 00199 { 00200 if( i < 0 ) 00201 return; 00202 00203 if( i >= nEntryCount ) 00204 { 00205 paoEntries = (GDALColorEntry *) 00206 CPLRealloc(paoEntries, sizeof(GDALColorEntry) * (i+1)); 00207 memset( paoEntries + nEntryCount, 0, 00208 sizeof(GDALColorEntry) * (i + 1 - nEntryCount) ); 00209 00210 nEntryCount = i+1; 00211 } 00212 00213 paoEntries[i] = *poEntry; 00214 } 00215 00216 /************************************************************************/ 00217 /* GDALSetColorEntry() */ 00218 /************************************************************************/ 00219 00220 void GDALSetColorEntry( GDALColorTableH hTable, int i, 00221 const GDALColorEntry * poEntry ) 00222 00223 { 00224 ((GDALColorTable *) hTable)->SetColorEntry( i, poEntry ); 00225 } 00226 00227 00228 /************************************************************************/ 00229 /* Clone() */ 00230 /************************************************************************/ 00231 00238 GDALColorTable *GDALColorTable::Clone() const 00239 00240 { 00241 GDALColorTable *poNew; 00242 00243 poNew = new GDALColorTable(eInterp); 00244 poNew->nEntryCount = nEntryCount; 00245 poNew->paoEntries = (GDALColorEntry *) 00246 CPLMalloc(sizeof(GDALColorEntry)*nEntryCount); 00247 memcpy( poNew->paoEntries, paoEntries, sizeof(GDALColorEntry)*nEntryCount); 00248 00249 return poNew; 00250 } 00251 00252 /************************************************************************/ 00253 /* GDALCloneColorTable() */ 00254 /************************************************************************/ 00255 00256 GDALColorTableH GDALCloneColorTable( GDALColorTableH hTable ) 00257 00258 { 00259 return (GDALColorTableH) ((GDALColorTable *) hTable)->Clone(); 00260 } 00261 00262 /************************************************************************/ 00263 /* GetColorEntryCount() */ 00264 /************************************************************************/ 00265 00274 int GDALColorTable::GetColorEntryCount() const 00275 00276 { 00277 return nEntryCount; 00278 } 00279 00280 /************************************************************************/ 00281 /* GDALGetColorEntryCount() */ 00282 /************************************************************************/ 00283 00284 int GDALGetColorEntryCount( GDALColorTableH hTable ) 00285 00286 { 00287 return ((GDALColorTable *) hTable)->GetColorEntryCount(); 00288 } 00289 00290 /************************************************************************/ 00291 /* GetPaletteInterpretation() */ 00292 /************************************************************************/ 00293 00304 GDALPaletteInterp GDALColorTable::GetPaletteInterpretation() const 00305 00306 { 00307 return eInterp; 00308 } 00309 00310 /************************************************************************/ 00311 /* GDALGetPaltteInterpretation() */ 00312 /************************************************************************/ 00313 00314 GDALPaletteInterp GDALGetPaletteInterpretation( GDALColorTableH hTable ) 00315 00316 { 00317 return ((GDALColorTable *) hTable)->GetPaletteInterpretation(); 00318 }