[FFmpeg-devel] [PATCH v1 17/23] avcodec/vvc/dsp: add adaptive_color_transform

toqsxw at gmail.com toqsxw at gmail.com
Thu May 1 17:43:15 EEST 2025


From: Wu Jianhua <toqsxw at outlook.com>

See 8.7.4.6 Residual modification process for blocks using colour space conversion

Signed-off-by: Wu Jianhua <toqsxw at outlook.com>
---
 libavcodec/vvc/dsp.h          |  2 ++
 libavcodec/vvc/dsp_template.c | 20 ++++++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/libavcodec/vvc/dsp.h b/libavcodec/vvc/dsp.h
index 25b7755109..e9ef9f5b25 100644
--- a/libavcodec/vvc/dsp.h
+++ b/libavcodec/vvc/dsp.h
@@ -127,6 +127,8 @@ typedef struct VVCItxDSPContext {
 
     void (*itx[VVC_N_TX_TYPE][VVC_N_TX_SIZE])(int *coeffs, ptrdiff_t step, size_t nz);
     void (*transform_bdpcm)(int *coeffs, int width, int height, int vertical, int log2_transform_range);
+
+    void (*adaptive_color_transform)(int *y, int *u, int *v, int width, int height);
 } VVCItxDSPContext;
 
 typedef struct VVCLMCSDSPContext {
diff --git a/libavcodec/vvc/dsp_template.c b/libavcodec/vvc/dsp_template.c
index c6dc6e22a7..218a600cce 100644
--- a/libavcodec/vvc/dsp_template.c
+++ b/libavcodec/vvc/dsp_template.c
@@ -91,6 +91,24 @@ static void FUNC(transform_bdpcm)(int *coeffs, const int width, const int height
     }
 }
 
+// 8.7.4.6 Residual modification process for blocks using colour space conversion
+static void FUNC(adaptive_color_transform)(int *y, int *u, int *v, const int width, const int height)
+{
+    const int size = width * height;
+    const int bits = BIT_DEPTH + 1;
+
+    for (int i = 0; i < size; i++) {
+        const int y0 = av_clip_intp2(y[i], bits);
+        const int cg = av_clip_intp2(u[i], bits);
+        const int co = av_clip_intp2(v[i], bits);
+        const int t  = y0 - (cg >> 1);
+
+        y[i] = cg + t;
+        u[i] = t - (co >> 1);
+        v[i] = co + u[i];
+    }
+}
+
 static void FUNC(ff_vvc_itx_dsp_init)(VVCItxDSPContext *const itx)
 {
 #define VVC_ITX(TYPE, type, s)                                                  \
@@ -112,6 +130,8 @@ static void FUNC(ff_vvc_itx_dsp_init)(VVCItxDSPContext *const itx)
     VVC_ITX_COMMON(DCT8, dct8)
     VVC_ITX_COMMON(DST7, dst7)
 
+    itx->adaptive_color_transform = FUNC(adaptive_color_transform);
+
 #undef VVC_ITX
 #undef VVC_ITX_COMMON
 }
-- 
2.44.0.windows.1



More information about the ffmpeg-devel mailing list