FFmpeg
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 "data.h"
26 #include "inter.h"
27 #include "intra.h"
28 #include "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
66 static void ilfnst_transform(const VVCLocalContext *lc, TransformBlock *tb)
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 VVCTxType *trh, enum VVCTxType *trv)
132 {
133  const CodingUnit *cu = lc->cu;
134  static const enum VVCTxType mts_to_trh[] = { VVC_DCT2, VVC_DST7, VVC_DCT8, VVC_DST7, VVC_DCT8 };
135  static const enum VVCTxType mts_to_trv[] = { VVC_DCT2, VVC_DST7, VVC_DST7, VVC_DCT8, VVC_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 = VVC_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) ? VVC_DST7 : VVC_DCT8;
156  *trv = (!cu->sbt_horizontal_flag || cu->sbt_pos_flag) ? VVC_DST7 : VVC_DCT8;
157  } else {
158  *trh = (w >= 4 && w <= 16) ? VVC_DST7 : VVC_DCT2;
159  *trv = (h >= 4 && h <= 16) ? VVC_DST7 : VVC_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 + 8 * 6 + 1] = {
343  0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5,
344  0, 1, 2, 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, 4, 5,
346  0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5,
347  0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3,
348  };
349 
350  static const uint8_t div6[63 + 8 * 6 + 1] = {
351  0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3,
352  4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7,
353  8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11,
354  12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15,
355  16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18,
356  };
357 
358  const static int level_scale[2][6] = {
359  { 40, 45, 51, 57, 64, 72 },
360  { 57, 64, 72, 80, 90, 102 }
361  };
362  const int addin = sh_dep_quant_used_flag && !tb->ts;
363  const int qp = tb->qp + addin;
364 
365  return level_scale[tb->rect_non_ts_flag][rem6[qp]] << div6[qp];
366 }
367 
368 //8.7.3 Scaling process for transform coefficients
369 static const uint8_t* derive_scale_m(const VVCLocalContext *lc, const TransformBlock *tb, uint8_t *scale_m)
370 {
371  //Table 38 – Specification of the scaling matrix identifier variable id according to predMode, cIdx, nTbW, and nTbH
372  const int ids[2][3][6] = {
373  {
374  { 0, 2, 8, 14, 20, 26 },
375  { 0, 3, 9, 15, 21, 21 },
376  { 0, 4, 10, 16, 22, 22 }
377  },
378  {
379  { 0, 5, 11, 17, 23, 27 },
380  { 0, 6, 12, 18, 24, 24 },
381  { 1, 7, 13, 19, 25, 25 },
382  }
383  };
384  const VVCFrameParamSets *ps = &lc->fc->ps;
385  const VVCSPS *sps = ps->sps;
386  const H266RawSliceHeader *rsh = lc->sc->sh.r;
387  const CodingUnit *cu = lc->cu;
388  const VVCScalingList *sl = ps->sl;
389  const int id = ids[cu->pred_mode != MODE_INTRA][tb->c_idx][FFMAX(tb->log2_tb_height, tb->log2_tb_width) - 1];
390  const int log2_matrix_size = (id < 2) ? 1 : (id < 8) ? 2 : 3;
391  uint8_t *p = scale_m;
392 
393  av_assert0(!sps->r->sps_scaling_matrix_for_alternative_colour_space_disabled_flag);
394 
395  if (!rsh->sh_explicit_scaling_list_used_flag || tb->ts ||
396  sps->r->sps_scaling_matrix_for_lfnst_disabled_flag && cu->apply_lfnst_flag[tb->c_idx])
397  return ff_vvc_default_scale_m;
398 
399  if (!sl) {
400  av_log(lc->fc->log_ctx, AV_LOG_WARNING, "bug: no scaling list aps, id = %d", ps->ph.r->ph_scaling_list_aps_id);
401  return ff_vvc_default_scale_m;
402  }
403 
404  for (int y = tb->min_scan_y; y <= tb->max_scan_y; y++) {
405  const int off = y << log2_matrix_size >> tb->log2_tb_height << log2_matrix_size;
406  const uint8_t *m = &sl->scaling_matrix_rec[id][off];
407 
408  for (int x = tb->min_scan_x; x <= tb->max_scan_x; x++)
409  *p++ = m[x << log2_matrix_size >> tb->log2_tb_width];
410  }
411  if (id >= SL_START_16x16 && !tb->min_scan_x && !tb->min_scan_y)
412  *scale_m = sl->scaling_matrix_dc_rec[id - SL_START_16x16];
413 
414  return scale_m;
415 }
416 
417 //8.7.3 Scaling process for transform coefficients
419  const int scale, const int scale_m, const int log2_transform_range)
420 {
421  coeff = ((int64_t) coeff * scale * scale_m + tb->bd_offset) >> tb->bd_shift;
422  coeff = av_clip_intp2(coeff, log2_transform_range);
423  return coeff;
424 }
425 
426 static void dequant(const VVCLocalContext *lc, const TransformUnit *tu, TransformBlock *tb)
427 {
428  uint8_t tmp[MAX_TB_SIZE * MAX_TB_SIZE];
429  const H266RawSliceHeader *rsh = lc->sc->sh.r;
430  const VVCSPS *sps = lc->fc->ps.sps;
431  const uint8_t *scale_m = derive_scale_m(lc, tb, tmp);
432  int scale;
433 
434  derive_qp(lc, tu, tb);
436 
437  for (int y = tb->min_scan_y; y <= tb->max_scan_y; y++) {
438  for (int x = tb->min_scan_x; x <= tb->max_scan_x; x++) {
439  int *coeff = tb->coeffs + y * tb->tb_width + x;
440 
441  if (*coeff)
442  *coeff = scale_coeff(tb, *coeff, scale, *scale_m, sps->log2_transform_range);
443  scale_m++;
444  }
445  }
446 }
447 
448 //transmatrix[0][0]
449 #define DCT_A 64
450 static void itx_2d(const VVCFrameContext *fc, TransformBlock *tb, const enum VVCTxType trh, const enum VVCTxType trv)
451 {
452  const VVCSPS *sps = fc->ps.sps;
453  const int w = tb->tb_width;
454  const int h = tb->tb_height;
455  const size_t nzw = tb->max_scan_x + 1;
456  const size_t nzh = tb->max_scan_y + 1;
457  const int shift[] = { 7, 5 + sps->log2_transform_range - sps->bit_depth };
458 
459  if (w == h && nzw == 1 && nzh == 1 && trh == VVC_DCT2 && trv == VVC_DCT2) {
460  const int add[] = { 1 << (shift[0] - 1), 1 << (shift[1] - 1) };
461  const int t = (tb->coeffs[0] * DCT_A + add[0]) >> shift[0];
462  const int dc = (t * DCT_A + add[1]) >> shift[1];
463 
464  for (int i = 0; i < w * h; i++)
465  tb->coeffs[i] = dc;
466 
467  return;
468  }
469 
470  for (int x = 0; x < nzw; x++)
471  fc->vvcdsp.itx.itx[trv][tb->log2_tb_height - 1](tb->coeffs + x, w, nzh);
472  scale_clip(tb->coeffs, nzw, w, h, shift[0], sps->log2_transform_range);
473 
474  for (int y = 0; y < h; y++)
475  fc->vvcdsp.itx.itx[trh][tb->log2_tb_width - 1](tb->coeffs + y * w, 1, nzw);
476  scale(tb->coeffs, tb->coeffs, w, h, shift[1]);
477 }
478 
479 static void itx_1d(const VVCFrameContext *fc, TransformBlock *tb, const enum VVCTxType trh, const enum VVCTxType trv)
480 {
481  const VVCSPS *sps = fc->ps.sps;
482  const int w = tb->tb_width;
483  const int h = tb->tb_height;
484  const size_t nzw = tb->max_scan_x + 1;
485  const size_t nzh = tb->max_scan_y + 1;
486 
487  if ((w > 1 && nzw == 1 && trh == VVC_DCT2) || (h > 1 && nzh == 1 && trv == VVC_DCT2)) {
488  const int shift = 6 + sps->log2_transform_range - sps->bit_depth;
489  const int add = 1 << (shift - 1);
490  const int dc = (tb->coeffs[0] * DCT_A + add) >> shift;
491 
492  for (int i = 0; i < w * h; i++)
493  tb->coeffs[i] = dc;
494 
495  return;
496  }
497 
498  if (w > 1)
499  fc->vvcdsp.itx.itx[trh][tb->log2_tb_width - 1](tb->coeffs, 1, nzw);
500  else
501  fc->vvcdsp.itx.itx[trv][tb->log2_tb_height - 1](tb->coeffs, 1, nzh);
502  scale(tb->coeffs, tb->coeffs, w, h, 6 + sps->log2_transform_range - sps->bit_depth);
503 }
504 
505 static void transform_bdpcm(TransformBlock *tb, const VVCLocalContext *lc, const CodingUnit *cu)
506 {
507  const VVCSPS *sps = lc->fc->ps.sps;
509  const int vertical = mode == INTRA_VERT;
510  lc->fc->vvcdsp.itx.transform_bdpcm(tb->coeffs, tb->tb_width, tb->tb_height,
511  vertical, sps->log2_transform_range);
512  if (vertical)
513  tb->max_scan_y = tb->tb_height - 1;
514  else
515  tb->max_scan_x = tb->tb_width - 1;
516 }
517 
518 static void itransform(VVCLocalContext *lc, TransformUnit *tu, const int tu_idx, const int target_ch_type)
519 {
520  const VVCFrameContext *fc = lc->fc;
521  const VVCSPS *sps = fc->ps.sps;
522  const VVCSH *sh = &lc->sc->sh;
523  const CodingUnit *cu = lc->cu;
524  const int ps = fc->ps.sps->pixel_shift;
526 
527  for (int i = 0; i < tu->nb_tbs; i++) {
528  TransformBlock *tb = &tu->tbs[i];
529  const int c_idx = tb->c_idx;
530  const int ch_type = c_idx > 0;
531 
532  if (ch_type == target_ch_type && tb->has_coeffs) {
533  const int w = tb->tb_width;
534  const int h = tb->tb_height;
535  const int chroma_scale = ch_type && sh->r->sh_lmcs_used_flag && fc->ps.ph.r->ph_chroma_residual_scale_flag && (w * h > 4);
536  const ptrdiff_t stride = fc->frame->linesize[c_idx];
537  const int hs = sps->hshift[c_idx];
538  const int vs = sps->vshift[c_idx];
539  uint8_t *dst = &fc->frame->data[c_idx][(tb->y0 >> vs) * stride + ((tb->x0 >> hs) << ps)];
540 
541  if (cu->bdpcm_flag[tb->c_idx])
542  transform_bdpcm(tb, lc, cu);
543  dequant(lc, tu, tb);
544  if (!tb->ts) {
545  enum VVCTxType trh, trv;
546 
547  if (cu->apply_lfnst_flag[c_idx])
548  ilfnst_transform(lc, tb);
549  derive_transform_type(fc, lc, tb, &trh, &trv);
550  if (w > 1 && h > 1)
551  itx_2d(fc, tb, trh, trv);
552  else
553  itx_1d(fc, tb, trh, trv);
554  }
555 
556  if (chroma_scale)
557  fc->vvcdsp.intra.lmcs_scale_chroma(lc, temp, tb->coeffs, w, h, cu->x0, cu->y0);
558  // TODO: Address performance issue here by combining transform, lmcs_scale_chroma, and add_residual into one function.
559  // Complete this task before implementing ASM code.
560  fc->vvcdsp.itx.add_residual(dst, chroma_scale ? temp : tb->coeffs, w, h, stride);
561 
562  if (tu->joint_cbcr_residual_flag && tb->c_idx)
563  add_residual_for_joint_coding_chroma(lc, tu, tb, chroma_scale);
564  }
565  }
566 }
567 
569 {
570  VVCFrameContext *fc = lc->fc;
571  CodingUnit *cu = lc->cu;
572  const int start = cu->tree_type == DUAL_TREE_CHROMA;
573  const int end = fc->ps.sps->r->sps_chroma_format_idc && (cu->tree_type != DUAL_TREE_LUMA);
574 
575  for (int ch_type = start; ch_type <= end; ch_type++) {
576  TransformUnit *tu = cu->tus.head;
577  for (int i = 0; tu; i++) {
578  predict_intra(lc, tu, i, ch_type);
579  itransform(lc, tu, i, ch_type);
580  tu = tu->next;
581  }
582  }
583  return 0;
584 }
585 
586 #define POS(c_idx, x, y) \
587  &fc->frame->data[c_idx][((y) >> fc->ps.sps->vshift[c_idx]) * fc->frame->linesize[c_idx] + \
588  (((x) >> fc->ps.sps->hshift[c_idx]) << fc->ps.sps->pixel_shift)]
589 
590 #define IBC_POS(c_idx, x, y) \
591  (fc->tab.ibc_vir_buf[c_idx] + \
592  (x << ps) + (y + ((cu->y0 & ~(sps->ctb_size_y - 1)) >> vs)) * ibc_stride)
593 #define IBC_X(x) ((x) & ((fc->tab.sz.ibc_buffer_width >> hs) - 1))
594 #define IBC_Y(y) ((y) & ((1 << sps->ctb_log2_size_y >> vs) - 1))
595 
596 static void intra_block_copy(const VVCLocalContext *lc, const int c_idx)
597 {
598  const CodingUnit *cu = lc->cu;
599  const PredictionUnit *pu = &cu->pu;
600  const VVCFrameContext *fc = lc->fc;
601  const VVCSPS *sps = fc->ps.sps;
602  const Mv *bv = &pu->mi.mv[L0][0];
603  const int hs = sps->hshift[c_idx];
604  const int vs = sps->vshift[c_idx];
605  const int ps = sps->pixel_shift;
606  const int ref_x = IBC_X((cu->x0 >> hs) + (bv->x >> (4 + hs)));
607  const int ref_y = IBC_Y((cu->y0 >> vs) + (bv->y >> (4 + vs)));
608  const int w = cu->cb_width >> hs;
609  const int h = cu->cb_height >> vs;
610  const int ibc_buf_width = fc->tab.sz.ibc_buffer_width >> hs; ///< IbcBufWidthY and IbcBufWidthC
611  const int rw = FFMIN(w, ibc_buf_width - ref_x);
612  const int ibc_stride = ibc_buf_width << ps;
613  const int dst_stride = fc->frame->linesize[c_idx];
614  const uint8_t *ibc_buf = IBC_POS(c_idx, ref_x, ref_y);
615  uint8_t *dst = POS(c_idx, cu->x0, cu->y0);
616 
617  av_image_copy_plane(dst, dst_stride, ibc_buf, ibc_stride, rw << ps, h);
618 
619  if (w > rw) {
620  //wrap around, left part
621  ibc_buf = IBC_POS(c_idx, 0, ref_y);
622  dst += rw << ps;
623  av_image_copy_plane(dst, dst_stride, ibc_buf, ibc_stride, (w - rw) << ps, h);
624  }
625 }
626 
627 static void vvc_predict_ibc(const VVCLocalContext *lc)
628 {
629  const H266RawSPS *rsps = lc->fc->ps.sps->r;
630 
631  intra_block_copy(lc, LUMA);
632  if (lc->cu->tree_type == SINGLE_TREE && rsps->sps_chroma_format_idc) {
633  intra_block_copy(lc, CB);
634  intra_block_copy(lc, CR);
635  }
636 }
637 
638 static void ibc_fill_vir_buf(const VVCLocalContext *lc, const CodingUnit *cu)
639 {
640  const VVCFrameContext *fc = lc->fc;
641  const VVCSPS *sps = fc->ps.sps;
642  const int has_chroma = sps->r->sps_chroma_format_idc && cu->tree_type != DUAL_TREE_LUMA;
643  const int start = cu->tree_type == DUAL_TREE_CHROMA;
644  const int end = has_chroma ? CR : LUMA;
645 
646  for (int c_idx = start; c_idx <= end; c_idx++) {
647  const int hs = sps->hshift[c_idx];
648  const int vs = sps->vshift[c_idx];
649  const int ps = sps->pixel_shift;
650  const int x = IBC_X(cu->x0 >> hs);
651  const int y = IBC_Y(cu->y0 >> vs);
652  const int src_stride = fc->frame->linesize[c_idx];
653  const int ibc_stride = fc->tab.sz.ibc_buffer_width >> hs << ps;
654  const uint8_t *src = POS(c_idx, cu->x0, cu->y0);
655  uint8_t *ibc_buf = IBC_POS(c_idx, x, y);
656 
657  av_image_copy_plane(ibc_buf, ibc_stride, src, src_stride, cu->cb_width >> hs << ps , cu->cb_height >> vs);
658  }
659 }
660 
661 int ff_vvc_reconstruct(VVCLocalContext *lc, const int rs, const int rx, const int ry)
662 {
663  const VVCFrameContext *fc = lc->fc;
664  const VVCSPS *sps = fc->ps.sps;
665  const int x_ctb = rx << sps->ctb_log2_size_y;
666  const int y_ctb = ry << sps->ctb_log2_size_y;
667  CodingUnit *cu = fc->tab.cus[rs];
668  int ret = 0;
669 
670  lc->num_ras[0] = lc->num_ras[1] = 0;
671  lc->lmcs.x_vpdu = -1;
672  lc->lmcs.y_vpdu = -1;
673  ff_vvc_decode_neighbour(lc, x_ctb, y_ctb, rx, ry, rs);
674  while (cu) {
675  lc->cu = cu;
676 
677  if (cu->ciip_flag)
679  else if (cu->pred_mode == MODE_IBC)
680  vvc_predict_ibc(lc);
681  if (cu->coded_flag) {
682  ret = reconstruct(lc);
683  } else {
684  if (cu->tree_type != DUAL_TREE_CHROMA)
685  add_reconstructed_area(lc, LUMA, cu->x0, cu->y0, cu->cb_width, cu->cb_height);
686  if (sps->r->sps_chroma_format_idc && cu->tree_type != DUAL_TREE_LUMA)
687  add_reconstructed_area(lc, CHROMA, cu->x0, cu->y0, cu->cb_width, cu->cb_height);
688  }
689  if (sps->r->sps_ibc_enabled_flag)
690  ibc_fill_vir_buf(lc, cu);
691  cu = cu->next;
692  }
693  ff_vvc_ctu_free_cus(fc->tab.cus + rs);
694  return ret;
695 }
696 
ff_vvc_reconstruct
int ff_vvc_reconstruct(VVCLocalContext *lc, const int rs, const int rx, const int ry)
reconstruct a CTU
Definition: intra.c:661
VVCSPS
Definition: ps.h:58
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: intra.c:218
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:215
derive_ilfnst_pred_mode_intra
static int derive_ilfnst_pred_mode_intra(const VVCLocalContext *lc, const TransformBlock *tb)
Definition: intra.c:35
VVC_DCT8
@ VVC_DCT8
Definition: dsp.h:33
av_clip
#define av_clip
Definition: common.h:100
LUMA
#define LUMA
Definition: filter.c:31
TransformBlock::tb_width
int tb_width
Definition: ctu.h:148
predict_intra
static void predict_intra(VVCLocalContext *lc, const TransformUnit *tu, const int idx, const int target_ch_type)
Definition: intra.c:246
MotionInfo::mv
Mv mv[2][MAX_CONTROL_POINTS]
Definition: ctu.h:249
H266RawSliceHeader::sh_explicit_scaling_list_used_flag
uint8_t sh_explicit_scaling_list_used_flag
Definition: cbs_h266.h:795
out
FILE * out
Definition: movenc.c:55
u
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:251
TransformUnit::height
int height
Definition: ctu.h:176
CB
#define CB
Definition: filter.c:32
vvc_predict_ibc
static void vvc_predict_ibc(const VVCLocalContext *lc)
Definition: intra.c:627
INTRA_T_CCLM
@ INTRA_T_CCLM
Definition: ctu.h:239
CodingUnit
Definition: hevcdec.h:288
int64_t
long long int64_t
Definition: coverity.c:34
CodingUnit::act_enabled_flag
uint8_t act_enabled_flag
Definition: ctu.h:298
VVC_DCT2
@ VVC_DCT2
Definition: dsp.h:31
CodingUnit::head
TransformUnit * head
RefStruct reference.
Definition: ctu.h:323
TransformUnit::nb_tbs
uint8_t nb_tbs
Definition: ctu.h:182
CodingUnit::bdpcm_flag
int bdpcm_flag[VVC_MAX_SAMPLE_ARRAYS]
BdpcmFlag.
Definition: ctu.h:318
TransformBlock::min_scan_y
int min_scan_y
Definition: ctu.h:156
MODE_IBC
@ MODE_IBC
Definition: ctu.h:193
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: intra.c:277
data.h
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: intra.c:418
mode
Definition: swscale.c:52
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: ctu.h:301
VVCLocalContext::sc
SliceContext * sc
Definition: ctu.h:434
INTRA_DC
@ INTRA_DC
Definition: hevcdec.h:124
itx_1d
static void itx_1d(const VVCFrameContext *fc, TransformBlock *tb, const enum VVCTxType trh, const enum VVCTxType trv)
Definition: intra.c:479
Mv::y
int16_t y
vertical component of motion vector
Definition: hevcdec.h:303
TransformUnit::x0
int x0
Definition: ctu.h:173
VVCSH::r
const H266RawSliceHeader * r
RefStruct reference.
Definition: ps.h:239
VVCDSPContext::itx
VVCItxDSPContext itx
Definition: dsp.h:172
TransformBlock::min_scan_x
int min_scan_x
Definition: ctu.h:155
fc
#define fc(width, name, range_min, range_max)
Definition: cbs_av1.c:472
ReconstructedArea
Definition: ctu.h:340
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
add_tu_area
static void add_tu_area(const TransformUnit *tu, int *x0, int *y0, int *w, int *h)
Definition: intra.c:209
TransformBlock::max_scan_y
int max_scan_y
Definition: ctu.h:154
VVCLocalContext::ras
ReconstructedArea ras[2][MAX_PARTS_IN_CTU]
Definition: ctu.h:419
TransformBlock::max_scan_x
int max_scan_x
Definition: ctu.h:153
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
JCBCR
#define JCBCR
Definition: dec.h:37
VVCFrameParamSets::sps
const VVCSPS * sps
RefStruct reference.
Definition: ps.h:230
VVCFrameParamSets
Definition: ps.h:229
VVCLocalContext::fc
VVCFrameContext * fc
Definition: ctu.h:435
PredictionUnit
Definition: hevcdec.h:321
CodingUnit::apply_lfnst_flag
int apply_lfnst_flag[VVC_MAX_SAMPLE_ARRAYS]
ApplyLfnstFlag[].
Definition: ctu.h:320
TransformBlock::c_idx
uint8_t c_idx
Definition: ctu.h:143
CodingUnit::sbt_pos_flag
uint8_t sbt_pos_flag
Definition: ctu.h:293
IBC_POS
#define IBC_POS(c_idx, x, y)
Definition: intra.c:590
TransformBlock::x0
int x0
Definition: ctu.h:145
VVCFrameParamSets::sl
const VVCScalingList * sl
RefStruct reference.
Definition: ps.h:235
ISP_VER_SPLIT
@ ISP_VER_SPLIT
Definition: ctu.h:121
CodingUnit::cb_width
int cb_width
Definition: ctu.h:284
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: intra.c:229
CodingUnit::pu
PredictionUnit pu
Definition: ctu.h:329
H266RawSPS::sps_chroma_format_idc
uint8_t sps_chroma_format_idc
Definition: cbs_h266.h:314
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
TransformBlock::y0
int y0
Definition: ctu.h:146
TransformUnit::next
struct TransformUnit * next
RefStruct reference.
Definition: ctu.h:185
derive_scale
static av_always_inline int derive_scale(const TransformBlock *tb, const int sh_dep_quant_used_flag)
Definition: intra.c:340
reconstruct
static int reconstruct(VVCLocalContext *lc)
Definition: intra.c:568
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
VVCSH
Definition: ps.h:238
POS
#define POS(c_idx, x, y)
Definition: intra.c:586
CodingUnit::tree_type
VVCTreeType tree_type
Definition: ctu.h:281
VVCFrameParamSets::ph
VVCPH ph
Definition: ps.h:232
CodingUnit::mts_idx
MtsIdx mts_idx
Definition: ctu.h:296
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:181
VVCLocalContext::num_ras
int num_ras[2]
Definition: ctu.h:420
ff_vvc_default_scale_m
uint8_t ff_vvc_default_scale_m[64 *64]
Definition: data.c:1641
VVCFrameContext::log_ctx
void * log_ctx
Definition: dec.h:118
ilfnst_transform
static void ilfnst_transform(const VVCLocalContext *lc, TransformBlock *tb)
Definition: intra.c:66
H266RawSliceHeader::sh_lmcs_used_flag
uint8_t sh_lmcs_used_flag
Definition: cbs_h266.h:794
H266RawSPS
Definition: cbs_h266.h:308
DCT_A
#define DCT_A
Definition: intra.c:449
CodingUnit::sbt_flag
uint8_t sbt_flag
Definition: ctu.h:291
inter.h
VVCTreeType
VVCTreeType
Definition: ctu.h:166
av_clip_intp2
#define av_clip_intp2
Definition: common.h:121
TransformBlock::rect_non_ts_flag
int rect_non_ts_flag
Definition: ctu.h:159
VVCLocalContext
Definition: ctu.h:373
VVCFrameContext::vvcdsp
VVCDSPContext vvcdsp
Definition: dec.h:134
CodingUnit::tus
struct CodingUnit::@285 tus
H266RawSliceHeader::sh_dep_quant_used_flag
uint8_t sh_dep_quant_used_flag
Definition: cbs_h266.h:824
TransformBlock::log2_tb_width
int log2_tb_width
Definition: ctu.h:150
transform_bdpcm
static void transform_bdpcm(TransformBlock *tb, const VVCLocalContext *lc, const CodingUnit *cu)
Definition: intra.c:505
L0
#define L0
Definition: hevcdec.h:58
Mv::x
int16_t x
horizontal component of motion vector
Definition: hevcdec.h:302
VVCPH::r
const H266RawPictureHeader * r
Definition: ps.h:148
VVCItxDSPContext::transform_bdpcm
void(* transform_bdpcm)(int *coeffs, int width, int height, int vertical, int log2_transform_range)
Definition: dsp.h:129
ff_vvc_diag_scan_y
const uint8_t ff_vvc_diag_scan_y[5][5][16 *16]
Definition: data.c:152
SAMPLE_CTB
#define SAMPLE_CTB(tab, x, y)
Definition: hevcdec.h:74
TransformUnit
Definition: hevcdec.h:331
itransform
static void itransform(VVCLocalContext *lc, TransformUnit *tu, const int tu_idx, const int target_ch_type)
Definition: intra.c:518
DUAL_TREE_LUMA
@ DUAL_TREE_LUMA
Definition: ctu.h:168
derive_qp
static void derive_qp(const VVCLocalContext *lc, const TransformUnit *tu, TransformBlock *tb)
Definition: intra.c:304
TransformBlock::bd_offset
int bd_offset
Definition: ctu.h:161
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:2494
VVCScalingList
Definition: ps.h:196
TransformBlock::tb_height
int tb_height
Definition: ctu.h:149
TransformBlock::ts
uint8_t ts
transform_skip_flag
Definition: ctu.h:144
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
IBC_Y
#define IBC_Y(y)
Definition: intra.c:594
CodingUnit::intra_pred_mode_y
IntraPredMode intra_pred_mode_y
IntraPredModeY.
Definition: ctu.h:314
DECLARE_ALIGNED
#define DECLARE_ALIGNED(n, t, v)
Definition: mem_internal.h:104
shift
static int shift(int a, int b)
Definition: bonk.c:261
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
derive_transform_type
static void derive_transform_type(const VVCFrameContext *fc, const VVCLocalContext *lc, const TransformBlock *tb, enum VVCTxType *trh, enum VVCTxType *trv)
Definition: intra.c:131
INTRA_PLANAR
@ INTRA_PLANAR
Definition: hevcdec.h:123
size
int size
Definition: twinvq_data.h:10344
CodingUnit::sbt_horizontal_flag
uint8_t sbt_horizontal_flag
Definition: ctu.h:292
intra.h
H266RawPictureHeader::ph_scaling_list_aps_id
uint8_t ph_scaling_list_aps_id
Definition: cbs_h266.h:704
frame.h
CodingUnit::coded_flag
uint8_t coded_flag
Definition: ctu.h:289
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: ctu.h:295
VVCScalingList::scaling_matrix_dc_rec
uint8_t scaling_matrix_dc_rec[SL_MAX_ID - SL_START_16x16]
ScalingMatrixDcRec[refId − 14].
Definition: ps.h:198
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: intra.c:189
ff_vvc_predict_ciip
void ff_vvc_predict_ciip(VVCLocalContext *lc)
CIIP(Combined Inter-Intra Prediction) for a coding block.
Definition: inter.c:1018
CodingUnit::intra_pred_mode_c
IntraPredMode intra_pred_mode_c
IntraPredModeC.
Definition: ctu.h:315
itx_1d.h
dequant
static void dequant(const VVCLocalContext *lc, const TransformUnit *tu, TransformBlock *tb)
Definition: intra.c:426
H266RawSliceHeader
Definition: cbs_h266.h:771
PredictionUnit::mi
MotionInfo mi
Definition: ctu.h:269
MODE_INTRA
#define MODE_INTRA
Definition: vp3.c:84
CR
#define CR
Definition: filter.c:33
MODE_PLT
@ MODE_PLT
Definition: ctu.h:192
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
ISP_NO_SPLIT
@ ISP_NO_SPLIT
Definition: ctu.h:119
ff_vvc_diag_scan_x
const uint8_t ff_vvc_diag_scan_x[5][5][16 *16]
Definition: data.c:27
MIN_ISP_PRED_WIDTH
#define MIN_ISP_PRED_WIDTH
Definition: intra.c:217
av_always_inline
#define av_always_inline
Definition: attributes.h:49
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
CodingUnit::x0
int x0
Definition: ctu.h:282
TransformUnit::tbs
TransformBlock tbs[VVC_MAX_SAMPLE_ARRAYS]
Definition: ctu.h:183
TransformBlock::coeffs
int * coeffs
Definition: ctu.h:163
TransformBlock::bd_shift
int bd_shift
Definition: ctu.h:160
itx_2d
static void itx_2d(const VVCFrameContext *fc, TransformBlock *tb, const enum VVCTxType trh, const enum VVCTxType trv)
Definition: intra.c:450
TransformUnit::width
int width
Definition: ctu.h:175
VVCLocalContext::cu
CodingUnit * cu
Definition: ctu.h:418
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: intra_utils.c:197
stride
#define stride
Definition: h264pred_template.c:537
INTRA_VERT
@ INTRA_VERT
Definition: ctu.h:235
ret
ret
Definition: filter_design.txt:187
IntraPredMode
IntraPredMode
Definition: hevcdec.h:122
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
SL_START_16x16
@ SL_START_16x16
Definition: ps.h:188
id
enum AVCodecID id
Definition: dts2pts.c:367
CodingUnit::cb_height
int cb_height
Definition: ctu.h:285
TransformBlock::log2_tb_height
int log2_tb_height
Definition: ctu.h:151
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:2527
DUAL_TREE_CHROMA
@ DUAL_TREE_CHROMA
Definition: ctu.h:169
TransformBlock::has_coeffs
uint8_t has_coeffs
Definition: ctu.h:142
INTRA_L_CCLM
@ INTRA_L_CCLM
Definition: ctu.h:238
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: intra.c:167
TransformBlock
Definition: ctu.h:141
CodingUnit::pred_mode
enum PredMode pred_mode
PredMode.
Definition: hevcdec.h:292
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: itx_1d.c:695
temp
else temp
Definition: vf_mcdeint.c:263
intra_block_copy
static void intra_block_copy(const VVCLocalContext *lc, const int c_idx)
Definition: intra.c:596
TransformUnit::y0
int y0
Definition: ctu.h:174
CodingUnit::next
struct CodingUnit * next
RefStruct reference.
Definition: ctu.h:331
Mv
Definition: hevcdec.h:301
VVCFrameContext::ps
VVCFrameParamSets ps
Definition: dec.h:126
VVCLocalContext::x_vpdu
int x_vpdu
Definition: ctu.h:414
SINGLE_TREE
@ SINGLE_TREE
Definition: ctu.h:167
scale
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition: intra.c:291
VVCLocalContext::y_vpdu
int y_vpdu
Definition: ctu.h:415
VVCSPS::r
const H266RawSPS * r
RefStruct reference.
Definition: ps.h:59
SliceContext::sh
VVCSH sh
Definition: dec.h:110
TransformBlock::qp
int qp
Definition: ctu.h:158
CodingUnit::isp_split_type
enum IspType isp_split_type
IntraSubPartitionsSplitType.
Definition: ctu.h:308
VVCFrameContext
Definition: dec.h:117
VVCTxType
VVCTxType
Definition: dsp.h:30
imgutils.h
VVC_DST7
@ VVC_DST7
Definition: dsp.h:32
coeff
static const double coeff[2][5]
Definition: vf_owdenoise.c:80
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
MAX_TB_SIZE
#define MAX_TB_SIZE
Definition: hevcdec.h:49
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:179
h
h
Definition: vp9dsp_template.c:2070
ibc_fill_vir_buf
static void ibc_fill_vir_buf(const VVCLocalContext *lc, const CodingUnit *cu)
Definition: intra.c:638
transpose
#define transpose(x)
INTRA_LT_CCLM
@ INTRA_LT_CCLM
Definition: ctu.h:237
CodingUnit::ciip_flag
uint8_t ciip_flag
Definition: ctu.h:305
IBC_X
#define IBC_X(x)
Definition: intra.c:593
VVCLocalContext::lmcs
struct VVCLocalContext::@287 lmcs
src
#define src
Definition: vp8dsp.c:248
CodingUnit::num_intra_subpartitions
int num_intra_subpartitions
Definition: ctu.h:312
VVCScalingList::scaling_matrix_rec
uint8_t scaling_matrix_rec[SL_MAX_ID][SL_MAX_MATRIX_SIZE *SL_MAX_MATRIX_SIZE]
ScalingMatrixRec.
Definition: ps.h:197
CodingUnit::y0
int y0
Definition: ctu.h:283
CodingUnit::qp
int8_t qp[4]
QpY, Qp′Cb, Qp′Cr, Qp′CbCr.
Definition: ctu.h:327
derive_scale_m
static const uint8_t * derive_scale_m(const VVCLocalContext *lc, const TransformBlock *tb, uint8_t *scale_m)
Definition: intra.c:369
is_cclm
static int is_cclm(enum IntraPredMode mode)
Definition: intra.c:30
ff_vvc_ctu_free_cus
void ff_vvc_ctu_free_cus(CodingUnit **cus)
Definition: ctu.c:2542