Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

gdalcolortable.cpp

00001 /******************************************************************************
00002  * $Id: gdalcolortable_cpp-source.html,v 1.5 2000/11/06 04:49:01 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.5  2000/11/06 04:49:01  warmerda
00029  * *** empty log message ***
00029  *
00030  * Revision 1.1  2000/03/06 02:26:00  warmerda
00031  * New
00032  *
00033  */
00034 
00035 #include "gdal_priv.h"
00036 
00037 /************************************************************************/
00038 /*                           GDALColorTable()                           */
00039 /************************************************************************/
00040 
00050 GDALColorTable::GDALColorTable( GDALPaletteInterp eInterpIn )
00051 
00052 {
00053     eInterp = eInterpIn;
00054 
00055     nEntryCount = 0;
00056     paoEntries = NULL;
00057 }
00058 
00059 /************************************************************************/
00060 /*                        GDALCreateColorTable()                        */
00061 /************************************************************************/
00062 
00063 GDALColorTableH GDALCreateColorTable( GDALPaletteInterp eInterp )
00064 
00065 {
00066     return (GDALColorTableH) (new GDALColorTable( eInterp ));
00067 }
00068 
00069 
00070 /************************************************************************/
00071 /*                          ~GDALColorTable()                           */
00072 /************************************************************************/
00073 
00080 GDALColorTable::~GDALColorTable()
00081 
00082 {
00083     CPLFree( paoEntries );
00084     paoEntries = NULL;
00085 }
00086 
00087 /************************************************************************/
00088 /*                       GDALDestroyColorTable()                        */
00089 /************************************************************************/
00090 
00091 void GDALDestroyColorTable( GDALColorTableH hTable )
00092 
00093 {
00094     delete (GDALColorTable *) hTable;
00095 }
00096 
00097 /************************************************************************/
00098 /*                           GetColorEntry()                            */
00099 /************************************************************************/
00100 
00111 const GDALColorEntry *GDALColorTable::GetColorEntry( int i ) const
00112 
00113 {
00114     if( i < 0 || i >= nEntryCount )
00115         return NULL;
00116     else
00117         return paoEntries + i;
00118 }
00119 
00120 /************************************************************************/
00121 /*                         GDALGetColorEntry()                          */
00122 /************************************************************************/
00123 
00124 const GDALColorEntry *GDALGetColorEntry( GDALColorTableH hTable, int i )
00125 
00126 {
00127     return ((GDALColorTable *) hTable)->GetColorEntry( i );
00128 }
00129 
00130 
00131 /************************************************************************/
00132 /*                         GetColorEntryAsRGB()                         */
00133 /************************************************************************/
00134 
00152 int GDALColorTable::GetColorEntryAsRGB( int i, GDALColorEntry *poEntry ) const
00153 
00154 {
00155     if( eInterp != GPI_RGB || i < 0 || i >= nEntryCount )
00156         return FALSE;
00157     
00158     *poEntry = paoEntries[i];
00159     return TRUE;
00160 }
00161 
00162 /************************************************************************/
00163 /*                       GDALGetColorEntryAsRGB()                       */
00164 /************************************************************************/
00165 
00166 int GDALGetColorEntryAsRGB( GDALColorTableH hTable, int i, 
00167                             GDALColorEntry *poEntry )
00168 
00169 {
00170     return ((GDALColorTable *) hTable)->GetColorEntryAsRGB( i, poEntry );
00171 }
00172 
00173 /************************************************************************/
00174 /*                           SetColorEntry()                            */
00175 /************************************************************************/
00176 
00192 void GDALColorTable::SetColorEntry( int i, const GDALColorEntry * poEntry )
00193 
00194 {
00195     if( i < 0 )
00196         return;
00197     
00198     if( i >= nEntryCount )
00199     {
00200         paoEntries = (GDALColorEntry *) 
00201             CPLRealloc(paoEntries, sizeof(GDALColorEntry) * (i+1));
00202         memset( paoEntries + nEntryCount, 0, 
00203                 sizeof(GDALColorEntry) * (i + 1 - nEntryCount) );
00204         
00205         nEntryCount = i+1;
00206     }
00207 
00208     paoEntries[i] = *poEntry;
00209 }
00210 
00211 /************************************************************************/
00212 /*                         GDALSetColorEntry()                          */
00213 /************************************************************************/
00214 
00215 void GDALSetColorEntry( GDALColorTableH hTable, int i, 
00216                         const GDALColorEntry * poEntry )
00217 
00218 {
00219     ((GDALColorTable *) hTable)->SetColorEntry( i, poEntry );
00220 }
00221 
00222 
00223 /************************************************************************/
00224 /*                               Clone()                                */
00225 /************************************************************************/
00226 
00233 GDALColorTable *GDALColorTable::Clone() const
00234 
00235 {
00236     GDALColorTable *poNew;
00237 
00238     poNew = new GDALColorTable(eInterp);
00239     poNew->nEntryCount = nEntryCount;
00240     poNew->paoEntries = (GDALColorEntry *) 
00241         CPLMalloc(sizeof(GDALColorEntry)*nEntryCount);
00242     memcpy( poNew->paoEntries, paoEntries, sizeof(GDALColorEntry)*nEntryCount);
00243 
00244     return poNew;
00245 }
00246 
00247 /************************************************************************/
00248 /*                        GDALCloneColorTable()                         */
00249 /************************************************************************/
00250 
00251 GDALColorTableH GDALCloneColorTable( GDALColorTableH hTable )
00252 
00253 {
00254     return (GDALColorTableH) ((GDALColorTable *) hTable)->Clone();
00255 }
00256 
00257 /************************************************************************/
00258 /*                         GetColorEntryCount()                         */
00259 /************************************************************************/
00260 
00269 int GDALColorTable::GetColorEntryCount() const
00270 
00271 {
00272     return nEntryCount;
00273 }
00274 
00275 /************************************************************************/
00276 /*                       GDALGetColorEntryCount()                       */
00277 /************************************************************************/
00278 
00279 int GDALGetColorEntryCount( GDALColorTableH hTable )
00280 
00281 {
00282     return ((GDALColorTable *) hTable)->GetColorEntryCount();
00283 }
00284 
00285 /************************************************************************/
00286 /*                      GetPaletteInterpretation()                      */
00287 /************************************************************************/
00288 
00299 GDALPaletteInterp GDALColorTable::GetPaletteInterpretation() const
00300 
00301 {
00302     return eInterp;
00303 }
00304 
00305 /************************************************************************/
00306 /*                    GDALGetPaltteInterpretation()                     */
00307 /************************************************************************/
00308 
00309 GDALPaletteInterp GDALGetPaletteInterpretation( GDALColorTableH hTable )
00310 
00311 {
00312     return ((GDALColorTable *) hTable)->GetPaletteInterpretation();
00313 }

doxygen1.2.3-20001105 Dimitri van Heesch, © 1997-2000