FFmpeg
ctu.c
Go to the documentation of this file.
1 /*
2  * VVC CTU(Coding Tree Unit) parser
3  *
4  * Copyright (C) 2022 Nuo Mi
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include "libavutil/error.h"
24 #include "libavutil/refstruct.h"
25 
26 #include "cabac.h"
27 #include "ctu.h"
28 #include "inter.h"
29 #include "intra.h"
30 #include "mvs.h"
31 
32 #define PROF_TEMP_SIZE (PROF_BLOCK_SIZE) * sizeof(int16_t)
33 
34 #define TAB_MSM(fc, depth, x, y) fc->tab.msm[(depth)][((y) >> 5) * fc->ps.pps->width32 + ((x) >> 5)]
35 #define TAB_ISPMF(fc, x, y) fc->tab.ispmf[((y) >> 6) * fc->ps.pps->width64 + ((x) >> 6)]
36 
37 typedef enum VVCModeType {
41 } VVCModeType;
42 
43 static void set_tb_size(const VVCFrameContext *fc, const TransformBlock *tb)
44 {
45  const int x_tb = tb->x0 >> MIN_TU_LOG2;
46  const int y_tb = tb->y0 >> MIN_TU_LOG2;
47  const int hs = fc->ps.sps->hshift[tb->c_idx];
48  const int vs = fc->ps.sps->vshift[tb->c_idx];
49  const int is_chroma = tb->c_idx != 0;
50  const int width = FFMAX(1, tb->tb_width >> (MIN_TU_LOG2 - hs));
51  const int end = y_tb + FFMAX(1, tb->tb_height >> (MIN_TU_LOG2 - vs));
52 
53  for (int y = y_tb; y < end; y++) {
54  const int off = y * fc->ps.pps->min_tu_width + x_tb;
55  memset(fc->tab.tb_width [is_chroma] + off, tb->tb_width, width);
56  memset(fc->tab.tb_height[is_chroma] + off, tb->tb_height, width);
57  }
58 }
59 
60 static void set_tb_tab(uint8_t *tab, uint8_t v, const VVCFrameContext *fc,
61  const TransformBlock *tb)
62 {
63  const int width = tb->tb_width << fc->ps.sps->hshift[tb->c_idx];
64  const int height = tb->tb_height << fc->ps.sps->vshift[tb->c_idx];
65 
66  for (int h = 0; h < height; h += MIN_TU_SIZE) {
67  const int y = (tb->y0 + h) >> MIN_TU_LOG2;
68  const int off = y * fc->ps.pps->min_tu_width + (tb->x0 >> MIN_TU_LOG2);
69  const int w = FFMAX(1, width >> MIN_TU_LOG2);
70  memset(tab + off, v, w);
71  }
72 }
73 
74 // 8.7.1 Derivation process for quantization parameters
75 static int get_qp_y_pred(const VVCLocalContext *lc)
76 {
77  const VVCFrameContext *fc = lc->fc;
78  const VVCSPS *sps = fc->ps.sps;
79  const VVCPPS *pps = fc->ps.pps;
80  const CodingUnit *cu = lc->cu;
81  const int ctb_log2_size = sps->ctb_log2_size_y;
82  const int ctb_size_mask = (1 << ctb_log2_size) - 1;
83  const int xQg = lc->parse.cu_qg_top_left_x;
84  const int yQg = lc->parse.cu_qg_top_left_y;
85  const int min_cb_width = fc->ps.pps->min_cb_width;
86  const int x_cb = cu->x0 >> sps->min_cb_log2_size_y;
87  const int y_cb = cu->y0 >> sps->min_cb_log2_size_y;
88  const int rx = cu->x0 >> ctb_log2_size;
89  const int ry = cu->y0 >> ctb_log2_size;
90  const int in_same_ctb_a = ((xQg - 1) >> ctb_log2_size) == rx && (yQg >> ctb_log2_size) == ry;
91  const int in_same_ctb_b = (xQg >> ctb_log2_size) == rx && ((yQg - 1) >> ctb_log2_size) == ry;
92  int qPy_pred, qPy_a, qPy_b;
93 
94  if (lc->na.cand_up) {
95  const int first_qg_in_ctu = !(xQg & ctb_size_mask) && !(yQg & ctb_size_mask);
96  const int qPy_up = fc->tab.qp[LUMA][x_cb + (y_cb - 1) * min_cb_width];
97  if (first_qg_in_ctu && pps->ctb_to_col_bd[xQg >> ctb_log2_size] == xQg >> ctb_log2_size)
98  return qPy_up;
99  }
100 
101  // qPy_pred
102  qPy_pred = lc->ep->is_first_qg ? lc->sc->sh.slice_qp_y : lc->ep->qp_y;
103 
104  // qPy_b
105  if (!lc->na.cand_up || !in_same_ctb_b)
106  qPy_b = qPy_pred;
107  else
108  qPy_b = fc->tab.qp[LUMA][x_cb + (y_cb - 1) * min_cb_width];
109 
110  // qPy_a
111  if (!lc->na.cand_left || !in_same_ctb_a)
112  qPy_a = qPy_pred;
113  else
114  qPy_a = fc->tab.qp[LUMA][(x_cb - 1) + y_cb * min_cb_width];
115 
116  av_assert2(qPy_a >= -fc->ps.sps->qp_bd_offset && qPy_a <= 63);
117  av_assert2(qPy_b >= -fc->ps.sps->qp_bd_offset && qPy_b <= 63);
118 
119  return (qPy_a + qPy_b + 1) >> 1;
120 }
121 
122 static void set_cb_tab(const VVCLocalContext *lc, uint8_t *tab, const uint8_t v)
123 {
124  const VVCFrameContext *fc = lc->fc;
125  const VVCPPS *pps = fc->ps.pps;
126  const CodingUnit *cu = lc->cu;
127  const int log2_min_cb_size = fc->ps.sps->min_cb_log2_size_y;
128  const int x_cb = cu->x0 >> log2_min_cb_size;
129  const int y_cb = cu->y0 >> log2_min_cb_size;
130  const int cb_width = cu->cb_width;
131  const int cb_height = cu->cb_height;
132  int x = y_cb * pps->min_cb_width + x_cb;
133 
134  for (int y = 0; y < (cb_height >> log2_min_cb_size); y++) {
135  const int width = cb_width >> log2_min_cb_size;
136 
137  memset(&tab[x], v, width);
138  x += pps->min_cb_width;
139  }
140 }
141 
142 static int set_qp_y(VVCLocalContext *lc, const int x0, const int y0, const int has_qp_delta)
143 {
144  const VVCSPS *sps = lc->fc->ps.sps;
145  EntryPoint *ep = lc->ep;
146  CodingUnit *cu = lc->cu;
147  int cu_qp_delta = 0;
148 
149  if (!lc->fc->ps.pps->r->pps_cu_qp_delta_enabled_flag) {
150  ep->qp_y = lc->sc->sh.slice_qp_y;
151  } else if (ep->is_first_qg || (lc->parse.cu_qg_top_left_x == x0 && lc->parse.cu_qg_top_left_y == y0)) {
152  ep->qp_y = get_qp_y_pred(lc);
153  ep->is_first_qg = 0;
154  }
155 
156  if (has_qp_delta) {
157  const int cu_qp_delta_abs = ff_vvc_cu_qp_delta_abs(lc);
158 
159  if (cu_qp_delta_abs)
160  cu_qp_delta = ff_vvc_cu_qp_delta_sign_flag(lc) ? -cu_qp_delta_abs : cu_qp_delta_abs;
161  if (cu_qp_delta > (31 + sps->qp_bd_offset / 2) || cu_qp_delta < -(32 + sps->qp_bd_offset / 2))
162  return AVERROR_INVALIDDATA;
163  lc->parse.is_cu_qp_delta_coded = 1;
164 
165  if (cu_qp_delta) {
166  int off = sps->qp_bd_offset;
167  ep->qp_y = FFUMOD(ep->qp_y + cu_qp_delta + 64 + 2 * off, 64 + off) - off;
168  }
169  }
170 
171  set_cb_tab(lc, lc->fc->tab.qp[LUMA], ep->qp_y);
172  cu->qp[LUMA] = ep->qp_y;
173 
174  return 0;
175 }
176 
177 static void set_qp_c_tab(const VVCLocalContext *lc, const TransformUnit *tu, const TransformBlock *tb)
178 {
179  const int is_jcbcr = tu->joint_cbcr_residual_flag && tu->coded_flag[CB] && tu->coded_flag[CR];
180  const int idx = is_jcbcr ? JCBCR : tb->c_idx;
181 
182  set_tb_tab(lc->fc->tab.qp[tb->c_idx], lc->cu->qp[idx], lc->fc, tb);
183 }
184 
185 static void set_qp_c(VVCLocalContext *lc)
186 {
187  const VVCFrameContext *fc = lc->fc;
188  const VVCSPS *sps = fc->ps.sps;
189  const VVCPPS *pps = fc->ps.pps;
190  const H266RawSliceHeader *rsh = lc->sc->sh.r;
191  CodingUnit *cu = lc->cu;
192  const int x_center = cu->x0 + cu->cb_width / 2;
193  const int y_center = cu->y0 + cu->cb_height / 2;
194  const int single_tree = cu->tree_type == SINGLE_TREE;
195  const int qp_luma = (single_tree ? lc->ep->qp_y : ff_vvc_get_qPy(fc, x_center, y_center)) + sps->qp_bd_offset;
196  const int qp_chroma = av_clip(qp_luma, 0, MAX_QP + sps->qp_bd_offset);
197  const int sh_chroma_qp_offset[] = {
198  rsh->sh_cb_qp_offset,
199  rsh->sh_cr_qp_offset,
201  };
202  int qp;
203 
204  for (int i = CB - 1; i < CR + sps->r->sps_joint_cbcr_enabled_flag; i++) {
205  qp = sps->chroma_qp_table[i][qp_chroma];
206  qp = qp + pps->chroma_qp_offset[i] + sh_chroma_qp_offset[i] + lc->parse.chroma_qp_offset[i];
207  qp = av_clip(qp, -sps->qp_bd_offset, MAX_QP) + sps->qp_bd_offset;
208  cu->qp[i + 1] = qp;
209  }
210 }
211 
213 {
214  TransformUnit *tu = av_refstruct_pool_get(fc->tu_pool);
215  if (!tu)
216  return NULL;
217 
218  tu->next = NULL;
219 
220  if (cu->tus.tail)
221  cu->tus.tail->next = tu;
222  else
223  cu->tus.head = tu;
224  cu->tus.tail = tu;
225 
226  return tu;
227 }
228 
229 static TransformUnit* add_tu(VVCFrameContext *fc, CodingUnit *cu, const int x0, const int y0, const int tu_width, const int tu_height)
230 {
231  TransformUnit *tu = alloc_tu(fc, cu);
232 
233  if (!tu)
234  return NULL;
235 
236  tu->x0 = x0;
237  tu->y0 = y0;
238  tu->width = tu_width;
239  tu->height = tu_height;
240  tu->joint_cbcr_residual_flag = 0;
241  memset(tu->coded_flag, 0, sizeof(tu->coded_flag));
242  tu->avail[LUMA] = tu->avail[CHROMA] = 0;
243  tu->nb_tbs = 0;
244 
245  return tu;
246 }
247 
249  const int x0, const int y0, const int tb_width, const int tb_height, const int c_idx)
250 {
251  TransformBlock *tb;
252 
253  tb = &tu->tbs[tu->nb_tbs++];
254  tb->has_coeffs = 0;
255  tb->x0 = x0;
256  tb->y0 = y0;
257  tb->tb_width = tb_width;
258  tb->tb_height = tb_height;
259  tb->log2_tb_width = av_log2(tb_width);
260  tb->log2_tb_height = av_log2(tb_height);
261 
262  tb->max_scan_x = tb->max_scan_y = 0;
263  tb->min_scan_x = tb->min_scan_y = 0;
264 
265  tb->c_idx = c_idx;
266  tb->ts = 0;
267  tb->coeffs = lc->coeffs;
268  lc->coeffs += tb_width * tb_height;
269  tu->avail[!!c_idx] = true;
270  return tb;
271 }
272 
273 static uint8_t tu_y_coded_flag_decode(VVCLocalContext *lc, const int is_sbt_not_coded,
274  const int sub_tu_index, const int is_isp, const int is_chroma_coded)
275 {
276  uint8_t tu_y_coded_flag = 0;
277  const VVCSPS *sps = lc->fc->ps.sps;
278  CodingUnit *cu = lc->cu;
279 
280  if (!is_sbt_not_coded) {
281  int has_y_coded_flag = sub_tu_index < cu->num_intra_subpartitions - 1 || !lc->parse.infer_tu_cbf_luma;
282  if (!is_isp) {
283  const int is_large = cu->cb_width > sps->max_tb_size_y || cu->cb_height > sps->max_tb_size_y;
284  has_y_coded_flag = (cu->pred_mode == MODE_INTRA && !cu->act_enabled_flag) || is_chroma_coded || is_large;
285  }
286  tu_y_coded_flag = has_y_coded_flag ? ff_vvc_tu_y_coded_flag(lc) : 1;
287  }
288  if (is_isp)
289  lc->parse.infer_tu_cbf_luma = lc->parse.infer_tu_cbf_luma && !tu_y_coded_flag;
290  return tu_y_coded_flag;
291 }
292 
293 static void chroma_qp_offset_decode(VVCLocalContext *lc, const int is_128, const int is_chroma_coded)
294 {
295  const VVCPPS *pps = lc->fc->ps.pps;
296  const H266RawSliceHeader *rsh = lc->sc->sh.r;
297 
298  if ((is_128 || is_chroma_coded) &&
300  const int cu_chroma_qp_offset_flag = ff_vvc_cu_chroma_qp_offset_flag(lc);
301  if (cu_chroma_qp_offset_flag) {
302  int cu_chroma_qp_offset_idx = 0;
303  if (pps->r->pps_chroma_qp_offset_list_len_minus1 > 0)
304  cu_chroma_qp_offset_idx = ff_vvc_cu_chroma_qp_offset_idx(lc);
305  for (int i = CB - 1; i < JCBCR; i++)
306  lc->parse.chroma_qp_offset[i] = pps->chroma_qp_offset_list[cu_chroma_qp_offset_idx][i];
307  } else {
308  memset(lc->parse.chroma_qp_offset, 0, sizeof(lc->parse.chroma_qp_offset));
309  }
311  }
312 }
313 
314 static int hls_transform_unit(VVCLocalContext *lc, int x0, int y0,int tu_width, int tu_height, int sub_tu_index, int ch_type)
315 {
316  VVCFrameContext *fc = lc->fc;
317  const VVCSPS *sps = fc->ps.sps;
318  const VVCPPS *pps = fc->ps.pps;
319  CodingUnit *cu = lc->cu;
320  TransformUnit *tu = add_tu(fc, cu, x0, y0, tu_width, tu_height);
321  const int min_cb_width = pps->min_cb_width;
322  const VVCTreeType tree_type = cu->tree_type;
323  const int is_128 = cu->cb_width > 64 || cu->cb_height > 64;
324  const int is_isp = cu->isp_split_type != ISP_NO_SPLIT;
325  const int is_isp_last_tu = is_isp && (sub_tu_index == cu->num_intra_subpartitions - 1);
326  const int is_sbt_not_coded = cu->sbt_flag &&
327  ((sub_tu_index == 0 && cu->sbt_pos_flag) || (sub_tu_index == 1 && !cu->sbt_pos_flag));
328  const int chroma_available = tree_type != DUAL_TREE_LUMA && sps->r->sps_chroma_format_idc &&
329  (!is_isp || is_isp_last_tu);
330  int ret, xc, yc, wc, hc, is_chroma_coded;
331 
332  if (!tu)
333  return AVERROR_INVALIDDATA;
334 
335  if (tree_type == SINGLE_TREE && is_isp_last_tu) {
336  const int x_cu = x0 >> fc->ps.sps->min_cb_log2_size_y;
337  const int y_cu = y0 >> fc->ps.sps->min_cb_log2_size_y;
338  xc = SAMPLE_CTB(fc->tab.cb_pos_x[ch_type], x_cu, y_cu);
339  yc = SAMPLE_CTB(fc->tab.cb_pos_y[ch_type], x_cu, y_cu);
340  wc = SAMPLE_CTB(fc->tab.cb_width[ch_type], x_cu, y_cu);
341  hc = SAMPLE_CTB(fc->tab.cb_height[ch_type], x_cu, y_cu);
342  } else {
343  xc = x0, yc = y0, wc = tu_width, hc = tu_height;
344  }
345 
346  if (chroma_available && !is_sbt_not_coded) {
349  }
350 
351  is_chroma_coded = chroma_available && (tu->coded_flag[CB] || tu->coded_flag[CR]);
352 
353  if (tree_type != DUAL_TREE_CHROMA) {
354  int has_qp_delta;
355  tu->coded_flag[LUMA] = tu_y_coded_flag_decode(lc, is_sbt_not_coded, sub_tu_index, is_isp, is_chroma_coded);
356  has_qp_delta = (is_128 || tu->coded_flag[LUMA] || is_chroma_coded) &&
357  pps->r->pps_cu_qp_delta_enabled_flag && !lc->parse.is_cu_qp_delta_coded;
358  ret = set_qp_y(lc, x0, y0, has_qp_delta);
359  if (ret < 0)
360  return ret;
361  add_tb(tu, lc, x0, y0, tu_width, tu_height, LUMA);
362  }
363  if (tree_type != DUAL_TREE_LUMA) {
364  chroma_qp_offset_decode(lc, is_128, is_chroma_coded);
365  if (chroma_available) {
366  const int hs = sps->hshift[CHROMA];
367  const int vs = sps->vshift[CHROMA];
368  add_tb(tu, lc, xc, yc, wc >> hs, hc >> vs, CB);
369  add_tb(tu, lc, xc, yc, wc >> hs, hc >> vs, CR);
370  }
371  }
372  if (sps->r->sps_joint_cbcr_enabled_flag && ((cu->pred_mode == MODE_INTRA &&
373  (tu->coded_flag[CB] || tu->coded_flag[CR])) ||
374  (tu->coded_flag[CB] && tu->coded_flag[CR])) &&
375  chroma_available) {
377  }
378 
379  for (int i = 0; i < tu->nb_tbs; i++) {
380  TransformBlock *tb = &tu->tbs[i];
381  const int is_chroma = tb->c_idx != LUMA;
382  tb->has_coeffs = tu->coded_flag[tb->c_idx];
383  if (tb->has_coeffs && is_chroma)
384  tb->has_coeffs = tb->c_idx == CB ? 1 : !(tu->coded_flag[CB] && tu->joint_cbcr_residual_flag);
385  if (tb->has_coeffs) {
386  tb->ts = cu->bdpcm_flag[tb->c_idx];
387  if (sps->r->sps_transform_skip_enabled_flag && !cu->bdpcm_flag[tb->c_idx] &&
388  tb->tb_width <= sps->max_ts_size && tb->tb_height <= sps->max_ts_size &&
389  !cu->sbt_flag && (is_chroma || !is_isp)) {
390  tb->ts = ff_vvc_transform_skip_flag(lc, is_chroma);
391  }
392  ret = ff_vvc_residual_coding(lc, tb);
393  if (ret < 0)
394  return ret;
395  set_tb_tab(fc->tab.tu_coded_flag[tb->c_idx], tu->coded_flag[tb->c_idx], fc, tb);
396  } else if (cu->act_enabled_flag) {
397  memset(tb->coeffs, 0, tb->tb_width * tb->tb_height * sizeof(*tb->coeffs));
398  }
399  if (tb->c_idx != CR)
400  set_tb_size(fc, tb);
401  if (tb->c_idx == CB)
402  set_tb_tab(fc->tab.tu_joint_cbcr_residual_flag, tu->joint_cbcr_residual_flag, fc, tb);
403  }
404 
405  return 0;
406 }
407 
408 static int hls_transform_tree(VVCLocalContext *lc, int x0, int y0,int tu_width, int tu_height, int ch_type)
409 {
410  const CodingUnit *cu = lc->cu;
411  const VVCSPS *sps = lc->fc->ps.sps;
412  int ret;
413 
414  lc->parse.infer_tu_cbf_luma = 1;
415  if (cu->isp_split_type == ISP_NO_SPLIT && !cu->sbt_flag) {
416  if (tu_width > sps->max_tb_size_y || tu_height > sps->max_tb_size_y) {
417  const int ver_split_first = tu_width > sps->max_tb_size_y && tu_width > tu_height;
418  const int trafo_width = ver_split_first ? (tu_width / 2) : tu_width;
419  const int trafo_height = !ver_split_first ? (tu_height / 2) : tu_height;
420 
421  #define TRANSFORM_TREE(x, y) do { \
422  ret = hls_transform_tree(lc, x, y, trafo_width, trafo_height, ch_type); \
423  if (ret < 0) \
424  return ret; \
425  } while (0)
426 
427  TRANSFORM_TREE(x0, y0);
428  if (ver_split_first)
429  TRANSFORM_TREE(x0 + trafo_width, y0);
430  else
431  TRANSFORM_TREE(x0, y0 + trafo_height);
432 
433  } else {
434  ret = hls_transform_unit(lc, x0, y0, tu_width, tu_height, 0, ch_type);
435  if (ret < 0)
436  return ret;
437 
438  }
439  } else if (cu->sbt_flag) {
440  if (!cu->sbt_horizontal_flag) {
441  #define TRANSFORM_UNIT(x, width, idx) do { \
442  ret = hls_transform_unit(lc, x, y0, width, tu_height, idx, ch_type); \
443  if (ret < 0) \
444  return ret; \
445  } while (0)
446 
447  const int trafo_width = tu_width * lc->parse.sbt_num_fourths_tb0 / 4;
448  TRANSFORM_UNIT(x0, trafo_width, 0);
449  TRANSFORM_UNIT(x0 + trafo_width, tu_width - trafo_width, 1);
450 
451  #undef TRANSFORM_UNIT
452  } else {
453  #define TRANSFORM_UNIT(y, height, idx) do { \
454  ret = hls_transform_unit(lc, x0, y, tu_width, height, idx, ch_type); \
455  if (ret < 0) \
456  return ret; \
457  } while (0)
458 
459  const int trafo_height = tu_height * lc->parse.sbt_num_fourths_tb0 / 4;
460  TRANSFORM_UNIT(y0, trafo_height, 0);
461  TRANSFORM_UNIT(y0 + trafo_height, tu_height - trafo_height, 1);
462 
463  #undef TRANSFORM_UNIT
464  }
465  } else if (cu->isp_split_type == ISP_HOR_SPLIT) {
466  const int trafo_height = tu_height / cu->num_intra_subpartitions;
467  for (int i = 0; i < cu->num_intra_subpartitions; i++) {
468  ret = hls_transform_unit(lc, x0, y0 + trafo_height * i, tu_width, trafo_height, i, 0);
469  if (ret < 0)
470  return ret;
471  }
472  } else if (cu->isp_split_type == ISP_VER_SPLIT) {
473  const int trafo_width = tu_width / cu->num_intra_subpartitions;
474  for (int i = 0; i < cu->num_intra_subpartitions; i++) {
475  ret = hls_transform_unit(lc, x0 + trafo_width * i , y0, trafo_width, tu_height, i, 0);
476  if (ret < 0)
477  return ret;
478  }
479  }
480 
481  return 0;
482 }
483 
484 static int skipped_transform_tree(VVCLocalContext *lc, int x0, int y0,int tu_width, int tu_height)
485 {
486  VVCFrameContext *fc = lc->fc;
487  const CodingUnit *cu = lc->cu;
488  const VVCSPS *sps = fc->ps.sps;
489 
490  if (tu_width > sps->max_tb_size_y || tu_height > sps->max_tb_size_y) {
491  const int ver_split_first = tu_width > sps->max_tb_size_y && tu_width > tu_height;
492  const int trafo_width = ver_split_first ? (tu_width / 2) : tu_width;
493  const int trafo_height = !ver_split_first ? (tu_height / 2) : tu_height;
494 
495  #define SKIPPED_TRANSFORM_TREE(x, y) do { \
496  int ret = skipped_transform_tree(lc, x, y, trafo_width, trafo_height); \
497  if (ret < 0) \
498  return ret; \
499  } while (0)
500 
501  SKIPPED_TRANSFORM_TREE(x0, y0);
502  if (ver_split_first)
503  SKIPPED_TRANSFORM_TREE(x0 + trafo_width, y0);
504  else
505  SKIPPED_TRANSFORM_TREE(x0, y0 + trafo_height);
506  } else {
507  TransformUnit *tu = add_tu(fc, lc->cu, x0, y0, tu_width, tu_height);
508  int start, end;
509 
510  if (!tu)
511  return AVERROR_INVALIDDATA;
512  ff_vvc_channel_range(&start, &end, cu->tree_type, sps->r->sps_chroma_format_idc);
513  for (int i = start; i < end; i++) {
514  TransformBlock *tb = add_tb(tu, lc, x0, y0, tu_width >> sps->hshift[i], tu_height >> sps->vshift[i], i);
515  if (i != CR)
516  set_tb_size(fc, tb);
517  }
518  }
519 
520  return 0;
521 }
522 
523 //6.4.1 Allowed quad split process
524 //6.4.2 Allowed binary split process
525 //6.4.3 Allowed ternary split process
526 static void can_split(const VVCLocalContext *lc, int x0, int y0,int cb_width, int cb_height,
527  int mtt_depth, int depth_offset, int part_idx, VVCSplitMode last_split_mode,
528  VVCTreeType tree_type, VVCModeType mode_type, VVCAllowedSplit* split)
529 {
530  int min_qt_size, max_bt_size, max_tt_size, max_mtt_depth;
531  const VVCFrameContext *fc = lc->fc;
532  const VVCSH *sh = &lc->sc->sh;
533  const VVCSPS *sps = fc->ps.sps;
534  const VVCPPS *pps = fc->ps.pps;
535  const int chroma = tree_type == DUAL_TREE_CHROMA;
536  int min_cb_size_y = sps->min_cb_size_y;
537  int *qt = &split->qt;
538  int *btv = &split->btv;
539  int *bth = &split->bth;
540  int *ttv = &split->ttv;
541  int *tth = &split->tth;
542 
543  *qt = *bth = *btv = *tth = *ttv = 1;
544 
545  if (mtt_depth)
546  *qt = 0;
547 
548  min_qt_size = sh->min_qt_size[chroma];
549  if (cb_width <= min_qt_size)
550  *qt = 0;
551 
552  if (chroma) {
553  int chroma_area = (cb_width >> sps->hshift[1]) * (cb_height >> sps->vshift[1]);
554  int chroma_width = cb_width >> sps->hshift[1];
555 
556  if (chroma_width == 8)
557  *ttv = 0;
558  else if (chroma_width <= 4) {
559  if (chroma_width == 4)
560  *btv = 0;
561  *qt = 0;
562  }
563  if (mode_type == MODE_TYPE_INTRA)
564  *qt = *btv = *bth = *ttv = *tth = 0;
565  if (chroma_area <= 32) {
566  *ttv = *tth = 0;
567  if (chroma_area <= 16)
568  *btv = *bth = 0;
569  }
570  }
571  max_bt_size = sh->max_bt_size[chroma];
572  max_tt_size = sh->max_tt_size[chroma];
573  max_mtt_depth = sh->max_mtt_depth[chroma] + depth_offset;
574 
575  if (mode_type == MODE_TYPE_INTER) {
576  int area = cb_width * cb_height;
577  if (area == 32)
578  *btv = *bth = 0;
579  else if (area == 64)
580  *ttv = *tth = 0;
581  }
582  if (cb_width <= 2 * min_cb_size_y) {
583  *ttv = 0;
584  if (cb_width <= min_cb_size_y)
585  *btv = 0;
586  }
587  if (cb_height <= 2 * min_cb_size_y) {
588  *tth = 0;
589  if (cb_height <= min_cb_size_y)
590  *bth = 0;
591  }
592  if (cb_width > max_bt_size || cb_height > max_bt_size)
593  *btv = *bth = 0;
594  max_tt_size = FFMIN(64, max_tt_size);
595  if (cb_width > max_tt_size || cb_height > max_tt_size)
596  *ttv = *tth = 0;
597  if (mtt_depth >= max_mtt_depth)
598  *btv = *bth = *ttv = *tth = 0;
599  if (x0 + cb_width > pps->width) {
600  *ttv = *tth = 0;
601  if (cb_height > 64)
602  *btv = 0;
603  if (y0 + cb_height <= pps->height)
604  *bth = 0;
605  else if (cb_width > min_qt_size)
606  *btv = *bth = 0;
607  }
608  if (y0 + cb_height > pps->height) {
609  *btv = *ttv = *tth = 0;
610  if (cb_width > 64)
611  *bth = 0;
612  }
613  if (mtt_depth > 0 && part_idx == 1) {
614  if (last_split_mode == SPLIT_TT_VER)
615  *btv = 0;
616  else if (last_split_mode == SPLIT_TT_HOR)
617  *bth = 0;
618  }
619  if (cb_width <= 64 && cb_height > 64)
620  *btv = 0;
621  if (cb_width > 64 && cb_height <= 64)
622  *bth = 0;
623 }
624 
625 static int get_num_intra_subpartitions(enum IspType isp_split_type, int cb_width, int cb_height)
626 {
627  if (isp_split_type == ISP_NO_SPLIT)
628  return 1;
629  if ((cb_width == 4 && cb_height == 8) || (cb_width == 8 && cb_height == 4))
630  return 2;
631  return 4;
632 }
633 
634 static int get_cclm_enabled(const VVCLocalContext *lc, const int x0, const int y0)
635 {
636  const VVCFrameContext *fc = lc->fc;
637  const VVCSPS *sps = fc->ps.sps;
638  int enabled = 0;
639 
640  if (!sps->r->sps_cclm_enabled_flag)
641  return 0;
642  if (!sps->r->sps_qtbtt_dual_tree_intra_flag || !IS_I(lc->sc->sh.r) || sps->ctb_log2_size_y < 6)
643  return 1;
644  else {
645  const int x64 = x0 >> 6 << 6;
646  const int y64 = y0 >> 6 << 6;
647  const int y32 = y0 >> 5 << 5;
648  const int x64_cu = x64 >> fc->ps.sps->min_cb_log2_size_y;
649  const int y64_cu = y64 >> fc->ps.sps->min_cb_log2_size_y;
650  const int y32_cu = y32 >> fc->ps.sps->min_cb_log2_size_y;
651  const int min_cb_width = fc->ps.pps->min_cb_width;
652  const int depth = SAMPLE_CTB(fc->tab.cqt_depth[1], x64_cu, y64_cu);
653  const int min_depth = fc->ps.sps->ctb_log2_size_y - 6;
654  const VVCSplitMode msm64 = (VVCSplitMode)TAB_MSM(fc, 0, x64, y64);
655  const VVCSplitMode msm32 = (VVCSplitMode)TAB_MSM(fc, 1, x64, y32);
656 
657  enabled = SAMPLE_CTB(fc->tab.cb_width[1], x64_cu, y64_cu) == 64 &&
658  SAMPLE_CTB(fc->tab.cb_height[1], x64_cu, y64_cu) == 64;
659  enabled |= depth == min_depth && msm64 == SPLIT_BT_HOR &&
660  SAMPLE_CTB(fc->tab.cb_width[1], x64_cu, y32_cu) == 64 &&
661  SAMPLE_CTB(fc->tab.cb_height[1], x64_cu, y32_cu) == 32;
662  enabled |= depth > min_depth;
663  enabled |= depth == min_depth && msm64 == SPLIT_BT_HOR && msm32 == SPLIT_BT_VER;
664 
665  if (enabled) {
666  const int w = SAMPLE_CTB(fc->tab.cb_width[0], x64_cu, y64_cu);
667  const int h = SAMPLE_CTB(fc->tab.cb_height[0], x64_cu, y64_cu);
668  const int depth0 = SAMPLE_CTB(fc->tab.cqt_depth[0], x64_cu, y64_cu);
669  if ((w == 64 && h == 64 && TAB_ISPMF(fc, x64, y64)) ||
670  ((w < 64 || h < 64) && depth0 == min_depth))
671  return 0;
672  }
673 
674  }
675 
676  return enabled;
677 }
678 
679 static int less(const void *a, const void *b)
680 {
681  return *(const int*)a - *(const int*)b;
682 }
683 
684 //8.4.2 Derivation process for luma intra prediction mode
685 static enum IntraPredMode luma_intra_pred_mode(VVCLocalContext* lc, const int intra_subpartitions_mode_flag)
686 {
687  VVCFrameContext *fc = lc->fc;
688  CodingUnit *cu = lc->cu;
689  const int x0 = cu->x0;
690  const int y0 = cu->y0;
691  enum IntraPredMode pred;
692  int intra_luma_not_planar_flag = 1;
693  int intra_luma_mpm_remainder = 0;
694  int intra_luma_mpm_flag = 1;
695  int intra_luma_mpm_idx = 0;
696 
697  if (!cu->intra_luma_ref_idx)
698  intra_luma_mpm_flag = ff_vvc_intra_luma_mpm_flag(lc);
699  if (intra_luma_mpm_flag) {
700  if (!cu->intra_luma_ref_idx)
701  intra_luma_not_planar_flag = ff_vvc_intra_luma_not_planar_flag(lc, intra_subpartitions_mode_flag);
702  if (intra_luma_not_planar_flag)
703  intra_luma_mpm_idx = ff_vvc_intra_luma_mpm_idx(lc);
704  } else {
705  intra_luma_mpm_remainder = ff_vvc_intra_luma_mpm_remainder(lc);
706  }
707 
708  if (!intra_luma_not_planar_flag) {
709  pred = INTRA_PLANAR;
710  } else {
711  const VVCSPS *sps = fc->ps.sps;
712  const int x_a = (x0 - 1) >> sps->min_cb_log2_size_y;
713  const int y_a = (y0 + cu->cb_height - 1) >> sps->min_cb_log2_size_y;
714  const int x_b = (x0 + cu->cb_width - 1) >> sps->min_cb_log2_size_y;
715  const int y_b = (y0 - 1) >> sps->min_cb_log2_size_y;
716  int min_cb_width = fc->ps.pps->min_cb_width;
717  int x0b = av_zero_extend(x0, sps->ctb_log2_size_y);
718  int y0b = av_zero_extend(y0, sps->ctb_log2_size_y);
719  const int available_l = lc->ctb_left_flag || x0b;
720  const int available_u = lc->ctb_up_flag || y0b;
721 
722  int a, b, cand[5];
723 
724  if (!available_l || (SAMPLE_CTB(fc->tab.cpm[0], x_a, y_a) != MODE_INTRA) ||
725  SAMPLE_CTB(fc->tab.imf, x_a, y_a)) {
726  a = INTRA_PLANAR;
727  } else {
728  a = SAMPLE_CTB(fc->tab.ipm, x_a, y_a);
729  }
730 
731  if (!available_u || (SAMPLE_CTB(fc->tab.cpm[0], x_b, y_b) != MODE_INTRA) ||
732  SAMPLE_CTB(fc->tab.imf, x_b, y_b) || !y0b) {
733  b = INTRA_PLANAR;
734  } else {
735  b = SAMPLE_CTB(fc->tab.ipm, x_b, y_b);
736  }
737 
738  if (a == b && a > INTRA_DC) {
739  cand[0] = a;
740  cand[1] = 2 + ((a + 61) % 64);
741  cand[2] = 2 + ((a - 1) % 64);
742  cand[3] = 2 + ((a + 60) % 64);
743  cand[4] = 2 + (a % 64);
744  } else {
745  const int minab = FFMIN(a, b);
746  const int maxab = FFMAX(a, b);
747  if (a > INTRA_DC && b > INTRA_DC) {
748  const int diff = maxab - minab;
749  cand[0] = a;
750  cand[1] = b;
751  if (diff == 1) {
752  cand[2] = 2 + ((minab + 61) % 64);
753  cand[3] = 2 + ((maxab - 1) % 64);
754  cand[4] = 2 + ((minab + 60) % 64);
755  } else if (diff >= 62) {
756  cand[2] = 2 + ((minab - 1) % 64);
757  cand[3] = 2 + ((maxab + 61) % 64);
758  cand[4] = 2 + (minab % 64);
759  } else if (diff == 2) {
760  cand[2] = 2 + ((minab - 1) % 64);
761  cand[3] = 2 + ((minab + 61) % 64);
762  cand[4] = 2 + ((maxab - 1) % 64);
763  } else {
764  cand[2] = 2 + ((minab + 61) % 64);
765  cand[3] = 2 + ((minab - 1) % 64);
766  cand[4] = 2 + ((maxab + 61) % 64);
767  }
768  } else if (a > INTRA_DC || b > INTRA_DC) {
769  cand[0] = maxab;
770  cand[1] = 2 + ((maxab + 61 ) % 64);
771  cand[2] = 2 + ((maxab - 1) % 64);
772  cand[3] = 2 + ((maxab + 60 ) % 64);
773  cand[4] = 2 + (maxab % 64);
774  } else {
775  cand[0] = INTRA_DC;
776  cand[1] = INTRA_VERT;
777  cand[2] = INTRA_HORZ;
778  cand[3] = INTRA_VERT - 4;
779  cand[4] = INTRA_VERT + 4;
780  }
781  }
782  if (intra_luma_mpm_flag) {
783  pred = cand[intra_luma_mpm_idx];
784  } else {
785  qsort(cand, FF_ARRAY_ELEMS(cand), sizeof(cand[0]), less);
786  pred = intra_luma_mpm_remainder + 1;
787  for (int i = 0; i < FF_ARRAY_ELEMS(cand); i++) {
788  if (pred >= cand[i])
789  pred++;
790  }
791  }
792  }
793  return pred;
794 }
795 
797 {
798  CodingUnit *cu = lc->cu;
799  const VVCTreeType tree_type = cu->tree_type;
800  const VVCSPS *sps = lc->fc->ps.sps;
801  const int cb_width = cu->cb_width;
802  const int cb_height = cu->cb_height;
803  const TransformUnit *tu = cu->tus.head;
804  int lfnst_width, lfnst_height, min_lfnst;
805  int lfnst_idx = 0;
806 
807  memset(cu->apply_lfnst_flag, 0, sizeof(cu->apply_lfnst_flag));
808 
809  if (!sps->r->sps_lfnst_enabled_flag || cu->pred_mode != MODE_INTRA || FFMAX(cb_width, cb_height) > sps->max_tb_size_y)
810  return 0;
811 
812  while (tu) {
813  for (int j = 0; j < tu->nb_tbs; j++) {
814  const TransformBlock *tb = tu->tbs + j;
815  if (tu->coded_flag[tb->c_idx] && tb->ts)
816  return 0;
817  }
818  tu = tu->next;
819  }
820 
821  if (tree_type == DUAL_TREE_CHROMA) {
822  lfnst_width = cb_width >> sps->hshift[1];
823  lfnst_height = cb_height >> sps->vshift[1];
824  } else {
825  const int vs = cu->isp_split_type == ISP_VER_SPLIT;
826  const int hs = cu->isp_split_type == ISP_HOR_SPLIT;
827  lfnst_width = vs ? cb_width / cu->num_intra_subpartitions : cb_width;
828  lfnst_height = hs ? cb_height / cu->num_intra_subpartitions : cb_height;
829  }
830  min_lfnst = FFMIN(lfnst_width, lfnst_height);
831  if (tree_type != DUAL_TREE_CHROMA && cu->intra_mip_flag && min_lfnst < 16)
832  return 0;
833 
834  if (min_lfnst >= 4) {
836  lfnst_idx = ff_vvc_lfnst_idx(lc, tree_type != SINGLE_TREE);
837  }
838 
839  if (lfnst_idx) {
840  cu->apply_lfnst_flag[LUMA] = tree_type != DUAL_TREE_CHROMA;
841  cu->apply_lfnst_flag[CB] = cu->apply_lfnst_flag[CR] = tree_type == DUAL_TREE_CHROMA;
842  }
843 
844  return lfnst_idx;
845 }
846 
848 {
849  const CodingUnit *cu = lc->cu;
850  const VVCSPS *sps = lc->fc->ps.sps;
851  const int cb_width = cu->cb_width;
852  const int cb_height = cu->cb_height;
853  const uint8_t transform_skip_flag = cu->tus.head->tbs[0].ts; //fix me
854  int mts_idx = MTS_DCT2_DCT2;
855  if (cu->tree_type != DUAL_TREE_CHROMA && !cu->lfnst_idx &&
856  !transform_skip_flag && FFMAX(cb_width, cb_height) <= 32 &&
857  cu->isp_split_type == ISP_NO_SPLIT && !cu->sbt_flag &&
859  if ((cu->pred_mode == MODE_INTER && sps->r->sps_explicit_mts_inter_enabled_flag) ||
860  (cu->pred_mode == MODE_INTRA && sps->r->sps_explicit_mts_intra_enabled_flag)) {
861  mts_idx = ff_vvc_mts_idx(lc);
862  }
863  }
864 
865  return mts_idx;
866 }
867 
869 {
870  const int x_center = (cu->x0 + cu->cb_width / 2) >> sps->min_cb_log2_size_y;
871  const int y_center = (cu->y0 + cu->cb_height / 2) >> sps->min_cb_log2_size_y;
872  const int min_cb_width = pps->min_cb_width;
873  const int intra_mip_flag = SAMPLE_CTB(fc->tab.imf, x_center, y_center);
874  const int cu_pred_mode = SAMPLE_CTB(fc->tab.cpm[0], x_center, y_center);
875  const int intra_pred_mode_y = SAMPLE_CTB(fc->tab.ipm, x_center, y_center);
876 
877  if (intra_mip_flag) {
878  if (cu->tree_type == SINGLE_TREE && sps->r->sps_chroma_format_idc == CHROMA_FORMAT_444)
879  return INTRA_INVALID;
880  return INTRA_PLANAR;
881  }
882  if (cu_pred_mode == MODE_IBC || cu_pred_mode == MODE_PLT)
883  return INTRA_DC;
884  return intra_pred_mode_y;
885 }
886 
888  const int cclm_mode_flag, const int cclm_mode_idx, const int intra_chroma_pred_mode)
889 {
890  const VVCFrameContext *fc = lc->fc;
891  CodingUnit *cu = lc->cu;
892  const VVCSPS *sps = fc->ps.sps;
893  const VVCPPS *pps = fc->ps.pps;
894  const int x_cb = cu->x0 >> sps->min_cb_log2_size_y;
895  const int y_cb = cu->y0 >> sps->min_cb_log2_size_y;
896  const int min_cb_width = pps->min_cb_width;
897  const int intra_mip_flag = SAMPLE_CTB(fc->tab.imf, x_cb, y_cb);
898  enum IntraPredMode luma_intra_pred_mode = SAMPLE_CTB(fc->tab.ipm, x_cb, y_cb);
899 
900  if (cu->tree_type == SINGLE_TREE && sps->r->sps_chroma_format_idc == CHROMA_FORMAT_444 &&
901  (intra_chroma_pred_mode == 4 || cu->act_enabled_flag) && intra_mip_flag) {
902  cu->mip_chroma_direct_flag = 1;
904  return;
905  }
907 
908  if (cu->act_enabled_flag) {
910  return;
911  }
912  if (cclm_mode_flag) {
913  cu->intra_pred_mode_c = INTRA_LT_CCLM + cclm_mode_idx;
914  } else if (intra_chroma_pred_mode == 4){
916  } else {
917  const static IntraPredMode pred_mode_c[][4 + 1] = {
922  };
923  const int modes[4] = {INTRA_PLANAR, INTRA_VERT, INTRA_HORZ, INTRA_DC};
924  int idx;
925 
926  // This workaround is necessary to have 4:4:4 video decode correctly
927  // See VVC ticket https://jvet.hhi.fraunhofer.de/trac/vvc/ticket/1602
928  // and VTM source https://vcgit.hhi.fraunhofer.de/jvet/VVCSoftware_VTM/-/blob/master/source/Lib/CommonLib/UnitTools.cpp#L736
929  if (cu->tree_type == SINGLE_TREE && sps->r->sps_chroma_format_idc == CHROMA_FORMAT_444 && intra_mip_flag) {
930  idx = 4;
931  } else {
932  for (idx = 0; idx < FF_ARRAY_ELEMS(modes); idx++) {
933  if (modes[idx] == luma_intra_pred_mode)
934  break;
935  }
936  }
937 
938  cu->intra_pred_mode_c = pred_mode_c[intra_chroma_pred_mode][idx];
939  }
940  if (sps->r->sps_chroma_format_idc == CHROMA_FORMAT_422 && cu->intra_pred_mode_c <= INTRA_VDIAG) {
941  const static int mode_map_422[INTRA_VDIAG + 1] = {
942  0, 1, 61, 62, 63, 64, 65, 66, 2, 3, 5, 6, 8, 10, 12, 13,
943  14, 16, 18, 20, 22, 23, 24, 26, 28, 30, 31, 33, 34, 35, 36, 37,
944  38, 39, 40, 41, 41, 42, 43, 43, 44, 44, 45, 45, 46, 47, 48, 48,
945  49, 49, 50, 51, 51, 52, 52, 53, 54, 55, 55, 56, 56, 57, 57, 58,
946  59, 59, 60,
947  };
948  cu->intra_pred_mode_c = mode_map_422[cu->intra_pred_mode_c];
949  }
950 }
951 
952 static av_always_inline uint8_t pack_mip_info(int intra_mip_flag,
953  int intra_mip_transposed_flag, int intra_mip_mode)
954 {
955  return (intra_mip_mode << 2) | (intra_mip_transposed_flag << 1) | intra_mip_flag;
956 }
957 
959 {
960  VVCFrameContext *fc = lc->fc;
961  const VVCSPS *sps = fc->ps.sps;
962  const VVCPPS *pps = fc->ps.pps;
963  CodingUnit *cu = lc->cu;
964  const int log2_min_cb_size = sps->min_cb_log2_size_y;
965  const int x0 = cu->x0;
966  const int y0 = cu->y0;
967  const int x_cb = x0 >> log2_min_cb_size;
968  const int y_cb = y0 >> log2_min_cb_size;
969  const int cb_width = cu->cb_width;
970  const int cb_height = cu->cb_height;
971 
972  cu->intra_luma_ref_idx = 0;
973  if (sps->r->sps_bdpcm_enabled_flag && cb_width <= sps->max_ts_size && cb_height <= sps->max_ts_size)
975  if (cu->bdpcm_flag[LUMA]) {
977  } else {
978  if (sps->r->sps_mip_enabled_flag)
979  cu->intra_mip_flag = ff_vvc_intra_mip_flag(lc, fc->tab.imf);
980  if (cu->intra_mip_flag) {
981  int intra_mip_transposed_flag = ff_vvc_intra_mip_transposed_flag(lc);
982  int intra_mip_mode = ff_vvc_intra_mip_mode(lc);
983  int x = y_cb * pps->min_cb_width + x_cb;
984  for (int y = 0; y < (cb_height>>log2_min_cb_size); y++) {
985  int width = cb_width>>log2_min_cb_size;
986  const uint8_t mip_info = pack_mip_info(cu->intra_mip_flag,
987  intra_mip_transposed_flag, intra_mip_mode);
988  memset(&fc->tab.imf[x], mip_info, width);
989  x += pps->min_cb_width;
990  }
991  cu->intra_pred_mode_y = intra_mip_mode;
992  } else {
993  int intra_subpartitions_mode_flag = 0;
994  if (sps->r->sps_mrl_enabled_flag && ((y0 % sps->ctb_size_y) > 0))
996  if (sps->r->sps_isp_enabled_flag && !cu->intra_luma_ref_idx &&
997  (cb_width <= sps->max_tb_size_y && cb_height <= sps->max_tb_size_y) &&
998  (cb_width * cb_height > MIN_TU_SIZE * MIN_TU_SIZE) &&
999  !cu->act_enabled_flag)
1000  intra_subpartitions_mode_flag = ff_vvc_intra_subpartitions_mode_flag(lc);
1001  if (!(x0 & 63) && !(y0 & 63))
1002  TAB_ISPMF(fc, x0, y0) = intra_subpartitions_mode_flag;
1003  cu->isp_split_type = ff_vvc_isp_split_type(lc, intra_subpartitions_mode_flag);
1004  cu->num_intra_subpartitions = get_num_intra_subpartitions(cu->isp_split_type, cb_width, cb_height);
1005  cu->intra_pred_mode_y = luma_intra_pred_mode(lc, intra_subpartitions_mode_flag);
1006  }
1007  }
1008  set_cb_tab(lc, fc->tab.ipm, cu->intra_pred_mode_y);
1009 }
1010 
1012 {
1013  const VVCSPS *sps = lc->fc->ps.sps;
1014  CodingUnit *cu = lc->cu;
1015  const int hs = sps->hshift[CHROMA];
1016  const int vs = sps->vshift[CHROMA];
1017  int cclm_mode_flag = 0;
1018  int cclm_mode_idx = 0;
1019  int intra_chroma_pred_mode = 0;
1020 
1021  if (!cu->act_enabled_flag) {
1022  cu->mip_chroma_direct_flag = 0;
1023  if (sps->r->sps_bdpcm_enabled_flag &&
1024  (cu->cb_width >> hs) <= sps->max_ts_size &&
1025  (cu->cb_height >> vs) <= sps->max_ts_size) {
1027  }
1028  if (cu->bdpcm_flag[CHROMA]) {
1030  } else {
1031  const int cclm_enabled = get_cclm_enabled(lc, cu->x0, cu->y0);
1032 
1033  if (cclm_enabled)
1034  cclm_mode_flag = ff_vvc_cclm_mode_flag(lc);
1035 
1036  if (cclm_mode_flag)
1037  cclm_mode_idx = ff_vvc_cclm_mode_idx(lc);
1038  else
1039  intra_chroma_pred_mode = ff_vvc_intra_chroma_pred_mode(lc);
1040  }
1041  }
1042 
1043  if (!cu->bdpcm_flag[CHROMA])
1044  derive_chroma_intra_pred_mode(lc, cclm_mode_flag, cclm_mode_idx, intra_chroma_pred_mode);
1045 }
1046 
1048  const VVCTreeType tree_type,
1049  const VVCModeType mode_type)
1050 {
1051  const VVCFrameContext *fc = lc->fc;
1052  CodingUnit *cu = lc->cu;
1053  const VVCSPS *sps = fc->ps.sps;
1054  const H266RawSliceHeader *rsh = lc->sc->sh.r;
1055  const int ch_type = tree_type == DUAL_TREE_CHROMA ? 1 : 0;
1056  const int is_4x4 = cu->cb_width == 4 && cu->cb_height == 4;
1057  const int is_128 = cu->cb_width == 128 || cu->cb_height == 128;
1058  const int hs = sps->hshift[CHROMA];
1059  const int vs = sps->vshift[CHROMA];
1060  int pred_mode_flag;
1061  int pred_mode_ibc_flag;
1062  PredMode pred_mode;
1063 
1064  cu->skip_flag = 0;
1065  if (!IS_I(rsh) || sps->r->sps_ibc_enabled_flag) {
1066  if (tree_type != DUAL_TREE_CHROMA &&
1067  ((!is_4x4 && mode_type != MODE_TYPE_INTRA) ||
1068  (sps->r->sps_ibc_enabled_flag && !is_128))) {
1069  cu->skip_flag = ff_vvc_cu_skip_flag(lc, fc->tab.skip);
1070  }
1071 
1072  if (is_4x4 || mode_type == MODE_TYPE_INTRA || IS_I(rsh)) {
1073  pred_mode_flag = 1;
1074  } else if (mode_type == MODE_TYPE_INTER || cu->skip_flag) {
1075  pred_mode_flag = 0;
1076  } else {
1077  pred_mode_flag = ff_vvc_pred_mode_flag(lc, ch_type);
1078  }
1079  pred_mode = pred_mode_flag ? MODE_INTRA : MODE_INTER;
1080 
1081  if (((IS_I(rsh) && !cu->skip_flag) ||
1082  (!IS_I(rsh) && (pred_mode != MODE_INTRA ||
1083  ((is_4x4 || mode_type == MODE_TYPE_INTRA) && !cu->skip_flag)))) &&
1084  !is_128 && mode_type != MODE_TYPE_INTER && sps->r->sps_ibc_enabled_flag &&
1085  tree_type != DUAL_TREE_CHROMA) {
1086  pred_mode_ibc_flag = ff_vvc_pred_mode_ibc_flag(lc, ch_type);
1087  } else if (cu->skip_flag && (is_4x4 || mode_type == MODE_TYPE_INTRA)) {
1088  pred_mode_ibc_flag = 1;
1089  } else if (is_128 || mode_type == MODE_TYPE_INTER || tree_type == DUAL_TREE_CHROMA) {
1090  pred_mode_ibc_flag = 0;
1091  } else {
1092  pred_mode_ibc_flag = (IS_I(rsh)) ? sps->r->sps_ibc_enabled_flag : 0;
1093  }
1094  if (pred_mode_ibc_flag)
1095  pred_mode = MODE_IBC;
1096  } else {
1097  pred_mode = MODE_INTRA;
1098  }
1099 
1100  if (pred_mode == MODE_INTRA && sps->r->sps_palette_enabled_flag && !is_128 && !cu->skip_flag &&
1101  mode_type != MODE_TYPE_INTER && ((cu->cb_width * cu->cb_height) >
1102  (tree_type != DUAL_TREE_CHROMA ? 16 : (16 << hs << vs))) &&
1103  (mode_type != MODE_TYPE_INTRA || tree_type != DUAL_TREE_CHROMA)) {
1104  if (ff_vvc_pred_mode_plt_flag(lc))
1105  pred_mode = MODE_PLT;
1106  }
1107 
1108  set_cb_tab(lc, fc->tab.cpm[cu->ch_type], pred_mode);
1109  if (tree_type == SINGLE_TREE)
1110  set_cb_tab(lc, fc->tab.cpm[CHROMA], pred_mode);
1111 
1112  return pred_mode;
1113 }
1114 
1115 static void sbt_info(VVCLocalContext *lc, const VVCSPS *sps)
1116 {
1117  CodingUnit *cu = lc->cu;
1118  const int cb_width = cu->cb_width;
1119  const int cb_height = cu->cb_height;
1120 
1121  if (cu->pred_mode == MODE_INTER && sps->r->sps_sbt_enabled_flag && !cu->ciip_flag
1122  && cb_width <= sps->max_tb_size_y && cb_height <= sps->max_tb_size_y) {
1123  const int sbt_ver_h = cb_width >= 8;
1124  const int sbt_hor_h = cb_height >= 8;
1125  cu->sbt_flag = 0;
1126  if (sbt_ver_h || sbt_hor_h)
1127  cu->sbt_flag = ff_vvc_sbt_flag(lc);
1128  if (cu->sbt_flag) {
1129  const int sbt_ver_q = cb_width >= 16;
1130  const int sbt_hor_q = cb_height >= 16;
1131  int cu_sbt_quad_flag = 0;
1132 
1133  if ((sbt_ver_h || sbt_hor_h) && (sbt_ver_q || sbt_hor_q))
1134  cu_sbt_quad_flag = ff_vvc_sbt_quad_flag(lc);
1135  if (cu_sbt_quad_flag) {
1136  cu->sbt_horizontal_flag = sbt_hor_q;
1137  if (sbt_ver_q && sbt_hor_q)
1139  } else {
1140  cu->sbt_horizontal_flag = sbt_hor_h;
1141  if (sbt_ver_h && sbt_hor_h)
1143  }
1145 
1146  {
1147  const int sbt_min = cu_sbt_quad_flag ? 1 : 2;
1148  lc->parse.sbt_num_fourths_tb0 = cu->sbt_pos_flag ? (4 - sbt_min) : sbt_min;
1149  }
1150  }
1151  }
1152 }
1153 
1155 {
1156  const H266RawSPS *rsps = lc->fc->ps.sps->r;
1157  const CodingUnit *cu = lc->cu;
1158  int ret;
1159 
1160  if (cu->tree_type != DUAL_TREE_CHROMA)
1161  set_qp_y(lc, cu->x0, cu->y0, 0);
1162  if (rsps->sps_chroma_format_idc && cu->tree_type != DUAL_TREE_LUMA)
1163  set_qp_c(lc);
1164  ret = skipped_transform_tree(lc, cu->x0, cu->y0, cu->cb_width, cu->cb_height);
1165  if (ret < 0)
1166  return ret;
1167  return 0;
1168 }
1169 
1170 static void set_cb_pos(const VVCFrameContext *fc, const CodingUnit *cu)
1171 {
1172  const VVCSPS *sps = fc->ps.sps;
1173  const VVCPPS *pps = fc->ps.pps;
1174  const int log2_min_cb_size = sps->min_cb_log2_size_y;
1175  const int x_cb = cu->x0 >> log2_min_cb_size;
1176  const int y_cb = cu->y0 >> log2_min_cb_size;
1177  const int ch_type = cu->ch_type;
1178  int x, y;
1179 
1180  x = y_cb * pps->min_cb_width + x_cb;
1181  for (y = 0; y < (cu->cb_height >> log2_min_cb_size); y++) {
1182  const int width = cu->cb_width >> log2_min_cb_size;
1183 
1184  for (int i = 0; i < width; i++) {
1185  fc->tab.cb_pos_x[ch_type][x + i] = cu->x0;
1186  fc->tab.cb_pos_y[ch_type][x + i] = cu->y0;
1187  }
1188  memset(&fc->tab.cb_width[ch_type][x], cu->cb_width, width);
1189  memset(&fc->tab.cb_height[ch_type][x], cu->cb_height, width);
1190  memset(&fc->tab.cqt_depth[ch_type][x], cu->cqt_depth, width);
1191 
1192  x += pps->min_cb_width;
1193  }
1194 }
1195 
1196 static CodingUnit* alloc_cu(VVCLocalContext *lc, const int x0, const int y0)
1197 {
1198  VVCFrameContext *fc = lc->fc;
1199  const VVCSPS *sps = fc->ps.sps;
1200  const VVCPPS *pps = fc->ps.pps;
1201  const int rx = x0 >> sps->ctb_log2_size_y;
1202  const int ry = y0 >> sps->ctb_log2_size_y;
1203  CodingUnit **cus = fc->tab.cus + ry * pps->ctb_width + rx;
1204  CodingUnit *cu = av_refstruct_pool_get(fc->cu_pool);
1205 
1206  if (!cu)
1207  return NULL;
1208  cu->next = NULL;
1209 
1210  if (lc->cu)
1211  lc->cu->next = cu;
1212  else
1213  *cus = cu;
1214  lc->cu = cu;
1215 
1216  return cu;
1217 }
1218 
1219 static CodingUnit* add_cu(VVCLocalContext *lc, const int x0, const int y0,
1220  const int cb_width, const int cb_height, const int cqt_depth, const VVCTreeType tree_type)
1221 {
1222  VVCFrameContext *fc = lc->fc;
1223  const int ch_type = tree_type == DUAL_TREE_CHROMA ? 1 : 0;
1224  CodingUnit *cu = alloc_cu(lc, x0, y0);
1225 
1226  if (!cu)
1227  return NULL;
1228 
1229  memset(&cu->pu, 0, sizeof(cu->pu));
1230 
1231  lc->parse.prev_tu_cbf_y = 0;
1232 
1233  cu->sbt_flag = 0;
1234  cu->act_enabled_flag = 0;
1235 
1236  cu->tree_type = tree_type;
1237  cu->x0 = x0;
1238  cu->y0 = y0;
1239  cu->cb_width = cb_width;
1240  cu->cb_height = cb_height;
1241  cu->ch_type = ch_type;
1242  cu->cqt_depth = cqt_depth;
1243  cu->tus.head = cu->tus.tail = NULL;
1244  cu->bdpcm_flag[LUMA] = cu->bdpcm_flag[CB] = cu->bdpcm_flag[CR] = 0;
1246  cu->intra_mip_flag = 0;
1247  cu->ciip_flag = 0;
1248  cu->coded_flag = 1;
1249  cu->num_intra_subpartitions = 1;
1250  cu->pu.dmvr_flag = 0;
1251 
1252  set_cb_pos(fc, cu);
1253  return cu;
1254 }
1255 
1256 static void set_cu_tabs(const VVCLocalContext *lc, const CodingUnit *cu)
1257 {
1258  const VVCFrameContext *fc = lc->fc;
1259  const PredictionUnit *pu = &cu->pu;
1260  const TransformUnit *tu = cu->tus.head;
1261 
1262  set_cb_tab(lc, fc->tab.mmi, pu->mi.motion_model_idc);
1263  set_cb_tab(lc, fc->tab.msf, pu->merge_subblock_flag);
1264  if (cu->tree_type != DUAL_TREE_CHROMA) {
1265  set_cb_tab(lc, fc->tab.skip, cu->skip_flag);
1266  set_cb_tab(lc, fc->tab.pcmf[LUMA], cu->bdpcm_flag[LUMA]);
1267  }
1268  if (cu->tree_type != DUAL_TREE_LUMA)
1269  set_cb_tab(lc, fc->tab.pcmf[CHROMA], cu->bdpcm_flag[CHROMA]);
1270 
1271  while (tu) {
1272  for (int j = 0; j < tu->nb_tbs; j++) {
1273  const TransformBlock *tb = tu->tbs + j;
1274  if (tb->c_idx != LUMA)
1275  set_qp_c_tab(lc, tu, tb);
1276  }
1277  tu = tu->next;
1278  }
1279 }
1280 
1281 //8.5.2.7 Derivation process for merge motion vector difference
1282 static void derive_mmvd(const VVCLocalContext *lc, MvField *mvf, const Mv *mmvd_offset)
1283 {
1284  const SliceContext *sc = lc->sc;
1285  Mv mmvd[2];
1286 
1287  if (mvf->pred_flag == PF_BI) {
1288  const RefPicList *rpl = sc->rpl;
1289  const int poc = lc->fc->ps.ph.poc;
1290  const int diff[] = {
1291  poc - rpl[L0].refs[mvf->ref_idx[L0]].poc,
1292  poc - rpl[L1].refs[mvf->ref_idx[L1]].poc
1293  };
1294  const int sign = FFSIGN(diff[0]) != FFSIGN(diff[1]);
1295 
1296  if (diff[0] == diff[1]) {
1297  mmvd[1] = mmvd[0] = *mmvd_offset;
1298  }
1299  else {
1300  const int i = FFABS(diff[0]) < FFABS(diff[1]);
1301  const int o = !i;
1302  mmvd[i] = *mmvd_offset;
1303  if (!rpl[L0].refs[mvf->ref_idx[L0]].is_lt && !rpl[L1].refs[mvf->ref_idx[L1]].is_lt) {
1304  ff_vvc_mv_scale(&mmvd[o], mmvd_offset, diff[i], diff[o]);
1305  }
1306  else {
1307  mmvd[o].x = sign ? -mmvd[i].x : mmvd[i].x;
1308  mmvd[o].y = sign ? -mmvd[i].y : mmvd[i].y;
1309  }
1310  }
1311  mvf->mv[0].x += mmvd[0].x;
1312  mvf->mv[0].y += mmvd[0].y;
1313  mvf->mv[1].x += mmvd[1].x;
1314  mvf->mv[1].y += mmvd[1].y;
1315  } else {
1316  const int idx = mvf->pred_flag - PF_L0;
1317  mvf->mv[idx].x += mmvd_offset->x;
1318  mvf->mv[idx].y += mmvd_offset->y;
1319  }
1320 
1321 }
1322 
1323 static void mvf_to_mi(const MvField *mvf, MotionInfo *mi)
1324 {
1325  mi->pred_flag = mvf->pred_flag;
1326  mi->bcw_idx = mvf->bcw_idx;
1327  mi->hpel_if_idx = mvf->hpel_if_idx;
1328  for (int i = 0; i < 2; i++) {
1329  const PredFlag mask = i + 1;
1330  if (mvf->pred_flag & mask) {
1331  mi->mv[i][0] = mvf->mv[i];
1332  mi->ref_idx[i] = mvf->ref_idx[i];
1333  }
1334  }
1335 }
1336 
1337 static void mv_merge_refine_pred_flag(MvField *mvf, const int width, const int height)
1338 {
1339  if (mvf->pred_flag == PF_BI && (width + height) == 12) {
1340  mvf->pred_flag = PF_L0;
1341  mvf->bcw_idx = 0;
1342  }
1343 }
1344 
1345 // subblock-based inter prediction data
1347 {
1348  const VVCFrameContext *fc = lc->fc;
1349  const VVCPH *ph = &fc->ps.ph;
1350  CodingUnit* cu = lc->cu;
1351  PredictionUnit *pu = &cu->pu;
1352  int merge_subblock_idx = 0;
1353 
1354  if (ph->max_num_subblock_merge_cand > 1) {
1355  merge_subblock_idx = ff_vvc_merge_subblock_idx(lc, ph->max_num_subblock_merge_cand);
1356  }
1357  ff_vvc_sb_mv_merge_mode(lc, merge_subblock_idx, pu);
1358 }
1359 
1361 {
1362  const VVCFrameContext *fc = lc->fc;
1363  const VVCSPS *sps = fc->ps.sps;
1364  const VVCPH *ph = &fc->ps.ph;
1365  const CodingUnit* cu = lc->cu;
1366  PredictionUnit *pu = &lc->cu->pu;
1367  int merge_idx = 0;
1368  Mv mmvd_offset;
1369  MvField mvf;
1370 
1371  if (sps->r->sps_mmvd_enabled_flag)
1373  if (pu->mmvd_merge_flag) {
1374  int mmvd_cand_flag = 0;
1375  if (sps->max_num_merge_cand > 1)
1376  mmvd_cand_flag = ff_vvc_mmvd_cand_flag(lc);
1377  ff_vvc_mmvd_offset_coding(lc, &mmvd_offset, ph->r->ph_mmvd_fullpel_only_flag);
1378  merge_idx = mmvd_cand_flag;
1379  } else if (sps->max_num_merge_cand > 1) {
1380  merge_idx = ff_vvc_merge_idx(lc);
1381  }
1382  ff_vvc_luma_mv_merge_mode(lc, merge_idx, 0, &mvf);
1383  if (pu->mmvd_merge_flag)
1384  derive_mmvd(lc, &mvf, &mmvd_offset);
1386  ff_vvc_store_mvf(lc, &mvf);
1387  mvf_to_mi(&mvf, &pu->mi);
1388 }
1389 
1390 static int ciip_flag_decode(VVCLocalContext *lc, const int ciip_avaiable, const int gpm_avaiable, const int is_128)
1391 {
1392  const VVCFrameContext *fc = lc->fc;
1393  const VVCSPS *sps = fc->ps.sps;
1394  const CodingUnit *cu = lc->cu;
1395 
1396  if (ciip_avaiable && gpm_avaiable)
1397  return ff_vvc_ciip_flag(lc);
1398  return sps->r->sps_ciip_enabled_flag && !cu->skip_flag &&
1399  !is_128 && (cu->cb_width * cu->cb_height >= 64);
1400 }
1401 
1403 {
1404  const VVCFrameContext *fc = lc->fc;
1405  const VVCSPS *sps = fc->ps.sps;
1406  PredictionUnit *pu = &lc->cu->pu;
1407  int merge_gpm_idx[2];
1408 
1409  pu->merge_gpm_flag = 1;
1411  merge_gpm_idx[0] = ff_vvc_merge_gpm_idx(lc, 0);
1412  merge_gpm_idx[1] = 0;
1413  if (sps->max_num_gpm_merge_cand > 2)
1414  merge_gpm_idx[1] = ff_vvc_merge_gpm_idx(lc, 1);
1415 
1416  ff_vvc_luma_mv_merge_gpm(lc, merge_gpm_idx, pu->gpm_mv);
1417  ff_vvc_store_gpm_mvf(lc, pu);
1418 }
1419 
1421 {
1422  const VVCFrameContext* fc = lc->fc;
1423  const VVCSPS* sps = fc->ps.sps;
1424  CodingUnit *cu = lc->cu;
1425  MotionInfo *mi = &cu->pu.mi;
1426  int merge_idx = 0;
1427  MvField mvf;
1428 
1429  if (sps->max_num_merge_cand > 1)
1430  merge_idx = ff_vvc_merge_idx(lc);
1431  ff_vvc_luma_mv_merge_mode(lc, merge_idx, 1, &mvf);
1433  ff_vvc_store_mvf(lc, &mvf);
1434  mvf_to_mi(&mvf, mi);
1436  cu->intra_luma_ref_idx = 0;
1437  cu->intra_mip_flag = 0;
1438 }
1439 
1440 // block-based inter prediction data
1442 {
1443  const VVCFrameContext* fc = lc->fc;
1444  const VVCSPS *sps = fc->ps.sps;
1445  const H266RawSliceHeader *rsh = lc->sc->sh.r;
1446  CodingUnit *cu = lc->cu;
1447  const int cb_width = cu->cb_width;
1448  const int cb_height = cu->cb_height;
1449  const int is_128 = cb_width == 128 || cb_height == 128;
1450  const int ciip_avaiable = sps->r->sps_ciip_enabled_flag &&
1451  !cu->skip_flag && (cb_width * cb_height >= 64);
1452  const int gpm_avaiable = sps->r->sps_gpm_enabled_flag && IS_B(rsh) &&
1453  (cb_width >= 8) && (cb_height >=8) &&
1454  (cb_width < 8 * cb_height) && (cb_height < 8 *cb_width);
1455 
1456  int regular_merge_flag = 1;
1457 
1458  if (!is_128 && (ciip_avaiable || gpm_avaiable))
1459  regular_merge_flag = ff_vvc_regular_merge_flag(lc, cu->skip_flag);
1460  if (regular_merge_flag) {
1461  merge_data_regular(lc);
1462  } else {
1463  cu->ciip_flag = ciip_flag_decode(lc, ciip_avaiable, gpm_avaiable, is_128);
1464  if (cu->ciip_flag)
1465  merge_data_ciip(lc);
1466  else
1467  merge_data_gpm(lc);
1468  }
1469 }
1470 
1472 {
1473  const VVCFrameContext* fc = lc->fc;
1474  const VVCSPS* sps = fc->ps.sps;
1475  MotionInfo *mi = &lc->cu->pu.mi;
1476  int merge_idx = 0;
1477  int ret;
1478 
1479  mi->pred_flag = PF_IBC;
1480 
1481  if (sps->max_num_ibc_merge_cand > 1)
1482  merge_idx = ff_vvc_merge_idx(lc);
1483 
1484  ret = ff_vvc_luma_mv_merge_ibc(lc, merge_idx, &mi->mv[L0][0]);
1485  if (ret)
1486  return ret;
1487  ff_vvc_store_mv(lc, mi);
1488 
1489  return 0;
1490 }
1491 
1493 {
1494  const VVCFrameContext *fc = lc->fc;
1495  const VVCPH *ph = &fc->ps.ph;
1496  const CodingUnit *cu = lc->cu;
1497  PredictionUnit *pu = &lc->cu->pu;
1498  int ret;
1499 
1500  pu->merge_gpm_flag = 0;
1501  pu->mi.num_sb_x = pu->mi.num_sb_y = 1;
1502  if (cu->pred_mode == MODE_IBC) {
1503  ret = merge_data_ibc(lc);
1504  if (ret)
1505  return ret;
1506  } else {
1507  if (ph->max_num_subblock_merge_cand > 0 && cu->cb_width >= 8 && cu->cb_height >= 8)
1509  if (pu->merge_subblock_flag)
1510  merge_data_subblock(lc);
1511  else
1512  merge_data_block(lc);
1513  }
1514  return 0;
1515 }
1516 
1517 static void hls_mvd_coding(VVCLocalContext *lc, Mv* mvd)
1518 {
1519  int32_t mv[2];
1520 
1521  for (int i = 0; i < 2; i++) {
1523  }
1524 
1525  for (int i = 0; i < 2; i++) {
1526  if (mv[i])
1528  }
1529 
1530  for (int i = 0; i < 2; i++) {
1531  if (mv[i] > 0) {
1532  if (mv[i] == 2)
1533  mv[i] += ff_vvc_abs_mvd_minus2(lc);
1534  mv[i] = (1 - 2 * ff_vvc_mvd_sign_flag(lc)) * mv[i];
1535  }
1536  }
1537  mvd->x = mv[0];
1538  mvd->y = mv[1];
1539 }
1540 
1541 static int bcw_idx_decode(VVCLocalContext *lc, const MotionInfo *mi, const int cb_width, const int cb_height)
1542 {
1543  const VVCFrameContext *fc = lc->fc;
1544  const VVCSPS *sps = fc->ps.sps;
1545  const VVCPPS *pps = fc->ps.pps;
1546  const VVCPH *ph = &fc->ps.ph;
1547  const VVCSH *sh = &lc->sc->sh;
1548  const PredWeightTable *w = pps->r->pps_wp_info_in_ph_flag ? &ph->pwt : &sh->pwt;
1549  int bcw_idx = 0;
1550 
1551  if (sps->r->sps_bcw_enabled_flag && mi->pred_flag == PF_BI &&
1552  !w->weight_flag[L0][LUMA][mi->ref_idx[0]] &&
1553  !w->weight_flag[L1][LUMA][mi->ref_idx[1]] &&
1554  !w->weight_flag[L0][CHROMA][mi->ref_idx[0]] &&
1555  !w->weight_flag[L1][CHROMA][mi->ref_idx[1]] &&
1556  cb_width * cb_height >= 256) {
1557  bcw_idx = ff_vvc_bcw_idx(lc, ff_vvc_no_backward_pred_flag(lc));
1558  }
1559  return bcw_idx;
1560 }
1561 
1562 static int8_t ref_idx_decode(VVCLocalContext *lc, const VVCSH *sh, const int sym_mvd_flag, const int lx)
1563 {
1564  const H266RawSliceHeader *rsh = sh->r;
1565  int ref_idx = 0;
1566 
1567  if (rsh->num_ref_idx_active[lx] > 1 && !sym_mvd_flag)
1568  ref_idx = ff_vvc_ref_idx_lx(lc, rsh->num_ref_idx_active[lx]);
1569  else if (sym_mvd_flag)
1570  ref_idx = sh->ref_idx_sym[lx];
1571  return ref_idx;
1572 }
1573 
1575  const int num_cp_mv, const int lx)
1576 {
1577  const VVCFrameContext *fc = lc->fc;
1578  const VVCPH *ph = &fc->ps.ph;
1579  const PredictionUnit *pu = &lc->cu->pu;
1580  const MotionInfo *mi = &pu->mi;
1581  int has_no_zero_mvd = 0;
1582 
1583  if (lx == L1 && ph->r->ph_mvd_l1_zero_flag && mi->pred_flag == PF_BI) {
1584  for (int j = 0; j < num_cp_mv; j++)
1585  AV_ZERO64(&mvds[lx][j]);
1586  } else {
1587  Mv *mvd0 = &mvds[lx][0];
1588  if (lx == L1 && pu->sym_mvd_flag) {
1589  mvd0->x = -mvds[L0][0].x;
1590  mvd0->y = -mvds[L0][0].y;
1591  } else {
1592  hls_mvd_coding(lc, mvd0);
1593  }
1594  has_no_zero_mvd |= (mvd0->x || mvd0->y);
1595  for (int j = 1; j < num_cp_mv; j++) {
1596  Mv *mvd = &mvds[lx][j];
1597  hls_mvd_coding(lc, mvd);
1598  mvd->x += mvd0->x;
1599  mvd->y += mvd0->y;
1600  has_no_zero_mvd |= (mvd->x || mvd->y);
1601  }
1602  }
1603  return has_no_zero_mvd;
1604 }
1605 
1606 static void mvp_add_difference(MotionInfo *mi, const int num_cp_mv,
1607  const Mv mvds[2][MAX_CONTROL_POINTS], const int amvr_shift)
1608 {
1609  for (int i = 0; i < 2; i++) {
1610  const PredFlag mask = i + PF_L0;
1611  if (mi->pred_flag & mask) {
1612  for (int j = 0; j < num_cp_mv; j++) {
1613  const Mv *mvd = &mvds[i][j];
1614  mi->mv[i][j].x += mvd->x * (1 << amvr_shift);
1615  mi->mv[i][j].y += mvd->y * (1 << amvr_shift);
1616  }
1617  }
1618  }
1619 }
1620 
1622 {
1623  const VVCFrameContext *fc = lc->fc;
1624  const CodingUnit *cu = lc->cu;
1625  const PredictionUnit *pu = &lc->cu->pu;
1626  const VVCSPS *sps = fc->ps.sps;
1627  MotionInfo *mi = &lc->cu->pu.mi;
1628  int mvp_l0_flag = 0;
1629  int amvr_shift = 4;
1630  Mv *mv = &mi->mv[L0][0];
1631  int ret;
1632 
1633  mi->pred_flag = PF_IBC;
1634  mi->num_sb_x = 1;
1635  mi->num_sb_y = 1;
1636 
1637  hls_mvd_coding(lc, mv);
1638  if (sps->max_num_ibc_merge_cand > 1)
1639  mvp_l0_flag = ff_vvc_mvp_lx_flag(lc);
1640  if (sps->r->sps_amvr_enabled_flag && (mv->x || mv->y))
1641  amvr_shift = ff_vvc_amvr_shift(lc, pu->inter_affine_flag, cu->pred_mode, 1);
1642 
1643  ret = ff_vvc_mvp_ibc(lc, mvp_l0_flag, amvr_shift, mv);
1644  if (ret)
1645  return ret;
1646  ff_vvc_store_mv(lc, mi);
1647 
1648  return 0;
1649 }
1650 
1651 static int mvp_data(VVCLocalContext *lc)
1652 {
1653  const VVCFrameContext *fc = lc->fc;
1654  const CodingUnit *cu = lc->cu;
1655  PredictionUnit *pu = &lc->cu->pu;
1656  const VVCSPS *sps = fc->ps.sps;
1657  const VVCPH *ph = &fc->ps.ph;
1658  const VVCSH *sh = &lc->sc->sh;
1659  const H266RawSliceHeader *rsh = sh->r;
1660  MotionInfo *mi = &pu->mi;
1661  const int cb_width = cu->cb_width;
1662  const int cb_height = cu->cb_height;
1663 
1664  int mvp_lx_flag[2] = {0};
1665  int cu_affine_type_flag = 0;
1666  int num_cp_mv;
1667  int amvr_enabled, has_no_zero_mvd = 0, amvr_shift;
1668  Mv mvds[2][MAX_CONTROL_POINTS];
1669 
1670  mi->pred_flag = ff_vvc_pred_flag(lc, IS_B(rsh));
1671  if (sps->r->sps_affine_enabled_flag && cb_width >= 16 && cb_height >= 16) {
1673  set_cb_tab(lc, fc->tab.iaf, pu->inter_affine_flag);
1674  if (sps->r->sps_6param_affine_enabled_flag && pu->inter_affine_flag)
1675  cu_affine_type_flag = ff_vvc_cu_affine_type_flag(lc);
1676  }
1677  mi->motion_model_idc = pu->inter_affine_flag + cu_affine_type_flag;
1678  num_cp_mv = mi->motion_model_idc + 1;
1679 
1680  if (sps->r->sps_smvd_enabled_flag && !ph->r->ph_mvd_l1_zero_flag &&
1681  mi->pred_flag == PF_BI && !pu->inter_affine_flag &&
1682  sh->ref_idx_sym[0] > -1 && sh->ref_idx_sym[1] > -1)
1684 
1685  for (int i = L0; i <= L1; i++) {
1686  const PredFlag pred_flag = PF_L0 + !i;
1687  if (mi->pred_flag != pred_flag) {
1688  mi->ref_idx[i] = ref_idx_decode(lc, sh, pu->sym_mvd_flag, i);
1689  has_no_zero_mvd |= mvds_decode(lc, mvds, num_cp_mv, i);
1690  mvp_lx_flag[i] = ff_vvc_mvp_lx_flag(lc);
1691  }
1692  }
1693 
1694  amvr_enabled = mi->motion_model_idc == MOTION_TRANSLATION ?
1695  sps->r->sps_amvr_enabled_flag : sps->r->sps_affine_amvr_enabled_flag;
1696  amvr_enabled &= has_no_zero_mvd;
1697 
1698  amvr_shift = ff_vvc_amvr_shift(lc, pu->inter_affine_flag, cu->pred_mode, amvr_enabled);
1699 
1700  mi->hpel_if_idx = amvr_shift == 3;
1701  mi->bcw_idx = bcw_idx_decode(lc, mi, cb_width, cb_height);
1702 
1703  if (mi->motion_model_idc)
1704  ff_vvc_affine_mvp(lc, mvp_lx_flag, amvr_shift, mi);
1705  else
1706  ff_vvc_mvp(lc, mvp_lx_flag, amvr_shift, mi);
1707 
1708  mvp_add_difference(mi, num_cp_mv, mvds, amvr_shift);
1709 
1710  if (mi->motion_model_idc)
1711  ff_vvc_store_sb_mvs(lc, pu);
1712  else
1713  ff_vvc_store_mv(lc, &pu->mi);
1714 
1715  return 0;
1716 }
1717 
1718 // derive bdofFlag from 8.5.6 Decoding process for inter blocks
1719 // derive dmvr from 8.5.1 General decoding process for coding units coded in inter prediction mode
1721 {
1722  const VVCFrameContext *fc = lc->fc;
1723  const VVCPPS *pps = fc->ps.pps;
1724  const VVCPH *ph = &fc->ps.ph;
1725  const VVCSH *sh = &lc->sc->sh;
1726  const int poc = ph->poc;
1727  const MotionInfo *mi = &pu->mi;
1728  const int8_t *ref_idx = mi->ref_idx;
1729  const VVCRefPic *rp0 = &lc->sc->rpl[L0].refs[ref_idx[L0]];
1730  const VVCRefPic *rp1 = &lc->sc->rpl[L1].refs[ref_idx[L1]];
1731  const CodingUnit *cu = lc->cu;
1732  const PredWeightTable *w = pps->r->pps_wp_info_in_ph_flag ? &fc->ps.ph.pwt : &sh->pwt;
1733 
1734  pu->bdof_flag = 0;
1735 
1736  if (mi->pred_flag == PF_BI &&
1737  (poc - rp0->poc == rp1->poc - poc) &&
1738  !rp0->is_lt && !rp1->is_lt &&
1739  !cu->ciip_flag &&
1740  !mi->bcw_idx &&
1741  !w->weight_flag[L0][LUMA][ref_idx[L0]] && !w->weight_flag[L1][LUMA][ref_idx[L1]] &&
1742  !w->weight_flag[L0][CHROMA][ref_idx[L0]] && !w->weight_flag[L1][CHROMA][ref_idx[L1]] &&
1743  cu->cb_width >= 8 && cu->cb_height >= 8 &&
1744  (cu->cb_width * cu->cb_height >= 128) &&
1745  !rp0->is_scaled && !rp1->is_scaled) {
1746  if (!ph->r->ph_bdof_disabled_flag &&
1747  mi->motion_model_idc == MOTION_TRANSLATION &&
1748  !pu->merge_subblock_flag &&
1749  !pu->sym_mvd_flag)
1750  pu->bdof_flag = 1;
1751  if (!ph->r->ph_dmvr_disabled_flag &&
1752  pu->general_merge_flag &&
1753  !pu->mmvd_merge_flag)
1754  pu->dmvr_flag = 1;
1755  }
1756 }
1757 
1758 // part of 8.5.1 General decoding process for coding units coded in inter prediction mode
1760 {
1761  const CodingUnit *cu = lc->cu;
1762  PredictionUnit *pu = &lc->cu->pu;
1763 
1764  derive_dmvr_bdof_flag(lc, pu);
1765  if (pu->dmvr_flag || pu->bdof_flag) {
1766  pu->mi.num_sb_x = (cu->cb_width > 16) ? (cu->cb_width >> 4) : 1;
1767  pu->mi.num_sb_y = (cu->cb_height > 16) ? (cu->cb_height >> 4) : 1;
1768  }
1769 }
1770 
1771 static void fill_dmvr_info(const VVCLocalContext *lc)
1772 {
1773  const VVCFrameContext *fc = lc->fc;
1774  const CodingUnit *cu = lc->cu;
1775 
1776  if (cu->pred_mode == MODE_IBC || cu->pred_mode == MODE_PLT) {
1777  ff_vvc_set_intra_mvf(lc, true, cu->pred_mode == MODE_IBC ? PF_IBC : PF_PLT, false);
1778  } else {
1779  const VVCPPS *pps = fc->ps.pps;
1780  const int w = cu->cb_width >> MIN_PU_LOG2;
1781 
1782  for (int y = cu->y0 >> MIN_PU_LOG2; y < (cu->y0 + cu->cb_height) >> MIN_PU_LOG2; y++) {
1783  const int idx = pps->min_pu_width * y + (cu->x0 >> MIN_PU_LOG2);
1784  const MvField *mvf = fc->tab.mvf + idx;
1785  MvField *dmvr_mvf = fc->ref->tab_dmvr_mvf + idx;
1786 
1787  memcpy(dmvr_mvf, mvf, sizeof(MvField) * w);
1788  }
1789  }
1790 }
1791 
1793 {
1794  const CodingUnit *cu = lc->cu;
1795  PredictionUnit *pu = &lc->cu->pu;
1796  const MotionInfo *mi = &pu->mi;
1797  int ret = 0;
1798 
1799  pu->general_merge_flag = 1;
1800  if (!cu->skip_flag)
1802 
1803  if (pu->general_merge_flag) {
1804  ret = hls_merge_data(lc);
1805  } else if (cu->pred_mode == MODE_IBC) {
1806  ret = mvp_data_ibc(lc);
1807  } else {
1808  ret = mvp_data(lc);
1809  }
1810 
1811  if (ret)
1812  return ret;
1813 
1814  if (cu->pred_mode == MODE_IBC) {
1815  ff_vvc_update_hmvp(lc, mi);
1816  } else if (!pu->merge_gpm_flag && !pu->inter_affine_flag && !pu->merge_subblock_flag) {
1818  ff_vvc_update_hmvp(lc, mi);
1819  }
1820 
1821  if (!pu->dmvr_flag)
1822  fill_dmvr_info(lc);
1823  return ret;
1824 }
1825 
1826 static TransformUnit* palette_add_tu(VVCLocalContext *lc, const int start, const int end, const VVCTreeType tree_type)
1827 {
1828  CodingUnit *cu = lc->cu;
1829  const VVCSPS *sps = lc->fc->ps.sps;
1830  TransformUnit *tu = add_tu(lc->fc, cu, cu->x0, cu->y0, cu->cb_width, cu->cb_height);
1831 
1832  if (!tu)
1833  return NULL;
1834 
1835  for (int c = start; c < end; c++) {
1836  const int w = tu->width >> sps->hshift[c];
1837  const int h = tu->height >> sps->vshift[c];
1838  TransformBlock *tb = add_tb(tu, lc, tu->x0, tu->y0, w, h, c);
1839  if (c != CR)
1840  set_tb_size(lc->fc, tb);
1841  }
1842 
1843  for (int i = 0; i < FF_ARRAY_ELEMS(cu->plt); i++)
1844  cu->plt[i].size = 0;
1845 
1846  return tu;
1847 }
1848 
1849 static int palette_predicted(VVCLocalContext *lc, const bool local_dual_tree, int start, int end,
1850  bool *predictor_reused, const int predictor_size, const int max_entries)
1851 {
1852  CodingUnit *cu = lc->cu;
1853  int nb_predicted = 0;
1854 
1855  if (local_dual_tree) {
1856  start = LUMA;
1857  end = VVC_MAX_SAMPLE_ARRAYS;
1858  }
1859 
1860  for (int i = 0; i < predictor_size && nb_predicted < max_entries; i++) {
1861  const int run = ff_vvc_palette_predictor_run(lc, predictor_size - i);
1862  if (run < 0)
1863  return run;
1864 
1865  if (run == 1)
1866  break;
1867 
1868  if (run > 1)
1869  i += run - 1;
1870 
1871  predictor_reused[i] = true;
1872  for (int c = start; c < end; c++)
1873  cu->plt[c].entries[nb_predicted] = lc->ep->pp[c].entries[i];
1874  nb_predicted++;
1875  }
1876 
1877  for (int c = start; c < end; c++)
1878  cu->plt[c].size = nb_predicted;
1879 
1880  return 0;
1881 }
1882 
1883 static int palette_signaled(VVCLocalContext *lc, const bool local_dual_tree,
1884  const int start, const int end, const int max_entries)
1885 {
1886  const VVCSPS *sps = lc->fc->ps.sps;
1887  CodingUnit *cu = lc->cu;
1888  const int nb_predicted = cu->plt[start].size;
1889  const int nb_signaled = nb_predicted < max_entries ? ff_vvc_num_signalled_palette_entries(lc, max_entries - nb_predicted) : 0;
1890  const int size = nb_predicted + nb_signaled;
1891  const bool dual_tree_luma = local_dual_tree && cu->tree_type == DUAL_TREE_LUMA;
1892 
1893  if (nb_signaled < 0)
1894  return AVERROR_INVALIDDATA;
1895 
1896  for (int c = start; c < end; c++) {
1897  Palette *plt = cu->plt + c;
1898  for (int i = nb_predicted; i < size; i++) {
1899  plt->entries[i] = ff_vvc_new_palette_entries(lc, sps->bit_depth);
1900  if (dual_tree_luma) {
1901  plt[CB].entries[i] = 1 << (sps->bit_depth - 1);
1902  plt[CR].entries[i] = 1 << (sps->bit_depth - 1);
1903  }
1904  }
1905  plt->size = size;
1906  }
1907 
1908  return 0;
1909 }
1910 
1911 static void palette_update_predictor(VVCLocalContext *lc, const bool local_dual_tree, int start, int end,
1912  bool *predictor_reused, const int predictor_size)
1913 {
1914  CodingUnit *cu = lc->cu;
1915  const int max_predictor = VVC_MAX_NUM_PALETTE_PREDICTOR_SIZE >> (cu->tree_type != SINGLE_TREE && !local_dual_tree);
1916 
1917  if (local_dual_tree) {
1918  start = LUMA;
1919  end = VVC_MAX_SAMPLE_ARRAYS;
1920  }
1921 
1922  for (int c = start; c < end; c++) {
1923  Palette *pp = lc->ep->pp + c;
1924  Palette *plt = cu->plt + c;
1925  int i = cu->plt[start].size;;
1926 
1927  // copy unused predictors to the end of plt
1928  for (int j = 0; j < predictor_size && i < max_predictor; j++) {
1929  if (!predictor_reused[j]) {
1930  plt->entries[i] = pp->entries[j];
1931  i++;
1932  }
1933  }
1934 
1935  memcpy(pp->entries, plt->entries, i * sizeof(pp->entries[0]));
1936  pp->size = i;
1937  }
1938 }
1939 
1940 static void palette_qp(VVCLocalContext *lc, VVCTreeType tree_type, const bool escape_present)
1941 {
1942  const VVCFrameContext *fc = lc->fc;
1943  const VVCPPS *pps = fc->ps.pps;
1944  const H266RawSliceHeader *rsh = lc->sc->sh.r;
1945  const CodingUnit *cu = lc->cu;
1946 
1947  if (tree_type != DUAL_TREE_CHROMA) {
1948  const bool has_qp_delta = escape_present &&
1949  pps->r->pps_cu_qp_delta_enabled_flag && !lc->parse.is_cu_qp_delta_coded;
1950  set_qp_y(lc, cu->x0, cu->y0, has_qp_delta);
1951  }
1952 
1953  if (tree_type != DUAL_TREE_LUMA) {
1955  chroma_qp_offset_decode(lc, 0, 1);
1956  set_qp_c(lc);
1957  }
1958 }
1959 
1960 #define PALETTE_SET_PIXEL(xc, yc, pix) \
1961  do { \
1962  const int off = ((xc) >> hs) + ((yc) >> vs) * tb->tb_width; \
1963  if (sps->bit_depth == 8) \
1964  u8[off] = pix; \
1965  else \
1966  u16[off] = pix; \
1967  } while (0)
1968 
1969 #define PALETTE_INDEX(x, y) index[(y) * cu->cb_width + (x)]
1970 
1971 // 6.5.3 Horizontal and vertical traverse scan order array initialization process
1972 // The hTravScan and vTravScan tables require approximately 576 KB of memory.
1973 // To save space, we use a macro to achieve the same functionality.
1974 #define TRAV_COL(p, wlog, mask) ((p & mask) ^ (-((p >> wlog) & 1) & mask))
1975 #define TRAV_ROW(p, hlog) (p >> hlog)
1976 #define TRAV(trans, p, wlog, hlog, mask) (trans ? TRAV_ROW((p), hlog) : TRAV_COL((p), wlog, mask))
1977 #define TRAV_X(pos) TRAV(transpose, pos, wlog2, hlog2, wmask)
1978 #define TRAV_Y(pos) TRAV(!transpose, pos, hlog2, wlog2, hmask)
1979 
1981  const int max_index, const int subset_id, const bool transpose,
1982  uint8_t *run_type, uint8_t *index, int *prev_run_pos, bool *adjust)
1983 {
1984  const CodingUnit *cu = lc->cu;
1985  TransformUnit *tu = cu->tus.head;
1986  const VVCSPS *sps = lc->fc->ps.sps;
1987  const int min_pos = subset_id << 4;
1988  const int max_pos = FFMIN(min_pos + 16, cu->cb_width * cu->cb_height);
1989  const int wmask = cu->cb_width - 1;
1990  const int hmask = cu->cb_height - 1;
1991  const int wlog2 = av_log2(cu->cb_width);
1992  const int hlog2 = av_log2(cu->cb_height);
1993  const uint8_t esc = cu->plt[tu->tbs[0].c_idx].size;
1994  uint8_t run_copy[16] = { 0 };
1995 
1996  for (int i = min_pos; i < max_pos; i++) {
1997  const int xc = TRAV_X(i);
1998  const int yc = TRAV_Y(i);
1999 
2000  if (i > 0 && max_index > 0)
2001  run_copy[i - min_pos] = ff_vvc_run_copy_flag(lc, run_type[i - 1], *prev_run_pos, i);
2002 
2003  run_type[i] = 0;
2004  if (max_index > 0 && !run_copy[i - min_pos]) {
2005  if (((!transpose && yc > 0) || (transpose && xc > 0))
2006  && i > 0 && !run_type[i - 1]) {
2007  run_type[i] = ff_vvc_copy_above_palette_indices_flag(lc);
2008  }
2009  *prev_run_pos = i;
2010  } else if (i > 0) {
2011  run_type[i] = run_type[i - 1];
2012  }
2013  }
2014 
2015  for (int i = min_pos; i < max_pos; i++) {
2016  const int xc = TRAV_X(i);
2017  const int yc = TRAV_Y(i);
2018  const int prev_xc = i > 0 ? TRAV_X(i - 1) : 0;
2019  const int prev_yc = i > 0 ? TRAV_Y(i - 1) : 0;
2020 
2021  int idx = 0;
2022  if (max_index > 0 && !run_copy[i - min_pos] && !run_type[i]) {
2023  if (max_index - *adjust > 0)
2024  idx = ff_vvc_palette_idx_idc(lc, max_index, *adjust);
2025  if (i > 0) {
2026  const int ref_idx = !run_type[i - 1] ?
2027  PALETTE_INDEX(prev_xc, prev_yc) : PALETTE_INDEX(xc - transpose, yc - !transpose);
2028  idx += (idx >= ref_idx);
2029  }
2030  *adjust = true;
2031  } else {
2032  idx = PALETTE_INDEX(prev_xc, prev_yc);
2033  }
2034 
2035  if (!run_type[i])
2036  PALETTE_INDEX(xc, yc) = idx;
2037  else
2038  PALETTE_INDEX(xc, yc) = PALETTE_INDEX(xc - transpose, yc - !transpose);
2039  }
2040 
2041  for (int c = 0; c < tu->nb_tbs; c++) {
2042  TransformBlock *tb = &tu->tbs[c];
2043  const Palette *plt = cu->plt + tb->c_idx;
2044  const int scale = ff_vvc_palette_derive_scale(lc, tu, tb);
2045  const int hs = sps->hshift[c];
2046  const int vs = sps->vshift[c];
2047  uint8_t *u8 = (uint8_t *)tb->coeffs;
2048  uint16_t *u16 = (uint16_t *)tb->coeffs;
2049 
2050  for (int i = min_pos; i < max_pos; i++) {
2051  const int xc = TRAV_X(i);
2052  const int yc = TRAV_Y(i);
2053  if (!(xc & hs) && !(yc & vs)) {
2054  const int v = PALETTE_INDEX(xc, yc);
2055  if (v == esc) {
2056  const int coeff = ff_vvc_palette_escape_val(lc, (1 << sps->bit_depth) - 1);
2057  const int pixel = av_clip_intp2(RSHIFT(coeff * scale, 6), sps->bit_depth);
2058  if (coeff < 0)
2059  return AVERROR_INVALIDDATA;
2060  PALETTE_SET_PIXEL(xc, yc, pixel);
2061  } else {
2062  PALETTE_SET_PIXEL(xc, yc, plt->entries[v]);
2063  }
2064  }
2065  }
2066  }
2067 
2068  return 0;
2069 }
2070 
2071 static int hls_palette_coding(VVCLocalContext *lc, const VVCTreeType tree_type)
2072 {
2073  const VVCFrameContext *fc = lc->fc;
2074  const VVCSPS *sps = fc->ps.sps;
2075  const H266RawSliceHeader *rsh = lc->sc->sh.r;
2076  CodingUnit *cu = lc->cu;
2077  Palette *pp = lc->ep->pp;
2078  const int max_entries = tree_type == SINGLE_TREE ? 31 : 15;
2079  const bool local_dual_tree = tree_type != SINGLE_TREE &&
2080  (!IS_I(rsh) || (IS_I(rsh) && !sps->r->sps_qtbtt_dual_tree_intra_flag));
2081  bool escape_present = false;
2082  bool transpose = false;
2083  bool adjust = false;
2084  int max_index = 0;
2085  int prev_run_pos = 0;
2086 
2087  int predictor_size, start, end, ret;
2089  uint8_t run_type[MAX_PALETTE_CU_SIZE * MAX_PALETTE_CU_SIZE];
2091 
2092  ff_vvc_channel_range(&start, &end, tree_type, sps->r->sps_chroma_format_idc);
2093 
2094  if (!palette_add_tu(lc, start, end, tree_type))
2095  return AVERROR(ENOMEM);
2096 
2097  predictor_size = pp[start].size;
2098  memset(reused, 0, sizeof(reused[0]) * predictor_size);
2099 
2100  ret = palette_predicted(lc, local_dual_tree, start, end, reused, predictor_size, max_entries);
2101  if (ret < 0)
2102  return ret;
2103 
2104  ret = palette_signaled(lc, local_dual_tree, start, end, max_entries);
2105  if (ret < 0)
2106  return ret;
2107 
2108  palette_update_predictor(lc, local_dual_tree, start, end, reused, predictor_size);
2109 
2110  if (cu->plt[start].size > 0)
2111  escape_present = ff_vvc_palette_escape_val_present_flag(lc);
2112 
2113  max_index = cu->plt[start].size - 1 + escape_present;
2114  if (max_index > 0) {
2115  adjust = false;
2117  }
2118 
2119  palette_qp(lc, tree_type, escape_present);
2120 
2121  index[0] = 0;
2122  for (int i = 0; i <= (cu->cb_width * cu->cb_height - 1) >> 4; i++) {
2123  ret = palette_subblock_data(lc, max_index, i, transpose,
2124  run_type, index, &prev_run_pos, &adjust);
2125  if (ret < 0)
2126  return ret;
2127  }
2128 
2129  return 0;
2130 }
2131 
2133 {
2134  const VVCSPS *sps = lc->fc->ps.sps;
2135  const CodingUnit *cu = lc->cu;
2136  const VVCTreeType tree_type = cu->tree_type;
2137  const bool pred_mode_plt_flag = cu->pred_mode == MODE_PLT;
2138  int ret = 0;
2139 
2140  if (tree_type == SINGLE_TREE || tree_type == DUAL_TREE_LUMA) {
2141  if (pred_mode_plt_flag) {
2142  if ((ret = hls_palette_coding(lc, tree_type)) < 0)
2143  return ret;
2144  ff_vvc_set_intra_mvf(lc, false, PF_PLT, false);
2145  } else {
2147  ff_vvc_set_intra_mvf(lc, false, PF_INTRA, cu->ciip_flag);
2148  }
2149  }
2150  if ((tree_type == SINGLE_TREE || tree_type == DUAL_TREE_CHROMA) && sps->r->sps_chroma_format_idc) {
2151  if (pred_mode_plt_flag && tree_type == DUAL_TREE_CHROMA) {
2152  if ((ret = hls_palette_coding(lc, tree_type)) < 0)
2153  return ret;
2154  } else if (!pred_mode_plt_flag) {
2156  }
2157  }
2158 
2159  return ret;
2160 }
2161 
2162 static int hls_coding_unit(VVCLocalContext *lc, int x0, int y0, int cb_width, int cb_height,
2163  int cqt_depth, const VVCTreeType tree_type, VVCModeType mode_type)
2164 {
2165  const VVCFrameContext *fc = lc->fc;
2166  const VVCSPS *sps = fc->ps.sps;
2167  const H266RawSliceHeader *rsh = lc->sc->sh.r;
2168  const int is_128 = cb_width > 64 || cb_height > 64;
2169  int ret = 0;
2170 
2171  CodingUnit *cu = add_cu(lc, x0, y0, cb_width, cb_height, cqt_depth, tree_type);
2172 
2173  if (!cu)
2174  return AVERROR(ENOMEM);
2175 
2176  ff_vvc_set_neighbour_available(lc, cu->x0, cu->y0, cu->cb_width, cu->cb_height);
2177 
2178  if (IS_I(rsh) && is_128)
2179  mode_type = MODE_TYPE_INTRA;
2180  cu->pred_mode = pred_mode_decode(lc, tree_type, mode_type);
2181 
2182  if (cu->pred_mode == MODE_INTRA && sps->r->sps_act_enabled_flag && tree_type == SINGLE_TREE)
2184 
2185  if (cu->pred_mode == MODE_INTRA || cu->pred_mode == MODE_PLT)
2186  ret = intra_data(lc);
2187  else if (tree_type != DUAL_TREE_CHROMA) /* MODE_INTER or MODE_IBC */
2188  ret = inter_data(lc);
2189 
2190  if (ret < 0)
2191  return ret;
2192 
2193  if (cu->pred_mode != MODE_INTRA && cu->pred_mode != MODE_PLT && !lc->cu->pu.general_merge_flag)
2194  cu->coded_flag = ff_vvc_cu_coded_flag(lc);
2195  else
2196  cu->coded_flag = !(cu->skip_flag || cu->pred_mode == MODE_PLT);
2197 
2198  if (cu->coded_flag) {
2199  sbt_info(lc, sps);
2200  if (sps->r->sps_act_enabled_flag && cu->pred_mode != MODE_INTRA && tree_type == SINGLE_TREE)
2202  lc->parse.lfnst_dc_only = 1;
2204  lc->parse.mts_dc_only = 1;
2206  ret = hls_transform_tree(lc, x0, y0, cb_width, cb_height, cu->ch_type);
2207  if (ret < 0)
2208  return ret;
2209  cu->lfnst_idx = lfnst_idx_decode(lc);
2210  cu->mts_idx = mts_idx_decode(lc);
2211  set_qp_c(lc);
2212  } else if (cu->pred_mode != MODE_PLT) {
2214  if (ret < 0)
2215  return ret;
2216  }
2217  set_cu_tabs(lc, cu);
2218 
2219  return 0;
2220 }
2221 
2223  const VVCSplitMode split, const int cb_width, const int cb_height, const VVCModeType mode_type_curr)
2224 {
2225  const H266RawSliceHeader *rsh = lc->sc->sh.r;
2226  const VVCSPS *sps = lc->fc->ps.sps;
2227  const int area = cb_width * cb_height;
2228 
2229  if ((IS_I(rsh) && sps->r->sps_qtbtt_dual_tree_intra_flag) ||
2230  mode_type_curr != MODE_TYPE_ALL || !sps->r->sps_chroma_format_idc ||
2231  sps->r->sps_chroma_format_idc == CHROMA_FORMAT_444)
2232  return 0;
2233  if ((area == 64 && (split == SPLIT_QT || split == SPLIT_TT_HOR || split == SPLIT_TT_VER)) ||
2234  (area == 32 && (split == SPLIT_BT_HOR || split == SPLIT_BT_VER)))
2235  return 1;
2236  if ((area == 64 && (split == SPLIT_BT_HOR || split == SPLIT_BT_VER) && sps->r->sps_chroma_format_idc == CHROMA_FORMAT_420) ||
2237  (area == 128 && (split == SPLIT_TT_HOR || split == SPLIT_TT_VER) && sps->r->sps_chroma_format_idc == CHROMA_FORMAT_420) ||
2238  (cb_width == 8 && split == SPLIT_BT_VER) || (cb_width == 16 && split == SPLIT_TT_VER))
2239  return 1 + !IS_I(rsh);
2240 
2241  return 0;
2242 }
2243 
2244 static VVCModeType mode_type_decode(VVCLocalContext *lc, const int x0, const int y0,
2245  const int cb_width, const int cb_height, const VVCSplitMode split, const int ch_type,
2246  const VVCModeType mode_type_curr)
2247 {
2248  VVCModeType mode_type;
2249  const int mode_type_condition = derive_mode_type_condition(lc, split, cb_width, cb_height, mode_type_curr);
2250 
2251  if (mode_type_condition == 1)
2252  mode_type = MODE_TYPE_INTRA;
2253  else if (mode_type_condition == 2) {
2254  mode_type = ff_vvc_non_inter_flag(lc, x0, y0, ch_type) ? MODE_TYPE_INTRA : MODE_TYPE_INTER;
2255  } else {
2256  mode_type = mode_type_curr;
2257  }
2258 
2259  return mode_type;
2260 }
2261 
2262 static int hls_coding_tree(VVCLocalContext *lc,
2263  int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2264  int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset, int part_idx,
2265  VVCSplitMode last_split_mode, VVCTreeType tree_type_curr, VVCModeType mode_type_curr);
2266 
2268  int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2269  int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset,
2270  VVCTreeType tree_type, VVCModeType mode_type)
2271 {
2272 #define CODING_TREE(x, idx) do { \
2273  ret = hls_coding_tree(lc, x, y0, cb_width / 2, cb_height, \
2274  qg_on_y, qg_on_c, cb_sub_div + 1, cqt_depth, mtt_depth + 1, \
2275  depth_offset, idx, SPLIT_BT_VER, tree_type, mode_type); \
2276  if (ret < 0) \
2277  return ret; \
2278 } while (0);
2279 
2280  const VVCPPS *pps = lc->fc->ps.pps;
2281  const int x1 = x0 + cb_width / 2;
2282  int ret = 0;
2283 
2284  depth_offset += (x0 + cb_width > pps->width) ? 1 : 0;
2285  CODING_TREE(x0, 0);
2286  if (x1 < pps->width)
2287  CODING_TREE(x1, 1);
2288 
2289  return 0;
2290 
2291 #undef CODING_TREE
2292 }
2293 
2295  int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2296  int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset,
2297  VVCTreeType tree_type, VVCModeType mode_type)
2298 {
2299 #define CODING_TREE(y, idx) do { \
2300  ret = hls_coding_tree(lc, x0, y, cb_width , cb_height / 2, \
2301  qg_on_y, qg_on_c, cb_sub_div + 1, cqt_depth, mtt_depth + 1, \
2302  depth_offset, idx, SPLIT_BT_HOR, tree_type, mode_type); \
2303  if (ret < 0) \
2304  return ret; \
2305  } while (0);
2306 
2307  const VVCPPS *pps = lc->fc->ps.pps;
2308  const int y1 = y0 + (cb_height / 2);
2309  int ret = 0;
2310 
2311  depth_offset += (y0 + cb_height > pps->height) ? 1 : 0;
2312  CODING_TREE(y0, 0);
2313  if (y1 < pps->height)
2314  CODING_TREE(y1, 1);
2315 
2316  return 0;
2317 
2318 #undef CODING_TREE
2319 }
2320 
2322  int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2323  int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset,
2324  VVCTreeType tree_type, VVCModeType mode_type)
2325 {
2326 #define CODING_TREE(x, w, sub_div, idx) do { \
2327  ret = hls_coding_tree(lc, x, y0, w, cb_height, \
2328  qg_on_y, qg_on_c, sub_div, cqt_depth, mtt_depth + 1, \
2329  depth_offset, idx, SPLIT_TT_VER, tree_type, mode_type); \
2330  if (ret < 0) \
2331  return ret; \
2332  } while (0);
2333 
2334  const VVCSH *sh = &lc->sc->sh;
2335  const int x1 = x0 + cb_width / 4;
2336  const int x2 = x0 + cb_width * 3 / 4;
2337  int ret;
2338 
2339  qg_on_y = qg_on_y && (cb_sub_div + 2 <= sh->cu_qp_delta_subdiv);
2340  qg_on_c = qg_on_c && (cb_sub_div + 2 <= sh->cu_chroma_qp_offset_subdiv);
2341 
2342  CODING_TREE(x0, cb_width / 4, cb_sub_div + 2, 0);
2343  CODING_TREE(x1, cb_width / 2, cb_sub_div + 1, 1);
2344  CODING_TREE(x2, cb_width / 4, cb_sub_div + 2, 2);
2345 
2346  return 0;
2347 
2348 #undef CODING_TREE
2349 }
2350 
2352  int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2353  int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset,
2354  VVCTreeType tree_type, VVCModeType mode_type)
2355 {
2356 #define CODING_TREE(y, h, sub_div, idx) do { \
2357  ret = hls_coding_tree(lc, x0, y, cb_width, h, \
2358  qg_on_y, qg_on_c, sub_div, cqt_depth, mtt_depth + 1, \
2359  depth_offset, idx, SPLIT_TT_HOR, tree_type, mode_type); \
2360  if (ret < 0) \
2361  return ret; \
2362  } while (0);
2363 
2364  const VVCSH *sh = &lc->sc->sh;
2365  const int y1 = y0 + (cb_height / 4);
2366  const int y2 = y0 + (3 * cb_height / 4);
2367  int ret;
2368 
2369  qg_on_y = qg_on_y && (cb_sub_div + 2 <= sh->cu_qp_delta_subdiv);
2370  qg_on_c = qg_on_c && (cb_sub_div + 2 <= sh->cu_chroma_qp_offset_subdiv);
2371 
2372  CODING_TREE(y0, cb_height / 4, cb_sub_div + 2, 0);
2373  CODING_TREE(y1, cb_height / 2, cb_sub_div + 1, 1);
2374  CODING_TREE(y2, cb_height / 4, cb_sub_div + 2, 2);
2375 
2376  return 0;
2377 
2378 #undef CODING_TREE
2379 }
2380 
2382  int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2383  int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset,
2384  VVCTreeType tree_type, VVCModeType mode_type)
2385 {
2386 #define CODING_TREE(x, y, idx) do { \
2387  ret = hls_coding_tree(lc, x, y, cb_width / 2, cb_height / 2, \
2388  qg_on_y, qg_on_c, cb_sub_div + 2, cqt_depth + 1, 0, 0, \
2389  idx, SPLIT_QT, tree_type, mode_type); \
2390  if (ret < 0) \
2391  return ret; \
2392  } while (0);
2393 
2394  const VVCPPS *pps = lc->fc->ps.pps;
2395  const int x1 = x0 + cb_width / 2;
2396  const int y1 = y0 + cb_height / 2;
2397  int ret = 0;
2398 
2399  CODING_TREE(x0, y0, 0);
2400  if (x1 < pps->width)
2401  CODING_TREE(x1, y0, 1);
2402  if (y1 < pps->height)
2403  CODING_TREE(x0, y1, 2);
2404  if (x1 < pps->width &&
2405  y1 < pps->height)
2406  CODING_TREE(x1, y1, 3);
2407 
2408  return 0;
2409 
2410 #undef CODING_TREE
2411 }
2412 
2413 typedef int (*coding_tree_fn)(VVCLocalContext *lc,
2414  int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2415  int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset,
2416  VVCTreeType tree_type, VVCModeType mode_type);
2417 
2418 const static coding_tree_fn coding_tree[] = {
2424 };
2425 
2427  int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2428  int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset, int part_idx,
2429  VVCSplitMode last_split_mode, VVCTreeType tree_type_curr, VVCModeType mode_type_curr)
2430 {
2431  VVCFrameContext *fc = lc->fc;
2432  const VVCPPS *pps = fc->ps.pps;
2433  const VVCSH *sh = &lc->sc->sh;
2434  const H266RawSliceHeader *rsh = sh->r;
2435  const int ch_type = tree_type_curr == DUAL_TREE_CHROMA;
2436  int ret;
2437  VVCAllowedSplit allowed;
2438 
2439  if (pps->r->pps_cu_qp_delta_enabled_flag && qg_on_y && cb_sub_div <= sh->cu_qp_delta_subdiv) {
2440  lc->parse.is_cu_qp_delta_coded = 0;
2441  lc->parse.cu_qg_top_left_x = x0;
2442  lc->parse.cu_qg_top_left_y = y0;
2443  }
2444  if (rsh->sh_cu_chroma_qp_offset_enabled_flag && qg_on_c &&
2445  cb_sub_div <= sh->cu_chroma_qp_offset_subdiv) {
2447  memset(lc->parse.chroma_qp_offset, 0, sizeof(lc->parse.chroma_qp_offset));
2448  }
2449 
2450  can_split(lc, x0, y0, cb_width, cb_height, mtt_depth, depth_offset, part_idx,
2451  last_split_mode, tree_type_curr, mode_type_curr, &allowed);
2452  if (ff_vvc_split_cu_flag(lc, x0, y0, cb_width, cb_height, ch_type, &allowed)) {
2453  VVCSplitMode split = ff_vvc_split_mode(lc, x0, y0, cb_width, cb_height, cqt_depth, mtt_depth, ch_type, &allowed);
2454  VVCModeType mode_type = mode_type_decode(lc, x0, y0, cb_width, cb_height, split, ch_type, mode_type_curr);
2455 
2456  VVCTreeType tree_type = (mode_type == MODE_TYPE_INTRA) ? DUAL_TREE_LUMA : tree_type_curr;
2457 
2458  if (split != SPLIT_QT) {
2459  if (!(x0 & 31) && !(y0 & 31) && mtt_depth <= 1)
2460  TAB_MSM(fc, mtt_depth, x0, y0) = split;
2461  }
2462  ret = coding_tree[split - 1](lc, x0, y0, cb_width, cb_height, qg_on_y, qg_on_c,
2463  cb_sub_div, cqt_depth, mtt_depth, depth_offset, tree_type, mode_type);
2464  if (ret < 0)
2465  return ret;
2466  if (mode_type_curr == MODE_TYPE_ALL && mode_type == MODE_TYPE_INTRA) {
2467  ret = hls_coding_tree(lc, x0, y0, cb_width, cb_height, 0, qg_on_c, cb_sub_div,
2468  cqt_depth, mtt_depth, 0, 0, split, DUAL_TREE_CHROMA, mode_type);
2469  if (ret < 0)
2470  return ret;
2471  }
2472  } else {
2473  ret = hls_coding_unit(lc, x0, y0, cb_width, cb_height, cqt_depth, tree_type_curr, mode_type_curr);
2474  if (ret < 0)
2475  return ret;
2476  }
2477 
2478  return 0;
2479 }
2480 
2482  const int x0, const int y0, const int cb_size, const int cqt_depth)
2483 {
2484  const VVCSH *sh = &lc->sc->sh;
2485  const H266RawSliceHeader *rsh = sh->r;
2486  const VVCPPS *pps = lc->fc->ps.pps;
2487  const int cb_subdiv = 2 * cqt_depth;
2488  int ret;
2489 
2490  if (cb_size > 64) {
2491  #define DUAL_TREE(x, y) do { \
2492  ret = dual_tree_implicit_qt_split(lc, x, y, cb_size / 2, cqt_depth + 1); \
2493  if (ret < 0) \
2494  return ret; \
2495  } while (0)
2496 
2497  const int x1 = x0 + (cb_size / 2);
2498  const int y1 = y0 + (cb_size / 2);
2499  if (pps->r->pps_cu_qp_delta_enabled_flag && cb_subdiv <= sh->cu_qp_delta_subdiv) {
2500  lc->parse.is_cu_qp_delta_coded = 0;
2501  lc->parse.cu_qg_top_left_x = x0;
2502  lc->parse.cu_qg_top_left_y = y0;
2503  }
2504  if (rsh->sh_cu_chroma_qp_offset_enabled_flag && cb_subdiv <= sh->cu_chroma_qp_offset_subdiv) {
2506  memset(lc->parse.chroma_qp_offset, 0, sizeof(lc->parse.chroma_qp_offset));
2507  }
2508  DUAL_TREE(x0, y0);
2509  if (x1 < pps->width)
2510  DUAL_TREE(x1, y0);
2511  if (y1 < pps->height)
2512  DUAL_TREE(x0, y1);
2513  if (x1 < pps->width && y1 < pps->height)
2514  DUAL_TREE(x1, y1);
2515  #undef DUAL_TREE
2516  } else {
2517  #define CODING_TREE(tree_type) do { \
2518  const int qg_on_y = tree_type == DUAL_TREE_LUMA; \
2519  ret = hls_coding_tree(lc, x0, y0, cb_size, cb_size, qg_on_y, !qg_on_y, \
2520  cb_subdiv, cqt_depth, 0, 0, 0, SPLIT_NONE, tree_type, MODE_TYPE_ALL); \
2521  if (ret < 0) \
2522  return ret; \
2523  } while (0)
2526  #undef CODING_TREE
2527  }
2528  return 0;
2529 }
2530 
2531 #define SET_SAO(elem, value) \
2532 do { \
2533  if (!sao_merge_up_flag && !sao_merge_left_flag) \
2534  sao->elem = value; \
2535  else if (sao_merge_left_flag) \
2536  sao->elem = CTB(fc->tab.sao, rx-1, ry).elem; \
2537  else if (sao_merge_up_flag) \
2538  sao->elem = CTB(fc->tab.sao, rx, ry-1).elem; \
2539  else \
2540  sao->elem = 0; \
2541 } while (0)
2542 
2543 static void hls_sao(VVCLocalContext *lc, const int rx, const int ry)
2544 {
2545  VVCFrameContext *fc = lc->fc;
2546  const H266RawSliceHeader *rsh = lc->sc->sh.r;
2547  int sao_merge_left_flag = 0;
2548  int sao_merge_up_flag = 0;
2549  SAOParams *sao = &CTB(fc->tab.sao, rx, ry);
2550  int c_idx, i;
2551 
2553  if (rx > 0) {
2554  if (lc->ctb_left_flag)
2555  sao_merge_left_flag = ff_vvc_sao_merge_flag_decode(lc);
2556  }
2557  if (ry > 0 && !sao_merge_left_flag) {
2558  if (lc->ctb_up_flag)
2559  sao_merge_up_flag = ff_vvc_sao_merge_flag_decode(lc);
2560  }
2561  }
2562 
2563  for (c_idx = 0; c_idx < (fc->ps.sps->r->sps_chroma_format_idc ? 3 : 1); c_idx++) {
2564  const int sao_used_flag = !c_idx ? rsh->sh_sao_luma_used_flag : rsh->sh_sao_chroma_used_flag;
2565  if (!sao_used_flag) {
2566  sao->type_idx[c_idx] = SAO_NOT_APPLIED;
2567  continue;
2568  }
2569 
2570  if (c_idx == 2) {
2571  sao->type_idx[2] = sao->type_idx[1];
2572  sao->eo_class[2] = sao->eo_class[1];
2573  } else {
2574  SET_SAO(type_idx[c_idx], ff_vvc_sao_type_idx_decode(lc));
2575  }
2576 
2577  if (sao->type_idx[c_idx] == SAO_NOT_APPLIED)
2578  continue;
2579 
2580  for (i = 0; i < 4; i++)
2581  SET_SAO(offset_abs[c_idx][i], ff_vvc_sao_offset_abs_decode(lc));
2582 
2583  if (sao->type_idx[c_idx] == SAO_BAND) {
2584  for (i = 0; i < 4; i++) {
2585  if (sao->offset_abs[c_idx][i]) {
2586  SET_SAO(offset_sign[c_idx][i],
2588  } else {
2589  sao->offset_sign[c_idx][i] = 0;
2590  }
2591  }
2592  SET_SAO(band_position[c_idx], ff_vvc_sao_band_position_decode(lc));
2593  } else if (c_idx != 2) {
2594  SET_SAO(eo_class[c_idx], ff_vvc_sao_eo_class_decode(lc));
2595  }
2596 
2597  // Inferred parameters
2598  sao->offset_val[c_idx][0] = 0;
2599  for (i = 0; i < 4; i++) {
2600  sao->offset_val[c_idx][i + 1] = sao->offset_abs[c_idx][i];
2601  if (sao->type_idx[c_idx] == SAO_EDGE) {
2602  if (i > 1)
2603  sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1];
2604  } else if (sao->offset_sign[c_idx][i]) {
2605  sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1];
2606  }
2607  sao->offset_val[c_idx][i + 1] *= 1 << (fc->ps.sps->bit_depth - FFMIN(10, fc->ps.sps->bit_depth));
2608  }
2609  }
2610 }
2611 
2612 static void alf_params(VVCLocalContext *lc, const int rx, const int ry)
2613 {
2614  const VVCFrameContext *fc = lc->fc;
2615  const H266RawSliceHeader *sh = lc->sc->sh.r;
2616  ALFParams *alf = &CTB(fc->tab.alf, rx, ry);
2617 
2618  alf->ctb_flag[LUMA] = alf->ctb_flag[CB] = alf->ctb_flag[CR] = 0;
2619  alf->ctb_cc_idc[0] = alf->ctb_cc_idc[1] = 0;
2620  if (sh->sh_alf_enabled_flag) {
2621  alf->ctb_flag[LUMA] = ff_vvc_alf_ctb_flag(lc, rx, ry, LUMA);
2622  if (alf->ctb_flag[LUMA]) {
2623  uint8_t alf_use_aps_flag = 0;
2624  if (sh->sh_num_alf_aps_ids_luma > 0)
2625  alf_use_aps_flag = ff_vvc_alf_use_aps_flag(lc);
2626  if (alf_use_aps_flag) {
2627  alf->ctb_filt_set_idx_y = 16;
2628  if (sh->sh_num_alf_aps_ids_luma > 1)
2630  } else {
2632  }
2633  }
2634  for (int c_idx = CB; c_idx <= CR; c_idx++) {
2635  const uint8_t alf_enabled_flag =
2636  c_idx == CB ? sh->sh_alf_cb_enabled_flag : sh->sh_alf_cr_enabled_flag;
2637  if (alf_enabled_flag) {
2638  const VVCALF *aps = fc->ps.alf_list[sh->sh_alf_aps_id_chroma];
2639  alf->ctb_flag[c_idx] = ff_vvc_alf_ctb_flag(lc, rx, ry, c_idx);
2640  alf->alf_ctb_filter_alt_idx[c_idx - 1] = 0;
2641  if (alf->ctb_flag[c_idx] && aps->num_chroma_filters > 1)
2642  alf->alf_ctb_filter_alt_idx[c_idx - 1] = ff_vvc_alf_ctb_filter_alt_idx(lc, c_idx, aps->num_chroma_filters);
2643  }
2644  }
2645  }
2646  if (fc->ps.sps->r->sps_ccalf_enabled_flag) {
2647  const uint8_t cc_enabled[] = { sh->sh_alf_cc_cb_enabled_flag, sh->sh_alf_cc_cr_enabled_flag };
2648  const uint8_t cc_aps_id[] = { sh->sh_alf_cc_cb_aps_id, sh->sh_alf_cc_cr_aps_id };
2649  for (int i = 0; i < 2; i++) {
2650  if (cc_enabled[i]) {
2651  const VVCALF *aps = fc->ps.alf_list[cc_aps_id[i]];
2652  alf->ctb_cc_idc[i] = ff_vvc_alf_ctb_cc_idc(lc, rx, ry, i, aps->num_cc_filters[i]);
2653  }
2654  }
2655  }
2656 }
2657 
2658 static void deblock_params(VVCLocalContext *lc, const int rx, const int ry)
2659 {
2660  VVCFrameContext *fc = lc->fc;
2661  const VVCSH *sh = &lc->sc->sh;
2662  CTB(fc->tab.deblock, rx, ry) = sh->deblock;
2663 }
2664 
2666  const int x0, const int y0, const int ctu_idx, const int rx, const int ry)
2667 {
2668  const VVCFrameContext *fc = lc->fc;
2669  const VVCSPS *sps = fc->ps.sps;
2670  const VVCPPS *pps = fc->ps.pps;
2671  const VVCSH *sh = &lc->sc->sh;
2672  const H266RawSliceHeader *rsh = sh->r;
2673  const unsigned int ctb_size = sps->ctb_size_y;
2674  int ret = 0;
2675 
2676  memset(lc->parse.chroma_qp_offset, 0, sizeof(lc->parse.chroma_qp_offset));
2677 
2678  hls_sao(lc, x0 >> sps->ctb_log2_size_y, y0 >> sps->ctb_log2_size_y);
2679  alf_params(lc, x0 >> sps->ctb_log2_size_y, y0 >> sps->ctb_log2_size_y);
2680  deblock_params(lc, x0 >> sps->ctb_log2_size_y, y0 >> sps->ctb_log2_size_y);
2681 
2682  if (IS_I(rsh) && sps->r->sps_qtbtt_dual_tree_intra_flag)
2683  ret = dual_tree_implicit_qt_split(lc, x0, y0, ctb_size, 0);
2684  else
2685  ret = hls_coding_tree(lc, x0, y0, ctb_size, ctb_size,
2686  1, 1, 0, 0, 0, 0, 0, SPLIT_NONE, SINGLE_TREE, MODE_TYPE_ALL);
2687  if (ret < 0)
2688  return ret;
2689 
2690  if (rx == pps->ctb_to_col_bd[rx + 1] - 1) {
2691  if (ctu_idx == sh->num_ctus_in_curr_slice - 1) {
2692  const int end_of_slice_one_bit = ff_vvc_end_of_slice_flag_decode(lc);
2693  if (!end_of_slice_one_bit)
2694  return AVERROR_INVALIDDATA;
2695  } else {
2696  if (ry == pps->ctb_to_row_bd[ry + 1] - 1) {
2697  const int end_of_tile_one_bit = ff_vvc_end_of_tile_one_bit(lc);
2698  if (!end_of_tile_one_bit)
2699  return AVERROR_INVALIDDATA;
2700  } else {
2701  if (fc->ps.sps->r->sps_entropy_coding_sync_enabled_flag) {
2702  const int end_of_subset_one_bit = ff_vvc_end_of_subset_one_bit(lc);
2703  if (!end_of_subset_one_bit)
2704  return AVERROR_INVALIDDATA;
2705  }
2706  }
2707  }
2708  }
2709 
2710  return 0;
2711 }
2712 
2713 static int has_inter_luma(const CodingUnit *cu)
2714 {
2715  return cu->pred_mode != MODE_INTRA && cu->pred_mode != MODE_PLT && cu->tree_type != DUAL_TREE_CHROMA;
2716 }
2717 
2718 static int pred_get_y(const VVCLocalContext *lc, const int y0, const Mv *mv, const int height)
2719 {
2720  const VVCPPS *pps = lc->fc->ps.pps;
2721  const int idx = lc->sc->sh.r->curr_subpic_idx;
2722  const int top = pps->subpic_y[idx];
2723  const int bottom = top + pps->subpic_height[idx];
2724 
2725  return av_clip(y0 + (mv->y >> 4) + height, top, bottom);
2726 }
2727 
2728 static void cu_get_max_y(const CodingUnit *cu, int max_y[2][VVC_MAX_REF_ENTRIES], const VVCLocalContext *lc)
2729 {
2730  const VVCFrameContext *fc = lc->fc;
2731  const PredictionUnit *pu = &cu->pu;
2732 
2733  if (pu->merge_gpm_flag) {
2734  for (int i = 0; i < FF_ARRAY_ELEMS(pu->gpm_mv); i++) {
2735  const MvField *mvf = pu->gpm_mv + i;
2736  const int lx = mvf->pred_flag - PF_L0;
2737  const int idx = mvf->ref_idx[lx];
2738  const int y = pred_get_y(lc, cu->y0, mvf->mv + lx, cu->cb_height);
2739 
2740  max_y[lx][idx] = FFMAX(max_y[lx][idx], y);
2741  }
2742  } else {
2743  const MotionInfo *mi = &pu->mi;
2744  const int max_dmvr_off = (!pu->inter_affine_flag && pu->dmvr_flag) ? 2 : 0;
2745  const int sbw = cu->cb_width / mi->num_sb_x;
2746  const int sbh = cu->cb_height / mi->num_sb_y;
2747  for (int sby = 0; sby < mi->num_sb_y; sby++) {
2748  for (int sbx = 0; sbx < mi->num_sb_x; sbx++) {
2749  const int x0 = cu->x0 + sbx * sbw;
2750  const int y0 = cu->y0 + sby * sbh;
2751  const MvField *mvf = ff_vvc_get_mvf(fc, x0, y0);
2752  for (int lx = 0; lx < 2; lx++) {
2753  const PredFlag mask = 1 << lx;
2754  if (mvf->pred_flag & mask) {
2755  const int idx = mvf->ref_idx[lx];
2756  const int y = pred_get_y(lc, y0, mvf->mv + lx, sbh);
2757 
2758  max_y[lx][idx] = FFMAX(max_y[lx][idx], y + max_dmvr_off);
2759  }
2760  }
2761  }
2762  }
2763  }
2764 }
2765 
2766 static void ctu_get_pred(VVCLocalContext *lc, const int rs)
2767 {
2768  const VVCFrameContext *fc = lc->fc;
2769  const H266RawSliceHeader *rsh = lc->sc->sh.r;
2770  CTU *ctu = fc->tab.ctus + rs;
2771  const CodingUnit *cu = fc->tab.cus[rs];
2772 
2773  ctu->has_dmvr = 0;
2774 
2775  if (IS_I(rsh))
2776  return;
2777 
2778  for (int lx = 0; lx < 2; lx++)
2779  memset(ctu->max_y[lx], -1, sizeof(ctu->max_y[0][0]) * rsh->num_ref_idx_active[lx]);
2780 
2781  while (cu) {
2782  if (has_inter_luma(cu)) {
2783  cu_get_max_y(cu, ctu->max_y, lc);
2784  ctu->has_dmvr |= cu->pu.dmvr_flag;
2785  }
2786  cu = cu->next;
2787  }
2788  ctu->max_y_idx[0] = ctu->max_y_idx[1] = 0;
2789 }
2790 
2792  const int ctu_idx, const int rs, const int rx, const int ry)
2793 {
2794  const VVCFrameContext *fc = lc->fc;
2795  const VVCSPS *sps = fc->ps.sps;
2796  const VVCPPS *pps = fc->ps.pps;
2797  const int x_ctb = rx << sps->ctb_log2_size_y;
2798  const int y_ctb = ry << sps->ctb_log2_size_y;
2799  const int ctb_size = 1 << sps->ctb_log2_size_y << sps->ctb_log2_size_y;
2800  EntryPoint* ep = lc->ep;
2801  int ret;
2802 
2803  if (rx == pps->ctb_to_col_bd[rx]) {
2804  ep->num_hmvp = 0;
2805  ep->num_hmvp_ibc = 0;
2806  ep->is_first_qg = ry == pps->ctb_to_row_bd[ry] || !ctu_idx;
2807  }
2808 
2809  lc->coeffs = fc->tab.coeffs + rs * ctb_size * VVC_MAX_SAMPLE_ARRAYS;
2810  lc->cu = NULL;
2811 
2812  ff_vvc_cabac_init(lc, ctu_idx, rx, ry);
2813  ff_vvc_decode_neighbour(lc, x_ctb, y_ctb, rx, ry, rs);
2814  ret = hls_coding_tree_unit(lc, x_ctb, y_ctb, ctu_idx, rx, ry);
2815  if (ret < 0)
2816  return ret;
2817  ctu_get_pred(lc, rs);
2818 
2819  return 0;
2820 }
2821 
2822 void ff_vvc_decode_neighbour(VVCLocalContext *lc, const int x_ctb, const int y_ctb,
2823  const int rx, const int ry, const int rs)
2824 {
2825  VVCFrameContext *fc = lc->fc;
2826  const int ctb_size = fc->ps.sps->ctb_size_y;
2827 
2828  lc->end_of_tiles_x = fc->ps.pps->width;
2829  lc->end_of_tiles_y = fc->ps.pps->height;
2830  if (fc->ps.pps->ctb_to_col_bd[rx] != fc->ps.pps->ctb_to_col_bd[rx + 1])
2831  lc->end_of_tiles_x = FFMIN(x_ctb + ctb_size, lc->end_of_tiles_x);
2832  if (fc->ps.pps->ctb_to_row_bd[ry] != fc->ps.pps->ctb_to_row_bd[ry + 1])
2833  lc->end_of_tiles_y = FFMIN(y_ctb + ctb_size, lc->end_of_tiles_y);
2834 
2835  lc->boundary_flags = 0;
2836  if (rx > 0 && fc->ps.pps->ctb_to_col_bd[rx] != fc->ps.pps->ctb_to_col_bd[rx - 1])
2838  if (rx > 0 && fc->tab.slice_idx[rs] != fc->tab.slice_idx[rs - 1])
2840  if (ry > 0 && fc->ps.pps->ctb_to_row_bd[ry] != fc->ps.pps->ctb_to_row_bd[ry - 1])
2842  if (ry > 0 && fc->tab.slice_idx[rs] != fc->tab.slice_idx[rs - fc->ps.pps->ctb_width])
2844  if (fc->ps.sps->r->sps_subpic_ctu_top_left_x[lc->sc->sh.r->curr_subpic_idx] == rx)
2846  if (fc->ps.sps->r->sps_subpic_ctu_top_left_y[lc->sc->sh.r->curr_subpic_idx] == ry)
2848  lc->ctb_left_flag = rx > 0 && !(lc->boundary_flags & BOUNDARY_LEFT_TILE);
2850  lc->ctb_up_right_flag = lc->ctb_up_flag && (fc->ps.pps->ctb_to_col_bd[rx] == fc->ps.pps->ctb_to_col_bd[rx + 1]) &&
2851  (fc->ps.pps->ctb_to_row_bd[ry] == fc->ps.pps->ctb_to_row_bd[ry - 1]);
2852  lc->ctb_up_left_flag = lc->ctb_left_flag && lc->ctb_up_flag;
2853 }
2854 
2856  const int x0, const int y0, const int w, const int h)
2857 {
2858  const int log2_ctb_size = lc->fc->ps.sps->ctb_log2_size_y;
2859  const int x0b = av_zero_extend(x0, log2_ctb_size);
2860  const int y0b = av_zero_extend(y0, log2_ctb_size);
2861 
2862  lc->na.cand_up = (lc->ctb_up_flag || y0b);
2863  lc->na.cand_left = (lc->ctb_left_flag || x0b);
2864  lc->na.cand_up_left = (x0b || y0b) ? lc->na.cand_left && lc->na.cand_up : lc->ctb_up_left_flag;
2865  lc->na.cand_up_right_sap =
2866  (x0b + w == 1 << log2_ctb_size) ? lc->ctb_up_right_flag && !y0b : lc->na.cand_up;
2867  lc->na.cand_up_right = lc->na.cand_up_right_sap && (x0 + w) < lc->end_of_tiles_x;
2868 }
2869 
2871 {
2872  while (*cus) {
2873  CodingUnit *cu = *cus;
2874  TransformUnit **head = &cu->tus.head;
2875 
2876  *cus = cu->next;
2877 
2878  while (*head) {
2879  TransformUnit *tu = *head;
2880  *head = tu->next;
2881  av_refstruct_unref(&tu);
2882  }
2883  cu->tus.tail = NULL;
2884 
2885  av_refstruct_unref(&cu);
2886  }
2887 }
2888 
2889 int ff_vvc_get_qPy(const VVCFrameContext *fc, const int xc, const int yc)
2890 {
2891  const int min_cb_log2_size_y = fc->ps.sps->min_cb_log2_size_y;
2892  const int x = xc >> min_cb_log2_size_y;
2893  const int y = yc >> min_cb_log2_size_y;
2894  return fc->tab.qp[LUMA][x + y * fc->ps.pps->min_cb_width];
2895 }
2896 
2898  const int bit_depth, const int persistent_rice_adaptation_enabled_flag)
2899 {
2900  for (size_t i = 0; i < FF_ARRAY_ELEMS(ep->stat_coeff); ++i) {
2901  ep->stat_coeff[i] =
2902  persistent_rice_adaptation_enabled_flag ? 2 * (av_log2(bit_depth - 10)) : 0;
2903  }
2904 }
2905 
2906 void ff_vvc_channel_range(int *start, int *end, const VVCTreeType tree_type, const uint8_t chroma_format_idc)
2907 {
2908  const bool has_chroma = chroma_format_idc && tree_type != DUAL_TREE_LUMA;
2909  const bool has_luma = tree_type != DUAL_TREE_CHROMA;
2910 
2911  *start = has_luma ? LUMA : CB;
2912  *end = has_chroma ? VVC_MAX_SAMPLE_ARRAYS : CB;
2913 }
VVCSPS
Definition: ps.h:58
ff_vvc_residual_coding
int ff_vvc_residual_coding(VVCLocalContext *lc, TransformBlock *tb)
Definition: cabac.c:2498
FFUMOD
#define FFUMOD(a, b)
Definition: common.h:66
L1
F H1 F F H1 F F F F H1<-F-------F-------F v v v H2 H3 H2 ^ ^ ^ F-------F-------F-> H1<-F-------F-------F|||||||||F H1 F|||||||||F H1 Funavailable fullpel samples(outside the picture for example) shall be equalto the closest available fullpel sampleSmaller pel interpolation:--------------------------if diag_mc is set then points which lie on a line between 2 vertically, horizontally or diagonally adjacent halfpel points shall be interpolatedlinearly with rounding to nearest and halfway values rounded up.points which lie on 2 diagonals at the same time should only use the onediagonal not containing the fullpel point F--> O q O<--h1-> O q O<--F v \/v \/v O O O O O O O|/|\|q q q q q|/|\|O O O O O O O ^/\ ^/\ ^ h2--> O q O<--h3-> O q O<--h2 v \/v \/v O O O O O O O|\|/|q q q q q|\|/|O O O O O O O ^/\ ^/\ ^ F--> O q O<--h1-> O q O<--Fthe remaining points shall be bilinearly interpolated from theup to 4 surrounding halfpel and fullpel points, again rounding should be tonearest and halfway values rounded upcompliant Snow decoders MUST support 1-1/8 pel luma and 1/2-1/16 pel chromainterpolation at leastOverlapped block motion compensation:-------------------------------------FIXMELL band prediction:===================Each sample in the LL0 subband is predicted by the median of the left, top andleft+top-topleft samples, samples outside the subband shall be considered tobe 0. To reverse this prediction in the decoder apply the following.for(y=0;y< height;y++){ for(x=0;x< width;x++){ sample[y][x]+=median(sample[y-1][x], sample[y][x-1], sample[y-1][x]+sample[y][x-1]-sample[y-1][x-1]);}}sample[-1][ *]=sample[ *][-1]=0;width, height here are the width and height of the LL0 subband not of the finalvideoDequantization:===============FIXMEWavelet Transform:==================Snow supports 2 wavelet transforms, the symmetric biorthogonal 5/3 integertransform and an integer approximation of the symmetric biorthogonal 9/7daubechies wavelet.2D IDWT(inverse discrete wavelet transform) --------------------------------------------The 2D IDWT applies a 2D filter recursively, each time combining the4 lowest frequency subbands into a single subband until only 1 subbandremains.The 2D filter is done by first applying a 1D filter in the vertical directionand then applying it in the horizontal one. --------------- --------------- --------------- ---------------|LL0|HL0|||||||||||||---+---|HL1||L0|H0|HL1||LL1|HL1|||||LH0|HH0|||||||||||||-------+-------|-> L1 H1 LH1 HH1 LH1 HH1 LH1 HH1 L1
Definition: snow.txt:554
VVCSH::cu_qp_delta_subdiv
uint8_t cu_qp_delta_subdiv
CuQpDeltaSubdiv.
Definition: ps.h:261
ff_vvc_cu_chroma_qp_offset_idx
int ff_vvc_cu_chroma_qp_offset_idx(VVCLocalContext *lc)
Definition: cabac.c:1754
H266RawSliceHeader::sh_alf_cc_cr_enabled_flag
uint8_t sh_alf_cc_cr_enabled_flag
Definition: cbs_h266.h:791
VVCSH::num_ctus_in_curr_slice
uint32_t num_ctus_in_curr_slice
NumCtusInCurrSlice.
Definition: ps.h:243
ff_vvc_mmvd_offset_coding
void ff_vvc_mmvd_offset_coding(VVCLocalContext *lc, Mv *mmvd_offset, const int ph_mmvd_fullpel_only_flag)
Definition: cabac.c:1500
VVCPH
Definition: ps.h:147
ff_vvc_update_hmvp
void ff_vvc_update_hmvp(VVCLocalContext *lc, const MotionInfo *mi)
Definition: mvs.c:1941
VVCPPS
Definition: ps.h:92
ff_vvc_sao_eo_class_decode
int ff_vvc_sao_eo_class_decode(VVCLocalContext *lc)
Definition: cabac.c:1048
av_clip
#define av_clip
Definition: common.h:100
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
less
static int less(const void *a, const void *b)
Definition: ctu.c:679
LUMA
#define LUMA
Definition: filter.c:31
skipped_transform_tree
static int skipped_transform_tree(VVCLocalContext *lc, int x0, int y0, int tu_width, int tu_height)
Definition: ctu.c:484
VVCLocalContext::mts_zero_out_sig_coeff_flag
int mts_zero_out_sig_coeff_flag
MtsZeroOutSigCoeffFlag;.
Definition: ctu.h:419
TransformBlock::tb_width
int tb_width
Definition: ctu.h:149
ff_vvc_new_palette_entries
int ff_vvc_new_palette_entries(VVCLocalContext *lc, const int bit_depth)
Definition: cabac.c:1395
VVCPPS::r
const H266RawPPS * r
RefStruct reference.
Definition: ps.h:93
MOTION_TRANSLATION
@ MOTION_TRANSLATION
Definition: ctu.h:217
CODING_TREE
#define CODING_TREE(x, idx)
CTU::max_y_idx
int max_y_idx[2]
Definition: ctu.h:345
ff_vvc_affine_mvp
void ff_vvc_affine_mvp(VVCLocalContext *lc, const int *mvp_lx_flag, const int amvr_shift, MotionInfo *mi)
Definition: mvs.c:1873
MotionInfo
Definition: ctu.h:244
SAO_BAND
@ SAO_BAND
Definition: hevcdec.h:166
set_cb_pos
static void set_cb_pos(const VVCFrameContext *fc, const CodingUnit *cu)
Definition: ctu.c:1170
TransformUnit::height
int height
Definition: ctu.h:177
CB
#define CB
Definition: filter.c:32
ff_vvc_regular_merge_flag
int ff_vvc_regular_merge_flag(VVCLocalContext *lc, const int cu_skip_flag)
Definition: cabac.c:1469
intra_chroma_pred_modes
static void intra_chroma_pred_modes(VVCLocalContext *lc)
Definition: ctu.c:1011
add_tu
static TransformUnit * add_tu(VVCFrameContext *fc, CodingUnit *cu, const int x0, const int y0, const int tu_width, const int tu_height)
Definition: ctu.c:229
PF_IBC
@ PF_IBC
Definition: ctu.h:227
mts_idx_decode
static MtsIdx mts_idx_decode(VVCLocalContext *lc)
Definition: ctu.c:847
VVCSH::cu_chroma_qp_offset_subdiv
uint8_t cu_chroma_qp_offset_subdiv
CuChromaQpOffsetSubdiv.
Definition: ps.h:262
CodingUnit
Definition: hevcdec.h:292
mv
static const int8_t mv[256][2]
Definition: 4xm.c:81
CodingUnit::act_enabled_flag
uint8_t act_enabled_flag
Definition: ctu.h:305
pred_get_y
static int pred_get_y(const VVCLocalContext *lc, const int y0, const Mv *mv, const int height)
Definition: ctu.c:2718
PredictionUnit::gpm_partition_idx
uint8_t gpm_partition_idx
Definition: ctu.h:266
palette_update_predictor
static void palette_update_predictor(VVCLocalContext *lc, const bool local_dual_tree, int start, int end, bool *predictor_reused, const int predictor_size)
Definition: ctu.c:1911
ff_vvc_ref_idx_lx
int ff_vvc_ref_idx_lx(VVCLocalContext *lc, const uint8_t nb_refs)
Definition: cabac.c:1597
CodingUnit::head
TransformUnit * head
RefStruct reference.
Definition: ctu.h:330
TransformUnit::nb_tbs
uint8_t nb_tbs
Definition: ctu.h:183
CodingUnit::bdpcm_flag
int bdpcm_flag[VVC_MAX_SAMPLE_ARRAYS]
BdpcmFlag.
Definition: ctu.h:325
ff_vvc_end_of_slice_flag_decode
int ff_vvc_end_of_slice_flag_decode(VVCLocalContext *lc)
Definition: cabac.c:2556
mask
int mask
Definition: mediacodecdec_common.c:154
MODE_IBC
@ MODE_IBC
Definition: ctu.h:194
TransformBlock::min_scan_y
int min_scan_y
Definition: ctu.h:157
ff_vvc_intra_luma_ref_idx
int ff_vvc_intra_luma_ref_idx(VVCLocalContext *lc)
Definition: cabac.c:1321
ff_vvc_inter_affine_flag
int ff_vvc_inter_affine_flag(VVCLocalContext *lc)
Definition: cabac.c:1581
ph
static int FUNC() ph(CodedBitstreamContext *ctx, RWContext *rw, H266RawPH *current)
Definition: cbs_h266_syntax_template.c:3043
VVCRefPic
Definition: dec.h:47
PALETTE_INDEX
#define PALETTE_INDEX(x, y)
Definition: ctu.c:1969
w
uint8_t w
Definition: llviddspenc.c:38
VVCLocalContext::mts_dc_only
int mts_dc_only
MtsDcOnly.
Definition: ctu.h:418
NeighbourAvailable::cand_left
int cand_left
Definition: hevcdec.h:318
CodingUnit::intra_mip_flag
uint8_t intra_mip_flag
intra_mip_flag
Definition: ctu.h:308
NeighbourAvailable::cand_up
int cand_up
Definition: hevcdec.h:319
ff_vvc_intra_mip_flag
int ff_vvc_intra_mip_flag(VVCLocalContext *lc, const uint8_t *intra_mip_flag)
Definition: cabac.c:1299
VVCLocalContext::sc
SliceContext * sc
Definition: ctu.h:445
SAOParams::offset_sign
int offset_sign[3][4]
sao_offset_sign
Definition: dsp.h:36
TRANSFORM_UNIT
#define TRANSFORM_UNIT(x, width, idx)
add_cu
static CodingUnit * add_cu(VVCLocalContext *lc, const int x0, const int y0, const int cb_width, const int cb_height, const int cqt_depth, const VVCTreeType tree_type)
Definition: ctu.c:1219
INTRA_DC
@ INTRA_DC
Definition: hevcdec.h:128
ff_vvc_lfnst_idx
int ff_vvc_lfnst_idx(VVCLocalContext *lc, const int inc)
Definition: cabac.c:2537
b
#define b
Definition: input.c:42
chroma
static av_always_inline void chroma(WaveformContext *s, AVFrame *in, AVFrame *out, int component, int intensity, int offset_y, int offset_x, int column, int mirror, int jobnr, int nb_jobs)
Definition: vf_waveform.c:1639
H266RawSliceHeader::sh_sao_luma_used_flag
uint8_t sh_sao_luma_used_flag
Definition: cbs_h266.h:813
VVCModeType
VVCModeType
Definition: ctu.c:37
coding_tree_bth
static int coding_tree_bth(VVCLocalContext *lc, int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c, int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset, VVCTreeType tree_type, VVCModeType mode_type)
Definition: ctu.c:2294
SPLIT_BT_HOR
@ SPLIT_BT_HOR
Definition: ctu.h:128
PALETTE_SET_PIXEL
#define PALETTE_SET_PIXEL(xc, yc, pix)
Definition: ctu.c:1960
NeighbourAvailable::cand_up_right
int cand_up_right
Definition: hevcdec.h:321
palette_qp
static void palette_qp(VVCLocalContext *lc, VVCTreeType tree_type, const bool escape_present)
Definition: ctu.c:1940
Mv::y
int16_t y
vertical component of motion vector
Definition: hevcdec.h:307
derive_mode_type_condition
static int derive_mode_type_condition(const VVCLocalContext *lc, const VVCSplitMode split, const int cb_width, const int cb_height, const VVCModeType mode_type_curr)
Definition: ctu.c:2222
ff_vvc_cu_affine_type_flag
int ff_vvc_cu_affine_type_flag(VVCLocalContext *lc)
Definition: cabac.c:1587
SAO_EDGE
@ SAO_EDGE
Definition: hevcdec.h:167
TransformUnit::x0
int x0
Definition: ctu.h:174
INTRA_VDIAG
@ INTRA_VDIAG
Definition: ctu.h:238
VVCSH::r
const H266RawSliceHeader * r
RefStruct reference.
Definition: ps.h:239
ff_vvc_mmvd_merge_flag
int ff_vvc_mmvd_merge_flag(VVCLocalContext *lc)
Definition: cabac.c:1475
ff_vvc_palette_escape_val_present_flag
bool ff_vvc_palette_escape_val_present_flag(VVCLocalContext *lc)
Definition: cabac.c:1400
TransformBlock::min_scan_x
int min_scan_x
Definition: ctu.h:156
TRAV_Y
#define TRAV_Y(pos)
Definition: ctu.c:1978
derive_center_luma_intra_pred_mode
static enum IntraPredMode derive_center_luma_intra_pred_mode(const VVCFrameContext *fc, const VVCSPS *sps, const VVCPPS *pps, const CodingUnit *cu)
Definition: ctu.c:868
VVCSplitMode
VVCSplitMode
Definition: ctu.h:125
ff_vvc_ciip_flag
int ff_vvc_ciip_flag(VVCLocalContext *lc)
Definition: cabac.c:1561
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
DUAL_TREE
#define DUAL_TREE(x, y)
CHROMA_FORMAT_422
@ CHROMA_FORMAT_422
Definition: ps.h:54
ff_vvc_intra_luma_mpm_idx
int ff_vvc_intra_luma_mpm_idx(VVCLocalContext *lc)
Definition: cabac.c:1353
mv_merge_refine_pred_flag
static void mv_merge_refine_pred_flag(MvField *mvf, const int width, const int height)
Definition: ctu.c:1337
intra_data
static int intra_data(VVCLocalContext *lc)
Definition: ctu.c:2132
derive_chroma_intra_pred_mode
static void derive_chroma_intra_pred_mode(VVCLocalContext *lc, const int cclm_mode_flag, const int cclm_mode_idx, const int intra_chroma_pred_mode)
Definition: ctu.c:887
MAX_PALETTE_CU_SIZE
#define MAX_PALETTE_CU_SIZE
Definition: ctu.h:39
TransformBlock::max_scan_y
int max_scan_y
Definition: ctu.h:155
bit_depth
static void bit_depth(AudioStatsContext *s, const uint64_t *const mask, uint8_t *depth)
Definition: af_astats.c:246
dual_tree_implicit_qt_split
static int dual_tree_implicit_qt_split(VVCLocalContext *lc, const int x0, const int y0, const int cb_size, const int cqt_depth)
Definition: ctu.c:2481
ff_vvc_abs_mvd_greater0_flag
int ff_vvc_abs_mvd_greater0_flag(VVCLocalContext *lc)
Definition: cabac.c:1612
RefPicList
Definition: hevcdec.h:196
alf_params
static void alf_params(VVCLocalContext *lc, const int rx, const int ry)
Definition: ctu.c:2612
ff_vvc_isp_split_type
enum IspType ff_vvc_isp_split_type(VVCLocalContext *lc, const int intra_subpartitions_mode_flag)
Definition: cabac.c:1336
VVCLocalContext::ctb_up_right_flag
uint8_t ctb_up_right_flag
Definition: ctu.h:387
ff_vvc_channel_range
void ff_vvc_channel_range(int *start, int *end, const VVCTreeType tree_type, const uint8_t chroma_format_idc)
Definition: ctu.c:2906
ff_vvc_sbt_quad_flag
int ff_vvc_sbt_quad_flag(VVCLocalContext *lc)
Definition: cabac.c:2519
alloc_tu
static TransformUnit * alloc_tu(VVCFrameContext *fc, CodingUnit *cu)
Definition: ctu.c:212
VVCLocalContext::coeffs
int * coeffs
Definition: ctu.h:448
PF_INTRA
@ PF_INTRA
Definition: hevcdec.h:120
VVCLocalContext::lfnst_zero_out_sig_coeff_flag
int lfnst_zero_out_sig_coeff_flag
LfnstZeroOutSigCoeffFlag.
Definition: ctu.h:416
deblock_params
static void deblock_params(VVCLocalContext *lc, const int rx, const int ry)
Definition: ctu.c:2658
TransformBlock::max_scan_x
int max_scan_x
Definition: ctu.h:154
SPLIT_QT
@ SPLIT_QT
Definition: ctu.h:131
ref_idx_decode
static int8_t ref_idx_decode(VVCLocalContext *lc, const VVCSH *sh, const int sym_mvd_flag, const int lx)
Definition: ctu.c:1562
VVCLocalContext::lfnst_dc_only
int lfnst_dc_only
LfnstDcOnly.
Definition: ctu.h:415
ff_vvc_intra_mip_transposed_flag
int ff_vvc_intra_mip_transposed_flag(VVCLocalContext *lc)
Definition: cabac.c:1307
ff_vvc_palette_idx_idc
int ff_vvc_palette_idx_idc(VVCLocalContext *lc, const int max_palette_index, const bool adjust)
Definition: cabac.c:1427
TRANSFORM_TREE
#define TRANSFORM_TREE(x, y)
ff_vvc_sb_mv_merge_mode
void ff_vvc_sb_mv_merge_mode(VVCLocalContext *lc, const int merge_subblock_idx, PredictionUnit *pu)
Definition: mvs.c:1424
VVCLocalContext::parse
struct VVCLocalContext::@323 parse
BOUNDARY_LEFT_TILE
#define BOUNDARY_LEFT_TILE
Definition: hevcdec.h:442
H266RawPPS::pps_cu_qp_delta_enabled_flag
uint8_t pps_cu_qp_delta_enabled_flag
Definition: cbs_h266.h:552
pred_mode_decode
static PredMode pred_mode_decode(VVCLocalContext *lc, const VVCTreeType tree_type, const VVCModeType mode_type)
Definition: ctu.c:1047
JCBCR
#define JCBCR
Definition: dec.h:39
ff_vvc_sao_offset_sign_decode
int ff_vvc_sao_offset_sign_decode(VVCLocalContext *lc)
Definition: cabac.c:1043
SPLIT_BT_VER
@ SPLIT_BT_VER
Definition: ctu.h:130
coding_tree_qt
static int coding_tree_qt(VVCLocalContext *lc, int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c, int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset, VVCTreeType tree_type, VVCModeType mode_type)
Definition: ctu.c:2381
MIN_PU_LOG2
#define MIN_PU_LOG2
Definition: dec.h:42
CodingUnit::ch_type
int ch_type
Definition: ctu.h:293
H266RawSliceHeader::sh_alf_cc_cr_aps_id
uint8_t sh_alf_cc_cr_aps_id
Definition: cbs_h266.h:792
H266RawSliceHeader::sh_cb_qp_offset
int8_t sh_cb_qp_offset
Definition: cbs_h266.h:808
ff_vvc_intra_mip_mode
int ff_vvc_intra_mip_mode(VVCLocalContext *lc)
Definition: cabac.c:1312
VVCFrameParamSets::sps
const VVCSPS * sps
RefStruct reference.
Definition: ps.h:230
ff_vvc_coding_tree_unit
int ff_vvc_coding_tree_unit(VVCLocalContext *lc, const int ctu_idx, const int rs, const int rx, const int ry)
parse a CTU
Definition: ctu.c:2791
PredictionUnit::gpm_mv
MvField gpm_mv[2]
Definition: ctu.h:267
CodingUnit::plt
Palette plt[VVC_MAX_SAMPLE_ARRAYS]
Definition: ctu.h:336
merge_data_regular
static void merge_data_regular(VVCLocalContext *lc)
Definition: ctu.c:1360
VVCLocalContext::fc
VVCFrameContext * fc
Definition: ctu.h:446
hls_coding_unit
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)
Definition: ctu.c:2162
VVCSH::pwt
PredWeightTable pwt
Definition: ps.h:247
PredictionUnit
Definition: hevcdec.h:325
EntryPoint::stat_coeff
int stat_coeff[VVC_MAX_SAMPLE_ARRAYS]
StatCoeff.
Definition: ctu.h:366
MODE_INTER
@ MODE_INTER
Definition: hevcdec.h:108
FFSIGN
#define FFSIGN(a)
Definition: common.h:75
CodingUnit::apply_lfnst_flag
int apply_lfnst_flag[VVC_MAX_SAMPLE_ARRAYS]
ApplyLfnstFlag[].
Definition: ctu.h:327
IS_B
#define IS_B(rsh)
Definition: ps.h:40
derive_dmvr_bdof_flag
static void derive_dmvr_bdof_flag(const VVCLocalContext *lc, PredictionUnit *pu)
Definition: ctu.c:1720
ff_vvc_cu_coded_flag
int ff_vvc_cu_coded_flag(VVCLocalContext *lc)
Definition: cabac.c:2506
tab
static const struct twinvq_data tab
Definition: twinvq_data.h:10345
TransformBlock::c_idx
uint8_t c_idx
Definition: ctu.h:144
SPLIT_TT_VER
@ SPLIT_TT_VER
Definition: ctu.h:129
CodingUnit::sbt_pos_flag
uint8_t sbt_pos_flag
Definition: ctu.h:300
VVCLocalContext::ctb_up_left_flag
uint8_t ctb_up_left_flag
Definition: ctu.h:388
alloc_cu
static CodingUnit * alloc_cu(VVCLocalContext *lc, const int x0, const int y0)
Definition: ctu.c:1196
ctu_get_pred
static void ctu_get_pred(VVCLocalContext *lc, const int rs)
Definition: ctu.c:2766
TransformBlock::x0
int x0
Definition: ctu.h:146
SliceContext::rpl
RefPicList * rpl
Definition: dec.h:118
VVCALF
Definition: ps.h:171
MODE_TYPE_ALL
@ MODE_TYPE_ALL
Definition: ctu.c:38
ff_vvc_mvp_lx_flag
int ff_vvc_mvp_lx_flag(VVCLocalContext *lc)
Definition: cabac.c:1632
H266RawSliceHeader::sh_alf_enabled_flag
uint8_t sh_alf_enabled_flag
Definition: cbs_h266.h:783
refstruct.h
ISP_VER_SPLIT
@ ISP_VER_SPLIT
Definition: ctu.h:122
CodingUnit::cb_width
int cb_width
Definition: ctu.h:291
coding_tree_ttv
static int coding_tree_ttv(VVCLocalContext *lc, int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c, int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset, VVCTreeType tree_type, VVCModeType mode_type)
Definition: ctu.c:2321
merge_data_subblock
static void merge_data_subblock(VVCLocalContext *lc)
Definition: ctu.c:1346
ff_vvc_split_cu_flag
int ff_vvc_split_cu_flag(VVCLocalContext *lc, const int x0, const int y0, const int cb_width, const int cb_height, const int is_chroma, const VVCAllowedSplit *a)
Definition: cabac.c:1115
H266RawSliceHeader::num_ref_idx_active
uint8_t num_ref_idx_active[2]
NumRefIdxActive[].
Definition: cbs_h266.h:839
merge_data_ciip
static void merge_data_ciip(VVCLocalContext *lc)
Definition: ctu.c:1420
VVC_MAX_SAMPLE_ARRAYS
@ VVC_MAX_SAMPLE_ARRAYS
Definition: vvc.h:77
CodingUnit::pu
PredictionUnit pu
Definition: ctu.h:338
ff_vvc_merge_gpm_idx
int ff_vvc_merge_gpm_idx(VVCLocalContext *lc, const int idx)
Definition: cabac.c:1547
H266RawSPS::sps_chroma_format_idc
uint8_t sps_chroma_format_idc
Definition: cbs_h266.h:314
hls_coding_tree
static int hls_coding_tree(VVCLocalContext *lc, int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c, int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset, int part_idx, VVCSplitMode last_split_mode, VVCTreeType tree_type_curr, VVCModeType mode_type_curr)
Definition: ctu.c:2426
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
ff_vvc_store_gpm_mvf
void ff_vvc_store_gpm_mvf(const VVCLocalContext *lc, const PredictionUnit *pu)
Definition: mvs.c:457
MTS_DCT2_DCT2
@ MTS_DCT2_DCT2
Definition: ctu.h:135
add_tb
static TransformBlock * add_tb(TransformUnit *tu, VVCLocalContext *lc, const int x0, const int y0, const int tb_width, const int tb_height, const int c_idx)
Definition: ctu.c:248
ff_vvc_palette_escape_val
int ff_vvc_palette_escape_val(VVCLocalContext *lc, const int max)
Definition: cabac.c:1432
RefPicList::refs
VVCRefPic refs[VVC_MAX_REF_ENTRIES]
Definition: dec.h:58
mode_type_decode
static VVCModeType mode_type_decode(VVCLocalContext *lc, const int x0, const int y0, const int cb_width, const int cb_height, const VVCSplitMode split, const int ch_type, const VVCModeType mode_type_curr)
Definition: ctu.c:2244
ff_vvc_tu_y_coded_flag
int ff_vvc_tu_y_coded_flag(VVCLocalContext *lc)
Definition: cabac.c:1697
ff_vvc_store_mv
void ff_vvc_store_mv(const VVCLocalContext *lc, const MotionInfo *mi)
Definition: mvs.c:508
TransformUnit::avail
bool avail[CHROMA+1]
Definition: ctu.h:178
SAO_NOT_APPLIED
@ SAO_NOT_APPLIED
Definition: hevcdec.h:165
ISP_HOR_SPLIT
@ ISP_HOR_SPLIT
Definition: ctu.h:121
coding_tree_tth
static int coding_tree_tth(VVCLocalContext *lc, int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c, int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset, VVCTreeType tree_type, VVCModeType mode_type)
Definition: ctu.c:2351
bcw_idx_decode
static int bcw_idx_decode(VVCLocalContext *lc, const MotionInfo *mi, const int cb_width, const int cb_height)
Definition: ctu.c:1541
AV_ZERO64
#define AV_ZERO64(d)
Definition: intreadwrite.h:666
mi
#define mi
Definition: vf_colormatrix.c:106
adjust
static int adjust(int x, int size)
Definition: mobiclip.c:513
TransformBlock::y0
int y0
Definition: ctu.h:147
TransformUnit::next
struct TransformUnit * next
RefStruct reference.
Definition: ctu.h:186
set_cu_tabs
static void set_cu_tabs(const VVCLocalContext *lc, const CodingUnit *cu)
Definition: ctu.c:1256
fc
#define fc(width, name, range_min, range_max)
Definition: cbs_av1.c:493
merge_data_ibc
static int merge_data_ibc(VVCLocalContext *lc)
Definition: ctu.c:1471
CodingUnit::cqt_depth
int cqt_depth
Definition: ctu.h:294
VVCSH
Definition: ps.h:238
mvp_add_difference
static void mvp_add_difference(MotionInfo *mi, const int num_cp_mv, const Mv mvds[2][MAX_CONTROL_POINTS], const int amvr_shift)
Definition: ctu.c:1606
ff_vvc_bcw_idx
int ff_vvc_bcw_idx(VVCLocalContext *lc, const int no_backward_pred_flag)
Definition: cabac.c:1676
PredWeightTable
Definition: ps.h:137
CodingUnit::tree_type
VVCTreeType tree_type
Definition: ctu.h:288
Palette::size
uint8_t size
Definition: ctu.h:283
VVCFrameParamSets::ph
VVCPH ph
Definition: ps.h:232
PredictionUnit::bdof_flag
uint8_t bdof_flag
Definition: ctu.h:275
ff_vvc_sbt_pos_flag
int ff_vvc_sbt_pos_flag(VVCLocalContext *lc)
Definition: cabac.c:2532
CodingUnit::mts_idx
MtsIdx mts_idx
Definition: ctu.h:303
ff_vvc_intra_luma_not_planar_flag
int ff_vvc_intra_luma_not_planar_flag(VVCLocalContext *lc, const int intra_subpartitions_mode_flag)
Definition: cabac.c:1348
TransformUnit::coded_flag
uint8_t coded_flag[VVC_MAX_SAMPLE_ARRAYS]
tu_y_coded_flag, tu_cb_coded_flag, tu_cr_coded_flag
Definition: ctu.h:182
RSHIFT
#define RSHIFT(a, b)
Definition: common.h:56
NeighbourAvailable::cand_up_right_sap
int cand_up_right_sap
Definition: hevcdec.h:322
ff_vvc_cu_skip_flag
int ff_vvc_cu_skip_flag(VVCLocalContext *lc, const uint8_t *cu_skip_flag)
Definition: cabac.c:1273
VVC_MAX_REF_ENTRIES
@ VVC_MAX_REF_ENTRIES
Definition: vvc.h:115
hls_merge_data
static int hls_merge_data(VVCLocalContext *lc)
Definition: ctu.c:1492
set_qp_y
static int set_qp_y(VVCLocalContext *lc, const int x0, const int y0, const int has_qp_delta)
Definition: ctu.c:142
ciip_flag_decode
static int ciip_flag_decode(VVCLocalContext *lc, const int ciip_avaiable, const int gpm_avaiable, const int is_128)
Definition: ctu.c:1390
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:74
H266RawSliceHeader::sh_cu_chroma_qp_offset_enabled_flag
uint8_t sh_cu_chroma_qp_offset_enabled_flag
Definition: cbs_h266.h:811
H266RawSPS
Definition: cbs_h266.h:308
CTU
Definition: ctu.h:343
hls_transform_unit
static int hls_transform_unit(VVCLocalContext *lc, int x0, int y0, int tu_width, int tu_height, int sub_tu_index, int ch_type)
Definition: ctu.c:314
aps
static int FUNC() aps(CodedBitstreamContext *ctx, RWContext *rw, H266RawAPS *current, int prefix)
Definition: cbs_h266_syntax_template.c:2501
EntryPoint::is_first_qg
uint8_t is_first_qg
Definition: ctu.h:376
VVCSPS::ctb_log2_size_y
uint8_t ctb_log2_size_y
CtbLog2SizeY.
Definition: ps.h:71
ff_vvc_palette_derive_scale
int ff_vvc_palette_derive_scale(VVCLocalContext *lc, const TransformUnit *tu, TransformBlock *tb)
Definition: intra.c:672
CodingUnit::sbt_flag
uint8_t sbt_flag
Definition: ctu.h:298
inter.h
VVCTreeType
VVCTreeType
Definition: ctu.h:167
IspType
IspType
Definition: ctu.h:119
NULL
#define NULL
Definition: coverity.c:32
av_clip_intp2
#define av_clip_intp2
Definition: common.h:121
SAOParams::offset_abs
int offset_abs[3][4]
sao_offset_abs
Definition: dsp.h:35
ff_vvc_mvp
void ff_vvc_mvp(VVCLocalContext *lc, const int *mvp_lx_flag, const int amvr_shift, MotionInfo *mi)
Definition: mvs.c:1614
run
uint8_t run
Definition: svq3.c:207
ff_vvc_pred_mode_plt_flag
int ff_vvc_pred_mode_plt_flag(VVCLocalContext *lc)
Definition: cabac.c:1248
pixel
uint8_t pixel
Definition: tiny_ssim.c:41
VVCLocalContext
Definition: ctu.h:384
VVCSH::ref_idx_sym
int8_t ref_idx_sym[2]
RefIdxSymL0, RefIdxSymL1.
Definition: ps.h:248
H266RawSliceHeader::curr_subpic_idx
uint16_t curr_subpic_idx
CurrSubpicIdx.
Definition: cbs_h266.h:837
INTRA_HORZ
@ INTRA_HORZ
Definition: ctu.h:235
VVCSH::max_tt_size
uint8_t max_tt_size[2]
MaxTtSizeY, MaxTtSizeC.
Definition: ps.h:259
EntryPoint::qp_y
int8_t qp_y
QpY.
Definition: ctu.h:364
ff_vvc_cu_act_enabled_flag
int ff_vvc_cu_act_enabled_flag(VVCLocalContext *lc)
Definition: cabac.c:1711
ff_vvc_cu_chroma_qp_offset_flag
int ff_vvc_cu_chroma_qp_offset_flag(VVCLocalContext *lc)
Definition: cabac.c:1749
TransformBlock::log2_tb_width
int log2_tb_width
Definition: ctu.h:151
CodingUnit::intra_luma_ref_idx
uint8_t intra_luma_ref_idx
IntraLumaRefLineIdx[][].
Definition: ctu.h:307
mvp_data_ibc
static int mvp_data_ibc(VVCLocalContext *lc)
Definition: ctu.c:1621
L0
#define L0
Definition: hevcdec.h:58
ff_vvc_sbt_horizontal_flag
int ff_vvc_sbt_horizontal_flag(VVCLocalContext *lc)
Definition: cabac.c:2524
ff_vvc_alf_ctb_filter_alt_idx
int ff_vvc_alf_ctb_filter_alt_idx(VVCLocalContext *lc, const int c_idx, const int num_chroma_filters)
Definition: cabac.c:1083
av_refstruct_pool_get
void * av_refstruct_pool_get(AVRefStructPool *pool)
Get an object from the pool, reusing an old one from the pool when available.
Definition: refstruct.c:297
ff_vvc_palette_transpose_flag
bool ff_vvc_palette_transpose_flag(VVCLocalContext *lc)
Definition: cabac.c:1405
hls_coding_tree_unit
static int hls_coding_tree_unit(VVCLocalContext *lc, const int x0, const int y0, const int ctu_idx, const int rx, const int ry)
Definition: ctu.c:2665
BOUNDARY_UPPER_TILE
#define BOUNDARY_UPPER_TILE
Definition: hevcdec.h:444
MODE_TYPE_INTRA
@ MODE_TYPE_INTRA
Definition: ctu.c:40
H266RawSliceHeader::sh_joint_cbcr_qp_offset
int8_t sh_joint_cbcr_qp_offset
Definition: cbs_h266.h:810
skipped_transform_tree_unit
static int skipped_transform_tree_unit(VVCLocalContext *lc)
Definition: ctu.c:1154
SPLIT_NONE
@ SPLIT_NONE
Definition: mss12.c:37
VVCRefPic::is_scaled
int is_scaled
RprConstraintsActiveFlag.
Definition: dec.h:53
SPLIT_TT_HOR
@ SPLIT_TT_HOR
Definition: ctu.h:127
MotionInfo::motion_model_idc
MotionModelIdc motion_model_idc
MotionModelIdc.
Definition: ctu.h:245
Mv::x
int16_t x
horizontal component of motion vector
Definition: hevcdec.h:306
CTB
#define CTB(tab, x, y)
Definition: filter.c:267
VVCRefPic::is_lt
int is_lt
Definition: dec.h:50
ff_vvc_alf_use_aps_flag
int ff_vvc_alf_use_aps_flag(VVCLocalContext *lc)
Definition: cabac.c:1068
PF_BI
@ PF_BI
Definition: hevcdec.h:123
MotionInfo::num_sb_y
int num_sb_y
Definition: ctu.h:253
ff_vvc_abs_mvd_minus2
int ff_vvc_abs_mvd_minus2(VVCLocalContext *lc)
Definition: cabac.c:1622
ff_vvc_tu_joint_cbcr_residual_flag
int ff_vvc_tu_joint_cbcr_residual_flag(VVCLocalContext *lc, const int tu_cb_coded_flag, const int tu_cr_coded_flag)
Definition: cabac.c:1808
index
int index
Definition: gxfenc.c:90
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
SAMPLE_CTB
#define SAMPLE_CTB(tab, x, y)
Definition: hevcdec.h:74
ff_vvc_alf_luma_prev_filter_idx
int ff_vvc_alf_luma_prev_filter_idx(VVCLocalContext *lc)
Definition: cabac.c:1073
cabac.h
error.h
TransformUnit
Definition: hevcdec.h:335
ff_vvc_pred_mode_ibc_flag
int ff_vvc_pred_mode_ibc_flag(VVCLocalContext *lc, const int is_chroma)
Definition: cabac.c:1279
DUAL_TREE_LUMA
@ DUAL_TREE_LUMA
Definition: ctu.h:169
SliceContext
Definition: mss12.h:70
SAOParams::offset_val
int16_t offset_val[3][5]
SaoOffsetVal.
Definition: dsp.h:42
VVCFrameParamSets::pps
const VVCPPS * pps
RefStruct reference.
Definition: ps.h:231
PredictionUnit::mmvd_merge_flag
uint8_t mmvd_merge_flag
Definition: ctu.h:258
ff_vvc_luma_mv_merge_mode
void ff_vvc_luma_mv_merge_mode(VVCLocalContext *lc, const int merge_idx, const int ciip_flag, MvField *mv)
Definition: mvs.c:829
VVCSH::max_mtt_depth
uint8_t max_mtt_depth[2]
MaxMttDepthY, MaxMttDepthC.
Definition: ps.h:260
ff_vvc_decode_neighbour
void ff_vvc_decode_neighbour(VVCLocalContext *lc, const int x_ctb, const int y_ctb, const int rx, const int ry, const int rs)
Definition: ctu.c:2822
Palette::entries
uint16_t entries[VVC_MAX_NUM_PALETTE_PREDICTOR_SIZE]
Definition: ctu.h:284
TransformBlock::tb_height
int tb_height
Definition: ctu.h:150
ff_vvc_intra_luma_mpm_remainder
int ff_vvc_intra_luma_mpm_remainder(VVCLocalContext *lc)
Definition: cabac.c:1361
EntryPoint::num_hmvp_ibc
int num_hmvp_ibc
NumHmvpIbcCand.
Definition: ctu.h:381
TransformBlock::ts
uint8_t ts
transform_skip_flag
Definition: ctu.h:145
ff_vvc_intra_bdpcm_chroma_dir_flag
int ff_vvc_intra_bdpcm_chroma_dir_flag(VVCLocalContext *lc)
Definition: cabac.c:1268
mvs.h
BOUNDARY_UPPER_SLICE
#define BOUNDARY_UPPER_SLICE
Definition: hevcdec.h:443
mvf_to_mi
static void mvf_to_mi(const MvField *mvf, MotionInfo *mi)
Definition: ctu.c:1323
CodingUnit::intra_pred_mode_y
IntraPredMode intra_pred_mode_y
IntraPredModeY.
Definition: ctu.h:321
ff_vvc_pred_flag
PredFlag ff_vvc_pred_flag(VVCLocalContext *lc, const int is_b)
Definition: cabac.c:1566
height
#define height
Definition: dsp.h:89
INTRA_PLANAR
@ INTRA_PLANAR
Definition: hevcdec.h:127
size
int size
Definition: twinvq_data.h:10344
coding_tree
const static coding_tree_fn coding_tree[]
Definition: ctu.c:2418
refine_regular_subblock
static void refine_regular_subblock(const VVCLocalContext *lc)
Definition: ctu.c:1759
ff_vvc_merge_subblock_idx
int ff_vvc_merge_subblock_idx(VVCLocalContext *lc, const int max_num_subblock_merge_cand)
Definition: cabac.c:1459
PredictionUnit::merge_gpm_flag
uint8_t merge_gpm_flag
Definition: ctu.h:265
VVCRefPic::poc
int poc
Definition: dec.h:49
CodingUnit::sbt_horizontal_flag
uint8_t sbt_horizontal_flag
Definition: ctu.h:299
ff_vvc_merge_gpm_partition_idx
int ff_vvc_merge_gpm_partition_idx(VVCLocalContext *lc)
Definition: cabac.c:1542
intra.h
H266RawSliceHeader::sh_alf_aps_id_chroma
uint8_t sh_alf_aps_id_chroma
Definition: cbs_h266.h:788
VVCLocalContext::infer_tu_cbf_luma
int infer_tu_cbf_luma
InferTuCbfLuma.
Definition: ctu.h:412
MvField
Definition: hevcdec.h:310
VVCLocalContext::end_of_tiles_x
int end_of_tiles_x
Definition: ctu.h:389
INTRA_INVALID
@ INTRA_INVALID
Definition: ctu.h:232
ff_vvc_luma_mv_merge_gpm
void ff_vvc_luma_mv_merge_gpm(VVCLocalContext *lc, const int merge_gpm_idx[2], MvField *mv)
Definition: mvs.c:842
diff
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
Definition: vf_paletteuse.c:166
ff_vvc_sym_mvd_flag
int ff_vvc_sym_mvd_flag(VVCLocalContext *lc)
Definition: cabac.c:1592
CodingUnit::coded_flag
uint8_t coded_flag
Definition: ctu.h:296
split
static char * split(char *message, char delim)
Definition: af_channelmap.c:89
VVCLocalContext::ctb_up_flag
uint8_t ctb_up_flag
Definition: ctu.h:386
ff_vvc_end_of_tile_one_bit
int ff_vvc_end_of_tile_one_bit(VVCLocalContext *lc)
Definition: cabac.c:2561
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
ff_vvc_intra_subpartitions_mode_flag
int ff_vvc_intra_subpartitions_mode_flag(VVCLocalContext *lc)
Definition: cabac.c:1331
CTU::has_dmvr
int has_dmvr
Definition: ctu.h:346
CodingUnit::lfnst_idx
int lfnst_idx
Definition: ctu.h:302
VVCSH::deblock
DBParams deblock
Definition: ps.h:254
MAX_CONTROL_POINTS
#define MAX_CONTROL_POINTS
Definition: ctu.h:67
VVC_MAX_NUM_PALETTE_PREDICTOR_SIZE
@ VVC_MAX_NUM_PALETTE_PREDICTOR_SIZE
Definition: vvc.h:159
H266RawSliceHeader::sh_cr_qp_offset
int8_t sh_cr_qp_offset
Definition: cbs_h266.h:809
H266RawSliceHeader::sh_alf_cb_enabled_flag
uint8_t sh_alf_cb_enabled_flag
Definition: cbs_h266.h:786
coding_tree_btv
static int coding_tree_btv(VVCLocalContext *lc, int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c, int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset, VVCTreeType tree_type, VVCModeType mode_type)
Definition: ctu.c:2267
av_zero_extend
#define av_zero_extend
Definition: common.h:151
VVCLocalContext::na
NeighbourAvailable na
Definition: ctu.h:433
CodingUnit::intra_pred_mode_c
IntraPredMode intra_pred_mode_c
IntraPredModeC.
Definition: ctu.h:322
ff_vvc_sao_band_position_decode
int ff_vvc_sao_band_position_decode(VVCLocalContext *lc)
Definition: cabac.c:1028
MODE_TYPE_INTER
@ MODE_TYPE_INTER
Definition: ctu.c:39
MvField::pred_flag
int8_t pred_flag
Definition: hevcdec.h:313
MvField::hpel_if_idx
uint8_t hpel_if_idx
hpelIfIdx
Definition: ctu.h:205
SAOParams::eo_class
int eo_class[3]
sao_eo_class
Definition: dsp.h:40
ff_vvc_merge_idx
int ff_vvc_merge_idx(VVCLocalContext *lc)
Definition: cabac.c:1527
ff_vvc_merge_subblock_flag
int ff_vvc_merge_subblock_flag(VVCLocalContext *lc)
Definition: cabac.c:1453
ALFParams::ctb_cc_idc
uint8_t ctb_cc_idc[2]
alf_ctb_cc_cb_idc, alf_ctb_cc_cr_idc
Definition: ctu.h:476
av_refstruct_unref
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
Definition: refstruct.c:120
ff_vvc_split_mode
VVCSplitMode ff_vvc_split_mode(VVCLocalContext *lc, const int x0, const int y0, const int cb_width, const int cb_height, const int cqt_depth, const int mtt_depth, const int ch_type, const VVCAllowedSplit *a)
Definition: cabac.c:1193
CTU::max_y
int max_y[2][VVC_MAX_REF_ENTRIES]
Definition: ctu.h:344
H266RawSliceHeader
Definition: cbs_h266.h:771
get_cclm_enabled
static int get_cclm_enabled(const VVCLocalContext *lc, const int x0, const int y0)
Definition: ctu.c:634
set_cb_tab
static void set_cb_tab(const VVCLocalContext *lc, uint8_t *tab, const uint8_t v)
Definition: ctu.c:122
VVCLocalContext::boundary_flags
int boundary_flags
Definition: ctu.h:443
PredictionUnit::mi
MotionInfo mi
Definition: ctu.h:271
MODE_INTRA
#define MODE_INTRA
Definition: vp3.c:84
av_assert2
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:68
CR
#define CR
Definition: filter.c:33
ff_vvc_num_signalled_palette_entries
int ff_vvc_num_signalled_palette_entries(VVCLocalContext *lc, const int max)
Definition: cabac.c:1390
tu_y_coded_flag_decode
static uint8_t tu_y_coded_flag_decode(VVCLocalContext *lc, const int is_sbt_not_coded, const int sub_tu_index, const int is_isp, const int is_chroma_coded)
Definition: ctu.c:273
VVCAllowedSplit
Definition: ctu.h:451
BOUNDARY_LEFT_SUBPIC
#define BOUNDARY_LEFT_SUBPIC
Definition: ctu.h:437
MODE_PLT
@ MODE_PLT
Definition: ctu.h:193
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
ISP_NO_SPLIT
@ ISP_NO_SPLIT
Definition: ctu.h:120
luma_intra_pred_mode
static enum IntraPredMode luma_intra_pred_mode(VVCLocalContext *lc, const int intra_subpartitions_mode_flag)
Definition: ctu.c:685
pack_mip_info
static av_always_inline uint8_t pack_mip_info(int intra_mip_flag, int intra_mip_transposed_flag, int intra_mip_mode)
Definition: ctu.c:952
NeighbourAvailable::cand_up_left
int cand_up_left
Definition: hevcdec.h:320
ff_vvc_alf_ctb_flag
int ff_vvc_alf_ctb_flag(VVCLocalContext *lc, const int rx, const int ry, const int c_idx)
Definition: cabac.c:1053
ff_vvc_abs_mvd_greater1_flag
int ff_vvc_abs_mvd_greater1_flag(VVCLocalContext *lc)
Definition: cabac.c:1617
ff_vvc_transform_skip_flag
int ff_vvc_transform_skip_flag(VVCLocalContext *lc, const int inc)
Definition: cabac.c:1813
modes
static const SiprModeParam modes[MODE_COUNT]
Definition: sipr.c:70
derive_mmvd
static void derive_mmvd(const VVCLocalContext *lc, MvField *mvf, const Mv *mmvd_offset)
Definition: ctu.c:1282
ff_vvc_set_intra_mvf
void ff_vvc_set_intra_mvf(const VVCLocalContext *lc, const bool dmvr, const PredFlag pf, const bool ciip_flag)
Definition: mvs.c:271
palette_signaled
static int palette_signaled(VVCLocalContext *lc, const bool local_dual_tree, const int start, const int end, const int max_entries)
Definition: ctu.c:1883
av_always_inline
#define av_always_inline
Definition: attributes.h:49
hls_palette_coding
static int hls_palette_coding(VVCLocalContext *lc, const VVCTreeType tree_type)
Definition: ctu.c:2071
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
ff_vvc_tu_cb_coded_flag
int ff_vvc_tu_cb_coded_flag(VVCLocalContext *lc)
Definition: cabac.c:1687
PF_L0
@ PF_L0
Definition: hevcdec.h:121
VVCLocalContext::prev_tu_cbf_y
int prev_tu_cbf_y
prevTuCbfY;
Definition: ctu.h:413
VVCLocalContext::cu_qg_top_left_x
int cu_qg_top_left_x
CuQgTopLeftX.
Definition: ctu.h:407
get_num_intra_subpartitions
static int get_num_intra_subpartitions(enum IspType isp_split_type, int cb_width, int cb_height)
Definition: ctu.c:625
CodingUnit::x0
int x0
Definition: ctu.h:289
TransformUnit::tbs
TransformBlock tbs[VVC_MAX_SAMPLE_ARRAYS]
Definition: ctu.h:184
H266RawSliceHeader::sh_sao_chroma_used_flag
uint8_t sh_sao_chroma_used_flag
Definition: cbs_h266.h:814
VVCPH::poc
int32_t poc
PicOrderCntVal.
Definition: ps.h:153
EntryPoint
Definition: ctu.h:363
TransformBlock::coeffs
int * coeffs
Definition: ctu.h:164
ff_vvc_store_sb_mvs
void ff_vvc_store_sb_mvs(const VVCLocalContext *lc, PredictionUnit *pu)
Definition: mvs.c:412
run_copy
static void run_copy(const SwsImg *out_base, const SwsImg *in_base, int y, int h, const SwsPass *pass)
Definition: graph.c:97
ff_vvc_end_of_subset_one_bit
int ff_vvc_end_of_subset_one_bit(VVCLocalContext *lc)
Definition: cabac.c:2566
set_qp_c
static void set_qp_c(VVCLocalContext *lc)
Definition: ctu.c:185
H266RawSliceHeader::sh_alf_cc_cb_aps_id
uint8_t sh_alf_cc_cb_aps_id
Definition: cbs_h266.h:790
ff_vvc_no_backward_pred_flag
int ff_vvc_no_backward_pred_flag(const VVCLocalContext *lc)
Definition: mvs.c:121
TransformUnit::width
int width
Definition: ctu.h:176
hls_sao
static void hls_sao(VVCLocalContext *lc, const int rx, const int ry)
Definition: ctu.c:2543
SAOParams
Definition: dsp.h:34
chroma_qp_offset_decode
static void chroma_qp_offset_decode(VVCLocalContext *lc, const int is_128, const int is_chroma_coded)
Definition: ctu.c:293
VVCLocalContext::cu
CodingUnit * cu
Definition: ctu.h:429
EntryPoint::pp
Palette pp[VVC_MAX_SAMPLE_ARRAYS]
Definition: ctu.h:368
ff_vvc_sbt_flag
int ff_vvc_sbt_flag(VVCLocalContext *lc)
Definition: cabac.c:2511
TRAV_X
#define TRAV_X(pos)
Definition: ctu.c:1977
ff_vvc_get_qPy
int ff_vvc_get_qPy(const VVCFrameContext *fc, const int xc, const int yc)
Definition: ctu.c:2889
ff_vvc_cu_qp_delta_abs
int ff_vvc_cu_qp_delta_abs(VVCLocalContext *lc)
Definition: cabac.c:1716
INTRA_VERT
@ INTRA_VERT
Definition: ctu.h:237
BOUNDARY_UPPER_SUBPIC
#define BOUNDARY_UPPER_SUBPIC
Definition: ctu.h:440
PredictionUnit::dmvr_flag
uint8_t dmvr_flag
Definition: ctu.h:274
hls_transform_tree
static int hls_transform_tree(VVCLocalContext *lc, int x0, int y0, int tu_width, int tu_height, int ch_type)
Definition: ctu.c:408
ret
ret
Definition: filter_design.txt:187
VVCLocalContext::chroma_qp_offset
int chroma_qp_offset[3]
CuQpOffsetCb, CuQpOffsetCr, CuQpOffsetCbCr.
Definition: ctu.h:410
pred
static const float pred[4]
Definition: siprdata.h:259
ff_vvc_pred_mode_flag
int ff_vvc_pred_mode_flag(VVCLocalContext *lc, const int is_chroma)
Definition: cabac.c:1237
IntraPredMode
IntraPredMode
Definition: hevcdec.h:126
ff_vvc_alf_luma_fixed_filter_idx
int ff_vvc_alf_luma_fixed_filter_idx(VVCLocalContext *lc)
Definition: cabac.c:1078
hls_mvd_coding
static void hls_mvd_coding(VVCLocalContext *lc, Mv *mvd)
Definition: ctu.c:1517
VVCLocalContext::sbt_num_fourths_tb0
int sbt_num_fourths_tb0
SbtNumFourthsTb0.
Definition: ctu.h:404
cu_get_max_y
static void cu_get_max_y(const CodingUnit *cu, int max_y[2][VVC_MAX_REF_ENTRIES], const VVCLocalContext *lc)
Definition: ctu.c:2728
CHROMA
@ CHROMA
Definition: vf_waveform.c:49
sps
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
Definition: cbs_h264_syntax_template.c:260
CodingUnit::tus
struct CodingUnit::@322 tus
ff_vvc_mvd_sign_flag
int ff_vvc_mvd_sign_flag(VVCLocalContext *lc)
Definition: cabac.c:1627
ff_vvc_mvp_ibc
int ff_vvc_mvp_ibc(VVCLocalContext *lc, const int mvp_l0_flag, const int amvr_shift, Mv *mv)
Definition: mvs.c:1735
H266RawSliceHeader::sh_alf_cc_cb_enabled_flag
uint8_t sh_alf_cc_cb_enabled_flag
Definition: cbs_h266.h:789
ALFParams::alf_ctb_filter_alt_idx
uint8_t alf_ctb_filter_alt_idx[2]
alf_ctb_filter_alt_idx[]
Definition: ctu.h:475
PredictionUnit::inter_affine_flag
uint8_t inter_affine_flag
Definition: ctu.h:260
ff_vvc_get_mvf
MvField * ff_vvc_get_mvf(const VVCFrameContext *fc, const int x0, const int y0)
Definition: mvs.c:1960
SKIPPED_TRANSFORM_TREE
#define SKIPPED_TRANSFORM_TREE(x, y)
CodingUnit::cb_height
int cb_height
Definition: ctu.h:292
ff_vvc_cu_qp_delta_sign_flag
int ff_vvc_cu_qp_delta_sign_flag(VVCLocalContext *lc)
Definition: cabac.c:1744
TransformBlock::log2_tb_height
int log2_tb_height
Definition: ctu.h:152
CodingUnit::tail
TransformUnit * tail
RefStruct reference.
Definition: ctu.h:331
ff_vvc_set_neighbour_available
void ff_vvc_set_neighbour_available(VVCLocalContext *lc, const int x0, const int y0, const int w, const int h)
Definition: ctu.c:2855
inter_data
static int inter_data(VVCLocalContext *lc)
Definition: ctu.c:1792
DUAL_TREE_CHROMA
@ DUAL_TREE_CHROMA
Definition: ctu.h:170
can_split
static void can_split(const VVCLocalContext *lc, int x0, int y0, int cb_width, int cb_height, int mtt_depth, int depth_offset, int part_idx, VVCSplitMode last_split_mode, VVCTreeType tree_type, VVCModeType mode_type, VVCAllowedSplit *split)
Definition: ctu.c:526
TransformBlock::has_coeffs
uint8_t has_coeffs
Definition: ctu.h:143
PredMode
PredMode
Definition: hevcdec.h:107
MotionInfo::num_sb_x
int num_sb_x
Definition: ctu.h:253
PredictionUnit::sym_mvd_flag
int sym_mvd_flag
Definition: ctu.h:269
ff_vvc_cclm_mode_idx
int ff_vvc_cclm_mode_idx(VVCLocalContext *lc)
Definition: cabac.c:1371
ff_vvc_palette_predictor_run
int ff_vvc_palette_predictor_run(VVCLocalContext *lc, const int max)
Definition: cabac.c:1385
ff_vvc_luma_mv_merge_ibc
int ff_vvc_luma_mv_merge_ibc(VVCLocalContext *lc, const int merge_idx, Mv *mv)
Definition: mvs.c:1744
fill_dmvr_info
static void fill_dmvr_info(const VVCLocalContext *lc)
Definition: ctu.c:1771
TransformBlock
Definition: ctu.h:142
intra_luma_pred_modes
static void intra_luma_pred_modes(VVCLocalContext *lc)
Definition: ctu.c:958
TAB_MSM
#define TAB_MSM(fc, depth, x, y)
Definition: ctu.c:34
VVCSH::slice_qp_y
int8_t slice_qp_y
SliceQpY.
Definition: ps.h:251
CodingUnit::pred_mode
enum PredMode pred_mode
PredMode.
Definition: hevcdec.h:296
ff_vvc_sao_type_idx_decode
int ff_vvc_sao_type_idx_decode(VVCLocalContext *lc)
Definition: cabac.c:1018
ALFParams::ctb_filt_set_idx_y
uint8_t ctb_filt_set_idx_y
AlfCtbFiltSetIdxY.
Definition: ctu.h:474
ff_vvc_cabac_init
int ff_vvc_cabac_init(VVCLocalContext *lc, const int ctu_idx, const int rx, const int ry)
Definition: cabac.c:842
ff_vvc_run_copy_flag
bool ff_vvc_run_copy_flag(VVCLocalContext *lc, const int prev_run_type, const int prev_run_position, const int cur_pos)
Definition: cabac.c:1410
MIN_TU_SIZE
#define MIN_TU_SIZE
Definition: ctu.h:46
pps
uint64_t pps
Definition: dovi_rpuenc.c:36
SAOParams::type_idx
uint8_t type_idx[3]
sao_type_idx
Definition: dsp.h:44
palette_add_tu
static TransformUnit * palette_add_tu(VVCLocalContext *lc, const int start, const int end, const VVCTreeType tree_type)
Definition: ctu.c:1826
mvp_data
static int mvp_data(VVCLocalContext *lc)
Definition: ctu.c:1651
EntryPoint::num_hmvp
int num_hmvp
NumHmvpCand.
Definition: ctu.h:379
get_qp_y_pred
static int get_qp_y_pred(const VVCLocalContext *lc)
Definition: ctu.c:75
PredictionUnit::general_merge_flag
uint8_t general_merge_flag
Definition: ctu.h:257
VVCLocalContext::end_of_tiles_y
int end_of_tiles_y
Definition: ctu.h:390
sbt_info
static void sbt_info(VVCLocalContext *lc, const VVCSPS *sps)
Definition: ctu.c:1115
MAX_QP
#define MAX_QP
Definition: hevcdec.h:50
TransformUnit::y0
int y0
Definition: ctu.h:175
VVCFrameContext::qp
int8_t * qp[VVC_MAX_SAMPLE_ARRAYS]
Definition: dec.h:165
CodingUnit::next
struct CodingUnit * next
RefStruct reference.
Definition: ctu.h:340
MvField::mv
Mv mv[2]
mvL0, vvL1
Definition: hevcdec.h:311
ALFParams
Definition: ctu.h:472
ff_vvc_sao_merge_flag_decode
int ff_vvc_sao_merge_flag_decode(VVCLocalContext *lc)
Definition: cabac.c:1013
Mv
Definition: hevcdec.h:305
merge_data_block
static void merge_data_block(VVCLocalContext *lc)
Definition: ctu.c:1441
MvField::ref_idx
int8_t ref_idx[2]
refIdxL0, refIdxL1
Definition: hevcdec.h:312
set_tb_tab
static void set_tb_tab(uint8_t *tab, uint8_t v, const VVCFrameContext *fc, const TransformBlock *tb)
Definition: ctu.c:60
set_tb_size
static void set_tb_size(const VVCFrameContext *fc, const TransformBlock *tb)
Definition: ctu.c:43
PF_PLT
@ PF_PLT
Definition: ctu.h:228
lfnst_idx_decode
static int lfnst_idx_decode(VVCLocalContext *lc)
Definition: ctu.c:796
ff_vvc_mts_idx
int ff_vvc_mts_idx(VVCLocalContext *lc)
Definition: cabac.c:2546
ff_vvc_general_merge_flag
int ff_vvc_general_merge_flag(VVCLocalContext *lc)
Definition: cabac.c:1437
VVCFrameContext::ps
VVCFrameParamSets ps
Definition: dec.h:131
VVCSH::max_bt_size
uint8_t max_bt_size[2]
MaxBtSizeY, MaxBtSizeC.
Definition: ps.h:258
TAB_ISPMF
#define TAB_ISPMF(fc, x, y)
Definition: ctu.c:35
SINGLE_TREE
@ SINGLE_TREE
Definition: ctu.h:168
ff_vvc_intra_chroma_pred_mode
int ff_vvc_intra_chroma_pred_mode(VVCLocalContext *lc)
Definition: cabac.c:1378
scale
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition: intra.c:273
VVCSPS::r
const H266RawSPS * r
RefStruct reference.
Definition: ps.h:59
PredFlag
PredFlag
Definition: hevcdec.h:119
H266RawSliceHeader::sh_num_alf_aps_ids_luma
uint8_t sh_num_alf_aps_ids_luma
Definition: cbs_h266.h:784
SliceContext::sh
VVCSH sh
Definition: dec.h:115
ff_vvc_tu_cr_coded_flag
int ff_vvc_tu_cr_coded_flag(VVCLocalContext *lc, int tu_cb_coded_flag)
Definition: cabac.c:1692
ff_vvc_alf_ctb_cc_idc
int ff_vvc_alf_ctb_cc_idc(VVCLocalContext *lc, const int rx, const int ry, const int idx, const int cc_filters_signalled)
Definition: cabac.c:1093
CodingUnit::isp_split_type
enum IspType isp_split_type
IntraSubPartitionsSplitType.
Definition: ctu.h:315
VVCFrameContext
Definition: dec.h:122
coding_tree_fn
int(* coding_tree_fn)(VVCLocalContext *lc, int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c, int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset, VVCTreeType tree_type, VVCModeType mode_type)
Definition: ctu.c:2413
ff_vvc_intra_luma_mpm_flag
int ff_vvc_intra_luma_mpm_flag(VVCLocalContext *lc)
Definition: cabac.c:1343
CodingUnit::mip_chroma_direct_flag
int mip_chroma_direct_flag
MipChromaDirectFlag.
Definition: ctu.h:323
Palette
Definition: flashsv2enc.c:83
ALFParams::ctb_flag
uint8_t ctb_flag[3]
alf_ctb_flag[]
Definition: ctu.h:473
MvField::bcw_idx
uint8_t bcw_idx
bcwIdx
Definition: ctu.h:206
ff_vvc_sao_offset_abs_decode
int ff_vvc_sao_offset_abs_decode(VVCLocalContext *lc)
Definition: cabac.c:1033
int32_t
int32_t
Definition: audioconvert.c:56
CodingUnit::skip_flag
uint8_t skip_flag
cu_skip_flag;
Definition: ctu.h:309
IS_I
#define IS_I(rsh)
Definition: ps.h:38
ff_vvc_mmvd_cand_flag
int ff_vvc_mmvd_cand_flag(VVCLocalContext *lc)
Definition: cabac.c:1480
ff_vvc_store_mvf
void ff_vvc_store_mvf(const VVCLocalContext *lc, const MvField *mvf)
Definition: mvs.c:502
SET_SAO
#define SET_SAO(elem, value)
Definition: ctu.c:2531
coeff
static const double coeff[2][5]
Definition: vf_owdenoise.c:80
VVCSH::min_qt_size
uint8_t min_qt_size[2]
MinQtSizeY, MinQtSizeC.
Definition: ps.h:257
mvds_decode
static int mvds_decode(VVCLocalContext *lc, Mv mvds[2][MAX_CONTROL_POINTS], const int num_cp_mv, const int lx)
Definition: ctu.c:1574
ff_vvc_amvr_shift
int ff_vvc_amvr_shift(VVCLocalContext *lc, const int inter_affine_flag, const PredMode pred_mode, const int has_amvr_flag)
Definition: cabac.c:1653
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
TransformUnit::joint_cbcr_residual_flag
uint8_t joint_cbcr_residual_flag
tu_joint_cbcr_residual_flag
Definition: ctu.h:180
ff_vvc_intra_bdpcm_luma_dir_flag
int ff_vvc_intra_bdpcm_luma_dir_flag(VVCLocalContext *lc)
Definition: cabac.c:1258
ff_vvc_intra_bdpcm_luma_flag
int ff_vvc_intra_bdpcm_luma_flag(VVCLocalContext *lc)
Definition: cabac.c:1253
h
h
Definition: vp9dsp_template.c:2070
ctu.h
BOUNDARY_LEFT_SLICE
#define BOUNDARY_LEFT_SLICE
Definition: hevcdec.h:441
VVCLocalContext::ep
EntryPoint * ep
Definition: ctu.h:447
width
#define width
Definition: dsp.h:89
transpose
#define transpose(x)
set_qp_c_tab
static void set_qp_c_tab(const VVCLocalContext *lc, const TransformUnit *tu, const TransformBlock *tb)
Definition: ctu.c:177
VVCLocalContext::cu_qg_top_left_y
int cu_qg_top_left_y
CuQgTopLeftY.
Definition: ctu.h:408
ff_vvc_ep_init_stat_coeff
void ff_vvc_ep_init_stat_coeff(EntryPoint *ep, const int bit_depth, const int persistent_rice_adaptation_enabled_flag)
Definition: ctu.c:2897
INTRA_LT_CCLM
@ INTRA_LT_CCLM
Definition: ctu.h:239
H266RawSliceHeader::sh_alf_cr_enabled_flag
uint8_t sh_alf_cr_enabled_flag
Definition: cbs_h266.h:787
CodingUnit::ciip_flag
uint8_t ciip_flag
Definition: ctu.h:312
ff_vvc_non_inter_flag
int ff_vvc_non_inter_flag(VVCLocalContext *lc, const int x0, const int y0, const int ch_type)
Definition: cabac.c:1227
ff_vvc_cclm_mode_flag
int ff_vvc_cclm_mode_flag(VVCLocalContext *lc)
Definition: cabac.c:1366
palette_predicted
static int palette_predicted(VVCLocalContext *lc, const bool local_dual_tree, int start, int end, bool *predictor_reused, const int predictor_size, const int max_entries)
Definition: ctu.c:1849
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
PredictionUnit::merge_subblock_flag
uint8_t merge_subblock_flag
Definition: ctu.h:263
CHROMA_FORMAT_444
@ CHROMA_FORMAT_444
Definition: ps.h:55
max_pos
static const int32_t max_pos[4]
Size of the MP-MLQ fixed excitation codebooks.
Definition: g723_1dec.c:97
palette_subblock_data
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)
Definition: ctu.c:1980
has_inter_luma
static int has_inter_luma(const CodingUnit *cu)
Definition: ctu.c:2713
CodingUnit::num_intra_subpartitions
int num_intra_subpartitions
Definition: ctu.h:319
VVCLocalContext::ctb_left_flag
uint8_t ctb_left_flag
Definition: ctu.h:385
ff_vvc_mv_scale
void ff_vvc_mv_scale(Mv *dst, const Mv *src, int td, int tb)
Definition: mvs.c:71
MtsIdx
MtsIdx
Definition: ctu.h:134
MIN_TU_LOG2
#define MIN_TU_LOG2
MinTbLog2SizeY.
Definition: dec.h:41
VVCLocalContext::is_cu_chroma_qp_offset_coded
int is_cu_chroma_qp_offset_coded
IsCuChromaQpOffsetCoded.
Definition: ctu.h:409
VVCLocalContext::is_cu_qp_delta_coded
uint8_t is_cu_qp_delta_coded
IsCuQpDeltaCoded.
Definition: ctu.h:406
merge_data_gpm
static void merge_data_gpm(VVCLocalContext *lc)
Definition: ctu.c:1402
CodingUnit::y0
int y0
Definition: ctu.h:290
CodingUnit::qp
int8_t qp[4]
QpY, Qp′Cb, Qp′Cr, Qp′CbCr.
Definition: ctu.h:334
ff_vvc_intra_bdpcm_chroma_flag
int ff_vvc_intra_bdpcm_chroma_flag(VVCLocalContext *lc)
Definition: cabac.c:1263
ff_vvc_copy_above_palette_indices_flag
bool ff_vvc_copy_above_palette_indices_flag(VVCLocalContext *lc)
Definition: cabac.c:1422
CHROMA_FORMAT_420
@ CHROMA_FORMAT_420
Definition: ps.h:53
VVCFrameContext::tab
struct VVCFrameContext::@325 tab
ff_vvc_ctu_free_cus
void ff_vvc_ctu_free_cus(CodingUnit **cus)
Definition: ctu.c:2870