24 static const char* MIN_VALUE_KW =
"min_value";
25 static const char* MAX_VALUE_KW =
"max_value";
26 static const char* MODE_KW =
"mode";
27 static const char* LUT_FILE_KW =
"lut_file";
33 theMinValueOverride(false),
34 theMaxValueOverride(false),
39 setDescription(
"Look-up-table remapper from single-band index image to 24-bit RGB.");
53 if (!tile || !tile->
getBuf())
78 std::map<double, ossimRgbVector>::const_iterator lut_entry;
87 index = ((
double*) tile->
getBuf())[pixel];
94 index = (double)(((
float*) tile->
getBuf())[pixel]);
112 if (index == null_index)
127 lut_entry =
theLut.find(index);
128 if (lut_entry ==
theLut.end())
131 color = lut_entry->second;
137 lut_entry =
theLut.find(index);
138 if (lut_entry !=
theLut.end())
141 color = lut_entry->second;
145 lut_entry =
theLut.upper_bound(index);
146 if ((lut_entry ==
theLut.end()) || (lut_entry ==
theLut.begin()))
151 double index_hi = lut_entry->first;
154 double index_lo = lut_entry->first;
156 double w_lo = (index_hi - index)/(index_hi - index_lo);
157 double w_hi = 1.0 - w_lo;
158 color.
setR(ossim::round<ossim_uint8, double>( color_hi.
getR()*w_hi + color_lo.
getR()*w_lo ));
159 color.
setG(ossim::round<ossim_uint8, double>( color_hi.
getG()*w_hi + color_lo.
getG()*w_lo ));
160 color.
setB(ossim::round<ossim_uint8, double>( color_hi.
getB()*w_hi + color_lo.
getB()*w_lo ));
166 outBuf[0][pixel] = color.
getR();
167 outBuf[1][pixel] = color.
getG();
168 outBuf[2][pixel] = color.
getB();
228 kwl.
add(prefix, MODE_KW, value.
c_str(),
true);
230 bool rtn_stat =
true;
239 std::map<double, ossimRgbVector>::const_iterator iter =
theLut.begin();
240 while (iter !=
theLut.end())
246 kwl.
add(prefix, (base_keyword+
".index").chars(), iter->first);
247 color_keyword = base_keyword +
".color";
251 color_keyword = base_keyword;
254 rgbVector = iter->second;
269 bool return_state =
true;
279 kwl->
add(prefix, lut_kwl,
false);
291 lookup = kwl->
find(prefix, MAX_VALUE_KW);
298 lookup = kwl->
find(prefix, MODE_KW);
301 else if (lookup.
contains(
"vertices"))
321 std::vector<ossimString> rgbList;
324 bool rtn_state =
true;
333 keyword = base_keyword +
".index";
334 indexStr = kwl->
find(prefix, keyword.
chars());
335 if (indexStr.
empty())
339 keyword = base_keyword +
".color";
340 rgbStr = kwl->
find(prefix, keyword.
chars());
346 index = (double) numEntries;
347 keyword = base_keyword;
348 rgbStr = kwl->
find(prefix, keyword.
chars());
352 rgbStr = kwl->
find(prefix, (keyword +
".r").chars());
354 rgbStr += kwl->
find(prefix, (keyword +
".g").chars());
356 rgbStr += kwl->
find(prefix, (keyword +
".b").chars());
362 rgbStr.
split(rgbList, blank,
true);
363 if (rgbList.size() != 3)
366 "Bad color specification in LUT KWL. LUT is not properly initialized."<<endl;
370 rgbVector.
setR(rgbList[0].toUInt8());
371 rgbVector.
setG(rgbList[1].toUInt8());
372 rgbVector.
setB(rgbList[2].toUInt8());
373 theLut.insert(std::pair<double, ossimRgbVector>(index, rgbVector));
382 std::map<double, ossimRgbVector> orig_lut =
theLut;
383 std::map<double, ossimRgbVector>::iterator iter = orig_lut.begin();
396 while (iter != orig_lut.end())
399 theLut.insert(std::pair<double, ossimRgbVector>(index, iter->second));
virtual void initialize()
16 bit unsigned integer (15 bits used)
virtual ossim_uint32 getWidth() const
virtual bool isSourceEnabled() const
ossim_uint32 getNumberOfOutputBands() const
Returns the number of bands in a tile returned from this TileSource.
virtual void setDescription(const ossimString &description)
unsigned char getR() const
virtual void setImageRectangle(const ossimIrect &rect)
void allocate()
Called on first getTile, will initialize all data needed.
Represents serializable keyword/value map.
bool addFile(const char *file)
virtual ossim_uint32 getNumberOfOutputBands() const
Returns the number of bands in a tile returned from this TileSource.
const char * find(const char *key) const
double nan()
Method to return ieee floating point double precision NAN.
This code was derived from https://gist.github.com/mshockwave.
void setR(unsigned char R)
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=NULL) const
Method to save the state of an object to a keyword list.
bool contains(char aChar) const
static ossimString toString(bool aValue)
Numeric to string methods.
virtual double getMaxPixelValue(ossim_uint32 band=0) const
Returns the max pixel of the band.
void split(std::vector< ossimString > &result, const ossimString &separatorList, bool skipBlankFields=false) const
Splits this string into a vector of strings (fields) using the delimiter list specified.
virtual ossimDataObjectStatus getDataObjectStatus() const
virtual ossim_uint32 getHeight() const
16 bit unsigned integer (14 bits used)
bool initializeLut(const ossimKeywordlist *kwl, const char *prefix=0)
16 bit unsigned integer (13 bits used)
unsigned short ossim_uint16
virtual double getNullPixelValue(ossim_uint32 band=0) const
Each band has a null pixel associated with it.
virtual void initialize()
Initialize the data buffer.
virtual ossimScalarType getOutputScalarType() const
This will be used to query the output pixel type of the tile source.
virtual void initialize()
void setB(unsigned char B)
virtual double getMinPixelValue(ossim_uint32 band=0) const
Returns the min pixel of the band.
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
static ossimImageDataFactory * instance()
virtual ossimDataObjectStatus validate() const
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=NULL)
Method to the load (recreate) the state of an object from a keyword list.
std::string::size_type length() const
signed short ossim_sint16
virtual double getMinPixelValue(ossim_uint32 band=0) const
Returns the min pixel of the band.
void setLut(const ossimFilename &file)
Set lookup table(lut) method.
ossimImageSource * theInputConnection
unsigned int ossim_uint32
virtual const ossim_float64 * getNullPix() const
const char * chars() const
For backward compatibility.
32 bit normalized floating point
unsigned char getB() const
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
virtual ossimRefPtr< ossimImageData > create(ossimSource *owner, ossimScalarType scalar, ossim_uint32 bands=1) const
double getMinValue() const
void setG(unsigned char G)
RTTI_DEF1(ossimIndexToRgbLutFilter, "ossimIndexToRgbLutFilter", ossimImageSourceFilter)
ossimIndexToRgbLutFilter()
unsigned char getG() const
virtual ossimScalarType getScalarType() const
virtual void makeBlank()
Initializes data to null pixel values.
16 bit unsigned integer (11 bits used)
virtual ossimScalarType getOutputScalarType() const
This will be used to query the output pixel type of the tile source.
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
virtual double getMaxPixelValue(ossim_uint32 band=0) const
Returns the max pixel of the band.
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &origin, ossim_uint32 resLevel=0)
virtual const void * getBuf() const
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string's contents...
std::map< double, ossimRgbVector > theLut
virtual void initialize()=0
double getMaxValue() const
virtual ~ossimIndexToRgbLutFilter()
ossimRefPtr< ossimImageData > theTile
unsigned char ossim_uint8
virtual double getNullPixelValue(ossim_uint32 band=0) const
Each band has a null pixel associated with it.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
void setMinValue(double value)
void setMaxValue(double value)
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)
16 bit unsigned integer (12 bits used)