PICCANTE  0.4
The hottest HDR imaging library!
color_conv_xyz_to_hdrlab.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_XYZ_TO_HDRLAB_HPP
19 #define PIC_COLORS_COLOR_CONV_XYZ_TO_HDRLAB_HPP
20 
21 #include <math.h>
22 
23 #include "../colors/color_conv.hpp"
24 
25 namespace pic {
26 
31 {
32 protected:
33 
34  float Yabs, Ys, two_e, epsilon;
35  float whitePoint[3];
36 
37 public:
38 
43  {
44  linear = false;
45 
46  whitePoint[0] = 1.0f;
47  whitePoint[1] = 1.0f;
48  whitePoint[2] = 1.0f;
49 
50  Ys = 0.5f;
51  Yabs = 1.0f;
52 
53  two_e = powf(2.0f, computeEpsilon(Ys, Yabs));
54  }
55 
62  {
63  this->Yabs = Yabs;
64  this->whitePoint[0] = whitePoint[0];
65  this->whitePoint[1] = whitePoint[1];
66  this->whitePoint[2] = whitePoint[2];
67 
68  Ys = 0.5f;
69 
71  two_e = powf(2.0f, epsilon);
72  }
73 
79  void direct(float *colIn, float *colOut)
80  {
81  //L_hdr
82  colOut[0] = f(colIn[1] / whitePoint[1]);
83 
84  //a_hdr
85  colOut[1] = 5.0f * (f(colIn[0] / whitePoint[0]) - f(colIn[1] / whitePoint[1]));
86 
87  //b_hdr
88  colOut[2] = 2.0f * (f(colIn[1] / whitePoint[1]) - f(colIn[2] / whitePoint[2]));
89  }
90 
96  void inverse(float *colIn, float *colOut)
97  {
98  colOut[1] = whitePoint[1] * f_inv( colIn[0] );
99  colOut[0] = whitePoint[0] * f_inv( colIn[0] + colIn[1]/5.0f );
100  colOut[2] = whitePoint[2] * f_inv( colIn[0] - colIn[2]/2.0f );
101  }
102 
108  float *WhitePointD65(float *whitePoint)
109  {
110  if(whitePoint == NULL) {
111  whitePoint = new float[3];
112  }
113 
114  whitePoint[0] = 95.047f;
115  whitePoint[1] = 100.0f;
116  whitePoint[2] = 108.883f;
117 
118  return whitePoint;
119  }
120 
126  float f(float omega)
127  {
128  float omega_e = powf(omega, epsilon);
129  return (247.0f * omega_e) / (omega_e + two_e) + 0.02f;
130  }
131 
137  float f_inv(float x)
138  {
139  float omega_e = ( (x - 0.02f) * two_e ) / (247.0f + 0.02f - x);
140  return powf(omega_e, 1.0f / epsilon);
141  }
142 
149  static float computeEpsilon(float Ys, float Yabs)
150  {
151  if(Yabs <= 0.0f) {
152  Yabs = 1.0f;
153  }
154 
155  if(Ys < 0.0f || Ys > 1.0f) {
156  Ys = 0.5f;
157  }
158 
159  float sf = 1.25f - 0.25f * (Ys / 0.184f);
160 
161  float lf = logf(318.0f) / logf(Yabs);
162 
163  return 0.58f / (sf * lf);
164  }
165 };
166 
167 } // end namespace pic
168 
169 #endif /* PIC_COLORS_COLOR_SPACE_HDRLAB_HPP */
170 
float Ys
Definition: color_conv_xyz_to_hdrlab.hpp:34
ColorConvXYZtoHDRLAB()
ColorConvXYZtoHDRLAB.
Definition: color_conv_xyz_to_hdrlab.hpp:42
void inverse(float *colIn, float *colOut)
inverse from HDR-CIELAB to XYZ
Definition: color_conv_xyz_to_hdrlab.hpp:96
float * WhitePointD65(float *whitePoint)
WhitePointD65.
Definition: color_conv_xyz_to_hdrlab.hpp:108
ColorConvXYZtoHDRLAB(float Yabs, float *whitePoint)
ColorConvXYZtoHDRLAB.
Definition: color_conv_xyz_to_hdrlab.hpp:61
bool linear
Definition: display.hpp:30
static float computeEpsilon(float Ys, float Yabs)
computeEpsilon
Definition: color_conv_xyz_to_hdrlab.hpp:149
float f(float omega)
f
Definition: color_conv_xyz_to_hdrlab.hpp:126
float f_inv(float x)
f_inv
Definition: color_conv_xyz_to_hdrlab.hpp:137
The ColorConvXYZtoHDRLAB class.
Definition: color_conv_xyz_to_hdrlab.hpp:30
float epsilon
Definition: color_conv_xyz_to_hdrlab.hpp:34
float two_e
Definition: color_conv_xyz_to_hdrlab.hpp:34
void direct(float *colIn, float *colOut)
direct from XYZ to HDR-CIELAB
Definition: color_conv_xyz_to_hdrlab.hpp:79
Definition: bilateral_separation.hpp:25
The ColorConv class.
Definition: color_conv.hpp:26
float Yabs
Definition: color_conv_xyz_to_hdrlab.hpp:34
float whitePoint[3]
Definition: color_conv_xyz_to_hdrlab.hpp:35