18 #ifndef PIC_UTIL_IMAGE_SAMPLER_HPP 19 #define PIC_UTIL_IMAGE_SAMPLER_HPP 21 #include "../base.hpp" 23 #include "../util/math.hpp" 45 template<
class Scalar>
inline Scalar
Bilinear(Scalar a, Scalar b, Scalar c, Scalar d,
float x,
float y)
47 Scalar px0 = a + y * (c - a);
48 Scalar px1 = b + y * (d - b);
49 return px0 + x * (px1 - px0);
59 inline void invBilinear(
float A,
float dx,
float dy,
float *out)
61 dx =
CLAMPi(dx, 0.0f, 1.0f);
62 dy =
CLAMPi(dy, 0.0f, 1.0f);
65 out[1] = A * (1.0f - dx);
67 float i_dy = 1.0f - dy;
68 out[2] = out[0] * i_dy;
69 out[3] = out[1] * i_dy;
80 inline float Rx(
float x)
82 float px_1 =
MAX(x - 1.0f, 0.0f);
83 float px =
MAX(x, 0.0f);
84 float px1 =
MAX(x + 1.0f, 0.0f);
85 float px2 =
MAX(x + 2.0f, 0.0f);
87 return ( px2 * px2 * px2
88 - 4.0f * px1 * px1 * px1 +
90 - 4.0f * px_1 * px_1 * px_1
106 float t_3 = 12.0f - 9.0f * B - 6.0f * C;
107 float t_2 = -18.0f + 12.0f * B + 6.0f * C;
108 float c = 6.0f - 2.0f * B;
109 return (t_3 * y_sq * y + t_2 * y_sq + c) / 6.0f;
113 float t_3 = -B - 6.0f * C;
114 float t_2 = 6.0f * B + 30.0f * C;
115 float t_1 = -12.0f * B - 48.0f * C;
116 float c = 8.0f * B + 24.0f * C;
117 return (t_3 * y_sq * y + t_2 * y_sq + t_1 * y + c) / 6.0f;
134 return (3.0f * y_sq * y -6.0f * y_sq + 4.0f) / 6.0f;
138 return (-1.0f * y_sq * y + 6.0f * y_sq - 12.0f * y + 8.0f) / 6.0f;
155 return (9.0f * y_sq * y - 15.0f * y_sq + 6.0f) / 6.0f;
159 return (-3.0f * y_sq * y + 15.0f * y_sq -24.0f * y + 12.0f) / 6.0f;
176 if(y > 0.0f && y < a) {
180 return (a * sinf(t) * sinf(t / a)) / d;
const float C_PI
Definition: math.hpp:50
float Bicubic(float x)
Bicubic.
Definition: image_sampler.hpp:129
float Lanczos(float x, float a)
Lanczos.
Definition: image_sampler.hpp:172
const float C_PI_2
Definition: math.hpp:52
void invBilinear(float A, float dx, float dy, float *out)
invBilinear
Definition: image_sampler.hpp:59
float MitchellNetravali(float x, float B, float C)
MitchellNetravali.
Definition: image_sampler.hpp:101
float CatmullRom(float x)
CatmullRom.
Definition: image_sampler.hpp:150
Scalar Bilinear(Scalar a, Scalar b, Scalar c, Scalar d, float x, float y)
Bilinear calculates 2D bilinear interpolation at the point (x,y).
Definition: image_sampler.hpp:45
float Rx(float x)
Rx evaluates B-spline (cubic).
Definition: image_sampler.hpp:80
#define CLAMPi(x, a, b)
Definition: math.hpp:81
Definition: bilateral_separation.hpp:25
#define MAX(a, b)
Definition: math.hpp:73