PICCANTE  0.4
The hottest HDR imaging library!
color_conv_rgb_to_srgb.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_SRGB_HPP
19 #define PIC_GL_COLORS_COLOR_CONV_RGB_TO_SRGB_HPP
20 
21 #include "../../gl/colors/color_conv.hpp"
22 
23 namespace pic {
24 
29 {
30 public:
31 
36  {
37  }
38 
39  // a = 0.055
40  // gamma = 2.4
41 
46  std::string getDirectFunction()
47  {
48  std::string fragment_source = MAKE_STRING(
49  uniform sampler2D u_tex; \n
50  out vec4 f_color; \n
51  \n
52  float fromRGBtosRGB(float x) {
53  if(x > 0.0031308) {
54  return 1.055 * pow(x, 1.0 / 2.4) - 0.055;
55  } else {
56  return x * 12.92;
57  }
58  }
59 
60  void main(void) {
61  ivec2 coords = ivec2(gl_FragCoord.xy); \n
62  vec3 colIn = texelFetch(u_tex, coords, 0).xyz; \n
63  vec3 colOut = vec3(fromRGBtosRGB(colIn.x),
64  fromRGBtosRGB(colIn.y),
65  fromRGBtosRGB(colIn.z));
66  f_color = vec4(colOut, 1.0); \n
67  \n
68  }
69  );
70 
71  return fragment_source;
72  }
73 
78  std::string getInverseFunction()
79  {
80  std::string fragment_source = MAKE_STRING(
81  uniform sampler2D u_tex; \n
82  out vec4 f_color; \n
83  \n
84  float fromsRGBtoRGB(float x) {
85  if(x > 0.04045) {
86  return pow((x + 0.055) / (1.055), 2.4);
87  } else {
88  return x / 12.92;
89  }
90  }
91 
92  void main(void) {
93  \n
94  ivec2 coords = ivec2(gl_FragCoord.xy); \n
95  vec3 colIn = texelFetch(u_tex, coords, 0).xyz; \n
96  vec3 colOut = vec3(fromsRGBtoRGB(colIn.x),
97  fromsRGBtoRGB(colIn.y),
98  fromsRGBtoRGB(colIn.z)); \n
99  f_color = vec4(colOut, 1.0); \n
100  \n
101  }
102  );
103 
104  return fragment_source;
105  }
106 
111  std::string getDirectFunctionAux()
112  {
113  return "";
114  }
115 
120  std::string getInverseFunctionAux()
121  {
122  return "";
123  }
124 
129  std::string getDirectUniforms()
130  {
131  return "";
132  }
133 
138  std::string getInverseUniforms()
139  {
140  return "";
141  }
142 
143 };
144 
145 } // end namespace pic
146 
147 #endif /* PIC_GL_COLORS_COLOR_CONV_RGB_TO_SRGB_HPP */
148 
std::string getDirectFunctionAux()
getDirectFunctionAux
Definition: color_conv_rgb_to_srgb.hpp:111
std::string getInverseUniforms()
getInverseUniforms
Definition: color_conv_rgb_to_srgb.hpp:138
std::string getDirectUniforms()
getDirectUniforms
Definition: color_conv_rgb_to_srgb.hpp:129
#define MAKE_STRING(input_string)
ColorConvGLRGBtosRGB(bool direct=true)
ColorConvGLRGBtosRGB.
Definition: color_conv_rgb_to_srgb.hpp:35
std::string getInverseFunctionAux()
getInverseFunctionAux
Definition: color_conv_rgb_to_srgb.hpp:120
The ColorConvGL class.
Definition: color_conv.hpp:30
std::string getDirectFunction()
getDirectFunction
Definition: color_conv_rgb_to_srgb.hpp:46
int direct
Definition: display.hpp:33
std::string getInverseFunction()
getInverseFunction
Definition: color_conv_rgb_to_srgb.hpp:78
Definition: bilateral_separation.hpp:25
The ColorConvGLRGBtosRGB class.
Definition: color_conv_rgb_to_srgb.hpp:28