PR #26371 opened by Jun Zhao (mypopydev) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26371 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26371.patch
Handle odd heights safely by using NEON for complete row pairs and C for single-row images, narrow widths, and remaining pixels. Add checkasm coverage for odd heights, edge widths, negative strides, and output boundaries. >From 55e1537803f7c2431e93832241152078c17c8962 Mon Sep 17 00:00:00 2001 From: Jun Zhao <[email protected]> Date: Thu, 26 Nov 2026 22:33:25 +0800 Subject: [PATCH 1/2] swscale/aarch64: handle odd heights in rgb24toyv12 The NEON kernel processes two rows per iteration. Passing an odd height lets it access a row beyond the image. Use NEON for complete row pairs in the 16-pixel-aligned region. Convert the remaining columns of those pairs and any unpaired last row in C. Fall back to C for single-row images or widths below 16 pixels. Fixes: https://code.ffmpeg.org/FFmpeg/FFmpeg/issues/26337 Signed-off-by: Jun Zhao <[email protected]> --- libswscale/aarch64/rgb2rgb.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/libswscale/aarch64/rgb2rgb.c b/libswscale/aarch64/rgb2rgb.c index b9d8aa4dc2d..c088850ba37 100644 --- a/libswscale/aarch64/rgb2rgb.c +++ b/libswscale/aarch64/rgb2rgb.c @@ -27,7 +27,7 @@ #include "libswscale/swscale.h" #include "libswscale/swscale_internal.h" -// Only handle width aligned to 16 +// Only handles widths aligned to 16 and even heights. void ff_rgb24toyv12_neon(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, int width, int height, int lumStride, int chromStride, int srcStride, const int32_t *rgb2yuv); @@ -36,18 +36,30 @@ static void rgb24toyv12(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, int width, int height, int lumStride, int chromStride, int srcStride, const int32_t *rgb2yuv) { - int width_align = width & (~15); + int width_align = width & ~15; + int height_align = height & ~1; - if (width_align > 0) - ff_rgb24toyv12_neon(src, ydst, udst, vdst, width_align, height, - lumStride, chromStride, srcStride, rgb2yuv); - if (width_align < width) { - src += width_align * 3; - ydst += width_align; - udst += width_align / 2; - vdst += width_align / 2; - ff_rgb24toyv12_c(src, ydst, udst, vdst, width - width_align, height, - lumStride, chromStride, srcStride, rgb2yuv); + if (!width_align || !height_align) { + ff_rgb24toyv12_c(src, ydst, udst, vdst, width, height, + lumStride, chromStride, srcStride, rgb2yuv); + return; + } + + ff_rgb24toyv12_neon(src, ydst, udst, vdst, width_align, height_align, + lumStride, chromStride, srcStride, rgb2yuv); + if (width_align < width) + ff_rgb24toyv12_c(src + width_align * 3, ydst + width_align, + udst + width_align / 2, vdst + width_align / 2, + width - width_align, height_align, + lumStride, chromStride, srcStride, rgb2yuv); + + if (height_align < height) { + ptrdiff_t chrom_offset = (ptrdiff_t)(height_align / 2) * chromStride; + + ff_rgb24toyv12_c(src + (ptrdiff_t)height_align * srcStride, + ydst + (ptrdiff_t)height_align * lumStride, + udst + chrom_offset, vdst + chrom_offset, width, 1, + lumStride, chromStride, srcStride, rgb2yuv); } } -- 2.54.1 >From b9a791544de0179b13dfd8c581894cd1556a76e1 Mon Sep 17 00:00:00 2001 From: Jun Zhao <[email protected]> Date: Thu, 26 Nov 2026 22:33:25 +0800 Subject: [PATCH 2/2] checkasm/sw_rgb: cover odd heights in rgb24toyv12 The existing cases use even heights and allow a one-unit difference across the entire output buffer, including padding. Add AArch64 cases for single rows, larger odd heights, aligned and remainder widths, and negative strides. Round up the chroma height and check that the scalar tail matches C exactly in all three planes. Require unchanged guard rows and padding, and keep the one-unit tolerance for the other active pixels. Signed-off-by: Jun Zhao <[email protected]> --- tests/checkasm/sw_rgb.c | 67 +++++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 23 deletions(-) diff --git a/tests/checkasm/sw_rgb.c b/tests/checkasm/sw_rgb.c index 723f8104113..9a4a1bb4bc4 100644 --- a/tests/checkasm/sw_rgb.c +++ b/tests/checkasm/sw_rgb.c @@ -123,18 +123,34 @@ static void check_interleaved_to_planar(void *func, const char *report, int odd_ #define MAX_LINE_SIZE 1920 #define BUFSIZE (NUM_LINES * MAX_LINE_SIZE) -static int cmp_off_by_n(const uint8_t *ref, const uint8_t *test, size_t n, int accuracy) +static int check_rgb24toyv12_plane(const uint8_t *ref, const uint8_t *test, + int size, int stride, int width, int height, + int guard_rows, int odd_height) { - for (size_t i = 0; i < n; i++) { - if (abs(ref[i] - test[i]) > accuracy) + /* The scalar last row must match exactly, including with negative strides. */ + int exact_row = odd_height ? guard_rows + (stride > 0 ? height - 1 : 0) : -1; + + stride = FFABS(stride); + for (int i = 0; i < size; i++) { + if (i < guard_rows * stride || i >= (height + guard_rows) * stride || + i % stride >= width) { + if (ref[i] != 0xFF || test[i] != 0xFF) + return 1; + } else if (abs(ref[i] - test[i]) > (i / stride != exact_row)) { return 1; + } } return 0; } static void check_rgb24toyv12(SwsContext *sws) { - static const int input_sizes[] = {16, 128, 512, MAX_LINE_SIZE, -MAX_LINE_SIZE}; + static const struct { int width, height; } sizes[] = { + { 16, 0 }, { 128, 0 }, { 512, 0 }, { MAX_LINE_SIZE, 0 }, { -MAX_LINE_SIZE, 0 }, +#if ARCH_AARCH64 + { 16, 1 }, { 22, 1 }, { 14, 17 }, { 32, 17 }, { 38, 17 }, { -38, 17 }, { 38, 16 }, +#endif + }; SwsInternal *ctx = sws_internal(sws); LOCAL_ALIGNED_32(uint8_t, src, [BUFSIZE * 3]); @@ -151,32 +167,34 @@ static void check_rgb24toyv12(SwsContext *sws) randomize_buffers(src, BUFSIZE * 3); - for (int isi = 0; isi < FF_ARRAY_ELEMS(input_sizes); isi++) { - int input_size = input_sizes[isi]; - int negstride = input_size < 0; + for (int i = 0; i < FF_ARRAY_ELEMS(sizes); i++) { + int negstride = sizes[i].width < 0; const char *negstride_str = negstride ? "_negstride" : ""; - int width = FFABS(input_size); + int width = FFABS(sizes[i].width); int linesize = width + 32; - /* calculate height based on specified width to use the entire buffer. */ - int height = (BUFSIZE / linesize) & ~1; + int height = sizes[i].height ? sizes[i].height : (BUFSIZE / linesize) & ~1; + int chrom_height = (height + 1) / 2; + /* The small boundary cases have room for guard rows at both ends. */ + int guard_rows = !!sizes[i].height; + int guard = guard_rows * linesize; uint8_t *src0 = src; uint8_t *src1 = src; - uint8_t *dst_y_0 = buf_y_0; - uint8_t *dst_y_1 = buf_y_1; - uint8_t *dst_u_0 = buf_u_0; - uint8_t *dst_u_1 = buf_u_1; - uint8_t *dst_v_0 = buf_v_0; - uint8_t *dst_v_1 = buf_v_1; + uint8_t *dst_y_0 = buf_y_0 + guard; + uint8_t *dst_y_1 = buf_y_1 + guard; + uint8_t *dst_u_0 = buf_u_0 + guard / 2; + uint8_t *dst_u_1 = buf_u_1 + guard / 2; + uint8_t *dst_v_0 = buf_v_0 + guard / 2; + uint8_t *dst_v_1 = buf_v_1 + guard / 2; if (negstride) { src0 += (height - 1) * (linesize * 3); src1 += (height - 1) * (linesize * 3); dst_y_0 += (height - 1) * linesize; dst_y_1 += (height - 1) * linesize; - dst_u_0 += ((height / 2) - 1) * (linesize / 2); - dst_u_1 += ((height / 2) - 1) * (linesize / 2); - dst_v_0 += ((height / 2) - 1) * (linesize / 2); - dst_v_1 += ((height / 2) - 1) * (linesize / 2); + dst_u_0 += (chrom_height - 1) * (linesize / 2); + dst_u_1 += (chrom_height - 1) * (linesize / 2); + dst_v_0 += (chrom_height - 1) * (linesize / 2); + dst_v_1 += (chrom_height - 1) * (linesize / 2); linesize *= -1; } @@ -192,9 +210,12 @@ static void check_rgb24toyv12(SwsContext *sws) linesize, linesize / 2, linesize * 3, ctx->input_rgb2yuv_table); call_new(src1, dst_y_1, dst_u_1, dst_v_1, width, height, linesize, linesize / 2, linesize * 3, ctx->input_rgb2yuv_table); - if (cmp_off_by_n(buf_y_0, buf_y_1, BUFSIZE, 1) || - cmp_off_by_n(buf_u_0, buf_u_1, BUFSIZE / 4, 1) || - cmp_off_by_n(buf_v_0, buf_v_1, BUFSIZE / 4, 1)) + if (check_rgb24toyv12_plane(buf_y_0, buf_y_1, BUFSIZE, linesize, + width, height, guard_rows, height & 1) || + check_rgb24toyv12_plane(buf_u_0, buf_u_1, BUFSIZE / 4, linesize / 2, + width / 2, chrom_height, guard_rows, height & 1) || + check_rgb24toyv12_plane(buf_v_0, buf_v_1, BUFSIZE / 4, linesize / 2, + width / 2, chrom_height, guard_rows, height & 1)) fail(); bench_new(src1, dst_y_1, dst_u_1, dst_v_1, width, height, linesize, linesize / 2, linesize * 3, ctx->input_rgb2yuv_table); -- 2.54.1 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
