24 #ifndef SRC_CORE_HELPERS_SCALEHELPERS_H
25 #define SRC_CORE_HELPERS_SCALEHELPERS_H
37 namespace scale_helpers
62 const float dx1 = 1.0f - dx;
63 const float dy1 = 1.0f - dy;
70 const float w1 = dx1 * dy1;
71 const float w2 = dx * dy1;
72 const float w3 = dx1 * dy;
73 const float w4 = dx * dy;
74 float res = a00 * w1 + a01 * w2 + a10 * w3 + a11 * w4;
101 const float dx1 = 1.0f - dx;
102 const float dy1 = 1.0f - dy;
109 const float w1 = dx1 * dy1;
110 const float w2 = dx * dy1;
111 const float w3 = dx1 * dy;
112 const float w4 = dx * dy;
113 float res = a00 * w1 + a01 * w2 + a10 * w3 + a11 * w4;
134 const uint8_t *first_pixel_ptr,
size_t stride,
size_t width,
size_t height,
float wr,
float hr,
int x,
int y)
139 float in_x = (x + 0.5f) * wr - 0.5f;
140 float in_y = (y + 0.5f) * hr - 0.5f;
143 int x_from = std::floor(x * wr - 0.5f - in_x);
144 int y_from = std::floor(y * hr - 0.5f - in_y);
145 int x_to = std::ceil((x + 1) * wr - 0.5f - in_x);
146 int y_to = std::ceil((y + 1) * hr - 0.5f - in_y);
149 in_x = std::max(-1.f, std::min(in_x,
static_cast<float>(width)));
150 in_y = std::max(-1.f, std::min(in_y,
static_cast<float>(height)));
153 x_from = ((in_x + x_from) < -1) ? -1 : x_from;
154 y_from = ((in_y + y_from) < -1) ? -1 : y_from;
155 x_to = ((in_x + x_to) > width) ? (width - in_x) : x_to;
156 y_to = ((in_y + y_to) > height) ? (height - in_y) : y_to;
159 const int xi = std::floor(in_x);
160 const int yi = std::floor(in_y);
163 const int x_elements = (x_to - x_from + 1);
164 const int y_elements = (y_to - y_from + 1);
169 for (
int j = yi + y_from, je = yi + y_to; j <= je; ++j)
171 const uint8_t *ptr = first_pixel_ptr + j * stride + xi + x_from;
176 return sum / (x_elements * y_elements);
193 inline float delta_bilinear(
float a00,
float a01,
float a10,
float a11,
float dx_val,
float dy_val)
195 const float dx1_val = 1.0f - dx_val;
196 const float dy1_val = 1.0f - dy_val;
198 const float w1 = dx1_val * dy1_val;
199 const float w2 = dx_val * dy1_val;
200 const float w3 = dx1_val * dy_val;
201 const float w4 = dx_val * dy_val;
202 return a00 * w1 + a01 * w2 + a10 * w3 + a11 * w4;