1 //******************************************************************* 2 // 3 // License: See top level LICENSE.txt file. 4 // 5 // Author: Garrett Potts 6 // Description: 7 // 8 //************************************************************************* 9 // $Id: ossimHsvVector.h 14789 2009-06-29 16:48:14Z dburken $ 10 #ifndef ossimHsvVector_HEADER 11 #define ossimHsvVector_HEADER 12 #include <iostream> 13 #include <ossim/base/ossimConstants.h> 14 15 class ossimRgbVector; 16 17 class OSSIMDLLEXPORT ossimHsvVector 18 { 19 public: 20 friend std::ostream& operator << (std::ostream& out, const ossimHsvVector & data) 21 { 22 out << "<" << data.theBuf[0] << ", " 23 << data.theBuf[1] << ", " 24 << data.theBuf[2] << ">"; 25 26 return out; 27 } 28 // assumed normalized floats 29 // 30 // 31 ossimHsvVector(float h=0, float s=0, float i=0) 32 { 33 theBuf[0] = h; 34 theBuf[1] = s; 35 theBuf[2] = i; 36 } 37 ossimHsvVector(const ossimRgbVector& rgb); 38 39 const ossimHsvVector& operator =(const ossimRgbVector& rgb); 40 41 float getH()const { return theBuf[0]; } 42 float getS()const { return theBuf[1]; } 43 float getV()const { return theBuf[2]; } 44 45 unsigned char getVUnNormalized()const getH()46 { 47 return static_cast<unsigned char>(theBuf[2]*255); 48 } setH(ossim_float64 H)49 void setH(float H) { theBuf[0] = H; } setS(ossim_float64 S)50 void setS(float S) { theBuf[1] = S; } setI(ossim_float64 I)51 void setV(float V) { theBuf[2] = V; } 52 53 float clamp(float colorValue, float min=0, float max=255)const 54 { 55 colorValue = colorValue > max? max:colorValue; 56 colorValue = colorValue < min? min:colorValue; 57 58 return colorValue; 59 } 60 61 static const float OSSIM_HSV_UNDEFINED; 62 protected: 63 /*! 64 * buf[0] = hue [0..1] 65 * buf[1] = saturation [0..1] 66 * buf[2] = value [0..1] 67 */ 68 float theBuf[3]; 69 70 }; 71 72 #endif 73