PICCANTE  0.4
The hottest HDR imaging library!
image_sampler_nearest.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_NEAREST_HPP
19 #define PIC_IMAGE_SAMPLERS_IMAGE_SAMPLER_NEAREST_HPP
20 
21 #include "../image_samplers/image_sampler.hpp"
22 
23 namespace pic {
24 
29 {
30 public:
35 
43  void SampleImage(Image *img, float x, float y, float *vOut)
44  {
45  x = CLAMPi(x, 0.0f, 1.0f);
46  y = CLAMPi(y, 0.0f, 1.0f);
47 
48  //Coordiantes in [0,width-1]x[0,height-1]
49  x = x * img->width1f;
50  y = y * img->height1f;
51 
52  SampleImageUC(img, x, y, vOut);
53  }
54 
62  void SampleImageUC(Image *img, float x, float y, float *vOut)
63  {
64  //Integer coordinates
65  int ix = CLAMP(int(x), img->width);
66  int iy = CLAMP(int(y), img->height);
67 
68  //Bilinear interpolation indicies
69  int ind = (ix * img->xstride + iy * img->ystride);
70 
71  for(int i = 0; i < img->channels; i++) {
72  vOut[i] = img->data[ind + i];
73  }
74  }
75 
84  void SampleImage(Image *img, float x, float y, float t, float *vOut)
85  {
86  x = CLAMPi(x, 0.0f, 1.0f);
87  y = CLAMPi(y, 0.0f, 1.0f);
88  t = CLAMPi(t, 0.0f, 1.0f);
89 
90  //coordiantes in [0,width-1] x [0,height-1] x [0,frames-1]
91  x = x * img->width1f;
92  y = y * img->height1f;
93  t = t * img->frames1f;
94 
95  //integer coordinates
96  int ix = int(x);
97  int iy = int(y);
98  int it = int(t);
99 
100  //indicies
101  int ind = (ix * img->xstride + iy * img->ystride + it * img->tstride);
102 
103  for(int i = 0; i < img->channels; i++) {
104  vOut[i] = img->data[ind + i];
105  }
106  }
107 };
108 
109 } // end namespace pic
110 
111 #endif /* PIC_IMAGE_SAMPLERS_IMAGE_SAMPLER_NEAREST_HPP */
112 
float * data
data is the main buffer where pixel values are stored.
Definition: image.hpp:91
int channels
Definition: image.hpp:80
The ImageSampler class.
Definition: image_sampler.hpp:29
void SampleImage(Image *img, float x, float y, float t, float *vOut)
SampleImage samples an image in uniform coordiantes.
Definition: image_sampler_nearest.hpp:84
void SampleImageUC(Image *img, float x, float y, float *vOut)
SampleImageUC samples an image in unnormalized coordinates [0,width-1]x[0,height-1].
Definition: image_sampler_nearest.hpp:62
void SampleImage(Image *img, float x, float y, float *vOut)
SampleImage samples an image in uniform coordiantes.
Definition: image_sampler_nearest.hpp:43
int xstride
Definition: image.hpp:82
float height1f
Definition: image.hpp:84
The Image class stores an image as buffer of float.
Definition: image.hpp:60
int ystride
Definition: image.hpp:82
#define CLAMPi(x, a, b)
Definition: math.hpp:81
Definition: bilateral_separation.hpp:25
int tstride
Definition: image.hpp:82
#define CLAMP(x, a)
Definition: math.hpp:77
ImageSamplerNearest()
ImageSamplerNearest.
Definition: image_sampler_nearest.hpp:34
int width
Definition: image.hpp:80
int height
Definition: image.hpp:80
The ImageSamplerNearest class.
Definition: image_sampler_nearest.hpp:28
float frames1f
Definition: image.hpp:84
float width1f
Definition: image.hpp:84