NHMLFixup v10
[jpcrr.git] / streamtools / rescalers / bicubic.cpp
blob7d0b0b144d7a842857670b8e499485af152a3752
1 #include "rescalers/linear-separable.hpp"
2 #include <stdint.h>
3 #include <cmath>
4 #include <stdexcept>
6 namespace
8 void compute_coefficients_bicubic(float* coeffs, position_t num, position_t denum, position_t width,
9 position_t twidth, unsigned& count, unsigned& base)
11 base = num / denum;
12 float t1 = (num % denum) / (float)denum;
13 float t2 = t1 * t1;
14 float t3 = t2 * t1;
15 count = 0;
17 In matrix form, the equation is:
18 / 0, 2, 0, 0 \ /a_-1\
19 |-1, 0, 1, 0 | |a_0 |
20 p(t) = 0.5 * [1, t, t², t³] | 2, -5, 4, -1 | |a_1 |
21 \-1, 3, -3, 1 / \a_2 /
22 Due to implicit muliplications, only the first part needs to be computed.
24 float c1 = t2 - 0.5 * (t1 + t3);
25 float c2 = 1 - 2.5 * t2 + 1.5 * t3;
26 float c3 = 0.5 * t1 + 2 * t2 - 1.5 * t3;
27 float c4 = 0.5 * (t3 - t2);
28 if(base == 0) {
29 coeffs[count++] = c2;
30 if(base < width - 1) coeffs[count++] = c3;
31 if(base < width - 2) coeffs[count++] = c4;
32 } else {
33 base--;
34 coeffs[count++] = c1;
35 coeffs[count++] = c2;
36 if(base < width - 2) coeffs[count++] = c3;
37 if(base < width - 3) coeffs[count++] = c4;
41 simple_rescaler_linear_separable r_bicubic("bicubic", make_bound_method(compute_coefficients_bicubic));