32 #define PROF_TEMP_SIZE (PROF_BLOCK_SIZE) * sizeof(int16_t)
34 #define TAB_MSM(fc, depth, x, y) fc->tab.msm[(depth)][((y) >> 5) * fc->ps.pps->width32 + ((x) >> 5)]
35 #define TAB_ISPMF(fc, x, y) fc->tab.ispmf[((y) >> 6) * fc->ps.pps->width64 + ((x) >> 6)]
47 const int hs =
fc->ps.sps->hshift[tb->
c_idx];
48 const int vs =
fc->ps.sps->vshift[tb->
c_idx];
49 const int is_chroma = tb->
c_idx != 0;
53 for (
int y = y_tb; y < end; y++) {
54 const int off = y *
fc->ps.pps->min_tu_width + x_tb;
70 memset(
tab + off, v,
w);
81 const int ctb_log2_size =
sps->ctb_log2_size_y;
82 const int ctb_size_mask = (1 << ctb_log2_size) - 1;
85 const int min_cb_width =
fc->ps.pps->min_cb_width;
86 const int x_cb = cu->
x0 >>
sps->min_cb_log2_size_y;
87 const int y_cb = cu->
y0 >>
sps->min_cb_log2_size_y;
88 const int rx = cu->
x0 >> ctb_log2_size;
89 const int ry = cu->
y0 >> ctb_log2_size;
90 const int in_same_ctb_a = ((xQg - 1) >> ctb_log2_size) == rx && (yQg >> ctb_log2_size) == ry;
91 const int in_same_ctb_b = (xQg >> ctb_log2_size) == rx && ((yQg - 1) >> ctb_log2_size) == ry;
92 int qPy_pred, qPy_a, qPy_b;
95 const int first_qg_in_ctu = !(xQg & ctb_size_mask) && !(yQg & ctb_size_mask);
96 const int qPy_up =
fc->tab.qp[
LUMA][x_cb + (y_cb - 1) * min_cb_width];
97 if (first_qg_in_ctu &&
pps->ctb_to_col_bd[xQg >> ctb_log2_size] == xQg >> ctb_log2_size)
108 qPy_b =
fc->tab.qp[
LUMA][x_cb + (y_cb - 1) * min_cb_width];
114 qPy_a =
fc->tab.qp[
LUMA][(x_cb - 1) + y_cb * min_cb_width];
116 av_assert2(qPy_a >= -
fc->ps.sps->qp_bd_offset && qPy_a <= 63);
117 av_assert2(qPy_b >= -
fc->ps.sps->qp_bd_offset && qPy_b <= 63);
119 return (qPy_a + qPy_b + 1) >> 1;
127 const int log2_min_cb_size =
fc->ps.sps->min_cb_log2_size_y;
128 const int x_cb = cu->
x0 >> log2_min_cb_size;
129 const int y_cb = cu->
y0 >> log2_min_cb_size;
132 int x = y_cb *
pps->min_cb_width + x_cb;
134 for (
int y = 0; y < (cb_height >> log2_min_cb_size); y++) {
135 const int width = cb_width >> log2_min_cb_size;
138 x +=
pps->min_cb_width;
161 if (cu_qp_delta > (31 +
sps->qp_bd_offset / 2) || cu_qp_delta < -(32 +
sps->qp_bd_offset / 2))
166 int off =
sps->qp_bd_offset;
167 ep->
qp_y =
FFUMOD(ep->
qp_y + cu_qp_delta + 64 + 2 * off, 64 + off) - off;
192 const int x_center = cu->
x0 + cu->
cb_width / 2;
197 const int sh_chroma_qp_offset[] = {
204 for (
int i =
CB - 1;
i <
CR +
sps->r->sps_joint_cbcr_enabled_flag;
i++) {
205 qp =
sps->chroma_qp_table[
i][qp_chroma];
238 tu->
width = tu_width;
249 const int x0,
const int y0,
const int tb_width,
const int tb_height,
const int c_idx)
268 lc->
coeffs += tb_width * tb_height;
269 tu->
avail[!!c_idx] =
true;
274 const int sub_tu_index,
const int is_isp,
const int is_chroma_coded)
276 uint8_t tu_y_coded_flag = 0;
280 if (!is_sbt_not_coded) {
290 return tu_y_coded_flag;
298 if ((is_128 || is_chroma_coded) &&
301 if (cu_chroma_qp_offset_flag) {
302 int cu_chroma_qp_offset_idx = 0;
303 if (
pps->r->pps_chroma_qp_offset_list_len_minus1 > 0)
321 const int min_cb_width =
pps->min_cb_width;
326 const int is_sbt_not_coded = cu->
sbt_flag &&
328 const int chroma_available = tree_type !=
DUAL_TREE_LUMA &&
sps->r->sps_chroma_format_idc &&
329 (!is_isp || is_isp_last_tu);
330 int ret, xc, yc, wc, hc, is_chroma_coded;
336 const int x_cu = x0 >>
fc->ps.sps->min_cb_log2_size_y;
337 const int y_cu = y0 >>
fc->ps.sps->min_cb_log2_size_y;
341 hc =
SAMPLE_CTB(
fc->tab.cb_height[ch_type], x_cu, y_cu);
343 xc = x0, yc = y0, wc = tu_width, hc = tu_height;
346 if (chroma_available && !is_sbt_not_coded) {
356 has_qp_delta = (is_128 || tu->
coded_flag[
LUMA] || is_chroma_coded) &&
361 add_tb(tu, lc, x0, y0, tu_width, tu_height,
LUMA);
365 if (chroma_available) {
368 add_tb(tu, lc, xc, yc, wc >> hs, hc >> vs,
CB);
369 add_tb(tu, lc, xc, yc, wc >> hs, hc >> vs,
CR);
389 !cu->
sbt_flag && (is_chroma || !is_isp)) {
416 if (tu_width >
sps->max_tb_size_y || tu_height >
sps->max_tb_size_y) {
417 const int ver_split_first = tu_width >
sps->max_tb_size_y && tu_width > tu_height;
418 const int trafo_width = ver_split_first ? (tu_width / 2) : tu_width;
419 const int trafo_height = !ver_split_first ? (tu_height / 2) : tu_height;
421 #define TRANSFORM_TREE(x, y) do { \
422 ret = hls_transform_tree(lc, x, y, trafo_width, trafo_height, ch_type); \
441 #define TRANSFORM_UNIT(x, width, idx) do { \
442 ret = hls_transform_unit(lc, x, y0, width, tu_height, idx, ch_type); \
451 #undef TRANSFORM_UNIT
453 #define TRANSFORM_UNIT(y, height, idx) do { \
454 ret = hls_transform_unit(lc, x0, y, tu_width, height, idx, ch_type); \
463 #undef TRANSFORM_UNIT
490 if (tu_width >
sps->max_tb_size_y || tu_height >
sps->max_tb_size_y) {
491 const int ver_split_first = tu_width >
sps->max_tb_size_y && tu_width > tu_height;
492 const int trafo_width = ver_split_first ? (tu_width / 2) : tu_width;
493 const int trafo_height = !ver_split_first ? (tu_height / 2) : tu_height;
495 #define SKIPPED_TRANSFORM_TREE(x, y) do { \
496 int ret = skipped_transform_tree(lc, x, y, trafo_width, trafo_height); \
513 for (
int i = start;
i < end;
i++) {
527 int mtt_depth,
int depth_offset,
int part_idx,
VVCSplitMode last_split_mode,
530 int min_qt_size, max_bt_size, max_tt_size, max_mtt_depth;
536 int min_cb_size_y =
sps->min_cb_size_y;
537 int *qt = &
split->qt;
538 int *btv = &
split->btv;
539 int *bth = &
split->bth;
540 int *ttv = &
split->ttv;
541 int *tth = &
split->tth;
543 *qt = *bth = *btv = *tth = *ttv = 1;
549 if (cb_width <= min_qt_size)
553 int chroma_area = (cb_width >>
sps->hshift[1]) * (cb_height >>
sps->vshift[1]);
554 int chroma_width = cb_width >>
sps->hshift[1];
556 if (chroma_width == 8)
558 else if (chroma_width <= 4) {
559 if (chroma_width == 4)
564 *qt = *btv = *bth = *ttv = *tth = 0;
565 if (chroma_area <= 32) {
567 if (chroma_area <= 16)
576 int area = cb_width * cb_height;
582 if (cb_width <= 2 * min_cb_size_y) {
584 if (cb_width <= min_cb_size_y)
587 if (cb_height <= 2 * min_cb_size_y) {
589 if (cb_height <= min_cb_size_y)
592 if (cb_width > max_bt_size || cb_height > max_bt_size)
594 max_tt_size =
FFMIN(64, max_tt_size);
595 if (cb_width > max_tt_size || cb_height > max_tt_size)
597 if (mtt_depth >= max_mtt_depth)
598 *btv = *bth = *ttv = *tth = 0;
599 if (x0 + cb_width >
pps->width) {
603 if (y0 + cb_height <= pps->
height)
605 else if (cb_width > min_qt_size)
608 if (y0 + cb_height >
pps->height) {
609 *btv = *ttv = *tth = 0;
613 if (mtt_depth > 0 && part_idx == 1) {
619 if (cb_width <= 64 && cb_height > 64)
621 if (cb_width > 64 && cb_height <= 64)
629 if ((cb_width == 4 && cb_height == 8) || (cb_width == 8 && cb_height == 4))
640 if (!
sps->r->sps_cclm_enabled_flag)
642 if (!
sps->r->sps_qtbtt_dual_tree_intra_flag || !
IS_I(lc->
sc->
sh.
r) ||
sps->ctb_log2_size_y < 6)
645 const int x64 = x0 >> 6 << 6;
646 const int y64 = y0 >> 6 << 6;
647 const int y32 = y0 >> 5 << 5;
648 const int x64_cu = x64 >>
fc->ps.sps->min_cb_log2_size_y;
649 const int y64_cu = y64 >>
fc->ps.sps->min_cb_log2_size_y;
650 const int y32_cu = y32 >>
fc->ps.sps->min_cb_log2_size_y;
651 const int min_cb_width =
fc->ps.pps->min_cb_width;
652 const int depth =
SAMPLE_CTB(
fc->tab.cqt_depth[1], x64_cu, y64_cu);
653 const int min_depth =
fc->ps.sps->ctb_log2_size_y - 6;
657 enabled =
SAMPLE_CTB(
fc->tab.cb_width[1], x64_cu, y64_cu) == 64 &&
659 enabled |= depth == min_depth && msm64 ==
SPLIT_BT_HOR &&
660 SAMPLE_CTB(
fc->tab.cb_width[1], x64_cu, y32_cu) == 64 &&
662 enabled |= depth > min_depth;
666 const int w =
SAMPLE_CTB(
fc->tab.cb_width[0], x64_cu, y64_cu);
667 const int h =
SAMPLE_CTB(
fc->tab.cb_height[0], x64_cu, y64_cu);
668 const int depth0 =
SAMPLE_CTB(
fc->tab.cqt_depth[0], x64_cu, y64_cu);
670 ((
w < 64 ||
h < 64) && depth0 == min_depth))
679 static int less(
const void *
a,
const void *
b)
681 return *(
const int*)
a - *(
const int*)
b;
689 const int x0 = cu->
x0;
690 const int y0 = cu->
y0;
692 int intra_luma_not_planar_flag = 1;
693 int intra_luma_mpm_remainder = 0;
694 int intra_luma_mpm_flag = 1;
695 int intra_luma_mpm_idx = 0;
699 if (intra_luma_mpm_flag) {
702 if (intra_luma_not_planar_flag)
708 if (!intra_luma_not_planar_flag) {
712 const int x_a = (x0 - 1) >>
sps->min_cb_log2_size_y;
713 const int y_a = (y0 + cu->
cb_height - 1) >>
sps->min_cb_log2_size_y;
714 const int x_b = (x0 + cu->
cb_width - 1) >>
sps->min_cb_log2_size_y;
715 const int y_b = (y0 - 1) >>
sps->min_cb_log2_size_y;
716 int min_cb_width =
fc->ps.pps->min_cb_width;
740 cand[1] = 2 + ((
a + 61) % 64);
741 cand[2] = 2 + ((
a - 1) % 64);
742 cand[3] = 2 + ((
a + 60) % 64);
743 cand[4] = 2 + (
a % 64);
748 const int diff = maxab - minab;
752 cand[2] = 2 + ((minab + 61) % 64);
753 cand[3] = 2 + ((maxab - 1) % 64);
754 cand[4] = 2 + ((minab + 60) % 64);
755 }
else if (
diff >= 62) {
756 cand[2] = 2 + ((minab - 1) % 64);
757 cand[3] = 2 + ((maxab + 61) % 64);
758 cand[4] = 2 + (minab % 64);
759 }
else if (
diff == 2) {
760 cand[2] = 2 + ((minab - 1) % 64);
761 cand[3] = 2 + ((minab + 61) % 64);
762 cand[4] = 2 + ((maxab - 1) % 64);
764 cand[2] = 2 + ((minab + 61) % 64);
765 cand[3] = 2 + ((minab - 1) % 64);
766 cand[4] = 2 + ((maxab + 61) % 64);
770 cand[1] = 2 + ((maxab + 61 ) % 64);
771 cand[2] = 2 + ((maxab - 1) % 64);
772 cand[3] = 2 + ((maxab + 60 ) % 64);
773 cand[4] = 2 + (maxab % 64);
782 if (intra_luma_mpm_flag) {
783 pred = cand[intra_luma_mpm_idx];
786 pred = intra_luma_mpm_remainder + 1;
804 int lfnst_width, lfnst_height, min_lfnst;
813 for (
int j = 0; j < tu->
nb_tbs; j++) {
822 lfnst_width = cb_width >>
sps->hshift[1];
823 lfnst_height = cb_height >>
sps->vshift[1];
830 min_lfnst =
FFMIN(lfnst_width, lfnst_height);
834 if (min_lfnst >= 4) {
853 const uint8_t transform_skip_flag = cu->
tus.
head->
tbs[0].
ts;
856 !transform_skip_flag &&
FFMAX(cb_width, cb_height) <= 32 &&
870 const int x_center = (cu->
x0 + cu->
cb_width / 2) >>
sps->min_cb_log2_size_y;
871 const int y_center = (cu->
y0 + cu->
cb_height / 2) >>
sps->min_cb_log2_size_y;
872 const int min_cb_width =
pps->min_cb_width;
873 const int intra_mip_flag =
SAMPLE_CTB(
fc->tab.imf, x_center, y_center);
874 const int cu_pred_mode =
SAMPLE_CTB(
fc->tab.cpm[0], x_center, y_center);
875 const int intra_pred_mode_y =
SAMPLE_CTB(
fc->tab.ipm, x_center, y_center);
877 if (intra_mip_flag) {
884 return intra_pred_mode_y;
888 const int cclm_mode_flag,
const int cclm_mode_idx,
const int intra_chroma_pred_mode)
894 const int x_cb = cu->
x0 >>
sps->min_cb_log2_size_y;
895 const int y_cb = cu->
y0 >>
sps->min_cb_log2_size_y;
896 const int min_cb_width =
pps->min_cb_width;
897 const int intra_mip_flag =
SAMPLE_CTB(
fc->tab.imf, x_cb, y_cb);
912 if (cclm_mode_flag) {
914 }
else if (intra_chroma_pred_mode == 4){
942 0, 1, 61, 62, 63, 64, 65, 66, 2, 3, 5, 6, 8, 10, 12, 13,
943 14, 16, 18, 20, 22, 23, 24, 26, 28, 30, 31, 33, 34, 35, 36, 37,
944 38, 39, 40, 41, 41, 42, 43, 43, 44, 44, 45, 45, 46, 47, 48, 48,
945 49, 49, 50, 51, 51, 52, 52, 53, 54, 55, 55, 56, 56, 57, 57, 58,
953 int intra_mip_transposed_flag,
int intra_mip_mode)
955 return (intra_mip_mode << 2) | (intra_mip_transposed_flag << 1) | intra_mip_flag;
964 const int log2_min_cb_size =
sps->min_cb_log2_size_y;
965 const int x0 = cu->
x0;
966 const int y0 = cu->
y0;
967 const int x_cb = x0 >> log2_min_cb_size;
968 const int y_cb = y0 >> log2_min_cb_size;
973 if (
sps->r->sps_bdpcm_enabled_flag && cb_width <= sps->max_ts_size && cb_height <= sps->max_ts_size)
978 if (
sps->r->sps_mip_enabled_flag)
983 int x = y_cb *
pps->min_cb_width + x_cb;
984 for (
int y = 0; y < (cb_height>>log2_min_cb_size); y++) {
985 int width = cb_width>>log2_min_cb_size;
987 intra_mip_transposed_flag, intra_mip_mode);
988 memset(&
fc->tab.imf[x], mip_info,
width);
989 x +=
pps->min_cb_width;
993 int intra_subpartitions_mode_flag = 0;
994 if (
sps->r->sps_mrl_enabled_flag && ((y0 %
sps->ctb_size_y) > 0))
997 (cb_width <= sps->max_tb_size_y && cb_height <= sps->max_tb_size_y) &&
1001 if (!(x0 & 63) && !(y0 & 63))
1002 TAB_ISPMF(
fc, x0, y0) = intra_subpartitions_mode_flag;
1017 int cclm_mode_flag = 0;
1018 int cclm_mode_idx = 0;
1019 int intra_chroma_pred_mode = 0;
1023 if (
sps->r->sps_bdpcm_enabled_flag &&
1061 int pred_mode_ibc_flag;
1065 if (!
IS_I(rsh) ||
sps->r->sps_ibc_enabled_flag) {
1068 (
sps->r->sps_ibc_enabled_flag && !is_128))) {
1088 pred_mode_ibc_flag = 1;
1090 pred_mode_ibc_flag = 0;
1092 pred_mode_ibc_flag = (
IS_I(rsh)) ?
sps->r->sps_ibc_enabled_flag : 0;
1094 if (pred_mode_ibc_flag)
1122 && cb_width <= sps->max_tb_size_y && cb_height <= sps->max_tb_size_y) {
1123 const int sbt_ver_h = cb_width >= 8;
1124 const int sbt_hor_h = cb_height >= 8;
1126 if (sbt_ver_h || sbt_hor_h)
1129 const int sbt_ver_q = cb_width >= 16;
1130 const int sbt_hor_q = cb_height >= 16;
1131 int cu_sbt_quad_flag = 0;
1133 if ((sbt_ver_h || sbt_hor_h) && (sbt_ver_q || sbt_hor_q))
1135 if (cu_sbt_quad_flag) {
1137 if (sbt_ver_q && sbt_hor_q)
1141 if (sbt_ver_h && sbt_hor_h)
1147 const int sbt_min = cu_sbt_quad_flag ? 1 : 2;
1177 const int log2_min_cb_size =
sps->min_cb_log2_size_y;
1178 const int x_cb = cu->
x0 >> log2_min_cb_size;
1179 const int y_cb = cu->
y0 >> log2_min_cb_size;
1180 const int ch_type = cu->
ch_type;
1183 x = y_cb *
pps->min_cb_width + x_cb;
1184 for (y = 0; y < (cu->
cb_height >> log2_min_cb_size); y++) {
1188 fc->tab.cb_pos_x[ch_type][x +
i] = cu->
x0;
1189 fc->tab.cb_pos_y[ch_type][x +
i] = cu->
y0;
1195 x +=
pps->min_cb_width;
1204 const int rx = x0 >>
sps->ctb_log2_size_y;
1205 const int ry = y0 >>
sps->ctb_log2_size_y;
1223 const int cb_width,
const int cb_height,
const int cqt_depth,
const VVCTreeType tree_type)
1232 memset(&cu->
pu, 0,
sizeof(cu->
pu));
1275 for (
int j = 0; j < tu->
nb_tbs; j++) {
1293 const int diff[] = {
1300 mmvd[1] = mmvd[0] = *mmvd_offset;
1305 mmvd[
i] = *mmvd_offset;
1310 mmvd[o].
x = sign ? -mmvd[
i].
x : mmvd[
i].
x;
1311 mmvd[o].
y = sign ? -mmvd[
i].
y : mmvd[
i].
y;
1314 mvf->
mv[0].
x += mmvd[0].
x;
1315 mvf->
mv[0].
y += mmvd[0].
y;
1316 mvf->
mv[1].
x += mmvd[1].
x;
1317 mvf->
mv[1].
y += mmvd[1].
y;
1320 mvf->
mv[idx].
x += mmvd_offset->
x;
1321 mvf->
mv[idx].
y += mmvd_offset->
y;
1331 for (
int i = 0;
i < 2;
i++) {
1334 mi->mv[
i][0] = mvf->
mv[
i];
1355 int merge_subblock_idx = 0;
1357 if (
ph->max_num_subblock_merge_cand > 1) {
1374 if (
sps->r->sps_mmvd_enabled_flag)
1377 int mmvd_cand_flag = 0;
1378 if (
sps->max_num_merge_cand > 1)
1381 merge_idx = mmvd_cand_flag;
1382 }
else if (
sps->max_num_merge_cand > 1) {
1399 if (ciip_avaiable && gpm_avaiable)
1401 return sps->r->sps_ciip_enabled_flag && !cu->
skip_flag &&
1410 int merge_gpm_idx[2];
1415 merge_gpm_idx[1] = 0;
1416 if (
sps->max_num_gpm_merge_cand > 2)
1432 if (
sps->max_num_merge_cand > 1)
1452 const int is_128 = cb_width == 128 || cb_height == 128;
1453 const int ciip_avaiable =
sps->r->sps_ciip_enabled_flag &&
1454 !cu->
skip_flag && (cb_width * cb_height >= 64);
1455 const int gpm_avaiable =
sps->r->sps_gpm_enabled_flag &&
IS_B(rsh) &&
1456 (cb_width >= 8) && (cb_height >=8) &&
1457 (cb_width < 8 * cb_height) && (cb_height < 8 *cb_width);
1459 int regular_merge_flag = 1;
1461 if (!is_128 && (ciip_avaiable || gpm_avaiable))
1463 if (regular_merge_flag) {
1484 if (
sps->max_num_ibc_merge_cand > 1)
1524 for (
int i = 0;
i < 2;
i++) {
1528 for (
int i = 0;
i < 2;
i++) {
1533 for (
int i = 0;
i < 2;
i++) {
1554 if (
sps->r->sps_bcw_enabled_flag &&
mi->pred_flag ==
PF_BI &&
1555 !
w->weight_flag[
L0][
LUMA][
mi->ref_idx[0]] &&
1556 !
w->weight_flag[
L1][
LUMA][
mi->ref_idx[1]] &&
1559 cb_width * cb_height >= 256) {
1572 else if (sym_mvd_flag)
1578 const int num_cp_mv,
const int lx)
1584 int has_no_zero_mvd = 0;
1586 if (lx ==
L1 &&
ph->r->ph_mvd_l1_zero_flag &&
mi->pred_flag ==
PF_BI) {
1587 for (
int j = 0; j < num_cp_mv; j++)
1590 Mv *mvd0 = &mvds[lx][0];
1592 mvd0->
x = -mvds[
L0][0].x;
1593 mvd0->
y = -mvds[
L0][0].y;
1597 has_no_zero_mvd |= (mvd0->
x || mvd0->
y);
1598 for (
int j = 1; j < num_cp_mv; j++) {
1599 Mv *mvd = &mvds[lx][j];
1603 has_no_zero_mvd |= (mvd->
x || mvd->
y);
1606 return has_no_zero_mvd;
1612 for (
int i = 0;
i < 2;
i++) {
1614 if (
mi->pred_flag &
mask) {
1615 for (
int j = 0; j < num_cp_mv; j++) {
1616 const Mv *mvd = &mvds[
i][j];
1617 mi->mv[
i][j].x += mvd->
x * (1 << amvr_shift);
1618 mi->mv[
i][j].y += mvd->
y * (1 << amvr_shift);
1631 int mvp_l0_flag = 0;
1641 if (
sps->max_num_ibc_merge_cand > 1)
1643 if (
sps->r->sps_amvr_enabled_flag && (
mv->x ||
mv->y))
1667 int mvp_lx_flag[2] = {0};
1668 int cu_affine_type_flag = 0;
1670 int amvr_enabled, has_no_zero_mvd = 0, amvr_shift;
1674 if (
sps->r->sps_affine_enabled_flag && cb_width >= 16 && cb_height >= 16) {
1681 num_cp_mv =
mi->motion_model_idc + 1;
1683 if (
sps->r->sps_smvd_enabled_flag && !
ph->r->ph_mvd_l1_zero_flag &&
1688 for (
int i =
L0;
i <=
L1;
i++) {
1690 if (
mi->pred_flag != pred_flag) {
1692 has_no_zero_mvd |=
mvds_decode(lc, mvds, num_cp_mv,
i);
1698 sps->r->sps_amvr_enabled_flag :
sps->r->sps_affine_amvr_enabled_flag;
1699 amvr_enabled &= has_no_zero_mvd;
1703 mi->hpel_if_idx = amvr_shift == 3;
1706 if (
mi->motion_model_idc)
1713 if (
mi->motion_model_idc)
1729 const int poc =
ph->poc;
1731 const int8_t *ref_idx =
mi->ref_idx;
1740 (poc - rp0->
poc == rp1->
poc - poc) &&
1749 if (!
ph->r->ph_bdof_disabled_flag &&
1754 if (!
ph->r->ph_dmvr_disabled_flag &&
1788 MvField *dmvr_mvf =
fc->ref->tab_dmvr_mvf + idx;
1790 memcpy(dmvr_mvf, mvf,
sizeof(
MvField) *
w);
1838 for (
int c = start;
c < end;
c++) {
1853 bool *predictor_reused,
const int predictor_size,
const int max_entries)
1856 int nb_predicted = 0;
1858 if (local_dual_tree) {
1863 for (
int i = 0;
i < predictor_size && nb_predicted < max_entries;
i++) {
1874 predictor_reused[
i] =
true;
1875 for (
int c = start;
c < end;
c++)
1880 for (
int c = start;
c < end;
c++)
1887 const int start,
const int end,
const int max_entries)
1891 const int nb_predicted = cu->
plt[start].
size;
1893 const int size = nb_predicted + nb_signaled;
1896 if (nb_signaled < 0)
1899 for (
int c = start;
c < end;
c++) {
1901 for (
int i = nb_predicted;
i <
size;
i++) {
1903 if (dual_tree_luma) {
1915 bool *predictor_reused,
const int predictor_size)
1920 if (local_dual_tree) {
1925 for (
int c = start;
c < end;
c++) {
1931 for (
int j = 0; j < predictor_size &&
i < max_predictor; j++) {
1932 if (!predictor_reused[j]) {
1952 const bool has_qp_delta = escape_present &&
1968 #define PALETTE_SET_PIXEL(xc, yc, pix) \
1970 const int off = ((xc) >> hs) + ((yc) >> vs) * tb->tb_width; \
1971 if (sps->bit_depth == 8) \
1977 #define PALETTE_INDEX(x, y) index[(y) * width + (x)]
1982 #define TRAV_COL(p, wlog, mask) ((p & mask) ^ (-((p >> wlog) & 1) & mask))
1983 #define TRAV_ROW(p, hlog) (p >> hlog)
1984 #define TRAV(trans, p, wlog, hlog, mask) (trans ? TRAV_ROW((p), hlog) : TRAV_COL((p), wlog, mask))
1985 #define TRAV_X(pos) TRAV(transpose, pos, wlog2, hlog2, wmask)
1986 #define TRAV_Y(pos) TRAV(!transpose, pos, hlog2, wlog2, hmask)
1989 const int max_index,
const int subset_id,
const bool transpose,
1990 uint8_t *run_type, uint8_t *
index,
int *prev_run_pos,
bool *
adjust)
1997 const int min_pos = subset_id << 4;
1999 const int wmask =
width - 1;
2000 const int hmask =
height - 1;
2003 const int start_idx = tu->
tbs[0].
c_idx;
2011 if (
i > 0 && max_index > 0)
2015 if (max_index > 0 && !
run_copy[
i - min_pos]) {
2017 &&
i > 0 && !run_type[
i - 1]) {
2022 run_type[
i] = run_type[
i - 1];
2029 const int prev_xc =
i > 0 ?
TRAV_X(
i - 1) : 0;
2030 const int prev_yc =
i > 0 ?
TRAV_Y(
i - 1) : 0;
2033 if (max_index > 0 && !
run_copy[
i - min_pos] && !run_type[
i]) {
2034 if (max_index - *
adjust > 0)
2037 const int ref_idx = !run_type[
i - 1] ?
2039 idx += (idx >= ref_idx);
2054 const int c_idx = tb->
c_idx;
2057 const int hs =
sps->hshift[c_idx] -
sps->hshift[start_idx];
2058 const int vs =
sps->vshift[c_idx] -
sps->vshift[start_idx];
2059 uint8_t *u8 = (uint8_t *)tb->
coeffs;
2060 uint16_t *u16 = (uint16_t *)tb->
coeffs;
2065 if (!(xc & hs) && !(yc & vs)) {
2090 const int max_entries = tree_type ==
SINGLE_TREE ? 31 : 15;
2091 const bool local_dual_tree = tree_type !=
SINGLE_TREE &&
2092 (!
IS_I(rsh) || (
IS_I(rsh) && !
sps->r->sps_qtbtt_dual_tree_intra_flag));
2093 bool escape_present =
false;
2097 int prev_run_pos = 0;
2099 int predictor_size, start, end,
ret;
2112 predictor_size = pp[start].
size;
2113 memset(reused, 0,
sizeof(reused[0]) * predictor_size);
2128 max_index = cu->
plt[start].
size - 1 + escape_present;
2129 if (max_index > 0) {
2158 if (pred_mode_plt_flag) {
2171 }
else if (!pred_mode_plt_flag) {
2185 const int is_128 = cb_width > 64 || cb_height > 64;
2188 CodingUnit *cu =
add_cu(lc, x0, y0, cb_width, cb_height, cqt_depth, tree_type);
2195 if (
IS_I(rsh) && is_128)
2244 const int area = cb_width * cb_height;
2246 if ((
IS_I(rsh) &&
sps->r->sps_qtbtt_dual_tree_intra_flag) ||
2256 return 1 + !
IS_I(rsh);
2262 const int cb_width,
const int cb_height,
const VVCSplitMode split,
const int ch_type,
2268 if (mode_type_condition == 1)
2270 else if (mode_type_condition == 2) {
2273 mode_type = mode_type_curr;
2280 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2281 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
int part_idx,
2285 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2286 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
2289 #define CODING_TREE(x, idx) do { \
2290 ret = hls_coding_tree(lc, x, y0, cb_width / 2, cb_height, \
2291 qg_on_y, qg_on_c, cb_sub_div + 1, cqt_depth, mtt_depth + 1, \
2292 depth_offset, idx, SPLIT_BT_VER, tree_type, mode_type); \
2298 const int x1 = x0 + cb_width / 2;
2301 depth_offset += (x0 + cb_width >
pps->width) ? 1 : 0;
2303 if (x1 < pps->
width)
2312 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2313 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
2316 #define CODING_TREE(y, idx) do { \
2317 ret = hls_coding_tree(lc, x0, y, cb_width , cb_height / 2, \
2318 qg_on_y, qg_on_c, cb_sub_div + 1, cqt_depth, mtt_depth + 1, \
2319 depth_offset, idx, SPLIT_BT_HOR, tree_type, mode_type); \
2325 const int y1 = y0 + (cb_height / 2);
2328 depth_offset += (y0 + cb_height >
pps->height) ? 1 : 0;
2339 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2340 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
2343 #define CODING_TREE(x, w, sub_div, idx) do { \
2344 ret = hls_coding_tree(lc, x, y0, w, cb_height, \
2345 qg_on_y, qg_on_c, sub_div, cqt_depth, mtt_depth + 1, \
2346 depth_offset, idx, SPLIT_TT_VER, tree_type, mode_type); \
2352 const int x1 = x0 + cb_width / 4;
2353 const int x2 = x0 + cb_width * 3 / 4;
2369 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2370 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
2373 #define CODING_TREE(y, h, sub_div, idx) do { \
2374 ret = hls_coding_tree(lc, x0, y, cb_width, h, \
2375 qg_on_y, qg_on_c, sub_div, cqt_depth, mtt_depth + 1, \
2376 depth_offset, idx, SPLIT_TT_HOR, tree_type, mode_type); \
2382 const int y1 = y0 + (cb_height / 4);
2383 const int y2 = y0 + (3 * cb_height / 4);
2389 CODING_TREE(y0, cb_height / 4, cb_sub_div + 2, 0);
2390 CODING_TREE(y1, cb_height / 2, cb_sub_div + 1, 1);
2391 CODING_TREE(y2, cb_height / 4, cb_sub_div + 2, 2);
2399 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2400 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
2403 #define CODING_TREE(x, y, idx) do { \
2404 ret = hls_coding_tree(lc, x, y, cb_width / 2, cb_height / 2, \
2405 qg_on_y, qg_on_c, cb_sub_div + 2, cqt_depth + 1, 0, 0, \
2406 idx, SPLIT_QT, tree_type, mode_type); \
2412 const int x1 = x0 + cb_width / 2;
2413 const int y1 = y0 + cb_height / 2;
2417 if (x1 < pps->
width)
2421 if (x1 < pps->
width &&
2431 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2432 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
2444 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2445 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
int part_idx,
2456 if (
pps->r->pps_cu_qp_delta_enabled_flag && qg_on_y && cb_sub_div <= sh->cu_qp_delta_subdiv) {
2462 cb_sub_div <= sh->cu_chroma_qp_offset_subdiv) {
2467 can_split(lc, x0, y0, cb_width, cb_height, mtt_depth, depth_offset, part_idx,
2468 last_split_mode, tree_type_curr, mode_type_curr, &allowed);
2476 if (!(x0 & 31) && !(y0 & 31) && mtt_depth <= 1)
2480 cb_sub_div, cqt_depth, mtt_depth, depth_offset, tree_type, mode_type);
2490 ret =
hls_coding_unit(lc, x0, y0, cb_width, cb_height, cqt_depth, tree_type_curr, mode_type_curr);
2499 const int x0,
const int y0,
const int cb_size,
const int cqt_depth)
2504 const int cb_subdiv = 2 * cqt_depth;
2508 #define DUAL_TREE(x, y) do { \
2509 ret = dual_tree_implicit_qt_split(lc, x, y, cb_size / 2, cqt_depth + 1); \
2514 const int x1 = x0 + (cb_size / 2);
2515 const int y1 = y0 + (cb_size / 2);
2516 if (
pps->r->pps_cu_qp_delta_enabled_flag && cb_subdiv <= sh->cu_qp_delta_subdiv) {
2526 if (x1 < pps->
width)
2534 #define CODING_TREE(tree_type) do { \
2535 const int qg_on_y = tree_type == DUAL_TREE_LUMA; \
2536 ret = hls_coding_tree(lc, x0, y0, cb_size, cb_size, qg_on_y, !qg_on_y, \
2537 cb_subdiv, cqt_depth, 0, 0, 0, SPLIT_NONE, tree_type, MODE_TYPE_ALL); \
2548 #define SET_SAO(elem, value) \
2550 if (!sao_merge_up_flag && !sao_merge_left_flag) \
2551 sao->elem = value; \
2552 else if (sao_merge_left_flag) \
2553 sao->elem = CTB(fc->tab.sao, rx-1, ry).elem; \
2554 else if (sao_merge_up_flag) \
2555 sao->elem = CTB(fc->tab.sao, rx, ry-1).elem; \
2564 int sao_merge_left_flag = 0;
2565 int sao_merge_up_flag = 0;
2574 if (ry > 0 && !sao_merge_left_flag) {
2580 for (c_idx = 0; c_idx < (
fc->ps.sps->r->sps_chroma_format_idc ? 3 : 1); c_idx++) {
2582 if (!sao_used_flag) {
2597 for (
i = 0;
i < 4;
i++)
2601 for (
i = 0;
i < 4;
i++) {
2610 }
else if (c_idx != 2) {
2616 for (
i = 0;
i < 4;
i++) {
2624 sao->
offset_val[c_idx][
i + 1] *= 1 << (
fc->ps.sps->bit_depth -
FFMIN(10,
fc->ps.sps->bit_depth));
2640 uint8_t alf_use_aps_flag = 0;
2643 if (alf_use_aps_flag) {
2651 for (
int c_idx =
CB; c_idx <=
CR; c_idx++) {
2652 const uint8_t alf_enabled_flag =
2654 if (alf_enabled_flag) {
2658 if (alf->
ctb_flag[c_idx] &&
aps->num_chroma_filters > 1)
2663 if (
fc->ps.sps->r->sps_ccalf_enabled_flag) {
2666 for (
int i = 0;
i < 2;
i++) {
2667 if (cc_enabled[
i]) {
2683 const int x0,
const int y0,
const int ctu_idx,
const int rx,
const int ry)
2690 const unsigned int ctb_size =
sps->ctb_size_y;
2695 hls_sao(lc, x0 >>
sps->ctb_log2_size_y, y0 >>
sps->ctb_log2_size_y);
2699 if (
IS_I(rsh) &&
sps->r->sps_qtbtt_dual_tree_intra_flag)
2707 if (rx ==
pps->ctb_to_col_bd[rx + 1] - 1) {
2710 if (!end_of_slice_one_bit)
2713 if (ry ==
pps->ctb_to_row_bd[ry + 1] - 1) {
2715 if (!end_of_tile_one_bit)
2718 if (
fc->ps.sps->r->sps_entropy_coding_sync_enabled_flag) {
2720 if (!end_of_subset_one_bit)
2739 const int top =
pps->subpic_y[idx];
2740 const int bottom = top +
pps->subpic_height[idx];
2754 const int idx = mvf->
ref_idx[lx];
2757 max_y[lx][idx] =
FFMAX(max_y[lx][idx], y);
2764 for (
int sby = 0; sby <
mi->num_sb_y; sby++) {
2765 for (
int sbx = 0; sbx <
mi->num_sb_x; sbx++) {
2766 const int x0 = cu->
x0 + sbx * sbw;
2767 const int y0 = cu->
y0 + sby * sbh;
2769 for (
int lx = 0; lx < 2; lx++) {
2772 const int idx = mvf->
ref_idx[lx];
2775 max_y[lx][idx] =
FFMAX(max_y[lx][idx], y + max_dmvr_off);
2787 CTU *ctu =
fc->tab.ctus + rs;
2795 for (
int lx = 0; lx < 2; lx++)
2809 const int ctu_idx,
const int rs,
const int rx,
const int ry)
2814 const int x_ctb = rx <<
sps->ctb_log2_size_y;
2815 const int y_ctb = ry <<
sps->ctb_log2_size_y;
2816 const int ctb_size = 1 <<
sps->ctb_log2_size_y <<
sps->ctb_log2_size_y;
2820 if (rx ==
pps->ctb_to_col_bd[rx]) {
2840 const int rx,
const int ry,
const int rs)
2843 const int ctb_size =
fc->ps.sps->ctb_size_y;
2847 if (
fc->ps.pps->ctb_to_col_bd[rx] !=
fc->ps.pps->ctb_to_col_bd[rx + 1])
2849 if (
fc->ps.pps->ctb_to_row_bd[ry] !=
fc->ps.pps->ctb_to_row_bd[ry + 1])
2853 if (rx > 0 &&
fc->ps.pps->ctb_to_col_bd[rx] !=
fc->ps.pps->ctb_to_col_bd[rx - 1])
2855 if (rx > 0 &&
fc->tab.slice_idx[rs] !=
fc->tab.slice_idx[rs - 1])
2857 if (ry > 0 &&
fc->ps.pps->ctb_to_row_bd[ry] !=
fc->ps.pps->ctb_to_row_bd[ry - 1])
2859 if (ry > 0 &&
fc->tab.slice_idx[rs] !=
fc->tab.slice_idx[rs -
fc->ps.pps->ctb_width])
2868 (
fc->ps.pps->ctb_to_row_bd[ry] ==
fc->ps.pps->ctb_to_row_bd[ry - 1]);
2873 const int x0,
const int y0,
const int w,
const int h)
2908 const int min_cb_log2_size_y =
fc->ps.sps->min_cb_log2_size_y;
2909 const int x = xc >> min_cb_log2_size_y;
2910 const int y = yc >> min_cb_log2_size_y;
2911 return fc->tab.qp[
LUMA][x + y *
fc->ps.pps->min_cb_width];
2915 const int bit_depth,
const int persistent_rice_adaptation_enabled_flag)
2919 persistent_rice_adaptation_enabled_flag ? 2 * (
av_log2(
bit_depth - 10)) : 0;
2925 const bool has_chroma = chroma_format_idc && tree_type !=
DUAL_TREE_LUMA;
2928 *start = has_luma ?
LUMA :
CB;