Commit c77ac81c68 for ffmpeg

commit c77ac81c68ca83736844862fc31b3a5571a3d72d
Author: Wu Jianhua <toqsxw@outlook.com>
Date:   Sun Sep 6 11:18:31 2026 +0800

    avcodec/vvc/ps: support 14/16-bit LMCS

    Signed-off-by: Wu Jianhua <toqsxw@outlook.com>

diff --git a/libavcodec/vvc/ps.c b/libavcodec/vvc/ps.c
index caa42d45b7..8d6cf31eec 100644
--- a/libavcodec/vvc/ps.c
+++ b/libavcodec/vvc/ps.c
@@ -829,10 +829,10 @@ static int ph_compute_poc(const H266RawPictureHeader *ph, const H266RawSPS *sps,
 }

 static av_always_inline uint16_t lmcs_derive_lut_sample(uint16_t sample,
-    uint16_t *pivot1, uint16_t *pivot2, uint16_t *scale_coeff, const int idx, const int max)
+    uint32_t *pivot1, uint32_t *pivot2, uint16_t *scale_coeff, const int idx, const int max)
 {
     const int lut_sample =
-        pivot1[idx] + ((scale_coeff[idx] * (sample - pivot2[idx]) + (1<< 10)) >> 11);
+        pivot1[idx] + (((int64_t)scale_coeff[idx] * (sample - (int)pivot2[idx]) + (1<< 10)) >> 11);
     return av_clip(lut_sample, 0, max - 1);
 }

@@ -845,7 +845,7 @@ static int lmcs_derive_lut(VVCLMCS *lmcs, const H266RawAPS *rlmcs, const H266Raw
     const int shift     = av_log2(org_cw);
     const int off       = 1 << (shift - 1);
     int cw[LMCS_MAX_BIN_SIZE];
-    uint16_t input_pivot[LMCS_MAX_BIN_SIZE];
+    uint32_t input_pivot[LMCS_MAX_BIN_SIZE];
     uint16_t scale_coeff[LMCS_MAX_BIN_SIZE];
     uint16_t inv_scale_coeff[LMCS_MAX_BIN_SIZE];
     int i, delta_crs, sum_cw = 0;
@@ -890,7 +890,7 @@ static int lmcs_derive_lut(VVCLMCS *lmcs, const H266RawAPS *rlmcs, const H266Raw
     }

     //derive lmcs_fwd_lut
-    for (uint16_t sample = 0; sample < max; sample++) {
+    for (int sample = 0; sample < max; sample++) {
         const int idx_y = sample >> shift;
         const uint16_t fwd_sample = lmcs_derive_lut_sample(sample, lmcs->pivot,
             input_pivot, scale_coeff, idx_y, max);
@@ -903,7 +903,7 @@ static int lmcs_derive_lut(VVCLMCS *lmcs, const H266RawAPS *rlmcs, const H266Raw

     //derive lmcs_inv_lut
     i = lmcs->min_bin_idx;
-    for (uint16_t sample = 0; sample < max; sample++) {
+    for (int sample = 0; sample < max; sample++) {
         uint16_t inv_sample;
         while (i <= lmcs->max_bin_idx && sample >= lmcs->pivot[i + 1])
             i++;
diff --git a/libavcodec/vvc/ps.h b/libavcodec/vvc/ps.h
index 95ee1d7f96..36ecb37cb7 100644
--- a/libavcodec/vvc/ps.h
+++ b/libavcodec/vvc/ps.h
@@ -43,7 +43,7 @@
 #define GDR_IS_RECOVERED(s)  (s->gdr_recovery_point_poc == INV_POC)
 #define GDR_SET_RECOVERED(s) (s->gdr_recovery_point_poc =  INV_POC)

-#define LMCS_MAX_BIT_DEPTH  12
+#define LMCS_MAX_BIT_DEPTH  16
 #define LMCS_MAX_LUT_SIZE   (1 << LMCS_MAX_BIT_DEPTH)
 #define LMCS_MAX_BIN_SIZE   16
 #define LADF_MAX_INTERVAL   5
@@ -207,7 +207,7 @@ typedef struct VVCLMCS {
         uint16_t u16[LMCS_MAX_LUT_SIZE]; ///< for high bit-depth
     } fwd_lut, inv_lut;

-    uint16_t pivot[LMCS_MAX_BIN_SIZE + 1];
+    uint32_t pivot[LMCS_MAX_BIN_SIZE + 1];
     uint16_t chroma_scale_coeff[LMCS_MAX_BIN_SIZE];
 } VVCLMCS;