PICCANTE  0.4
The hottest HDR imaging library!
color_conv.hpp
Go to the documentation of this file.
1 /*
2 
3 PICCANTE
4 The hottest HDR imaging library!
5 http://vcg.isti.cnr.it/piccante
6 
7 Copyright (C) 2014
8 Visual Computing Laboratory - ISTI CNR
9 http://vcg.isti.cnr.it
10 First author: Francesco Banterle
11 
12 This Source Code Form is subject to the terms of the Mozilla Public
13 License, v. 2.0. If a copy of the MPL was not distributed with this
14 file, You can obtain one at http://mozilla.org/MPL/2.0/.
15 
16 */
17 
18 #ifndef PIC_COLORS_COLOR_CONV_HPP
19 #define PIC_COLORS_COLOR_CONV_HPP
20 
21 namespace pic {
22 
26 class ColorConv
27 {
28 protected:
29  bool linear;
30 
31  float mtx[9], mtx_inv[9];
32 
33 public:
34 
39  {
40  linear = true;
41  }
42 
48  virtual void direct(float *colIn, float *colOut)
49  {
50  apply(mtx, colIn, colOut);
51  }
52 
58  virtual void inverse(float *colIn, float *colOut)
59  {
60  apply(mtx_inv, colIn, colOut);
61  }
62 
69  void transform(float *colIn, float *colOut, bool bDirection) {
70  if(bDirection) {
71  direct(colIn, colOut);
72  } else {
73  inverse(colIn, colOut);
74  }
75  }
76 
83  static void apply(const float *mtx, float *colIn, float *colOut)
84  {
85  //working copy
86  float tmp[3];
87  tmp[0] = colIn[0];
88  tmp[1] = colIn[1];
89  tmp[2] = colIn[2];
90 
91  //conversion
92  colOut[0] = tmp[0] * mtx[0] + tmp[1] * mtx[1] + tmp[2] * mtx[2];
93  colOut[1] = tmp[0] * mtx[3] + tmp[1] * mtx[4] + tmp[2] * mtx[5];
94  colOut[2] = tmp[0] * mtx[6] + tmp[1] * mtx[7] + tmp[2] * mtx[8];
95  }
96 
103  static void apply_s(const float *mtx, float *colIn, float *colOut)
104  {
105  if(mtx == NULL || colIn == NULL || colOut == NULL) {
106  printf("Error in ColorSpaceLinear::ConvertLinearSpace_s");
107  return;
108  }
109 
110  apply(mtx, colIn, colOut);
111  }
112 };
113 
114 } // end namespace pic
115 
116 #endif /* PIC_COLORS_COLOR_CONV_HPP */
117 
virtual void inverse(float *colIn, float *colOut)
inverse is the inverse of direct.
Definition: color_conv.hpp:58
float mtx_inv[9]
Definition: color_conv.hpp:31
static void apply(const float *mtx, float *colIn, float *colOut)
apply
Definition: color_conv.hpp:83
void transform(float *colIn, float *colOut, bool bDirection)
transform
Definition: color_conv.hpp:69
Definition: bilateral_separation.hpp:25
virtual void direct(float *colIn, float *colOut)
direct converts from a color space to another one.
Definition: color_conv.hpp:48
float mtx[9]
Definition: color_conv.hpp:31
bool linear
Definition: color_conv.hpp:29
The ColorConv class.
Definition: color_conv.hpp:26
ColorConv()
ColorConv.
Definition: color_conv.hpp:38
static void apply_s(const float *mtx, float *colIn, float *colOut)
apply_s a safe apply
Definition: color_conv.hpp:103