Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH v1 01/23] avcodec/vvc/cabac: add 9.3.3.5 k-th order Exp - Golomb binarization process
@ 2025-05-14 13:40 toqsxw
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 02/23] avcodec/vvc/cabac: add 9.3.3.7 Fixed-length " toqsxw
                   ` (22 more replies)
  0 siblings, 23 replies; 26+ messages in thread
From: toqsxw @ 2025-05-14 13:40 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Wu Jianhua

From: Wu Jianhua <toqsxw@outlook.com>

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
---
 libavcodec/vvc/cabac.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/libavcodec/vvc/cabac.c b/libavcodec/vvc/cabac.c
index 5510144893..54055ed736 100644
--- a/libavcodec/vvc/cabac.c
+++ b/libavcodec/vvc/cabac.c
@@ -928,6 +928,27 @@ static int truncated_binary_decode(VVCLocalContext *lc, const int c_max)
     return v;
 }
 
+// 9.3.3.5 k-th order Exp - Golomb binarization process
+static int kth_order_egk_decode(CABACContext *c, int k)
+{
+    int bit    = 1;
+    int value  = 0;
+    int symbol = 0;
+
+    while (bit) {
+        bit = get_cabac_bypass(c);
+        value += bit << k++;
+    }
+
+    if (--k) {
+        for (int i = 0; i < k; i++)
+            symbol = (symbol << 1) | get_cabac_bypass(c);
+        value += symbol;
+    }
+
+    return value;
+}
+
 // 9.3.3.6 Limited k-th order Exp-Golomb binarization process
 static int limited_kth_order_egk_decode(CABACContext *c, const int k, const int max_pre_ext_len, const int trunc_suffix_len)
 {
-- 
2.44.0.windows.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [FFmpeg-devel] [PATCH v1 02/23] avcodec/vvc/cabac: add 9.3.3.7 Fixed-length binarization process
  2025-05-14 13:40 [FFmpeg-devel] [PATCH v1 01/23] avcodec/vvc/cabac: add 9.3.3.5 k-th order Exp - Golomb binarization process toqsxw
@ 2025-05-14 13:40 ` toqsxw
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 03/23] avcodec/vvc/cabac: add palette support toqsxw
                   ` (21 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: toqsxw @ 2025-05-14 13:40 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Wu Jianhua

From: Wu Jianhua <toqsxw@outlook.com>

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
---
 libavcodec/vvc/cabac.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/libavcodec/vvc/cabac.c b/libavcodec/vvc/cabac.c
index 54055ed736..9290ecd90f 100644
--- a/libavcodec/vvc/cabac.c
+++ b/libavcodec/vvc/cabac.c
@@ -968,6 +968,17 @@ static int limited_kth_order_egk_decode(CABACContext *c, const int k, const int
     return val;
 }
 
+// 9.3.3.7 Fixed-length binarization process
+static int fixed_length_decode(CABACContext* c, const int len)
+{
+    int value = 0;
+
+    for (int i = 0; i < len; i++)
+        value = (value << 1) | get_cabac_bypass(c);
+
+    return value;
+}
+
 static av_always_inline
 void get_left_top(const VVCLocalContext *lc, uint8_t *left, uint8_t *top,
     const int x0, const int y0, const uint8_t *left_ctx, const uint8_t *top_ctx)
@@ -1011,11 +1022,7 @@ int ff_vvc_sao_type_idx_decode(VVCLocalContext *lc)
 
 int ff_vvc_sao_band_position_decode(VVCLocalContext *lc)
 {
-    int value = get_cabac_bypass(&lc->ep->cc);
-
-    for (int i = 0; i < 4; i++)
-        value = (value << 1) | get_cabac_bypass(&lc->ep->cc);
-    return value;
+    return fixed_length_decode(&lc->ep->cc, 5);
 }
 
 int ff_vvc_sao_offset_abs_decode(VVCLocalContext *lc)
@@ -1035,9 +1042,7 @@ int ff_vvc_sao_offset_sign_decode(VVCLocalContext *lc)
 
 int ff_vvc_sao_eo_class_decode(VVCLocalContext *lc)
 {
-    int ret = get_cabac_bypass(&lc->ep->cc) << 1;
-    ret    |= get_cabac_bypass(&lc->ep->cc);
-    return ret;
+    return (get_cabac_bypass(&lc->ep->cc) << 1) | get_cabac_bypass(&lc->ep->cc);
 }
 
 int ff_vvc_alf_ctb_flag(VVCLocalContext *lc, const int rx, const int ry, const int c_idx)
@@ -1479,12 +1484,7 @@ int ff_vvc_merge_idx(VVCLocalContext *lc)
 
 int ff_vvc_merge_gpm_partition_idx(VVCLocalContext *lc)
 {
-    int i = 0;
-
-    for (int j = 0; j < 6; j++)
-        i = (i << 1) | get_cabac_bypass(&lc->ep->cc);
-
-    return i;
+    return fixed_length_decode(&lc->ep->cc, 6);
 }
 
 int ff_vvc_merge_gpm_idx(VVCLocalContext *lc, const int idx)
-- 
2.44.0.windows.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [FFmpeg-devel] [PATCH v1 03/23] avcodec/vvc/cabac: add palette support
  2025-05-14 13:40 [FFmpeg-devel] [PATCH v1 01/23] avcodec/vvc/cabac: add 9.3.3.5 k-th order Exp - Golomb binarization process toqsxw
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 02/23] avcodec/vvc/cabac: add 9.3.3.7 Fixed-length " toqsxw
@ 2025-05-14 13:40 ` toqsxw
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 04/23] avcodec/vvc: add VVC_MAX_NUM_PALETTE_PREDICTOR_SIZE toqsxw
                   ` (20 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: toqsxw @ 2025-05-14 13:40 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Wu Jianhua

From: Wu Jianhua <toqsxw@outlook.com>

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
---
 libavcodec/vvc/cabac.c | 52 ++++++++++++++++++++++++++++++++++++++++++
 libavcodec/vvc/cabac.h |  9 ++++++++
 2 files changed, 61 insertions(+)

diff --git a/libavcodec/vvc/cabac.c b/libavcodec/vvc/cabac.c
index 9290ecd90f..700b719b7c 100644
--- a/libavcodec/vvc/cabac.c
+++ b/libavcodec/vvc/cabac.c
@@ -1377,6 +1377,58 @@ int ff_vvc_intra_chroma_pred_mode(VVCLocalContext *lc)
     return (get_cabac_bypass(&lc->ep->cc) << 1) | get_cabac_bypass(&lc->ep->cc);
 }
 
+int ff_vvc_palette_predictor_run(VVCLocalContext *lc)
+{
+    return kth_order_egk_decode(&lc->ep->cc, 0);
+}
+
+int ff_vvc_num_signalled_palette_entries(VVCLocalContext *lc)
+{
+    return kth_order_egk_decode(&lc->ep->cc, 0);
+}
+
+int ff_vvc_new_palette_entries(VVCLocalContext *lc, const int bit_depth)
+{
+    return fixed_length_decode(&lc->ep->cc, bit_depth);
+}
+
+bool ff_vvc_palette_escape_val_present_flag(VVCLocalContext *lc)
+{
+    return get_cabac_bypass(&lc->ep->cc);
+}
+
+bool ff_vvc_palette_transpose_flag(VVCLocalContext *lc)
+{
+    return GET_CABAC(PALETTE_TRANSPOSE_FLAG);
+}
+
+bool ff_vvc_run_copy_flag(VVCLocalContext *lc, const int prev_run_type, const int prev_run_position, const int cur_pos)
+{
+    uint8_t run_left_lut[] = { 0, 1, 2, 3, 4 };
+    uint8_t run_top_lut[] = { 5, 6, 6, 7, 7 };
+
+    int bin_dist = cur_pos - prev_run_position - 1;
+    uint8_t *run_lut = prev_run_type == 1 ? run_top_lut : run_left_lut;
+    uint8_t ctx_inc = bin_dist <= 4 ? run_lut[bin_dist] : run_lut[4];
+
+    return GET_CABAC(RUN_COPY_FLAG + ctx_inc);
+}
+
+bool ff_vvc_copy_above_palette_indices_flag(VVCLocalContext *lc)
+{
+    return GET_CABAC(COPY_ABOVE_PALETTE_INDICES_FLAG);
+}
+
+int ff_vvc_palette_idx_idc(VVCLocalContext *lc, const int max_palette_index, const bool adjust)
+{
+    return truncated_binary_decode(lc, max_palette_index - adjust);
+}
+
+int ff_vvc_palette_escape_val(VVCLocalContext *lc)
+{
+    return kth_order_egk_decode(&lc->ep->cc, 5);
+}
+
 int ff_vvc_general_merge_flag(VVCLocalContext *lc)
 {
     return GET_CABAC(GENERAL_MERGE_FLAG);
diff --git a/libavcodec/vvc/cabac.h b/libavcodec/vvc/cabac.h
index e9bc98e23a..92f0163c85 100644
--- a/libavcodec/vvc/cabac.h
+++ b/libavcodec/vvc/cabac.h
@@ -81,6 +81,15 @@ int ff_vvc_intra_luma_mpm_remainder(VVCLocalContext *lc);
 int ff_vvc_cclm_mode_flag(VVCLocalContext *lc);
 int ff_vvc_cclm_mode_idx(VVCLocalContext *lc);
 int ff_vvc_intra_chroma_pred_mode(VVCLocalContext *lc);
+int ff_vvc_palette_predictor_run(VVCLocalContext *lc);
+int ff_vvc_num_signalled_palette_entries(VVCLocalContext *lc);
+int ff_vvc_new_palette_entries(VVCLocalContext *lc, int bit_dpeth);
+bool ff_vvc_palette_escape_val_present_flag(VVCLocalContext *lc);
+bool ff_vvc_palette_transpose_flag(VVCLocalContext *lc);
+bool ff_vvc_run_copy_flag(VVCLocalContext *lc, int prev_run_type, int prev_run_position, int cur_pos);
+bool ff_vvc_copy_above_palette_indices_flag(VVCLocalContext *lc);
+int ff_vvc_palette_idx_idc(VVCLocalContext *lc, int max_palette_index, bool adjust);
+int ff_vvc_palette_escape_val(VVCLocalContext *lc);
 
 //inter
 int ff_vvc_general_merge_flag(VVCLocalContext *lc);
-- 
2.44.0.windows.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [FFmpeg-devel] [PATCH v1 04/23] avcodec/vvc: add VVC_MAX_NUM_PALETTE_PREDICTOR_SIZE
  2025-05-14 13:40 [FFmpeg-devel] [PATCH v1 01/23] avcodec/vvc/cabac: add 9.3.3.5 k-th order Exp - Golomb binarization process toqsxw
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 02/23] avcodec/vvc/cabac: add 9.3.3.7 Fixed-length " toqsxw
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 03/23] avcodec/vvc/cabac: add palette support toqsxw
@ 2025-05-14 13:40 ` toqsxw
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 05/23] avcodec/vvc/ctu: refact out ff_vvc_channel_range toqsxw
                   ` (19 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: toqsxw @ 2025-05-14 13:40 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Wu Jianhua

From: Wu Jianhua <toqsxw@outlook.com>

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
---
 libavcodec/vvc.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavcodec/vvc.h b/libavcodec/vvc.h
index 92639779c1..5490ddb4c8 100644
--- a/libavcodec/vvc.h
+++ b/libavcodec/vvc.h
@@ -154,6 +154,9 @@ enum {
 
     // {sps, ph}_num_{ver, hor}_virtual_boundaries should in [0, 3]
     VVC_MAX_VBS = 3,
+
+    // 8.4.5.3 Decoding process for palette mode - maxNumPalettePredictorSize
+    VVC_MAX_NUM_PALETTE_PREDICTOR_SIZE = 63
 };
 
 #endif /* AVCODEC_VVC_H */
-- 
2.44.0.windows.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [FFmpeg-devel] [PATCH v1 05/23] avcodec/vvc/ctu: refact out ff_vvc_channel_range
  2025-05-14 13:40 [FFmpeg-devel] [PATCH v1 01/23] avcodec/vvc/cabac: add 9.3.3.5 k-th order Exp - Golomb binarization process toqsxw
                   ` (2 preceding siblings ...)
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 04/23] avcodec/vvc: add VVC_MAX_NUM_PALETTE_PREDICTOR_SIZE toqsxw
@ 2025-05-14 13:40 ` toqsxw
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 06/23] avcodec/vvc: refact out ep_init and ep_init_wpp toqsxw
                   ` (18 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: toqsxw @ 2025-05-14 13:40 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Wu Jianhua

From: Wu Jianhua <toqsxw@outlook.com>

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
---
 libavcodec/vvc/ctu.c   | 16 ++++++++++++----
 libavcodec/vvc/ctu.h   |  1 +
 libavcodec/vvc/intra.c |  8 ++++----
 3 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/libavcodec/vvc/ctu.c b/libavcodec/vvc/ctu.c
index 080b740cc6..c621b6d5d6 100644
--- a/libavcodec/vvc/ctu.c
+++ b/libavcodec/vvc/ctu.c
@@ -501,13 +501,12 @@ static int skipped_transform_tree(VVCLocalContext *lc, int x0, int y0,int tu_wid
             SKIPPED_TRANSFORM_TREE(x0, y0 + trafo_height);
     } else {
         TransformUnit *tu    = add_tu(fc, lc->cu, x0, y0, tu_width, tu_height);
-        const int has_chroma = sps->r->sps_chroma_format_idc && cu->tree_type != DUAL_TREE_LUMA;
-        const int c_start    = cu->tree_type == DUAL_TREE_CHROMA ? CB : LUMA;
-        const int c_end      = has_chroma ? VVC_MAX_SAMPLE_ARRAYS : CB;
+        int start, end;
 
         if (!tu)
             return AVERROR_INVALIDDATA;
-        for (int i = c_start; i < c_end; i++) {
+        ff_vvc_channel_range(&start, &end, cu->tree_type, sps->r->sps_chroma_format_idc);
+        for (int i = start; i < end; i++) {
             TransformBlock *tb = add_tb(tu, lc, x0, y0, tu_width >> sps->hshift[i], tu_height >> sps->vshift[i], i);
             if (i != CR)
                 set_tb_size(fc, tb);
@@ -2580,3 +2579,12 @@ void ff_vvc_ep_init_stat_coeff(EntryPoint *ep,
             persistent_rice_adaptation_enabled_flag ? 2 * (av_log2(bit_depth - 10)) : 0;
     }
 }
+
+void ff_vvc_channel_range(int *start, int *end, const VVCTreeType tree_type, const uint8_t chroma_format_idc)
+{
+    const bool has_chroma = chroma_format_idc && tree_type != DUAL_TREE_LUMA;
+    const bool has_luma   = tree_type != DUAL_TREE_CHROMA;
+
+    *start = has_luma   ? LUMA : CB;
+    *end   = has_chroma ? VVC_MAX_SAMPLE_ARRAYS : CB;
+}
diff --git a/libavcodec/vvc/ctu.h b/libavcodec/vvc/ctu.h
index c5533c1ad0..dab6f453f1 100644
--- a/libavcodec/vvc/ctu.h
+++ b/libavcodec/vvc/ctu.h
@@ -489,5 +489,6 @@ void ff_vvc_decode_neighbour(VVCLocalContext *lc, int x_ctb, int y_ctb, int rx,
 void ff_vvc_ctu_free_cus(CodingUnit **cus);
 int ff_vvc_get_qPy(const VVCFrameContext *fc, int xc, int yc);
 void ff_vvc_ep_init_stat_coeff(EntryPoint *ep, int bit_depth, int persistent_rice_adaptation_enabled_flag);
+void ff_vvc_channel_range(int *start, int *end, VVCTreeType tree_type, uint8_t chroma_format_idc);
 
 #endif // AVCODEC_VVC_CTU_H
diff --git a/libavcodec/vvc/intra.c b/libavcodec/vvc/intra.c
index 41ed89c946..2e6cb8f09e 100644
--- a/libavcodec/vvc/intra.c
+++ b/libavcodec/vvc/intra.c
@@ -639,11 +639,11 @@ static void ibc_fill_vir_buf(const VVCLocalContext *lc, const CodingUnit *cu)
 {
     const VVCFrameContext *fc = lc->fc;
     const VVCSPS *sps         = fc->ps.sps;
-    const int has_chroma      = sps->r->sps_chroma_format_idc && cu->tree_type != DUAL_TREE_LUMA;
-    const int start           = cu->tree_type == DUAL_TREE_CHROMA;
-    const int end             = has_chroma ? CR : LUMA;
+    int start, end;
 
-    for (int c_idx = start; c_idx <= end; c_idx++) {
+    ff_vvc_channel_range(&start, &end, cu->tree_type, sps->r->sps_chroma_format_idc);
+
+    for (int c_idx = start; c_idx < end; c_idx++) {
         const int hs = sps->hshift[c_idx];
         const int vs = sps->vshift[c_idx];
         const int ps = sps->pixel_shift;
-- 
2.44.0.windows.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [FFmpeg-devel] [PATCH v1 06/23] avcodec/vvc: refact out ep_init and ep_init_wpp
  2025-05-14 13:40 [FFmpeg-devel] [PATCH v1 01/23] avcodec/vvc/cabac: add 9.3.3.5 k-th order Exp - Golomb binarization process toqsxw
                   ` (3 preceding siblings ...)
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 05/23] avcodec/vvc/ctu: refact out ff_vvc_channel_range toqsxw
@ 2025-05-14 13:40 ` toqsxw
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 07/23] avcodec/vvc: refact, save pf and ciip_flag in ff_vvc_set_intra_mvf toqsxw
                   ` (17 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: toqsxw @ 2025-05-14 13:40 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Wu Jianhua

From: Wu Jianhua <toqsxw@outlook.com>

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
---
 libavcodec/vvc/dec.c    | 48 ++++++++++++++++++++++++++---------------
 libavcodec/vvc/thread.c | 12 +++++++----
 2 files changed, 39 insertions(+), 21 deletions(-)

diff --git a/libavcodec/vvc/dec.c b/libavcodec/vvc/dec.c
index f860e116ab..09b0053703 100644
--- a/libavcodec/vvc/dec.c
+++ b/libavcodec/vvc/dec.c
@@ -506,23 +506,18 @@ static int slices_realloc(VVCFrameContext *fc)
     return 0;
 }
 
-static int ep_init_cabac_decoder(SliceContext *sc, const int index,
-    const H2645NAL *nal, GetBitContext *gb, const CodedBitstreamUnit *unit)
+static int get_ep_size(const H266RawSliceHeader *rsh, GetBitContext *gb, const H2645NAL *nal, const int header_size, const int ep_index)
 {
-    const H266RawSlice *slice     = unit->content_ref;
-    const H266RawSliceHeader *rsh = sc->sh.r;
-    EntryPoint *ep                = sc->eps + index;
     int size;
-    int ret;
 
-    if (index < rsh->num_entry_points) {
+    if (ep_index < rsh->num_entry_points) {
         int skipped = 0;
         int64_t start =  (gb->index >> 3);
-        int64_t end = start + rsh->sh_entry_point_offset_minus1[index] + 1;
-        while (skipped < nal->skipped_bytes && nal->skipped_bytes_pos[skipped] <= start + slice->header_size) {
+        int64_t end = start + rsh->sh_entry_point_offset_minus1[ep_index] + 1;
+        while (skipped < nal->skipped_bytes && nal->skipped_bytes_pos[skipped] <= start + header_size) {
             skipped++;
         }
-        while (skipped < nal->skipped_bytes && nal->skipped_bytes_pos[skipped] <= end + slice->header_size) {
+        while (skipped < nal->skipped_bytes && nal->skipped_bytes_pos[skipped] <= end + header_size) {
             end--;
             skipped++;
         }
@@ -531,6 +526,13 @@ static int ep_init_cabac_decoder(SliceContext *sc, const int index,
     } else {
         size = get_bits_left(gb) / 8;
     }
+    return size;
+}
+
+static int ep_init_cabac_decoder(EntryPoint *ep, GetBitContext *gb, const int size)
+{
+    int ret;
+
     av_assert0(gb->buffer + get_bits_count(gb) / 8 + size <= gb->buffer_end);
     ret = ff_init_cabac_decoder (&ep->cc, gb->buffer + get_bits_count(gb) / 8, size);
     if (ret < 0)
@@ -539,6 +541,19 @@ static int ep_init_cabac_decoder(SliceContext *sc, const int index,
     return 0;
 }
 
+static int ep_init(EntryPoint *ep, const int ctu_addr, const int ctu_end, GetBitContext *gb, const int size)
+{
+    const int ret = ep_init_cabac_decoder(ep, gb, size);
+
+    if (ret < 0)
+        return ret;
+
+    ep->ctu_start = ctu_addr;
+    ep->ctu_end   = ctu_end;
+
+    return 0;
+}
+
 static int slice_init_entry_points(SliceContext *sc,
     VVCFrameContext *fc, const H2645NAL *nal, const CodedBitstreamUnit *unit)
 {
@@ -562,20 +577,19 @@ static int slice_init_entry_points(SliceContext *sc,
         return ret;
     for (int i = 0; i < sc->nb_eps; i++)
     {
-        EntryPoint *ep = sc->eps + i;
+        const int size    = get_ep_size(sc->sh.r, &gb, nal, slice->header_size, i);
+        const int ctu_end = (i + 1 == sc->nb_eps ? sh->num_ctus_in_curr_slice : sh->entry_point_start_ctu[i]);
+        EntryPoint *ep    = sc->eps + i;
 
-        ep->ctu_start = ctu_addr;
-        ep->ctu_end   = (i + 1 == sc->nb_eps ? sh->num_ctus_in_curr_slice : sh->entry_point_start_ctu[i]);
+        ret = ep_init(ep, ctu_addr, ctu_end, &gb, size);
+        if (ret < 0)
+            return ret;
 
         for (int j = ep->ctu_start; j < ep->ctu_end; j++) {
             const int rs = sc->sh.ctb_addr_in_curr_slice[j];
             fc->tab.slice_idx[rs] = sc->slice_idx;
         }
 
-        ret = ep_init_cabac_decoder(sc, i, nal, &gb, unit);
-        if (ret < 0)
-            return ret;
-
         if (i + 1 < sc->nb_eps)
             ctu_addr = sh->entry_point_start_ctu[i];
     }
diff --git a/libavcodec/vvc/thread.c b/libavcodec/vvc/thread.c
index 6194416e14..e1d64bd3d2 100644
--- a/libavcodec/vvc/thread.c
+++ b/libavcodec/vvc/thread.c
@@ -283,6 +283,12 @@ static void add_progress_listener(VVCFrame *ref, ProgressListener *l,
     ff_vvc_add_progress_listener(ref, (VVCProgressListener*)l);
 }
 
+static void ep_init_wpp(EntryPoint *next, const EntryPoint *ep, const VVCSPS *sps)
+{
+    memcpy(next->cabac_state, ep->cabac_state, sizeof(next->cabac_state));
+    ff_vvc_ep_init_stat_coeff(next, sps->bit_depth, sps->r->sps_persistent_rice_adaptation_enabled_flag);
+}
+
 static void schedule_next_parse(VVCContext *s, VVCFrameContext *fc, const SliceContext *sc, const VVCTask *t)
 {
     VVCFrameThread *ft = fc->ft;
@@ -292,10 +298,8 @@ static void schedule_next_parse(VVCContext *s, VVCFrameContext *fc, const SliceC
     if (sps->r->sps_entropy_coding_sync_enabled_flag) {
         if (t->rx == fc->ps.pps->ctb_to_col_bd[t->rx]) {
             EntryPoint *next = ep + 1;
-            if (next < sc->eps + sc->nb_eps && !is_first_row(fc, t->rx, t->ry + 1)) {
-                memcpy(next->cabac_state, ep->cabac_state, sizeof(next->cabac_state));
-                ff_vvc_ep_init_stat_coeff(next, sps->bit_depth, sps->r->sps_persistent_rice_adaptation_enabled_flag);
-            }
+            if (next < sc->eps + sc->nb_eps && !is_first_row(fc, t->rx, t->ry + 1))
+                ep_init_wpp(next, ep, sps);
         }
         if (t->ry + 1 < ft->ctu_height && !is_first_row(fc, t->rx, t->ry + 1))
             frame_thread_add_score(s, ft, t->rx, t->ry + 1, VVC_TASK_STAGE_PARSE);
-- 
2.44.0.windows.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [FFmpeg-devel] [PATCH v1 07/23] avcodec/vvc: refact, save pf and ciip_flag in ff_vvc_set_intra_mvf
  2025-05-14 13:40 [FFmpeg-devel] [PATCH v1 01/23] avcodec/vvc/cabac: add 9.3.3.5 k-th order Exp - Golomb binarization process toqsxw
                   ` (4 preceding siblings ...)
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 06/23] avcodec/vvc: refact out ep_init and ep_init_wpp toqsxw
@ 2025-05-14 13:40 ` toqsxw
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 08/23] avcodec/vvc/ctu: refact out intra_data toqsxw
                   ` (16 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: toqsxw @ 2025-05-14 13:40 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Wu Jianhua

From: Wu Jianhua <toqsxw@outlook.com>

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
---
 libavcodec/vvc/ctu.c |  4 ++--
 libavcodec/vvc/mvs.c | 24 ++++++++++++++++++++----
 libavcodec/vvc/mvs.h |  2 +-
 3 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/libavcodec/vvc/ctu.c b/libavcodec/vvc/ctu.c
index c621b6d5d6..f77697af08 100644
--- a/libavcodec/vvc/ctu.c
+++ b/libavcodec/vvc/ctu.c
@@ -1756,7 +1756,7 @@ static void fill_dmvr_info(const VVCLocalContext *lc)
     const CodingUnit *cu      = lc->cu;
 
     if (cu->pred_mode == MODE_IBC) {
-        ff_vvc_set_intra_mvf(lc, 1);
+        ff_vvc_set_intra_mvf(lc, true, PF_IBC, false);
     } else {
         const VVCPPS *pps = fc->ps.pps;
         const int w       = cu->cb_width >> MIN_PU_LOG2;
@@ -1849,8 +1849,8 @@ static int hls_coding_unit(VVCLocalContext *lc, int x0, int y0, int cb_width, in
                 return AVERROR_PATCHWELCOME;
             } else {
                 intra_luma_pred_modes(lc);
+                ff_vvc_set_intra_mvf(lc, false, PF_INTRA, cu->ciip_flag);
             }
-            ff_vvc_set_intra_mvf(lc, 0);
         }
         if ((tree_type == SINGLE_TREE || tree_type == DUAL_TREE_CHROMA) && sps->r->sps_chroma_format_idc) {
             if (pred_mode_plt_flag && tree_type == DUAL_TREE_CHROMA) {
diff --git a/libavcodec/vvc/mvs.c b/libavcodec/vvc/mvs.c
index 566df158a8..8946b00b5b 100644
--- a/libavcodec/vvc/mvs.c
+++ b/libavcodec/vvc/mvs.c
@@ -144,7 +144,8 @@ static int derive_temporal_colocated_mvs(const VVCLocalContext *lc, MvField temp
     const SliceContext *sc      = lc->sc;
     RefPicList* refPicList      = sc->rpl;
 
-    if (temp_col.pred_flag == PF_INTRA)
+    if (temp_col.pred_flag == PF_INTRA ||
+        temp_col.pred_flag == PF_IBC)
         return 0;
 
     if (sb_flag){
@@ -266,7 +267,7 @@ void ff_vvc_set_mvf(const VVCLocalContext *lc, const int x0, const int y0, const
     }
 }
 
-void ff_vvc_set_intra_mvf(const VVCLocalContext *lc, const int dmvr)
+void ff_vvc_set_intra_mvf(const VVCLocalContext *lc, const bool dmvr, const PredFlag pf, const bool ciip_flag)
 {
     const VVCFrameContext *fc   = lc->fc;
     const CodingUnit *cu        = lc->cu;
@@ -277,7 +278,10 @@ void ff_vvc_set_intra_mvf(const VVCLocalContext *lc, const int dmvr)
         for (int dx = 0; dx < cu->cb_width; dx += min_pu_size) {
             const int x = cu->x0 + dx;
             const int y = cu->y0 + dy;
-            TAB_MVF(x, y).pred_flag = PF_INTRA;
+            MvField *mv = &TAB_MVF(x, y);
+
+            mv->pred_flag = pf;
+            mv->ciip_flag = ciip_flag;
         }
     }
 }
@@ -599,7 +603,19 @@ static void init_neighbour_context(NeighbourContext *ctx, const VVCLocalContext
 
 static av_always_inline PredMode pred_flag_to_mode(PredFlag pred)
 {
-    return pred == PF_IBC ? MODE_IBC : (pred == PF_INTRA ? MODE_INTRA : MODE_INTER);
+    static const PredMode lut[] = {
+        MODE_INTRA, // PF_INTRA
+        MODE_INTER, // PF_L0
+        MODE_INTER, // PF_L1
+        MODE_INTER, // PF_BI
+        0,          // invalid
+        MODE_IBC,   // PF_IBC
+        0,          // invalid
+        0,          // invalid
+        MODE_PLT,   // PF_PLT
+    };
+
+    return lut[pred];
 }
 
 static int check_available(Neighbour *n, const VVCLocalContext *lc, const int check_mer)
diff --git a/libavcodec/vvc/mvs.h b/libavcodec/vvc/mvs.h
index b2242b2a4d..7150c0b8cf 100644
--- a/libavcodec/vvc/mvs.h
+++ b/libavcodec/vvc/mvs.h
@@ -43,6 +43,6 @@ void ff_vvc_update_hmvp(VVCLocalContext *lc, const MotionInfo *mi);
 int ff_vvc_no_backward_pred_flag(const VVCLocalContext *lc);
 MvField* ff_vvc_get_mvf(const VVCFrameContext *fc, const int x0, const int y0);
 void ff_vvc_set_mvf(const VVCLocalContext *lc, const int x0, const int y0, const int w, const int h, const MvField *mvf);
-void ff_vvc_set_intra_mvf(const VVCLocalContext *lc, int dmvr);
+void ff_vvc_set_intra_mvf(const VVCLocalContext *lc, bool dmvr, PredFlag pf, bool ciip_flag);
 
 #endif //AVCODEC_VVC_MVS_H
-- 
2.44.0.windows.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [FFmpeg-devel] [PATCH v1 08/23] avcodec/vvc/ctu: refact out intra_data
  2025-05-14 13:40 [FFmpeg-devel] [PATCH v1 01/23] avcodec/vvc/cabac: add 9.3.3.5 k-th order Exp - Golomb binarization process toqsxw
                   ` (5 preceding siblings ...)
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 07/23] avcodec/vvc: refact, save pf and ciip_flag in ff_vvc_set_intra_mvf toqsxw
@ 2025-05-14 13:40 ` toqsxw
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 09/23] avcodec/vvc/intra: add ff_vvc_palette_derive_scale toqsxw
                   ` (15 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: toqsxw @ 2025-05-14 13:40 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Wu Jianhua

From: Wu Jianhua <toqsxw@outlook.com>

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
---
 libavcodec/vvc/ctu.c | 64 +++++++++++++++++++++++++++-----------------
 1 file changed, 40 insertions(+), 24 deletions(-)

diff --git a/libavcodec/vvc/ctu.c b/libavcodec/vvc/ctu.c
index f77697af08..c5df898f7b 100644
--- a/libavcodec/vvc/ctu.c
+++ b/libavcodec/vvc/ctu.c
@@ -1805,6 +1805,37 @@ static int inter_data(VVCLocalContext *lc)
     return ret;
 }
 
+static int intra_data(VVCLocalContext *lc)
+{
+    const VVCFrameContext *fc      = lc->fc;
+    const VVCSPS *sps              = lc->fc->ps.sps;
+    const CodingUnit *cu           = lc->cu;
+    const VVCTreeType tree_type    = cu->tree_type;
+    const bool  pred_mode_plt_flag = cu->pred_mode == MODE_PLT;
+    int ret                        = 0;
+
+    if (tree_type == SINGLE_TREE || tree_type == DUAL_TREE_LUMA) {
+        if (pred_mode_plt_flag) {
+            avpriv_report_missing_feature(fc->log_ctx, "Palette");
+            return AVERROR_PATCHWELCOME;
+        } else {
+            intra_luma_pred_modes(lc);
+            ff_vvc_set_intra_mvf(lc, false, PF_INTRA, cu->ciip_flag);
+        }
+    }
+    if ((tree_type == SINGLE_TREE || tree_type == DUAL_TREE_CHROMA) && sps->r->sps_chroma_format_idc) {
+        if (pred_mode_plt_flag && tree_type == DUAL_TREE_CHROMA) {
+            avpriv_report_missing_feature(fc->log_ctx, "Palette");
+            return AVERROR_PATCHWELCOME;
+        } else if (!pred_mode_plt_flag) {
+            if (!cu->act_enabled_flag)
+                intra_chroma_pred_modes(lc);
+        }
+    }
+
+    return ret;
+}
+
 static int hls_coding_unit(VVCLocalContext *lc, int x0, int y0, int cb_width, int cb_height,
     int cqt_depth, const VVCTreeType tree_type, VVCModeType mode_type)
 {
@@ -1815,7 +1846,7 @@ static int hls_coding_unit(VVCLocalContext *lc, int x0, int y0, int cb_width, in
     const int vs                    = sps->vshift[CHROMA];
     const int is_128                = cb_width > 64 || cb_height > 64;
     int pred_mode_plt_flag          = 0;
-    int ret;
+    int ret                         = 0;
 
     CodingUnit *cu = add_cu(lc, x0, y0, cb_width, cb_height, cqt_depth, tree_type);
 
@@ -1842,29 +1873,14 @@ static int hls_coding_unit(VVCLocalContext *lc, int x0, int y0, int cb_width, in
         avpriv_report_missing_feature(fc->log_ctx, "Adaptive Color Transform");
         return AVERROR_PATCHWELCOME;
     }
-    if (cu->pred_mode == MODE_INTRA || cu->pred_mode == MODE_PLT) {
-        if (tree_type == SINGLE_TREE || tree_type == DUAL_TREE_LUMA) {
-            if (pred_mode_plt_flag) {
-                avpriv_report_missing_feature(fc->log_ctx, "Palette");
-                return AVERROR_PATCHWELCOME;
-            } else {
-                intra_luma_pred_modes(lc);
-                ff_vvc_set_intra_mvf(lc, false, PF_INTRA, cu->ciip_flag);
-            }
-        }
-        if ((tree_type == SINGLE_TREE || tree_type == DUAL_TREE_CHROMA) && sps->r->sps_chroma_format_idc) {
-            if (pred_mode_plt_flag && tree_type == DUAL_TREE_CHROMA) {
-                avpriv_report_missing_feature(fc->log_ctx, "Palette");
-                return AVERROR_PATCHWELCOME;
-            } else if (!pred_mode_plt_flag) {
-                if (!cu->act_enabled_flag)
-                    intra_chroma_pred_modes(lc);
-            }
-        }
-    } else if (tree_type != DUAL_TREE_CHROMA) { /* MODE_INTER or MODE_IBC */
-        if ((ret = inter_data(lc)) < 0)
-            return ret;
-    }
+    if (cu->pred_mode == MODE_INTRA || cu->pred_mode == MODE_PLT)
+        ret = intra_data(lc);
+    else if (tree_type != DUAL_TREE_CHROMA) /* MODE_INTER or MODE_IBC */
+        ret = inter_data(lc);
+
+    if (ret < 0)
+        return ret;
+
     if (cu->pred_mode != MODE_INTRA && !pred_mode_plt_flag && !lc->cu->pu.general_merge_flag)
         cu->coded_flag = ff_vvc_cu_coded_flag(lc);
     else
-- 
2.44.0.windows.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [FFmpeg-devel] [PATCH v1 09/23] avcodec/vvc/intra: add ff_vvc_palette_derive_scale
  2025-05-14 13:40 [FFmpeg-devel] [PATCH v1 01/23] avcodec/vvc/cabac: add 9.3.3.5 k-th order Exp - Golomb binarization process toqsxw
                   ` (6 preceding siblings ...)
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 08/23] avcodec/vvc/ctu: refact out intra_data toqsxw
@ 2025-05-14 13:40 ` toqsxw
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 10/23] avcodec/vvc/ctu: add palette support toqsxw
                   ` (14 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: toqsxw @ 2025-05-14 13:40 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Wu Jianhua

From: Wu Jianhua <toqsxw@outlook.com>

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
---
 libavcodec/vvc/intra.c | 52 ++++++++++++++++++++++++++----------------
 libavcodec/vvc/intra.h |  1 +
 2 files changed, 33 insertions(+), 20 deletions(-)

diff --git a/libavcodec/vvc/intra.c b/libavcodec/vvc/intra.c
index 2e6cb8f09e..2e1703e234 100644
--- a/libavcodec/vvc/intra.c
+++ b/libavcodec/vvc/intra.c
@@ -336,29 +336,30 @@ static void derive_qp(const VVCLocalContext *lc, const TransformUnit *tu, Transf
     tb->bd_offset = (1 << tb->bd_shift) >> 1;
 }
 
+static const uint8_t rem6[63 + 8 * 6 + 1] = {
+    0,  1,  2,  3,  4,  5,  0,  1,  2,  3,  4,  5,  0,  1,  2,  3,  4,  5,  0,  1,  2,  3,  4,  5,
+    0,  1,  2,  3,  4,  5,  0,  1,  2,  3,  4,  5,  0,  1,  2,  3,  4,  5,  0,  1,  2,  3,  4,  5,
+    0,  1,  2,  3,  4,  5,  0,  1,  2,  3,  4,  5,  0,  1,  2,  3,  4,  5,  0,  1,  2,  3,  4,  5,
+    0,  1,  2,  3,  4,  5,  0,  1,  2,  3,  4,  5,  0,  1,  2,  3,  4,  5,  0,  1,  2,  3,  4,  5,
+    0,  1,  2,  3,  4,  5,  0,  1,  2,  3,  4,  5,  0,  1,  2,  3,
+};
+
+static const uint8_t div6[63 + 8 * 6 + 1] = {
+    0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1,  1,  2,  2,  2,  2,  2,  2,  3,  3,  3,  3,  3,  3,
+    4,  4,  4,  4,  4,  4,  5,  5,  5,  5,  5,  5,  6,  6,  6,  6,  6,  6,  7,  7,  7,  7,  7,  7,
+    8,  8,  8,  8,  8,  8,  9,  9,  9,  9,  9,  9, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11,
+   12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15,
+   16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18,
+};
+
+const static int level_scale[2][6] = {
+   { 40, 45, 51, 57, 64, 72 },
+   { 57, 64, 72, 80, 90, 102 }
+};
+
 //8.7.3 Scaling process for transform coefficients
 static av_always_inline int derive_scale(const TransformBlock *tb, const int sh_dep_quant_used_flag)
 {
-    static const uint8_t rem6[63 + 8 * 6 + 1] = {
-         0,  1,  2,  3,  4,  5,  0,  1,  2,  3,  4,  5,  0,  1,  2,  3,  4,  5,  0,  1,  2,  3,  4,  5,
-         0,  1,  2,  3,  4,  5,  0,  1,  2,  3,  4,  5,  0,  1,  2,  3,  4,  5,  0,  1,  2,  3,  4,  5,
-         0,  1,  2,  3,  4,  5,  0,  1,  2,  3,  4,  5,  0,  1,  2,  3,  4,  5,  0,  1,  2,  3,  4,  5,
-         0,  1,  2,  3,  4,  5,  0,  1,  2,  3,  4,  5,  0,  1,  2,  3,  4,  5,  0,  1,  2,  3,  4,  5,
-         0,  1,  2,  3,  4,  5,  0,  1,  2,  3,  4,  5,  0,  1,  2,  3,
-    };
-
-    static const uint8_t div6[63 + 8 * 6 + 1] = {
-         0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1,  1,  2,  2,  2,  2,  2,  2,  3,  3,  3,  3,  3,  3,
-         4,  4,  4,  4,  4,  4,  5,  5,  5,  5,  5,  5,  6,  6,  6,  6,  6,  6,  7,  7,  7,  7,  7,  7,
-         8,  8,  8,  8,  8,  8,  9,  9,  9,  9,  9,  9, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11,
-        12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15,
-        16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18,
-    };
-
-    const static int level_scale[2][6] = {
-        { 40, 45, 51, 57, 64, 72 },
-        { 57, 64, 72, 80, 90, 102 }
-    };
     const int addin = sh_dep_quant_used_flag && !tb->ts;
     const int qp    = tb->qp + addin;
 
@@ -658,6 +659,17 @@ static void ibc_fill_vir_buf(const VVCLocalContext *lc, const CodingUnit *cu)
     }
 }
 
+int ff_vvc_palette_derive_scale(VVCLocalContext *lc, const TransformUnit *tu, TransformBlock *tb)
+{
+    const VVCSPS *sps = lc->fc->ps.sps;
+    const int qp_prime_ts_min  = 4 + 6 * sps->r->sps_min_qp_prime_ts;
+    int qp;
+
+    derive_qp(lc, tu, tb);
+    qp = FFMAX(qp_prime_ts_min, tb->qp);
+    return level_scale[0][rem6[qp]] << div6[qp];
+}
+
 int ff_vvc_reconstruct(VVCLocalContext *lc, const int rs, const int rx, const int ry)
 {
     const VVCFrameContext *fc   = lc->fc;
diff --git a/libavcodec/vvc/intra.h b/libavcodec/vvc/intra.h
index 8a02699135..1201c70836 100644
--- a/libavcodec/vvc/intra.h
+++ b/libavcodec/vvc/intra.h
@@ -45,5 +45,6 @@ int ff_vvc_intra_pred_angle_derive(int pred_mode);
 int ff_vvc_intra_inv_angle_derive(int pred_mode);
 int ff_vvc_wide_angle_mode_mapping(const CodingUnit *cu,
     int tb_width, int tb_height, int c_idx, int pred_mode_intra);
+int ff_vvc_palette_derive_scale(VVCLocalContext *lc, const TransformUnit *tu, TransformBlock *tb);
 
 #endif // AVCODEC_VVC_INTRA_H
-- 
2.44.0.windows.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [FFmpeg-devel] [PATCH v1 10/23] avcodec/vvc/ctu: add palette support
  2025-05-14 13:40 [FFmpeg-devel] [PATCH v1 01/23] avcodec/vvc/cabac: add 9.3.3.5 k-th order Exp - Golomb binarization process toqsxw
                   ` (7 preceding siblings ...)
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 09/23] avcodec/vvc/intra: add ff_vvc_palette_derive_scale toqsxw
@ 2025-05-14 13:40 ` toqsxw
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 11/23] avcodec/vvc/filter: skip deblocking filter for palette toqsxw
                   ` (13 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: toqsxw @ 2025-05-14 13:40 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Wu Jianhua

From: Wu Jianhua <toqsxw@outlook.com>

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
---
 libavcodec/vvc/ctu.c    | 339 ++++++++++++++++++++++++++++++++++++----
 libavcodec/vvc/ctu.h    |  11 ++
 libavcodec/vvc/dec.c    |   3 +
 libavcodec/vvc/mvs.c    |   3 +-
 libavcodec/vvc/thread.c |   1 +
 5 files changed, 327 insertions(+), 30 deletions(-)

diff --git a/libavcodec/vvc/ctu.c b/libavcodec/vvc/ctu.c
index c5df898f7b..979a27c6ad 100644
--- a/libavcodec/vvc/ctu.c
+++ b/libavcodec/vvc/ctu.c
@@ -25,6 +25,7 @@
 #include "cabac.h"
 #include "ctu.h"
 #include "inter.h"
+#include "intra.h"
 #include "mvs.h"
 
 #define PROF_TEMP_SIZE (PROF_BLOCK_SIZE) * sizeof(int16_t)
@@ -1046,13 +1047,15 @@ static PredMode pred_mode_decode(VVCLocalContext *lc,
     const H266RawSliceHeader *rsh   = lc->sc->sh.r;
     const int ch_type               = tree_type == DUAL_TREE_CHROMA ? 1 : 0;
     const int is_4x4                = cu->cb_width == 4 && cu->cb_height == 4;
+    const int is_128                = cu->cb_width == 128 || cu->cb_height == 128;
+    const int hs                    = sps->hshift[CHROMA];
+    const int vs                    = sps->vshift[CHROMA];
     int pred_mode_flag;
     int pred_mode_ibc_flag;
     PredMode pred_mode;
 
     cu->skip_flag = 0;
     if (!IS_I(rsh) || sps->r->sps_ibc_enabled_flag) {
-        const int is_128 = cu->cb_width == 128 || cu->cb_height == 128;
         if (tree_type != DUAL_TREE_CHROMA &&
             ((!is_4x4 && mode_type != MODE_TYPE_INTRA) ||
             (sps->r->sps_ibc_enabled_flag && !is_128))) {
@@ -1087,6 +1090,14 @@ static PredMode pred_mode_decode(VVCLocalContext *lc,
         pred_mode = MODE_INTRA;
     }
 
+    if (pred_mode == MODE_INTRA && sps->r->sps_palette_enabled_flag && !is_128 && !cu->skip_flag &&
+        mode_type != MODE_TYPE_INTER && ((cu->cb_width * cu->cb_height) >
+            (tree_type != DUAL_TREE_CHROMA ? 16 : (16 << hs << vs))) &&
+        (mode_type != MODE_TYPE_INTRA || tree_type != DUAL_TREE_CHROMA)) {
+        if (ff_vvc_pred_mode_plt_flag(lc))
+            pred_mode = MODE_PLT;
+    }
+
     set_cb_tab(lc, fc->tab.cpm[cu->ch_type], pred_mode);
     if (tree_type == SINGLE_TREE)
         set_cb_tab(lc, fc->tab.cpm[CHROMA], pred_mode);
@@ -1755,8 +1766,8 @@ static void fill_dmvr_info(const VVCLocalContext *lc)
     const VVCFrameContext *fc = lc->fc;
     const CodingUnit *cu      = lc->cu;
 
-    if (cu->pred_mode == MODE_IBC) {
-        ff_vvc_set_intra_mvf(lc, true, PF_IBC, false);
+    if (cu->pred_mode == MODE_IBC || cu->pred_mode == MODE_PLT) {
+        ff_vvc_set_intra_mvf(lc, true, cu->pred_mode == MODE_IBC ? PF_IBC : PF_PLT, false);
     } else {
         const VVCPPS *pps = fc->ps.pps;
         const int w       = cu->cb_width >> MIN_PU_LOG2;
@@ -1805,9 +1816,291 @@ static int inter_data(VVCLocalContext *lc)
     return ret;
 }
 
+static TransformUnit* palette_add_tu(VVCLocalContext *lc, const int start, const int end, const VVCTreeType tree_type)
+{
+    CodingUnit   *cu  = lc->cu;
+    const VVCSPS *sps = lc->fc->ps.sps;
+    TransformUnit *tu = add_tu(lc->fc, cu, cu->x0, cu->y0, cu->cb_width, cu->cb_height);
+
+    if (!tu)
+        return NULL;
+
+    for (int c = start; c < end; c++) {
+        const int w = tu->width >> sps->hshift[c];
+        const int h = tu->height >> sps->vshift[c];
+        TransformBlock *tb = add_tb(tu, lc, tu->x0, tu->y0, w, h, c);
+        if (c != CR)
+            set_tb_size(lc->fc, tb);
+    }
+
+    for (int i = 0; i < FF_ARRAY_ELEMS(cu->plt); i++)
+        cu->plt[i].size = 0;
+
+    return tu;
+}
+
+static void palette_predicted(VVCLocalContext *lc, const bool local_dual_tree, int start, int end,
+    bool *predictor_reused, const int predictor_size, const int max_entries)
+{
+    CodingUnit  *cu  = lc->cu;
+    int nb_predicted = 0;
+
+    if (local_dual_tree) {
+        start = LUMA;
+        end = VVC_MAX_SAMPLE_ARRAYS;
+    }
+
+    for (int i = 0; i < predictor_size && nb_predicted < max_entries; i++) {
+        const int run = ff_vvc_palette_predictor_run(lc);
+        if (run == 1)
+            break;
+
+        if (run > 1)
+            i += run - 1;
+        predictor_reused[i] = true;
+        for (int c = start; c < end; c++)
+            cu->plt[c].entries[nb_predicted] = lc->ep->pp[c].entries[i];
+        nb_predicted++;
+    }
+
+    for (int c = start; c < end; c++)
+        cu->plt[c].size = nb_predicted;
+}
+
+static void palette_signaled(VVCLocalContext *lc, const bool local_dual_tree,
+    const int start, const int end, const int max_entries)
+{
+    const VVCSPS *sps         = lc->fc->ps.sps;
+    CodingUnit  *cu           = lc->cu;
+    const int nb_predicted    = cu->plt[start].size;
+    const int nb_signaled     = nb_predicted < max_entries ? ff_vvc_num_signalled_palette_entries(lc) : 0;
+    const int size            = nb_predicted + nb_signaled;
+    const bool dual_tree_luma = local_dual_tree && cu->tree_type == DUAL_TREE_LUMA;
+
+    for (int c = start; c < end; c++) {
+        Palette *plt = cu->plt + c;
+        for (int i = nb_predicted; i < size; i++) {
+            plt->entries[i] = ff_vvc_new_palette_entries(lc, sps->bit_depth);
+            if (dual_tree_luma) {
+                plt[CB].entries[i] = 1 << (sps->bit_depth - 1);
+                plt[CR].entries[i] = 1 << (sps->bit_depth - 1);
+            }
+        }
+        plt->size = size;
+    }
+}
+
+static void palette_update_predictor(VVCLocalContext *lc, const bool local_dual_tree, int start, int end,
+    bool *predictor_reused, const int predictor_size)
+{
+    CodingUnit  *cu         = lc->cu;
+    const int max_predictor = VVC_MAX_NUM_PALETTE_PREDICTOR_SIZE >> (cu->tree_type != SINGLE_TREE && !local_dual_tree);
+
+    if (local_dual_tree) {
+        start = LUMA;
+        end = VVC_MAX_SAMPLE_ARRAYS;
+    }
+
+    for (int c = start; c < end; c++) {
+        Palette *pp  = lc->ep->pp + c;
+        Palette *plt = cu->plt + c;
+        int i = cu->plt[start].size;;
+
+        // copy unused predictors to the end of plt
+        for (int j = 0; j < predictor_size && i < max_predictor; j++) {
+            if (!predictor_reused[j]) {
+                plt->entries[i] = pp->entries[j];
+                i++;
+            }
+        }
+
+        memcpy(pp->entries, plt->entries, i * sizeof(pp->entries[0]));
+        pp->size = i;
+    }
+}
+
+static void palette_qp(VVCLocalContext *lc, VVCTreeType tree_type, const bool escape_present)
+{
+    const VVCFrameContext *fc     = lc->fc;
+    const VVCPPS *pps             = fc->ps.pps;
+    const H266RawSliceHeader *rsh = lc->sc->sh.r;
+    const CodingUnit *cu          = lc->cu;
+
+    if (tree_type != DUAL_TREE_CHROMA) {
+        const bool has_qp_delta = escape_present &&
+            pps->r->pps_cu_qp_delta_enabled_flag && !lc->parse.is_cu_qp_delta_coded;
+        set_qp_y(lc, cu->x0, cu->y0, has_qp_delta);
+    }
+
+    if (tree_type != DUAL_TREE_LUMA) {
+        if (rsh->sh_cu_chroma_qp_offset_enabled_flag && !lc->parse.is_cu_chroma_qp_offset_coded)
+            chroma_qp_offset_decode(lc, 0, 1);
+        set_qp_c(lc);
+    }
+}
+
+#define PALETTE_SET_PIXEL(xc, yc, pix)                              \
+    do {                                                            \
+        const int off = ((xc) >> hs) + ((yc) >> vs) * tb->tb_width; \
+        if (sps->bit_depth == 8)                                    \
+            u8[off] = pix;                                          \
+        else                                                        \
+            u16[off] = pix;                                         \
+    } while (0)
+
+#define PALETTE_INDEX(x, y) index[(y) * cu->cb_width + (x)]
+
+// 6.5.3 Horizontal and vertical traverse scan order array initialization process
+// The hTravScan and vTravScan tables require approximately 576 KB of memory.
+// To save space, we use a macro to achieve the same functionality.
+#define TRAV_COL(p, wlog, mask) ((p & mask) ^ (-((p >> wlog) & 1) & mask))
+#define TRAV_ROW(p, hlog) (p >> hlog)
+#define TRAV(trans, p, wlog, hlog, mask)  (trans ? TRAV_ROW((p), hlog) : TRAV_COL((p), wlog, mask))
+#define TRAV_X(pos) TRAV(transpose, pos, wlog2, hlog2, wmask)
+#define TRAV_Y(pos) TRAV(!transpose, pos, hlog2, wlog2, hmask)
+
+static int palette_subblock_data(VVCLocalContext *lc,
+    const int max_index, const int subset_id, const bool transpose,
+    uint8_t *run_type, uint8_t *index, int *prev_run_pos, bool *adjust)
+{
+    const CodingUnit *cu = lc->cu;
+    TransformUnit *tu    = cu->tus.head;
+    const VVCSPS *sps    = lc->fc->ps.sps;
+    const int min_pos    = subset_id << 4;
+    const int max_pos    = FFMIN(min_pos + 16, cu->cb_width * cu->cb_height);
+    const int wmask      = cu->cb_width  - 1;
+    const int hmask      = cu->cb_height - 1;
+    const int wlog2      = av_log2(cu->cb_width);
+    const int hlog2      = av_log2(cu->cb_height);
+    const uint8_t esc    = cu->plt[tu->tbs[0].c_idx].size;
+    uint8_t run_copy[16] = { 0 };
+
+    for (int i = min_pos; i < max_pos; i++) {
+        const int xc = TRAV_X(i);
+        const int yc = TRAV_Y(i);
+
+        if (i > 0 && max_index > 0)
+            run_copy[i - min_pos] = ff_vvc_run_copy_flag(lc, run_type[i - 1], *prev_run_pos, i);
+
+        run_type[i] = 0;
+        if (max_index > 0 && !run_copy[i - min_pos]) {
+            if (((!transpose && yc > 0) || (transpose && xc > 0))
+                && i > 0 && !run_type[i - 1]) {
+                run_type[i] = ff_vvc_copy_above_palette_indices_flag(lc);
+            }
+            *prev_run_pos = i;
+        } else if (i > 0) {
+            run_type[i] = run_type[i - 1];
+        }
+    }
+
+    for (int i = min_pos; i < max_pos; i++) {
+        const int xc = TRAV_X(i);
+        const int yc = TRAV_Y(i);
+        const int prev_xc = i > 0 ? TRAV_X(i - 1) : 0;
+        const int prev_yc = i > 0 ? TRAV_Y(i - 1) : 0;
+
+        int idx = 0;
+        if (max_index > 0 && !run_copy[i - min_pos] && !run_type[i]) {
+            if (max_index - *adjust > 0)
+                idx = ff_vvc_palette_idx_idc(lc, max_index, *adjust);
+            if (i > 0) {
+                const int ref_idx = !run_type[i - 1] ?
+                    PALETTE_INDEX(prev_xc, prev_yc) : PALETTE_INDEX(xc - transpose, yc - !transpose);
+                idx += (idx >= ref_idx);
+            }
+            *adjust = true;
+        } else {
+            idx = PALETTE_INDEX(prev_xc, prev_yc);
+        }
+
+        if (!run_type[i])
+            PALETTE_INDEX(xc, yc) = idx;
+        else
+            PALETTE_INDEX(xc, yc) = PALETTE_INDEX(xc - transpose, yc - !transpose);
+    }
+
+    for (int c = 0; c < tu->nb_tbs; c++) {
+        TransformBlock *tb = &tu->tbs[c];
+        const Palette *plt = cu->plt + tb->c_idx;
+        const int scale    = ff_vvc_palette_derive_scale(lc, tu, tb);
+        const int hs       = sps->hshift[c];
+        const int vs       = sps->vshift[c];
+        uint8_t *u8        = (uint8_t *)tb->coeffs;
+        uint16_t *u16      = (uint16_t *)tb->coeffs;
+
+        for (int i = min_pos; i < max_pos; i++) {
+            const int xc = TRAV_X(i);
+            const int yc = TRAV_Y(i);
+            if (!(xc & hs) && !(yc & vs)) {
+                const int v = PALETTE_INDEX(xc, yc);
+                if (v == esc) {
+                    const int coeff = ff_vvc_palette_escape_val(lc);
+                    const int pixel = av_clip_intp2(RSHIFT(coeff * scale, 6), sps->bit_depth);
+                    PALETTE_SET_PIXEL(xc, yc, pixel);
+                } else {
+                    PALETTE_SET_PIXEL(xc, yc, plt->entries[v]);
+                }
+            }
+        }
+    }
+
+    return 0;
+}
+
+static int hls_palette_coding(VVCLocalContext *lc, const VVCTreeType tree_type)
+{
+    const VVCFrameContext *fc     = lc->fc;
+    const VVCSPS *sps             = fc->ps.sps;
+    const H266RawSliceHeader *rsh = lc->sc->sh.r;
+    CodingUnit *cu                = lc->cu;
+    Palette *pp                   = lc->ep->pp;
+    const int max_entries         = tree_type == SINGLE_TREE ? 31 : 15;
+    const bool local_dual_tree    = tree_type != SINGLE_TREE &&
+                                        (!IS_I(rsh) || (IS_I(rsh) && !sps->r->sps_qtbtt_dual_tree_intra_flag));
+    bool escape_present           = false;
+    bool transpose                = false;
+    bool adjust                   = false;
+    int max_index                 = 0;
+    int prev_run_pos              = 0;
+
+    int predictor_size, start, end;
+    bool reused[VVC_MAX_NUM_PALETTE_PREDICTOR_SIZE];
+    uint8_t run_type[MAX_PALETTE_CU_SIZE * MAX_PALETTE_CU_SIZE];
+    uint8_t index[MAX_PALETTE_CU_SIZE * MAX_PALETTE_CU_SIZE];
+
+    ff_vvc_channel_range(&start, &end, tree_type, sps->r->sps_chroma_format_idc);
+
+    if (!palette_add_tu(lc, start, end, tree_type))
+        return AVERROR(ENOMEM);
+
+    predictor_size = pp[start].size;
+    memset(reused, 0, sizeof(reused[0]) * predictor_size);
+    palette_predicted(lc, local_dual_tree, start, end, reused, predictor_size, max_entries);
+    palette_signaled(lc, local_dual_tree, start, end, max_entries);
+    palette_update_predictor(lc, local_dual_tree, start, end, reused, predictor_size);
+
+    if (cu->plt[start].size > 0)
+        escape_present = ff_vvc_palette_escape_val_present_flag(lc);
+
+    max_index = cu->plt[start].size - 1 + escape_present;
+    if (max_index > 0) {
+        adjust = false;
+        transpose = ff_vvc_palette_transpose_flag(lc);
+    }
+
+    palette_qp(lc, tree_type, escape_present);
+
+    index[0] = 0;
+    for (int i = 0; i <= (cu->cb_width * cu->cb_height - 1) >> 4; i++)
+        palette_subblock_data(lc, max_index, i, transpose,
+            run_type, index, &prev_run_pos, &adjust);
+
+    return 0;
+}
+
 static int intra_data(VVCLocalContext *lc)
 {
-    const VVCFrameContext *fc      = lc->fc;
     const VVCSPS *sps              = lc->fc->ps.sps;
     const CodingUnit *cu           = lc->cu;
     const VVCTreeType tree_type    = cu->tree_type;
@@ -1816,8 +2109,9 @@ static int intra_data(VVCLocalContext *lc)
 
     if (tree_type == SINGLE_TREE || tree_type == DUAL_TREE_LUMA) {
         if (pred_mode_plt_flag) {
-            avpriv_report_missing_feature(fc->log_ctx, "Palette");
-            return AVERROR_PATCHWELCOME;
+            if ((ret = hls_palette_coding(lc, tree_type)) < 0)
+                return ret;
+            ff_vvc_set_intra_mvf(lc, false, PF_PLT, false);
         } else {
             intra_luma_pred_modes(lc);
             ff_vvc_set_intra_mvf(lc, false, PF_INTRA, cu->ciip_flag);
@@ -1825,8 +2119,8 @@ static int intra_data(VVCLocalContext *lc)
     }
     if ((tree_type == SINGLE_TREE || tree_type == DUAL_TREE_CHROMA) && sps->r->sps_chroma_format_idc) {
         if (pred_mode_plt_flag && tree_type == DUAL_TREE_CHROMA) {
-            avpriv_report_missing_feature(fc->log_ctx, "Palette");
-            return AVERROR_PATCHWELCOME;
+            if ((ret = hls_palette_coding(lc, tree_type)) < 0)
+                return ret;
         } else if (!pred_mode_plt_flag) {
             if (!cu->act_enabled_flag)
                 intra_chroma_pred_modes(lc);
@@ -1839,14 +2133,11 @@ static int intra_data(VVCLocalContext *lc)
 static int hls_coding_unit(VVCLocalContext *lc, int x0, int y0, int cb_width, int cb_height,
     int cqt_depth, const VVCTreeType tree_type, VVCModeType mode_type)
 {
-    const VVCFrameContext *fc       = lc->fc;
-    const VVCSPS *sps               = fc->ps.sps;
-    const H266RawSliceHeader *rsh   = lc->sc->sh.r;
-    const int hs                    = sps->hshift[CHROMA];
-    const int vs                    = sps->vshift[CHROMA];
-    const int is_128                = cb_width > 64 || cb_height > 64;
-    int pred_mode_plt_flag          = 0;
-    int ret                         = 0;
+    const VVCFrameContext *fc     = lc->fc;
+    const VVCSPS *sps             = fc->ps.sps;
+    const H266RawSliceHeader *rsh = lc->sc->sh.r;
+    const int is_128              = cb_width > 64 || cb_height > 64;
+    int ret                       = 0;
 
     CodingUnit *cu = add_cu(lc, x0, y0, cb_width, cb_height, cqt_depth, tree_type);
 
@@ -1859,16 +2150,6 @@ static int hls_coding_unit(VVCLocalContext *lc, int x0, int y0, int cb_width, in
         mode_type = MODE_TYPE_INTRA;
     cu->pred_mode = pred_mode_decode(lc, tree_type, mode_type);
 
-    if (cu->pred_mode == MODE_INTRA && sps->r->sps_palette_enabled_flag && !is_128 && !cu->skip_flag &&
-        mode_type != MODE_TYPE_INTER && ((cb_width * cb_height) >
-        (tree_type != DUAL_TREE_CHROMA ? 16 : (16 << hs << vs))) &&
-        (mode_type != MODE_TYPE_INTRA || tree_type != DUAL_TREE_CHROMA)) {
-        pred_mode_plt_flag = ff_vvc_pred_mode_plt_flag(lc);
-        if (pred_mode_plt_flag) {
-            avpriv_report_missing_feature(fc->log_ctx, "Palette");
-            return AVERROR_PATCHWELCOME;
-        }
-    }
     if (cu->pred_mode == MODE_INTRA && sps->r->sps_act_enabled_flag && tree_type == SINGLE_TREE) {
         avpriv_report_missing_feature(fc->log_ctx, "Adaptive Color Transform");
         return AVERROR_PATCHWELCOME;
@@ -1881,10 +2162,10 @@ static int hls_coding_unit(VVCLocalContext *lc, int x0, int y0, int cb_width, in
     if (ret < 0)
         return ret;
 
-    if (cu->pred_mode != MODE_INTRA && !pred_mode_plt_flag && !lc->cu->pu.general_merge_flag)
+    if (cu->pred_mode != MODE_INTRA && cu->pred_mode != MODE_PLT && !lc->cu->pu.general_merge_flag)
         cu->coded_flag = ff_vvc_cu_coded_flag(lc);
     else
-        cu->coded_flag = !(cu->skip_flag || pred_mode_plt_flag);
+        cu->coded_flag = !(cu->skip_flag || cu->pred_mode == MODE_PLT);
 
     if (cu->coded_flag) {
         sbt_info(lc, sps);
@@ -1902,7 +2183,7 @@ static int hls_coding_unit(VVCLocalContext *lc, int x0, int y0, int cb_width, in
         cu->lfnst_idx = lfnst_idx_decode(lc);
         cu->mts_idx = mts_idx_decode(lc);
         set_qp_c(lc);
-    } else {
+    } else if (cu->pred_mode != MODE_PLT) {
         ret = skipped_transform_tree_unit(lc);
         if (ret < 0)
             return ret;
diff --git a/libavcodec/vvc/ctu.h b/libavcodec/vvc/ctu.h
index dab6f453f1..e37bacf9dd 100644
--- a/libavcodec/vvc/ctu.h
+++ b/libavcodec/vvc/ctu.h
@@ -36,6 +36,7 @@
 #define MIN_CU_SIZE             4
 #define MIN_CU_LOG2             2
 #define MAX_CU_DEPTH            7
+#define MAX_PALETTE_CU_SIZE     64
 
 #define MAX_PARTS_IN_CTU        ((MAX_CTU_SIZE >> MIN_CU_LOG2) * (MAX_CTU_SIZE >> MIN_CU_LOG2))
 
@@ -224,6 +225,7 @@ typedef enum PredFlag {
     PF_L1    = 0x2,
     PF_BI    = 0x3,
     PF_IBC   = PF_L0 | 0x4,
+    PF_PLT   = 0x8,
 } PredFlag;
 
 typedef enum IntraPredMode {
@@ -277,6 +279,11 @@ typedef struct PredictionUnit {
     int cb_prof_flag[2];
 } PredictionUnit;
 
+typedef struct Palette {
+    uint8_t size;
+    uint16_t entries[VVC_MAX_NUM_PALETTE_PREDICTOR_SIZE];
+} Palette;
+
 typedef struct CodingUnit {
     VVCTreeType tree_type;
     int x0;
@@ -326,6 +333,8 @@ typedef struct CodingUnit {
 
     int8_t qp[4];                                   ///< QpY, Qp′Cb, Qp′Cr, Qp′CbCr
 
+    Palette plt[VVC_MAX_SAMPLE_ARRAYS];
+
     PredictionUnit pu;
 
     struct CodingUnit *next;                        ///< RefStruct reference
@@ -356,6 +365,8 @@ typedef struct EntryPoint {
 
     int stat_coeff[VVC_MAX_SAMPLE_ARRAYS];          ///< StatCoeff
 
+    Palette pp[VVC_MAX_SAMPLE_ARRAYS];              // PalettePredictor
+
     VVCCabacState cabac_state[VVC_CONTEXTS];
     CABACContext cc;
 
diff --git a/libavcodec/vvc/dec.c b/libavcodec/vvc/dec.c
index 09b0053703..3db2c9955c 100644
--- a/libavcodec/vvc/dec.c
+++ b/libavcodec/vvc/dec.c
@@ -551,6 +551,9 @@ static int ep_init(EntryPoint *ep, const int ctu_addr, const int ctu_end, GetBit
     ep->ctu_start = ctu_addr;
     ep->ctu_end   = ctu_end;
 
+    for (int c_idx = LUMA; c_idx <= CR; c_idx++)
+        ep->pp[c_idx].size = 0;
+
     return 0;
 }
 
diff --git a/libavcodec/vvc/mvs.c b/libavcodec/vvc/mvs.c
index 8946b00b5b..2cf67def7b 100644
--- a/libavcodec/vvc/mvs.c
+++ b/libavcodec/vvc/mvs.c
@@ -145,7 +145,8 @@ static int derive_temporal_colocated_mvs(const VVCLocalContext *lc, MvField temp
     RefPicList* refPicList      = sc->rpl;
 
     if (temp_col.pred_flag == PF_INTRA ||
-        temp_col.pred_flag == PF_IBC)
+        temp_col.pred_flag == PF_IBC   ||
+        temp_col.pred_flag == PF_PLT)
         return 0;
 
     if (sb_flag){
diff --git a/libavcodec/vvc/thread.c b/libavcodec/vvc/thread.c
index e1d64bd3d2..2138341b0f 100644
--- a/libavcodec/vvc/thread.c
+++ b/libavcodec/vvc/thread.c
@@ -286,6 +286,7 @@ static void add_progress_listener(VVCFrame *ref, ProgressListener *l,
 static void ep_init_wpp(EntryPoint *next, const EntryPoint *ep, const VVCSPS *sps)
 {
     memcpy(next->cabac_state, ep->cabac_state, sizeof(next->cabac_state));
+    memcpy(next->pp, ep->pp, sizeof(next->pp));
     ff_vvc_ep_init_stat_coeff(next, sps->bit_depth, sps->r->sps_persistent_rice_adaptation_enabled_flag);
 }
 
-- 
2.44.0.windows.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [FFmpeg-devel] [PATCH v1 11/23] avcodec/vvc/filter: skip deblocking filter for palette
  2025-05-14 13:40 [FFmpeg-devel] [PATCH v1 01/23] avcodec/vvc/cabac: add 9.3.3.5 k-th order Exp - Golomb binarization process toqsxw
                   ` (8 preceding siblings ...)
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 10/23] avcodec/vvc/ctu: add palette support toqsxw
@ 2025-05-14 13:40 ` toqsxw
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 12/23] avcodec/vvc/intra: add palette coding decoder toqsxw
                   ` (12 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: toqsxw @ 2025-05-14 13:40 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Wu Jianhua

From: Wu Jianhua <toqsxw@outlook.com>

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
---
 libavcodec/vvc/filter.c | 29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/libavcodec/vvc/filter.c b/libavcodec/vvc/filter.c
index a7f102bc64..e3886d008e 100644
--- a/libavcodec/vvc/filter.c
+++ b/libavcodec/vvc/filter.c
@@ -772,17 +772,15 @@ static int get_qp(const VVCFrameContext *fc, const uint8_t *src, const int x, co
 
 static void vvc_deblock(const VVCLocalContext *lc, int x0, int y0, const int rs, const int vertical)
 {
-    VVCFrameContext *fc    = lc->fc;
-    const VVCSPS *sps      = fc->ps.sps;
-    const int c_end        = sps->r->sps_chroma_format_idc ? VVC_MAX_SAMPLE_ARRAYS : 1;
-    const int ctb_size     = fc->ps.sps->ctb_size_y;
-    const DBParams *params = fc->tab.deblock + rs;
-    int x_end              = FFMIN(x0 + ctb_size, fc->ps.pps->width);
-    int y_end              = FFMIN(y0 + ctb_size, fc->ps.pps->height);
-
-    //not use this yet, may needed by plt.
-    const uint8_t no_p[4]  = { 0 };
-    const uint8_t no_q[4]  = { 0 } ;
+    VVCFrameContext *fc        = lc->fc;
+    const VVCSPS *sps          = fc->ps.sps;
+    const int c_end            = sps->r->sps_chroma_format_idc ? VVC_MAX_SAMPLE_ARRAYS : 1;
+    const int ctb_size         = fc->ps.sps->ctb_size_y;
+    const DBParams *params     = fc->tab.deblock + rs;
+    int x_end                  = FFMIN(x0 + ctb_size, fc->ps.pps->width);
+    int y_end                  = FFMIN(y0 + ctb_size, fc->ps.pps->height);
+    const int log2_min_cb_size = fc->ps.sps->min_cb_log2_size_y;
+    const int min_cb_width     = fc->ps.pps->min_cb_width;
 
     if (!vertical) {
         FFSWAP(int, x_end, y_end);
@@ -802,6 +800,8 @@ static void vvc_deblock(const VVCLocalContext *lc, int x0, int y0, const int rs,
                 const uint8_t horizontal_ctu_edge = !vertical && !(x % ctb_size);
                 int32_t bs[4], beta[4], tc[4] = { 0 }, all_zero_bs = 1;
                 uint8_t max_len_p[4], max_len_q[4];
+                uint8_t no_p[4] = { 0 };
+                uint8_t no_q[4] = { 0 };
 
                 for (int i = 0; i < DEBLOCK_STEP >> (2 - vs); i++) {
                     int tx         = x;
@@ -818,6 +818,13 @@ static void vvc_deblock(const VVCLocalContext *lc, int x0, int y0, const int rs,
                         tc[i] = TC_CALC(qp, bs[i]) ;
                         max_filter_length(fc, tx, ty, c_idx, vertical, horizontal_ctu_edge, bs[i], &max_len_p[i], &max_len_q[i]);
                         all_zero_bs = 0;
+
+                        if (sps->r->sps_palette_enabled_flag) {
+                            const int cu_q = (ty             >> log2_min_cb_size) * min_cb_width + (tx            >> log2_min_cb_size);
+                            const int cu_p = (ty - !vertical >> log2_min_cb_size) * min_cb_width + (tx - vertical >> log2_min_cb_size);
+                            no_q[i] = fc->tab.cpm[!!c_idx][cu_q] == MODE_PLT;
+                            no_p[i] = cu_p >= 0 && fc->tab.cpm[!!c_idx][cu_p] == MODE_PLT;
+                        }
                     }
                 }
 
-- 
2.44.0.windows.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [FFmpeg-devel] [PATCH v1 12/23] avcodec/vvc/intra: add palette coding decoder
  2025-05-14 13:40 [FFmpeg-devel] [PATCH v1 01/23] avcodec/vvc/cabac: add 9.3.3.5 k-th order Exp - Golomb binarization process toqsxw
                   ` (9 preceding siblings ...)
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 11/23] avcodec/vvc/filter: skip deblocking filter for palette toqsxw
@ 2025-05-14 13:40 ` toqsxw
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 13/23] avcodec/vvc/cabac: add ff_vvc_cu_act_enabled_flag toqsxw
                   ` (11 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: toqsxw @ 2025-05-14 13:40 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Wu Jianhua

From: Wu Jianhua <toqsxw@outlook.com>

Introduction at https://ieeexplore.ieee.org/document/9408666

passed files:
    10b422_G_Sony_5.bit
    10b422_H_Sony_5.bit
    10b422_I_Sony_5.bit
    10b422_J_Sony_5.bit
    10b422_K_Sony_5.bit
    10b422_L_Sony_5.bit
    8b422_G_Sony_5.bit
    8b422_H_Sony_5.bit
    8b422_I_Sony_5.bit
    8b422_J_Sony_5.bit
    8b422_K_Sony_5.bit
    8b422_L_Sony_5.bit
    8b444_A_Kwai_2.bit
    8b444_B_Kwai_2.bit
    PALETTE_A_Alibaba_2.bit
    PALETTE_B_Alibaba_2.bit
    PALETTE_C_Alibaba_2.bit
    PALETTE_D_Alibaba_2.bit
    PALETTE_E_Alibaba_2.bit

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
---
 libavcodec/vvc/intra.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/libavcodec/vvc/intra.c b/libavcodec/vvc/intra.c
index 2e1703e234..7f772fa4ae 100644
--- a/libavcodec/vvc/intra.c
+++ b/libavcodec/vvc/intra.c
@@ -670,6 +670,27 @@ int ff_vvc_palette_derive_scale(VVCLocalContext *lc, const TransformUnit *tu, Tr
     return level_scale[0][rem6[qp]] << div6[qp];
 }
 
+// 8.4.5.3 Decoding process for palette mode
+static void vvc_predict_palette(VVCLocalContext *lc)
+{
+    const VVCFrameContext *fc = lc->fc;
+    const CodingUnit *cu      = lc->cu;
+    TransformUnit *tu         = cu->tus.head;
+    const VVCSPS *sps         = fc->ps.sps;
+    const int ps              = sps->pixel_shift;
+
+    for (int i = 0; i < tu->nb_tbs; i++) {
+        TransformBlock *tb     = &tu->tbs[i];
+        const int c_idx        = tb->c_idx;
+        const int w            = tb->tb_width;
+        const int h            = tb->tb_height;
+        const ptrdiff_t stride = fc->frame->linesize[c_idx];
+        uint8_t *dst           = POS(c_idx, cu->x0, cu->y0);
+
+        av_image_copy_plane(dst, stride, (uint8_t*)tb->coeffs, w << ps, w << ps, h);
+    }
+}
+
 int ff_vvc_reconstruct(VVCLocalContext *lc, const int rs, const int rx, const int ry)
 {
     const VVCFrameContext *fc   = lc->fc;
@@ -690,6 +711,8 @@ int ff_vvc_reconstruct(VVCLocalContext *lc, const int rs, const int rx, const in
             ff_vvc_predict_ciip(lc);
         else if (cu->pred_mode == MODE_IBC)
             vvc_predict_ibc(lc);
+        else if (cu->pred_mode == MODE_PLT)
+            vvc_predict_palette(lc);
         if (cu->coded_flag) {
             ret = reconstruct(lc);
         } else {
-- 
2.44.0.windows.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [FFmpeg-devel] [PATCH v1 13/23] avcodec/vvc/cabac: add ff_vvc_cu_act_enabled_flag
  2025-05-14 13:40 [FFmpeg-devel] [PATCH v1 01/23] avcodec/vvc/cabac: add 9.3.3.5 k-th order Exp - Golomb binarization process toqsxw
                   ` (10 preceding siblings ...)
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 12/23] avcodec/vvc/intra: add palette coding decoder toqsxw
@ 2025-05-14 13:40 ` toqsxw
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 14/23] avcodec/vvc/ctu: read act_enabled_flag for adaptive color transform toqsxw
                   ` (10 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: toqsxw @ 2025-05-14 13:40 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Wu Jianhua

From: Wu Jianhua <toqsxw@outlook.com>

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
---
 libavcodec/vvc/cabac.c | 5 +++++
 libavcodec/vvc/cabac.h | 1 +
 2 files changed, 6 insertions(+)

diff --git a/libavcodec/vvc/cabac.c b/libavcodec/vvc/cabac.c
index 700b719b7c..6847ce59af 100644
--- a/libavcodec/vvc/cabac.c
+++ b/libavcodec/vvc/cabac.c
@@ -1703,6 +1703,11 @@ int ff_vvc_tu_y_coded_flag(VVCLocalContext *lc)
     return lc->parse.prev_tu_cbf_y;
 }
 
+int ff_vvc_cu_act_enabled_flag(VVCLocalContext *lc)
+{
+    return GET_CABAC(CU_ACT_ENABLED_FLAG);
+}
+
 int ff_vvc_cu_qp_delta_abs(VVCLocalContext *lc)
 {
     int v, i, k;
diff --git a/libavcodec/vvc/cabac.h b/libavcodec/vvc/cabac.h
index 92f0163c85..972890317e 100644
--- a/libavcodec/vvc/cabac.h
+++ b/libavcodec/vvc/cabac.h
@@ -120,6 +120,7 @@ int ff_vvc_bcw_idx(VVCLocalContext *lc, int no_backward_pred_flag);
 int ff_vvc_tu_cb_coded_flag(VVCLocalContext *lc);
 int ff_vvc_tu_cr_coded_flag(VVCLocalContext *lc, int tu_cb_coded_flag);
 int ff_vvc_tu_y_coded_flag(VVCLocalContext *lc);
+int ff_vvc_cu_act_enabled_flag(VVCLocalContext *lc);
 int ff_vvc_cu_chroma_qp_offset_flag(VVCLocalContext *lc);
 int ff_vvc_cu_chroma_qp_offset_idx(VVCLocalContext *lc);
 int ff_vvc_tu_joint_cbcr_residual_flag(VVCLocalContext *lc, int tu_cb_coded_flag, int tu_cr_coded_flag);
-- 
2.44.0.windows.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [FFmpeg-devel] [PATCH v1 14/23] avcodec/vvc/ctu: read act_enabled_flag for adaptive color transform
  2025-05-14 13:40 [FFmpeg-devel] [PATCH v1 01/23] avcodec/vvc/cabac: add 9.3.3.5 k-th order Exp - Golomb binarization process toqsxw
                   ` (11 preceding siblings ...)
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 13/23] avcodec/vvc/cabac: add ff_vvc_cu_act_enabled_flag toqsxw
@ 2025-05-14 13:40 ` toqsxw
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 15/23] avcodec/vvc/ctu: fix derive_chroma_intra_pred_mode toqsxw
                   ` (9 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: toqsxw @ 2025-05-14 13:40 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Wu Jianhua

From: Wu Jianhua <toqsxw@outlook.com>

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
---
 libavcodec/vvc/ctu.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/libavcodec/vvc/ctu.c b/libavcodec/vvc/ctu.c
index 979a27c6ad..a83c59f27c 100644
--- a/libavcodec/vvc/ctu.c
+++ b/libavcodec/vvc/ctu.c
@@ -2150,10 +2150,9 @@ static int hls_coding_unit(VVCLocalContext *lc, int x0, int y0, int cb_width, in
         mode_type = MODE_TYPE_INTRA;
     cu->pred_mode = pred_mode_decode(lc, tree_type, mode_type);
 
-    if (cu->pred_mode == MODE_INTRA && sps->r->sps_act_enabled_flag && tree_type == SINGLE_TREE) {
-        avpriv_report_missing_feature(fc->log_ctx, "Adaptive Color Transform");
-        return AVERROR_PATCHWELCOME;
-    }
+    if (cu->pred_mode == MODE_INTRA && sps->r->sps_act_enabled_flag && tree_type == SINGLE_TREE)
+        cu->act_enabled_flag = ff_vvc_cu_act_enabled_flag(lc);
+
     if (cu->pred_mode == MODE_INTRA || cu->pred_mode == MODE_PLT)
         ret = intra_data(lc);
     else if (tree_type != DUAL_TREE_CHROMA) /* MODE_INTER or MODE_IBC */
@@ -2169,10 +2168,8 @@ static int hls_coding_unit(VVCLocalContext *lc, int x0, int y0, int cb_width, in
 
     if (cu->coded_flag) {
         sbt_info(lc, sps);
-        if (sps->r->sps_act_enabled_flag && cu->pred_mode != MODE_INTRA && tree_type == SINGLE_TREE) {
-            avpriv_report_missing_feature(fc->log_ctx, "Adaptive Color Transform");
-            return AVERROR_PATCHWELCOME;
-        }
+        if (sps->r->sps_act_enabled_flag && cu->pred_mode != MODE_INTRA && tree_type == SINGLE_TREE)
+            cu->act_enabled_flag = ff_vvc_cu_act_enabled_flag(lc);
         lc->parse.lfnst_dc_only = 1;
         lc->parse.lfnst_zero_out_sig_coeff_flag = 1;
         lc->parse.mts_dc_only = 1;
-- 
2.44.0.windows.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [FFmpeg-devel] [PATCH v1 15/23] avcodec/vvc/ctu: fix derive_chroma_intra_pred_mode
  2025-05-14 13:40 [FFmpeg-devel] [PATCH v1 01/23] avcodec/vvc/cabac: add 9.3.3.5 k-th order Exp - Golomb binarization process toqsxw
                   ` (12 preceding siblings ...)
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 14/23] avcodec/vvc/ctu: read act_enabled_flag for adaptive color transform toqsxw
@ 2025-05-14 13:40 ` toqsxw
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 16/23] avcodec/vvc/dsp: update the interface of pred_residual_joint for joint cbcr residual functionality toqsxw
                   ` (8 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: toqsxw @ 2025-05-14 13:40 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Wu Jianhua

From: Wu Jianhua <toqsxw@outlook.com>

See 8.4.3 Derivation process for chroma intra prediction mode

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
---
 libavcodec/vvc/ctu.c | 57 +++++++++++++++++++++++---------------------
 1 file changed, 30 insertions(+), 27 deletions(-)

diff --git a/libavcodec/vvc/ctu.c b/libavcodec/vvc/ctu.c
index a83c59f27c..e160199580 100644
--- a/libavcodec/vvc/ctu.c
+++ b/libavcodec/vvc/ctu.c
@@ -895,7 +895,7 @@ static void derive_chroma_intra_pred_mode(VVCLocalContext *lc,
     enum IntraPredMode luma_intra_pred_mode = SAMPLE_CTB(fc->tab.ipm, x_cb, y_cb);
 
     if (cu->tree_type == SINGLE_TREE && sps->r->sps_chroma_format_idc == CHROMA_FORMAT_444 &&
-        intra_chroma_pred_mode == 4 && intra_mip_flag) {
+        (intra_chroma_pred_mode == 4 || cu->act_enabled_flag) && intra_mip_flag) {
         cu->mip_chroma_direct_flag = 1;
         cu->intra_pred_mode_c = luma_intra_pred_mode;
         return;
@@ -1007,34 +1007,38 @@ static void intra_luma_pred_modes(VVCLocalContext *lc)
 
 static void intra_chroma_pred_modes(VVCLocalContext *lc)
 {
-    const VVCSPS *sps   = lc->fc->ps.sps;
-    CodingUnit *cu      = lc->cu;
-    const int hs        = sps->hshift[CHROMA];
-    const int vs        = sps->vshift[CHROMA];
+    const VVCSPS *sps          = lc->fc->ps.sps;
+    CodingUnit *cu             = lc->cu;
+    const int hs               = sps->hshift[CHROMA];
+    const int vs               = sps->vshift[CHROMA];
+    int cclm_mode_flag         = 0;
+    int cclm_mode_idx          = 0;
+    int intra_chroma_pred_mode = 0;
+
+    if (!cu->act_enabled_flag) {
+        cu->mip_chroma_direct_flag = 0;
+        if (sps->r->sps_bdpcm_enabled_flag &&
+            (cu->cb_width  >> hs) <= sps->max_ts_size &&
+            (cu->cb_height >> vs) <= sps->max_ts_size) {
+            cu->bdpcm_flag[CB] = cu->bdpcm_flag[CR] = ff_vvc_intra_bdpcm_chroma_flag(lc);
+        }
+        if (cu->bdpcm_flag[CHROMA]) {
+            cu->intra_pred_mode_c = ff_vvc_intra_bdpcm_chroma_dir_flag(lc) ? INTRA_VERT : INTRA_HORZ;
+        } else {
+            const int cclm_enabled = get_cclm_enabled(lc, cu->x0, cu->y0);
 
-    cu->mip_chroma_direct_flag = 0;
-    if (sps->r->sps_bdpcm_enabled_flag &&
-        (cu->cb_width  >> hs) <= sps->max_ts_size &&
-        (cu->cb_height >> vs) <= sps->max_ts_size) {
-        cu->bdpcm_flag[CB] = cu->bdpcm_flag[CR] = ff_vvc_intra_bdpcm_chroma_flag(lc);
-    }
-    if (cu->bdpcm_flag[CHROMA]) {
-        cu->intra_pred_mode_c = ff_vvc_intra_bdpcm_chroma_dir_flag(lc) ? INTRA_VERT : INTRA_HORZ;
-    } else {
-        const int cclm_enabled = get_cclm_enabled(lc, cu->x0, cu->y0);
-        int cclm_mode_flag = 0;
-        int cclm_mode_idx = 0;
-        int intra_chroma_pred_mode = 0;
+            if (cclm_enabled)
+                cclm_mode_flag = ff_vvc_cclm_mode_flag(lc);
 
-        if (cclm_enabled)
-            cclm_mode_flag = ff_vvc_cclm_mode_flag(lc);
+            if (cclm_mode_flag)
+                cclm_mode_idx = ff_vvc_cclm_mode_idx(lc);
+            else
+                intra_chroma_pred_mode = ff_vvc_intra_chroma_pred_mode(lc);
+        }
+    }
 
-        if (cclm_mode_flag)
-            cclm_mode_idx = ff_vvc_cclm_mode_idx(lc);
-        else
-            intra_chroma_pred_mode = ff_vvc_intra_chroma_pred_mode(lc);
+    if (!cu->bdpcm_flag[CHROMA])
         derive_chroma_intra_pred_mode(lc, cclm_mode_flag, cclm_mode_idx, intra_chroma_pred_mode);
-    }
 }
 
 static PredMode pred_mode_decode(VVCLocalContext *lc,
@@ -2122,8 +2126,7 @@ static int intra_data(VVCLocalContext *lc)
             if ((ret = hls_palette_coding(lc, tree_type)) < 0)
                 return ret;
         } else if (!pred_mode_plt_flag) {
-            if (!cu->act_enabled_flag)
-                intra_chroma_pred_modes(lc);
+            intra_chroma_pred_modes(lc);
         }
     }
 
-- 
2.44.0.windows.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [FFmpeg-devel] [PATCH v1 16/23] avcodec/vvc/dsp: update the interface of pred_residual_joint for joint cbcr residual functionality
  2025-05-14 13:40 [FFmpeg-devel] [PATCH v1 01/23] avcodec/vvc/cabac: add 9.3.3.5 k-th order Exp - Golomb binarization process toqsxw
                   ` (13 preceding siblings ...)
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 15/23] avcodec/vvc/ctu: fix derive_chroma_intra_pred_mode toqsxw
@ 2025-05-14 13:40 ` toqsxw
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 17/23] avcodec/vvc/dsp: add adaptive_color_transform toqsxw
                   ` (7 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: toqsxw @ 2025-05-14 13:40 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Wu Jianhua

From: Wu Jianhua <toqsxw@outlook.com>

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
---
 libavcodec/vvc/dsp.h          |  2 +-
 libavcodec/vvc/dsp_template.c | 11 ++++-------
 libavcodec/vvc/intra.c        |  2 +-
 3 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/libavcodec/vvc/dsp.h b/libavcodec/vvc/dsp.h
index fc4c3a6799..25b7755109 100644
--- a/libavcodec/vvc/dsp.h
+++ b/libavcodec/vvc/dsp.h
@@ -123,7 +123,7 @@ typedef struct VVCIntraDSPContext {
 typedef struct VVCItxDSPContext {
     void (*add_residual)(uint8_t *dst, const int *res, int width, int height, ptrdiff_t stride);
     void (*add_residual_joint)(uint8_t *dst, const int *res, int width, int height, ptrdiff_t stride, int c_sign, int shift);
-    void (*pred_residual_joint)(int *buf, int width, int height, int c_sign, int shift);
+    void (*pred_residual_joint)(int *dst, const int *src, int width, int height, int c_sign, int shift);
 
     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);
diff --git a/libavcodec/vvc/dsp_template.c b/libavcodec/vvc/dsp_template.c
index 1aa1e027bd..c6dc6e22a7 100644
--- a/libavcodec/vvc/dsp_template.c
+++ b/libavcodec/vvc/dsp_template.c
@@ -62,15 +62,12 @@ static void FUNC(add_residual_joint)(uint8_t *_dst, const int *res,
     }
 }
 
-static void FUNC(pred_residual_joint)(int *buf, const int w, const int h,
+static void FUNC(pred_residual_joint)(int *dst, const int *src, const int w, const int h,
     const int c_sign, const int shift)
 {
-    for (int y = 0; y < h; y++) {
-        for (int x = 0; x < w; x++) {
-            *buf = ((*buf) * c_sign) >> shift;
-            buf++;
-        }
-    }
+    const int size = w * h;
+    for (int i = 0; i < size; i++)
+        dst[i] = (src[i] * c_sign) >> shift;
 }
 
 static void FUNC(transform_bdpcm)(int *coeffs, const int width, const int height,
diff --git a/libavcodec/vvc/intra.c b/libavcodec/vvc/intra.c
index 7f772fa4ae..bdcb193077 100644
--- a/libavcodec/vvc/intra.c
+++ b/libavcodec/vvc/intra.c
@@ -178,7 +178,7 @@ static void add_residual_for_joint_coding_chroma(VVCLocalContext *lc,
     uint8_t *dst = &fc->frame->data[c_idx][(tb->y0 >> vs) * stride +
                                           ((tb->x0 >> hs) << fc->ps.sps->pixel_shift)];
     if (chroma_scale) {
-        fc->vvcdsp.itx.pred_residual_joint(tb->coeffs, tb->tb_width, tb->tb_height, c_sign, shift);
+        fc->vvcdsp.itx.pred_residual_joint(tb->coeffs, tb->coeffs, tb->tb_width, tb->tb_height, c_sign, shift);
         fc->vvcdsp.intra.lmcs_scale_chroma(lc, tb->coeffs, tb->coeffs, tb->tb_width, tb->tb_height, cu->x0, cu->y0);
         fc->vvcdsp.itx.add_residual(dst, tb->coeffs, tb->tb_width, tb->tb_height, stride);
     } else {
-- 
2.44.0.windows.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [FFmpeg-devel] [PATCH v1 17/23] avcodec/vvc/dsp: add adaptive_color_transform
  2025-05-14 13:40 [FFmpeg-devel] [PATCH v1 01/23] avcodec/vvc/cabac: add 9.3.3.5 k-th order Exp - Golomb binarization process toqsxw
                   ` (14 preceding siblings ...)
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 16/23] avcodec/vvc/dsp: update the interface of pred_residual_joint for joint cbcr residual functionality toqsxw
@ 2025-05-14 13:40 ` toqsxw
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 18/23] avcodec/vvc/intra: fix scaling process for transform coefficients toqsxw
                   ` (6 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: toqsxw @ 2025-05-14 13:40 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Wu Jianhua

From: Wu Jianhua <toqsxw@outlook.com>

See 8.7.4.6 Residual modification process for blocks using colour space conversion

Signed-off-by: Wu Jianhua <toqsxw@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

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [FFmpeg-devel] [PATCH v1 18/23] avcodec/vvc/intra: fix scaling process for transform coefficients
  2025-05-14 13:40 [FFmpeg-devel] [PATCH v1 01/23] avcodec/vvc/cabac: add 9.3.3.5 k-th order Exp - Golomb binarization process toqsxw
                   ` (15 preceding siblings ...)
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 17/23] avcodec/vvc/dsp: add adaptive_color_transform toqsxw
@ 2025-05-14 13:40 ` toqsxw
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 19/23] avcodec/vvc/intra: refact, predict jcbcr to tb->coeffs toqsxw
                   ` (5 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: toqsxw @ 2025-05-14 13:40 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Wu Jianhua

From: Wu Jianhua <toqsxw@outlook.com>

See 8.7.3 Scaling process for transform coefficients

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
---
 libavcodec/vvc/intra.c | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/libavcodec/vvc/intra.c b/libavcodec/vvc/intra.c
index bdcb193077..5f9bbea3d1 100644
--- a/libavcodec/vvc/intra.c
+++ b/libavcodec/vvc/intra.c
@@ -303,21 +303,15 @@ static void scale(int *out, const int *in, const int w, const int h, const int s
 // part of 8.7.3 Scaling process for transform coefficients
 static void derive_qp(const VVCLocalContext *lc, const TransformUnit *tu, TransformBlock *tb)
 {
-    const VVCSPS *sps               = lc->fc->ps.sps;
-    const H266RawSliceHeader *rsh   = lc->sc->sh.r;
-    const CodingUnit *cu            = lc->cu;
-    int qp, qp_act_offset;
+    const VVCSPS *sps             = lc->fc->ps.sps;
+    const H266RawSliceHeader *rsh = lc->sc->sh.r;
+    const CodingUnit *cu          = lc->cu;
+    const bool is_jcbcr           = tb->c_idx && tu->joint_cbcr_residual_flag && tu->coded_flag[CB] && tu->coded_flag[CR];
+    const int idx                 = is_jcbcr ? JCBCR : tb->c_idx;
+    const int qp                  = cu->qp[idx] + (idx ? 0 : sps->qp_bd_offset);
+    const int act_offset[]        = { -5, 1, 3, 1 };
+    const int qp_act_offset       = cu->act_enabled_flag ? act_offset[idx] : 0;
 
-    if (tb->c_idx == 0) {
-        //fix me
-        qp = cu->qp[LUMA] + sps->qp_bd_offset;
-        qp_act_offset = cu->act_enabled_flag ? -5 : 0;
-    } else {
-        const int is_jcbcr = tu->joint_cbcr_residual_flag && tu->coded_flag[CB] && tu->coded_flag[CR];
-        const int idx = is_jcbcr ? JCBCR : tb->c_idx;
-        qp = cu->qp[idx];
-        qp_act_offset = cu->act_enabled_flag ? 1 : 0;
-    }
     if (tb->ts) {
         const int qp_prime_ts_min = 4 + 6 * sps->r->sps_min_qp_prime_ts;
 
-- 
2.44.0.windows.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [FFmpeg-devel] [PATCH v1 19/23] avcodec/vvc/intra: refact, predict jcbcr to tb->coeffs
  2025-05-14 13:40 [FFmpeg-devel] [PATCH v1 01/23] avcodec/vvc/cabac: add 9.3.3.5 k-th order Exp - Golomb binarization process toqsxw
                   ` (16 preceding siblings ...)
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 18/23] avcodec/vvc/intra: fix scaling process for transform coefficients toqsxw
@ 2025-05-14 13:40 ` toqsxw
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 20/23] avcodec/vvc/intra: make lmcs_scale_chroma inplace toqsxw
                   ` (4 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: toqsxw @ 2025-05-14 13:40 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Wu Jianhua

From: Wu Jianhua <toqsxw@outlook.com>

prepare for adaptive color transform

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
---
 libavcodec/vvc/dsp.h          |  1 -
 libavcodec/vvc/dsp_template.c | 18 -------------
 libavcodec/vvc/intra.c        | 51 ++++++++++++++---------------------
 3 files changed, 20 insertions(+), 50 deletions(-)

diff --git a/libavcodec/vvc/dsp.h b/libavcodec/vvc/dsp.h
index e9ef9f5b25..fa1387aadd 100644
--- a/libavcodec/vvc/dsp.h
+++ b/libavcodec/vvc/dsp.h
@@ -122,7 +122,6 @@ typedef struct VVCIntraDSPContext {
 
 typedef struct VVCItxDSPContext {
     void (*add_residual)(uint8_t *dst, const int *res, int width, int height, ptrdiff_t stride);
-    void (*add_residual_joint)(uint8_t *dst, const int *res, int width, int height, ptrdiff_t stride, int c_sign, int shift);
     void (*pred_residual_joint)(int *dst, const int *src, int width, int height, int c_sign, int shift);
 
     void (*itx[VVC_N_TX_TYPE][VVC_N_TX_SIZE])(int *coeffs, ptrdiff_t step, size_t nz);
diff --git a/libavcodec/vvc/dsp_template.c b/libavcodec/vvc/dsp_template.c
index 218a600cce..13bd8cd4a1 100644
--- a/libavcodec/vvc/dsp_template.c
+++ b/libavcodec/vvc/dsp_template.c
@@ -45,23 +45,6 @@ static void FUNC(add_residual)(uint8_t *_dst, const int *res,
     }
 }
 
-static void FUNC(add_residual_joint)(uint8_t *_dst, const int *res,
-    const int w, const int h, const ptrdiff_t _stride, const int c_sign, const int shift)
-{
-    pixel *dst = (pixel *)_dst;
-
-    const int stride = _stride / sizeof(pixel);
-
-    for (int y = 0; y < h; y++) {
-        for (int x = 0; x < w; x++) {
-            const int r = ((*res) * c_sign) >> shift;
-            dst[x] = av_clip_pixel(dst[x] + r);
-            res++;
-        }
-        dst += stride;
-    }
-}
-
 static void FUNC(pred_residual_joint)(int *dst, const int *src, const int w, const int h,
     const int c_sign, const int shift)
 {
@@ -121,7 +104,6 @@ static void FUNC(ff_vvc_itx_dsp_init)(VVCItxDSPContext *const itx)
         VVC_ITX(TYPE, type, 32);
 
     itx->add_residual                = FUNC(add_residual);
-    itx->add_residual_joint          = FUNC(add_residual_joint);
     itx->pred_residual_joint         = FUNC(pred_residual_joint);
     itx->transform_bdpcm             = FUNC(transform_bdpcm);
     VVC_ITX(DCT2, dct2, 2)
diff --git a/libavcodec/vvc/intra.c b/libavcodec/vvc/intra.c
index 5f9bbea3d1..3db3347d8c 100644
--- a/libavcodec/vvc/intra.c
+++ b/libavcodec/vvc/intra.c
@@ -164,28 +164,6 @@ static void derive_transform_type(const VVCFrameContext *fc, const VVCLocalConte
     *trv = mts_to_trv[cu->mts_idx];
 }
 
-static void add_residual_for_joint_coding_chroma(VVCLocalContext *lc,
-    const TransformUnit *tu, TransformBlock *tb, const int chroma_scale)
-{
-    const VVCFrameContext *fc  = lc->fc;
-    const CodingUnit *cu = lc->cu;
-    const int c_sign = 1 - 2 * fc->ps.ph.r->ph_joint_cbcr_sign_flag;
-    const int shift  = tu->coded_flag[1] ^ tu->coded_flag[2];
-    const int c_idx  = 1 + tu->coded_flag[1];
-    const ptrdiff_t stride = fc->frame->linesize[c_idx];
-    const int hs = fc->ps.sps->hshift[c_idx];
-    const int vs = fc->ps.sps->vshift[c_idx];
-    uint8_t *dst = &fc->frame->data[c_idx][(tb->y0 >> vs) * stride +
-                                          ((tb->x0 >> hs) << fc->ps.sps->pixel_shift)];
-    if (chroma_scale) {
-        fc->vvcdsp.itx.pred_residual_joint(tb->coeffs, tb->coeffs, tb->tb_width, tb->tb_height, c_sign, shift);
-        fc->vvcdsp.intra.lmcs_scale_chroma(lc, tb->coeffs, tb->coeffs, tb->tb_width, tb->tb_height, cu->x0, cu->y0);
-        fc->vvcdsp.itx.add_residual(dst, tb->coeffs, tb->tb_width, tb->tb_height, stride);
-    } else {
-        fc->vvcdsp.itx.add_residual_joint(dst, tb->coeffs, tb->tb_width, tb->tb_height, stride, c_sign, shift);
-    }
-}
-
 static int add_reconstructed_area(VVCLocalContext *lc, const int ch_type, const int x0, const int y0, const int w, const int h)
 {
     const VVCSPS *sps       = lc->fc->ps.sps;
@@ -531,7 +509,7 @@ static void itransform(VVCLocalContext *lc, TransformUnit *tu, const int tu_idx,
             const ptrdiff_t stride  = fc->frame->linesize[c_idx];
             const int hs            = sps->hshift[c_idx];
             const int vs            = sps->vshift[c_idx];
-            uint8_t *dst            = &fc->frame->data[c_idx][(tb->y0 >> vs) * stride + ((tb->x0 >> hs) << ps)];
+            const int has_jcbcr     = tu->joint_cbcr_residual_flag && c_idx;
 
             if (cu->bdpcm_flag[tb->c_idx])
                 transform_bdpcm(tb, lc, cu);
@@ -548,14 +526,25 @@ static void itransform(VVCLocalContext *lc, TransformUnit *tu, const int tu_idx,
                     itx_1d(fc, tb, trh, trv);
             }
 
-            if (chroma_scale)
-                fc->vvcdsp.intra.lmcs_scale_chroma(lc, temp, tb->coeffs, w, h, cu->x0, cu->y0);
-            // TODO: Address performance issue here by combining transform, lmcs_scale_chroma, and add_residual into one function.
-            // Complete this task before implementing ASM code.
-            fc->vvcdsp.itx.add_residual(dst, chroma_scale ? temp : tb->coeffs, w, h, stride);
-
-            if (tu->joint_cbcr_residual_flag && tb->c_idx)
-                add_residual_for_joint_coding_chroma(lc, tu, tb, chroma_scale);
+            for (int j = 0; j < 1 + has_jcbcr; j++) {
+                const bool is_jcbcr   = j > 0;
+                const int jcbcr_idx   = CB + tu->coded_flag[CB];
+                TransformBlock *jcbcr = &tu->tbs[jcbcr_idx - tu->tbs[0].c_idx];
+                const int c           = is_jcbcr ? jcbcr_idx : tb->c_idx;
+                int *coeffs           = is_jcbcr ? jcbcr->coeffs : tb->coeffs;
+                uint8_t *dst          = &fc->frame->data[c][(tb->y0 >> vs) * stride + ((tb->x0 >> hs) << ps)];
+
+                if (!j && has_jcbcr) {
+                    const int c_sign = 1 - 2 * fc->ps.ph.r->ph_joint_cbcr_sign_flag;
+                    const int shift  = tu->coded_flag[CB] ^ tu->coded_flag[CR];
+                    fc->vvcdsp.itx.pred_residual_joint(jcbcr->coeffs, tb->coeffs, tb->tb_width, tb->tb_height, c_sign, shift);
+                }
+                if (chroma_scale)
+                    fc->vvcdsp.intra.lmcs_scale_chroma(lc, temp, coeffs, w, h, cu->x0, cu->y0);
+                // TODO: Address performance issue here by combining transform, lmcs_scale_chroma, and add_residual into one function.
+                // Complete this task before implementing ASM code.
+                fc->vvcdsp.itx.add_residual(dst, chroma_scale ? temp : coeffs, w, h, stride);
+            }
         }
     }
 }
-- 
2.44.0.windows.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [FFmpeg-devel] [PATCH v1 20/23] avcodec/vvc/intra: make lmcs_scale_chroma inplace
  2025-05-14 13:40 [FFmpeg-devel] [PATCH v1 01/23] avcodec/vvc/cabac: add 9.3.3.5 k-th order Exp - Golomb binarization process toqsxw
                   ` (17 preceding siblings ...)
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 19/23] avcodec/vvc/intra: refact, predict jcbcr to tb->coeffs toqsxw
@ 2025-05-14 13:40 ` toqsxw
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 21/23] avcodec/vvc/intra: refact out lmcs_scale_chroma and add_residual toqsxw
                   ` (3 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: toqsxw @ 2025-05-14 13:40 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Wu Jianhua

From: Wu Jianhua <toqsxw@outlook.com>

prepare for adaptive color transform

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
---
 libavcodec/vvc/dsp.h            | 2 +-
 libavcodec/vvc/intra.c          | 5 ++---
 libavcodec/vvc/intra_template.c | 7 +++----
 3 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/libavcodec/vvc/dsp.h b/libavcodec/vvc/dsp.h
index fa1387aadd..ae22900931 100644
--- a/libavcodec/vvc/dsp.h
+++ b/libavcodec/vvc/dsp.h
@@ -106,7 +106,7 @@ struct VVCLocalContext;
 
 typedef struct VVCIntraDSPContext {
     void (*intra_cclm_pred)(const struct VVCLocalContext *lc, int x0, int y0, int w, int h);
-    void (*lmcs_scale_chroma)(struct VVCLocalContext *lc, int *dst, const int *coeff, int w, int h, int x0_cu, int y0_cu);
+    void (*lmcs_scale_chroma)(struct VVCLocalContext *lc, int *coeff, int w, int h, int x0_cu, int y0_cu);
     void (*intra_pred)(const struct VVCLocalContext *lc, int x0, int y0, int w, int h, int c_idx);
     void (*pred_planar)(uint8_t *src, const uint8_t *top, const uint8_t *left, int w, int h, ptrdiff_t stride);
     void (*pred_mip)(uint8_t *src, const uint8_t *top, const uint8_t *left, int w, int h, ptrdiff_t stride,
diff --git a/libavcodec/vvc/intra.c b/libavcodec/vvc/intra.c
index 3db3347d8c..b5842a93d1 100644
--- a/libavcodec/vvc/intra.c
+++ b/libavcodec/vvc/intra.c
@@ -495,7 +495,6 @@ static void itransform(VVCLocalContext *lc, TransformUnit *tu, const int tu_idx,
     const VVCSH *sh             = &lc->sc->sh;
     const CodingUnit *cu        = lc->cu;
     const int ps                = fc->ps.sps->pixel_shift;
-    DECLARE_ALIGNED(32, int, temp)[MAX_TB_SIZE * MAX_TB_SIZE];
 
     for (int i = 0; i < tu->nb_tbs; i++) {
         TransformBlock *tb  = &tu->tbs[i];
@@ -540,10 +539,10 @@ static void itransform(VVCLocalContext *lc, TransformUnit *tu, const int tu_idx,
                     fc->vvcdsp.itx.pred_residual_joint(jcbcr->coeffs, tb->coeffs, tb->tb_width, tb->tb_height, c_sign, shift);
                 }
                 if (chroma_scale)
-                    fc->vvcdsp.intra.lmcs_scale_chroma(lc, temp, coeffs, w, h, cu->x0, cu->y0);
+                    fc->vvcdsp.intra.lmcs_scale_chroma(lc, coeffs, w, h, cu->x0, cu->y0);
                 // TODO: Address performance issue here by combining transform, lmcs_scale_chroma, and add_residual into one function.
                 // Complete this task before implementing ASM code.
-                fc->vvcdsp.itx.add_residual(dst, chroma_scale ? temp : coeffs, w, h, stride);
+                fc->vvcdsp.itx.add_residual(dst, coeffs, w, h, stride);
             }
         }
     }
diff --git a/libavcodec/vvc/intra_template.c b/libavcodec/vvc/intra_template.c
index 440ac5b6cc..3ec6c72213 100644
--- a/libavcodec/vvc/intra_template.c
+++ b/libavcodec/vvc/intra_template.c
@@ -428,7 +428,7 @@ static int FUNC(lmcs_derive_chroma_scale)(VVCLocalContext *lc, const int x0, con
 }
 
 // 8.7.5.3 Picture reconstruction with luma dependent chroma residual scaling process for chroma samples
-static void FUNC(lmcs_scale_chroma)(VVCLocalContext *lc, int *dst, const int *coeff,
+static void FUNC(lmcs_scale_chroma)(VVCLocalContext *lc, int *coeff,
     const int width, const int height, const int x0_cu, const int y0_cu)
 {
     const int chroma_scale = FUNC(lmcs_derive_chroma_scale)(lc, x0_cu, y0_cu);
@@ -438,11 +438,10 @@ static void FUNC(lmcs_scale_chroma)(VVCLocalContext *lc, int *dst, const int *co
             const int c = av_clip_intp2(*coeff, BIT_DEPTH);
 
             if (c > 0)
-                *dst = (c * chroma_scale + (1 << 10)) >> 11;
+                *coeff = (c * chroma_scale + (1 << 10)) >> 11;
             else
-                *dst = -((-c * chroma_scale + (1 << 10)) >> 11);
+                *coeff = -((-c * chroma_scale + (1 << 10)) >> 11);
             coeff++;
-            dst++;
         }
     }
 }
-- 
2.44.0.windows.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [FFmpeg-devel] [PATCH v1 21/23] avcodec/vvc/intra: refact out lmcs_scale_chroma and add_residual
  2025-05-14 13:40 [FFmpeg-devel] [PATCH v1 01/23] avcodec/vvc/cabac: add 9.3.3.5 k-th order Exp - Golomb binarization process toqsxw
                   ` (18 preceding siblings ...)
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 20/23] avcodec/vvc/intra: make lmcs_scale_chroma inplace toqsxw
@ 2025-05-14 13:40 ` toqsxw
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 22/23] avcodec/vvc: add adaptive color transform support toqsxw
                   ` (2 subsequent siblings)
  22 siblings, 0 replies; 26+ messages in thread
From: toqsxw @ 2025-05-14 13:40 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Wu Jianhua

From: Wu Jianhua <toqsxw@outlook.com>

prepare for adaptive color transform

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
---
 libavcodec/vvc/intra.c | 107 ++++++++++++++++++++++++-----------------
 1 file changed, 63 insertions(+), 44 deletions(-)

diff --git a/libavcodec/vvc/intra.c b/libavcodec/vvc/intra.c
index b5842a93d1..0ea33e1e73 100644
--- a/libavcodec/vvc/intra.c
+++ b/libavcodec/vvc/intra.c
@@ -27,6 +27,10 @@
 #include "intra.h"
 #include "itx_1d.h"
 
+#define POS(c_idx, x, y)    \
+    &fc->frame->data[c_idx][((y) >> fc->ps.sps->vshift[c_idx]) * fc->frame->linesize[c_idx] +   \
+        (((x) >> fc->ps.sps->hshift[c_idx]) << fc->ps.sps->pixel_shift)]
+
 static int is_cclm(enum IntraPredMode mode)
 {
     return mode == INTRA_LT_CCLM || mode == INTRA_L_CCLM || mode == INTRA_T_CCLM;
@@ -488,28 +492,65 @@ static void transform_bdpcm(TransformBlock *tb, const VVCLocalContext *lc, const
         tb->max_scan_x = tb->tb_width - 1;
 }
 
-static void itransform(VVCLocalContext *lc, TransformUnit *tu, const int tu_idx, const int target_ch_type)
+static void lmcs_scale_chroma(VVCLocalContext *lc, TransformUnit *tu, TransformBlock *tb, const int target_ch_type)
 {
-    const VVCFrameContext *fc   = lc->fc;
-    const VVCSPS *sps           = fc->ps.sps;
-    const VVCSH *sh             = &lc->sc->sh;
-    const CodingUnit *cu        = lc->cu;
-    const int ps                = fc->ps.sps->pixel_shift;
+    const VVCFrameContext *fc = lc->fc;
+    const VVCSH *sh           = &lc->sc->sh;
+    const CodingUnit *cu      = lc->cu;
+    const int c_idx           = tb->c_idx;
+    const int ch_type         = c_idx > 0;
+    const int w               = tb->tb_width;
+    const int h               = tb->tb_height;
+    const int chroma_scale    = ch_type && sh->r->sh_lmcs_used_flag && fc->ps.ph.r->ph_chroma_residual_scale_flag && (w * h > 4);
+    const int has_jcbcr       = tu->joint_cbcr_residual_flag && c_idx;
+
+    for (int j = 0; j < 1 + has_jcbcr; j++) {
+        const bool is_jcbcr   = j > 0;
+        const int jcbcr_idx   = CB + tu->coded_flag[CB];
+        TransformBlock *jcbcr = &tu->tbs[jcbcr_idx - tu->tbs[0].c_idx];
+        int *coeffs           = is_jcbcr ? jcbcr->coeffs : tb->coeffs;
+
+        if (!j && has_jcbcr) {
+            const int c_sign = 1 - 2 * fc->ps.ph.r->ph_joint_cbcr_sign_flag;
+            const int shift  = tu->coded_flag[CB] ^ tu->coded_flag[CR];
+            fc->vvcdsp.itx.pred_residual_joint(jcbcr->coeffs, tb->coeffs, w, h, c_sign, shift);
+        }
+        if (chroma_scale)
+            fc->vvcdsp.intra.lmcs_scale_chroma(lc, coeffs, w, h, cu->x0, cu->y0);
+    }
+}
+
+static void add_residual(const VVCLocalContext *lc, TransformUnit *tu, const int target_ch_type)
+{
+    const VVCFrameContext *fc = lc->fc;
 
     for (int i = 0; i < tu->nb_tbs; i++) {
-        TransformBlock *tb  = &tu->tbs[i];
-        const int c_idx     = tb->c_idx;
-        const int ch_type   = c_idx > 0;
-
-        if (ch_type == target_ch_type && tb->has_coeffs) {
-            const int w             = tb->tb_width;
-            const int h             = tb->tb_height;
-            const int chroma_scale  = ch_type && sh->r->sh_lmcs_used_flag && fc->ps.ph.r->ph_chroma_residual_scale_flag && (w * h > 4);
-            const ptrdiff_t stride  = fc->frame->linesize[c_idx];
-            const int hs            = sps->hshift[c_idx];
-            const int vs            = sps->vshift[c_idx];
-            const int has_jcbcr     = tu->joint_cbcr_residual_flag && c_idx;
+        TransformBlock *tb      = tu->tbs + i;
+        const int c_idx         = tb->c_idx;
+        const int ch_type       = c_idx > 0;
+        const ptrdiff_t stride  = fc->frame->linesize[c_idx];
+        const bool has_residual = tb->has_coeffs ||
+                                  (c_idx && tu->joint_cbcr_residual_flag);
+        uint8_t *dst            = POS(c_idx, tb->x0, tb->y0);
+
+        if (ch_type == target_ch_type && has_residual)
+             fc->vvcdsp.itx.add_residual(dst, tb->coeffs, tb->tb_width, tb->tb_height, stride);
+    }
+}
+
+static void itransform(VVCLocalContext *lc, TransformUnit *tu, const int target_ch_type)
+{
+    const VVCFrameContext *fc = lc->fc;
+    const CodingUnit *cu      = lc->cu;
+    TransformBlock *tbs       = tu->tbs;
+
+    for (int i = 0; i < tu->nb_tbs; i++) {
+        TransformBlock *tb = tbs + i;
+        const int c_idx    = tb->c_idx;
+        const int ch_type  = c_idx > 0;
+        const bool do_itx  = ch_type == target_ch_type;
 
+        if (tb->has_coeffs && do_itx) {
             if (cu->bdpcm_flag[tb->c_idx])
                 transform_bdpcm(tb, lc, cu);
             dequant(lc, tu, tb);
@@ -519,33 +560,15 @@ static void itransform(VVCLocalContext *lc, TransformUnit *tu, const int tu_idx,
                 if (cu->apply_lfnst_flag[c_idx])
                     ilfnst_transform(lc, tb);
                 derive_transform_type(fc, lc, tb, &trh, &trv);
-                if (w > 1 && h > 1)
+                if (tb->tb_width > 1 && tb->tb_height > 1)
                     itx_2d(fc, tb, trh, trv);
                 else
                     itx_1d(fc, tb, trh, trv);
             }
-
-            for (int j = 0; j < 1 + has_jcbcr; j++) {
-                const bool is_jcbcr   = j > 0;
-                const int jcbcr_idx   = CB + tu->coded_flag[CB];
-                TransformBlock *jcbcr = &tu->tbs[jcbcr_idx - tu->tbs[0].c_idx];
-                const int c           = is_jcbcr ? jcbcr_idx : tb->c_idx;
-                int *coeffs           = is_jcbcr ? jcbcr->coeffs : tb->coeffs;
-                uint8_t *dst          = &fc->frame->data[c][(tb->y0 >> vs) * stride + ((tb->x0 >> hs) << ps)];
-
-                if (!j && has_jcbcr) {
-                    const int c_sign = 1 - 2 * fc->ps.ph.r->ph_joint_cbcr_sign_flag;
-                    const int shift  = tu->coded_flag[CB] ^ tu->coded_flag[CR];
-                    fc->vvcdsp.itx.pred_residual_joint(jcbcr->coeffs, tb->coeffs, tb->tb_width, tb->tb_height, c_sign, shift);
-                }
-                if (chroma_scale)
-                    fc->vvcdsp.intra.lmcs_scale_chroma(lc, coeffs, w, h, cu->x0, cu->y0);
-                // TODO: Address performance issue here by combining transform, lmcs_scale_chroma, and add_residual into one function.
-                // Complete this task before implementing ASM code.
-                fc->vvcdsp.itx.add_residual(dst, coeffs, w, h, stride);
-            }
+            lmcs_scale_chroma(lc, tu, tb, target_ch_type);
         }
     }
+    add_residual(lc, tu, target_ch_type);
 }
 
 static int reconstruct(VVCLocalContext *lc)
@@ -559,17 +582,13 @@ static int reconstruct(VVCLocalContext *lc)
         TransformUnit *tu = cu->tus.head;
         for (int i = 0; tu; i++) {
             predict_intra(lc, tu, i, ch_type);
-            itransform(lc, tu, i, ch_type);
+            itransform(lc, tu, ch_type);
             tu = tu->next;
         }
     }
     return 0;
 }
 
-#define POS(c_idx, x, y)    \
-    &fc->frame->data[c_idx][((y) >> fc->ps.sps->vshift[c_idx]) * fc->frame->linesize[c_idx] +   \
-        (((x) >> fc->ps.sps->hshift[c_idx]) << fc->ps.sps->pixel_shift)]
-
 #define IBC_POS(c_idx, x, y) \
     (fc->tab.ibc_vir_buf[c_idx] + \
         (x << ps) + (y + ((cu->y0 & ~(sps->ctb_size_y - 1)) >> vs)) * ibc_stride)
-- 
2.44.0.windows.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [FFmpeg-devel] [PATCH v1 22/23] avcodec/vvc: add adaptive color transform support
  2025-05-14 13:40 [FFmpeg-devel] [PATCH v1 01/23] avcodec/vvc/cabac: add 9.3.3.5 k-th order Exp - Golomb binarization process toqsxw
                   ` (19 preceding siblings ...)
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 21/23] avcodec/vvc/intra: refact out lmcs_scale_chroma and add_residual toqsxw
@ 2025-05-14 13:40 ` toqsxw
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 23/23] Changelog: VVC supports all content of SCC toqsxw
  2025-05-14 13:46 ` [FFmpeg-devel] 回复: [PATCH v1 01/23] avcodec/vvc/cabac: add 9.3.3.5 k-th order Exp - Golomb binarization process Wu Jianhua
  22 siblings, 0 replies; 26+ messages in thread
From: toqsxw @ 2025-05-14 13:40 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Wu Jianhua

From: Wu Jianhua <toqsxw@outlook.com>

passed files:
    ACT_A_Kwai_3.bit
    ACT_B_Kwai_3.bit

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
---
 libavcodec/vvc/ctu.c   |  2 ++
 libavcodec/vvc/intra.c | 13 +++++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/libavcodec/vvc/ctu.c b/libavcodec/vvc/ctu.c
index e160199580..62c9d4f5c0 100644
--- a/libavcodec/vvc/ctu.c
+++ b/libavcodec/vvc/ctu.c
@@ -392,6 +392,8 @@ static int hls_transform_unit(VVCLocalContext *lc, int x0, int y0,int tu_width,
             if (ret < 0)
                 return ret;
             set_tb_tab(fc->tab.tu_coded_flag[tb->c_idx], tu->coded_flag[tb->c_idx], fc, tb);
+        } else if (cu->act_enabled_flag) {
+            memset(tb->coeffs, 0, tb->tb_width * tb->tb_height * sizeof(*tb->coeffs));
         }
         if (tb->c_idx != CR)
             set_tb_size(fc, tb);
diff --git a/libavcodec/vvc/intra.c b/libavcodec/vvc/intra.c
index 0ea33e1e73..f56b43be66 100644
--- a/libavcodec/vvc/intra.c
+++ b/libavcodec/vvc/intra.c
@@ -523,13 +523,14 @@ static void lmcs_scale_chroma(VVCLocalContext *lc, TransformUnit *tu, TransformB
 static void add_residual(const VVCLocalContext *lc, TransformUnit *tu, const int target_ch_type)
 {
     const VVCFrameContext *fc = lc->fc;
+    const CodingUnit *cu      = lc->cu;
 
     for (int i = 0; i < tu->nb_tbs; i++) {
         TransformBlock *tb      = tu->tbs + i;
         const int c_idx         = tb->c_idx;
         const int ch_type       = c_idx > 0;
         const ptrdiff_t stride  = fc->frame->linesize[c_idx];
-        const bool has_residual = tb->has_coeffs ||
+        const bool has_residual = tb->has_coeffs || cu->act_enabled_flag ||
                                   (c_idx && tu->joint_cbcr_residual_flag);
         uint8_t *dst            = POS(c_idx, tb->x0, tb->y0);
 
@@ -543,12 +544,13 @@ static void itransform(VVCLocalContext *lc, TransformUnit *tu, const int target_
     const VVCFrameContext *fc = lc->fc;
     const CodingUnit *cu      = lc->cu;
     TransformBlock *tbs       = tu->tbs;
+    const bool is_act_luma    = cu->act_enabled_flag && target_ch_type == LUMA;
 
     for (int i = 0; i < tu->nb_tbs; i++) {
         TransformBlock *tb = tbs + i;
         const int c_idx    = tb->c_idx;
         const int ch_type  = c_idx > 0;
-        const bool do_itx  = ch_type == target_ch_type;
+        const bool do_itx  = is_act_luma || !cu->act_enabled_flag && ch_type == target_ch_type;
 
         if (tb->has_coeffs && do_itx) {
             if (cu->bdpcm_flag[tb->c_idx])
@@ -568,6 +570,13 @@ static void itransform(VVCLocalContext *lc, TransformUnit *tu, const int target_
             lmcs_scale_chroma(lc, tu, tb, target_ch_type);
         }
     }
+
+    if (is_act_luma) {
+        fc->vvcdsp.itx.adaptive_color_transform(
+            tbs[LUMA].coeffs, tbs[CB].coeffs, tbs[CR].coeffs,
+            tbs[LUMA].tb_width, tbs[LUMA].tb_height);
+    }
+
     add_residual(lc, tu, target_ch_type);
 }
 
-- 
2.44.0.windows.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [FFmpeg-devel] [PATCH v1 23/23] Changelog: VVC supports all content of SCC
  2025-05-14 13:40 [FFmpeg-devel] [PATCH v1 01/23] avcodec/vvc/cabac: add 9.3.3.5 k-th order Exp - Golomb binarization process toqsxw
                   ` (20 preceding siblings ...)
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 22/23] avcodec/vvc: add adaptive color transform support toqsxw
@ 2025-05-14 13:40 ` toqsxw
  2025-05-14 13:46 ` [FFmpeg-devel] 回复: [PATCH v1 01/23] avcodec/vvc/cabac: add 9.3.3.5 k-th order Exp - Golomb binarization process Wu Jianhua
  22 siblings, 0 replies; 26+ messages in thread
From: toqsxw @ 2025-05-14 13:40 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Wu Jianhua

From: Wu Jianhua <toqsxw@outlook.com>

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
---
 Changelog | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Changelog b/Changelog
index a09dcd82c2..4f47b30038 100644
--- a/Changelog
+++ b/Changelog
@@ -11,6 +11,8 @@ version <next>:
 - Enhanced FLV v2: Multitrack audio/video, modern codec support
 - Animated JPEG XL encoding (via libjxl)
 - VVC in Matroska
+- VVC decoder supports all content of SCC (Screen Content Coding):
+  IBC (Inter Block Copy), Palette Mode and ACT (Adaptive Color Transform)
 
 version 7.1:
 - Raw Captions with Time (RCWT) closed caption demuxer
@@ -53,7 +55,6 @@ version 7.1:
   constrains
 - FFV1 parser
 
-
 version 7.0:
 - DXV DXT1 encoder
 - LEAD MCMP decoder
-- 
2.44.0.windows.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [FFmpeg-devel] 回复: [PATCH v1 01/23] avcodec/vvc/cabac: add 9.3.3.5 k-th order Exp - Golomb binarization process
  2025-05-14 13:40 [FFmpeg-devel] [PATCH v1 01/23] avcodec/vvc/cabac: add 9.3.3.5 k-th order Exp - Golomb binarization process toqsxw
                   ` (21 preceding siblings ...)
  2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 23/23] Changelog: VVC supports all content of SCC toqsxw
@ 2025-05-14 13:46 ` Wu Jianhua
  2025-05-17  5:39   ` [FFmpeg-devel] " Nuo Mi
  22 siblings, 1 reply; 26+ messages in thread
From: Wu Jianhua @ 2025-05-14 13:46 UTC (permalink / raw)
  To: toqsxw, ffmpeg-devel, Nuo Mi

Wu Jianhua:
> From: Wu Jianhua <toqsxw@outlook.com>
>
> Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
> ---
>  libavcodec/vvc/cabac.c | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
>
> diff --git a/libavcodec/vvc/cabac.c b/libavcodec/vvc/cabac.c
> index 5510144893..54055ed736 100644
> --- a/libavcodec/vvc/cabac.c
> +++ b/libavcodec/vvc/cabac.c
> @@ -928,6 +928,27 @@ static int truncated_binary_decode(VVCLocalContext *lc, const int c_max)
>      return v;
>  }

The patchset before didn't appear on the patchwork, so resend it for CI build.

Thanks,
Jianhua


_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [FFmpeg-devel] [PATCH v1 01/23] avcodec/vvc/cabac: add 9.3.3.5 k-th order Exp - Golomb binarization process
  2025-05-14 13:46 ` [FFmpeg-devel] 回复: [PATCH v1 01/23] avcodec/vvc/cabac: add 9.3.3.5 k-th order Exp - Golomb binarization process Wu Jianhua
@ 2025-05-17  5:39   ` Nuo Mi
  0 siblings, 0 replies; 26+ messages in thread
From: Nuo Mi @ 2025-05-17  5:39 UTC (permalink / raw)
  To: Wu Jianhua; +Cc: toqsxw, ffmpeg-devel

On Wed, May 14, 2025 at 9:46 PM Wu Jianhua <toqsxw@outlook.com> wrote:

> Wu Jianhua:
> > From: Wu Jianhua <toqsxw@outlook.com>
> >
> > Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
> > ---
> >  libavcodec/vvc/cabac.c | 21 +++++++++++++++++++++
> >  1 file changed, 21 insertions(+)
> >
> > diff --git a/libavcodec/vvc/cabac.c b/libavcodec/vvc/cabac.c
> > index 5510144893..54055ed736 100644
> > --- a/libavcodec/vvc/cabac.c
> > +++ b/libavcodec/vvc/cabac.c
> > @@ -928,6 +928,27 @@ static int truncated_binary_decode(VVCLocalContext
> *lc, const int c_max)
> >      return v;
> >  }
>
> The patchset before didn't appear on the patchwork, so resend it for CI
> build.
>
Hi Jianhua,

Patch applied.
Thank you again for your excellent work.

> 
> Thanks,
> Jianhua
>
>
>
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [FFmpeg-devel] [PATCH v1 03/23] avcodec/vvc/cabac: add palette support
  2025-05-01 14:42 toqsxw
@ 2025-05-01 14:43 ` toqsxw
  0 siblings, 0 replies; 26+ messages in thread
From: toqsxw @ 2025-05-01 14:43 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Wu Jianhua

From: Wu Jianhua <toqsxw@outlook.com>

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
---
 libavcodec/vvc/cabac.c | 52 ++++++++++++++++++++++++++++++++++++++++++
 libavcodec/vvc/cabac.h |  9 ++++++++
 2 files changed, 61 insertions(+)

diff --git a/libavcodec/vvc/cabac.c b/libavcodec/vvc/cabac.c
index 9290ecd90f..700b719b7c 100644
--- a/libavcodec/vvc/cabac.c
+++ b/libavcodec/vvc/cabac.c
@@ -1377,6 +1377,58 @@ int ff_vvc_intra_chroma_pred_mode(VVCLocalContext *lc)
     return (get_cabac_bypass(&lc->ep->cc) << 1) | get_cabac_bypass(&lc->ep->cc);
 }
 
+int ff_vvc_palette_predictor_run(VVCLocalContext *lc)
+{
+    return kth_order_egk_decode(&lc->ep->cc, 0);
+}
+
+int ff_vvc_num_signalled_palette_entries(VVCLocalContext *lc)
+{
+    return kth_order_egk_decode(&lc->ep->cc, 0);
+}
+
+int ff_vvc_new_palette_entries(VVCLocalContext *lc, const int bit_depth)
+{
+    return fixed_length_decode(&lc->ep->cc, bit_depth);
+}
+
+bool ff_vvc_palette_escape_val_present_flag(VVCLocalContext *lc)
+{
+    return get_cabac_bypass(&lc->ep->cc);
+}
+
+bool ff_vvc_palette_transpose_flag(VVCLocalContext *lc)
+{
+    return GET_CABAC(PALETTE_TRANSPOSE_FLAG);
+}
+
+bool ff_vvc_run_copy_flag(VVCLocalContext *lc, const int prev_run_type, const int prev_run_position, const int cur_pos)
+{
+    uint8_t run_left_lut[] = { 0, 1, 2, 3, 4 };
+    uint8_t run_top_lut[] = { 5, 6, 6, 7, 7 };
+
+    int bin_dist = cur_pos - prev_run_position - 1;
+    uint8_t *run_lut = prev_run_type == 1 ? run_top_lut : run_left_lut;
+    uint8_t ctx_inc = bin_dist <= 4 ? run_lut[bin_dist] : run_lut[4];
+
+    return GET_CABAC(RUN_COPY_FLAG + ctx_inc);
+}
+
+bool ff_vvc_copy_above_palette_indices_flag(VVCLocalContext *lc)
+{
+    return GET_CABAC(COPY_ABOVE_PALETTE_INDICES_FLAG);
+}
+
+int ff_vvc_palette_idx_idc(VVCLocalContext *lc, const int max_palette_index, const bool adjust)
+{
+    return truncated_binary_decode(lc, max_palette_index - adjust);
+}
+
+int ff_vvc_palette_escape_val(VVCLocalContext *lc)
+{
+    return kth_order_egk_decode(&lc->ep->cc, 5);
+}
+
 int ff_vvc_general_merge_flag(VVCLocalContext *lc)
 {
     return GET_CABAC(GENERAL_MERGE_FLAG);
diff --git a/libavcodec/vvc/cabac.h b/libavcodec/vvc/cabac.h
index e9bc98e23a..92f0163c85 100644
--- a/libavcodec/vvc/cabac.h
+++ b/libavcodec/vvc/cabac.h
@@ -81,6 +81,15 @@ int ff_vvc_intra_luma_mpm_remainder(VVCLocalContext *lc);
 int ff_vvc_cclm_mode_flag(VVCLocalContext *lc);
 int ff_vvc_cclm_mode_idx(VVCLocalContext *lc);
 int ff_vvc_intra_chroma_pred_mode(VVCLocalContext *lc);
+int ff_vvc_palette_predictor_run(VVCLocalContext *lc);
+int ff_vvc_num_signalled_palette_entries(VVCLocalContext *lc);
+int ff_vvc_new_palette_entries(VVCLocalContext *lc, int bit_dpeth);
+bool ff_vvc_palette_escape_val_present_flag(VVCLocalContext *lc);
+bool ff_vvc_palette_transpose_flag(VVCLocalContext *lc);
+bool ff_vvc_run_copy_flag(VVCLocalContext *lc, int prev_run_type, int prev_run_position, int cur_pos);
+bool ff_vvc_copy_above_palette_indices_flag(VVCLocalContext *lc);
+int ff_vvc_palette_idx_idc(VVCLocalContext *lc, int max_palette_index, bool adjust);
+int ff_vvc_palette_escape_val(VVCLocalContext *lc);
 
 //inter
 int ff_vvc_general_merge_flag(VVCLocalContext *lc);
-- 
2.44.0.windows.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2025-05-17  5:39 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-14 13:40 [FFmpeg-devel] [PATCH v1 01/23] avcodec/vvc/cabac: add 9.3.3.5 k-th order Exp - Golomb binarization process toqsxw
2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 02/23] avcodec/vvc/cabac: add 9.3.3.7 Fixed-length " toqsxw
2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 03/23] avcodec/vvc/cabac: add palette support toqsxw
2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 04/23] avcodec/vvc: add VVC_MAX_NUM_PALETTE_PREDICTOR_SIZE toqsxw
2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 05/23] avcodec/vvc/ctu: refact out ff_vvc_channel_range toqsxw
2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 06/23] avcodec/vvc: refact out ep_init and ep_init_wpp toqsxw
2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 07/23] avcodec/vvc: refact, save pf and ciip_flag in ff_vvc_set_intra_mvf toqsxw
2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 08/23] avcodec/vvc/ctu: refact out intra_data toqsxw
2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 09/23] avcodec/vvc/intra: add ff_vvc_palette_derive_scale toqsxw
2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 10/23] avcodec/vvc/ctu: add palette support toqsxw
2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 11/23] avcodec/vvc/filter: skip deblocking filter for palette toqsxw
2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 12/23] avcodec/vvc/intra: add palette coding decoder toqsxw
2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 13/23] avcodec/vvc/cabac: add ff_vvc_cu_act_enabled_flag toqsxw
2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 14/23] avcodec/vvc/ctu: read act_enabled_flag for adaptive color transform toqsxw
2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 15/23] avcodec/vvc/ctu: fix derive_chroma_intra_pred_mode toqsxw
2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 16/23] avcodec/vvc/dsp: update the interface of pred_residual_joint for joint cbcr residual functionality toqsxw
2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 17/23] avcodec/vvc/dsp: add adaptive_color_transform toqsxw
2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 18/23] avcodec/vvc/intra: fix scaling process for transform coefficients toqsxw
2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 19/23] avcodec/vvc/intra: refact, predict jcbcr to tb->coeffs toqsxw
2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 20/23] avcodec/vvc/intra: make lmcs_scale_chroma inplace toqsxw
2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 21/23] avcodec/vvc/intra: refact out lmcs_scale_chroma and add_residual toqsxw
2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 22/23] avcodec/vvc: add adaptive color transform support toqsxw
2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 23/23] Changelog: VVC supports all content of SCC toqsxw
2025-05-14 13:46 ` [FFmpeg-devel] 回复: [PATCH v1 01/23] avcodec/vvc/cabac: add 9.3.3.5 k-th order Exp - Golomb binarization process Wu Jianhua
2025-05-17  5:39   ` [FFmpeg-devel] " Nuo Mi
  -- strict thread matches above, loose matches on Subject: below --
2025-05-01 14:42 toqsxw
2025-05-01 14:43 ` [FFmpeg-devel] [PATCH v1 03/23] avcodec/vvc/cabac: add palette support toqsxw

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