PICCANTE  0.4
The hottest HDR imaging library!
image_sampler_catmull_rom.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_CATMULL_ROM_HPP
19 #define PIC_IMAGE_SAMPLERS_IMAGE_SAMPLER_CATMULL_ROM_HPP
20 
21 #include "../image_samplers/image_sampler.hpp"
22 
23 namespace pic {
24 
29 {
30 public:
32 
40  void SampleImage(Image *img, float x, float y, float *vOut)
41  {
42  float xx, yy, dx, dy;
43 
44  //Coordiantes in [0,width-1]x[0,height-1]
45  x *= img->width1f;
46  y *= img->height1f;
47 
48  //Coordinates without fractions
49  xx = floorf(x);
50  yy = floorf(y);
51 
52  //Interpolation values
53  dx = (x - xx);
54  dy = (y - yy);
55 
56  //Integer coordinates
57  int ix = int(xx);
58  int iy = int(yy);
59 
60  for(int k = 0; k < img->channels; k++) {
61  vOut[k] = 0.0f;
62  }
63 
64  //Catmull-rom interpolation
65  float rx, ry;
66  int ey, ex;
67  for(int j = -1; j < 3; j++) {
68  ry = CatmullRom(float(j) - dy);
69  ey = CLAMP(iy + j, img->height);
70 
71  for(int i = -1; i < 3; i++) {
72  rx = CatmullRom(-(float(i) - dx));
73  ex = CLAMP(ix + i, img->width);
74  int ind = (ey * img->width + ex) * img->channels;
75 
76  rx *= ry;
77  for(int k = 0; k < img->channels; k++) {
78  vOut[k] += img->data[ind + k] * rx;
79  }
80  }
81  }
82  }
83 };
84 
85 } // end namespace pic
86 
87 #endif /* PIC_IMAGE_SAMPLERS_IMAGE_SAMPLER_CATMULL_ROM_HPP */
88 
ImageSamplerCatmullRom()
Definition: image_sampler_catmull_rom.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 ImageSamplerCatmullRom class.
Definition: image_sampler_catmull_rom.hpp:28
The ImageSampler class.
Definition: image_sampler.hpp:29
float CatmullRom(float x)
CatmullRom.
Definition: image_sampler.hpp:150
void SampleImage(Image *img, float x, float y, float *vOut)
SampleImage samples an image in uniform coordiantes.
Definition: image_sampler_catmull_rom.hpp:40
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
#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