PICCANTE  0.4
The hottest HDR imaging library!
color_conv_xyz_to_cielab.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_CIELAB_HPP
19 #define PIC_COLORS_COLOR_CONV_XYZ_TO_CIELAB_HPP
20 
21 #include "../colors/color_conv.hpp"
22 
23 namespace pic {
24 
25 const float C_SIX_OVER_TWENTY_NINE = 0.20689655172413793103448275862069f;
26 const float C_SIX_OVER_TWENTY_NINE_CUBIC = 0.00885645167903563081717167575546f;
27 // (29/6)^2 / 3
28 const float C_CIELAB_C1 = 7.787037037037037037037037037037f;
29 // (6/29)^2 * 3
30 const float C_CIELAB_C1_INV = 0.12841854934601664684898929845422f;
31 const float C_FOUR_OVER_TWENTY_NINE = 0.13793103448275862068965517241379f;
32 
37 {
38 protected:
39 
40  float white_point[3];
41 
42 public:
43 
48  {
49  linear = false;
50  white_point[0] = 1.0f;
51  white_point[1] = 1.0f;
52  white_point[2] = 1.0f;
53  }
54 
60  void direct(float *colIn, float *colOut)
61  {
62  float fY_Yn = f(colIn[1] / white_point[1]);
63 
64  colOut[0] = 116.0f * fY_Yn - 16.0f;
65  colOut[1] = 500.0f * (f(colIn[0] / white_point[0]) - fY_Yn);
66  colOut[2] = 200.0f * (fY_Yn - f(colIn[2] / white_point[2]));
67  }
68 
74  void inverse(float *colIn, float *colOut)
75  {
76  float tmp = (colIn[0] + 16.0f) / 116.0f;
77 
78  colOut[1] = white_point[1] * f_inv(tmp);
79  colOut[0] = white_point[0] * f_inv(tmp + colIn[1] / 500.0f);
80  colOut[2] = white_point[2] * f_inv(tmp - colIn[2] / 200.0f);
81  }
82 
88  static float f(float t)
89  {
91  return powf(t, 1.0f / 3.0f);
92  } else {
93  return C_CIELAB_C1 * t +
95  }
96  }
97 
103  static float f_inv(float t)
104  {
105  if(t > C_SIX_OVER_TWENTY_NINE ) {
106  return powf(t, 3.0f);
107  } else {
109  }
110  }
111 };
112 
113 } // end namespace pic
114 
115 #endif /* PIC_COLORS_COLOR_SPACE_CIELAB_HPP */
116 
const float C_CIELAB_C1_INV
Definition: color_conv_xyz_to_cielab.hpp:30
ColorConvXYZtoCIELAB()
ColorConvXYZtoCIELAB.
Definition: color_conv_xyz_to_cielab.hpp:47
The ColorConvXYZtoCIELAB class.
Definition: color_conv_xyz_to_cielab.hpp:36
static float f_inv(float t)
f_inv
Definition: color_conv_xyz_to_cielab.hpp:103
bool linear
Definition: display.hpp:30
void direct(float *colIn, float *colOut)
direct
Definition: color_conv_xyz_to_cielab.hpp:60
float white_point[3]
Definition: color_conv_xyz_to_cielab.hpp:40
void inverse(float *colIn, float *colOut)
inverse
Definition: color_conv_xyz_to_cielab.hpp:74
static float f(float t)
f
Definition: color_conv_xyz_to_cielab.hpp:88
const float C_SIX_OVER_TWENTY_NINE
Definition: color_conv_xyz_to_cielab.hpp:25
Definition: bilateral_separation.hpp:25
const float C_SIX_OVER_TWENTY_NINE_CUBIC
Definition: color_conv_xyz_to_cielab.hpp:26
const float C_FOUR_OVER_TWENTY_NINE
Definition: color_conv_xyz_to_cielab.hpp:31
The ColorConv class.
Definition: color_conv.hpp:26
const float C_CIELAB_C1
Definition: color_conv_xyz_to_cielab.hpp:28