1 #include "resize-linear-separable.hpp"
8 double pi
= 3.1415926535897932384626;
10 //num / denum = x * swidth / twidth
11 // swidth = n * twidth => x * n
12 // twdith = n * swidth => x / n
14 void compute_coefficients_lanczos(float* coeffs
, position_t num
, position_t denum
, position_t width
,
15 position_t twidth
, unsigned& count
, unsigned& base
, int a
)
18 throw std::runtime_error("Parameter alpha must be positive in lanczos resizer");
21 throw std::runtime_error("Parameter alpha way too large in lanczos resizer");
23 if(2 * a
+ 1 > MAXCOEFFICIENTS
)
24 throw std::runtime_error("Parameter alpha value would require more coefficients than "
29 bool base_set
= false;
30 position_t centralpoint
= num
/ denum
;
31 for(int i
= -a
+ 1; i
<= a
; i
++) {
32 position_t point
= centralpoint
+ i
;
34 if(point
< 0 || point
>= width
)
35 continue; //Out of range.
38 base
= (unsigned)point
;
40 double x
= point
+ 0.5 - (double)num
/ denum
- 0.5 * width
/ twidth
;
41 if(x
< -1e-10 || x
> 1e-10) {
43 coeffs
[count
++] = a
* sin(xpi
) * sin(xpi
/ a
) / ((xpi
) * (xpi
));
50 void compute_coefficients_average(float* coeffs
, position_t num
, position_t denum
, position_t width
,
51 position_t twidth
, unsigned& count
, unsigned& base
)
53 signed lowbound
, highbound
, scan
;
56 highbound
= num
+ width
;
57 scan
= lowbound
- lowbound
% denum
;
59 if((width
+ denum
- 1) / denum
> MAXCOEFFICIENTS
)
60 throw std::runtime_error("Conversion would require more coefficients than supported");
63 *coeffs
= (scan
+ denum
) - lowbound
;
66 while(scan
< highbound
) {
67 if(scan
+ denum
> highbound
)
68 coeffs
[count
++] = highbound
- scan
;
70 coeffs
[count
++] = denum
;
76 simple_resizer_linear_separable
r_average("average", compute_coefficients_average
);
77 simple_resizer_linear_separable
r_lanczos1("lanczos1", compute_coefficients_lanczos
, 1);
78 simple_resizer_linear_separable
r_lanczos2("lanczos2", compute_coefficients_lanczos
, 2);
79 simple_resizer_linear_separable
r_lanczos3("lanczos3", compute_coefficients_lanczos
, 3);
80 simple_resizer_linear_separable
r_lanczos4("lanczos4", compute_coefficients_lanczos
, 4);
81 simple_resizer_linear_separable
r_lanczos5("lanczos5", compute_coefficients_lanczos
, 5);