OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimRgbToHsiSource.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: ossimRgbToHsiSource.cpp 17206 2010-04-25 23:20:40Z dburken $
12 
16 #include <ossim/base/ossimCommon.h>
20 
22 
25  theBlankTile(NULL),
26  theTile(NULL)
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 
51  resLevel);
52  if(!isSourceEnabled() || !inputTile.valid())
53  {
54  return inputTile;
55  }
56 
57  if(!theTile)
58  {
59  allocate(); // First time through...
60  }
61 
62  if (!theTile.valid())
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  ossimHsiVector hsi(rgb);
102 
103 
104  outputBands[0][offset] = hsi.getH();
105  outputBands[1][offset] = hsi.getS();
106  outputBands[2][offset] = hsi.getI();
107 
108  ++offset;
109  }
110  }
111  }
112  else // Input tile not of correct type to process...
113  {
114  return inputTile;
115  }
116 
117  theTile->validate();
118  return theTile;
119 }
120 
122 {
123  return OSSIM_NORMALIZED_FLOAT;
124 }
125 
127 {
128  // Base class will recapture "theInputConnection".
130 }
131 
133 {
134  theBlankTile = NULL;
135  theTile = NULL;
136 
137  if(!theInputConnection) return;
138 
141  theTile->initialize();
142 }
143 
145 {
146  return 3;
147 }
148 
150 {
151  return ossim::nan();
152 }
153 
155 {
156  return 0.0;
157 }
158 
160 {
161  return 1.0;
162 }
ossimRefPtr< ossimImageData > theTile
virtual ossim_uint32 getWidth() const
virtual bool isSourceEnabled() const
Definition: ossimSource.cpp:79
virtual ossim_uint32 getNumberOfBands() const
ossim_float64 getS() const
virtual void setImageRectangle(const ossimIrect &rect)
ossim_float64 getH() const
virtual ossim_uint32 getNumberOfOutputBands() const
Returns the number of bands in a tile returned from this TileSource.
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &tileRect, ossim_uint32 resLevel=0)
bool valid() const
Definition: ossimRefPtr.h:75
ossimRefPtr< ossimImageData > theBlankTile
double nan()
Method to return ieee floating point double precision NAN.
Definition: ossimCommon.h:135
void allocate()
Called on first getTile, will initialize all data needed.
virtual ossimDataObjectStatus getDataObjectStatus() const
virtual ossim_uint32 getHeight() const
virtual double getMinPixelValue(ossim_uint32 band=0) const
Returns the min pixel of the band.
virtual void initialize()
Initialize the data buffer.
virtual ossimObject * dup() const
static ossimImageDataFactory * instance()
virtual ossimDataObjectStatus validate() const
virtual double getNullPixelValue() const
ossimImageSource * theInputConnection
unsigned int ossim_uint32
ossim_float64 getI() const
32 bit normalized floating point
virtual ossimRefPtr< ossimImageData > create(ossimSource *owner, ossimScalarType scalar, ossim_uint32 bands=1) const
virtual ossimScalarType getOutputScalarType() const
This will be used to query the output pixel type of the tile source.
ossimScalarType
virtual ossimScalarType getScalarType() const
virtual const void * getBuf() const
#define RTTI_DEF1(cls, name, b1)
Definition: ossimRtti.h:485
virtual double getMaxPixelValue(ossim_uint32 band=0) const
Returns the max pixel of the band.
unsigned char ossim_uint8
8 bit unsigned iteger
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)