PR #21397 opened by mkver URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21397 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21397.patch
>From b6aa27da24bea6fd35674975386e6a8da343f1bf Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Tue, 6 Jan 2026 16:37:39 +0100 Subject: [PATCH 1/4] avcodec/pngdec: Move ff_add_png_paeth_prediction() to pngdsp.c Also rename it to ff_png_add_paeth_prediction() so that it has a proper prefix. Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavcodec/png.h | 2 -- libavcodec/pngdec.c | 28 ---------------------------- libavcodec/pngdsp.c | 28 +++++++++++++++++++++++++++- libavcodec/pngdsp.h | 6 ++++++ 4 files changed, 33 insertions(+), 31 deletions(-) diff --git a/libavcodec/png.h b/libavcodec/png.h index 01171e682e..903f217aed 100644 --- a/libavcodec/png.h +++ b/libavcodec/png.h @@ -57,8 +57,6 @@ int ff_png_get_nb_channels(int color_type); /* compute the row size of an interleaved pass */ int ff_png_pass_row_size(int pass, int bits_per_pixel, int width); -void ff_add_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp); - void ff_png_filter_row(PNGDSPContext *dsp, uint8_t *dst, int filter_type, uint8_t *src, uint8_t *last, int size, int bpp); diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c index fff27305d5..3651da265f 100644 --- a/libavcodec/pngdec.c +++ b/libavcodec/pngdec.c @@ -218,34 +218,6 @@ static void png_put_interlaced_row(uint8_t *dst, int width, } } -void ff_add_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top, - int w, int bpp) -{ - int i; - for (i = 0; i < w; i++) { - int a, b, c, p, pa, pb, pc; - - a = dst[i - bpp]; - b = top[i]; - c = top[i - bpp]; - - p = b - c; - pc = a - c; - - pa = abs(p); - pb = abs(pc); - pc = abs(p + pc); - - if (pa <= pb && pa <= pc) - p = a; - else if (pb <= pc) - p = b; - else - p = c; - dst[i] = p + src[i]; - } -} - #define UNROLL1(bpp, op) \ { \ r = dst[0]; \ diff --git a/libavcodec/pngdsp.c b/libavcodec/pngdsp.c index ae40113a51..fa22bfcb07 100644 --- a/libavcodec/pngdsp.c +++ b/libavcodec/pngdsp.c @@ -23,7 +23,6 @@ #include "libavutil/attributes.h" #include "libavutil/intreadwrite.h" #include "libavutil/macros.h" -#include "png.h" #include "pngdsp.h" #if HAVE_FAST_64BIT @@ -53,6 +52,33 @@ static void add_bytes_l2_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w) dst[i] = src1[i] + src2[i]; } +void ff_add_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top, + int w, int bpp) +{ + for (int i = 0; i < w; ++i) { + int a, b, c, p, pa, pb, pc; + + a = dst[i - bpp]; + b = top[i]; + c = top[i - bpp]; + + p = b - c; + pc = a - c; + + pa = abs(p); + pb = abs(pc); + pc = abs(p + pc); + + if (pa <= pb && pa <= pc) + p = a; + else if (pb <= pc) + p = b; + else + p = c; + dst[i] = p + src[i]; + } +} + av_cold void ff_pngdsp_init(PNGDSPContext *dsp) { dsp->add_bytes_l2 = add_bytes_l2_c; diff --git a/libavcodec/pngdsp.h b/libavcodec/pngdsp.h index 5475d0d943..a32ffb88af 100644 --- a/libavcodec/pngdsp.h +++ b/libavcodec/pngdsp.h @@ -24,6 +24,8 @@ #include <stdint.h> +#include "libavutil/attributes_internal.h" + typedef struct PNGDSPContext { void (*add_bytes_l2)(uint8_t *dst, uint8_t *src1 /* align 16 */, @@ -34,7 +36,11 @@ typedef struct PNGDSPContext { uint8_t *top, int w, int bpp); } PNGDSPContext; +FF_VISIBILITY_PUSH_HIDDEN +void ff_add_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp); + void ff_pngdsp_init(PNGDSPContext *dsp); void ff_pngdsp_init_x86(PNGDSPContext *dsp); +FF_VISIBILITY_POP_HIDDEN #endif /* AVCODEC_PNGDSP_H */ -- 2.49.1 >From f100eda442185ca44eb891a79ac3ad0dd5d5a16c Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Tue, 6 Jan 2026 16:55:43 +0100 Subject: [PATCH 2/4] avcodec/pngdsp: Constify Also constify ff_png_filter_row(). Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavcodec/png.h | 2 +- libavcodec/pngdec.c | 4 ++-- libavcodec/pngdsp.c | 7 ++++--- libavcodec/pngdsp.h | 11 ++++++----- libavcodec/x86/pngdsp_init.c | 12 ++++++------ 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/libavcodec/png.h b/libavcodec/png.h index 903f217aed..1e2cf11d1c 100644 --- a/libavcodec/png.h +++ b/libavcodec/png.h @@ -58,6 +58,6 @@ int ff_png_get_nb_channels(int color_type); int ff_png_pass_row_size(int pass, int bits_per_pixel, int width); void ff_png_filter_row(PNGDSPContext *dsp, uint8_t *dst, int filter_type, - uint8_t *src, uint8_t *last, int size, int bpp); + const uint8_t *src, const uint8_t *last, int size, int bpp); #endif /* AVCODEC_PNG_H */ diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c index 3651da265f..723f2aec4d 100644 --- a/libavcodec/pngdec.c +++ b/libavcodec/pngdec.c @@ -257,7 +257,7 @@ static void png_put_interlaced_row(uint8_t *dst, int width, /* NOTE: 'dst' can be equal to 'last' */ void ff_png_filter_row(PNGDSPContext *dsp, uint8_t *dst, int filter_type, - uint8_t *src, uint8_t *last, int size, int bpp) + const uint8_t *src, const uint8_t *last, int size, int bpp) { int i, p, r, g, b, a; @@ -271,7 +271,7 @@ void ff_png_filter_row(PNGDSPContext *dsp, uint8_t *dst, int filter_type, if (bpp == 4) { p = *(int *)dst; for (; i < size; i += bpp) { - unsigned s = *(int *)(src + i); + unsigned s = *(const int *)(src + i); p = ((s & 0x7f7f7f7f) + (p & 0x7f7f7f7f)) ^ ((s ^ p) & 0x80808080); *(int *)(dst + i) = p; } diff --git a/libavcodec/pngdsp.c b/libavcodec/pngdsp.c index fa22bfcb07..c5e870dd6e 100644 --- a/libavcodec/pngdsp.c +++ b/libavcodec/pngdsp.c @@ -40,7 +40,8 @@ typedef uint32_t uint_native; #define pb_7f (~(uint_native)0 / 255 * 0x7f) #define pb_80 (~(uint_native)0 / 255 * 0x80) -static void add_bytes_l2_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w) +static void add_bytes_l2_c(uint8_t *dst, const uint8_t *src1, + const uint8_t *src2, int w) { long i; for (i = 0; i <= w - (int) sizeof(uint_native); i += sizeof(uint_native)) { @@ -52,8 +53,8 @@ static void add_bytes_l2_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w) dst[i] = src1[i] + src2[i]; } -void ff_add_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top, - int w, int bpp) +void ff_add_png_paeth_prediction(uint8_t *dst, const uint8_t *src, + const uint8_t *top, int w, int bpp) { for (int i = 0; i < w; ++i) { int a, b, c, p, pa, pb, pc; diff --git a/libavcodec/pngdsp.h b/libavcodec/pngdsp.h index a32ffb88af..f2c4b4708f 100644 --- a/libavcodec/pngdsp.h +++ b/libavcodec/pngdsp.h @@ -28,16 +28,17 @@ typedef struct PNGDSPContext { void (*add_bytes_l2)(uint8_t *dst, - uint8_t *src1 /* align 16 */, - uint8_t *src2, int w); + const uint8_t *src1 /* align 16 */, + const uint8_t *src2, int w); /* this might write to dst[w] */ - void (*add_paeth_prediction)(uint8_t *dst, uint8_t *src, - uint8_t *top, int w, int bpp); + void (*add_paeth_prediction)(uint8_t *dst, const uint8_t *src, + const uint8_t *top, int w, int bpp); } PNGDSPContext; FF_VISIBILITY_PUSH_HIDDEN -void ff_add_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp); +void ff_add_png_paeth_prediction(uint8_t *dst, const uint8_t *src, + const uint8_t *top, int w, int bpp); void ff_pngdsp_init(PNGDSPContext *dsp); void ff_pngdsp_init_x86(PNGDSPContext *dsp); diff --git a/libavcodec/x86/pngdsp_init.c b/libavcodec/x86/pngdsp_init.c index e2cd5effe3..0af58640b8 100644 --- a/libavcodec/x86/pngdsp_init.c +++ b/libavcodec/x86/pngdsp_init.c @@ -24,12 +24,12 @@ #include "libavutil/x86/cpu.h" #include "libavcodec/pngdsp.h" -void ff_add_png_paeth_prediction_mmxext(uint8_t *dst, uint8_t *src, - uint8_t *top, int w, int bpp); -void ff_add_png_paeth_prediction_ssse3(uint8_t *dst, uint8_t *src, - uint8_t *top, int w, int bpp); -void ff_add_bytes_l2_sse2(uint8_t *dst, uint8_t *src1, - uint8_t *src2, int w); +void ff_add_png_paeth_prediction_mmxext(uint8_t *dst, const uint8_t *src, + const uint8_t *top, int w, int bpp); +void ff_add_png_paeth_prediction_ssse3(uint8_t *dst, const uint8_t *src, + const uint8_t *top, int w, int bpp); +void ff_add_bytes_l2_sse2(uint8_t *dst, const uint8_t *src1, + const uint8_t *src2, int w); av_cold void ff_pngdsp_init_x86(PNGDSPContext *dsp) { -- 2.49.1 >From 71263fdf1bb5c74dbf7d7c5f8eef70e7b6cfd205 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Tue, 6 Jan 2026 17:05:03 +0100 Subject: [PATCH 3/4] avcodec/pngdsp: Use proper prefix ff_add_png->ff_png_add Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavcodec/pngdec.c | 2 +- libavcodec/pngdsp.c | 4 ++-- libavcodec/pngdsp.h | 2 +- libavcodec/x86/pngdsp.asm | 2 +- libavcodec/x86/pngdsp_init.c | 8 ++++---- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c index 723f2aec4d..042b6a5c2f 100644 --- a/libavcodec/pngdec.c +++ b/libavcodec/pngdec.c @@ -306,7 +306,7 @@ void ff_png_filter_row(PNGDSPContext *dsp, uint8_t *dst, int filter_type, i = w; } } - ff_add_png_paeth_prediction(dst + i, src + i, last + i, size - i, bpp); + ff_png_add_paeth_prediction(dst + i, src + i, last + i, size - i, bpp); break; } } diff --git a/libavcodec/pngdsp.c b/libavcodec/pngdsp.c index c5e870dd6e..7f44563a2d 100644 --- a/libavcodec/pngdsp.c +++ b/libavcodec/pngdsp.c @@ -53,7 +53,7 @@ static void add_bytes_l2_c(uint8_t *dst, const uint8_t *src1, dst[i] = src1[i] + src2[i]; } -void ff_add_png_paeth_prediction(uint8_t *dst, const uint8_t *src, +void ff_png_add_paeth_prediction(uint8_t *dst, const uint8_t *src, const uint8_t *top, int w, int bpp) { for (int i = 0; i < w; ++i) { @@ -83,7 +83,7 @@ void ff_add_png_paeth_prediction(uint8_t *dst, const uint8_t *src, av_cold void ff_pngdsp_init(PNGDSPContext *dsp) { dsp->add_bytes_l2 = add_bytes_l2_c; - dsp->add_paeth_prediction = ff_add_png_paeth_prediction; + dsp->add_paeth_prediction = ff_png_add_paeth_prediction; #if ARCH_X86 && HAVE_X86ASM ff_pngdsp_init_x86(dsp); diff --git a/libavcodec/pngdsp.h b/libavcodec/pngdsp.h index f2c4b4708f..bd35431ae7 100644 --- a/libavcodec/pngdsp.h +++ b/libavcodec/pngdsp.h @@ -37,7 +37,7 @@ typedef struct PNGDSPContext { } PNGDSPContext; FF_VISIBILITY_PUSH_HIDDEN -void ff_add_png_paeth_prediction(uint8_t *dst, const uint8_t *src, +void ff_png_add_paeth_prediction(uint8_t *dst, const uint8_t *src, const uint8_t *top, int w, int bpp); void ff_pngdsp_init(PNGDSPContext *dsp); diff --git a/libavcodec/x86/pngdsp.asm b/libavcodec/x86/pngdsp.asm index 10a1fd648b..59d4ff5d5c 100644 --- a/libavcodec/x86/pngdsp.asm +++ b/libavcodec/x86/pngdsp.asm @@ -78,7 +78,7 @@ cglobal add_bytes_l2, 4, 6, 2, dst, src1, src2, wa, w, i RET %macro ADD_PAETH_PRED_FN 1 -cglobal add_png_paeth_prediction, 5, 7, %1, dst, src, top, w, bpp, end, cntr +cglobal png_add_paeth_prediction, 5, 7, %1, dst, src, top, w, bpp, end, cntr %if ARCH_X86_64 movsxd bppq, bppd movsxd wq, wd diff --git a/libavcodec/x86/pngdsp_init.c b/libavcodec/x86/pngdsp_init.c index 0af58640b8..36cd4c1d42 100644 --- a/libavcodec/x86/pngdsp_init.c +++ b/libavcodec/x86/pngdsp_init.c @@ -24,9 +24,9 @@ #include "libavutil/x86/cpu.h" #include "libavcodec/pngdsp.h" -void ff_add_png_paeth_prediction_mmxext(uint8_t *dst, const uint8_t *src, +void ff_png_add_paeth_prediction_mmxext(uint8_t *dst, const uint8_t *src, const uint8_t *top, int w, int bpp); -void ff_add_png_paeth_prediction_ssse3(uint8_t *dst, const uint8_t *src, +void ff_png_add_paeth_prediction_ssse3(uint8_t *dst, const uint8_t *src, const uint8_t *top, int w, int bpp); void ff_add_bytes_l2_sse2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int w); @@ -36,9 +36,9 @@ av_cold void ff_pngdsp_init_x86(PNGDSPContext *dsp) int cpu_flags = av_get_cpu_flags(); if (EXTERNAL_MMXEXT(cpu_flags)) - dsp->add_paeth_prediction = ff_add_png_paeth_prediction_mmxext; + dsp->add_paeth_prediction = ff_png_add_paeth_prediction_mmxext; if (EXTERNAL_SSE2(cpu_flags)) dsp->add_bytes_l2 = ff_add_bytes_l2_sse2; if (EXTERNAL_SSSE3(cpu_flags)) - dsp->add_paeth_prediction = ff_add_png_paeth_prediction_ssse3; + dsp->add_paeth_prediction = ff_png_add_paeth_prediction_ssse3; } -- 2.49.1 >From abe6de59585ef090af3c82f4687e0fc928e925ab Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Wed, 24 Dec 2025 13:32:09 +0100 Subject: [PATCH 4/4] avcodec/x86/pngdsp: Remove MMXEXT function overridden by SSSE3 Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavcodec/x86/pngdsp.asm | 23 ++--------------------- libavcodec/x86/pngdsp_init.c | 4 ---- 2 files changed, 2 insertions(+), 25 deletions(-) diff --git a/libavcodec/x86/pngdsp.asm b/libavcodec/x86/pngdsp.asm index 59d4ff5d5c..8ff49565d3 100644 --- a/libavcodec/x86/pngdsp.asm +++ b/libavcodec/x86/pngdsp.asm @@ -77,8 +77,8 @@ cglobal add_bytes_l2, 4, 6, 2, dst, src1, src2, wa, w, i jl .loop_s RET -%macro ADD_PAETH_PRED_FN 1 -cglobal png_add_paeth_prediction, 5, 7, %1, dst, src, top, w, bpp, end, cntr +INIT_MMX ssse3 +cglobal png_add_paeth_prediction, 5, 7, 0, dst, src, top, w, bpp, end, cntr %if ARCH_X86_64 movsxd bppq, bppd movsxd wq, wd @@ -109,21 +109,9 @@ cglobal png_add_paeth_prediction, 5, 7, %1, dst, src, top, w, bpp, end, cntr psubw m4, m0 mova m5, m3 paddw m5, m4 -%if cpuflag(ssse3) pabsw m3, m3 pabsw m4, m4 pabsw m5, m5 -%else ; !cpuflag(ssse3) - psubw m7, m5 - pmaxsw m5, m7 - pxor m6, m6 - pxor m7, m7 - psubw m6, m3 - psubw m7, m4 - pmaxsw m3, m6 - pmaxsw m4, m7 - pxor m7, m7 -%endif ; cpuflag(ssse3) mova m6, m4 pminsw m6, m5 pcmpgtw m3, m6 @@ -153,10 +141,3 @@ cglobal png_add_paeth_prediction, 5, 7, %1, dst, src, top, w, bpp, end, cntr POP dstq emms RET -%endmacro - -INIT_MMX mmxext -ADD_PAETH_PRED_FN 0 - -INIT_MMX ssse3 -ADD_PAETH_PRED_FN 0 diff --git a/libavcodec/x86/pngdsp_init.c b/libavcodec/x86/pngdsp_init.c index 36cd4c1d42..5121140dcc 100644 --- a/libavcodec/x86/pngdsp_init.c +++ b/libavcodec/x86/pngdsp_init.c @@ -24,8 +24,6 @@ #include "libavutil/x86/cpu.h" #include "libavcodec/pngdsp.h" -void ff_png_add_paeth_prediction_mmxext(uint8_t *dst, const uint8_t *src, - const uint8_t *top, int w, int bpp); void ff_png_add_paeth_prediction_ssse3(uint8_t *dst, const uint8_t *src, const uint8_t *top, int w, int bpp); void ff_add_bytes_l2_sse2(uint8_t *dst, const uint8_t *src1, @@ -35,8 +33,6 @@ av_cold void ff_pngdsp_init_x86(PNGDSPContext *dsp) { int cpu_flags = av_get_cpu_flags(); - if (EXTERNAL_MMXEXT(cpu_flags)) - dsp->add_paeth_prediction = ff_png_add_paeth_prediction_mmxext; if (EXTERNAL_SSE2(cpu_flags)) dsp->add_bytes_l2 = ff_add_bytes_l2_sse2; if (EXTERNAL_SSSE3(cpu_flags)) -- 2.49.1 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
