PICCANTE  0.4
The hottest HDR imaging library!
image_sampler_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_IMAGE_SAMPLERS_IMAGE_SAMPLER_BICUBIC_HPP
19 #define PIC_IMAGE_SAMPLERS_IMAGE_SAMPLER_BICUBIC_HPP
20 
21 #include "../image_samplers/image_sampler.hpp"
22 
23 namespace pic {
24 
29 {
30 public:
32  {
33 
34  }
35 
43  void SampleImage(Image *img, float x, float y, float *vOut)
44  {
45  float xx, yy, dx, dy;
46 
47  //Coordiantes in [0,width-1]x[0,height-1]
48  x *= img->width1f;
49  y *= img->height1f;
50 
51  //Coordinates without fractions
52  xx = floorf(x);
53  yy = floorf(y);
54 
55  //Interpolation values
56  dx = (x - xx);
57  dy = (y - yy);
58 
59  //Integer coordinates
60  int ix = int(xx);
61  int iy = int(yy);
62 
63  for(int k = 0; k < img->channels; k++) {
64  vOut[k] = 0.0f;
65  }
66 
67  //Bicubic interpolation
68  float rx, ry;
69  int ey, ex;
70  for(int j = -1; j < 3; j++) {
71  ry = Bicubic(float(j) - dy);
72  ey = CLAMP(iy + j, img->height);
73 
74  for(int i = -1; i < 3; i++) {
75  rx = Bicubic(-(float(i) - dx));
76  ex = CLAMP(ix + i, img->width);
77  int ind = (ey * img->width + ex) * img->channels;
78 
79  rx *= ry;
80  for(int k = 0; k < img->channels; k++) {
81  vOut[k] += img->data[ind + k] * rx;
82  }
83  }
84  }
85  }
86 };
87 
88 } // end namespace pic
89 
90 #endif /* PIC_IMAGE_SAMPLERS_IMAGE_SAMPLER_BICUBIC_HPP */
91 
ImageSamplerBicubic()
Definition: image_sampler_bicubic.hpp:31
float * data
data is the main buffer where pixel values are stored.
Definition: image.hpp:91
int channels
Definition: image.hpp:80
The ImageSamplerBicubic class.
Definition: image_sampler_bicubic.hpp:28
The ImageSampler class.
Definition: image_sampler.hpp:29
float Bicubic(float x)
Bicubic.
Definition: image_sampler.hpp:129
float height1f
Definition: image.hpp:84
void SampleImage(Image *img, float x, float y, float *vOut)
SampleImage samples an image in uniform coordiantes.
Definition: image_sampler_bicubic.hpp:43
The Image class stores an image as buffer of float.
Definition: image.hpp:60
Definition: bilateral_separation.hpp:25
#define CLAMP(x, a)
Definition: math.hpp:77
int width
Definition: image.hpp:80
int height
Definition: image.hpp:80
float width1f
Definition: image.hpp:84