OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimHsvToRgbSource.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: ossimHsvToRgbSource.cpp 17195 2010-04-23 17:32:18Z dburken $
15 #include <ossim/base/ossimCommon.h>
19 
21 
24  theBlankTile(NULL),
25  theTile(NULL)
26 {
27 }
28 
30  : ossimImageSourceFilter(inputSource),
31  theBlankTile(NULL),
32  theTile(NULL)
33 {
34 }
35 
37 {
38 }
39 
41  const ossimIrect& tileRect,
42  ossim_uint32 resLevel)
43 {
45  {
46  ossimRefPtr<ossimImageData> imageData =
47  theInputConnection->getTile(tileRect, resLevel);
48 
49  if(!imageData.valid()) return theBlankTile;
50 
51  if(!isSourceEnabled())
52  {
53  return imageData;
54  }
55 
56  if(!theTile.valid()) allocate();
57  if(!theTile.valid())
58  {
60  << "Unable to initialize ossimHsvToRgbSource in getTile"
61  << std::endl;
63  }
64 
65  long w = tileRect.width();
66  long h = tileRect.height();
67  long tw = theTile->getWidth();
68  long th = theTile->getHeight();
69 
70  theBlankTile->setOrigin(tileRect.ul());
72  theTile->setWidthHeight(w, h);
73  theTile->setOrigin(tileRect.ul());
74  if( (tw*th) != (w*h))
75  {
77  }
78  else
79  {
80  theTile->makeBlank();
81  }
82 
83  if((imageData->getNumberOfBands()==3)&&
84  (imageData->getScalarType()==OSSIM_NORMALIZED_FLOAT)&&
85  (imageData->getDataObjectStatus()!=OSSIM_NULL))
86  {
87  ossim_uint8* outputBands[3];
88  float* inputBands[3];
89  outputBands[0] = static_cast<ossim_uint8*>(theTile->getBuf(0));
90  outputBands[1] = static_cast<ossim_uint8*>(theTile->getBuf(1));
91  outputBands[2] = static_cast<ossim_uint8*>(theTile->getBuf(2));
92  inputBands[0] = static_cast<float*>(imageData->getBuf(0));
93  inputBands[1] = static_cast<float*>(imageData->getBuf(1));
94  inputBands[2] = static_cast<float*>(imageData->getBuf(2));
95 
96  long height = imageData->getHeight();
97  long width = imageData->getWidth();
98  long offset = 0;
99  for(long row = 0; row < height; ++row)
100  {
101  for(long col = 0; col < width; ++col)
102  {
103  ossimHsvVector hsv(inputBands[0][offset],
104  inputBands[1][offset],
105  inputBands[2][offset]);
106 
107  ossimRgbVector rgb(hsv);
108 
109  outputBands[0][offset] = rgb.getR();
110  outputBands[1][offset] = rgb.getG();
111  outputBands[2][offset] = rgb.getB();
112 
113  ++offset;
114  }
115  }
116  }
117  else
118  {
119  return imageData;
120  }
121  theTile->validate();
122  return theTile;
123  }
124 
125  return theBlankTile;
126 }
127 
129 {
130  theBlankTile = NULL;
131  theTile = NULL;
132 }
133 
135 {
138  theTile->initialize();
139 }
140 
142 {
143  return OSSIM_UINT8;
144 }
145 
147 {
148  return 0;
149 }
150 
152 {
154 }
155 
157 {
159 }
virtual ossim_uint32 getWidth() const
virtual bool isSourceEnabled() const
Definition: ossimSource.cpp:79
virtual ossim_uint32 getNumberOfBands() const
unsigned char getR() const
virtual void setWidthHeight(ossim_uint32 w, ossim_uint32 h)
virtual double getNullPixelValue() const
bool valid() const
Definition: ossimRefPtr.h:75
#define OSSIM_DEFAULT_MAX_PIX_UCHAR
ossim_uint32 height() const
Definition: ossimIrect.h:487
const ossimIpt & ul() const
Definition: ossimIrect.h:274
virtual ossimDataObjectStatus getDataObjectStatus() const
virtual ossim_uint32 getHeight() const
virtual void initialize()
Initialize the data buffer.
virtual ossimObject * dup() const
ossimRefPtr< ossimImageData > theBlankTile
static ossimImageDataFactory * instance()
#define OSSIM_DEFAULT_MIN_PIX_UCHAR
virtual ossimDataObjectStatus validate() const
virtual double getMinPixelValue(ossim_uint32 band=0) const
Returns the min pixel of the band.
ossimImageSource * theInputConnection
unsigned int ossim_uint32
32 bit normalized floating point
ossimRefPtr< ossimImageData > theTile
unsigned char getB() const
virtual ossimScalarType getOutputScalarType() const
This will be used to query the output pixel type of the tile source.
virtual ossimRefPtr< ossimImageData > create(ossimSource *owner, ossimScalarType scalar, ossim_uint32 bands=1) const
ossim_uint32 width() const
Definition: ossimIrect.h:500
ossimScalarType
virtual void setOrigin(const ossimIpt &origin)
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &tileRect, ossim_uint32 resLevel=0)
unsigned char getG() const
virtual ossimScalarType getScalarType() const
virtual void makeBlank()
Initializes data to null pixel values.
virtual const void * getBuf() const
8 bit unsigned integer
#define RTTI_DEF1(cls, name, b1)
Definition: ossimRtti.h:485
unsigned char ossim_uint8
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
virtual double getMaxPixelValue(ossim_uint32 band=0) const
Returns the max pixel of the band.
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)