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_GL_COLORS_COLOR_CONV_XYZ_TO_CIE_LAB_HPP
19 #define PIC_GL_COLORS_COLOR_CONV_XYZ_TO_CIE_LAB_HPP
20 
21 #include "../../gl/colors/color_conv.hpp"
22 
23 namespace pic {
24 
29 {
30 protected:
31  float white_point[3];
32 
33 public:
34 
39  {
40  white_point[0] = 1.0f;
41  white_point[1] = 1.0f;
42  white_point[2] = 1.0f;
43  }
44 
49  std::string getDirectFunction()
50  {
51  std::string fragment_source = MAKE_STRING
52  (
53  uniform sampler2D u_tex; \n
54  uniform vec3 white_point; \n
55  out vec4 f_color; \n
56  \n
57 
58  const float C_SIX_OVER_TWENTY_NINE_CUBIC = 0.00885645167903563081717167575546;
59  const float C_FOUR_OVER_TWENTY_NINE = 0.13793103448275862068965517241379;
60  const float C_CIELAB_C1 = 7.787037037037037037037037037037;
61 
62  float f(float t) {
64  return pow(t, 1.0 / 3.0);
65  } else {
66  return C_CIELAB_C1 * t +
68  }
69  }
70 
71  void main(void) {
72  \n
73  ivec2 coords = ivec2(gl_FragCoord.xy); \n
74  vec3 colIn = texelFetch(u_tex, coords, 0).xyz; \n
75 
76  vec3 colOut;
77  float fY_Yn = f(colIn[1] / white_point[1]);
78 
79  colOut[0] = 116.0 * fY_Yn - 16.0;
80  colOut[1] = 500.0 * (f(colIn[0] / white_point[0]) - fY_Yn);
81  colOut[2] = 200.0 * (fY_Yn - f(colIn[2] / white_point[2]));
82 
83  f_color = vec4(colOut, 1.0); \n
84  \n
85  }
86  );
87  return fragment_source;
88  }
89 
94  std::string getInverseFunction()
95  {
96  std::string fragment_source = MAKE_STRING
97  (
98  uniform sampler2D u_tex; \n
99  uniform vec3 white_point; \n
100  out vec4 f_color; \n
101  const float C_CIELAB_C1_INV = 0.12841854934601664684898929845422; \n
102  const float C_FOUR_OVER_TWENTY_NINE = 0.13793103448275862068965517241379; \n
103  const float C_SIX_OVER_TWENTY_NINE = 0.20689655172413793103448275862069; \n
104  \n
105  \n
106  float f_inv(float t) {
107  if(t > C_SIX_OVER_TWENTY_NINE ){
108  return pow(t, 3.0);
109  } else {
111  }
112  }
113 
114  void main(void) {
115  \n
116  ivec2 coords = ivec2(gl_FragCoord.xy); \n
117  vec3 colIn = texelFetch(u_tex, coords, 0).xyz; \n
118  vec3 colOut;
119 
120  float tmp = (colIn[0] + 16.0f) / 116.0;
121 
122  colOut[1] = white_point[1] * f_inv(tmp);
123  colOut[0] = white_point[0] * f_inv(tmp + colIn[1] / 500.0);
124  colOut[2] = white_point[2] * f_inv(tmp - colIn[2] / 200.0);
125 
126  f_color = vec4(colOut, 1.0); \n
127  \n
128  }
129  );
130  return fragment_source;
131  }
132 
136  void setUniforms()
137  {
138  if(direct) {
139  techniques[0].bind();
140  techniques[0].setUniform3fv("white_point", white_point);
141  techniques[0].unbind();
142  } else {
143  techniques[1].bind();
144  techniques[1].setUniform3fv("white_point", white_point);
145  techniques[1].unbind();
146  }
147  }
148 };
149 
150 } // end namespace pic
151 
152 #endif /* PIC_GL_COLORS_COLOR_CONV_XYZ_TO_CIE_LAB_HPP */
153 
void setUniforms()
setUniforms
Definition: color_conv_xyz_to_cielab.hpp:136
const float C_CIELAB_C1_INV
Definition: color_conv_xyz_to_cielab.hpp:30
std::string getInverseFunction()
getInverseFunction
Definition: color_conv_xyz_to_cielab.hpp:94
void bind()
bind
Definition: display.hpp:189
#define MAKE_STRING(input_string)
std::string getDirectFunction()
getDirectFunction
Definition: color_conv_xyz_to_cielab.hpp:49
The ColorConvGLXYZtoCIELAB class.
Definition: color_conv_xyz_to_cielab.hpp:28
TechniqueGL techniques[2]
Definition: display.hpp:34
The ColorConvGL class.
Definition: color_conv.hpp:30
float white_point[3]
Definition: color_conv_xyz_to_cielab.hpp:31
const float C_SIX_OVER_TWENTY_NINE
Definition: color_conv_xyz_to_cielab.hpp:25
int direct
Definition: display.hpp:33
void unbind()
unbind
Definition: display.hpp:197
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
void setUniform3fv(const char *name_uniform, const float *value)
setUniform3
Definition: display.hpp:331
const float C_CIELAB_C1
Definition: color_conv_xyz_to_cielab.hpp:28
ColorConvGLXYZtoCIELAB(bool direct=true)
ColorConvGLXYZtoCIELAB.
Definition: color_conv_xyz_to_cielab.hpp:38