PICCANTE  0.4
The hottest HDR imaging library!
color_conv_rgb_to_hsl.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_RGB_TO_HSL_HPP
19 #define PIC_GL_COLORS_COLOR_CONV_RGB_TO_HSL_HPP
20 
21 #include "../../gl/colors/color_conv.hpp"
22 
23 namespace pic {
24 
29 {
30 public:
31 
36  {
37  }
38 
43  static std::string getDirect()
44  {
45  std::string fun = MAKE_STRING(
46  const vec3 LUM_XYZ = vec3(0.213, 0.715, 0.072);
47  const vec3 ALPHA_VAL = vec3(0.0, 0.866, -0.866);
48  const vec3 BETA_VAL = vec3(1.0, -0.5, -0.5);
49 
50  vec3 RGB2HSL(vec3 col) {
51  vec3 ret;
52 
53  //Intensity
54  ret.y = dot(col, LUM_XYZ);
55 
56  //alpha beta
57  float alpha = dot(col, BETA_VAL);
58  float beta = dot(col, ALPHA_VAL);
59 
60  //Hue
61  if(alpha == 0.0 && beta == 0.0) {
62  ret.x = 0.0;
63  ret.z = 0.0;
64  } else {
65  ret.x = atan(alpha, beta); //atan2(x,y) == atan(y,x)
66  ret.z = sqrt(alpha * alpha + beta * beta);
67  }
68 
69  return ret;
70  }
71  );
72  return fun;
73  }
74 
79  static std::string getInverse()
80  {
81  std::string fun = MAKE_STRING(
82  const vec3 R_VAL = vec3(0.9990, -0.3709, 0.7862);
83  const vec3 G_VAL = vec3(0.9990, 0.2065, -0.2138);
84  const vec3 B_VAL = vec3(0.9990, -0.9482, -0.2138);
85  out vec4 f_color; \n
86  \n
87 
88  vec3 HSL2RGB(vec3 col) {
89  vec3 ret;
90  vec3 tmp;
91  tmp.x = col.y; //Luminance
92  tmp.y = col.z * cos(col.x); //Alpha
93  tmp.z = col.z * sin(col.x); //Beta
94 
95  ret.x = dot(tmp, R_VAL);
96  ret.y = dot(tmp, G_VAL);
97  ret.z = dot(tmp, B_VAL);
98 
99  return ret;
100  }
101  );
102  return fun;
103  }
104 
109  std::string getDirectFunction()
110  {
111  std::string fragment_source = getDirect() + MAKE_STRING(
112  uniform sampler2D u_tex; \n
113  out vec4 f_color; \n
114 
115  void main(void) {
116  ivec2 coords = ivec2(gl_FragCoord.xy); \n
117  vec3 color = texelFetch(u_tex, coords, 0).xyz; \n
118  f_color = vec4(RGB2HSL(color), 1.0); \n
119  \n
120  }
121  );
122 
123  return fragment_source;
124  }
125 
130  std::string getInverseFunction()
131  {
132  std::string fragment_source = getInverse() + MAKE_STRING(
133  uniform sampler2D u_tex; \n
134  out vec4 f_color; \n
135  void main(void) {\n
136  ivec2 coords = ivec2(gl_FragCoord.xy); \n
137  vec3 color = texelFetch(u_tex, coords, 0).xyz; \n
138  f_color = vec4(HSL2RGB(color), 1.0); \n
139  \n
140  }
141  );
142 
143  return fragment_source;
144  }
145 };
146 
147 } // end namespace pic
148 
149 #endif /* PIC_GL_COLORS_COLOR_CONV_RGB_TO_HSL_HPP */
150 
#define MAKE_STRING(input_string)
std::string getDirectFunction()
getDirectFunction
Definition: color_conv_rgb_to_hsl.hpp:109
ColorConvGLRGBtoHSL(bool direct=true)
ColorConvGLRGBtoHSL.
Definition: color_conv_rgb_to_hsl.hpp:35
std::string getInverseFunction()
getInverseFunction
Definition: color_conv_rgb_to_hsl.hpp:130
The ColorConvGL class.
Definition: color_conv.hpp:30
static std::string getInverse()
getInverse
Definition: color_conv_rgb_to_hsl.hpp:79
int direct
Definition: display.hpp:33
Definition: bilateral_separation.hpp:25
The ColorConvGLRGBtoHSL class.
Definition: color_conv_rgb_to_hsl.hpp:28
static std::string getDirect()
getDirect
Definition: color_conv_rgb_to_hsl.hpp:43