PICCANTE  0.4
The hottest HDR imaging library!
image_sampler_lanczos.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_IMAGE_SAMPLERS_IMAGE_SAMPLER_LANCZOS_HPP
19 #define PIC_IMAGE_SAMPLERS_IMAGE_SAMPLER_LANCZOS_HPP
20 
21 #include "../image_samplers/image_sampler.hpp"
22 
23 namespace pic {
24 
29 {
30 protected:
31  float a;
32  int a_i;
33 
34 public:
39  {
40  a = 2.0f;
41  a_i = 2;
42  }
43 
50  {
51  this->a = a;
52  a_i = int(a);
53  }
54 
62  void SampleImage(Image *img, float x, float y, float *vOut)
63  {
64  float xx, yy, dx, dy;
65 
66  //Coordiantes in [0,width-1]x[0,height-1]
67  x *= img->width1f;
68  y *= img->height1f;
69 
70  //Coordinates without fractions
71  xx = floorf(x);
72  yy = floorf(y);
73 
74  //Interpolation values
75  dx = (x - xx);
76  dy = (y - yy);
77 
78  //Integer coordinates
79  int ix = int(xx);
80  int iy = int(yy);
81 
82  for(int k = 0; k < img->channels; k++) {
83  vOut[k] = 0.0f;
84  }
85 
86  float rx, ry;
87  int ey, ex;
88  for(int j = - a_i + 1; j <= a_i; j++) {
89  ry = Lanczos(dy - float(j), a);
90  ey = CLAMP(iy + j, img->height);
91 
92  for(int i = - a_i + 1; i <= a_i; i++) {
93  rx = Lanczos(dx - float(i), a);
94  ex = CLAMP(ix + i, img->width);
95  int ind = (ey * img->width + ex) * img->channels;
96 
97  rx *= ry;
98  for(int k = 0; k < img->channels; k++) {
99  vOut[k] += img->data[ind + k] * rx;
100  }
101  }
102  }
103  }
104 };
105 
106 } // end namespace pic
107 
108 #endif /* PIC_IMAGE_SAMPLERS_IMAGE_SAMPLER_LANCZOS_HPP */
109 
float * data
data is the main buffer where pixel values are stored.
Definition: image.hpp:91
int channels
Definition: image.hpp:80
ImageSamplerLanczos(float a)
ImageSamplerLanczos.
Definition: image_sampler_lanczos.hpp:49
The ImageSampler class.
Definition: image_sampler.hpp:29
void SampleImage(Image *img, float x, float y, float *vOut)
SampleImage samples an image in uniform coordiantes.
Definition: image_sampler_lanczos.hpp:62
int a_i
Definition: image_sampler_lanczos.hpp:32
float Lanczos(float x, float a)
Lanczos.
Definition: image_sampler.hpp:172
float height1f
Definition: image.hpp:84
The Image class stores an image as buffer of float.
Definition: image.hpp:60
Definition: bilateral_separation.hpp:25
The ImageSamplerLanczos class.
Definition: image_sampler_lanczos.hpp:28
#define CLAMP(x, a)
Definition: math.hpp:77
ImageSamplerLanczos()
ImageSamplerLanczos.
Definition: image_sampler_lanczos.hpp:38
int width
Definition: image.hpp:80
int height
Definition: image.hpp:80
float width1f
Definition: image.hpp:84
float a
Definition: image_sampler_lanczos.hpp:31