31 #define PROF_TEMP_SIZE (PROF_BLOCK_SIZE) * sizeof(int16_t)
33 #define TAB_MSM(fc, depth, x, y) fc->tab.msm[(depth)][((y) >> 5) * fc->ps.pps->width32 + ((x) >> 5)]
34 #define TAB_ISPMF(fc, x, y) fc->tab.ispmf[((y) >> 6) * fc->ps.pps->width64 + ((x) >> 6)]
46 const int hs =
fc->ps.sps->hshift[tb->
c_idx];
47 const int vs =
fc->ps.sps->vshift[tb->
c_idx];
48 const int is_chroma = tb->
c_idx != 0;
52 for (
int y = y_tb; y < end; y++) {
53 const int off = y *
fc->ps.pps->min_tu_width + x_tb;
69 memset(
tab + off, v,
w);
80 const int ctb_log2_size =
sps->ctb_log2_size_y;
81 const int ctb_size_mask = (1 << ctb_log2_size) - 1;
84 const int min_cb_width =
fc->ps.pps->min_cb_width;
85 const int x_cb = cu->
x0 >>
sps->min_cb_log2_size_y;
86 const int y_cb = cu->
y0 >>
sps->min_cb_log2_size_y;
87 const int rx = cu->
x0 >> ctb_log2_size;
88 const int ry = cu->
y0 >> ctb_log2_size;
89 const int in_same_ctb_a = ((xQg - 1) >> ctb_log2_size) == rx && (yQg >> ctb_log2_size) == ry;
90 const int in_same_ctb_b = (xQg >> ctb_log2_size) == rx && ((yQg - 1) >> ctb_log2_size) == ry;
91 int qPy_pred, qPy_a, qPy_b;
94 const int first_qg_in_ctu = !(xQg & ctb_size_mask) && !(yQg & ctb_size_mask);
95 const int qPy_up =
fc->tab.qp[
LUMA][x_cb + (y_cb - 1) * min_cb_width];
96 if (first_qg_in_ctu &&
pps->ctb_to_col_bd[xQg >> ctb_log2_size] == xQg >> ctb_log2_size)
107 qPy_b =
fc->tab.qp[
LUMA][x_cb + (y_cb - 1) * min_cb_width];
113 qPy_a =
fc->tab.qp[
LUMA][(x_cb - 1) + y_cb * min_cb_width];
115 av_assert2(qPy_a >= -
fc->ps.sps->qp_bd_offset && qPy_a <= 63);
116 av_assert2(qPy_b >= -
fc->ps.sps->qp_bd_offset && qPy_b <= 63);
118 return (qPy_a + qPy_b + 1) >> 1;
126 const int log2_min_cb_size =
fc->ps.sps->min_cb_log2_size_y;
127 const int x_cb = cu->
x0 >> log2_min_cb_size;
128 const int y_cb = cu->
y0 >> log2_min_cb_size;
131 int x = y_cb *
pps->min_cb_width + x_cb;
133 for (
int y = 0; y < (cb_height >> log2_min_cb_size); y++) {
134 const int width = cb_width >> log2_min_cb_size;
137 x +=
pps->min_cb_width;
160 if (cu_qp_delta > (31 +
sps->qp_bd_offset / 2) || cu_qp_delta < -(32 +
sps->qp_bd_offset / 2))
165 int off =
sps->qp_bd_offset;
166 ep->
qp_y =
FFUMOD(ep->
qp_y + cu_qp_delta + 64 + 2 * off, 64 + off) - off;
191 const int x_center = cu->
x0 + cu->
cb_width / 2;
196 const int sh_chroma_qp_offset[] = {
203 for (
int i =
CB - 1;
i <
CR +
sps->r->sps_joint_cbcr_enabled_flag;
i++) {
204 qp =
sps->chroma_qp_table[
i][qp_chroma];
237 tu->
width = tu_width;
248 const int x0,
const int y0,
const int tb_width,
const int tb_height,
const int c_idx)
267 lc->
coeffs += tb_width * tb_height;
268 tu->
avail[!!c_idx] =
true;
273 const int sub_tu_index,
const int is_isp,
const int is_chroma_coded)
275 uint8_t tu_y_coded_flag = 0;
279 if (!is_sbt_not_coded) {
289 return tu_y_coded_flag;
297 if ((is_128 || is_chroma_coded) &&
300 if (cu_chroma_qp_offset_flag) {
301 int cu_chroma_qp_offset_idx = 0;
302 if (
pps->r->pps_chroma_qp_offset_list_len_minus1 > 0)
320 const int min_cb_width =
pps->min_cb_width;
325 const int is_sbt_not_coded = cu->
sbt_flag &&
327 const int chroma_available = tree_type !=
DUAL_TREE_LUMA &&
sps->r->sps_chroma_format_idc &&
328 (!is_isp || is_isp_last_tu);
329 int ret, xc, yc, wc, hc, is_chroma_coded;
335 const int x_cu = x0 >>
fc->ps.sps->min_cb_log2_size_y;
336 const int y_cu = y0 >>
fc->ps.sps->min_cb_log2_size_y;
340 hc =
SAMPLE_CTB(
fc->tab.cb_height[ch_type], x_cu, y_cu);
342 xc = x0, yc = y0, wc = tu_width, hc = tu_height;
345 if (chroma_available && !is_sbt_not_coded) {
355 has_qp_delta = (is_128 || tu->
coded_flag[
LUMA] || is_chroma_coded) &&
360 add_tb(tu, lc, x0, y0, tu_width, tu_height,
LUMA);
364 if (chroma_available) {
367 add_tb(tu, lc, xc, yc, wc >> hs, hc >> vs,
CB);
368 add_tb(tu, lc, xc, yc, wc >> hs, hc >> vs,
CR);
388 !cu->
sbt_flag && (is_chroma || !is_isp)) {
415 if (tu_width >
sps->max_tb_size_y || tu_height >
sps->max_tb_size_y) {
416 const int ver_split_first = tu_width >
sps->max_tb_size_y && tu_width > tu_height;
417 const int trafo_width = ver_split_first ? (tu_width / 2) : tu_width;
418 const int trafo_height = !ver_split_first ? (tu_height / 2) : tu_height;
420 #define TRANSFORM_TREE(x, y) do { \
421 ret = hls_transform_tree(lc, x, y, trafo_width, trafo_height, ch_type); \
440 #define TRANSFORM_UNIT(x, width, idx) do { \
441 ret = hls_transform_unit(lc, x, y0, width, tu_height, idx, ch_type); \
450 #undef TRANSFORM_UNIT
452 #define TRANSFORM_UNIT(y, height, idx) do { \
453 ret = hls_transform_unit(lc, x0, y, tu_width, height, idx, ch_type); \
462 #undef TRANSFORM_UNIT
489 if (tu_width >
sps->max_tb_size_y || tu_height >
sps->max_tb_size_y) {
490 const int ver_split_first = tu_width >
sps->max_tb_size_y && tu_width > tu_height;
491 const int trafo_width = ver_split_first ? (tu_width / 2) : tu_width;
492 const int trafo_height = !ver_split_first ? (tu_height / 2) : tu_height;
494 #define SKIPPED_TRANSFORM_TREE(x, y) do { \
495 int ret = skipped_transform_tree(lc, x, y, trafo_width, trafo_height); \
512 for (
int i = start;
i < end;
i++) {
526 int mtt_depth,
int depth_offset,
int part_idx,
VVCSplitMode last_split_mode,
529 int min_qt_size, max_bt_size, max_tt_size, max_mtt_depth;
535 int min_cb_size_y =
sps->min_cb_size_y;
536 int *qt = &
split->qt;
537 int *btv = &
split->btv;
538 int *bth = &
split->bth;
539 int *ttv = &
split->ttv;
540 int *tth = &
split->tth;
542 *qt = *bth = *btv = *tth = *ttv = 1;
548 if (cb_width <= min_qt_size)
552 int chroma_area = (cb_width >>
sps->hshift[1]) * (cb_height >>
sps->vshift[1]);
553 int chroma_width = cb_width >>
sps->hshift[1];
555 if (chroma_width == 8)
557 else if (chroma_width <= 4) {
558 if (chroma_width == 4)
563 *qt = *btv = *bth = *ttv = *tth = 0;
564 if (chroma_area <= 32) {
566 if (chroma_area <= 16)
575 int area = cb_width * cb_height;
581 if (cb_width <= 2 * min_cb_size_y) {
583 if (cb_width <= min_cb_size_y)
586 if (cb_height <= 2 * min_cb_size_y) {
588 if (cb_height <= min_cb_size_y)
591 if (cb_width > max_bt_size || cb_height > max_bt_size)
593 max_tt_size =
FFMIN(64, max_tt_size);
594 if (cb_width > max_tt_size || cb_height > max_tt_size)
596 if (mtt_depth >= max_mtt_depth)
597 *btv = *bth = *ttv = *tth = 0;
598 if (x0 + cb_width >
pps->width) {
602 if (y0 + cb_height <= pps->
height)
604 else if (cb_width > min_qt_size)
607 if (y0 + cb_height >
pps->height) {
608 *btv = *ttv = *tth = 0;
612 if (mtt_depth > 0 && part_idx == 1) {
618 if (cb_width <= 64 && cb_height > 64)
620 if (cb_width > 64 && cb_height <= 64)
628 if ((cb_width == 4 && cb_height == 8) || (cb_width == 8 && cb_height == 4))
639 if (!
sps->r->sps_cclm_enabled_flag)
641 if (!
sps->r->sps_qtbtt_dual_tree_intra_flag || !
IS_I(lc->
sc->
sh.
r) ||
sps->ctb_log2_size_y < 6)
644 const int x64 = x0 >> 6 << 6;
645 const int y64 = y0 >> 6 << 6;
646 const int y32 = y0 >> 5 << 5;
647 const int x64_cu = x64 >>
fc->ps.sps->min_cb_log2_size_y;
648 const int y64_cu = y64 >>
fc->ps.sps->min_cb_log2_size_y;
649 const int y32_cu = y32 >>
fc->ps.sps->min_cb_log2_size_y;
650 const int min_cb_width =
fc->ps.pps->min_cb_width;
651 const int depth =
SAMPLE_CTB(
fc->tab.cqt_depth[1], x64_cu, y64_cu);
652 const int min_depth =
fc->ps.sps->ctb_log2_size_y - 6;
656 enabled =
SAMPLE_CTB(
fc->tab.cb_width[1], x64_cu, y64_cu) == 64 &&
658 enabled |= depth == min_depth && msm64 ==
SPLIT_BT_HOR &&
659 SAMPLE_CTB(
fc->tab.cb_width[1], x64_cu, y32_cu) == 64 &&
661 enabled |= depth > min_depth;
665 const int w =
SAMPLE_CTB(
fc->tab.cb_width[0], x64_cu, y64_cu);
666 const int h =
SAMPLE_CTB(
fc->tab.cb_height[0], x64_cu, y64_cu);
667 const int depth0 =
SAMPLE_CTB(
fc->tab.cqt_depth[0], x64_cu, y64_cu);
669 ((
w < 64 ||
h < 64) && depth0 == min_depth))
678 static int less(
const void *
a,
const void *
b)
680 return *(
const int*)
a - *(
const int*)
b;
688 const int x0 = cu->
x0;
689 const int y0 = cu->
y0;
691 int intra_luma_not_planar_flag = 1;
692 int intra_luma_mpm_remainder = 0;
693 int intra_luma_mpm_flag = 1;
694 int intra_luma_mpm_idx = 0;
698 if (intra_luma_mpm_flag) {
701 if (intra_luma_not_planar_flag)
707 if (!intra_luma_not_planar_flag) {
711 const int x_a = (x0 - 1) >>
sps->min_cb_log2_size_y;
712 const int y_a = (y0 + cu->
cb_height - 1) >>
sps->min_cb_log2_size_y;
713 const int x_b = (x0 + cu->
cb_width - 1) >>
sps->min_cb_log2_size_y;
714 const int y_b = (y0 - 1) >>
sps->min_cb_log2_size_y;
715 int min_cb_width =
fc->ps.pps->min_cb_width;
739 cand[1] = 2 + ((
a + 61) % 64);
740 cand[2] = 2 + ((
a - 1) % 64);
741 cand[3] = 2 + ((
a + 60) % 64);
742 cand[4] = 2 + (
a % 64);
747 const int diff = maxab - minab;
751 cand[2] = 2 + ((minab + 61) % 64);
752 cand[3] = 2 + ((maxab - 1) % 64);
753 cand[4] = 2 + ((minab + 60) % 64);
754 }
else if (
diff >= 62) {
755 cand[2] = 2 + ((minab - 1) % 64);
756 cand[3] = 2 + ((maxab + 61) % 64);
757 cand[4] = 2 + (minab % 64);
758 }
else if (
diff == 2) {
759 cand[2] = 2 + ((minab - 1) % 64);
760 cand[3] = 2 + ((minab + 61) % 64);
761 cand[4] = 2 + ((maxab - 1) % 64);
763 cand[2] = 2 + ((minab + 61) % 64);
764 cand[3] = 2 + ((minab - 1) % 64);
765 cand[4] = 2 + ((maxab + 61) % 64);
769 cand[1] = 2 + ((maxab + 61 ) % 64);
770 cand[2] = 2 + ((maxab - 1) % 64);
771 cand[3] = 2 + ((maxab + 60 ) % 64);
772 cand[4] = 2 + (maxab % 64);
781 if (intra_luma_mpm_flag) {
782 pred = cand[intra_luma_mpm_idx];
785 pred = intra_luma_mpm_remainder + 1;
803 int lfnst_width, lfnst_height, min_lfnst;
812 for (
int j = 0; j < tu->
nb_tbs; j++) {
821 lfnst_width = cb_width >>
sps->hshift[1];
822 lfnst_height = cb_height >>
sps->vshift[1];
829 min_lfnst =
FFMIN(lfnst_width, lfnst_height);
833 if (min_lfnst >= 4) {
852 const uint8_t transform_skip_flag = cu->
tus.
head->
tbs[0].
ts;
855 !transform_skip_flag &&
FFMAX(cb_width, cb_height) <= 32 &&
869 const int x_center = (cu->
x0 + cu->
cb_width / 2) >>
sps->min_cb_log2_size_y;
870 const int y_center = (cu->
y0 + cu->
cb_height / 2) >>
sps->min_cb_log2_size_y;
871 const int min_cb_width =
pps->min_cb_width;
872 const int intra_mip_flag =
SAMPLE_CTB(
fc->tab.imf, x_center, y_center);
873 const int cu_pred_mode =
SAMPLE_CTB(
fc->tab.cpm[0], x_center, y_center);
874 const int intra_pred_mode_y =
SAMPLE_CTB(
fc->tab.ipm, x_center, y_center);
876 if (intra_mip_flag) {
883 return intra_pred_mode_y;
887 const int cclm_mode_flag,
const int cclm_mode_idx,
const int intra_chroma_pred_mode)
893 const int x_cb = cu->
x0 >>
sps->min_cb_log2_size_y;
894 const int y_cb = cu->
y0 >>
sps->min_cb_log2_size_y;
895 const int min_cb_width =
pps->min_cb_width;
896 const int intra_mip_flag =
SAMPLE_CTB(
fc->tab.imf, x_cb, y_cb);
911 if (cclm_mode_flag) {
913 }
else if (intra_chroma_pred_mode == 4){
941 0, 1, 61, 62, 63, 64, 65, 66, 2, 3, 5, 6, 8, 10, 12, 13,
942 14, 16, 18, 20, 22, 23, 24, 26, 28, 30, 31, 33, 34, 35, 36, 37,
943 38, 39, 40, 41, 41, 42, 43, 43, 44, 44, 45, 45, 46, 47, 48, 48,
944 49, 49, 50, 51, 51, 52, 52, 53, 54, 55, 55, 56, 56, 57, 57, 58,
952 int intra_mip_transposed_flag,
int intra_mip_mode)
954 return (intra_mip_mode << 2) | (intra_mip_transposed_flag << 1) | intra_mip_flag;
963 const int log2_min_cb_size =
sps->min_cb_log2_size_y;
964 const int x0 = cu->
x0;
965 const int y0 = cu->
y0;
966 const int x_cb = x0 >> log2_min_cb_size;
967 const int y_cb = y0 >> log2_min_cb_size;
972 if (
sps->r->sps_bdpcm_enabled_flag && cb_width <= sps->max_ts_size && cb_height <= sps->max_ts_size)
977 if (
sps->r->sps_mip_enabled_flag)
982 int x = y_cb *
pps->min_cb_width + x_cb;
983 for (
int y = 0; y < (cb_height>>log2_min_cb_size); y++) {
984 int width = cb_width>>log2_min_cb_size;
986 intra_mip_transposed_flag, intra_mip_mode);
987 memset(&
fc->tab.imf[x], mip_info,
width);
988 x +=
pps->min_cb_width;
992 int intra_subpartitions_mode_flag = 0;
993 if (
sps->r->sps_mrl_enabled_flag && ((y0 %
sps->ctb_size_y) > 0))
996 (cb_width <= sps->max_tb_size_y && cb_height <= sps->max_tb_size_y) &&
1000 if (!(x0 & 63) && !(y0 & 63))
1001 TAB_ISPMF(
fc, x0, y0) = intra_subpartitions_mode_flag;
1016 int cclm_mode_flag = 0;
1017 int cclm_mode_idx = 0;
1018 int intra_chroma_pred_mode = 0;
1022 if (
sps->r->sps_bdpcm_enabled_flag &&
1060 int pred_mode_ibc_flag;
1064 if (!
IS_I(rsh) ||
sps->r->sps_ibc_enabled_flag) {
1067 (
sps->r->sps_ibc_enabled_flag && !is_128))) {
1087 pred_mode_ibc_flag = 1;
1089 pred_mode_ibc_flag = 0;
1091 pred_mode_ibc_flag = (
IS_I(rsh)) ?
sps->r->sps_ibc_enabled_flag : 0;
1093 if (pred_mode_ibc_flag)
1121 && cb_width <= sps->max_tb_size_y && cb_height <= sps->max_tb_size_y) {
1122 const int sbt_ver_h = cb_width >= 8;
1123 const int sbt_hor_h = cb_height >= 8;
1125 if (sbt_ver_h || sbt_hor_h)
1128 const int sbt_ver_q = cb_width >= 16;
1129 const int sbt_hor_q = cb_height >= 16;
1130 int cu_sbt_quad_flag = 0;
1132 if ((sbt_ver_h || sbt_hor_h) && (sbt_ver_q || sbt_hor_q))
1134 if (cu_sbt_quad_flag) {
1136 if (sbt_ver_q && sbt_hor_q)
1140 if (sbt_ver_h && sbt_hor_h)
1146 const int sbt_min = cu_sbt_quad_flag ? 1 : 2;
1173 const int log2_min_cb_size =
sps->min_cb_log2_size_y;
1174 const int x_cb = cu->
x0 >> log2_min_cb_size;
1175 const int y_cb = cu->
y0 >> log2_min_cb_size;
1176 const int ch_type = cu->
ch_type;
1179 x = y_cb *
pps->min_cb_width + x_cb;
1180 for (y = 0; y < (cu->
cb_height >> log2_min_cb_size); y++) {
1184 fc->tab.cb_pos_x[ch_type][x +
i] = cu->
x0;
1185 fc->tab.cb_pos_y[ch_type][x +
i] = cu->
y0;
1191 x +=
pps->min_cb_width;
1200 const int rx = x0 >>
sps->ctb_log2_size_y;
1201 const int ry = y0 >>
sps->ctb_log2_size_y;
1219 const int cb_width,
const int cb_height,
const int cqt_depth,
const VVCTreeType tree_type)
1228 memset(&cu->
pu, 0,
sizeof(cu->
pu));
1271 for (
int j = 0; j < tu->
nb_tbs; j++) {
1289 const int diff[] = {
1296 mmvd[1] = mmvd[0] = *mmvd_offset;
1301 mmvd[
i] = *mmvd_offset;
1306 mmvd[o].
x = sign ? -mmvd[
i].
x : mmvd[
i].
x;
1307 mmvd[o].
y = sign ? -mmvd[
i].
y : mmvd[
i].
y;
1310 mvf->
mv[0].
x += mmvd[0].
x;
1311 mvf->
mv[0].
y += mmvd[0].
y;
1312 mvf->
mv[1].
x += mmvd[1].
x;
1313 mvf->
mv[1].
y += mmvd[1].
y;
1316 mvf->
mv[idx].
x += mmvd_offset->
x;
1317 mvf->
mv[idx].
y += mmvd_offset->
y;
1327 for (
int i = 0;
i < 2;
i++) {
1330 mi->mv[
i][0] = mvf->
mv[
i];
1351 int merge_subblock_idx = 0;
1353 if (
ph->max_num_subblock_merge_cand > 1) {
1370 if (
sps->r->sps_mmvd_enabled_flag)
1373 int mmvd_cand_flag = 0;
1374 if (
sps->max_num_merge_cand > 1)
1377 merge_idx = mmvd_cand_flag;
1378 }
else if (
sps->max_num_merge_cand > 1) {
1395 if (ciip_avaiable && gpm_avaiable)
1397 return sps->r->sps_ciip_enabled_flag && !cu->
skip_flag &&
1406 int merge_gpm_idx[2];
1411 merge_gpm_idx[1] = 0;
1412 if (
sps->max_num_gpm_merge_cand > 2)
1428 if (
sps->max_num_merge_cand > 1)
1448 const int is_128 = cb_width == 128 || cb_height == 128;
1449 const int ciip_avaiable =
sps->r->sps_ciip_enabled_flag &&
1450 !cu->
skip_flag && (cb_width * cb_height >= 64);
1451 const int gpm_avaiable =
sps->r->sps_gpm_enabled_flag &&
IS_B(rsh) &&
1452 (cb_width >= 8) && (cb_height >=8) &&
1453 (cb_width < 8 * cb_height) && (cb_height < 8 *cb_width);
1455 int regular_merge_flag = 1;
1457 if (!is_128 && (ciip_avaiable || gpm_avaiable))
1459 if (regular_merge_flag) {
1480 if (
sps->max_num_ibc_merge_cand > 1)
1520 for (
int i = 0;
i < 2;
i++) {
1524 for (
int i = 0;
i < 2;
i++) {
1529 for (
int i = 0;
i < 2;
i++) {
1550 if (
sps->r->sps_bcw_enabled_flag &&
mi->pred_flag ==
PF_BI &&
1551 !
w->weight_flag[
L0][
LUMA][
mi->ref_idx[0]] &&
1552 !
w->weight_flag[
L1][
LUMA][
mi->ref_idx[1]] &&
1555 cb_width * cb_height >= 256) {
1568 else if (sym_mvd_flag)
1574 const int num_cp_mv,
const int lx)
1580 int has_no_zero_mvd = 0;
1582 if (lx ==
L1 &&
ph->r->ph_mvd_l1_zero_flag &&
mi->pred_flag ==
PF_BI) {
1583 for (
int j = 0; j < num_cp_mv; j++)
1586 Mv *mvd0 = &mvds[lx][0];
1588 mvd0->
x = -mvds[
L0][0].x;
1589 mvd0->
y = -mvds[
L0][0].y;
1593 has_no_zero_mvd |= (mvd0->
x || mvd0->
y);
1594 for (
int j = 1; j < num_cp_mv; j++) {
1595 Mv *mvd = &mvds[lx][j];
1599 has_no_zero_mvd |= (mvd->
x || mvd->
y);
1602 return has_no_zero_mvd;
1608 for (
int i = 0;
i < 2;
i++) {
1610 if (
mi->pred_flag &
mask) {
1611 for (
int j = 0; j < num_cp_mv; j++) {
1612 const Mv *mvd = &mvds[
i][j];
1613 mi->mv[
i][j].x += mvd->
x * (1 << amvr_shift);
1614 mi->mv[
i][j].y += mvd->
y * (1 << amvr_shift);
1627 int mvp_l0_flag = 0;
1637 if (
sps->max_num_ibc_merge_cand > 1)
1639 if (
sps->r->sps_amvr_enabled_flag && (
mv->x ||
mv->y))
1663 int mvp_lx_flag[2] = {0};
1664 int cu_affine_type_flag = 0;
1666 int amvr_enabled, has_no_zero_mvd = 0, amvr_shift;
1670 if (
sps->r->sps_affine_enabled_flag && cb_width >= 16 && cb_height >= 16) {
1677 num_cp_mv =
mi->motion_model_idc + 1;
1679 if (
sps->r->sps_smvd_enabled_flag && !
ph->r->ph_mvd_l1_zero_flag &&
1684 for (
int i =
L0;
i <=
L1;
i++) {
1686 if (
mi->pred_flag != pred_flag) {
1688 has_no_zero_mvd |=
mvds_decode(lc, mvds, num_cp_mv,
i);
1694 sps->r->sps_amvr_enabled_flag :
sps->r->sps_affine_amvr_enabled_flag;
1695 amvr_enabled &= has_no_zero_mvd;
1699 mi->hpel_if_idx = amvr_shift == 3;
1702 if (
mi->motion_model_idc)
1709 if (
mi->motion_model_idc)
1725 const int poc =
ph->poc;
1727 const int8_t *ref_idx =
mi->ref_idx;
1736 (poc - rp0->
poc == rp1->
poc - poc) &&
1745 if (!
ph->r->ph_bdof_disabled_flag &&
1750 if (!
ph->r->ph_dmvr_disabled_flag &&
1784 MvField *dmvr_mvf =
fc->ref->tab_dmvr_mvf + idx;
1786 memcpy(dmvr_mvf, mvf,
sizeof(
MvField) *
w);
1834 for (
int c = start;
c < end;
c++) {
1849 bool *predictor_reused,
const int predictor_size,
const int max_entries)
1852 int nb_predicted = 0;
1854 if (local_dual_tree) {
1859 for (
int i = 0;
i < predictor_size && nb_predicted < max_entries;
i++) {
1867 if (
i >= predictor_size)
1870 predictor_reused[
i] =
true;
1871 for (
int c = start;
c < end;
c++)
1876 for (
int c = start;
c < end;
c++)
1883 const int start,
const int end,
const int max_entries)
1887 const int nb_predicted = cu->
plt[start].
size;
1889 const int size = nb_predicted + nb_signaled;
1892 if (
size > max_entries || nb_signaled < 0)
1895 for (
int c = start;
c < end;
c++) {
1897 for (
int i = nb_predicted;
i <
size;
i++) {
1899 if (dual_tree_luma) {
1911 bool *predictor_reused,
const int predictor_size)
1916 if (local_dual_tree) {
1921 for (
int c = start;
c < end;
c++) {
1927 for (
int j = 0; j < predictor_size &&
i < max_predictor; j++) {
1928 if (!predictor_reused[j]) {
1947 const bool has_qp_delta = escape_present &&
1959 #define PALETTE_SET_PIXEL(xc, yc, pix) \
1961 const int off = ((xc) >> hs) + ((yc) >> vs) * tb->tb_width; \
1962 if (sps->bit_depth == 8) \
1968 #define PALETTE_INDEX(x, y) index[(y) * cu->cb_width + (x)]
1973 #define TRAV_COL(p, wlog, mask) ((p & mask) ^ (-((p >> wlog) & 1) & mask))
1974 #define TRAV_ROW(p, hlog) (p >> hlog)
1975 #define TRAV(trans, p, wlog, hlog, mask) (trans ? TRAV_ROW((p), hlog) : TRAV_COL((p), wlog, mask))
1976 #define TRAV_X(pos) TRAV(transpose, pos, wlog2, hlog2, wmask)
1977 #define TRAV_Y(pos) TRAV(!transpose, pos, hlog2, wlog2, hmask)
1980 const int max_index,
const int subset_id,
const bool transpose,
1981 uint8_t *run_type, uint8_t *
index,
int *prev_run_pos,
bool *
adjust)
1986 const int min_pos = subset_id << 4;
1988 const int wmask = cu->
cb_width - 1;
1999 if (
i > 0 && max_index > 0)
2003 if (max_index > 0 && !
run_copy[
i - min_pos]) {
2005 &&
i > 0 && !run_type[
i - 1]) {
2010 run_type[
i] = run_type[
i - 1];
2017 const int prev_xc =
i > 0 ?
TRAV_X(
i - 1) : 0;
2018 const int prev_yc =
i > 0 ?
TRAV_Y(
i - 1) : 0;
2021 if (max_index > 0 && !
run_copy[
i - min_pos] && !run_type[
i]) {
2022 if (max_index - *
adjust > 0)
2025 const int ref_idx = !run_type[
i - 1] ?
2027 idx += (idx >= ref_idx);
2044 const int hs =
sps->hshift[
c];
2045 const int vs =
sps->vshift[
c];
2046 uint8_t *u8 = (uint8_t *)tb->
coeffs;
2047 uint16_t *u16 = (uint16_t *)tb->
coeffs;
2052 if (!(xc & hs) && !(yc & vs)) {
2077 const int max_entries = tree_type ==
SINGLE_TREE ? 31 : 15;
2078 const bool local_dual_tree = tree_type !=
SINGLE_TREE &&
2079 (!
IS_I(rsh) || (
IS_I(rsh) && !
sps->r->sps_qtbtt_dual_tree_intra_flag));
2080 bool escape_present =
false;
2084 int prev_run_pos = 0;
2086 int predictor_size, start, end,
ret;
2096 predictor_size = pp[start].
size;
2097 memset(reused, 0,
sizeof(reused[0]) * predictor_size);
2112 max_index = cu->
plt[start].
size - 1 + escape_present;
2113 if (max_index > 0) {
2137 if (pred_mode_plt_flag) {
2150 }
else if (!pred_mode_plt_flag) {
2164 const int is_128 = cb_width > 64 || cb_height > 64;
2167 CodingUnit *cu =
add_cu(lc, x0, y0, cb_width, cb_height, cqt_depth, tree_type);
2174 if (
IS_I(rsh) && is_128)
2223 const int area = cb_width * cb_height;
2225 if ((
IS_I(rsh) &&
sps->r->sps_qtbtt_dual_tree_intra_flag) ||
2235 return 1 + !
IS_I(rsh);
2241 const int cb_width,
const int cb_height,
const VVCSplitMode split,
const int ch_type,
2247 if (mode_type_condition == 1)
2249 else if (mode_type_condition == 2) {
2252 mode_type = mode_type_curr;
2259 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2260 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
int part_idx,
2264 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2265 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
2268 #define CODING_TREE(x, idx) do { \
2269 ret = hls_coding_tree(lc, x, y0, cb_width / 2, cb_height, \
2270 qg_on_y, qg_on_c, cb_sub_div + 1, cqt_depth, mtt_depth + 1, \
2271 depth_offset, idx, SPLIT_BT_VER, tree_type, mode_type); \
2277 const int x1 = x0 + cb_width / 2;
2280 depth_offset += (x0 + cb_width >
pps->width) ? 1 : 0;
2282 if (x1 < pps->
width)
2291 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2292 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
2295 #define CODING_TREE(y, idx) do { \
2296 ret = hls_coding_tree(lc, x0, y, cb_width , cb_height / 2, \
2297 qg_on_y, qg_on_c, cb_sub_div + 1, cqt_depth, mtt_depth + 1, \
2298 depth_offset, idx, SPLIT_BT_HOR, tree_type, mode_type); \
2304 const int y1 = y0 + (cb_height / 2);
2307 depth_offset += (y0 + cb_height >
pps->height) ? 1 : 0;
2318 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2319 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
2322 #define CODING_TREE(x, w, sub_div, idx) do { \
2323 ret = hls_coding_tree(lc, x, y0, w, cb_height, \
2324 qg_on_y, qg_on_c, sub_div, cqt_depth, mtt_depth + 1, \
2325 depth_offset, idx, SPLIT_TT_VER, tree_type, mode_type); \
2331 const int x1 = x0 + cb_width / 4;
2332 const int x2 = x0 + cb_width * 3 / 4;
2348 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2349 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
2352 #define CODING_TREE(y, h, sub_div, idx) do { \
2353 ret = hls_coding_tree(lc, x0, y, cb_width, h, \
2354 qg_on_y, qg_on_c, sub_div, cqt_depth, mtt_depth + 1, \
2355 depth_offset, idx, SPLIT_TT_HOR, tree_type, mode_type); \
2361 const int y1 = y0 + (cb_height / 4);
2362 const int y2 = y0 + (3 * cb_height / 4);
2368 CODING_TREE(y0, cb_height / 4, cb_sub_div + 2, 0);
2369 CODING_TREE(y1, cb_height / 2, cb_sub_div + 1, 1);
2370 CODING_TREE(y2, cb_height / 4, cb_sub_div + 2, 2);
2378 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2379 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
2382 #define CODING_TREE(x, y, idx) do { \
2383 ret = hls_coding_tree(lc, x, y, cb_width / 2, cb_height / 2, \
2384 qg_on_y, qg_on_c, cb_sub_div + 2, cqt_depth + 1, 0, 0, \
2385 idx, SPLIT_QT, tree_type, mode_type); \
2391 const int x1 = x0 + cb_width / 2;
2392 const int y1 = y0 + cb_height / 2;
2396 if (x1 < pps->
width)
2400 if (x1 < pps->
width &&
2410 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2411 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
2423 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2424 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
int part_idx,
2435 if (
pps->r->pps_cu_qp_delta_enabled_flag && qg_on_y && cb_sub_div <= sh->cu_qp_delta_subdiv) {
2441 cb_sub_div <= sh->cu_chroma_qp_offset_subdiv) {
2446 can_split(lc, x0, y0, cb_width, cb_height, mtt_depth, depth_offset, part_idx,
2447 last_split_mode, tree_type_curr, mode_type_curr, &allowed);
2455 if (!(x0 & 31) && !(y0 & 31) && mtt_depth <= 1)
2459 cb_sub_div, cqt_depth, mtt_depth, depth_offset, tree_type, mode_type);
2469 ret =
hls_coding_unit(lc, x0, y0, cb_width, cb_height, cqt_depth, tree_type_curr, mode_type_curr);
2478 const int x0,
const int y0,
const int cb_size,
const int cqt_depth)
2483 const int cb_subdiv = 2 * cqt_depth;
2487 #define DUAL_TREE(x, y) do { \
2488 ret = dual_tree_implicit_qt_split(lc, x, y, cb_size / 2, cqt_depth + 1); \
2493 const int x1 = x0 + (cb_size / 2);
2494 const int y1 = y0 + (cb_size / 2);
2495 if (
pps->r->pps_cu_qp_delta_enabled_flag && cb_subdiv <= sh->cu_qp_delta_subdiv) {
2505 if (x1 < pps->
width)
2513 #define CODING_TREE(tree_type) do { \
2514 const int qg_on_y = tree_type == DUAL_TREE_LUMA; \
2515 ret = hls_coding_tree(lc, x0, y0, cb_size, cb_size, qg_on_y, !qg_on_y, \
2516 cb_subdiv, cqt_depth, 0, 0, 0, SPLIT_NONE, tree_type, MODE_TYPE_ALL); \
2527 #define SET_SAO(elem, value) \
2529 if (!sao_merge_up_flag && !sao_merge_left_flag) \
2530 sao->elem = value; \
2531 else if (sao_merge_left_flag) \
2532 sao->elem = CTB(fc->tab.sao, rx-1, ry).elem; \
2533 else if (sao_merge_up_flag) \
2534 sao->elem = CTB(fc->tab.sao, rx, ry-1).elem; \
2543 int sao_merge_left_flag = 0;
2544 int sao_merge_up_flag = 0;
2553 if (ry > 0 && !sao_merge_left_flag) {
2559 for (c_idx = 0; c_idx < (
fc->ps.sps->r->sps_chroma_format_idc ? 3 : 1); c_idx++) {
2561 if (!sao_used_flag) {
2576 for (
i = 0;
i < 4;
i++)
2580 for (
i = 0;
i < 4;
i++) {
2589 }
else if (c_idx != 2) {
2595 for (
i = 0;
i < 4;
i++) {
2603 sao->
offset_val[c_idx][
i + 1] *= 1 << (
fc->ps.sps->bit_depth -
FFMIN(10,
fc->ps.sps->bit_depth));
2619 uint8_t alf_use_aps_flag = 0;
2622 if (alf_use_aps_flag) {
2630 for (
int c_idx =
CB; c_idx <=
CR; c_idx++) {
2631 const uint8_t alf_enabled_flag =
2633 if (alf_enabled_flag) {
2637 if (alf->
ctb_flag[c_idx] &&
aps->num_chroma_filters > 1)
2642 if (
fc->ps.sps->r->sps_ccalf_enabled_flag) {
2645 for (
int i = 0;
i < 2;
i++) {
2646 if (cc_enabled[
i]) {
2662 const int x0,
const int y0,
const int ctu_idx,
const int rx,
const int ry)
2669 const unsigned int ctb_size =
sps->ctb_size_y;
2674 hls_sao(lc, x0 >>
sps->ctb_log2_size_y, y0 >>
sps->ctb_log2_size_y);
2678 if (
IS_I(rsh) &&
sps->r->sps_qtbtt_dual_tree_intra_flag)
2686 if (rx ==
pps->ctb_to_col_bd[rx + 1] - 1) {
2689 if (!end_of_slice_one_bit)
2692 if (ry ==
pps->ctb_to_row_bd[ry + 1] - 1) {
2694 if (!end_of_tile_one_bit)
2697 if (
fc->ps.sps->r->sps_entropy_coding_sync_enabled_flag) {
2699 if (!end_of_subset_one_bit)
2718 const int top =
pps->subpic_y[idx];
2719 const int bottom = top +
pps->subpic_height[idx];
2733 const int idx = mvf->
ref_idx[lx];
2736 max_y[lx][idx] =
FFMAX(max_y[lx][idx], y);
2743 for (
int sby = 0; sby <
mi->num_sb_y; sby++) {
2744 for (
int sbx = 0; sbx <
mi->num_sb_x; sbx++) {
2745 const int x0 = cu->
x0 + sbx * sbw;
2746 const int y0 = cu->
y0 + sby * sbh;
2748 for (
int lx = 0; lx < 2; lx++) {
2751 const int idx = mvf->
ref_idx[lx];
2754 max_y[lx][idx] =
FFMAX(max_y[lx][idx], y + max_dmvr_off);
2766 CTU *ctu =
fc->tab.ctus + rs;
2774 for (
int lx = 0; lx < 2; lx++)
2788 const int ctu_idx,
const int rs,
const int rx,
const int ry)
2793 const int x_ctb = rx <<
sps->ctb_log2_size_y;
2794 const int y_ctb = ry <<
sps->ctb_log2_size_y;
2795 const int ctb_size = 1 <<
sps->ctb_log2_size_y <<
sps->ctb_log2_size_y;
2799 if (rx ==
pps->ctb_to_col_bd[rx]) {
2819 const int rx,
const int ry,
const int rs)
2822 const int ctb_size =
fc->ps.sps->ctb_size_y;
2826 if (
fc->ps.pps->ctb_to_col_bd[rx] !=
fc->ps.pps->ctb_to_col_bd[rx + 1])
2828 if (
fc->ps.pps->ctb_to_row_bd[ry] !=
fc->ps.pps->ctb_to_row_bd[ry + 1])
2832 if (rx > 0 &&
fc->ps.pps->ctb_to_col_bd[rx] !=
fc->ps.pps->ctb_to_col_bd[rx - 1])
2834 if (rx > 0 &&
fc->tab.slice_idx[rs] !=
fc->tab.slice_idx[rs - 1])
2836 if (ry > 0 &&
fc->ps.pps->ctb_to_row_bd[ry] !=
fc->ps.pps->ctb_to_row_bd[ry - 1])
2838 if (ry > 0 &&
fc->tab.slice_idx[rs] !=
fc->tab.slice_idx[rs -
fc->ps.pps->ctb_width])
2847 (
fc->ps.pps->ctb_to_row_bd[ry] ==
fc->ps.pps->ctb_to_row_bd[ry - 1]);
2852 const int x0,
const int y0,
const int w,
const int h)
2887 const int min_cb_log2_size_y =
fc->ps.sps->min_cb_log2_size_y;
2888 const int x = xc >> min_cb_log2_size_y;
2889 const int y = yc >> min_cb_log2_size_y;
2890 return fc->tab.qp[
LUMA][x + y *
fc->ps.pps->min_cb_width];
2894 const int bit_depth,
const int persistent_rice_adaptation_enabled_flag)
2898 persistent_rice_adaptation_enabled_flag ? 2 * (
av_log2(
bit_depth - 10)) : 0;
2904 const bool has_chroma = chroma_format_idc && tree_type !=
DUAL_TREE_LUMA;
2907 *start = has_luma ?
LUMA :
CB;