30 #define PROF_TEMP_SIZE (PROF_BLOCK_SIZE) * sizeof(int16_t)
32 #define TAB_MSM(fc, depth, x, y) fc->tab.msm[(depth)][((y) >> 5) * fc->ps.pps->width32 + ((x) >> 5)]
33 #define TAB_ISPMF(fc, x, y) fc->tab.ispmf[((y) >> 6) * fc->ps.pps->width64 + ((x) >> 6)]
45 const int hs =
fc->ps.sps->hshift[tb->
c_idx];
46 const int vs =
fc->ps.sps->vshift[tb->
c_idx];
47 const int is_chroma = tb->
c_idx != 0;
51 for (
int y = y_tb; y < end; y++) {
52 const int off = y *
fc->ps.pps->min_tu_width + x_tb;
54 fc->tab.tb_pos_x0[is_chroma][off +
i] = tb->
x0;
55 fc->tab.tb_pos_y0[is_chroma][off +
i] = tb->
y0;
72 memset(
tab + off, v,
w);
83 const int ctb_log2_size =
sps->ctb_log2_size_y;
84 const int ctb_size_mask = (1 << ctb_log2_size) - 1;
87 const int min_cb_width =
fc->ps.pps->min_cb_width;
88 const int x_cb = cu->
x0 >>
sps->min_cb_log2_size_y;
89 const int y_cb = cu->
y0 >>
sps->min_cb_log2_size_y;
90 const int rx = cu->
x0 >> ctb_log2_size;
91 const int ry = cu->
y0 >> ctb_log2_size;
92 const int in_same_ctb_a = ((xQg - 1) >> ctb_log2_size) == rx && (yQg >> ctb_log2_size) == ry;
93 const int in_same_ctb_b = (xQg >> ctb_log2_size) == rx && ((yQg - 1) >> ctb_log2_size) == ry;
94 int qPy_pred, qPy_a, qPy_b;
97 const int first_qg_in_ctu = !(xQg & ctb_size_mask) && !(yQg & ctb_size_mask);
98 const int qPy_up =
fc->tab.qp[
LUMA][x_cb + (y_cb - 1) * min_cb_width];
99 if (first_qg_in_ctu &&
pps->ctb_to_col_bd[xQg >> ctb_log2_size] == xQg >> ctb_log2_size)
110 qPy_b =
fc->tab.qp[
LUMA][x_cb + (y_cb - 1) * min_cb_width];
116 qPy_a =
fc->tab.qp[
LUMA][(x_cb - 1) + y_cb * min_cb_width];
118 av_assert2(qPy_a >= -
fc->ps.sps->qp_bd_offset && qPy_a < 63);
119 av_assert2(qPy_b >= -
fc->ps.sps->qp_bd_offset && qPy_b < 63);
121 return (qPy_a + qPy_b + 1) >> 1;
129 const int log2_min_cb_size =
fc->ps.sps->min_cb_log2_size_y;
130 const int x_cb = cu->
x0 >> log2_min_cb_size;
131 const int y_cb = cu->
y0 >> log2_min_cb_size;
134 int x = y_cb *
pps->min_cb_width + x_cb;
136 for (
int y = 0; y < (cb_height >> log2_min_cb_size); y++) {
137 const int width = cb_width >> log2_min_cb_size;
140 x +=
pps->min_cb_width;
163 if (cu_qp_delta > (31 +
sps->qp_bd_offset / 2) || cu_qp_delta < -(32 +
sps->qp_bd_offset / 2))
168 int off =
sps->qp_bd_offset;
169 ep->
qp_y =
FFUMOD(ep->
qp_y + cu_qp_delta + 64 + 2 * off, 64 + off) - off;
194 const int x_center = cu->
x0 + cu->
cb_width / 2;
199 const int sh_chroma_qp_offset[] = {
206 for (
int i =
CB - 1;
i <
CR +
sps->r->sps_joint_cbcr_enabled_flag;
i++) {
207 qp =
sps->chroma_qp_table[
i][qp_chroma];
240 tu->
width = tu_width;
250 const int x0,
const int y0,
const int tb_width,
const int tb_height,
const int c_idx)
269 lc->
coeffs += tb_width * tb_height;
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)) {
414 if (tu_width >
sps->max_tb_size_y || tu_height >
sps->max_tb_size_y) {
415 const int ver_split_first = tu_width >
sps->max_tb_size_y && tu_width > tu_height;
416 const int trafo_width = ver_split_first ? (tu_width / 2) : tu_width;
417 const int trafo_height = !ver_split_first ? (tu_height / 2) : tu_height;
419 #define TRANSFORM_TREE(x, y) do { \
420 ret = hls_transform_tree(lc, x, y, trafo_width, trafo_height, ch_type); \
439 #define TRANSFORM_UNIT(x, width, idx) do { \
440 ret = hls_transform_unit(lc, x, y0, width, tu_height, idx, ch_type); \
449 #undef TRANSFORM_UNIT
451 #define TRANSFORM_UNIT(y, height, idx) do { \
452 ret = hls_transform_unit(lc, x0, y, tu_width, height, idx, ch_type); \
461 #undef TRANSFORM_UNIT
488 if (tu_width >
sps->max_tb_size_y || tu_height >
sps->max_tb_size_y) {
489 const int ver_split_first = tu_width >
sps->max_tb_size_y && tu_width > tu_height;
490 const int trafo_width = ver_split_first ? (tu_width / 2) : tu_width;
491 const int trafo_height = !ver_split_first ? (tu_height / 2) : tu_height;
493 #define SKIPPED_TRANSFORM_TREE(x, y) do { \
494 int ret = skipped_transform_tree(lc, x, y, trafo_width, trafo_height); \
512 for (
int i = c_start;
i < c_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);
900 intra_chroma_pred_mode == 4 && intra_mip_flag) {
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,
957 const int log2_min_cb_size =
sps->min_cb_log2_size_y;
958 const int x0 = cu->
x0;
959 const int y0 = cu->
y0;
960 const int x_cb = x0 >> log2_min_cb_size;
961 const int y_cb = y0 >> log2_min_cb_size;
966 if (
sps->r->sps_bdpcm_enabled_flag && cb_width <= sps->max_ts_size && cb_height <= sps->max_ts_size)
971 if (
sps->r->sps_mip_enabled_flag)
976 int x = y_cb *
pps->min_cb_width + x_cb;
977 for (
int y = 0; y < (cb_height>>log2_min_cb_size); y++) {
978 int width = cb_width>>log2_min_cb_size;
980 fc->tab.imtf[x] = intra_mip_transposed_flag;
981 fc->tab.imm[x] = intra_mip_mode;
982 x +=
pps->min_cb_width;
986 int intra_subpartitions_mode_flag = 0;
987 if (
sps->r->sps_mrl_enabled_flag && ((y0 %
sps->ctb_size_y) > 0))
990 (cb_width <= sps->max_tb_size_y && cb_height <= sps->max_tb_size_y) &&
994 if (!(x0 & 63) && !(y0 & 63))
995 TAB_ISPMF(
fc, x0, y0) = intra_subpartitions_mode_flag;
1012 if (
sps->r->sps_bdpcm_enabled_flag &&
1021 int cclm_mode_flag = 0;
1022 int cclm_mode_idx = 0;
1023 int intra_chroma_pred_mode = 0;
1047 int pred_mode_ibc_flag;
1051 if (!
IS_I(rsh) ||
sps->r->sps_ibc_enabled_flag) {
1055 (
sps->r->sps_ibc_enabled_flag && !is_128))) {
1075 pred_mode_ibc_flag = 1;
1077 pred_mode_ibc_flag = 0;
1079 pred_mode_ibc_flag = (
IS_I(rsh)) ?
sps->r->sps_ibc_enabled_flag : 0;
1081 if (pred_mode_ibc_flag)
1096 && cb_width <= sps->max_tb_size_y && cb_height <= sps->max_tb_size_y) {
1097 const int sbt_ver_h = cb_width >= 8;
1098 const int sbt_hor_h = cb_height >= 8;
1100 if (sbt_ver_h || sbt_hor_h)
1103 const int sbt_ver_q = cb_width >= 16;
1104 const int sbt_hor_q = cb_height >= 16;
1105 int cu_sbt_quad_flag = 0;
1107 if ((sbt_ver_h || sbt_hor_h) && (sbt_ver_q || sbt_hor_q))
1109 if (cu_sbt_quad_flag) {
1111 if (sbt_ver_q && sbt_hor_q)
1115 if (sbt_ver_h && sbt_hor_h)
1121 const int sbt_min = cu_sbt_quad_flag ? 1 : 2;
1148 const int log2_min_cb_size =
sps->min_cb_log2_size_y;
1149 const int x_cb = cu->
x0 >> log2_min_cb_size;
1150 const int y_cb = cu->
y0 >> log2_min_cb_size;
1151 const int ch_type = cu->
ch_type;
1154 x = y_cb *
pps->min_cb_width + x_cb;
1155 for (y = 0; y < (cu->
cb_height >> log2_min_cb_size); y++) {
1159 fc->tab.cb_pos_x[ch_type][x +
i] = cu->
x0;
1160 fc->tab.cb_pos_y[ch_type][x +
i] = cu->
y0;
1166 x +=
pps->min_cb_width;
1175 const int rx = x0 >>
sps->ctb_log2_size_y;
1176 const int ry = y0 >>
sps->ctb_log2_size_y;
1177 CTU *ctu =
fc->tab.ctus + ry *
pps->ctb_width + rx;
1194 const int cb_width,
const int cb_height,
const int cqt_depth,
const VVCTreeType tree_type)
1203 memset(&cu->
pu, 0,
sizeof(cu->
pu));
1243 for (
int j = 0; j < tu->
nb_tbs; j++) {
1263 const int diff[] = {
1270 mmvd[1] = mmvd[0] = *mmvd_offset;
1275 mmvd[
i] = *mmvd_offset;
1280 mmvd[o].
x = sign ? -mmvd[
i].
x : mmvd[
i].
x;
1281 mmvd[o].
y = sign ? -mmvd[
i].
y : mmvd[
i].
y;
1284 mvf->
mv[0].
x += mmvd[0].
x;
1285 mvf->
mv[0].
y += mmvd[0].
y;
1286 mvf->
mv[1].
x += mmvd[1].
x;
1287 mvf->
mv[1].
y += mmvd[1].
y;
1290 mvf->
mv[idx].
x += mmvd_offset->
x;
1291 mvf->
mv[idx].
y += mmvd_offset->
y;
1301 for (
int i = 0;
i < 2;
i++) {
1304 mi->mv[
i][0] = mvf->
mv[
i];
1325 int merge_subblock_idx = 0;
1328 if (
ph->max_num_subblock_merge_cand > 1) {
1345 if (
sps->r->sps_mmvd_enabled_flag)
1348 int mmvd_cand_flag = 0;
1349 if (
sps->max_num_merge_cand > 1)
1352 merge_idx = mmvd_cand_flag;
1353 }
else if (
sps->max_num_merge_cand > 1) {
1370 if (ciip_avaiable && gpm_avaiable)
1372 return sps->r->sps_ciip_enabled_flag && !cu->
skip_flag &&
1381 int merge_gpm_idx[2];
1386 merge_gpm_idx[1] = 0;
1387 if (
sps->max_num_gpm_merge_cand > 2)
1403 if (
sps->max_num_merge_cand > 1)
1423 const int is_128 = cb_width == 128 || cb_height == 128;
1424 const int ciip_avaiable =
sps->r->sps_ciip_enabled_flag &&
1425 !cu->
skip_flag && (cb_width * cb_height >= 64);
1426 const int gpm_avaiable =
sps->r->sps_gpm_enabled_flag &&
IS_B(rsh) &&
1427 (cb_width >= 8) && (cb_height >=8) &&
1428 (cb_width < 8 * cb_height) && (cb_height < 8 *cb_width);
1430 int regular_merge_flag = 1;
1432 if (!is_128 && (ciip_avaiable || gpm_avaiable))
1434 if (regular_merge_flag) {
1455 if (
sps->max_num_ibc_merge_cand > 1)
1495 for (
int i = 0;
i < 2;
i++) {
1499 for (
int i = 0;
i < 2;
i++) {
1504 for (
int i = 0;
i < 2;
i++) {
1525 if (
sps->r->sps_bcw_enabled_flag &&
mi->pred_flag ==
PF_BI &&
1526 !
w->weight_flag[
L0][
LUMA][
mi->ref_idx[0]] &&
1527 !
w->weight_flag[
L1][
LUMA][
mi->ref_idx[1]] &&
1530 cb_width * cb_height >= 256) {
1543 else if (sym_mvd_flag)
1549 const int num_cp_mv,
const int lx)
1555 int has_no_zero_mvd = 0;
1557 if (lx ==
L1 &&
ph->r->ph_mvd_l1_zero_flag &&
mi->pred_flag ==
PF_BI) {
1558 for (
int j = 0; j < num_cp_mv; j++)
1561 Mv *mvd0 = &mvds[lx][0];
1563 mvd0->
x = -mvds[
L0][0].x;
1564 mvd0->
y = -mvds[
L0][0].y;
1568 has_no_zero_mvd |= (mvd0->
x || mvd0->
y);
1569 for (
int j = 1; j < num_cp_mv; j++) {
1570 Mv *mvd = &mvds[lx][j];
1574 has_no_zero_mvd |= (mvd->
x || mvd->
y);
1577 return has_no_zero_mvd;
1583 for (
int i = 0;
i < 2;
i++) {
1585 if (
mi->pred_flag &
mask) {
1586 for (
int j = 0; j < num_cp_mv; j++) {
1587 const Mv *mvd = &mvds[
i][j];
1588 mi->mv[
i][j].x += mvd->
x * (1 << amvr_shift);
1589 mi->mv[
i][j].y += mvd->
y * (1 << amvr_shift);
1602 int mvp_l0_flag = 0;
1612 if (
sps->max_num_ibc_merge_cand > 1)
1614 if (
sps->r->sps_amvr_enabled_flag && (
mv->x ||
mv->y))
1638 int mvp_lx_flag[2] = {0};
1639 int cu_affine_type_flag = 0;
1641 int amvr_enabled, has_no_zero_mvd = 0, amvr_shift;
1645 if (
sps->r->sps_affine_enabled_flag && cb_width >= 16 && cb_height >= 16) {
1652 num_cp_mv =
mi->motion_model_idc + 1;
1654 if (
sps->r->sps_smvd_enabled_flag && !
ph->r->ph_mvd_l1_zero_flag &&
1659 for (
int i =
L0;
i <=
L1;
i++) {
1661 if (
mi->pred_flag != pred_flag) {
1663 has_no_zero_mvd |=
mvds_decode(lc, mvds, num_cp_mv,
i);
1669 sps->r->sps_amvr_enabled_flag :
sps->r->sps_affine_amvr_enabled_flag;
1670 amvr_enabled &= has_no_zero_mvd;
1674 mi->hpel_if_idx = amvr_shift == 3;
1677 if (
mi->motion_model_idc)
1684 if (
mi->motion_model_idc)
1700 const int poc =
ph->poc;
1702 const int8_t *ref_idx =
mi->ref_idx;
1711 (poc - rp0->
poc == rp1->
poc - poc) &&
1720 if (!
ph->r->ph_bdof_disabled_flag &&
1725 if (!
ph->r->ph_dmvr_disabled_flag &&
1759 MvField *dmvr_mvf =
fc->ref->tab_dmvr_mvf + idx;
1761 memcpy(dmvr_mvf, mvf,
sizeof(
MvField) *
w);
1806 const int is_128 = cb_width > 64 || cb_height > 64;
1807 int pred_mode_plt_flag = 0;
1810 CodingUnit *cu =
add_cu(lc, x0, y0, cb_width, cb_height, cqt_depth, tree_type);
1817 if (
IS_I(rsh) && is_128)
1826 if (pred_mode_plt_flag) {
1837 if (pred_mode_plt_flag) {
1849 }
else if (!pred_mode_plt_flag) {
1894 const int area = cb_width * cb_height;
1896 if ((
IS_I(rsh) &&
sps->r->sps_qtbtt_dual_tree_intra_flag) ||
1906 return 1 + !
IS_I(rsh);
1912 const int cb_width,
const int cb_height,
const VVCSplitMode split,
const int ch_type,
1918 if (mode_type_condition == 1)
1920 else if (mode_type_condition == 2) {
1923 mode_type = mode_type_curr;
1930 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
1931 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
int part_idx,
1935 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
1936 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
1939 #define CODING_TREE(x, idx) do { \
1940 ret = hls_coding_tree(lc, x, y0, cb_width / 2, cb_height, \
1941 qg_on_y, qg_on_c, cb_sub_div + 1, cqt_depth, mtt_depth + 1, \
1942 depth_offset, idx, SPLIT_BT_VER, tree_type, mode_type); \
1948 const int x1 = x0 + cb_width / 2;
1951 depth_offset += (x0 + cb_width >
pps->width) ? 1 : 0;
1953 if (x1 < pps->
width)
1962 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
1963 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
1966 #define CODING_TREE(y, idx) do { \
1967 ret = hls_coding_tree(lc, x0, y, cb_width , cb_height / 2, \
1968 qg_on_y, qg_on_c, cb_sub_div + 1, cqt_depth, mtt_depth + 1, \
1969 depth_offset, idx, SPLIT_BT_HOR, tree_type, mode_type); \
1975 const int y1 = y0 + (cb_height / 2);
1978 depth_offset += (y0 + cb_height >
pps->height) ? 1 : 0;
1989 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
1990 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
1993 #define CODING_TREE(x, w, sub_div, idx) do { \
1994 ret = hls_coding_tree(lc, x, y0, w, cb_height, \
1995 qg_on_y, qg_on_c, sub_div, cqt_depth, mtt_depth + 1, \
1996 depth_offset, idx, SPLIT_TT_VER, tree_type, mode_type); \
2002 const int x1 = x0 + cb_width / 4;
2003 const int x2 = x0 + cb_width * 3 / 4;
2019 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2020 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
2023 #define CODING_TREE(y, h, sub_div, idx) do { \
2024 ret = hls_coding_tree(lc, x0, y, cb_width, h, \
2025 qg_on_y, qg_on_c, sub_div, cqt_depth, mtt_depth + 1, \
2026 depth_offset, idx, SPLIT_TT_HOR, tree_type, mode_type); \
2032 const int y1 = y0 + (cb_height / 4);
2033 const int y2 = y0 + (3 * cb_height / 4);
2039 CODING_TREE(y0, cb_height / 4, cb_sub_div + 2, 0);
2040 CODING_TREE(y1, cb_height / 2, cb_sub_div + 1, 1);
2041 CODING_TREE(y2, cb_height / 4, cb_sub_div + 2, 2);
2049 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2050 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
2053 #define CODING_TREE(x, y, idx) do { \
2054 ret = hls_coding_tree(lc, x, y, cb_width / 2, cb_height / 2, \
2055 qg_on_y, qg_on_c, cb_sub_div + 2, cqt_depth + 1, 0, 0, \
2056 idx, SPLIT_QT, tree_type, mode_type); \
2062 const int x1 = x0 + cb_width / 2;
2063 const int y1 = y0 + cb_height / 2;
2067 if (x1 < pps->
width)
2071 if (x1 < pps->
width &&
2081 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2082 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
2094 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2095 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
int part_idx,
2106 if (
pps->r->pps_cu_qp_delta_enabled_flag && qg_on_y && cb_sub_div <= sh->cu_qp_delta_subdiv) {
2112 cb_sub_div <= sh->cu_chroma_qp_offset_subdiv) {
2117 can_split(lc, x0, y0, cb_width, cb_height, mtt_depth, depth_offset, part_idx,
2118 last_split_mode, tree_type_curr, mode_type_curr, &allowed);
2126 if (!(x0 & 31) && !(y0 & 31) && mtt_depth <= 1)
2130 cb_sub_div, cqt_depth, mtt_depth, depth_offset, tree_type, mode_type);
2140 ret =
hls_coding_unit(lc, x0, y0, cb_width, cb_height, cqt_depth, tree_type_curr, mode_type_curr);
2149 const int x0,
const int y0,
const int cb_size,
const int cqt_depth)
2154 const int cb_subdiv = 2 * cqt_depth;
2158 #define DUAL_TREE(x, y) do { \
2159 ret = dual_tree_implicit_qt_split(lc, x, y, cb_size / 2, cqt_depth + 1); \
2164 const int x1 = x0 + (cb_size / 2);
2165 const int y1 = y0 + (cb_size / 2);
2166 if (
pps->r->pps_cu_qp_delta_enabled_flag && cb_subdiv <= sh->cu_qp_delta_subdiv) {
2176 if (x1 < pps->
width)
2184 #define CODING_TREE(tree_type) do { \
2185 const int qg_on_y = tree_type == DUAL_TREE_LUMA; \
2186 ret = hls_coding_tree(lc, x0, y0, cb_size, cb_size, qg_on_y, !qg_on_y, \
2187 cb_subdiv, cqt_depth, 0, 0, 0, SPLIT_NONE, tree_type, MODE_TYPE_ALL); \
2198 #define SET_SAO(elem, value) \
2200 if (!sao_merge_up_flag && !sao_merge_left_flag) \
2201 sao->elem = value; \
2202 else if (sao_merge_left_flag) \
2203 sao->elem = CTB(fc->tab.sao, rx-1, ry).elem; \
2204 else if (sao_merge_up_flag) \
2205 sao->elem = CTB(fc->tab.sao, rx, ry-1).elem; \
2214 int sao_merge_left_flag = 0;
2215 int sao_merge_up_flag = 0;
2224 if (ry > 0 && !sao_merge_left_flag) {
2230 for (c_idx = 0; c_idx < (
fc->ps.sps->r->sps_chroma_format_idc ? 3 : 1); c_idx++) {
2232 if (!sao_used_flag) {
2247 for (
i = 0;
i < 4;
i++)
2251 for (
i = 0;
i < 4;
i++) {
2260 }
else if (c_idx != 2) {
2266 for (
i = 0;
i < 4;
i++) {
2274 sao->
offset_val[c_idx][
i + 1] *= 1 << (
fc->ps.sps->bit_depth -
FFMIN(10,
fc->ps.sps->bit_depth));
2289 uint8_t alf_use_aps_flag = 0;
2292 if (alf_use_aps_flag) {
2300 for (
int c_idx =
CB; c_idx <=
CR; c_idx++) {
2301 const uint8_t alf_enabled_flag =
2303 if (alf_enabled_flag) {
2307 if (alf->
ctb_flag[c_idx] &&
aps->num_chroma_filters > 1)
2312 if (
fc->ps.sps->r->sps_ccalf_enabled_flag) {
2315 for (
int i = 0;
i < 2;
i++) {
2317 if (cc_enabled[
i]) {
2333 const int x0,
const int y0,
const int ctu_idx,
const int rx,
const int ry)
2340 const unsigned int ctb_size =
sps->ctb_size_y;
2345 hls_sao(lc, x0 >>
sps->ctb_log2_size_y, y0 >>
sps->ctb_log2_size_y);
2349 if (
IS_I(rsh) &&
sps->r->sps_qtbtt_dual_tree_intra_flag)
2357 if (rx ==
pps->ctb_to_col_bd[rx + 1] - 1) {
2360 if (!end_of_slice_one_bit)
2363 if (ry ==
pps->ctb_to_row_bd[ry + 1] - 1) {
2365 if (!end_of_tile_one_bit)
2368 if (
fc->ps.sps->r->sps_entropy_coding_sync_enabled_flag) {
2370 if (!end_of_subset_one_bit)
2398 const int idx = mvf->
ref_idx[lx];
2401 max_y[lx][idx] =
FFMAX(max_y[lx][idx], y);
2408 for (
int sby = 0; sby <
mi->num_sb_y; sby++) {
2409 for (
int sbx = 0; sbx <
mi->num_sb_x; sbx++) {
2410 const int x0 = cu->
x0 + sbx * sbw;
2411 const int y0 = cu->
y0 + sby * sbh;
2413 for (
int lx = 0; lx < 2; lx++) {
2416 const int idx = mvf->
ref_idx[lx];
2419 max_y[lx][idx] =
FFMAX(max_y[lx][idx], y + max_dmvr_off);
2431 CTU *ctu =
fc->tab.ctus + rs;
2437 for (
int lx = 0; lx < 2; lx++)
2451 const int ctu_idx,
const int rs,
const int rx,
const int ry)
2456 const int x_ctb = rx <<
sps->ctb_log2_size_y;
2457 const int y_ctb = ry <<
sps->ctb_log2_size_y;
2458 const int ctb_size = 1 <<
sps->ctb_log2_size_y <<
sps->ctb_log2_size_y;
2462 if (rx ==
pps->ctb_to_col_bd[rx]) {
2482 const int rx,
const int ry,
const int rs)
2485 const int ctb_size =
fc->ps.sps->ctb_size_y;
2489 if (
fc->ps.pps->ctb_to_col_bd[rx] !=
fc->ps.pps->ctb_to_col_bd[rx + 1])
2491 if (
fc->ps.pps->ctb_to_row_bd[ry] !=
fc->ps.pps->ctb_to_row_bd[ry + 1])
2495 if (rx > 0 &&
fc->ps.pps->ctb_to_col_bd[rx] !=
fc->ps.pps->ctb_to_col_bd[rx - 1])
2497 if (rx > 0 &&
fc->tab.slice_idx[rs] !=
fc->tab.slice_idx[rs - 1])
2499 if (ry > 0 &&
fc->ps.pps->ctb_to_row_bd[ry] !=
fc->ps.pps->ctb_to_row_bd[ry - 1])
2501 if (ry > 0 &&
fc->tab.slice_idx[rs] !=
fc->tab.slice_idx[rs -
fc->ps.pps->ctb_width])
2510 (
fc->ps.pps->ctb_to_row_bd[ry] ==
fc->ps.pps->ctb_to_row_bd[ry - 1]);
2515 const int x0,
const int y0,
const int w,
const int h)
2551 const int min_cb_log2_size_y =
fc->ps.sps->min_cb_log2_size_y;
2552 const int x = xc >> min_cb_log2_size_y;
2553 const int y = yc >> min_cb_log2_size_y;
2554 return fc->tab.qp[
LUMA][x + y *
fc->ps.pps->min_cb_width];
2558 const int bit_depth,
const int persistent_rice_adaptation_enabled_flag)
2562 persistent_rice_adaptation_enabled_flag ? 2 * (
av_log2(
bit_depth - 10)) : 0;