PICCANTE  0.4
The hottest HDR imaging library!
filter_hsl_replace.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_FILTERING_FILTER_HSL_REPLACE_HPP
19 #define PIC_GL_FILTERING_FILTER_HSL_REPLACE_HPP
20 
21 #include "../../base.hpp"
22 
23 #include "../../gl/colors/color_conv_rgb_to_hsl.hpp"
24 #include "../../gl/filtering/filter.hpp"
25 
26 namespace pic {
27 
32 {
33 protected:
35 
39  void initShaders()
40  {
42  (
43  uniform float delta_hue; \n
44  uniform float delta_saturation; \n
45  uniform sampler2D u_tex; \n
46  uniform sampler2D u_change; \n
47  out vec4 f_color; \n
48 
49  void main(void) {
50  \n
51  ivec2 coords = ivec2(gl_FragCoord.xy);
52  \n
53  vec3 color = texelFetch(u_tex, coords, 0).xyz;
54  \n
55  float weight = texelFetch(u_change, coords, 0).x;
56  weight = min(max(weight, 0.0), 1.0);
57 
58  if(weight > 0.0) {
59  color = RGB2HSL(color);
60  \n
61  color.x += delta_hue * weight;
62  \n
63  color.z += max(delta_saturation * weight, 0.0);
64  \n
65  color = HSL2RGB(color);
66  \n
67  }
68 
69  f_color = vec4(color.xyz, 1.0);
70  \n
71  }
72  );
73 
74  //Final fragment source
75  std::string final_fragment_source;
76  final_fragment_source = ColorConvGLRGBtoHSL::getDirect();
77  final_fragment_source += ColorConvGLRGBtoHSL::getInverse();
78  final_fragment_source += fragment_source;
79 
80  technique.initStandard("330", vertex_source, final_fragment_source, "FilterGLGradient");
81 
82  technique.bind();
83  technique.setUniform1i("u_tex", 0);
84  technique.setUniform1i("u_change", 1);
85  technique.setUniform1f("delta_hue", delta_hue);
86  technique.setUniform1f("delta_saturation", delta_saturation);
87  technique.unbind();
88  }
89 
90 public:
97  {
98  this->delta_hue = delta_hue;
99  this->delta_saturation = delta_saturation;
100  initShaders();
101  }
102 
104  {
105  release();
106  }
107 
112  void setDeltaHue(float delta_hue)
113  {
114  this->delta_hue = delta_hue;
115  }
116 };
117 
118 } // end namespace pic
119 
120 #endif /* PIC_GL_FILTERING_FILTER_HSL_REPLACE_HPP */
121 
TechniqueGL technique
Definition: display.hpp:45
void setDeltaHue(float delta_hue)
setDeltaHue
Definition: filter_hsl_replace.hpp:112
float delta_hue
Definition: filter_hsl_replace.hpp:34
~FilterGLHSLReplace()
Definition: filter_hsl_replace.hpp:103
void bind()
bind
Definition: display.hpp:189
#define MAKE_STRING(input_string)
void setUniform1f(const char *name_uniform, float value0)
SetUniform1f.
Definition: display.hpp:247
void initShaders()
initShaders
Definition: filter_hsl_replace.hpp:39
The FilterGL class.
Definition: filter.hpp:35
FilterGLHSLReplace(float delta_hue, float delta_saturation)
FilterGLHSLReplace.
Definition: filter_hsl_replace.hpp:96
The FilterGLHSLReplace class.
Definition: filter_hsl_replace.hpp:31
float delta_saturation
Definition: filter_hsl_replace.hpp:34
bool initStandard(std::string version_number, std::string vertex_shader_source, std::string fragment_shader_source, std::string name)
initStandard
Definition: display.hpp:114
static std::string getInverse()
getInverse
Definition: color_conv_rgb_to_hsl.hpp:79
void unbind()
unbind
Definition: display.hpp:197
std::string vertex_source
Definition: display.hpp:57
Definition: bilateral_separation.hpp:25
std::string fragment_source
Definition: display.hpp:57
static std::string getDirect()
getDirect
Definition: color_conv_rgb_to_hsl.hpp:43
void release()
release
Definition: display.hpp:85
void setUniform1i(const char *name_uniform, int value0)
SetUniform.
Definition: display.hpp:236