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;
1174 const int log2_min_cb_size =
sps->min_cb_log2_size_y;
1175 const int x_cb = cu->
x0 >> log2_min_cb_size;
1176 const int y_cb = cu->
y0 >> log2_min_cb_size;
1177 const int ch_type = cu->
ch_type;
1180 x = y_cb *
pps->min_cb_width + x_cb;
1181 for (y = 0; y < (cu->
cb_height >> log2_min_cb_size); y++) {
1185 fc->tab.cb_pos_x[ch_type][x +
i] = cu->
x0;
1186 fc->tab.cb_pos_y[ch_type][x +
i] = cu->
y0;
1192 x +=
pps->min_cb_width;
1201 const int rx = x0 >>
sps->ctb_log2_size_y;
1202 const int ry = y0 >>
sps->ctb_log2_size_y;
1220 const int cb_width,
const int cb_height,
const int cqt_depth,
const VVCTreeType tree_type)
1229 memset(&cu->
pu, 0,
sizeof(cu->
pu));
1272 for (
int j = 0; j < tu->
nb_tbs; j++) {
1290 const int diff[] = {
1297 mmvd[1] = mmvd[0] = *mmvd_offset;
1302 mmvd[
i] = *mmvd_offset;
1307 mmvd[o].
x = sign ? -mmvd[
i].
x : mmvd[
i].
x;
1308 mmvd[o].
y = sign ? -mmvd[
i].
y : mmvd[
i].
y;
1311 mvf->
mv[0].
x += mmvd[0].
x;
1312 mvf->
mv[0].
y += mmvd[0].
y;
1313 mvf->
mv[1].
x += mmvd[1].
x;
1314 mvf->
mv[1].
y += mmvd[1].
y;
1317 mvf->
mv[idx].
x += mmvd_offset->
x;
1318 mvf->
mv[idx].
y += mmvd_offset->
y;
1328 for (
int i = 0;
i < 2;
i++) {
1331 mi->mv[
i][0] = mvf->
mv[
i];
1352 int merge_subblock_idx = 0;
1354 if (
ph->max_num_subblock_merge_cand > 1) {
1371 if (
sps->r->sps_mmvd_enabled_flag)
1374 int mmvd_cand_flag = 0;
1375 if (
sps->max_num_merge_cand > 1)
1378 merge_idx = mmvd_cand_flag;
1379 }
else if (
sps->max_num_merge_cand > 1) {
1396 if (ciip_avaiable && gpm_avaiable)
1398 return sps->r->sps_ciip_enabled_flag && !cu->
skip_flag &&
1407 int merge_gpm_idx[2];
1412 merge_gpm_idx[1] = 0;
1413 if (
sps->max_num_gpm_merge_cand > 2)
1429 if (
sps->max_num_merge_cand > 1)
1449 const int is_128 = cb_width == 128 || cb_height == 128;
1450 const int ciip_avaiable =
sps->r->sps_ciip_enabled_flag &&
1451 !cu->
skip_flag && (cb_width * cb_height >= 64);
1452 const int gpm_avaiable =
sps->r->sps_gpm_enabled_flag &&
IS_B(rsh) &&
1453 (cb_width >= 8) && (cb_height >=8) &&
1454 (cb_width < 8 * cb_height) && (cb_height < 8 *cb_width);
1456 int regular_merge_flag = 1;
1458 if (!is_128 && (ciip_avaiable || gpm_avaiable))
1460 if (regular_merge_flag) {
1481 if (
sps->max_num_ibc_merge_cand > 1)
1521 for (
int i = 0;
i < 2;
i++) {
1525 for (
int i = 0;
i < 2;
i++) {
1530 for (
int i = 0;
i < 2;
i++) {
1551 if (
sps->r->sps_bcw_enabled_flag &&
mi->pred_flag ==
PF_BI &&
1552 !
w->weight_flag[
L0][
LUMA][
mi->ref_idx[0]] &&
1553 !
w->weight_flag[
L1][
LUMA][
mi->ref_idx[1]] &&
1556 cb_width * cb_height >= 256) {
1569 else if (sym_mvd_flag)
1575 const int num_cp_mv,
const int lx)
1581 int has_no_zero_mvd = 0;
1583 if (lx ==
L1 &&
ph->r->ph_mvd_l1_zero_flag &&
mi->pred_flag ==
PF_BI) {
1584 for (
int j = 0; j < num_cp_mv; j++)
1587 Mv *mvd0 = &mvds[lx][0];
1589 mvd0->
x = -mvds[
L0][0].x;
1590 mvd0->
y = -mvds[
L0][0].y;
1594 has_no_zero_mvd |= (mvd0->
x || mvd0->
y);
1595 for (
int j = 1; j < num_cp_mv; j++) {
1596 Mv *mvd = &mvds[lx][j];
1600 has_no_zero_mvd |= (mvd->
x || mvd->
y);
1603 return has_no_zero_mvd;
1609 for (
int i = 0;
i < 2;
i++) {
1611 if (
mi->pred_flag &
mask) {
1612 for (
int j = 0; j < num_cp_mv; j++) {
1613 const Mv *mvd = &mvds[
i][j];
1614 mi->mv[
i][j].x += mvd->
x * (1 << amvr_shift);
1615 mi->mv[
i][j].y += mvd->
y * (1 << amvr_shift);
1628 int mvp_l0_flag = 0;
1638 if (
sps->max_num_ibc_merge_cand > 1)
1640 if (
sps->r->sps_amvr_enabled_flag && (
mv->x ||
mv->y))
1664 int mvp_lx_flag[2] = {0};
1665 int cu_affine_type_flag = 0;
1667 int amvr_enabled, has_no_zero_mvd = 0, amvr_shift;
1671 if (
sps->r->sps_affine_enabled_flag && cb_width >= 16 && cb_height >= 16) {
1678 num_cp_mv =
mi->motion_model_idc + 1;
1680 if (
sps->r->sps_smvd_enabled_flag && !
ph->r->ph_mvd_l1_zero_flag &&
1685 for (
int i =
L0;
i <=
L1;
i++) {
1687 if (
mi->pred_flag != pred_flag) {
1689 has_no_zero_mvd |=
mvds_decode(lc, mvds, num_cp_mv,
i);
1695 sps->r->sps_amvr_enabled_flag :
sps->r->sps_affine_amvr_enabled_flag;
1696 amvr_enabled &= has_no_zero_mvd;
1700 mi->hpel_if_idx = amvr_shift == 3;
1703 if (
mi->motion_model_idc)
1710 if (
mi->motion_model_idc)
1726 const int poc =
ph->poc;
1728 const int8_t *ref_idx =
mi->ref_idx;
1737 (poc - rp0->
poc == rp1->
poc - poc) &&
1746 if (!
ph->r->ph_bdof_disabled_flag &&
1751 if (!
ph->r->ph_dmvr_disabled_flag &&
1785 MvField *dmvr_mvf =
fc->ref->tab_dmvr_mvf + idx;
1787 memcpy(dmvr_mvf, mvf,
sizeof(
MvField) *
w);
1835 for (
int c = start;
c < end;
c++) {
1850 bool *predictor_reused,
const int predictor_size,
const int max_entries)
1853 int nb_predicted = 0;
1855 if (local_dual_tree) {
1860 for (
int i = 0;
i < predictor_size && nb_predicted < max_entries;
i++) {
1871 predictor_reused[
i] =
true;
1872 for (
int c = start;
c < end;
c++)
1877 for (
int c = start;
c < end;
c++)
1884 const int start,
const int end,
const int max_entries)
1888 const int nb_predicted = cu->
plt[start].
size;
1890 const int size = nb_predicted + nb_signaled;
1893 if (nb_signaled < 0)
1896 for (
int c = start;
c < end;
c++) {
1898 for (
int i = nb_predicted;
i <
size;
i++) {
1900 if (dual_tree_luma) {
1912 bool *predictor_reused,
const int predictor_size)
1917 if (local_dual_tree) {
1922 for (
int c = start;
c < end;
c++) {
1928 for (
int j = 0; j < predictor_size &&
i < max_predictor; j++) {
1929 if (!predictor_reused[j]) {
1948 const bool has_qp_delta = escape_present &&
1960 #define PALETTE_SET_PIXEL(xc, yc, pix) \
1962 const int off = ((xc) >> hs) + ((yc) >> vs) * tb->tb_width; \
1963 if (sps->bit_depth == 8) \
1969 #define PALETTE_INDEX(x, y) index[(y) * cu->cb_width + (x)]
1974 #define TRAV_COL(p, wlog, mask) ((p & mask) ^ (-((p >> wlog) & 1) & mask))
1975 #define TRAV_ROW(p, hlog) (p >> hlog)
1976 #define TRAV(trans, p, wlog, hlog, mask) (trans ? TRAV_ROW((p), hlog) : TRAV_COL((p), wlog, mask))
1977 #define TRAV_X(pos) TRAV(transpose, pos, wlog2, hlog2, wmask)
1978 #define TRAV_Y(pos) TRAV(!transpose, pos, hlog2, wlog2, hmask)
1981 const int max_index,
const int subset_id,
const bool transpose,
1982 uint8_t *run_type, uint8_t *
index,
int *prev_run_pos,
bool *
adjust)
1987 const int min_pos = subset_id << 4;
1989 const int wmask = cu->
cb_width - 1;
2000 if (
i > 0 && max_index > 0)
2004 if (max_index > 0 && !
run_copy[
i - min_pos]) {
2006 &&
i > 0 && !run_type[
i - 1]) {
2011 run_type[
i] = run_type[
i - 1];
2018 const int prev_xc =
i > 0 ?
TRAV_X(
i - 1) : 0;
2019 const int prev_yc =
i > 0 ?
TRAV_Y(
i - 1) : 0;
2022 if (max_index > 0 && !
run_copy[
i - min_pos] && !run_type[
i]) {
2023 if (max_index - *
adjust > 0)
2026 const int ref_idx = !run_type[
i - 1] ?
2028 idx += (idx >= ref_idx);
2045 const int hs =
sps->hshift[
c];
2046 const int vs =
sps->vshift[
c];
2047 uint8_t *u8 = (uint8_t *)tb->
coeffs;
2048 uint16_t *u16 = (uint16_t *)tb->
coeffs;
2053 if (!(xc & hs) && !(yc & vs)) {
2078 const int max_entries = tree_type ==
SINGLE_TREE ? 31 : 15;
2079 const bool local_dual_tree = tree_type !=
SINGLE_TREE &&
2080 (!
IS_I(rsh) || (
IS_I(rsh) && !
sps->r->sps_qtbtt_dual_tree_intra_flag));
2081 bool escape_present =
false;
2085 int prev_run_pos = 0;
2087 int predictor_size, start, end,
ret;
2097 predictor_size = pp[start].
size;
2098 memset(reused, 0,
sizeof(reused[0]) * predictor_size);
2113 max_index = cu->
plt[start].
size - 1 + escape_present;
2114 if (max_index > 0) {
2141 if (pred_mode_plt_flag) {
2154 }
else if (!pred_mode_plt_flag) {
2168 const int is_128 = cb_width > 64 || cb_height > 64;
2171 CodingUnit *cu =
add_cu(lc, x0, y0, cb_width, cb_height, cqt_depth, tree_type);
2178 if (
IS_I(rsh) && is_128)
2227 const int area = cb_width * cb_height;
2229 if ((
IS_I(rsh) &&
sps->r->sps_qtbtt_dual_tree_intra_flag) ||
2239 return 1 + !
IS_I(rsh);
2245 const int cb_width,
const int cb_height,
const VVCSplitMode split,
const int ch_type,
2251 if (mode_type_condition == 1)
2253 else if (mode_type_condition == 2) {
2256 mode_type = mode_type_curr;
2263 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2264 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
int part_idx,
2268 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2269 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
2272 #define CODING_TREE(x, idx) do { \
2273 ret = hls_coding_tree(lc, x, y0, cb_width / 2, cb_height, \
2274 qg_on_y, qg_on_c, cb_sub_div + 1, cqt_depth, mtt_depth + 1, \
2275 depth_offset, idx, SPLIT_BT_VER, tree_type, mode_type); \
2281 const int x1 = x0 + cb_width / 2;
2284 depth_offset += (x0 + cb_width >
pps->width) ? 1 : 0;
2286 if (x1 < pps->
width)
2295 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2296 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
2299 #define CODING_TREE(y, idx) do { \
2300 ret = hls_coding_tree(lc, x0, y, cb_width , cb_height / 2, \
2301 qg_on_y, qg_on_c, cb_sub_div + 1, cqt_depth, mtt_depth + 1, \
2302 depth_offset, idx, SPLIT_BT_HOR, tree_type, mode_type); \
2308 const int y1 = y0 + (cb_height / 2);
2311 depth_offset += (y0 + cb_height >
pps->height) ? 1 : 0;
2322 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2323 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
2326 #define CODING_TREE(x, w, sub_div, idx) do { \
2327 ret = hls_coding_tree(lc, x, y0, w, cb_height, \
2328 qg_on_y, qg_on_c, sub_div, cqt_depth, mtt_depth + 1, \
2329 depth_offset, idx, SPLIT_TT_VER, tree_type, mode_type); \
2335 const int x1 = x0 + cb_width / 4;
2336 const int x2 = x0 + cb_width * 3 / 4;
2352 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2353 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
2356 #define CODING_TREE(y, h, sub_div, idx) do { \
2357 ret = hls_coding_tree(lc, x0, y, cb_width, h, \
2358 qg_on_y, qg_on_c, sub_div, cqt_depth, mtt_depth + 1, \
2359 depth_offset, idx, SPLIT_TT_HOR, tree_type, mode_type); \
2365 const int y1 = y0 + (cb_height / 4);
2366 const int y2 = y0 + (3 * cb_height / 4);
2372 CODING_TREE(y0, cb_height / 4, cb_sub_div + 2, 0);
2373 CODING_TREE(y1, cb_height / 2, cb_sub_div + 1, 1);
2374 CODING_TREE(y2, cb_height / 4, cb_sub_div + 2, 2);
2382 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2383 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
2386 #define CODING_TREE(x, y, idx) do { \
2387 ret = hls_coding_tree(lc, x, y, cb_width / 2, cb_height / 2, \
2388 qg_on_y, qg_on_c, cb_sub_div + 2, cqt_depth + 1, 0, 0, \
2389 idx, SPLIT_QT, tree_type, mode_type); \
2395 const int x1 = x0 + cb_width / 2;
2396 const int y1 = y0 + cb_height / 2;
2400 if (x1 < pps->
width)
2404 if (x1 < pps->
width &&
2414 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2415 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
2427 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2428 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
int part_idx,
2439 if (
pps->r->pps_cu_qp_delta_enabled_flag && qg_on_y && cb_sub_div <= sh->cu_qp_delta_subdiv) {
2445 cb_sub_div <= sh->cu_chroma_qp_offset_subdiv) {
2450 can_split(lc, x0, y0, cb_width, cb_height, mtt_depth, depth_offset, part_idx,
2451 last_split_mode, tree_type_curr, mode_type_curr, &allowed);
2459 if (!(x0 & 31) && !(y0 & 31) && mtt_depth <= 1)
2463 cb_sub_div, cqt_depth, mtt_depth, depth_offset, tree_type, mode_type);
2473 ret =
hls_coding_unit(lc, x0, y0, cb_width, cb_height, cqt_depth, tree_type_curr, mode_type_curr);
2482 const int x0,
const int y0,
const int cb_size,
const int cqt_depth)
2487 const int cb_subdiv = 2 * cqt_depth;
2491 #define DUAL_TREE(x, y) do { \
2492 ret = dual_tree_implicit_qt_split(lc, x, y, cb_size / 2, cqt_depth + 1); \
2497 const int x1 = x0 + (cb_size / 2);
2498 const int y1 = y0 + (cb_size / 2);
2499 if (
pps->r->pps_cu_qp_delta_enabled_flag && cb_subdiv <= sh->cu_qp_delta_subdiv) {
2509 if (x1 < pps->
width)
2517 #define CODING_TREE(tree_type) do { \
2518 const int qg_on_y = tree_type == DUAL_TREE_LUMA; \
2519 ret = hls_coding_tree(lc, x0, y0, cb_size, cb_size, qg_on_y, !qg_on_y, \
2520 cb_subdiv, cqt_depth, 0, 0, 0, SPLIT_NONE, tree_type, MODE_TYPE_ALL); \
2531 #define SET_SAO(elem, value) \
2533 if (!sao_merge_up_flag && !sao_merge_left_flag) \
2534 sao->elem = value; \
2535 else if (sao_merge_left_flag) \
2536 sao->elem = CTB(fc->tab.sao, rx-1, ry).elem; \
2537 else if (sao_merge_up_flag) \
2538 sao->elem = CTB(fc->tab.sao, rx, ry-1).elem; \
2547 int sao_merge_left_flag = 0;
2548 int sao_merge_up_flag = 0;
2557 if (ry > 0 && !sao_merge_left_flag) {
2563 for (c_idx = 0; c_idx < (
fc->ps.sps->r->sps_chroma_format_idc ? 3 : 1); c_idx++) {
2565 if (!sao_used_flag) {
2580 for (
i = 0;
i < 4;
i++)
2584 for (
i = 0;
i < 4;
i++) {
2593 }
else if (c_idx != 2) {
2599 for (
i = 0;
i < 4;
i++) {
2607 sao->
offset_val[c_idx][
i + 1] *= 1 << (
fc->ps.sps->bit_depth -
FFMIN(10,
fc->ps.sps->bit_depth));
2623 uint8_t alf_use_aps_flag = 0;
2626 if (alf_use_aps_flag) {
2634 for (
int c_idx =
CB; c_idx <=
CR; c_idx++) {
2635 const uint8_t alf_enabled_flag =
2637 if (alf_enabled_flag) {
2641 if (alf->
ctb_flag[c_idx] &&
aps->num_chroma_filters > 1)
2646 if (
fc->ps.sps->r->sps_ccalf_enabled_flag) {
2649 for (
int i = 0;
i < 2;
i++) {
2650 if (cc_enabled[
i]) {
2666 const int x0,
const int y0,
const int ctu_idx,
const int rx,
const int ry)
2673 const unsigned int ctb_size =
sps->ctb_size_y;
2678 hls_sao(lc, x0 >>
sps->ctb_log2_size_y, y0 >>
sps->ctb_log2_size_y);
2682 if (
IS_I(rsh) &&
sps->r->sps_qtbtt_dual_tree_intra_flag)
2690 if (rx ==
pps->ctb_to_col_bd[rx + 1] - 1) {
2693 if (!end_of_slice_one_bit)
2696 if (ry ==
pps->ctb_to_row_bd[ry + 1] - 1) {
2698 if (!end_of_tile_one_bit)
2701 if (
fc->ps.sps->r->sps_entropy_coding_sync_enabled_flag) {
2703 if (!end_of_subset_one_bit)
2722 const int top =
pps->subpic_y[idx];
2723 const int bottom = top +
pps->subpic_height[idx];
2737 const int idx = mvf->
ref_idx[lx];
2740 max_y[lx][idx] =
FFMAX(max_y[lx][idx], y);
2747 for (
int sby = 0; sby <
mi->num_sb_y; sby++) {
2748 for (
int sbx = 0; sbx <
mi->num_sb_x; sbx++) {
2749 const int x0 = cu->
x0 + sbx * sbw;
2750 const int y0 = cu->
y0 + sby * sbh;
2752 for (
int lx = 0; lx < 2; lx++) {
2755 const int idx = mvf->
ref_idx[lx];
2758 max_y[lx][idx] =
FFMAX(max_y[lx][idx], y + max_dmvr_off);
2770 CTU *ctu =
fc->tab.ctus + rs;
2778 for (
int lx = 0; lx < 2; lx++)
2792 const int ctu_idx,
const int rs,
const int rx,
const int ry)
2797 const int x_ctb = rx <<
sps->ctb_log2_size_y;
2798 const int y_ctb = ry <<
sps->ctb_log2_size_y;
2799 const int ctb_size = 1 <<
sps->ctb_log2_size_y <<
sps->ctb_log2_size_y;
2803 if (rx ==
pps->ctb_to_col_bd[rx]) {
2823 const int rx,
const int ry,
const int rs)
2826 const int ctb_size =
fc->ps.sps->ctb_size_y;
2830 if (
fc->ps.pps->ctb_to_col_bd[rx] !=
fc->ps.pps->ctb_to_col_bd[rx + 1])
2832 if (
fc->ps.pps->ctb_to_row_bd[ry] !=
fc->ps.pps->ctb_to_row_bd[ry + 1])
2836 if (rx > 0 &&
fc->ps.pps->ctb_to_col_bd[rx] !=
fc->ps.pps->ctb_to_col_bd[rx - 1])
2838 if (rx > 0 &&
fc->tab.slice_idx[rs] !=
fc->tab.slice_idx[rs - 1])
2840 if (ry > 0 &&
fc->ps.pps->ctb_to_row_bd[ry] !=
fc->ps.pps->ctb_to_row_bd[ry - 1])
2842 if (ry > 0 &&
fc->tab.slice_idx[rs] !=
fc->tab.slice_idx[rs -
fc->ps.pps->ctb_width])
2851 (
fc->ps.pps->ctb_to_row_bd[ry] ==
fc->ps.pps->ctb_to_row_bd[ry - 1]);
2856 const int x0,
const int y0,
const int w,
const int h)
2891 const int min_cb_log2_size_y =
fc->ps.sps->min_cb_log2_size_y;
2892 const int x = xc >> min_cb_log2_size_y;
2893 const int y = yc >> min_cb_log2_size_y;
2894 return fc->tab.qp[
LUMA][x + y *
fc->ps.pps->min_cb_width];
2898 const int bit_depth,
const int persistent_rice_adaptation_enabled_flag)
2902 persistent_rice_adaptation_enabled_flag ? 2 * (
av_log2(
bit_depth - 10)) : 0;
2908 const bool has_chroma = chroma_format_idc && tree_type !=
DUAL_TREE_LUMA;
2911 *start = has_luma ?
LUMA :
CB;