OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimRgbVector.h
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // Author: Garrett Potts
6 // Description:
7 //
8 //*************************************************************************
9 // $Id: ossimRgbVector.h 23064 2015-01-07 03:20:21Z okramer $
10 #ifndef ossimRgbVector_HEADER
11 #define ossimRgbVector_HEADER
12 #include <iostream>
13 using namespace std;
15 
17 class ossimHsiVector;
18 class ossimHsvVector;
19 class ossimCmyVector;
20 
22 {
23 public:
24  friend ostream& operator <<(ostream& out, const ossimRgbVector& data)
25  {
26  out << "<" << (long)data.theBuf[0] << ", "
27  << (long)data.theBuf[1] << ", "
28  << (long)data.theBuf[2] << ">";
29 
30  return out;
31  }
32  ossimRgbVector(unsigned char r=0, unsigned char g=0, unsigned char b=0)
33  {
34  theBuf[0] = r;
35  theBuf[1] = g;
36  theBuf[2] = b;
37  }
38  ossimRgbVector(const ossimRgbVector& copy_this)
39  {
40  theBuf[0] = copy_this.theBuf[0];
41  theBuf[1] = copy_this.theBuf[1];
42  theBuf[2] = copy_this.theBuf[2];
43  }
44  ossimRgbVector(unsigned char grey)
45  {
46  theBuf[0] = grey;
47  theBuf[1] = grey;
48  theBuf[2] = grey;
49  }
50  ossimRgbVector(unsigned char colorData[3])
51  {
52  theBuf[0] = colorData[0];
53  theBuf[1] = colorData[1];
54  theBuf[2] = colorData[2];
55  }
56 
58  ossimRgbVector(const ossimHsiVector& hsi);
59  ossimRgbVector(const ossimHsvVector& hsv);
60  ossimRgbVector(const ossimCmyVector& cmy);
61 
63  {
64  return ossimRgbVector((unsigned char)clamp((long)theBuf[0] - (long)rgb.theBuf[0]),
65  (unsigned char)clamp((long)theBuf[1] - (long)rgb.theBuf[1]),
66  (unsigned char)clamp((long)theBuf[2] - (long)rgb.theBuf[2]));
67  }
68 
70  {
71  return ossimRgbVector((unsigned char)clamp((long)theBuf[0] + (long)rgb.theBuf[0]),
72  (unsigned char)clamp((long)theBuf[1] + (long)rgb.theBuf[1]),
73  (unsigned char)clamp((long)theBuf[2] + (long)rgb.theBuf[2]));
74  }
75  ossimRgbVector operator *(double t)const
76  {
77  return ossimRgbVector((unsigned char)clamp((long)(theBuf[0]*t)),
78  (unsigned char)clamp((long)(theBuf[1]*t)),
79  (unsigned char)clamp((long)(theBuf[2]*t)));
80  }
81  const ossimRgbVector& operator =(const ossimJpegYCbCrVector& data);
82  const ossimRgbVector& operator =(const ossimHsiVector& hsi);
83  const ossimRgbVector& operator =(const ossimHsvVector& hsv);
84  const ossimRgbVector& operator =(const ossimCmyVector& cmy);
85  bool operator ==(const ossimRgbVector& rgb)
86  {
87  return ( (rgb.theBuf[0] == theBuf[0])&&
88  (rgb.theBuf[1] == theBuf[1])&&
89  (rgb.theBuf[2] == theBuf[2]));
90  }
91  bool operator !=(const ossimRgbVector& rgb)
92  {
93  return ( (rgb.theBuf[0] != theBuf[0])||
94  (rgb.theBuf[1] != theBuf[1])||
95  (rgb.theBuf[2] != theBuf[2]));
96  }
97  static long clamp(long colorValue, unsigned char min=0, unsigned char max=255)
98  {
99  colorValue = colorValue > (long)max? (long)max:colorValue;
100  colorValue = colorValue < (long)min? (long)min:colorValue;
101 
102  return colorValue;
103  }
104  unsigned char getR() const { return theBuf[0]; }
105  unsigned char getG()const { return theBuf[1]; }
106  unsigned char getB()const { return theBuf[2]; }
107  void setR(unsigned char R) { theBuf[0] = R; }
108  void setG(unsigned char G) { theBuf[1] = G; }
109  void setB(unsigned char B) { theBuf[2] = B; }
110 
111 protected:
112  unsigned char theBuf[3];
113 };
114 
115 #endif
ossimRgbVector(const ossimRgbVector &copy_this)
unsigned char theBuf[3]
ossimRationalNumber operator-(ossim_int32 i, ossimRationalNumber &r)
unsigned char getR() const
#define OSSIMDLLEXPORT
T clamp(T x, T a, T b)
Definition: ossimCommon.h:168
bool operator!=(const ossimRefPtr< _Tp1 > &__a, const ossimRefPtr< _Tp2 > &__b) noexcept
Definition: ossimRefPtr.h:111
static long clamp(long colorValue, unsigned char min=0, unsigned char max=255)
void setR(unsigned char R)
ossimRgbVector(unsigned char r=0, unsigned char g=0, unsigned char b=0)
ossimRationalNumber operator*(ossim_int32 i, ossimRationalNumber &r)
void setB(unsigned char B)
ostream & operator<<(ostream &out, const ossimAxes &axes)
Definition: ossimAxes.h:88
unsigned char getB() const
ossimRgbVector(unsigned char colorData[3])
bool operator==(const ossimRefPtr< _Tp1 > &__a, const ossimRefPtr< _Tp2 > &__b) noexcept
Definition: ossimRefPtr.h:101
void setG(unsigned char G)
unsigned char getG() const
#define max(a, b)
Definition: auxiliary.h:76
ossimRgbVector(unsigned char grey)
ossimRationalNumber operator+(ossim_int32 i, ossimRationalNumber &r)
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
#define min(a, b)
Definition: auxiliary.h:75