PICCANTE  0.4
The hottest HDR imaging library!
filter_down_pp.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_DOWN_PP_HPP
19 #define PIC_GL_FILTERING_FILTER_DOWN_PP_HPP
20 
21 #include "../../gl/filtering/filter.hpp"
22 
23 #include "../../util/array.hpp"
24 
25 namespace pic {
26 
30 class FilterGLDownPP: public FilterGL
31 {
32 protected:
33 
34  float threshold, *value;
35  int channels;
36 
40  void initShaders()
41  {
43  (
44  uniform sampler2D u_tex; \n
45  uniform vec4 value; \n
46  uniform float threshold; \n
47  out vec4 f_color; \n
48 
49  void main(void) { \n
50  ivec2 coords = ivec2(gl_FragCoord.xy) * ivec2(2); \n
51  vec3 color[4]; \n
52  color[0] = texelFetch(u_tex, coords , 0).xyz; \n
53  color[1] = texelFetch(u_tex, coords + ivec2(1, 0), 0).xyz; \n
54  color[2] = texelFetch(u_tex, coords + ivec2(0, 1), 0).xyz; \n
55  color[3] = texelFetch(u_tex, coords + ivec2(1, 1), 0).xyz; \n
56 
57  int counter = 0;
58  vec3 ret = vec3(0.0);
59 
60  for(int i = 0; i < 4; i++) {
61  if(distance(color[i], value.xyz) > threshold) {
62  ret += color[i];
63  counter++;
64  }
65  }
66 
67  if(counter > 0) {
68  ret /= vec3(counter);
69  } else {
70  ret = value.xyz;
71  }
72 
73  f_color = vec4(ret.xyz, 1.0); \n
74  }
75  );
76 
78 
79  #ifdef PIC_DEBUG
80  technique.printLog("FilterGLDownPP");
81  #endif
82 
83  technique.bind();
84  technique.setAttributeIndex("a_position", 0);
86  technique.link();
87  technique.unbind();
88  }
89 
90 public:
96  {
97  initShaders();
99  }
100 
102  {
103  release();
104  }
105 
111  void update(float *value, float threshold)
112  {
113  if(value == NULL) {
114  printf("ERROR in FilterGLDownPP");
115  }
116 
117  this->value = value;
118 
119  this->threshold = (threshold > 0.0f) ? threshold : 1e-6f;
120 
121  technique.bind();
122  technique.setUniform1i("u_tex", 0);
123  technique.setUniform1f("threshold", this->threshold);
124  technique.setUniform4fv("value", this->value);
125  technique.unbind();
126  }
127 
136  void OutputSize(ImageGLVec imgIn, int &width, int &height, int &channels, int &frames)
137  {
138  if(imgIn.size() == 1) {
139  width = imgIn[0]->width >> 1;
140  height = imgIn[0]->height >> 1;
141  } else {
142  width = imgIn[1]->width;
143  height = imgIn[1]->height;
144  }
145 
146  channels = imgIn[0]->channels;
147  frames = imgIn[0]->frames;
148  }
149 };
150 
151 } // end namespace pic
152 
153 #endif /* PIC_GL_FILTERING_FILTER_DOWN_PP_HPP */
TechniqueGL technique
Definition: display.hpp:45
void OutputSize(ImageGLVec imgIn, int &width, int &height, int &channels, int &frames)
OutputSize.
Definition: filter_down_pp.hpp:136
FilterGLDownPP(float *value, float threshold)
FilterGLDownPP.
Definition: filter_down_pp.hpp:95
void printLog(std::string name)
printLog
Definition: display.hpp:176
void bind()
bind
Definition: display.hpp:189
int channels
Definition: filter_down_pp.hpp:35
#define MAKE_STRING(input_string)
~FilterGLDownPP()
Definition: filter_down_pp.hpp:101
void setUniform4fv(const char *name_uniform, const float *value)
setUniform4
Definition: display.hpp:343
void setUniform1f(const char *name_uniform, float value0)
SetUniform1f.
Definition: display.hpp:247
void update(float *value, float threshold)
update
Definition: filter_down_pp.hpp:111
void setAttributeIndex(const char *attribute_name, unsigned int index)
setAttributeIndex
Definition: display.hpp:225
float threshold
Definition: filter_down_pp.hpp:34
The FilterGL class.
Definition: filter.hpp:35
void unbind()
unbind
Definition: display.hpp:197
std::string vertex_source
Definition: display.hpp:57
void initShaders()
initShaders
Definition: filter_down_pp.hpp:40
Definition: bilateral_separation.hpp:25
void setOutputFragmentShaderIndex(const char *fragment_output_color_name, unsigned int index)
setOutputFragmentShaderIndex
Definition: display.hpp:215
float * value
Definition: filter_down_pp.hpp:34
The FilterGLDownPP class.
Definition: filter_down_pp.hpp:30
void link()
link
Definition: display.hpp:205
std::string fragment_source
Definition: display.hpp:57
bool init(std::string version_number, std::string vertex_shader_source, std::string fragment_shader_source)
Definition: display.hpp:67
std::vector< ImageGL * > ImageGLVec
ImageGLVec an std::vector of pic::ImageGL.
Definition: image_vec.hpp:32
void release()
release
Definition: display.hpp:85
void setUniform1i(const char *name_uniform, int value0)
SetUniform.
Definition: display.hpp:236