OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimNormRgbVector.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2005 Garrett Potts
3 //
4 // License: LGPL
5 // Author: Garrett Potts
6 // Description:
7 //
8 //*************************************************************************
9 // $Id: ossimNormRgbVector.cpp 9094 2006-06-13 19:12:40Z dburken $
16 #include <ossim/base/ossimCommon.h>
17 #include <math.h>
18 
20 {
21  theBuf[0] = rgb.getR()/255.0;
22  theBuf[1] = rgb.getG()/255.0;
23  theBuf[2] = rgb.getB()/255.0;
24 }
25 
27 {
28  (*this) = YCbCr;
29 
30 }
31 
33 {
34  (*this)=hsi;
35 }
36 
38 {
39  (*this) = hsv;
40 }
41 
43 {
44  theBuf[0] = 255 - cmy.getC();
45  theBuf[1] = 255 - cmy.getM();
46  theBuf[2] = 255 - cmy.getY();
47 }
48 
50 {
51  // H is given on [0, 6] or UNDEFINED. S and V are given on [0, 1].
52  // RGB are each returned on [0, 1].
53  float h = hsv.getH(), // unnormalize it
54  s = hsv.getS(),
55  v = hsv.getV();
56  float m, n, f;
57  int i;
59  {
60  theBuf[0] = clamp(v);
61  theBuf[1] = clamp(v);
62  theBuf[2] = clamp(v);
63  }
64  else
65  {
66  h*=6.0; // unnormalize h
67  i = (int)floor(h);
68  f = h - i;
69  if(!(i & 1)) f = 1 - f; // if i is even
70  m = v * (1 - s);
71  n = v * (1 - s * f);
72  switch (i)
73  {
74  case 6:
75  case 0:
76  {
77  theBuf[0] = clamp(v);
78  theBuf[1] = clamp(n);
79  theBuf[2] = clamp(m);
80  break;
81  }
82  case 1:
83  {
84  theBuf[0] = clamp(n);
85  theBuf[1] = clamp(v);
86  theBuf[2] = clamp(m);
87  break;
88  }
89  case 2:
90  {
91  theBuf[0] = clamp(m);
92  theBuf[1] = clamp(v);
93  theBuf[2] = clamp(n);
94  break;
95  }
96  case 3:
97  {
98  theBuf[0] = clamp(m);
99  theBuf[1] = clamp(n);
100  theBuf[2] = clamp(v);
101  break;
102  }
103  case 4:
104  {
105  theBuf[0] = clamp(n);
106  theBuf[1] = clamp(m);
107  theBuf[2] = clamp(v);
108  break;
109  }
110  case 5:
111  {
112  theBuf[0] = clamp(v);
113  theBuf[1] = clamp(m);
114  theBuf[2] = clamp(n);
115  break;
116  }
117  }
118  }
119  return *this;
120 }
121 
123 {
124  theBuf[0] = clamp((YCbCr.getY() +
125  1.402 * (YCbCr.getCr()-128.0))/255.0);
126  theBuf[1] = clamp((YCbCr.getY() -
127  0.34414 *(YCbCr.getCb()-128.0) -
128  0.71414*(YCbCr.getCr()-128.0))/255.0);
129  theBuf[2] = clamp((YCbCr.getY() +
130  1.772 * ( YCbCr.getCb()-128.0))/255.0);
131 
132  return *this;
133 }
134 
136 {
137  ossim_float32 h = hsi.getH();
138  ossim_float32 s = hsi.getS();
139  ossim_float32 i = hsi.getI();
140 
141  ossim_float32 r=0;
142  ossim_float32 g=0;
143  ossim_float32 b=0;
144 
145  if(h <= 120.0)
146  {
147  b = i*(1-s);
148 
149  r = i*(1 + s*cos(RAD_PER_DEG*h)/cos((60-h)*RAD_PER_DEG));
150  g = 3*i - (r+b);
151  }
152  else if(h <= 240.0)
153  {
154  h-=120;
155 
156  r = i*(1-s);
157  g = i*(1 + s*cos(RAD_PER_DEG*h)/cos((60-h)*RAD_PER_DEG));
158  b = 3*i - (r+g);
159  }
160  else if(h <= 360.0)
161  {
162  h-=240;
163 
164  g = i*(1-s);
165  b = i*(1 + s*cos(RAD_PER_DEG*h)/cos((60-h)*RAD_PER_DEG));
166  r = 3*i - (g+b);
167  }
168 
169  theBuf[0] = clamp(r);
170  theBuf[1] = clamp(g);
171  theBuf[2] = clamp(b);
172 
173  return *this;
174 }
175 
177 {
178  theBuf[0] = (255 - cmy.getC())/255.0;
179  theBuf[1] = (255 - cmy.getM())/255.0;
180  theBuf[2] = (255 - cmy.getY())/255.0;
181 
182  return *this;
183 }
ossimNormRgbVector(ossim_float64 r=0, ossim_float64 g=0, ossim_float64 b=0)
unsigned char getR() const
ossim_float64 getS() const
ossim_float64 getH() const
static const float OSSIM_HSV_UNDEFINED
float ossim_float32
float getS() const
unsigned char getY() const
ossim_uint8 getC() const
static ossim_float64 clamp(ossim_float64 colorValue, ossim_float64 min=0.0, ossim_float64 max=1.0)
os2<< "> n<< " > nendobj n
ossim_float64 getI() const
float getH() const
unsigned char getB() const
ossim_uint8 getM() const
const ossimNormRgbVector & operator=(const ossimJpegYCbCrVector &data)
unsigned char getG() const
unsigned char getCr() const
ossim_float64 theBuf[3]
float getV() const
unsigned char getCb() const
#define RAD_PER_DEG
ossim_uint8 getY() const