root/tags/gdal_1_3_2/gcore/gdalcolortable.cpp
| Revision 9398, 10.0 kB (checked in by fwarmerdam, 3 years ago) | |
|---|---|
| |
| Line | |
|---|---|
| 1 | /****************************************************************************** |
| 2 | * $Id$ |
| 3 | * |
| 4 | * Project: GDAL Core |
| 5 | * Purpose: Color table implementation. |
| 6 | * Author: Frank Warmerdam, warmerdam@pobox.com |
| 7 | * |
| 8 | ********************************************************************** |
| 9 | * Copyright (c) 2000, Frank Warmerdam |
| 10 | * |
| 11 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 12 | * copy of this software and associated documentation files (the "Software"), |
| 13 | * to deal in the Software without restriction, including without limitation |
| 14 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 15 | * and/or sell copies of the Software, and to permit persons to whom the |
| 16 | * Software is furnished to do so, subject to the following conditions: |
| 17 | * |
| 18 | * The above copyright notice and this permission notice shall be included |
| 19 | * in all copies or substantial portions of the Software. |
| 20 | * |
| 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 22 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 24 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 27 | * DEALINGS IN THE SOFTWARE. |
| 28 | ****************************************************************************** |
| 29 | * $Log$ |
| 30 | * Revision 1.6 2006/03/28 14:49:56 fwarmerdam |
| 31 | * updated contact info |
| 32 | * |
| 33 | * Revision 1.5 2005/09/05 19:29:29 fwarmerdam |
| 34 | * minor formatting fix |
| 35 | * |
| 36 | * Revision 1.4 2005/07/25 21:24:28 ssoule |
| 37 | * Changed GDALColorTable's "GDALColorEntry *paoEntries" to |
| 38 | * "std::vector<GDALColorEntry> aoEntries". |
| 39 | * |
| 40 | * Revision 1.3 2005/04/04 15:24:48 fwarmerdam |
| 41 | * Most C entry points now CPL_STDCALL |
| 42 | * |
| 43 | * Revision 1.2 2001/07/18 04:04:30 warmerda |
| 44 | * added CPL_CVSID |
| 45 | * |
| 46 | * Revision 1.1 2000/03/06 02:26:00 warmerda |
| 47 | * New |
| 48 | * |
| 49 | */ |
| 50 | |
| 51 | #include "gdal_priv.h" |
| 52 | |
| 53 | CPL_CVSID("$Id$"); |
| 54 | |
| 55 | /************************************************************************/ |
| 56 | /* GDALColorTable() */ |
| 57 | /************************************************************************/ |
| 58 | |
| 59 | /** |
| 60 | * Construct a new color table. |
| 61 | * |
| 62 | * This constructor is the same as the C GDALCreateColorTable() function. |
| 63 | * |
| 64 | * @param eInterpIn the interpretation to be applied to GDALColorEntry |
| 65 | * values. |
| 66 | */ |
| 67 | |
| 68 | GDALColorTable::GDALColorTable( GDALPaletteInterp eInterpIn ) |
| 69 | |
| 70 | { |
| 71 | eInterp = eInterpIn; |
| 72 | } |
| 73 | |
| 74 | /************************************************************************/ |
| 75 | /* GDALCreateColorTable() */ |
| 76 | /************************************************************************/ |
| 77 | |
| 78 | GDALColorTableH CPL_STDCALL GDALCreateColorTable( GDALPaletteInterp eInterp ) |
| 79 | |
| 80 | { |
| 81 | return (GDALColorTableH) (new GDALColorTable( eInterp )); |
| 82 | } |
| 83 | |
| 84 | |
| 85 | /************************************************************************/ |
| 86 | /* ~GDALColorTable() */ |
| 87 | /************************************************************************/ |
| 88 | |
| 89 | /** |
| 90 | * Destructor. |
| 91 | * |
| 92 | * This descructor is the same as the C GDALDestroyColorTable() function. |
| 93 | */ |
| 94 | |
| 95 | GDALColorTable::~GDALColorTable() |
| 96 | |
| 97 | { |
| 98 | } |
| 99 | |
| 100 | /************************************************************************/ |
| 101 | /* GDALDestroyColorTable() */ |
| 102 | /************************************************************************/ |
| 103 | |
| 104 | void CPL_STDCALL GDALDestroyColorTable( GDALColorTableH hTable ) |
| 105 | |
| 106 | { |
| 107 | delete (GDALColorTable *) hTable; |
| 108 | } |
| 109 | |
| 110 | /************************************************************************/ |
| 111 | /* GetColorEntry() */ |
| 112 | /************************************************************************/ |
| 113 | |
| 114 | /** |
| 115 | * Fetch a color entry from table. |
| 116 | * |
| 117 | * This method is the same as the C function GDALGetColorEntry(). |
| 118 | * |
| 119 | * @param i entry offset from zero to GetColorEntryCount()-1. |
| 120 | * |
| 121 | * @return pointer to internal color entry, or NULL if index is out of range. |
| 122 | */ |
| 123 | |
| 124 | const GDALColorEntry *GDALColorTable::GetColorEntry( int i ) const |
| 125 | |
| 126 | { |
| 127 | if( i < 0 || i >= static_cast<int>(aoEntries.size()) ) |
| 128 | return NULL; |
| 129 | else |
| 130 | return &aoEntries[i]; |
| 131 | } |
| 132 | |
| 133 | /************************************************************************/ |
| 134 | /* GDALGetColorEntry() */ |
| 135 | /************************************************************************/ |
| 136 | |
| 137 | const GDALColorEntry * CPL_STDCALL |
| 138 | GDALGetColorEntry( GDALColorTableH hTable, int i ) |
| 139 | |
| 140 | { |
| 141 | return ((GDALColorTable *) hTable)->GetColorEntry( i ); |
| 142 | } |
| 143 | |
| 144 | |
| 145 | /************************************************************************/ |
| 146 | /* GetColorEntryAsRGB() */ |
| 147 | /************************************************************************/ |
| 148 | |
| 149 | /** |
| 150 | * Fetch a table entry in RGB format. |
| 151 | * |
| 152 | * In theory this method should support translation of color palettes in |
| 153 | * non-RGB color spaces into RGB on the fly, but currently it only works |
| 154 | * on RGB color tables. |
| 155 | * |
| 156 | * This method is the same as the C function GDALGetColorEntryAsRGB(). |
| 157 | * |
| 158 | * @param i entry offset from zero to GetColorEntryCount()-1. |
| 159 | * |
| 160 | * @param poEntry the existing GDALColorEntry to be overrwritten with the RGB |
| 161 | * values. |
| 162 | * |
| 163 | * @return TRUE on success, or FALSE if the conversion isn't supported. |
| 164 | */ |
| 165 | |
| 166 | int GDALColorTable::GetColorEntryAsRGB( int i, GDALColorEntry *poEntry ) const |
| 167 | |
| 168 | { |
| 169 | if( eInterp != GPI_RGB || i < 0 || i >= static_cast<int>(aoEntries.size()) ) |
| 170 | return FALSE; |
| 171 | |
| 172 | *poEntry = aoEntries[i]; |
| 173 | return TRUE; |
| 174 | } |
| 175 | |
| 176 | /************************************************************************/ |
| 177 | /* GDALGetColorEntryAsRGB() */ |
| 178 | /************************************************************************/ |
| 179 | |
| 180 | int CPL_STDCALL GDALGetColorEntryAsRGB( GDALColorTableH hTable, int i, |
| 181 | GDALColorEntry *poEntry ) |
| 182 | |
| 183 | { |
| 184 | return ((GDALColorTable *) hTable)->GetColorEntryAsRGB( i, poEntry ); |
| 185 | } |
| 186 | |
| 187 | /************************************************************************/ |
| 188 | /* SetColorEntry() */ |
| 189 | /************************************************************************/ |
| 190 | |
| 191 | /** |
| 192 | * Set entry in color table. |
| 193 | * |
| 194 | * Note that the passed in color entry is copied, and no internal reference |
| 195 | * to it is maintained. Also, the passed in entry must match the color |
| 196 | * interpretation of the table to which it is being assigned. |
| 197 | * |
| 198 | * The table is grown as needed to hold the supplied offset. |
| 199 | * |
| 200 | * This function is the same as the C function GDALSetColorEntry(). |
| 201 | * |
| 202 | * @param i entry offset from zero to GetColorEntryCount()-1. |
| 203 | * @param poEntry value to assign to table. |
| 204 | */ |
| 205 | |
| 206 | void GDALColorTable::SetColorEntry( int i, const GDALColorEntry * poEntry ) |
| 207 | |
| 208 | { |
| 209 | if( i < 0 ) |
| 210 | return; |
| 211 | |
| 212 | if( i >= static_cast<int>(aoEntries.size()) ) |
| 213 | { |
| 214 | GDALColorEntry oBlack; |
| 215 | oBlack.c1 = oBlack.c2 = oBlack.c3 = oBlack.c4 = 0; |
| 216 | aoEntries.resize(i+1, oBlack); |
| 217 | } |
| 218 | |
| 219 | aoEntries[i] = *poEntry; |
| 220 | } |
| 221 | |
| 222 | /************************************************************************/ |
| 223 | /* GDALSetColorEntry() */ |
| 224 | /************************************************************************/ |
| 225 | |
| 226 | void CPL_STDCALL GDALSetColorEntry( GDALColorTableH hTable, int i, |
| 227 | const GDALColorEntry * poEntry ) |
| 228 | |
| 229 | { |
| 230 | ((GDALColorTable *) hTable)->SetColorEntry( i, poEntry ); |
| 231 | } |
| 232 | |
| 233 | |
| 234 | /************************************************************************/ |
| 235 | /* Clone() */ |
| 236 | /************************************************************************/ |
| 237 | |
| 238 | /** |
| 239 | * Make a copy of a color table. |
| 240 | * |
| 241 | * This method is the same as the C function GDALCloneColorTable(). |
| 242 | */ |
| 243 | |
| 244 | GDALColorTable *GDALColorTable::Clone() const |
| 245 | |
| 246 | { |
| 247 | return new GDALColorTable(*this); |
| 248 | } |
| 249 | |
| 250 | /************************************************************************/ |
| 251 | /* GDALCloneColorTable() */ |
| 252 | /************************************************************************/ |
| 253 | |
| 254 | GDALColorTableH CPL_STDCALL GDALCloneColorTable( GDALColorTableH hTable ) |
| 255 | |
| 256 | { |
| 257 | return (GDALColorTableH) ((GDALColorTable *) hTable)->Clone(); |
| 258 | } |
| 259 | |
| 260 | /************************************************************************/ |
| 261 | /* GetColorEntryCount() */ |
| 262 | /************************************************************************/ |
| 263 | |
| 264 | /** |
| 265 | * Get number of color entries in table. |
| 266 | * |
| 267 | * This method is the same as the function GDALGetColorEntryCount(). |
| 268 | * |
| 269 | * @return the number of color entries. |
| 270 | */ |
| 271 | |
| 272 | int GDALColorTable::GetColorEntryCount() const |
| 273 | |
| 274 | { |
| 275 | return aoEntries.size(); |
| 276 | } |
| 277 | |
| 278 | /************************************************************************/ |
| 279 | /* GDALGetColorEntryCount() */ |
| 280 | /************************************************************************/ |
| 281 | |
| 282 | int CPL_STDCALL GDALGetColorEntryCount( GDALColorTableH hTable ) |
| 283 | |
| 284 | { |
| 285 | return ((GDALColorTable *) hTable)->GetColorEntryCount(); |
| 286 | } |
| 287 | |
| 288 | /************************************************************************/ |
| 289 | /* GetPaletteInterpretation() */ |
| 290 | /************************************************************************/ |
| 291 | |
| 292 | /** |
| 293 | * Fetch palette interpretation. |
| 294 | * |
| 295 | * The returned value is used to interprete the values in the GDALColorEntry. |
| 296 | * |
| 297 | * This method is the same as the C function GDALGetPaletteInterpretation(). |
| 298 | * |
| 299 | * @return palette interpretation enumeration value, usually GPI_RGB. |
| 300 | */ |
| 301 | |
| 302 | GDALPaletteInterp GDALColorTable::GetPaletteInterpretation() const |
| 303 | |
| 304 | { |
| 305 | return eInterp; |
| 306 | } |
| 307 | |
| 308 | /************************************************************************/ |
| 309 | /* GDALGetPaltteInterpretation() */ |
| 310 | /************************************************************************/ |
| 311 | |
| 312 | GDALPaletteInterp CPL_STDCALL |
| 313 | GDALGetPaletteInterpretation( GDALColorTableH hTable ) |
| 314 | |
| 315 | { |
| 316 | return ((GDALColorTable *) hTable)->GetPaletteInterpretation(); |
| 317 | } |
Note: See TracBrowser for help on using the browser.
