17 const auto get_coordinate = [](
const int x,
const int size,
const WrappingMode mode) ->
int {
27 return size - 1 - (x - size) % size;
29 default:
return (x + size) % size;
32 const auto get_buffer_value = [&](
int xx,
int yy) ->
float {
33 xx = get_coordinate(xx,
static_cast<int>(width), mode_x);
34 yy = get_coordinate(yy,
static_cast<int>(height), mode_y);
35 const int index = (yy % height) * width + (xx % width);
39 const auto sx =
static_cast<int>(std::floor(sx_ - 0.5));
40 const auto sy =
static_cast<int>(std::floor(sy_ - 0.5));
42 samples(0) = get_buffer_value(sx - 1, sy - 1);
43 samples(1) = get_buffer_value(sx, sy - 1);
44 samples(2) = get_buffer_value(sx + 1, sy - 1);
45 samples(3) = get_buffer_value(sx + 2, sy - 1);
47 samples(4) = get_buffer_value(sx - 1, sy);
48 samples(5) = get_buffer_value(sx, sy);
49 samples(6) = get_buffer_value(sx + 1, sy);
50 samples(7) = get_buffer_value(sx + 2, sy);
52 samples(8) = get_buffer_value(sx - 1, sy + 1);
53 samples(9) = get_buffer_value(sx, sy + 1);
54 samples(10) = get_buffer_value(sx + 1, sy + 1);
55 samples(11) = get_buffer_value(sx + 2, sy + 1);
57 samples(12) = get_buffer_value(sx - 1, sy + 2);
58 samples(13) = get_buffer_value(sx, sy + 2);
59 samples(14) = get_buffer_value(sx + 1, sy + 2);
60 samples(15) = get_buffer_value(sx + 2, sy + 2);
69 for (
float yy = -1; yy < 3; yy++)
70 for (
float xx = -1; xx < 3; xx++) {
73 ope(row, 2) = xx * xx;
74 ope(row, 3) = xx * xx * xx;
77 ope(row, 5) = xx * yy;
78 ope(row, 6) = xx * xx * yy;
79 ope(row, 7) = xx * xx * xx * yy;
81 ope(row, 8) = yy * yy;
82 ope(row, 9) = xx * yy * yy;
83 ope(row, 10) = xx * xx * yy * yy;
84 ope(row, 11) = xx * xx * xx * yy * yy;
86 ope(row, 12) = yy * yy * yy;
87 ope(row, 13) = xx * yy * yy * yy;
88 ope(row, 14) = xx * xx * yy * yy * yy;
89 ope(row, 15) = xx * xx * xx * yy * yy * yy;
96 ss << ope << std::endl;
97 logger().debug(
"ope det {}\n{}", ope.determinant(), ss.str());
104 ope_inv = ope_inv.unaryExpr([](
const float& xx) {
return fabs(xx) < 1e-5f ? 0 : xx; });
107 std::stringstream ss;
108 ss << ope_inv << std::endl;
109 logger().debug(
"ope_inv det {}\n{}", ope_inv.determinant(), ss.str());
113 assert((ope * ope_inv - BicubicMatrix::Identity()).array().
abs().maxCoeff() < 1e-5);
BicubicMatrix make_samples_to_bicubic_coeffs_operator()
const BicubicMatrix & get_bicubic_matrix()
Eigen::Matrix< T, 16, 1 > BicubicVector
BicubicVector< float > extract_samples(const size_t width, const size_t height, const float *buffer, const double sx_, const double sy_, const WrappingMode mode_x, const WrappingMode mode_y)
Eigen::Matrix< float, 16, 16 > BicubicMatrix
Rational abs(const Rational &r0)
spdlog::logger & logger()
Retrieves the current logger.