PICCANTE  0.4
The hottest HDR imaging library!
filter_up_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_UP_PP_HPP
19 #define PIC_GL_FILTERING_FILTER_UP_PP_HPP
20 
21 #include "../../base.hpp"
22 
23 #include "../../util/array.hpp"
24 #include "../../gl/filtering/filter.hpp"
25 
26 namespace pic {
27 
31 class FilterGLUpPP: public FilterGL
32 {
33 protected:
34 
35  float threshold, *value;
36 
40  void initShaders()
41  {
43  (
44  uniform sampler2D u_tex0; \n
45  uniform sampler2D u_tex1; \n
46  uniform vec4 value; \n
47  uniform float threshold; \n
48  out vec4 f_color; \n
49 
50  void main(void) { \n
51  ivec2 coords = ivec2(gl_FragCoord.xy); \n
52  vec3 color = texelFetch(u_tex1, coords, 0).xyz; \n
53 
54  vec3 ret;
55 
56  if(distance(color, value.xyz) < threshold) { \n
57  ret = texelFetch(u_tex0, coords / ivec2(2), 0).xyz; \n
58  } else { \n
59  ret = color.xyz; \n
60  }\n
61 
62  f_color = vec4(ret.xyz, 1.0); \n
63  }
64  );
65 
66  technique.initStandard("330", vertex_source, fragment_source, "FilterGLUpPP");
67 
68  }
69 
70 public:
75  FilterGLUpPP(float *value, float threshold) : FilterGL()
76  {
77  initShaders();
79  }
80 
82  {
83  release();
84  }
85 
91  void update(float *value, float threshold)
92  {
93  this->value = value;
94 
95  if(value == NULL) {
96  printf("Error in FilterGLUpPP\n");
97  }
98 
99  this->threshold = (threshold > 0.0f) ? threshold : 1e-4f;
100 
101  technique.bind();
102  technique.setUniform1i("u_tex0", 0);
103  technique.setUniform1i("u_tex1", 1);
104  technique.setUniform1f("threshold", this->threshold);
105  technique.setUniform4fv("value", this->value);
106  technique.unbind();
107  }
108 
117  void OutputSize(ImageGLVec imgIn, int &width, int &height, int &channels, int &frames)
118  {
119  if(imgIn.size() == 1) {
120  width = imgIn[0]->width << 1;
121  height = imgIn[0]->height << 1;
122  } else {
123  width = imgIn[1]->width;
124  height = imgIn[1]->height;
125  }
126 
127  channels = imgIn[0]->channels;
128  frames = imgIn[0]->frames;
129  }
130 };
131 
132 } // end namespace pic
133 
134 #endif /* PIC_GL_FILTERING_FILTER_UP_PP_HPP */
TechniqueGL technique
Definition: display.hpp:45
void bind()
bind
Definition: display.hpp:189
#define MAKE_STRING(input_string)
void initShaders()
initShaders
Definition: filter_up_pp.hpp:40
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
FilterGLUpPP(float *value, float threshold)
FilterGLUpPP.
Definition: filter_up_pp.hpp:75
The FilterGL class.
Definition: filter.hpp:35
bool initStandard(std::string version_number, std::string vertex_shader_source, std::string fragment_shader_source, std::string name)
initStandard
Definition: display.hpp:114
~FilterGLUpPP()
Definition: filter_up_pp.hpp:81
void OutputSize(ImageGLVec imgIn, int &width, int &height, int &channels, int &frames)
OutputSize.
Definition: filter_up_pp.hpp:117
void unbind()
unbind
Definition: display.hpp:197
std::string vertex_source
Definition: display.hpp:57
Definition: bilateral_separation.hpp:25
float threshold
Definition: filter_up_pp.hpp:35
The FilterGLUpPP class.
Definition: filter_up_pp.hpp:31
void update(float *value, float threshold)
update
Definition: filter_up_pp.hpp:91
std::string fragment_source
Definition: display.hpp:57
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
float * value
Definition: filter_up_pp.hpp:35