FFmpeg
vvc_intra.c
Go to the documentation of this file.
1 /*
2  * VVC intra prediction
3  *
4  * Copyright (C) 2021 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 #include "libavutil/frame.h"
23 #include "libavutil/imgutils.h"
24 
25 #include "vvc_data.h"
26 #include "vvc_inter.h"
27 #include "vvc_intra.h"
28 #include "vvc_itx_1d.h"
29 
30 static int is_cclm(enum IntraPredMode mode)
31 {
32  return mode == INTRA_LT_CCLM || mode == INTRA_L_CCLM || mode == INTRA_T_CCLM;
33 }
34 
36 {
37  const VVCFrameContext *fc = lc->fc;
38  const VVCSPS *sps = fc->ps.sps;
39  const CodingUnit *cu = lc->cu;
40  const int x_tb = tb->x0 >> fc->ps.sps->min_cb_log2_size_y;
41  const int y_tb = tb->y0 >> fc->ps.sps->min_cb_log2_size_y;
42  const int x_c = (tb->x0 + (tb->tb_width << sps->hshift[1] >> 1) ) >> fc->ps.sps->min_cb_log2_size_y;
43  const int y_c = (tb->y0 + (tb->tb_height << sps->vshift[1] >> 1)) >> fc->ps.sps->min_cb_log2_size_y;
44  const int min_cb_width = fc->ps.pps->min_cb_width;
45  const int intra_mip_flag = SAMPLE_CTB(fc->tab.imf, x_tb, y_tb);
46  int pred_mode_intra = tb->c_idx == 0 ? cu->intra_pred_mode_y : cu->intra_pred_mode_c;
47  if (intra_mip_flag && !tb->c_idx) {
48  pred_mode_intra = INTRA_PLANAR;
49  } else if (is_cclm(pred_mode_intra)) {
50  int intra_mip_flag_c = SAMPLE_CTB(fc->tab.imf, x_c, y_c);
51  int cu_pred_mode = SAMPLE_CTB(fc->tab.cpm[0], x_c, y_c);
52  if (intra_mip_flag_c) {
53  pred_mode_intra = INTRA_PLANAR;
54  } else if (cu_pred_mode == MODE_IBC || cu_pred_mode == MODE_PLT) {
55  pred_mode_intra = INTRA_DC;
56  } else {
57  pred_mode_intra = SAMPLE_CTB(fc->tab.ipm, x_c, y_c);
58  }
59  }
60  pred_mode_intra = ff_vvc_wide_angle_mode_mapping(cu, tb->tb_width, tb->tb_height, tb->c_idx, pred_mode_intra);
61 
62  return pred_mode_intra;
63 }
64 
65 //8.7.4 Transformation process for scaled transform coefficients
67 {
68  const VVCSPS *sps = lc->fc->ps.sps;
69  const CodingUnit *cu = lc->cu;
70  const int w = tb->tb_width;
71  const int h = tb->tb_height;
72  const int n_lfnst_out_size = (w >= 8 && h >= 8) ? 48 : 16; ///< nLfnstOutSize
73  const int log2_lfnst_size = (w >= 8 && h >= 8) ? 3 : 2; ///< log2LfnstSize
74  const int n_lfnst_size = 1 << log2_lfnst_size; ///< nLfnstSize
75  const int non_zero_size = ((w == 8 && h == 8) || (w == 4 && h == 4)) ? 8 : 16; ///< nonZeroSize
76  const int pred_mode_intra = derive_ilfnst_pred_mode_intra(lc, tb);
77  const int transpose = pred_mode_intra > 34;
78  int u[16], v[48];
79 
80  for (int x = 0; x < non_zero_size; x++) {
81  int xc = ff_vvc_diag_scan_x[2][2][x];
82  int yc = ff_vvc_diag_scan_y[2][2][x];
83  u[x] = tb->coeffs[w * yc + xc];
84  }
85  ff_vvc_inv_lfnst_1d(v, u, non_zero_size, n_lfnst_out_size, pred_mode_intra,
86  cu->lfnst_idx, sps->log2_transform_range);
87  if (transpose) {
88  int *dst = tb->coeffs;
89  const int *src = v;
90  if (n_lfnst_size == 4) {
91  for (int y = 0; y < 4; y++) {
92  dst[0] = src[0];
93  dst[1] = src[4];
94  dst[2] = src[8];
95  dst[3] = src[12];
96  src++;
97  dst += w;
98  }
99  } else {
100  for (int y = 0; y < 8; y++) {
101  dst[0] = src[0];
102  dst[1] = src[8];
103  dst[2] = src[16];
104  dst[3] = src[24];
105  if (y < 4) {
106  dst[4] = src[32];
107  dst[5] = src[36];
108  dst[6] = src[40];
109  dst[7] = src[44];
110  }
111  src++;
112  dst += w;
113  }
114  }
115 
116  } else {
117  int *dst = tb->coeffs;
118  const int *src = v;
119  for (int y = 0; y < n_lfnst_size; y++) {
120  int size = (y < 4) ? n_lfnst_size : 4;
121  memcpy(dst, src, size * sizeof(int));
122  src += size;
123  dst += w;
124  }
125  }
126  tb->max_scan_x = n_lfnst_size - 1;
127  tb->max_scan_y = n_lfnst_size - 1;
128 }
129 
130 //part of 8.7.4 Transformation process for scaled transform coefficients
131 static void derive_transform_type(const VVCFrameContext *fc, const VVCLocalContext *lc, const TransformBlock *tb, enum TxType *trh, enum TxType *trv)
132 {
133  const CodingUnit *cu = lc->cu;
134  static const enum TxType mts_to_trh[] = {DCT2, DST7, DCT8, DST7, DCT8};
135  static const enum TxType mts_to_trv[] = {DCT2, DST7, DST7, DCT8, DCT8};
136  const VVCSPS *sps = fc->ps.sps;
137  int implicit_mts_enabled = 0;
138  if (tb->c_idx || (cu->isp_split_type != ISP_NO_SPLIT && cu->lfnst_idx)) {
139  *trh = *trv = DCT2;
140  return;
141  }
142 
143  if (sps->r->sps_mts_enabled_flag) {
144  if (cu->isp_split_type != ISP_NO_SPLIT ||
145  (cu->sbt_flag && FFMAX(tb->tb_width, tb->tb_height) <= 32) ||
146  (!sps->r->sps_explicit_mts_intra_enabled_flag && cu->pred_mode == MODE_INTRA &&
147  !cu->lfnst_idx && !cu->intra_mip_flag)) {
148  implicit_mts_enabled = 1;
149  }
150  }
151  if (implicit_mts_enabled) {
152  const int w = tb->tb_width;
153  const int h = tb->tb_height;
154  if (cu->sbt_flag) {
155  *trh = (cu->sbt_horizontal_flag || cu->sbt_pos_flag) ? DST7 : DCT8;
156  *trv = (!cu->sbt_horizontal_flag || cu->sbt_pos_flag) ? DST7 : DCT8;
157  } else {
158  *trh = (w >= 4 && w <= 16) ? DST7 : DCT2;
159  *trv = (h >= 4 && h <= 16) ? DST7 : DCT2;
160  }
161  return;
162  }
163  *trh = mts_to_trh[cu->mts_idx];
164  *trv = mts_to_trv[cu->mts_idx];
165 }
166 
168  const TransformUnit *tu, TransformBlock *tb, const int chroma_scale)
169 {
170  const VVCFrameContext *fc = lc->fc;
171  const CodingUnit *cu = lc->cu;
172  const int c_sign = 1 - 2 * fc->ps.ph.r->ph_joint_cbcr_sign_flag;
173  const int shift = tu->coded_flag[1] ^ tu->coded_flag[2];
174  const int c_idx = 1 + tu->coded_flag[1];
175  const ptrdiff_t stride = fc->frame->linesize[c_idx];
176  const int hs = fc->ps.sps->hshift[c_idx];
177  const int vs = fc->ps.sps->vshift[c_idx];
178  uint8_t *dst = &fc->frame->data[c_idx][(tb->y0 >> vs) * stride +
179  ((tb->x0 >> hs) << fc->ps.sps->pixel_shift)];
180  if (chroma_scale) {
181  fc->vvcdsp.itx.pred_residual_joint(tb->coeffs, tb->tb_width, tb->tb_height, c_sign, shift);
182  fc->vvcdsp.intra.lmcs_scale_chroma(lc, tb->coeffs, tb->coeffs, tb->tb_width, tb->tb_height, cu->x0, cu->y0);
183  fc->vvcdsp.itx.add_residual(dst, tb->coeffs, tb->tb_width, tb->tb_height, stride);
184  } else {
185  fc->vvcdsp.itx.add_residual_joint(dst, tb->coeffs, tb->tb_width, tb->tb_height, stride, c_sign, shift);
186  }
187 }
188 
189 static int add_reconstructed_area(VVCLocalContext *lc, const int ch_type, const int x0, const int y0, const int w, const int h)
190 {
191  const VVCSPS *sps = lc->fc->ps.sps;
192  const int hs = sps->hshift[ch_type];
193  const int vs = sps->vshift[ch_type];
195 
196  if (lc->num_ras[ch_type] >= FF_ARRAY_ELEMS(lc->ras[ch_type]))
197  return AVERROR_INVALIDDATA;
198 
199  a = &lc->ras[ch_type][lc->num_ras[ch_type]];
200  a->x = x0 >> hs;
201  a->y = y0 >> vs;
202  a->w = w >> hs;
203  a->h = h >> vs;
204  lc->num_ras[ch_type]++;
205 
206  return 0;
207 }
208 
209 static void add_tu_area(const TransformUnit *tu, int *x0, int *y0, int *w, int *h)
210 {
211  *x0 = tu->x0;
212  *y0 = tu->y0;
213  *w = tu->width;
214  *h = tu->height;
215 }
216 
217 #define MIN_ISP_PRED_WIDTH 4
218 static int get_luma_predict_unit(const CodingUnit *cu, const TransformUnit *tu, const int idx, int *x0, int *y0, int *w, int *h)
219 {
220  int has_luma = 1;
221  add_tu_area(tu, x0, y0, w, h);
224  has_luma = !(idx % (MIN_ISP_PRED_WIDTH / tu->width));
225  }
226  return has_luma;
227 }
228 
229 static int get_chroma_predict_unit(const CodingUnit *cu, const TransformUnit *tu, const int idx, int *x0, int *y0, int *w, int *h)
230 {
231  if (cu->isp_split_type == ISP_NO_SPLIT) {
232  add_tu_area(tu, x0, y0, w, h);
233  return 1;
234  }
235  if (idx == cu->num_intra_subpartitions - 1) {
236  *x0 = cu->x0;
237  *y0 = cu->y0;
238  *w = cu->cb_width;
239  *h = cu->cb_height;
240  return 1;
241  }
242  return 0;
243 }
244 
245 //8.4.5.1 General decoding process for intra blocks
246 static void predict_intra(VVCLocalContext *lc, const TransformUnit *tu, const int idx, const int target_ch_type)
247 {
248  const VVCFrameContext *fc = lc->fc;
249  const CodingUnit *cu = lc->cu;
250  const VVCTreeType tree_type = cu->tree_type;
251  int x0, y0, w, h;
252  if (cu->pred_mode != MODE_INTRA) {
253  add_reconstructed_area(lc, target_ch_type, tu->x0, tu->y0, tu->width, tu->height);
254  return;
255  }
256  if (!target_ch_type && tree_type != DUAL_TREE_CHROMA) {
257  if (get_luma_predict_unit(cu, tu, idx, &x0, &y0, &w, &h)) {
258  ff_vvc_set_neighbour_available(lc, x0, y0, w, h);
259  fc->vvcdsp.intra.intra_pred(lc, x0, y0, w, h, 0);
260  add_reconstructed_area(lc, 0, x0, y0, w, h);
261  }
262  }
263  if (target_ch_type && tree_type != DUAL_TREE_LUMA) {
264  if (get_chroma_predict_unit(cu, tu, idx, &x0, &y0, &w, &h)){
265  ff_vvc_set_neighbour_available(lc, x0, y0, w, h);
266  if (is_cclm(cu->intra_pred_mode_c)) {
267  fc->vvcdsp.intra.intra_cclm_pred(lc, x0, y0, w, h);
268  } else {
269  fc->vvcdsp.intra.intra_pred(lc, x0, y0, w, h, 1);
270  fc->vvcdsp.intra.intra_pred(lc, x0, y0, w, h, 2);
271  }
272  add_reconstructed_area(lc, 1, x0, y0, w, h);
273  }
274  }
275 }
276 
277 static void scale_clip(int *coeff, const int nzw, const int w, const int h,
278  const int shift, const int log2_transform_range)
279 {
280  const int add = 1 << (shift - 1);
281  for (int y = 0; y < h; y++) {
282  int *p = coeff + y * w;
283  for (int x = 0; x < nzw; x++) {
284  *p = av_clip_intp2((*p + add) >> shift, log2_transform_range);
285  p++;
286  }
287  memset(p, 0, sizeof(*p) * (w - nzw));
288  }
289 }
290 
291 static void scale(int *out, const int *in, const int w, const int h, const int shift)
292 {
293  const int add = 1 << (shift - 1);
294  for (int y = 0; y < h; y++) {
295  for (int x = 0; x < w; x++) {
296  int *o = out + y * w + x;
297  const int *i = in + y * w + x;
298  *o = (*i + add) >> shift;
299  }
300  }
301 }
302 
303 // part of 8.7.3 Scaling process for transform coefficients
304 static void derive_qp(const VVCLocalContext *lc, const TransformUnit *tu, TransformBlock *tb)
305 {
306  const VVCSPS *sps = lc->fc->ps.sps;
307  const H266RawSliceHeader *rsh = lc->sc->sh.r;
308  const CodingUnit *cu = lc->cu;
309  int qp, qp_act_offset;
310 
311  if (tb->c_idx == 0) {
312  //fix me
313  qp = cu->qp[LUMA] + sps->qp_bd_offset;
314  qp_act_offset = cu->act_enabled_flag ? -5 : 0;
315  } else {
316  const int is_jcbcr = tu->joint_cbcr_residual_flag && tu->coded_flag[CB] && tu->coded_flag[CR];
317  const int idx = is_jcbcr ? JCBCR : tb->c_idx;
318  qp = cu->qp[idx];
319  qp_act_offset = cu->act_enabled_flag ? 1 : 0;
320  }
321  if (tb->ts) {
322  const int qp_prime_ts_min = 4 + 6 * sps->r->sps_min_qp_prime_ts;
323 
324  tb->qp = av_clip(qp + qp_act_offset, qp_prime_ts_min, 63 + sps->qp_bd_offset);
325  tb->rect_non_ts_flag = 0;
326  tb->bd_shift = 10;
327  } else {
328  const int log_sum = tb->log2_tb_width + tb->log2_tb_height;
329  const int rect_non_ts_flag = log_sum & 1;
330 
331  tb->qp = av_clip(qp + qp_act_offset, 0, 63 + sps->qp_bd_offset);
332  tb->rect_non_ts_flag = rect_non_ts_flag;
333  tb->bd_shift = sps->bit_depth + rect_non_ts_flag + (log_sum / 2)
334  + 10 - sps->log2_transform_range + rsh->sh_dep_quant_used_flag;
335  }
336  tb->bd_offset = (1 << tb->bd_shift) >> 1;
337 }
338 
339 //8.7.3 Scaling process for transform coefficients
340 static av_always_inline int derive_scale(const TransformBlock *tb, const int sh_dep_quant_used_flag)
341 {
342  static const uint8_t rem6[63 + 2 * 6 + 1] = {
343  0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2,
344  3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5,
345  0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3,
346  4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3
347  };
348 
349  static const uint8_t div6[63 + 2 * 6 + 1] = {
350  0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3,
351  3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6,
352  7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10,
353  10, 10, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12
354  };
355 
356  const static int level_scale[2][6] = {
357  { 40, 45, 51, 57, 64, 72 },
358  { 57, 64, 72, 80, 90, 102 }
359  };
360  const int addin = sh_dep_quant_used_flag && !tb->ts;
361  const int qp = tb->qp + addin;
362 
363  return level_scale[tb->rect_non_ts_flag][rem6[qp]] << div6[qp];
364 }
365 
366 //8.7.3 Scaling process for transform coefficients
367 static const uint8_t* derive_scale_m(const VVCLocalContext *lc, const TransformBlock *tb, uint8_t *scale_m)
368 {
369  //Table 38 – Specification of the scaling matrix identifier variable id according to predMode, cIdx, nTbW, and nTbH
370  const int ids[2][3][6] = {
371  {
372  { 0, 2, 8, 14, 20, 26 },
373  { 0, 3, 9, 15, 21, 21 },
374  { 0, 4, 10, 16, 22, 22 }
375  },
376  {
377  { 0, 5, 11, 17, 23, 27 },
378  { 0, 6, 12, 18, 24, 24 },
379  { 1, 7, 13, 19, 25, 25 },
380  }
381  };
382  const VVCFrameParamSets *ps = &lc->fc->ps;
383  const VVCSPS *sps = ps->sps;
384  const H266RawSliceHeader *rsh = lc->sc->sh.r;
385  const CodingUnit *cu = lc->cu;
386  const VVCScalingList *sl = ps->sl;
387  const int id = ids[cu->pred_mode != MODE_INTRA][tb->c_idx][FFMAX(tb->log2_tb_height, tb->log2_tb_width) - 1];
388  const int log2_matrix_size = (id < 2) ? 1 : (id < 8) ? 2 : 3;
389  uint8_t *p = scale_m;
390 
391  av_assert0(!sps->r->sps_scaling_matrix_for_alternative_colour_space_disabled_flag);
392 
393  if (!rsh->sh_explicit_scaling_list_used_flag || tb->ts ||
394  sps->r->sps_scaling_matrix_for_lfnst_disabled_flag && cu->apply_lfnst_flag[tb->c_idx])
395  return ff_vvc_default_scale_m;
396 
397  if (!sl) {
398  av_log(lc->fc->log_ctx, AV_LOG_WARNING, "bug: no scaling list aps, id = %d", ps->ph.r->ph_scaling_list_aps_id);
399  return ff_vvc_default_scale_m;
400  }
401 
402  for (int y = tb->min_scan_y; y <= tb->max_scan_y; y++) {
403  const int off = y << log2_matrix_size >> tb->log2_tb_height << log2_matrix_size;
404  const uint8_t *m = &sl->scaling_matrix_rec[id][off];
405 
406  for (int x = tb->min_scan_x; x <= tb->max_scan_x; x++)
407  *p++ = m[x << log2_matrix_size >> tb->log2_tb_width];
408  }
409  if (id >= SL_START_16x16 && !tb->min_scan_x && !tb->min_scan_y)
410  *scale_m = sl->scaling_matrix_dc_rec[id - SL_START_16x16];
411 
412  return scale_m;
413 }
414 
415 //8.7.3 Scaling process for transform coefficients
417  const int scale, const int scale_m, const int log2_transform_range)
418 {
419  coeff = (coeff * scale * scale_m + tb->bd_offset) >> tb->bd_shift;
420  coeff = av_clip_intp2(coeff, log2_transform_range);
421  return coeff;
422 }
423 
424 static void dequant(const VVCLocalContext *lc, const TransformUnit *tu, TransformBlock *tb)
425 {
426  uint8_t tmp[MAX_TB_SIZE * MAX_TB_SIZE];
427  const H266RawSliceHeader *rsh = lc->sc->sh.r;
428  const VVCSPS *sps = lc->fc->ps.sps;
429  const uint8_t *scale_m = derive_scale_m(lc, tb, tmp);
430  int scale;
431 
432  derive_qp(lc, tu, tb);
434 
435  for (int y = tb->min_scan_y; y <= tb->max_scan_y; y++) {
436  for (int x = tb->min_scan_x; x <= tb->max_scan_x; x++) {
437  int *coeff = tb->coeffs + y * tb->tb_width + x;
438 
439  if (*coeff)
440  *coeff = scale_coeff(tb, *coeff, scale, *scale_m, sps->log2_transform_range);
441  scale_m++;
442  }
443  }
444 }
445 
446 //transmatrix[0][0]
447 #define DCT_A 64
448 static void itx_2d(const VVCFrameContext *fc, TransformBlock *tb, const enum TxType trh, const enum TxType trv)
449 {
450  const VVCSPS *sps = fc->ps.sps;
451  const int w = tb->tb_width;
452  const int h = tb->tb_height;
453  const size_t nzw = tb->max_scan_x + 1;
454  const size_t nzh = tb->max_scan_y + 1;
455  const int shift[] = { 7, 5 + sps->log2_transform_range - sps->bit_depth };
456 
457  if (w == h && nzw == 1 && nzh == 1 && trh == DCT2 && trv == DCT2) {
458  const int add[] = { 1 << (shift[0] - 1), 1 << (shift[1] - 1) };
459  const int t = (tb->coeffs[0] * DCT_A + add[0]) >> shift[0];
460  const int dc = (t * DCT_A + add[1]) >> shift[1];
461 
462  for (int i = 0; i < w * h; i++)
463  tb->coeffs[i] = dc;
464 
465  return;
466  }
467 
468  for (int x = 0; x < nzw; x++)
469  fc->vvcdsp.itx.itx[trv][tb->log2_tb_height - 1](tb->coeffs + x, w, nzh);
470  scale_clip(tb->coeffs, nzw, w, h, shift[0], sps->log2_transform_range);
471 
472  for (int y = 0; y < h; y++)
473  fc->vvcdsp.itx.itx[trh][tb->log2_tb_width - 1](tb->coeffs + y * w, 1, nzw);
474  scale(tb->coeffs, tb->coeffs, w, h, shift[1]);
475 }
476 
477 static void itx_1d(const VVCFrameContext *fc, TransformBlock *tb, const enum TxType trh, const enum TxType trv)
478 {
479  const VVCSPS *sps = fc->ps.sps;
480  const int w = tb->tb_width;
481  const int h = tb->tb_height;
482  const size_t nzw = tb->max_scan_x + 1;
483  const size_t nzh = tb->max_scan_y + 1;
484 
485  if ((w > 1 && nzw == 1 && trh == DCT2) || (h > 1 && nzh == 1 && trv == DCT2)) {
486  const int shift = 6 + sps->log2_transform_range - sps->bit_depth;
487  const int add = 1 << (shift - 1);
488  const int dc = (tb->coeffs[0] * DCT_A + add) >> shift;
489 
490  for (int i = 0; i < w * h; i++)
491  tb->coeffs[i] = dc;
492 
493  return;
494  }
495 
496  if (w > 1)
497  fc->vvcdsp.itx.itx[trh][tb->log2_tb_width - 1](tb->coeffs, 1, nzw);
498  else
499  fc->vvcdsp.itx.itx[trv][tb->log2_tb_height - 1](tb->coeffs, 1, nzh);
500  scale(tb->coeffs, tb->coeffs, w, h, 6 + sps->log2_transform_range - sps->bit_depth);
501 }
502 
503 static void transform_bdpcm(TransformBlock *tb, const VVCLocalContext *lc, const CodingUnit *cu)
504 {
505  const VVCSPS *sps = lc->fc->ps.sps;
506  const IntraPredMode mode = tb->c_idx ? cu->intra_pred_mode_c : cu->intra_pred_mode_y;
507  const int vertical = mode == INTRA_VERT;
508  lc->fc->vvcdsp.itx.transform_bdpcm(tb->coeffs, tb->tb_width, tb->tb_height,
509  vertical, sps->log2_transform_range);
510  if (vertical)
511  tb->max_scan_y = tb->tb_height - 1;
512  else
513  tb->max_scan_x = tb->tb_width - 1;
514 }
515 
516 static void itransform(VVCLocalContext *lc, TransformUnit *tu, const int tu_idx, const int target_ch_type)
517 {
518  const VVCFrameContext *fc = lc->fc;
519  const VVCSPS *sps = fc->ps.sps;
520  const VVCSH *sh = &lc->sc->sh;
521  const CodingUnit *cu = lc->cu;
522  const int ps = fc->ps.sps->pixel_shift;
524 
525  for (int i = 0; i < tu->nb_tbs; i++) {
526  TransformBlock *tb = &tu->tbs[i];
527  const int c_idx = tb->c_idx;
528  const int ch_type = c_idx > 0;
529 
530  if (ch_type == target_ch_type && tb->has_coeffs) {
531  const int w = tb->tb_width;
532  const int h = tb->tb_height;
533  const int chroma_scale = ch_type && sh->r->sh_lmcs_used_flag && fc->ps.ph.r->ph_chroma_residual_scale_flag && (w * h > 4);
534  const ptrdiff_t stride = fc->frame->linesize[c_idx];
535  const int hs = sps->hshift[c_idx];
536  const int vs = sps->vshift[c_idx];
537  uint8_t *dst = &fc->frame->data[c_idx][(tb->y0 >> vs) * stride + ((tb->x0 >> hs) << ps)];
538 
539  if (cu->bdpcm_flag[tb->c_idx])
540  transform_bdpcm(tb, lc, cu);
541  dequant(lc, tu, tb);
542  if (!tb->ts) {
543  enum TxType trh, trv;
544 
545  if (cu->apply_lfnst_flag[c_idx])
546  ilfnst_transform(lc, tb);
547  derive_transform_type(fc, lc, tb, &trh, &trv);
548  if (w > 1 && h > 1)
549  itx_2d(fc, tb, trh, trv);
550  else
551  itx_1d(fc, tb, trh, trv);
552  }
553 
554  if (chroma_scale)
555  fc->vvcdsp.intra.lmcs_scale_chroma(lc, temp, tb->coeffs, w, h, cu->x0, cu->y0);
556  // TODO: Address performance issue here by combining transform, lmcs_scale_chroma, and add_residual into one function.
557  // Complete this task before implementing ASM code.
558  fc->vvcdsp.itx.add_residual(dst, chroma_scale ? temp : tb->coeffs, w, h, stride);
559 
560  if (tu->joint_cbcr_residual_flag && tb->c_idx)
561  add_residual_for_joint_coding_chroma(lc, tu, tb, chroma_scale);
562  }
563  }
564 }
565 
567 {
568  VVCFrameContext *fc = lc->fc;
569  CodingUnit *cu = lc->cu;
570  const int start = cu->tree_type == DUAL_TREE_CHROMA;
571  const int end = fc->ps.sps->r->sps_chroma_format_idc && (cu->tree_type != DUAL_TREE_LUMA);
572 
573  for (int ch_type = start; ch_type <= end; ch_type++) {
574  TransformUnit *tu = cu->tus.head;
575  for (int i = 0; tu; i++) {
576  predict_intra(lc, tu, i, ch_type);
577  itransform(lc, tu, i, ch_type);
578  tu = tu->next;
579  }
580  }
581  return 0;
582 }
583 
584 #define POS(c_idx, x, y) \
585  &fc->frame->data[c_idx][((y) >> fc->ps.sps->vshift[c_idx]) * fc->frame->linesize[c_idx] + \
586  (((x) >> fc->ps.sps->hshift[c_idx]) << fc->ps.sps->pixel_shift)]
587 
588 #define IBC_POS(c_idx, x, y) \
589  (fc->tab.ibc_vir_buf[c_idx] + \
590  (x << ps) + (y + ((cu->y0 & ~(sps->ctb_size_y - 1)) >> vs)) * ibc_stride)
591 #define IBC_X(x) ((x) & ((fc->tab.sz.ibc_buffer_width >> hs) - 1))
592 #define IBC_Y(y) ((y) & ((1 << sps->ctb_log2_size_y >> vs) - 1))
593 
594 static void intra_block_copy(const VVCLocalContext *lc, const int c_idx)
595 {
596  const CodingUnit *cu = lc->cu;
597  const PredictionUnit *pu = &cu->pu;
598  const VVCFrameContext *fc = lc->fc;
599  const VVCSPS *sps = fc->ps.sps;
600  const Mv *bv = &pu->mi.mv[L0][0];
601  const int hs = sps->hshift[c_idx];
602  const int vs = sps->vshift[c_idx];
603  const int ps = sps->pixel_shift;
604  const int ref_x = IBC_X((cu->x0 >> hs) + (bv->x >> (4 + hs)));
605  const int ref_y = IBC_Y((cu->y0 >> vs) + (bv->y >> (4 + vs)));
606  const int w = cu->cb_width >> hs;
607  const int h = cu->cb_height >> vs;
608  const int ibc_buf_width = fc->tab.sz.ibc_buffer_width >> hs; ///< IbcBufWidthY and IbcBufWidthC
609  const int rw = FFMIN(w, ibc_buf_width - ref_x);
610  const int ibc_stride = ibc_buf_width << ps;
611  const int dst_stride = fc->frame->linesize[c_idx];
612  const uint8_t *ibc_buf = IBC_POS(c_idx, ref_x, ref_y);
613  uint8_t *dst = POS(c_idx, cu->x0, cu->y0);
614 
615  av_image_copy_plane(dst, dst_stride, ibc_buf, ibc_stride, rw << ps, h);
616 
617  if (w > rw) {
618  //wrap around, left part
619  ibc_buf = IBC_POS(c_idx, 0, ref_y);
620  dst += rw << ps;
621  av_image_copy_plane(dst, dst_stride, ibc_buf, ibc_stride, (w - rw) << ps, h);
622  }
623 }
624 
625 static void vvc_predict_ibc(const VVCLocalContext *lc)
626 {
627  const H266RawSPS *rsps = lc->fc->ps.sps->r;
628 
629  intra_block_copy(lc, LUMA);
630  if (lc->cu->tree_type == SINGLE_TREE && rsps->sps_chroma_format_idc) {
631  intra_block_copy(lc, CB);
632  intra_block_copy(lc, CR);
633  }
634 }
635 
636 static void ibc_fill_vir_buf(const VVCLocalContext *lc, const CodingUnit *cu)
637 {
638  const VVCFrameContext *fc = lc->fc;
639  const VVCSPS *sps = fc->ps.sps;
640  const int has_chroma = sps->r->sps_chroma_format_idc && cu->tree_type != DUAL_TREE_LUMA;
641  const int start = cu->tree_type == DUAL_TREE_CHROMA;
642  const int end = has_chroma ? CR : LUMA;
643 
644  for (int c_idx = start; c_idx <= end; c_idx++) {
645  const int hs = sps->hshift[c_idx];
646  const int vs = sps->vshift[c_idx];
647  const int ps = sps->pixel_shift;
648  const int x = IBC_X(cu->x0 >> hs);
649  const int y = IBC_Y(cu->y0 >> vs);
650  const int src_stride = fc->frame->linesize[c_idx];
651  const int ibc_stride = fc->tab.sz.ibc_buffer_width >> hs << ps;
652  const uint8_t *src = POS(c_idx, cu->x0, cu->y0);
653  uint8_t *ibc_buf = IBC_POS(c_idx, x, y);
654 
655  av_image_copy_plane(ibc_buf, ibc_stride, src, src_stride, cu->cb_width >> hs << ps , cu->cb_height >> vs);
656  }
657 }
658 
659 int ff_vvc_reconstruct(VVCLocalContext *lc, const int rs, const int rx, const int ry)
660 {
661  const VVCFrameContext *fc = lc->fc;
662  const VVCSPS *sps = fc->ps.sps;
663  const int x_ctb = rx << sps->ctb_log2_size_y;
664  const int y_ctb = ry << sps->ctb_log2_size_y;
665  CTU *ctu = fc->tab.ctus + rs;
666  CodingUnit *cu = ctu->cus;
667  int ret = 0;
668 
669  lc->num_ras[0] = lc->num_ras[1] = 0;
670  lc->lmcs.x_vpdu = -1;
671  lc->lmcs.y_vpdu = -1;
672  ff_vvc_decode_neighbour(lc, x_ctb, y_ctb, rx, ry, rs);
673  while (cu) {
674  lc->cu = cu;
675 
676  if (cu->ciip_flag)
678  else if (cu->pred_mode == MODE_IBC)
679  vvc_predict_ibc(lc);
680  if (cu->coded_flag) {
681  ret = reconstruct(lc);
682  } else {
683  if (cu->tree_type != DUAL_TREE_CHROMA)
684  add_reconstructed_area(lc, LUMA, cu->x0, cu->y0, cu->cb_width, cu->cb_height);
685  if (sps->r->sps_chroma_format_idc && cu->tree_type != DUAL_TREE_LUMA)
686  add_reconstructed_area(lc, CHROMA, cu->x0, cu->y0, cu->cb_width, cu->cb_height);
687  }
688  if (sps->r->sps_ibc_enabled_flag)
689  ibc_fill_vir_buf(lc, cu);
690  cu = cu->next;
691  }
692  ff_vvc_ctu_free_cus(ctu);
693  return ret;
694 }
695 
CodingUnit::tus
struct CodingUnit::@220 tus
CB
#define CB
Definition: hevc_filter.c:32
VVCSPS
Definition: vvc_ps.h:58
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
transform_bdpcm
static void transform_bdpcm(TransformBlock *tb, const VVCLocalContext *lc, const CodingUnit *cu)
Definition: vvc_intra.c:503
DCT8
@ DCT8
Definition: vvcdsp.h:33
av_clip
#define av_clip
Definition: common.h:98
MotionInfo::mv
Mv mv[2][MAX_CONTROL_POINTS]
Definition: vvc_ctu.h:243
predict_intra
static void predict_intra(VVCLocalContext *lc, const TransformUnit *tu, const int idx, const int target_ch_type)
Definition: vvc_intra.c:246
H266RawSliceHeader::sh_explicit_scaling_list_used_flag
uint8_t sh_explicit_scaling_list_used_flag
Definition: cbs_h266.h:793
out
FILE * out
Definition: movenc.c:54
u
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:250
TransformUnit::height
int height
Definition: vvc_ctu.h:171
itx_2d
static void itx_2d(const VVCFrameContext *fc, TransformBlock *tb, const enum TxType trh, const enum TxType trv)
Definition: vvc_intra.c:448
dequant
static void dequant(const VVCLocalContext *lc, const TransformUnit *tu, TransformBlock *tb)
Definition: vvc_intra.c:424
CodingUnit
Definition: hevcdec.h:282
CodingUnit::act_enabled_flag
uint8_t act_enabled_flag
Definition: vvc_ctu.h:292
add_reconstructed_area
static int add_reconstructed_area(VVCLocalContext *lc, const int ch_type, const int x0, const int y0, const int w, const int h)
Definition: vvc_intra.c:189
CodingUnit::head
TransformUnit * head
RefStruct reference.
Definition: vvc_ctu.h:317
TransformUnit::nb_tbs
uint8_t nb_tbs
Definition: vvc_ctu.h:176
CodingUnit::bdpcm_flag
int bdpcm_flag[VVC_MAX_SAMPLE_ARRAYS]
BdpcmFlag.
Definition: vvc_ctu.h:312
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
w
uint8_t w
Definition: llviddspenc.c:38
CodingUnit::intra_mip_flag
uint8_t intra_mip_flag
intra_mip_flag
Definition: vvc_ctu.h:295
VVCLocalContext::sc
SliceContext * sc
Definition: vvc_ctu.h:430
INTRA_DC
@ INTRA_DC
Definition: hevcdec.h:121
Mv::y
int16_t y
vertical component of motion vector
Definition: hevcdec.h:297
TransformUnit::x0
int x0
Definition: vvc_ctu.h:168
INTRA_L_CCLM
@ INTRA_L_CCLM
Definition: vvc_ctu.h:232
VVCSH::r
const H266RawSliceHeader * r
RefStruct reference.
Definition: vvc_ps.h:225
TxType
TxType
Definition: vvcdsp.h:30
VVCDSPContext::itx
VVCItxDSPContext itx
Definition: vvcdsp.h:161
fc
#define fc(width, name, range_min, range_max)
Definition: cbs_av1.c:472
ReconstructedArea
Definition: vvc_ctu.h:335
add_residual_for_joint_coding_chroma
static void add_residual_for_joint_coding_chroma(VVCLocalContext *lc, const TransformUnit *tu, TransformBlock *tb, const int chroma_scale)
Definition: vvc_intra.c:167
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
ff_vvc_default_scale_m
uint8_t ff_vvc_default_scale_m[64 *64]
Definition: vvc_data.c:1641
VVCLocalContext::ras
ReconstructedArea ras[2][MAX_PARTS_IN_CTU]
Definition: vvc_ctu.h:417
av_image_copy_plane
void av_image_copy_plane(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int bytewidth, int height)
Copy image plane from src to dst.
Definition: imgutils.c:374
vvc_intra.h
derive_scale
static av_always_inline int derive_scale(const TransformBlock *tb, const int sh_dep_quant_used_flag)
Definition: vvc_intra.c:340
ff_vvc_wide_angle_mode_mapping
int ff_vvc_wide_angle_mode_mapping(const CodingUnit *cu, int tb_width, int tb_height, int c_idx, int pred_mode_intra)
Definition: vvc_intra_utils.c:197
VVCTreeType
VVCTreeType
Definition: vvc_ctu.h:161
VVCFrameParamSets::sps
const VVCSPS * sps
RefStruct reference.
Definition: vvc_ps.h:216
vvc_data.h
VVCFrameParamSets
Definition: vvc_ps.h:215
VVCLocalContext::fc
VVCFrameContext * fc
Definition: vvc_ctu.h:431
add_tu_area
static void add_tu_area(const TransformUnit *tu, int *x0, int *y0, int *w, int *h)
Definition: vvc_intra.c:209
PredictionUnit
Definition: hevcdec.h:315
CodingUnit::apply_lfnst_flag
int apply_lfnst_flag[VVC_MAX_SAMPLE_ARRAYS]
ApplyLfnstFlag[].
Definition: vvc_ctu.h:314
CodingUnit::sbt_pos_flag
uint8_t sbt_pos_flag
Definition: vvc_ctu.h:287
IBC_X
#define IBC_X(x)
Definition: vvc_intra.c:591
VVCFrameParamSets::sl
const VVCScalingList * sl
RefStruct reference.
Definition: vvc_ps.h:221
vvc_predict_ibc
static void vvc_predict_ibc(const VVCLocalContext *lc)
Definition: vvc_intra.c:625
derive_transform_type
static void derive_transform_type(const VVCFrameContext *fc, const VVCLocalContext *lc, const TransformBlock *tb, enum TxType *trh, enum TxType *trv)
Definition: vvc_intra.c:131
CodingUnit::cb_width
int cb_width
Definition: vvc_ctu.h:278
CodingUnit::pu
PredictionUnit pu
Definition: vvc_ctu.h:323
H266RawSPS::sps_chroma_format_idc
uint8_t sps_chroma_format_idc
Definition: cbs_h266.h:314
SINGLE_TREE
@ SINGLE_TREE
Definition: vvc_ctu.h:162
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
VVCLocalContext::lmcs
struct VVCLocalContext::@222 lmcs
derive_ilfnst_pred_mode_intra
static int derive_ilfnst_pred_mode_intra(const VVCLocalContext *lc, const TransformBlock *tb)
Definition: vvc_intra.c:35
TransformUnit::next
struct TransformUnit * next
RefStruct reference.
Definition: vvc_ctu.h:179
ff_vvc_diag_scan_y
const uint8_t ff_vvc_diag_scan_y[5][5][16 *16]
Definition: vvc_data.c:152
IBC_Y
#define IBC_Y(y)
Definition: vvc_intra.c:592
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
VVCSH
Definition: vvc_ps.h:224
ISP_NO_SPLIT
@ ISP_NO_SPLIT
Definition: vvc_ctu.h:114
CodingUnit::tree_type
VVCTreeType tree_type
Definition: vvc_ctu.h:275
VVCFrameParamSets::ph
VVCPH ph
Definition: vvc_ps.h:218
CodingUnit::mts_idx
MtsIdx mts_idx
Definition: vvc_ctu.h:290
ibc_fill_vir_buf
static void ibc_fill_vir_buf(const VVCLocalContext *lc, const CodingUnit *cu)
Definition: vvc_intra.c:636
TransformUnit::coded_flag
uint8_t coded_flag[VVC_MAX_SAMPLE_ARRAYS]
tu_y_coded_flag, tu_cb_coded_flag, tu_cr_coded_flag
Definition: vvc_ctu.h:175
intra_block_copy
static void intra_block_copy(const VVCLocalContext *lc, const int c_idx)
Definition: vvc_intra.c:594
VVCLocalContext::num_ras
int num_ras[2]
Definition: vvc_ctu.h:418
VVCFrameContext::log_ctx
void * log_ctx
Definition: vvcdec.h:93
H266RawSliceHeader::sh_lmcs_used_flag
uint8_t sh_lmcs_used_flag
Definition: cbs_h266.h:792
H266RawSPS
Definition: cbs_h266.h:308
itx_1d
static void itx_1d(const VVCFrameContext *fc, TransformBlock *tb, const enum TxType trh, const enum TxType trv)
Definition: vvc_intra.c:477
CTU
Definition: vvc_ctu.h:328
DCT2
@ DCT2
Definition: vvcdsp.h:31
CodingUnit::sbt_flag
uint8_t sbt_flag
Definition: vvc_ctu.h:285
av_clip_intp2
#define av_clip_intp2
Definition: common.h:119
ISP_VER_SPLIT
@ ISP_VER_SPLIT
Definition: vvc_ctu.h:116
VVCLocalContext
Definition: vvc_ctu.h:368
VVCFrameContext::vvcdsp
VVCDSPContext vvcdsp
Definition: vvcdec.h:109
H266RawSliceHeader::sh_dep_quant_used_flag
uint8_t sh_dep_quant_used_flag
Definition: cbs_h266.h:822
reconstruct
static int reconstruct(VVCLocalContext *lc)
Definition: vvc_intra.c:566
L0
#define L0
Definition: hevcdec.h:57
Mv::x
int16_t x
horizontal component of motion vector
Definition: hevcdec.h:296
VVCPH::r
const H266RawPictureHeader * r
Definition: vvc_ps.h:144
JCBCR
#define JCBCR
Definition: vvcdec.h:37
VVCItxDSPContext::transform_bdpcm
void(* transform_bdpcm)(int *coeffs, int width, int height, int vertical, int log2_transform_range)
Definition: vvcdsp.h:118
ff_vvc_ctu_free_cus
void ff_vvc_ctu_free_cus(CTU *ctu)
Definition: vvc_ctu.c:2516
SAMPLE_CTB
#define SAMPLE_CTB(tab, x, y)
Definition: hevcdec.h:73
TransformUnit
Definition: hevcdec.h:325
DUAL_TREE_CHROMA
@ DUAL_TREE_CHROMA
Definition: vvc_ctu.h:164
VVCScalingList
Definition: vvc_ps.h:185
ff_vvc_inv_lfnst_1d
void ff_vvc_inv_lfnst_1d(int *v, const int *u, int no_zero_size, int n_tr_s, int pred_mode_intra, int lfnst_idx, int log2_transform_range)
Definition: vvc_itx_1d.c:695
scale
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition: vvc_intra.c:291
dc
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled top and top right vectors is used as motion vector prediction the used motion vector is the sum of the predictor and(mvx_diff, mvy_diff) *mv_scale Intra DC Prediction block[y][x] dc[1]
Definition: snow.txt:400
CodingUnit::intra_pred_mode_y
IntraPredMode intra_pred_mode_y
IntraPredModeY.
Definition: vvc_ctu.h:308
DECLARE_ALIGNED
#define DECLARE_ALIGNED(n, t, v)
Definition: mem_internal.h:109
shift
static int shift(int a, int b)
Definition: bonk.c:262
INTRA_PLANAR
@ INTRA_PLANAR
Definition: hevcdec.h:120
derive_scale_m
static const uint8_t * derive_scale_m(const VVCLocalContext *lc, const TransformBlock *tb, uint8_t *scale_m)
Definition: vvc_intra.c:367
size
int size
Definition: twinvq_data.h:10344
CR
#define CR
Definition: hevc_filter.c:33
CodingUnit::sbt_horizontal_flag
uint8_t sbt_horizontal_flag
Definition: vvc_ctu.h:286
MIN_ISP_PRED_WIDTH
#define MIN_ISP_PRED_WIDTH
Definition: vvc_intra.c:217
H266RawPictureHeader::ph_scaling_list_aps_id
uint8_t ph_scaling_list_aps_id
Definition: cbs_h266.h:702
frame.h
CodingUnit::coded_flag
uint8_t coded_flag
Definition: vvc_ctu.h:283
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
CodingUnit::lfnst_idx
int lfnst_idx
Definition: vvc_ctu.h:289
VVCScalingList::scaling_matrix_dc_rec
uint8_t scaling_matrix_dc_rec[SL_MAX_ID - SL_START_16x16]
ScalingMatrixDcRec[refId − 14].
Definition: vvc_ps.h:187
get_luma_predict_unit
static int get_luma_predict_unit(const CodingUnit *cu, const TransformUnit *tu, const int idx, int *x0, int *y0, int *w, int *h)
Definition: vvc_intra.c:218
INTRA_VERT
@ INTRA_VERT
Definition: vvc_ctu.h:229
CodingUnit::intra_pred_mode_c
IntraPredMode intra_pred_mode_c
IntraPredModeC.
Definition: vvc_ctu.h:309
DUAL_TREE_LUMA
@ DUAL_TREE_LUMA
Definition: vvc_ctu.h:163
ff_vvc_diag_scan_x
const uint8_t ff_vvc_diag_scan_x[5][5][16 *16]
Definition: vvc_data.c:27
POS
#define POS(c_idx, x, y)
Definition: vvc_intra.c:584
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: vvc_ctu.c:2472
SL_START_16x16
@ SL_START_16x16
Definition: vvc_ps.h:177
DST7
@ DST7
Definition: vvcdsp.h:32
derive_qp
static void derive_qp(const VVCLocalContext *lc, const TransformUnit *tu, TransformBlock *tb)
Definition: vvc_intra.c:304
H266RawSliceHeader
Definition: cbs_h266.h:769
PredictionUnit::mi
MotionInfo mi
Definition: vvc_ctu.h:263
MODE_INTRA
#define MODE_INTRA
Definition: vp3.c:83
MODE_IBC
@ MODE_IBC
Definition: vvc_ctu.h:187
scale_clip
static void scale_clip(int *coeff, const int nzw, const int w, const int h, const int shift, const int log2_transform_range)
Definition: vvc_intra.c:277
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
av_always_inline
#define av_always_inline
Definition: attributes.h:49
INTRA_T_CCLM
@ INTRA_T_CCLM
Definition: vvc_ctu.h:233
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
CodingUnit::x0
int x0
Definition: vvc_ctu.h:276
TransformUnit::tbs
TransformBlock tbs[VVC_MAX_SAMPLE_ARRAYS]
Definition: vvc_ctu.h:177
tb
#define tb
Definition: regdef.h:68
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: vvc_ctu.c:2501
get_chroma_predict_unit
static int get_chroma_predict_unit(const CodingUnit *cu, const TransformUnit *tu, const int idx, int *x0, int *y0, int *w, int *h)
Definition: vvc_intra.c:229
TransformUnit::width
int width
Definition: vvc_ctu.h:170
VVCLocalContext::cu
CodingUnit * cu
Definition: vvc_ctu.h:416
stride
#define stride
Definition: h264pred_template.c:537
ret
ret
Definition: filter_design.txt:187
IntraPredMode
IntraPredMode
Definition: hevcdec.h:119
ff_vvc_predict_ciip
void ff_vvc_predict_ciip(VVCLocalContext *lc)
CIIP(Combined Inter-Intra Prediction) for a coding block.
Definition: vvc_inter.c:918
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
id
enum AVCodecID id
Definition: dts2pts.c:364
CodingUnit::cb_height
int cb_height
Definition: vvc_ctu.h:279
INTRA_LT_CCLM
@ INTRA_LT_CCLM
Definition: vvc_ctu.h:231
mode
mode
Definition: ebur128.h:83
TransformBlock
Definition: vvc_ctu.h:136
ff_vvc_reconstruct
int ff_vvc_reconstruct(VVCLocalContext *lc, const int rs, const int rx, const int ry)
reconstruct a CTU
Definition: vvc_intra.c:659
CodingUnit::pred_mode
enum PredMode pred_mode
PredMode.
Definition: hevcdec.h:286
ilfnst_transform
static void ilfnst_transform(const VVCLocalContext *lc, TransformBlock *tb)
Definition: vvc_intra.c:66
temp
else temp
Definition: vf_mcdeint.c:263
TransformUnit::y0
int y0
Definition: vvc_ctu.h:169
CodingUnit::next
struct CodingUnit * next
RefStruct reference.
Definition: vvc_ctu.h:325
Mv
Definition: hevcdec.h:295
CTU::cus
CodingUnit * cus
Definition: vvc_ctu.h:329
itransform
static void itransform(VVCLocalContext *lc, TransformUnit *tu, const int tu_idx, const int target_ch_type)
Definition: vvc_intra.c:516
VVCFrameContext::ps
VVCFrameParamSets ps
Definition: vvcdec.h:101
VVCLocalContext::x_vpdu
int x_vpdu
Definition: vvc_ctu.h:412
VVCLocalContext::y_vpdu
int y_vpdu
Definition: vvc_ctu.h:413
VVCSPS::r
const H266RawSPS * r
RefStruct reference.
Definition: vvc_ps.h:59
SliceContext::sh
VVCSH sh
Definition: vvcdec.h:85
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
CodingUnit::isp_split_type
enum IspType isp_split_type
IntraSubPartitionsSplitType.
Definition: vvc_ctu.h:302
VVCFrameContext
Definition: vvcdec.h:92
DCT_A
#define DCT_A
Definition: vvc_intra.c:447
imgutils.h
coeff
static const double coeff[2][5]
Definition: vf_owdenoise.c:79
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
MAX_TB_SIZE
#define MAX_TB_SIZE
Definition: hevcdec.h:48
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: vvc_ctu.h:173
h
h
Definition: vp9dsp_template.c:2038
transpose
#define transpose(x)
scale_coeff
static av_always_inline int scale_coeff(const TransformBlock *tb, int coeff, const int scale, const int scale_m, const int log2_transform_range)
Definition: vvc_intra.c:416
CodingUnit::ciip_flag
uint8_t ciip_flag
Definition: vvc_ctu.h:299
is_cclm
static int is_cclm(enum IntraPredMode mode)
Definition: vvc_intra.c:30
vvc_itx_1d.h
CodingUnit::num_intra_subpartitions
int num_intra_subpartitions
Definition: vvc_ctu.h:306
LUMA
#define LUMA
Definition: hevc_filter.c:31
IBC_POS
#define IBC_POS(c_idx, x, y)
Definition: vvc_intra.c:588
VVCScalingList::scaling_matrix_rec
uint8_t scaling_matrix_rec[SL_MAX_ID][SL_MAX_MATRIX_SIZE *SL_MAX_MATRIX_SIZE]
ScalingMatrixRec.
Definition: vvc_ps.h:186
CodingUnit::y0
int y0
Definition: vvc_ctu.h:277
CodingUnit::qp
int8_t qp[4]
QpY, Qp′Cb, Qp′Cr, Qp′CbCr.
Definition: vvc_ctu.h:321
vvc_inter.h
MODE_PLT
@ MODE_PLT
Definition: vvc_ctu.h:186