OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimHsiToRgbSource.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: ossimHsiToRgbSource.cpp 17206 2010-04-25 23:20:40Z 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  return NULL; // This filter requires an input.
47  }
48 
49  ossimRefPtr<ossimImageData> inputTile =
50  theInputConnection->getTile(tileRect, resLevel);
51  if(!isSourceEnabled())
52  {
53  return inputTile;
54  }
55 
56  if(!theTile.valid())
57  {
58  allocate(); // First time through...
59  }
60 
61  if( !inputTile.valid() ||
62  inputTile->getDataObjectStatus() == OSSIM_NULL ||
63  inputTile->getDataObjectStatus() == OSSIM_EMPTY )
64  {
66  return theBlankTile;
67  }
68 
69  if((inputTile->getNumberOfBands()==3)&&
70  (inputTile->getScalarType()==OSSIM_NORMALIZED_FLOAT)&&
71  (inputTile->getDataObjectStatus()!=OSSIM_NULL))
72  {
73  // Set the origin, resize if needed of the output tile.
74  theTile->setImageRectangle(tileRect);
75 
76  ossim_uint8* outputBands[3];
77  float* inputBands[3];
78  outputBands[0] = static_cast<ossim_uint8*>(theTile->getBuf(0));
79  outputBands[1] = static_cast<ossim_uint8*>(theTile->getBuf(1));
80  outputBands[2] = static_cast<ossim_uint8*>(theTile->getBuf(2));
81  inputBands[0] = static_cast<float*>(inputTile->getBuf(0));
82  inputBands[1] = static_cast<float*>(inputTile->getBuf(1));
83  inputBands[2] = static_cast<float*>(inputTile->getBuf(2));
84 
85  long height = inputTile->getHeight();
86  long width = inputTile->getWidth();
87  long offset = 0;
88  for(long row = 0; row < height; ++row)
89  {
90  for(long col = 0; col < width; ++col)
91  {
92  ossimHsiVector hsi(inputBands[0][offset],
93  inputBands[1][offset],
94  inputBands[2][offset]);
95 
96  ossimRgbVector rgb(hsi);
97 
98 
99  outputBands[0][offset] = rgb.getR();
100  outputBands[1][offset] = rgb.getG();
101  outputBands[2][offset] = rgb.getB();
102 
103  ++offset;
104  }
105  }
106  }
107  else
108  {
109  return inputTile;
110  }
111 
112  theTile->validate();
113 
114  return theTile;
115 }
116 
118 {
120 }
121 
123 {
126  theTile->initialize();
127 }
128 
130 {
131  return OSSIM_UCHAR;
132 }
133 
135 {
136  return 0.0;
137 }
138 
140 {
142 }
143 
145 {
147 }
virtual ossim_uint32 getWidth() const
virtual bool isSourceEnabled() const
Definition: ossimSource.cpp:79
virtual ossim_uint32 getNumberOfBands() const
unsigned char getR() const
virtual void setImageRectangle(const ossimIrect &rect)
virtual double getMaxPixelValue(ossim_uint32 band=0) const
Returns the max pixel of the band.
bool valid() const
Definition: ossimRefPtr.h:75
#define OSSIM_DEFAULT_MAX_PIX_UCHAR
virtual ossimDataObjectStatus getDataObjectStatus() const
virtual ossim_uint32 getHeight() const
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &tileRect, ossim_uint32 resLevel=0)
virtual double getNullPixelValue() const
virtual void initialize()
Initialize the data buffer.
virtual ossimObject * dup() const
static ossimImageDataFactory * instance()
virtual ossimScalarType getOutputScalarType() const
This will be used to query the output pixel type of the tile source.
#define OSSIM_DEFAULT_MIN_PIX_UCHAR
virtual ossimDataObjectStatus validate() const
ossimImageSource * theInputConnection
unsigned int ossim_uint32
32 bit normalized floating point
ossimRefPtr< ossimImageData > theTile
unsigned char getB() const
virtual ossimRefPtr< ossimImageData > create(ossimSource *owner, ossimScalarType scalar, ossim_uint32 bands=1) const
ossimScalarType
unsigned char getG() const
virtual ossimScalarType getScalarType() const
virtual const void * getBuf() const
virtual double getMinPixelValue(ossim_uint32 band=0) const
Returns the min pixel of the band.
#define RTTI_DEF1(cls, name, b1)
Definition: ossimRtti.h:485
ossimRefPtr< ossimImageData > theBlankTile
unsigned char ossim_uint8
8 bit unsigned iteger
void allocate()
Called on first getTile, will initialize all data needed.
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)