Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: mkver via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: mkver <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH] avcodec/h264idct_template: Deduplicate h264_{luma,chroma}_dc_dequant_idct (PR #20874)
Date: Sun, 09 Nov 2025 13:52:22 -0000
Message-ID: <176269634350.25.643446669966125103@2cb04c0e5124> (raw)

PR #20874 opened by mkver
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20874
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20874.patch


>From 0b211afaedb40de46b1fd871496b16ba0da3f6c1 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Sun, 9 Nov 2025 14:30:00 +0100
Subject: [PATCH 1/2] avcodec/bit_depth_template: Add PIXELSIZE

Sometimes functions for bit depth 9..16 are the same (because they
actually only depend on the underlying pixel type). The macros added
here allow to support this usecase.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/bit_depth_template.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/libavcodec/bit_depth_template.c b/libavcodec/bit_depth_template.c
index ca5037148a..6a80cdaf32 100644
--- a/libavcodec/bit_depth_template.c
+++ b/libavcodec/bit_depth_template.c
@@ -43,11 +43,13 @@
 #   undef FUNCC
 #   undef av_clip_pixel
 #   undef PIXEL_SPLAT_X4
+#   undef PIXELSIZE
 #else
 #   define AVCODEC_BIT_DEPTH_TEMPLATE_C
 #endif
 
 #if BIT_DEPTH > 8
+#   define PIXELSIZE 16
 #   define pixel  uint16_t
 #   define pixel2 uint32_t
 #   define pixel4 uint64_t
@@ -76,6 +78,7 @@
 #   define av_clip_pixel(a) av_clip_uintp2(a, BIT_DEPTH)
 #   define CLIP(a)          av_clip_uintp2(a, BIT_DEPTH)
 #else
+#   define PIXELSIZE 8
 #   define pixel  uint8_t
 #   define pixel2 uint16_t
 #   define pixel4 uint32_t
@@ -100,6 +103,7 @@
 #define FUNC2(a, b, c)  FUNC3(a, b, c)
 #define FUNC(a)  FUNC2(a, BIT_DEPTH,)
 #define FUNCC(a) FUNC2(a, BIT_DEPTH, _c)
+#define FUNCC2(a) FUNC2(a, PIXELSIZE, _c)
 #define FUNC4(a, b, c)  a ## _int ## b ## _ ## c ## bit
 #define FUNC5(a, b, c)  FUNC4(a, b, c)
 #define FUNC6(a)  FUNC5(a, IN_IDCT_DEPTH, BIT_DEPTH)
-- 
2.49.1


>From 5d99c5529ecade161610af37f9e4a9daa5aba2d5 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Sun, 9 Nov 2025 14:41:16 +0100
Subject: [PATCH 2/2] avcodec/h264idct_template: Deduplicate
 h264_{luma,chroma}_dc_dequant_idct

All the high bit depth functions of these types are identical.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/h264dsp.c           | 16 ++++++++--------
 libavcodec/h264idct.h          | 11 ++++++++---
 libavcodec/h264idct_template.c | 11 ++++++++---
 3 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/libavcodec/h264dsp.c b/libavcodec/h264dsp.c
index 1ba936be1c..8a6a3f5325 100644
--- a/libavcodec/h264dsp.c
+++ b/libavcodec/h264dsp.c
@@ -69,14 +69,19 @@ av_cold void ff_h264dsp_init(H264DSPContext *c, const int bit_depth,
 #undef FUNC
 #define FUNC(a, depth) a ## _ ## depth ## _c
 
-#define ADDPX_DSP(depth) \
+#define SET_PIXSIZE_FUNCS(depth) \
+    c->h264_luma_dc_dequant_idct= FUNC(ff_h264_luma_dc_dequant_idct, depth);\
+    if (chroma_format_idc <= 1)\
+        c->h264_chroma_dc_dequant_idct= FUNC(ff_h264_chroma_dc_dequant_idct, depth);\
+    else\
+        c->h264_chroma_dc_dequant_idct= FUNC(ff_h264_chroma422_dc_dequant_idct, depth);\
     c->h264_add_pixels4_clear = FUNC(ff_h264_add_pixels4, depth);\
     c->h264_add_pixels8_clear = FUNC(ff_h264_add_pixels8, depth)
 
     if (bit_depth > 8 && bit_depth <= 16) {
-        ADDPX_DSP(16);
+        SET_PIXSIZE_FUNCS(16);
     } else {
-        ADDPX_DSP(8);
+        SET_PIXSIZE_FUNCS(8);
     }
 
 #define H264_DSP(depth) \
@@ -91,11 +96,6 @@ av_cold void ff_h264dsp_init(H264DSPContext *c, const int bit_depth,
     else\
         c->h264_idct_add8  = FUNC(ff_h264_idct_add8_422, depth);\
     c->h264_idct_add16intra= FUNC(ff_h264_idct_add16intra, depth);\
-    c->h264_luma_dc_dequant_idct= FUNC(ff_h264_luma_dc_dequant_idct, depth);\
-    if (chroma_format_idc <= 1)\
-        c->h264_chroma_dc_dequant_idct= FUNC(ff_h264_chroma_dc_dequant_idct, depth);\
-    else\
-        c->h264_chroma_dc_dequant_idct= FUNC(ff_h264_chroma422_dc_dequant_idct, depth);\
 \
     c->weight_h264_pixels_tab[0]= FUNC(weight_h264_pixels16, depth);\
     c->weight_h264_pixels_tab[1]= FUNC(weight_h264_pixels8, depth);\
diff --git a/libavcodec/h264idct.h b/libavcodec/h264idct.h
index 6f18df9e5f..42e93ed17a 100644
--- a/libavcodec/h264idct.h
+++ b/libavcodec/h264idct.h
@@ -31,9 +31,6 @@ void ff_h264_idct_add16intra_ ## depth ## _c(uint8_t *dst, const int *blockoffse
 void ff_h264_idct8_add4_ ## depth ## _c(uint8_t *dst, const int *blockoffset, int16_t *block, int stride, const uint8_t nnzc[5 * 8]);\
 void ff_h264_idct_add8_422_ ## depth ## _c(uint8_t **dest, const int *blockoffset, int16_t *block, int stride, const uint8_t nnzc[15 * 8]);\
 void ff_h264_idct_add8_ ## depth ## _c(uint8_t **dest, const int *blockoffset, int16_t *block, int stride, const uint8_t nnzc[15 * 8]);\
-void ff_h264_luma_dc_dequant_idct_ ## depth ## _c(int16_t *output, int16_t *input, int qmul);\
-void ff_h264_chroma422_dc_dequant_idct_ ## depth ## _c(int16_t *block, int qmul);\
-void ff_h264_chroma_dc_dequant_idct_ ## depth ## _c(int16_t *block, int qmul);
 
 H264_IDCT( 8)
 H264_IDCT( 9)
@@ -41,4 +38,12 @@ H264_IDCT(10)
 H264_IDCT(12)
 H264_IDCT(14)
 
+#define H264_IDCT2(pixsize) \
+void ff_h264_luma_dc_dequant_idct_ ## pixsize ## _c(int16_t *output, int16_t *input, int qmul);\
+void ff_h264_chroma422_dc_dequant_idct_ ## pixsize ## _c(int16_t *block, int qmul);\
+void ff_h264_chroma_dc_dequant_idct_ ## pixsize ## _c(int16_t *block, int qmul);
+
+H264_IDCT2( 8)
+H264_IDCT2(16)
+
 #endif /* AVCODEC_H264IDCT_H */
diff --git a/libavcodec/h264idct_template.c b/libavcodec/h264idct_template.c
index db19b5f9fb..64f5faddca 100644
--- a/libavcodec/h264idct_template.c
+++ b/libavcodec/h264idct_template.c
@@ -244,11 +244,13 @@ void FUNCC(ff_h264_idct_add8_422)(uint8_t **dest, const int *block_offset, int16
     }
 }
 
+#if BIT_DEPTH == 8 || BIT_DEPTH == 9
 /**
  * IDCT transforms the 16 dc values and dequantizes them.
  * @param qmul quantization parameter
  */
-void FUNCC(ff_h264_luma_dc_dequant_idct)(int16_t *_output, int16_t *_input, int qmul){
+void FUNCC2(ff_h264_luma_dc_dequant_idct)(int16_t *_output, int16_t *_input, int qmul)
+{
 #define stride 16
     int i;
     int temp[16];
@@ -283,7 +285,8 @@ void FUNCC(ff_h264_luma_dc_dequant_idct)(int16_t *_output, int16_t *_input, int
 #undef stride
 }
 
-void FUNCC(ff_h264_chroma422_dc_dequant_idct)(int16_t *_block, int qmul){
+void FUNCC2(ff_h264_chroma422_dc_dequant_idct)(int16_t *_block, int qmul)
+{
     const int stride= 16*2;
     const int xStride= 16;
     int i;
@@ -310,7 +313,8 @@ void FUNCC(ff_h264_chroma422_dc_dequant_idct)(int16_t *_block, int qmul){
     }
 }
 
-void FUNCC(ff_h264_chroma_dc_dequant_idct)(int16_t *_block, int qmul){
+void FUNCC2(ff_h264_chroma_dc_dequant_idct)(int16_t *_block, int qmul)
+{
     const int stride= 16*2;
     const int xStride= 16;
     SUINT a,b,c,d,e;
@@ -331,3 +335,4 @@ void FUNCC(ff_h264_chroma_dc_dequant_idct)(int16_t *_block, int qmul){
     block[stride*1 + xStride*0]= (int)((a-c)*qmul) >> 7;
     block[stride*1 + xStride*1]= (int)((e-b)*qmul) >> 7;
 }
+#endif
-- 
2.49.1

_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

                 reply	other threads:[~2025-11-09 13:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=176269634350.25.643446669966125103@2cb04c0e5124 \
    --to=ffmpeg-devel@ffmpeg.org \
    --cc=code@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git