From ef7f472429e2410510aeb085d283eaf168a15106 Mon Sep 17 00:00:00 2001 From: kallaballa Date: Mon, 13 Nov 2023 10:00:32 +0100 Subject: [PATCH] fixed copy n paste error --- modules/imgproc/src/opencl/resize.cl | 89 ++++++++-------------------- 1 file changed, 25 insertions(+), 64 deletions(-) diff --git a/modules/imgproc/src/opencl/resize.cl b/modules/imgproc/src/opencl/resize.cl index 197af5bc63..72aaaedb17 100644 --- a/modules/imgproc/src/opencl/resize.cl +++ b/modules/imgproc/src/opencl/resize.cl @@ -128,21 +128,6 @@ __kernel void resizeSampler(__read_only image2d_t srcImage, #elif defined INTER_LINEAR_INTEGER -#define FIXED_POINT_BITS 16 -#define FIXED_POINT_SCALE (1 << FIXED_POINT_BITS) - -// Fixed-point multiply -#define FIXED_MUL(a, b) (((a) * (b)) >> FIXED_POINT_BITS) - -// Rounding methods -#define ROUND_NEAREST_EVEN 0 -#define ROUND_DOWN 1 -#define ROUND_UP 2 -#define TRUNCATE 3 - -// Choose rounding method -#define ROUNDING_METHOD ROUND_NEAREST_EVEN - __kernel void resizeLN(__global const uchar * srcptr, int src_step, int src_offset, int src_rows, int src_cols, __global uchar * dstptr, int dst_step, int dst_offset, int dst_rows, int dst_cols, __global const uchar * buffer) @@ -177,9 +162,6 @@ __kernel void resizeLN(__global const uchar * srcptr, int src_step, int src_offs } } - - - #elif defined INTER_LINEAR __kernel void resizeLN(__global const uchar * srcptr, int src_step, int src_offset, int src_rows, int src_cols, @@ -256,61 +238,40 @@ __kernel void resizeLN(__global const uchar * srcptr, int src_step, int src_offs #define ROUNDING_METHOD ROUND_NEAREST_EVEN __kernel void resizeLN(__global const uchar * srcptr, int src_step, int src_offset, int src_rows, int src_cols, - __global uchar * dstptr, int dst_step, int dst_offset, int dst_rows, int dst_cols, - __global const int * xofs, __global const int * yofs, - __global const short * ialpha, __global const short * ibeta) + __global uchar * dstptr, int dst_step, int dst_offset, int dst_rows, int dst_cols, + __global const uchar * buffer) { int dx = get_global_id(0); int dy = get_global_id(1); - if (dx >= dst_cols || dy >= dst_rows) + if (dx < dst_cols && dy < dst_rows) { - return; // Exit if dx or dy is out of bounds + __global const int * xofs = (__global const int *)(buffer), * yofs = xofs + dst_cols; + __global const short * ialpha = (__global const short *)(yofs + dst_rows); + __global const short * ibeta = ialpha + ((dst_cols + dy) << 1); + ialpha += dx << 1; + + int sx0 = xofs[dx], sy0 = clamp(yofs[dy], 0, src_rows - 1), + sy1 = clamp(yofs[dy] + 1, 0, src_rows - 1); + short a0 = ialpha[0], a1 = ialpha[1]; + short b0 = ibeta[0], b1 = ibeta[1]; + + int src_index0 = mad24(sy0, src_step, mad24(sx0, TSIZE, src_offset)), + src_index1 = mad24(sy1, src_step, mad24(sx0, TSIZE, src_offset)); + WT data0 = convertToWT(loadpix(srcptr + src_index0)); + WT data1 = convertToWT(loadpix(srcptr + src_index0 + TSIZE)); + WT data2 = convertToWT(loadpix(srcptr + src_index1)); + WT data3 = convertToWT(loadpix(srcptr + src_index1 + TSIZE)); + + WT val = ( (((data0 * a0 + data1 * a1) >> 4) * b0) >> 16) + + ( (((data2 * a0 + data3 * a1) >> 4) * b1) >> 16); + + storepix(convertToDT((val + 2) >> 2), + dstptr + mad24(dy, dst_step, mad24(dx, TSIZE, dst_offset))); } - - // Calculate source coordinates - int sx = (dx * ifx) >> 16; - int sy = (dy * ify) >> 16; - - // Perform boundary checks - sx = clamp(sx, 0, src_cols - 1); - sy = clamp(sy, 0, src_rows - 1); - - // Calculate interpolation coefficients - int u = (dx * ifx) & 0xFFFF; - int v = (dy * ify) & 0xFFFF; - - int U = (0x10000 - u) >> 8; - int V = (0x10000 - v) >> 8; - int U1 = u >> 8; - int V1 = v >> 8; - - // Load pixel values - WT data0 = convertToWT(loadpix(srcptr + mad24(sy, src_step, mad24(sx, TSIZE, src_offset)))); - WT data1 = convertToWT(loadpix(srcptr + mad24(sy, src_step, mad24(INC(sx, src_cols), TSIZE, src_offset)))); - WT data2 = convertToWT(loadpix(srcptr + mad24(INC(sy, src_rows), src_step, mad24(sx, TSIZE, src_offset)))); - WT data3 = convertToWT(loadpix(srcptr + mad24(INC(sy, src_rows), src_step, mad24(INC(sx, src_cols), TSIZE, src_offset)))); - - // Perform fixed-point interpolation - WT val = mul24((WT)mul24(U1, V1), data0) + mul24((WT)mul24(U, V1), data1) + - mul24((WT)mul24(U1, V), data2) + mul24((WT)mul24(U, V), data3); - - // Convert and store the result -#if ROUNDING_METHOD == ROUND_NEAREST_EVEN - T uval = convertToDT((val + FIXED_POINT_SCALE / 2) >> FIXED_POINT_BITS); -#elif ROUNDING_METHOD == ROUND_DOWN - T uval = convertToDT(val >> FIXED_POINT_BITS); -#elif ROUNDING_METHOD == ROUND_UP - T uval = convertToDT((val + FIXED_POINT_SCALE - 1) >> FIXED_POINT_BITS); -#elif ROUNDING_METHOD == TRUNCATE - T uval = convertToDT(val >> FIXED_POINT_BITS); -#endif - storepix(uval, dstptr + mad24(dy, dst_step, mad24(dx, TSIZE, dst_offset))); } - - #elif defined INTER_NEAREST __kernel void resizeNN(__global const uchar * srcptr, int src_step, int src_offset, int src_rows, int src_cols,