24 #ifndef SRC_CORE_HELPERS_SCALEHELPERS_H 25 #define SRC_CORE_HELPERS_SCALEHELPERS_H 37 namespace scale_helpers
56 const float dx1 = 1.0f - dx;
57 const float dy1 = 1.0f - dy;
59 const T a00 = *pixel_ptr;
60 const T a01 = *(pixel_ptr + 1);
61 const T a10 = *(pixel_ptr + stride);
62 const T a11 = *(pixel_ptr + stride + 1);
64 const float w1 = dx1 * dy1;
65 const float w2 = dx * dy1;
66 const float w3 = dx1 * dy;
67 const float w4 = dx * dy;
69 return static_cast<T>(a00 * w1 + a01 * w2 + a10 * w3 + a11 * w4);
91 const float dx1 = 1.0f - dx;
92 const float dy1 = 1.0f - dy;
99 const float w1 = dx1 * dy1;
100 const float w2 = dx * dy1;
101 const float w3 = dx1 * dy;
102 const float w4 = dx * dy;
103 float res = a00 * w1 + a01 * w2 + a10 * w3 + a11 * w4;
126 const float dx1 = 1.0f - dx;
127 const float dy1 = 1.0f - dy;
134 const float w1 = dx1 * dy1;
135 const float w2 = dx * dy1;
136 const float w3 = dx1 * dy;
137 const float w4 = dx * dy;
138 float res = a00 * w1 + a01 * w2 + a10 * w3 + a11 * w4;
153 template <
typename T>
158 const float dy1 = 1.0f - dy;
160 const T a00 = *pixel_ptr;
161 const T a10 = *(pixel_ptr + stride);
163 const float w1 = dy1;
166 return static_cast<T>(a00 * w1 + a10 * w3);
179 template <
typename T>
184 const T a00 = *pixel_ptr;
185 const T a01 = *(pixel_ptr + 1);
187 const float dx1 = 1.0f - dx;
189 const float w1 = dx1;
192 return static_cast<T>(a00 * w1 + a01 * w2);
206 template <
typename T>
211 const int32_t xi = std::floor(x);
212 const int32_t yi = std::floor(y);
214 const float dx = x - xi;
215 const float dy = y - yi;
233 template <
typename T>
239 x = std::max(-1.f, std::min(x, static_cast<float>(width)));
240 y = std::max(-1.f, std::min(y, static_cast<float>(height)));
242 const float xi = std::floor(x);
243 const float yi = std::floor(y);
245 const float dx = x - xi;
246 const float dy = y - yi;
252 return static_cast<T>(first_pixel_ptr[static_cast<int32_t>(xi) + static_cast<int32_t>(yi) * stride]);
254 return delta_linear_c1_y(first_pixel_ptr + static_cast<int32_t>(xi) + static_cast<int32_t>(yi) * stride,
259 return delta_linear_c1_x(first_pixel_ptr + static_cast<int32_t>(xi) + static_cast<int32_t>(yi) * stride,
262 return delta_bilinear_c1(first_pixel_ptr + static_cast<int32_t>(xi) + static_cast<int32_t>(yi) * stride, stride,
284 float hr,
int x,
int y)
289 float in_x = (x + 0.5f) * wr - 0.5f;
290 float in_y = (y + 0.5f) * hr - 0.5f;
293 int x_from = std::floor(x * wr - 0.5f - in_x);
294 int y_from = std::floor(y * hr - 0.5f - in_y);
295 int x_to = std::ceil((x + 1) * wr - 0.5f - in_x);
296 int y_to = std::ceil((y + 1) * hr - 0.5f - in_y);
299 in_x = std::max(-1.f, std::min(in_x, static_cast<float>(width)));
300 in_y = std::max(-1.f, std::min(in_y, static_cast<float>(height)));
303 x_from = ((in_x + x_from) < -1) ? -1 : x_from;
304 y_from = ((in_y + y_from) < -1) ? -1 : y_from;
305 x_to = ((in_x + x_to) > width) ? (width - in_x) : x_to;
306 y_to = ((in_y + y_to) > height) ? (height - in_y) : y_to;
309 const int xi = std::floor(in_x);
310 const int yi = std::floor(in_y);
313 const int x_elements = (x_to - x_from + 1);
314 const int y_elements = (y_to - y_from + 1);
319 for(
int j = yi + y_from, je = yi + y_to; j <= je; ++j)
321 const uint8_t *ptr = first_pixel_ptr + j * stride + xi + x_from;
326 return sum / (x_elements * y_elements);
343 inline float delta_bilinear(
float a00,
float a01,
float a10,
float a11,
float dx_val,
float dy_val)
345 const float dx1_val = 1.0f - dx_val;
346 const float dy1_val = 1.0f - dy_val;
348 const float w1 = dx1_val * dy1_val;
349 const float w2 = dx_val * dy1_val;
350 const float w3 = dx1_val * dy_val;
351 const float w4 = dx_val * dy_val;
352 return a00 * w1 + a01 * w2 + a10 * w3 + a11 * w4;
uint8_t delta_bilinear_c1_quantized(const uint8_t *pixel_ptr, size_t stride, float dx, float dy, UniformQuantizationInfo iq_info, UniformQuantizationInfo oq_info)
Computes bilinear interpolation for quantized input and output, using the pointer to the top-left pix...
float dequantize_qasymm8(uint8_t value, const INFO_TYPE &qinfo)
Dequantize a value given an unsigned 8-bit asymmetric quantization scheme.
uint8_t quantize_qasymm8(float value, const INFO_TYPE &qinfo, RoundingPolicy rounding_policy=RoundingPolicy::TO_NEAREST_UP)
Quantize a value given an unsigned 8-bit asymmetric quantization scheme.
T delta_linear_c1_x(const T *pixel_ptr, float dx)
Computes linear interpolation using the pointer to the left pixel and the pixel's distance between th...
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
SimpleTensor< T2 > accumulate(const SimpleTensor< T1 > &src, DataType output_data_type)
Copyright (c) 2017-2021 Arm Limited.
T delta_bilinear_c1(const T *pixel_ptr, size_t stride, float dx, float dy)
Computes bilinear interpolation using the pointer to the top-left pixel and the pixel's distance betw...
int8_t quantize_qasymm8_signed(float value, const INFO_TYPE &qinfo, RoundingPolicy rounding_policy=RoundingPolicy::TO_NEAREST_UP)
Quantize a value given a signed 8-bit asymmetric quantization scheme.
uint8_t pixel_area_c1u8_clamp(const uint8_t *first_pixel_ptr, size_t stride, size_t width, size_t height, float wr, float hr, int x, int y)
Return the pixel at (x,y) using area interpolation by clamping when out of borders.
uint8_t pixel_bilinear_c1_clamp(const T *first_pixel_ptr, size_t stride, size_t width, size_t height, float x, float y)
Return the pixel at (x,y) using bilinear interpolation by clamping when out of borders.
T delta_linear_c1_y(const T *pixel_ptr, size_t stride, float dy)
Computes linear interpolation using the pointer to the top pixel and the pixel's distance between the...
float dequantize_qasymm8_signed(int8_t value, const INFO_TYPE &qinfo)
Dequantize a value given a signed 8-bit asymmetric quantization scheme.
T pixel_bilinear_c1(const T *first_pixel_ptr, size_t stride, float x, float y)
Return the pixel at (x,y) using bilinear interpolation.
float delta_bilinear(float a00, float a01, float a10, float a11, float dx_val, float dy_val)
Computes bilinear interpolation using the top-left, top-right, bottom-left, bottom-right pixels and t...