OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimBrightnessContrastSource.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2000 ImageLinks Inc.
3 //
4 // License: See LICENSE.txt file in the top level directory.
5 //
6 // Author: Garrett Potts
7 //
8 // Description: A brief description of the contents of the file.
9 //
10 //*************************************************************************
11 // $Id: ossimBrightnessContrastSource.cpp 9094 2006-06-13 19:12:40Z dburken $
12 
17 #include <ossim/base/ossimCommon.h>
19 #include <ossim/base/ossimTrace.h>
24 
26  "ossimBrightnessContrastSource",
28 
31  theBrightness(0.0),
32  theContrast(1.0)
33 {
34 }
35 
36 
38 {
39 }
40 
42  const ossimIrect& tileRect, ossim_uint32 resLevel)
43 {
44  ossimRefPtr<ossimImageData> tile = NULL;
45 
47  {
48  tile = theInputConnection->getTile(tileRect, resLevel);
49 
50  if(!tile.valid())
51  {
52  return tile;
53  }
54 
55  if(!isSourceEnabled() ||
56  (tile->getDataObjectStatus()==OSSIM_NULL)||
57  (tile->getDataObjectStatus()==OSSIM_EMPTY)||
58  ( (theBrightness == 0.0) && (theContrast == 1.0) ) )
59  {
60  return tile;
61  }
62 
63  if(!theTile.valid() || !theNormTile.valid())
64  {
65  allocate();
66  }
67 
68  if(!theTile.valid() || !theNormTile.valid())
69  {
70  return tile;
71  }
72 
73  theTile->setImageRectangle(tileRect);
74  theNormTile->setImageRectangle(tileRect);
75 
78 
79  if (theNormTile->getNumberOfBands() == 3)
80  {
82  }
83  else
84  {
86  }
87 
89  theNormTile->getBuf());
90  theTile->validate();
91  return theTile;
92  }
93 
94  return tile;
95 }
96 
98 {
99  ossim_float32* bands[3];
100 
101  bands[0] = (ossim_float32*)theNormTile->getBuf(0);
102  bands[1] = (ossim_float32*)theNormTile->getBuf(1);
103  bands[2] = (ossim_float32*)theNormTile->getBuf(2);
104 
105  ossim_uint32 offset = 0;
107  ossimHsiVector hsi;
108  ossim_float32 i;
110  {
111  for(offset = 0; offset < maxIdx; ++offset)
112  {
113  ossimNormRgbVector rgb(bands[0][offset], bands[1][offset], bands[2][offset]);
114  hsi = rgb;
115  i = (hsi.getI()*theContrast + theBrightness);
117  if(i > 1.0) i = 1.0;
118  hsi.setI(i);
119  rgb = hsi;
120  bands[0][offset] = rgb.getR();
121  bands[1][offset] = rgb.getG();
122  bands[2][offset] = rgb.getB();
123  }
124  }
125  else
126  {
127  for(offset = 0; offset < maxIdx; ++offset)
128  {
129  if((bands[0][offset] != 0.0)&&
130  (bands[1][offset] != 0.0)&&
131  (bands[2][offset] != 0.0))
132  {
133  ossimNormRgbVector rgb(bands[0][offset], bands[1][offset], bands[2][offset]);
134  hsi = rgb;
135  i = (hsi.getI()*theContrast + theBrightness);
137  if(i > 1.0) i = 1.0;
138  hsi.setI(i);
139  rgb = hsi;
140  bands[0][offset] = rgb.getR();
141  bands[1][offset] = rgb.getG();
142  bands[2][offset] = rgb.getB();
143  }
144  }
145  }
146 }
147 
149 {
150  const ossim_uint32 BANDS = theNormTile->getNumberOfBands();
151  const ossim_uint32 PPB = theNormTile->getSizePerBand();
153 
154  for (ossim_uint32 band = 0; band < BANDS; ++band)
155  {
156  ossim_float32* buf = theNormTile->getFloatBuf(band);
157 
158  for (ossim_uint32 i = 0; i < PPB; ++i)
159  {
160  if (buf[i] != 0.0)
161  {
162  ossim_float32 p = buf[i] * theContrast + theBrightness;
163  buf[i] = (p < 1.0) ? ( (p > MP) ? p : 0.0 ) : 1.0;
164  }
165  }
166  }
167 }
168 
170 {
172 
173  theTile = 0;
174  theNormTile = 0;
175 }
176 
178 {
180  {
182  if(theTile.valid())
183  {
187  }
188  if(theTile.valid() && theNormTile.valid())
189  {
190  theTile->initialize();
192  }
193  else
194  {
195  theTile = 0;
196  theNormTile = 0;
197  }
198  }
199 }
200 
202 {
203  if(!property)
204  {
205  return;
206  }
207  ossimString name = property->getName();
208  if(name == "brightness")
209  {
210  theBrightness = property->valueToString().toDouble();
211  }
212  else if(name == "contrast")
213  {
214  theContrast = property->valueToString().toDouble();
215  }
216  else
217  {
219  }
220 }
221 
223 {
224  if(name == "brightness")
225  {
226  ossimNumericProperty* numeric = new ossimNumericProperty(name,
228  -1.0, 1.0);
230  numeric->setCacheRefreshBit();
231  return numeric;
232  }
233  else if(name == "contrast")
234  {
235  ossimNumericProperty* numeric = new ossimNumericProperty(name,
237  0.0, 20.0);
239  numeric->setCacheRefreshBit();
240  return numeric;
241  }
242 
244 }
245 
246 void ossimBrightnessContrastSource::getPropertyNames(std::vector<ossimString>& propertyNames)const
247 {
249 
250  propertyNames.push_back("brightness");
251  propertyNames.push_back("contrast");
252 }
253 
254 
256  const char* prefix)
257 {
258  const char* brightness = kwl.find(prefix, "brightness");
259  const char* contrast = kwl.find(prefix, "contrast");
260 
261  if(brightness)
262  {
263  theBrightness = ossimString(brightness).toDouble();
264  }
265  if(contrast)
266  {
267  theContrast = ossimString(contrast).toDouble();
268  }
269 
270  return ossimImageSourceFilter::loadState(kwl, prefix);
271 }
272 
274  const char* prefix)const
275 {
276  kwl.add(prefix,
277  "brightness",
279  true);
280  kwl.add(prefix,
281  "contrast",
282  theContrast,
283  true);
284 
285  return ossimImageSourceFilter::saveState(kwl, prefix);
286 }
287 
288 
290  ossim_float64 brightness, ossim_float64 contrast)
291 {
292  theBrightness = brightness;
293  theContrast = contrast;
294 }
295 
297 {
298  setBrightnessContrast(brightness, getContrast());
299 }
300 
302 {
304 }
305 
307 {
308  return theBrightness;
309 }
310 
312 {
313  return theContrast;
314 }
virtual ossim_uint32 getWidth() const
virtual bool isSourceEnabled() const
Definition: ossimSource.cpp:79
virtual void setProperty(ossimRefPtr< ossimProperty > property)
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &tileRect, ossim_uint32 resLevel=0)
Will apply the algorithm: i*c + b where b is brightnes c is contrast i is the input value...
virtual ossim_uint32 getNumberOfBands() const
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Keywords saved to list by this method.
virtual void setImageRectangle(const ossimIrect &rect)
virtual ossim_float64 getMinNormalizedPix() const
returns normalized minimum pixel value of band zero.
Represents serializable keyword/value map.
bool valid() const
Definition: ossimRefPtr.h:75
const char * find(const char *key) const
float ossim_float32
void allocate()
Called to initialize tiles by first get tile when theTile or theNormTile are not initialized.
static ossimString toString(bool aValue)
Numeric to string methods.
virtual ossimDataObjectStatus getDataObjectStatus() const
virtual ossim_uint32 getHeight() const
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Keywords searched for by this method.
32 bit floating point
ossimBrightnessContrastSource()
Currently works in hsi space so must be one or three bands.
virtual void setProperty(ossimRefPtr< ossimProperty > property)
virtual void initialize()
Initialize the data buffer.
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
RTTI_DEF1(ossimBrightnessContrastSource, "ossimBrightnessContrastSource", ossimImageSourceFilter) ossimBrightnessContrastSource
double ossim_float64
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
ossimRefPtr< ossimImageData > theTile
void setI(ossim_float64 I)
virtual void setContrast(ossim_float64 contrast)
static ossimImageDataFactory * instance()
virtual void setNumericType(ossimNumericPropertyType type)
void processRgbTile()
Applies the brightness contrast to tile.
virtual ossimDataObjectStatus validate() const
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
virtual ossim_uint32 getSizePerBand() const
Returns the number of pixels in a single band in a tile.
ossimImageSource * theInputConnection
unsigned int ossim_uint32
ossim_float64 getI() const
double toDouble() const
virtual void copyTileToNormalizedBuffer(ossim_float64 *buf) const
Copies entire tile to buf passed in.
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 void copyNormalizedBufferToTile(ossim_float64 *buf)
Copies buf passed in to tile.
virtual ossimRefPtr< ossimImageData > create(ossimSource *owner, ossimScalarType scalar, ossim_uint32 bands=1) const
virtual void initialize()
Calls base ossimImageSourceFilter::initialize() to reset connection if needed then nulls out tiles...
virtual const ossim_float32 * getFloatBuf() const
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
ossim_float64 getB() const
virtual ossim_float64 getContrast() const
virtual const void * getBuf() const
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
#define OSSIM_DEFAULT_MIN_PIX_NORM_FLOAT
virtual void setDataObjectStatus(ossimDataObjectStatus status) const
Full list found in ossimConstants.h.
virtual ossim_float64 getBrightness() const
ossim_float64 getG() const
virtual void setBrightnessContrast(ossim_float64 brightness, ossim_float64 contrast)
ossimRefPtr< ossimImageData > theNormTile
ossim_float64 getR() const
void processNBandTile()
Applies the brightness contrast to tile.
virtual void setBrightness(ossim_float64 brightness)
void setCacheRefreshBit()
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)