PICCANTE  0.4
The hottest HDR imaging library!
filter_channel.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_CHANNEL_HPP
19 #define PIC_GL_FILTERING_FILTER_CHANNEL_HPP
20 
21 #include "../../base.hpp"
22 #include "../../util/math.hpp"
23 #include "../../gl/filtering/filter.hpp"
24 
25 namespace pic {
26 
31 {
32 protected:
36  void initShaders()
37  {
39  (
40  uniform sampler2D u_tex; \n
41  uniform int channel; \n
42  out vec4 f_color; \n
43  \n
44  void main(void) {
45  \n
46  ivec2 coords = ivec2(gl_FragCoord.xy); \n
47  vec4 color = texelFetch(u_tex, coords, 0); \n
48  float v = color[channel]; \n
49  f_color = vec4(v, v, v, 1.0); \n
50 
51  }
52  );
53 
54  technique.initStandard("330", vertex_source, fragment_source, "FilterGLChannel");
55  }
56 
57  int channel;
58 
59 public:
60 
66  {
67  initShaders();
68  update(channel);
69  }
70 
72  {
73  release();
74  }
75 
80  void update(int channel)
81  {
82  this->channel = CLAMP(channel, 4);
83 
84  if(technique.isValid()) {
85  technique.bind();
86  technique.setUniform1i("u_tex", 0);
87  technique.setUniform1i("channel", channel);
88  technique.unbind();
89  }
90  }
91 
100  void OutputSize(ImageGLVec imgIn, int &width, int &height, int &channels, int &frames)
101  {
102  width = imgIn[0]->width;
103  height = imgIn[0]->height;
104  channels = 1;
105  frames = imgIn[0]->frames;
106  }
107 
115  static ImageGL *execute(ImageGL *imgIn, ImageGL *imgOut, int channel = 0)
116  {
118  return flt.Process(SingleGL(imgIn), imgOut);
119  }
120 
124  static void Test()
125  {
126  ImageGL imgIn(1, 512, 512, 3, IMG_GPU_CPU, GL_TEXTURE_2D);
127 
128  for(auto i = 0; i < imgIn.size(); i += 3) {
129  imgIn.data[i ] = 1.0f;
130  imgIn.data[i + 1] = 0.5f;
131  imgIn.data[i + 2] = 0.25f;
132  }
133 
134  imgIn.generateTextureGL();
135 
136  FilterGLChannel filter(0);
137  ImageGL *outR = filter.Process(SingleGL(&imgIn), NULL);
138 
139  filter.update(1);
140  ImageGL *outG = filter.Process(SingleGL(&imgIn), NULL);
141 
142  filter.update(2);
143  ImageGL *outB = filter.Process(SingleGL(&imgIn), NULL);
144 
145  outR->loadToMemory();
146  outR->Write("channel_R.bmp");
147  outG->loadToMemory();
148  outG->Write("channel_G.bmp");
149  outB->loadToMemory();
150  outB->Write("channel_B.bmp");
151  }
152 };
153 
154 } // end namespace pic
155 
156 #endif /* PIC_GL_FILTERING_FILTER_CHANNEL_HPP */
157 
void initShaders()
initShaders
Definition: filter_channel.hpp:36
TechniqueGL technique
Definition: display.hpp:45
float * data
data is the main buffer where pixel values are stored.
Definition: filter_radial_basis_function.hpp:91
Definition: image.hpp:37
static ImageGL * execute(ImageGL *imgIn, ImageGL *imgOut, int channel=0)
execute
Definition: filter_channel.hpp:115
GLuint generateTextureGL(GLenum target, GLenum format_type, bool mipmap)
generateTextureGL
void bind()
bind
Definition: display.hpp:189
~FilterGLChannel()
Definition: filter_channel.hpp:71
#define MAKE_STRING(input_string)
int channel
Definition: filter_channel.hpp:57
PIC_INLINE ImageGLVec SingleGL(ImageGL *img)
SingleGL creates a single for filters input.
Definition: image_vec.hpp:39
void update(int channel)
update
Definition: filter_channel.hpp:80
static void Test()
Test.
Definition: filter_channel.hpp:124
The ImageGL class.
Definition: image.hpp:42
bool Write(std::string nameFile, LDR_type typeWrite, int writerCounter)
Write saves an Image into a file on the disk.
Definition: filter_radial_basis_function.hpp:1924
int size() const
size computes the number of values.
Definition: filter_radial_basis_function.hpp:481
virtual ImageGL * Process(ImageGLVec imgIn, ImageGL *imgOut)
Process.
Definition: display.hpp:258
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
void OutputSize(ImageGLVec imgIn, int &width, int &height, int &channels, int &frames)
OutputSize.
Definition: filter_channel.hpp:100
void unbind()
unbind
Definition: display.hpp:197
void loadToMemory()
loadToMemory
std::string vertex_source
Definition: display.hpp:57
Definition: bilateral_separation.hpp:25
#define CLAMP(x, a)
Definition: math.hpp:77
bool isValid()
Definition: display.hpp:62
std::string fragment_source
Definition: display.hpp:57
The FilterGLChannel class.
Definition: filter_channel.hpp:30
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
FilterGLChannel(int channel)
FilterGLChannel.
Definition: filter_channel.hpp:65