OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimRgbToHsvSource.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: ossimRgbToHsvSource.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 
29 
31  : ossimImageSourceFilter(inputSource),
32  theBlankTile(NULL),
33  theTile(NULL)
34 {
35 }
36 
38 {
39 }
40 
42  const ossimIrect& tileRect,
43  ossim_uint32 resLevel)
44 {
46  {
47  return ossimRefPtr<ossimImageData>(); // This filter requires an input.
48  }
49 
50  ossimRefPtr<ossimImageData> inputTile =
51  theInputConnection->getTile(tileRect, resLevel);
52  if(!isSourceEnabled() || !inputTile.valid())
53  {
54  return inputTile;
55  }
56 
57  if(!theTile.valid())
58  {
59  allocate(); // First time through...
60  }
61 
62  if (!theTile.valid()) // throw exeption...
63  {
64  return inputTile;
65  }
66 
67  if( inputTile->getDataObjectStatus() == OSSIM_NULL ||
68  inputTile->getDataObjectStatus() == OSSIM_EMPTY )
69  {
71  return theBlankTile;
72  }
73 
74  if((inputTile->getNumberOfBands()==3)&&
75  (inputTile->getScalarType()==OSSIM_UCHAR)&&
76  (inputTile->getDataObjectStatus()!=OSSIM_NULL))
77  {
78  // Set the origin, resize if needed of the output tile.
79  theTile->setImageRectangle(tileRect);
80 
81  float* outputBands[3];
82  ossim_uint8* inputBands[3];
83  outputBands[0] = static_cast<float*>(theTile->getBuf(0));
84  outputBands[1] = static_cast<float*>(theTile->getBuf(1));
85  outputBands[2] = static_cast<float*>(theTile->getBuf(2));
86  inputBands[0] = static_cast<ossim_uint8*>(inputTile->getBuf(0));
87  inputBands[1] = static_cast<ossim_uint8*>(inputTile->getBuf(1));
88  inputBands[2] = static_cast<ossim_uint8*>(inputTile->getBuf(2));
89 
90  long height = inputTile->getHeight();
91  long width = inputTile->getWidth();
92  long offset = 0;
93  for(long row = 0; row < height; ++row)
94  {
95  for(long col = 0; col < width; ++col)
96  {
97  ossimRgbVector rgb(inputBands[0][offset],
98  inputBands[1][offset],
99  inputBands[2][offset]);
100 
101  ossimHsvVector hsv(rgb);
102 
103  outputBands[0][offset] = hsv.getH();
104  outputBands[1][offset] = hsv.getS();
105  outputBands[2][offset] = hsv.getV();
106 
107  ++offset;
108  }
109  }
110  }
111  else // Input tile not of correct type to process...
112  {
113  return inputTile;
114  }
115  theTile->validate();
116  return theTile;
117 }
118 
120 {
121  // Base class will recapture "theInputConnection".
123 }
124 
126 {
129  theTile->initialize();
130 }
131 
133 {
134  return OSSIM_NORMALIZED_FLOAT;
135 }
136 
138 {
139  return 3;
140 }
141 
143 {
144  return ossim::nan();
145 }
146 
148 {
149  return 0.0;
150 }
151 
153 {
154  return 1.0;
155 }
virtual ossim_uint32 getWidth() const
virtual bool isSourceEnabled() const
Definition: ossimSource.cpp:79
virtual double getNullPixelValue() const
virtual ossim_uint32 getNumberOfBands() const
virtual void setImageRectangle(const ossimIrect &rect)
bool valid() const
Definition: ossimRefPtr.h:75
double nan()
Method to return ieee floating point double precision NAN.
Definition: ossimCommon.h:135
float getS() const
ossimRefPtr< ossimImageData > theBlankTile
virtual ossimDataObjectStatus getDataObjectStatus() const
virtual ossim_uint32 getHeight() const
virtual void initialize()
Initialize the data buffer.
virtual ossimObject * dup() const
virtual ossim_uint32 getNumberOfOutputBands() const
Returns the number of bands in a tile returned from this TileSource.
static ossimImageDataFactory * instance()
virtual ossimDataObjectStatus validate() const
ossimImageSource * theInputConnection
unsigned int ossim_uint32
32 bit normalized floating point
float getH() const
void allocate()
Called on first getTile, will initialize all data needed.
virtual ossimRefPtr< ossimImageData > create(ossimSource *owner, ossimScalarType scalar, ossim_uint32 bands=1) const
ossimScalarType
virtual double getMinPixelValue(ossim_uint32 band=0) const
Returns the min pixel of the band.
virtual ossimScalarType getScalarType() const
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &tileRect, ossim_uint32 resLevel=0)
virtual const void * getBuf() const
ossimRefPtr< ossimImageData > theTile
virtual ossimScalarType getOutputScalarType() const
This will be used to query the output pixel type of the tile source.
#define RTTI_DEF1(cls, name, b1)
Definition: ossimRtti.h:485
float getV() const
unsigned char ossim_uint8
8 bit unsigned iteger
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)
virtual double getMaxPixelValue(ossim_uint32 band=0) const
Returns the max pixel of the band.