OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Public Member Functions | Static Public Attributes | Protected Attributes | Friends | List of all members
ossimHsvVector Class Reference

#include <ossimHsvVector.h>

Public Member Functions

 ossimHsvVector (float h=0, float s=0, float i=0)
 
 ossimHsvVector (const ossimRgbVector &rgb)
 
const ossimHsvVectoroperator= (const ossimRgbVector &rgb)
 
float getH () const
 
float getS () const
 
float getV () const
 
unsigned char getVUnNormalized () const
 
void setH (float H)
 
void setS (float S)
 
void setV (float V)
 
float clamp (float colorValue, float min=0, float max=255) const
 

Static Public Attributes

static const float OSSIM_HSV_UNDEFINED = -1
 

Protected Attributes

float theBuf [3]
 

Friends

ostream & operator<< (ostream &out, const ossimHsvVector &data)
 

Detailed Description

Definition at line 18 of file ossimHsvVector.h.

Constructor & Destructor Documentation

◆ ossimHsvVector() [1/2]

ossimHsvVector::ossimHsvVector ( float  h = 0,
float  s = 0,
float  i = 0 
)
inline

Definition at line 32 of file ossimHsvVector.h.

33  {
34  theBuf[0] = h;
35  theBuf[1] = s;
36  theBuf[2] = i;
37  }

◆ ossimHsvVector() [2/2]

ossimHsvVector::ossimHsvVector ( const ossimRgbVector rgb)

Definition at line 19 of file ossimHsvVector.cpp.

References clamp(), ossimRgbVector::getB(), ossimRgbVector::getG(), ossimRgbVector::getR(), max, min, OSSIM_HSV_UNDEFINED, theBuf, and x.

20 {
21  float r,g,b;
22 
23  r = rgb.getR()/255.0;
24  g = rgb.getG()/255.0;
25  b = rgb.getB()/255.0;
26 
27  // this code was taken from http://www.acm.org/jgt/papers/SmithLyons96/hsv_rgb.html
28  // the input RGB is required to be on [0, 1].
29  // Their S and V are returned on [0, 1] and H is but we will try
30  // to make it return on 0..255 for S and V and see what that looks
31  // like and keep the H on 0..6.
32  // returned on [0, 6]. Exception: H is returned UNDEFINED if S==0.
33 
34  float x, v, f, i;
35 
36  x = min(min(r, g), b);
37  v = max(max(r, g), b);
38  if(v==x)
39  {
40  theBuf[0] = OSSIM_HSV_UNDEFINED, // we really need to mark as undefined
41  theBuf[1] = 0;
42  theBuf[2] = v;
43  }
44  else
45  {
46  f = (r == x) ? g - b : ((g == x) ? b - r : r - g);
47  i = (r == x) ? 3 : ((g == x) ? 5 : 1);
48 
49  theBuf[0] = clamp(i - f /(v - x), 0, 6);
50  theBuf[0]/=6.0;
51  theBuf[1] = clamp((v - x)/v, 0, 1);
52  theBuf[2] = clamp(v, 0, 1);
53  }
54 }
ossim_uint32 x
unsigned char getR() const
float clamp(float colorValue, float min=0, float max=255) const
static const float OSSIM_HSV_UNDEFINED
unsigned char getB() const
unsigned char getG() const
#define max(a, b)
Definition: auxiliary.h:76
#define min(a, b)
Definition: auxiliary.h:75

Member Function Documentation

◆ clamp()

float ossimHsvVector::clamp ( float  colorValue,
float  min = 0,
float  max = 255 
) const
inline

Definition at line 54 of file ossimHsvVector.h.

References max, and min.

Referenced by operator=(), and ossimHsvVector().

55  {
56  colorValue = colorValue > max? max:colorValue;
57  colorValue = colorValue < min? min:colorValue;
58 
59  return colorValue;
60  }
#define max(a, b)
Definition: auxiliary.h:76
#define min(a, b)
Definition: auxiliary.h:75

◆ getH()

float ossimHsvVector::getH ( ) const
inline

◆ getS()

float ossimHsvVector::getS ( ) const
inline

◆ getV()

float ossimHsvVector::getV ( ) const
inline

◆ getVUnNormalized()

unsigned char ossimHsvVector::getVUnNormalized ( ) const
inline

Definition at line 46 of file ossimHsvVector.h.

47  {
48  return static_cast<unsigned char>(theBuf[2]*255);
49  }

◆ operator=()

const ossimHsvVector & ossimHsvVector::operator= ( const ossimRgbVector rgb)

Definition at line 56 of file ossimHsvVector.cpp.

References clamp(), ossimRgbVector::getB(), ossimRgbVector::getG(), ossimRgbVector::getR(), max, min, OSSIM_HSV_UNDEFINED, theBuf, and x.

57 {
58  float r,g,b;
59 
60  r = rgb.getR()/255.0;
61  g = rgb.getG()/255.0;
62  b = rgb.getB()/255.0;
63 
64  // this code was taken from http://www.acm.org/jgt/papers/SmithLyons96/hsv_rgb.html
65  // the input RGB is required to be on [0, 1].
66  // Their S and V are returned on [0, 1] and H is but we will try
67  // to make it return on 0..255 for S and V and see what that looks
68  // like and keep the H on 0..6.
69  // returned on [0, 6]. Exception: H is returned UNDEFINED if S==0.
70 
71  float x, v, f, i;
72 
73  x = min(min(r, g), b);
74  v = max(max(r, g), b);
75  if(v==x)
76  {
77  theBuf[0] = OSSIM_HSV_UNDEFINED, // we really need to mark as undefined
78  theBuf[1] = 0;
79  theBuf[2] = v;
80  }
81  else
82  {
83  f = (r == x) ? g - b : ((g == x) ? b - r : r - g);
84  i = (r == x) ? 3 : ((g == x) ? 5 : 1);
85 
86  theBuf[0] = clamp(i - f /(v - x), 0, 6);
87  theBuf[0]/=6.0;
88  theBuf[1] = clamp((v - x)/v, 0, 1);
89  theBuf[2] = clamp(v, 0, 1);
90  }
91 
92  return *this;
93 }
ossim_uint32 x
unsigned char getR() const
float clamp(float colorValue, float min=0, float max=255) const
static const float OSSIM_HSV_UNDEFINED
unsigned char getB() const
unsigned char getG() const
#define max(a, b)
Definition: auxiliary.h:76
#define min(a, b)
Definition: auxiliary.h:75

◆ setH()

void ossimHsvVector::setH ( float  H)
inline

Definition at line 50 of file ossimHsvVector.h.

50 { theBuf[0] = H; }

◆ setS()

void ossimHsvVector::setS ( float  S)
inline

Definition at line 51 of file ossimHsvVector.h.

51 { theBuf[1] = S; }

◆ setV()

void ossimHsvVector::setV ( float  V)
inline

Definition at line 52 of file ossimHsvVector.h.

Referenced by ossimIntensityAdjustmentFilter::getTile().

52 { theBuf[2] = V; }

Friends And Related Function Documentation

◆ operator<<

ostream& operator<< ( ostream &  out,
const ossimHsvVector data 
)
friend

Definition at line 21 of file ossimHsvVector.h.

22  {
23  out << "<" << data.theBuf[0] << ", "
24  << data.theBuf[1] << ", "
25  << data.theBuf[2] << ">";
26 
27  return out;
28  }

Member Data Documentation

◆ OSSIM_HSV_UNDEFINED

const float ossimHsvVector::OSSIM_HSV_UNDEFINED = -1
static

◆ theBuf

float ossimHsvVector::theBuf[3]
protected

buf[0] = hue [0..1] buf[1] = saturation [0..1] buf[2] = value [0..1]

Definition at line 69 of file ossimHsvVector.h.

Referenced by operator=(), and ossimHsvVector().


The documentation for this class was generated from the following files: