OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimRgbToIndexFilter.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2000 ImageLinks Inc.
3 //
4 // License: LGPL
5 //
6 // See LICENSE.txt file in the top level directory for more details.
7 //
8 // Author: Garrett Potts
9 //
10 //*************************************************************************
11 // $Id: ossimRgbToIndexFilter.cpp 17195 2010-04-23 17:32:18Z dburken $
12 
16 
17 
19  "ossimRgbToIndexFilter",
21 
24  theLut(new ossimRgbLutDataObject()),
25  theTile(NULL)
26 {
27 }
28 
30  const ossimRgbLutDataObject& rgbLut)
31  :ossimImageSourceFilter(inputSource),
32  theLut((ossimRgbLutDataObject*)rgbLut.dup()),
33  theTile(NULL)
34 {
35 }
36 
38 {
39  theLut = 0;
40 }
41 
43 {
45 
46  // Force allocate on next getTile.
47  theTile = NULL;
48 }
49 
51 {
52  theTile = NULL;
53 
54  if(isSourceEnabled())
55  {
58  }
59 }
60 
62 {
64  theTile = NULL;
65 }
66 
68  const ossimIrect& origin,
69  ossim_uint32 resLevel)
70 {
72  {
74  }
75 
76  if(!theTile.valid())
77  {
78  allocate();
79  }
80 
82  resLevel);
83 
84  if(!theTile.valid() || !input.valid())
85  {
86  return input;
87  }
88 
89  theTile->setImageRectangle(origin);
90 
91  if(input->getScalarType() == OSSIM_UCHAR)
92  {
94  return convertInputTile(input);
95  }
96  else
97  {
98  theTile->makeBlank();
99  }
100 
102 
103  return theTile;
104 }
105 
107 {
108  if (!tile)
109  {
110  return theTile;
111  }
112 
113  const ossim_uint32 BANDS = tile->getNumberOfBands();
114 
115  if (!BANDS)
116  {
117  return theTile;
118  }
119 
120  ossim_uint8* band[3];
121  ossim_uint8* outBand = (ossim_uint8*)theTile->getBuf();
122 
123  if(BANDS >= 3)
124  {
125  band[0] = (ossim_uint8*)(tile->getBuf(0));
126  band[1] = (ossim_uint8*)(tile->getBuf(1));
127  band[2] = (ossim_uint8*)(tile->getBuf(2));
128  }
129  else
130  {
131  band[0] = (ossim_uint8*)(tile->getBuf(0));
132  band[1] = (ossim_uint8*)(tile->getBuf(0));
133  band[2] = (ossim_uint8*)(tile->getBuf(0));
134  }
135 
136  if(band[0])
137  {
138  ossim_uint32 upper = tile->getWidth()*tile->getHeight();
139 
140  for(ossim_uint32 offset = 0; offset < upper; ++offset)
141  {
142  *outBand = theLut->findIndex(*band[0], *band[1], *band[2]);
143 
144  ++outBand;
145  ++band[0];
146  ++band[1];
147  ++band[2];
148  }
149  }
150 
151  return theTile;
152 }
153 
155  const char* prefix)const
156 {
157  ossimString newPrefix = prefix;
158  newPrefix = newPrefix + "lut.";
159 
160  theLut->saveState(kwl, newPrefix.c_str());
161 
162  return ossimImageSourceFilter::saveState(kwl, prefix);
163 }
164 
165 bool ossimRgbToIndexFilter::loadState(const ossimKeywordlist& kwl, const char* prefix)
166 {
167  ossimString newPrefix = prefix;
168  newPrefix = newPrefix + "lut.";
169 
170  theLut->loadState(kwl, newPrefix.c_str());
171 
172  return ossimImageSourceFilter::loadState(kwl, prefix);
173 }
174 
176 {
177  if(isSourceEnabled())
178  {
179  return 1;
180  }
181 
183 }
184 
186 {
187  if(isSourceEnabled())
188  {
189  return OSSIM_UCHAR;
190  }
191 
193 }
194 
196 {
197  theLut = (ossimRgbLutDataObject*) lut.dup();
198 }
199 
201 {
202  if(isSourceEnabled())
203  {
204  return 0.0;
205  }
206 
208 }
209 
211 {
212  if(isSourceEnabled())
213  {
214  return 1.0;
215  }
216 
218 }
219 
221 {
222  if(isSourceEnabled())
223  {
224  return 255.0;
225  }
226 
228 }
virtual ossimScalarType getOutputScalarType() const
This will be used to query the output pixel type of the tile source.
virtual ossim_uint32 getWidth() const
virtual bool isSourceEnabled() const
Definition: ossimSource.cpp:79
virtual ossim_uint32 getNumberOfBands() const
RTTI_DEF1(ossimRgbToIndexFilter, "ossimRgbToIndexFilter", ossimImageSourceFilter)
virtual void setImageRectangle(const ossimIrect &rect)
Represents serializable keyword/value map.
virtual ossim_uint32 getNumberOfOutputBands() const
Returns the number of bands in a tile returned from this TileSource.
bool valid() const
Definition: ossimRefPtr.h:75
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &origin, ossim_uint32 resLevel=0)
ossimRefPtr< ossimRgbLutDataObject > theLut
virtual void disableSource()
Definition: ossimSource.cpp:89
virtual ossim_uint32 getHeight() const
virtual double getMaxPixelValue(ossim_uint32 band=0) const
Returns the max pixel of the band.
virtual void initialize()
Initialize the data buffer.
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
virtual ossim_uint32 getNumberOfOutputBands() const
Returns the number of bands in a tile returned from this TileSource.
virtual double getMinPixelValue(ossim_uint32 band=0) const
Returns the min pixel of the band.
static ossimImageDataFactory * instance()
ossimImageSource * theInputConnection
unsigned int ossim_uint32
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 double getNullPixelValue(ossim_uint32 band=0) const
Each band has a null pixel associated with it.
virtual ossimRefPtr< ossimImageData > create(ossimSource *owner, ossimScalarType scalar, ossim_uint32 bands=1) const
virtual ossimRefPtr< ossimImageData > convertInputTile(ossimRefPtr< ossimImageData > &tile)
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
ossimScalarType
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
virtual ossimScalarType getScalarType() const
virtual void makeBlank()
Initializes data to null pixel values.
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 double getMinPixelValue(ossim_uint32 band=0) const
Returns the min pixel of the band.
ossimRefPtr< ossimImageData > theTile
virtual const void * getBuf() const
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
virtual void setDataObjectStatus(ossimDataObjectStatus status) const
Full list found in ossimConstants.h.
int findIndex(const ossimRgbVector &rgb)
virtual ossimObject * dup() const
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
void setLut(ossimRgbLutDataObject &lut)
unsigned char ossim_uint8
virtual double getNullPixelValue(ossim_uint32 band=0) const
Each band has a null pixel associated with it.
8 bit unsigned iteger
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)