PICCANTE  0.4
The hottest HDR imaging library!
bicubic.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_UTIL_GL_BICUBIC_HPP
19 #define PIC_UTIL_GL_BICUBIC_HPP
20 
21 #include "../../base.hpp"
22 
23 #include "../../util/string.hpp"
24 
25 namespace pic {
26 
31 PIC_INLINE std::string GLSL_BICUBIC()
32 {
33  std::string ret;
34 
35  ret = MAKE_STRING(
36  float Bicubic(float x)
37  {
38  float y = abs(x);
39  if(y < 1.0) {
40  float y_sq = y * y;
41  return (3.0 * y_sq * y - 6.0 * y_sq + 4.0) / 6.0;
42  } else {
43  if(y < 2.0) {
44  float y_sq = y * y;
45  return (-1.0 * y_sq * y + 6.0 * y_sq - 12.0 * y + 8.0) / 6.0;
46  } else {
47  return 0.0;
48  }
49  }
50  }
51  );
52 
53  return ret;
54 }
55 
61 {
62  std::string ret;
63 
64  ret = MAKE_STRING(
65 
66  vec4 textureBicubic(sampler2D u_tex, vec2 coords)
67  {
68  ivec2 tSize_u = textureSize(u_tex, 0) - ivec2(1, 1);
69  vec2 tSize = vec2(tSize_u);
70  vec2 coords_uc = vec2(coords * tSize);
71  vec2 d = fract(coords_uc);
72 
73  ivec2 coords_i = ivec2(floor(coords_uc));
74  vec2 r;
75  ivec2 e;
76  vec4 ret = vec4(0.0);
77 
78  for(int j = -1; j < 3; j++) {
79  r.y = Bicubic(float(j) - d.y);
80  e.y = clamp(coords_i.y + j, 0, tSize_u.y);
81 
82  for(int i = -1; i < 3; i++) {
83  r.x = Bicubic(-(float(i) - d.x));
84  e.x = clamp(coords_i.x + i, 0, tSize_u.x);
85  r.x *= r.y;
86 
87  ret += r.x * texelFetch(u_tex, e, 0);
88  }
89  }
90  return ret;
91  }
92  );
93 
94  return ret;
95 }
96 
97 } // end namespace pic
98 
99 #endif /* PIC_UTIL_GL_BICUBIC_HPP */
100 
#define MAKE_STRING(input_string)
float Bicubic(float x)
Bicubic.
Definition: image_sampler.hpp:129
PIC_INLINE std::string GLSL_TEXTURE_BICUBIC()
GLSL_TEXTURE_BICUBIC.
Definition: bicubic.hpp:60
#define PIC_INLINE
Definition: base.hpp:33
PIC_INLINE std::string GLSL_BICUBIC()
GLSL_BICUBIC returns bicubic sample.
Definition: bicubic.hpp:31
Definition: bilateral_separation.hpp:25