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;
68 memset(
tab + off, v,
w);
79 const int ctb_log2_size =
sps->ctb_log2_size_y;
80 const int ctb_size_mask = (1 << ctb_log2_size) - 1;
83 const int min_cb_width =
fc->ps.pps->min_cb_width;
84 const int x_cb = cu->
x0 >>
sps->min_cb_log2_size_y;
85 const int y_cb = cu->
y0 >>
sps->min_cb_log2_size_y;
86 const int rx = cu->
x0 >> ctb_log2_size;
87 const int ry = cu->
y0 >> ctb_log2_size;
88 const int in_same_ctb_a = ((xQg - 1) >> ctb_log2_size) == rx && (yQg >> ctb_log2_size) == ry;
89 const int in_same_ctb_b = (xQg >> ctb_log2_size) == rx && ((yQg - 1) >> ctb_log2_size) == ry;
90 int qPy_pred, qPy_a, qPy_b;
93 const int first_qg_in_ctu = !(xQg & ctb_size_mask) && !(yQg & ctb_size_mask);
94 const int qPy_up =
fc->tab.qp[
LUMA][x_cb + (y_cb - 1) * min_cb_width];
95 if (first_qg_in_ctu &&
pps->ctb_to_col_bd[xQg >> ctb_log2_size] == xQg >> ctb_log2_size)
106 qPy_b =
fc->tab.qp[
LUMA][x_cb + (y_cb - 1) * min_cb_width];
112 qPy_a =
fc->tab.qp[
LUMA][(x_cb - 1) + y_cb * min_cb_width];
114 av_assert2(qPy_a >= -
fc->ps.sps->qp_bd_offset && qPy_a <= 63);
115 av_assert2(qPy_b >= -
fc->ps.sps->qp_bd_offset && qPy_b <= 63);
117 return (qPy_a + qPy_b + 1) >> 1;
125 const int log2_min_cb_size =
fc->ps.sps->min_cb_log2_size_y;
126 const int x_cb = cu->
x0 >> log2_min_cb_size;
127 const int y_cb = cu->
y0 >> log2_min_cb_size;
130 int x = y_cb *
pps->min_cb_width + x_cb;
132 for (
int y = 0; y < (cb_height >> log2_min_cb_size); y++) {
133 const int width = cb_width >> log2_min_cb_size;
136 x +=
pps->min_cb_width;
159 if (cu_qp_delta > (31 +
sps->qp_bd_offset / 2) || cu_qp_delta < -(32 +
sps->qp_bd_offset / 2))
164 int off =
sps->qp_bd_offset;
165 ep->
qp_y =
FFUMOD(ep->
qp_y + cu_qp_delta + 64 + 2 * off, 64 + off) - off;
190 const int x_center = cu->
x0 + cu->
cb_width / 2;
195 const int sh_chroma_qp_offset[] = {
202 for (
int i =
CB - 1;
i <
CR +
sps->r->sps_joint_cbcr_enabled_flag;
i++) {
203 qp =
sps->chroma_qp_table[
i][qp_chroma];
236 tu->
width = tu_width;
247 const int x0,
const int y0,
const int tb_width,
const int tb_height,
const int c_idx)
266 lc->
coeffs += tb_width * tb_height;
267 tu->
avail[!!c_idx] =
true;
272 const int sub_tu_index,
const int is_isp,
const int is_chroma_coded)
274 uint8_t tu_y_coded_flag = 0;
278 if (!is_sbt_not_coded) {
288 return tu_y_coded_flag;
296 if ((is_128 || is_chroma_coded) &&
299 if (cu_chroma_qp_offset_flag) {
300 int cu_chroma_qp_offset_idx = 0;
301 if (
pps->r->pps_chroma_qp_offset_list_len_minus1 > 0)
319 const int min_cb_width =
pps->min_cb_width;
324 const int is_sbt_not_coded = cu->
sbt_flag &&
326 const int chroma_available = tree_type !=
DUAL_TREE_LUMA &&
sps->r->sps_chroma_format_idc &&
327 (!is_isp || is_isp_last_tu);
328 int ret, xc, yc, wc, hc, is_chroma_coded;
334 const int x_cu = x0 >>
fc->ps.sps->min_cb_log2_size_y;
335 const int y_cu = y0 >>
fc->ps.sps->min_cb_log2_size_y;
339 hc =
SAMPLE_CTB(
fc->tab.cb_height[ch_type], x_cu, y_cu);
341 xc = x0, yc = y0, wc = tu_width, hc = tu_height;
344 if (chroma_available && !is_sbt_not_coded) {
354 has_qp_delta = (is_128 || tu->
coded_flag[
LUMA] || is_chroma_coded) &&
359 add_tb(tu, lc, x0, y0, tu_width, tu_height,
LUMA);
363 if (chroma_available) {
366 add_tb(tu, lc, xc, yc, wc >> hs, hc >> vs,
CB);
367 add_tb(tu, lc, xc, yc, wc >> hs, hc >> vs,
CR);
387 !cu->
sbt_flag && (is_chroma || !is_isp)) {
412 if (tu_width >
sps->max_tb_size_y || tu_height >
sps->max_tb_size_y) {
413 const int ver_split_first = tu_width >
sps->max_tb_size_y && tu_width > tu_height;
414 const int trafo_width = ver_split_first ? (tu_width / 2) : tu_width;
415 const int trafo_height = !ver_split_first ? (tu_height / 2) : tu_height;
417 #define TRANSFORM_TREE(x, y) do { \
418 ret = hls_transform_tree(lc, x, y, trafo_width, trafo_height, ch_type); \
437 #define TRANSFORM_UNIT(x, width, idx) do { \
438 ret = hls_transform_unit(lc, x, y0, width, tu_height, idx, ch_type); \
447 #undef TRANSFORM_UNIT
449 #define TRANSFORM_UNIT(y, height, idx) do { \
450 ret = hls_transform_unit(lc, x0, y, tu_width, height, idx, ch_type); \
459 #undef TRANSFORM_UNIT
486 if (tu_width >
sps->max_tb_size_y || tu_height >
sps->max_tb_size_y) {
487 const int ver_split_first = tu_width >
sps->max_tb_size_y && tu_width > tu_height;
488 const int trafo_width = ver_split_first ? (tu_width / 2) : tu_width;
489 const int trafo_height = !ver_split_first ? (tu_height / 2) : tu_height;
491 #define SKIPPED_TRANSFORM_TREE(x, y) do { \
492 int ret = skipped_transform_tree(lc, x, y, trafo_width, trafo_height); \
510 for (
int i = c_start;
i < c_end;
i++) {
524 int mtt_depth,
int depth_offset,
int part_idx,
VVCSplitMode last_split_mode,
527 int min_qt_size, max_bt_size, max_tt_size, max_mtt_depth;
533 int min_cb_size_y =
sps->min_cb_size_y;
534 int *qt = &
split->qt;
535 int *btv = &
split->btv;
536 int *bth = &
split->bth;
537 int *ttv = &
split->ttv;
538 int *tth = &
split->tth;
540 *qt = *bth = *btv = *tth = *ttv = 1;
546 if (cb_width <= min_qt_size)
550 int chroma_area = (cb_width >>
sps->hshift[1]) * (cb_height >>
sps->vshift[1]);
551 int chroma_width = cb_width >>
sps->hshift[1];
553 if (chroma_width == 8)
555 else if (chroma_width <= 4) {
556 if (chroma_width == 4)
561 *qt = *btv = *bth = *ttv = *tth = 0;
562 if (chroma_area <= 32) {
564 if (chroma_area <= 16)
573 int area = cb_width * cb_height;
579 if (cb_width <= 2 * min_cb_size_y) {
581 if (cb_width <= min_cb_size_y)
584 if (cb_height <= 2 * min_cb_size_y) {
586 if (cb_height <= min_cb_size_y)
589 if (cb_width > max_bt_size || cb_height > max_bt_size)
591 max_tt_size =
FFMIN(64, max_tt_size);
592 if (cb_width > max_tt_size || cb_height > max_tt_size)
594 if (mtt_depth >= max_mtt_depth)
595 *btv = *bth = *ttv = *tth = 0;
596 if (x0 + cb_width >
pps->width) {
600 if (y0 + cb_height <= pps->
height)
602 else if (cb_width > min_qt_size)
605 if (y0 + cb_height >
pps->height) {
606 *btv = *ttv = *tth = 0;
610 if (mtt_depth > 0 && part_idx == 1) {
616 if (cb_width <= 64 && cb_height > 64)
618 if (cb_width > 64 && cb_height <= 64)
626 if ((cb_width == 4 && cb_height == 8) || (cb_width == 8 && cb_height == 4))
637 if (!
sps->r->sps_cclm_enabled_flag)
639 if (!
sps->r->sps_qtbtt_dual_tree_intra_flag || !
IS_I(lc->
sc->
sh.
r) ||
sps->ctb_log2_size_y < 6)
642 const int x64 = x0 >> 6 << 6;
643 const int y64 = y0 >> 6 << 6;
644 const int y32 = y0 >> 5 << 5;
645 const int x64_cu = x64 >>
fc->ps.sps->min_cb_log2_size_y;
646 const int y64_cu = y64 >>
fc->ps.sps->min_cb_log2_size_y;
647 const int y32_cu = y32 >>
fc->ps.sps->min_cb_log2_size_y;
648 const int min_cb_width =
fc->ps.pps->min_cb_width;
649 const int depth =
SAMPLE_CTB(
fc->tab.cqt_depth[1], x64_cu, y64_cu);
650 const int min_depth =
fc->ps.sps->ctb_log2_size_y - 6;
654 enabled =
SAMPLE_CTB(
fc->tab.cb_width[1], x64_cu, y64_cu) == 64 &&
656 enabled |= depth == min_depth && msm64 ==
SPLIT_BT_HOR &&
657 SAMPLE_CTB(
fc->tab.cb_width[1], x64_cu, y32_cu) == 64 &&
659 enabled |= depth > min_depth;
663 const int w =
SAMPLE_CTB(
fc->tab.cb_width[0], x64_cu, y64_cu);
664 const int h =
SAMPLE_CTB(
fc->tab.cb_height[0], x64_cu, y64_cu);
665 const int depth0 =
SAMPLE_CTB(
fc->tab.cqt_depth[0], x64_cu, y64_cu);
667 ((
w < 64 ||
h < 64) && depth0 == min_depth))
676 static int less(
const void *
a,
const void *
b)
678 return *(
const int*)
a - *(
const int*)
b;
686 const int x0 = cu->
x0;
687 const int y0 = cu->
y0;
689 int intra_luma_not_planar_flag = 1;
690 int intra_luma_mpm_remainder = 0;
691 int intra_luma_mpm_flag = 1;
692 int intra_luma_mpm_idx = 0;
696 if (intra_luma_mpm_flag) {
699 if (intra_luma_not_planar_flag)
705 if (!intra_luma_not_planar_flag) {
709 const int x_a = (x0 - 1) >>
sps->min_cb_log2_size_y;
710 const int y_a = (y0 + cu->
cb_height - 1) >>
sps->min_cb_log2_size_y;
711 const int x_b = (x0 + cu->
cb_width - 1) >>
sps->min_cb_log2_size_y;
712 const int y_b = (y0 - 1) >>
sps->min_cb_log2_size_y;
713 int min_cb_width =
fc->ps.pps->min_cb_width;
737 cand[1] = 2 + ((
a + 61) % 64);
738 cand[2] = 2 + ((
a - 1) % 64);
739 cand[3] = 2 + ((
a + 60) % 64);
740 cand[4] = 2 + (
a % 64);
745 const int diff = maxab - minab;
749 cand[2] = 2 + ((minab + 61) % 64);
750 cand[3] = 2 + ((maxab - 1) % 64);
751 cand[4] = 2 + ((minab + 60) % 64);
752 }
else if (
diff >= 62) {
753 cand[2] = 2 + ((minab - 1) % 64);
754 cand[3] = 2 + ((maxab + 61) % 64);
755 cand[4] = 2 + (minab % 64);
756 }
else if (
diff == 2) {
757 cand[2] = 2 + ((minab - 1) % 64);
758 cand[3] = 2 + ((minab + 61) % 64);
759 cand[4] = 2 + ((maxab - 1) % 64);
761 cand[2] = 2 + ((minab + 61) % 64);
762 cand[3] = 2 + ((minab - 1) % 64);
763 cand[4] = 2 + ((maxab + 61) % 64);
767 cand[1] = 2 + ((maxab + 61 ) % 64);
768 cand[2] = 2 + ((maxab - 1) % 64);
769 cand[3] = 2 + ((maxab + 60 ) % 64);
770 cand[4] = 2 + (maxab % 64);
779 if (intra_luma_mpm_flag) {
780 pred = cand[intra_luma_mpm_idx];
783 pred = intra_luma_mpm_remainder + 1;
801 int lfnst_width, lfnst_height, min_lfnst;
810 for (
int j = 0; j < tu->
nb_tbs; j++) {
819 lfnst_width = cb_width >>
sps->hshift[1];
820 lfnst_height = cb_height >>
sps->vshift[1];
827 min_lfnst =
FFMIN(lfnst_width, lfnst_height);
831 if (min_lfnst >= 4) {
850 const uint8_t transform_skip_flag = cu->
tus.
head->
tbs[0].
ts;
853 !transform_skip_flag &&
FFMAX(cb_width, cb_height) <= 32 &&
867 const int x_center = (cu->
x0 + cu->
cb_width / 2) >>
sps->min_cb_log2_size_y;
868 const int y_center = (cu->
y0 + cu->
cb_height / 2) >>
sps->min_cb_log2_size_y;
869 const int min_cb_width =
pps->min_cb_width;
870 const int intra_mip_flag =
SAMPLE_CTB(
fc->tab.imf, x_center, y_center);
871 const int cu_pred_mode =
SAMPLE_CTB(
fc->tab.cpm[0], x_center, y_center);
872 const int intra_pred_mode_y =
SAMPLE_CTB(
fc->tab.ipm, x_center, y_center);
874 if (intra_mip_flag) {
881 return intra_pred_mode_y;
885 const int cclm_mode_flag,
const int cclm_mode_idx,
const int intra_chroma_pred_mode)
891 const int x_cb = cu->
x0 >>
sps->min_cb_log2_size_y;
892 const int y_cb = cu->
y0 >>
sps->min_cb_log2_size_y;
893 const int min_cb_width =
pps->min_cb_width;
894 const int intra_mip_flag =
SAMPLE_CTB(
fc->tab.imf, x_cb, y_cb);
898 intra_chroma_pred_mode == 4 && intra_mip_flag) {
909 if (cclm_mode_flag) {
911 }
else if (intra_chroma_pred_mode == 4){
939 0, 1, 61, 62, 63, 64, 65, 66, 2, 3, 5, 6, 8, 10, 12, 13,
940 14, 16, 18, 20, 22, 23, 24, 26, 28, 30, 31, 33, 34, 35, 36, 37,
941 38, 39, 40, 41, 41, 42, 43, 43, 44, 44, 45, 45, 46, 47, 48, 48,
942 49, 49, 50, 51, 51, 52, 52, 53, 54, 55, 55, 56, 56, 57, 57, 58,
955 const int log2_min_cb_size =
sps->min_cb_log2_size_y;
956 const int x0 = cu->
x0;
957 const int y0 = cu->
y0;
958 const int x_cb = x0 >> log2_min_cb_size;
959 const int y_cb = y0 >> log2_min_cb_size;
964 if (
sps->r->sps_bdpcm_enabled_flag && cb_width <= sps->max_ts_size && cb_height <= sps->max_ts_size)
969 if (
sps->r->sps_mip_enabled_flag)
974 int x = y_cb *
pps->min_cb_width + x_cb;
975 for (
int y = 0; y < (cb_height>>log2_min_cb_size); y++) {
976 int width = cb_width>>log2_min_cb_size;
978 fc->tab.imtf[x] = intra_mip_transposed_flag;
979 fc->tab.imm[x] = intra_mip_mode;
980 x +=
pps->min_cb_width;
984 int intra_subpartitions_mode_flag = 0;
985 if (
sps->r->sps_mrl_enabled_flag && ((y0 %
sps->ctb_size_y) > 0))
988 (cb_width <= sps->max_tb_size_y && cb_height <= sps->max_tb_size_y) &&
992 if (!(x0 & 63) && !(y0 & 63))
993 TAB_ISPMF(
fc, x0, y0) = intra_subpartitions_mode_flag;
1010 if (
sps->r->sps_bdpcm_enabled_flag &&
1019 int cclm_mode_flag = 0;
1020 int cclm_mode_idx = 0;
1021 int intra_chroma_pred_mode = 0;
1045 int pred_mode_ibc_flag;
1049 if (!
IS_I(rsh) ||
sps->r->sps_ibc_enabled_flag) {
1053 (
sps->r->sps_ibc_enabled_flag && !is_128))) {
1073 pred_mode_ibc_flag = 1;
1075 pred_mode_ibc_flag = 0;
1077 pred_mode_ibc_flag = (
IS_I(rsh)) ?
sps->r->sps_ibc_enabled_flag : 0;
1079 if (pred_mode_ibc_flag)
1099 && cb_width <= sps->max_tb_size_y && cb_height <= sps->max_tb_size_y) {
1100 const int sbt_ver_h = cb_width >= 8;
1101 const int sbt_hor_h = cb_height >= 8;
1103 if (sbt_ver_h || sbt_hor_h)
1106 const int sbt_ver_q = cb_width >= 16;
1107 const int sbt_hor_q = cb_height >= 16;
1108 int cu_sbt_quad_flag = 0;
1110 if ((sbt_ver_h || sbt_hor_h) && (sbt_ver_q || sbt_hor_q))
1112 if (cu_sbt_quad_flag) {
1114 if (sbt_ver_q && sbt_hor_q)
1118 if (sbt_ver_h && sbt_hor_h)
1124 const int sbt_min = cu_sbt_quad_flag ? 1 : 2;
1151 const int log2_min_cb_size =
sps->min_cb_log2_size_y;
1152 const int x_cb = cu->
x0 >> log2_min_cb_size;
1153 const int y_cb = cu->
y0 >> log2_min_cb_size;
1154 const int ch_type = cu->
ch_type;
1157 x = y_cb *
pps->min_cb_width + x_cb;
1158 for (y = 0; y < (cu->
cb_height >> log2_min_cb_size); y++) {
1162 fc->tab.cb_pos_x[ch_type][x +
i] = cu->
x0;
1163 fc->tab.cb_pos_y[ch_type][x +
i] = cu->
y0;
1169 x +=
pps->min_cb_width;
1178 const int rx = x0 >>
sps->ctb_log2_size_y;
1179 const int ry = y0 >>
sps->ctb_log2_size_y;
1197 const int cb_width,
const int cb_height,
const int cqt_depth,
const VVCTreeType tree_type)
1206 memset(&cu->
pu, 0,
sizeof(cu->
pu));
1249 for (
int j = 0; j < tu->
nb_tbs; j++) {
1267 const int diff[] = {
1274 mmvd[1] = mmvd[0] = *mmvd_offset;
1279 mmvd[
i] = *mmvd_offset;
1284 mmvd[o].
x = sign ? -mmvd[
i].
x : mmvd[
i].
x;
1285 mmvd[o].
y = sign ? -mmvd[
i].
y : mmvd[
i].
y;
1288 mvf->
mv[0].
x += mmvd[0].
x;
1289 mvf->
mv[0].
y += mmvd[0].
y;
1290 mvf->
mv[1].
x += mmvd[1].
x;
1291 mvf->
mv[1].
y += mmvd[1].
y;
1294 mvf->
mv[idx].
x += mmvd_offset->
x;
1295 mvf->
mv[idx].
y += mmvd_offset->
y;
1305 for (
int i = 0;
i < 2;
i++) {
1308 mi->mv[
i][0] = mvf->
mv[
i];
1329 int merge_subblock_idx = 0;
1331 if (
ph->max_num_subblock_merge_cand > 1) {
1348 if (
sps->r->sps_mmvd_enabled_flag)
1351 int mmvd_cand_flag = 0;
1352 if (
sps->max_num_merge_cand > 1)
1355 merge_idx = mmvd_cand_flag;
1356 }
else if (
sps->max_num_merge_cand > 1) {
1373 if (ciip_avaiable && gpm_avaiable)
1375 return sps->r->sps_ciip_enabled_flag && !cu->
skip_flag &&
1384 int merge_gpm_idx[2];
1389 merge_gpm_idx[1] = 0;
1390 if (
sps->max_num_gpm_merge_cand > 2)
1406 if (
sps->max_num_merge_cand > 1)
1426 const int is_128 = cb_width == 128 || cb_height == 128;
1427 const int ciip_avaiable =
sps->r->sps_ciip_enabled_flag &&
1428 !cu->
skip_flag && (cb_width * cb_height >= 64);
1429 const int gpm_avaiable =
sps->r->sps_gpm_enabled_flag &&
IS_B(rsh) &&
1430 (cb_width >= 8) && (cb_height >=8) &&
1431 (cb_width < 8 * cb_height) && (cb_height < 8 *cb_width);
1433 int regular_merge_flag = 1;
1435 if (!is_128 && (ciip_avaiable || gpm_avaiable))
1437 if (regular_merge_flag) {
1458 if (
sps->max_num_ibc_merge_cand > 1)
1498 for (
int i = 0;
i < 2;
i++) {
1502 for (
int i = 0;
i < 2;
i++) {
1507 for (
int i = 0;
i < 2;
i++) {
1528 if (
sps->r->sps_bcw_enabled_flag &&
mi->pred_flag ==
PF_BI &&
1529 !
w->weight_flag[
L0][
LUMA][
mi->ref_idx[0]] &&
1530 !
w->weight_flag[
L1][
LUMA][
mi->ref_idx[1]] &&
1533 cb_width * cb_height >= 256) {
1546 else if (sym_mvd_flag)
1552 const int num_cp_mv,
const int lx)
1558 int has_no_zero_mvd = 0;
1560 if (lx ==
L1 &&
ph->r->ph_mvd_l1_zero_flag &&
mi->pred_flag ==
PF_BI) {
1561 for (
int j = 0; j < num_cp_mv; j++)
1564 Mv *mvd0 = &mvds[lx][0];
1566 mvd0->
x = -mvds[
L0][0].x;
1567 mvd0->
y = -mvds[
L0][0].y;
1571 has_no_zero_mvd |= (mvd0->
x || mvd0->
y);
1572 for (
int j = 1; j < num_cp_mv; j++) {
1573 Mv *mvd = &mvds[lx][j];
1577 has_no_zero_mvd |= (mvd->
x || mvd->
y);
1580 return has_no_zero_mvd;
1586 for (
int i = 0;
i < 2;
i++) {
1588 if (
mi->pred_flag &
mask) {
1589 for (
int j = 0; j < num_cp_mv; j++) {
1590 const Mv *mvd = &mvds[
i][j];
1591 mi->mv[
i][j].x += mvd->
x * (1 << amvr_shift);
1592 mi->mv[
i][j].y += mvd->
y * (1 << amvr_shift);
1605 int mvp_l0_flag = 0;
1615 if (
sps->max_num_ibc_merge_cand > 1)
1617 if (
sps->r->sps_amvr_enabled_flag && (
mv->x ||
mv->y))
1641 int mvp_lx_flag[2] = {0};
1642 int cu_affine_type_flag = 0;
1644 int amvr_enabled, has_no_zero_mvd = 0, amvr_shift;
1648 if (
sps->r->sps_affine_enabled_flag && cb_width >= 16 && cb_height >= 16) {
1655 num_cp_mv =
mi->motion_model_idc + 1;
1657 if (
sps->r->sps_smvd_enabled_flag && !
ph->r->ph_mvd_l1_zero_flag &&
1662 for (
int i =
L0;
i <=
L1;
i++) {
1664 if (
mi->pred_flag != pred_flag) {
1666 has_no_zero_mvd |=
mvds_decode(lc, mvds, num_cp_mv,
i);
1672 sps->r->sps_amvr_enabled_flag :
sps->r->sps_affine_amvr_enabled_flag;
1673 amvr_enabled &= has_no_zero_mvd;
1677 mi->hpel_if_idx = amvr_shift == 3;
1680 if (
mi->motion_model_idc)
1687 if (
mi->motion_model_idc)
1703 const int poc =
ph->poc;
1705 const int8_t *ref_idx =
mi->ref_idx;
1714 (poc - rp0->
poc == rp1->
poc - poc) &&
1723 if (!
ph->r->ph_bdof_disabled_flag &&
1728 if (!
ph->r->ph_dmvr_disabled_flag &&
1762 MvField *dmvr_mvf =
fc->ref->tab_dmvr_mvf + idx;
1764 memcpy(dmvr_mvf, mvf,
sizeof(
MvField) *
w);
1809 const int is_128 = cb_width > 64 || cb_height > 64;
1810 int pred_mode_plt_flag = 0;
1813 CodingUnit *cu =
add_cu(lc, x0, y0, cb_width, cb_height, cqt_depth, tree_type);
1820 if (
IS_I(rsh) && is_128)
1829 if (pred_mode_plt_flag) {
1840 if (pred_mode_plt_flag) {
1852 }
else if (!pred_mode_plt_flag) {
1897 const int area = cb_width * cb_height;
1899 if ((
IS_I(rsh) &&
sps->r->sps_qtbtt_dual_tree_intra_flag) ||
1909 return 1 + !
IS_I(rsh);
1915 const int cb_width,
const int cb_height,
const VVCSplitMode split,
const int ch_type,
1921 if (mode_type_condition == 1)
1923 else if (mode_type_condition == 2) {
1926 mode_type = mode_type_curr;
1933 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
1934 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
int part_idx,
1938 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
1939 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
1942 #define CODING_TREE(x, idx) do { \
1943 ret = hls_coding_tree(lc, x, y0, cb_width / 2, cb_height, \
1944 qg_on_y, qg_on_c, cb_sub_div + 1, cqt_depth, mtt_depth + 1, \
1945 depth_offset, idx, SPLIT_BT_VER, tree_type, mode_type); \
1951 const int x1 = x0 + cb_width / 2;
1954 depth_offset += (x0 + cb_width >
pps->width) ? 1 : 0;
1956 if (x1 < pps->
width)
1965 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
1966 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
1969 #define CODING_TREE(y, idx) do { \
1970 ret = hls_coding_tree(lc, x0, y, cb_width , cb_height / 2, \
1971 qg_on_y, qg_on_c, cb_sub_div + 1, cqt_depth, mtt_depth + 1, \
1972 depth_offset, idx, SPLIT_BT_HOR, tree_type, mode_type); \
1978 const int y1 = y0 + (cb_height / 2);
1981 depth_offset += (y0 + cb_height >
pps->height) ? 1 : 0;
1992 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
1993 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
1996 #define CODING_TREE(x, w, sub_div, idx) do { \
1997 ret = hls_coding_tree(lc, x, y0, w, cb_height, \
1998 qg_on_y, qg_on_c, sub_div, cqt_depth, mtt_depth + 1, \
1999 depth_offset, idx, SPLIT_TT_VER, tree_type, mode_type); \
2005 const int x1 = x0 + cb_width / 4;
2006 const int x2 = x0 + cb_width * 3 / 4;
2022 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2023 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
2026 #define CODING_TREE(y, h, sub_div, idx) do { \
2027 ret = hls_coding_tree(lc, x0, y, cb_width, h, \
2028 qg_on_y, qg_on_c, sub_div, cqt_depth, mtt_depth + 1, \
2029 depth_offset, idx, SPLIT_TT_HOR, tree_type, mode_type); \
2035 const int y1 = y0 + (cb_height / 4);
2036 const int y2 = y0 + (3 * cb_height / 4);
2042 CODING_TREE(y0, cb_height / 4, cb_sub_div + 2, 0);
2043 CODING_TREE(y1, cb_height / 2, cb_sub_div + 1, 1);
2044 CODING_TREE(y2, cb_height / 4, cb_sub_div + 2, 2);
2052 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2053 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
2056 #define CODING_TREE(x, y, idx) do { \
2057 ret = hls_coding_tree(lc, x, y, cb_width / 2, cb_height / 2, \
2058 qg_on_y, qg_on_c, cb_sub_div + 2, cqt_depth + 1, 0, 0, \
2059 idx, SPLIT_QT, tree_type, mode_type); \
2065 const int x1 = x0 + cb_width / 2;
2066 const int y1 = y0 + cb_height / 2;
2070 if (x1 < pps->
width)
2074 if (x1 < pps->
width &&
2084 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2085 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
2097 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2098 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
int part_idx,
2109 if (
pps->r->pps_cu_qp_delta_enabled_flag && qg_on_y && cb_sub_div <= sh->cu_qp_delta_subdiv) {
2115 cb_sub_div <= sh->cu_chroma_qp_offset_subdiv) {
2120 can_split(lc, x0, y0, cb_width, cb_height, mtt_depth, depth_offset, part_idx,
2121 last_split_mode, tree_type_curr, mode_type_curr, &allowed);
2129 if (!(x0 & 31) && !(y0 & 31) && mtt_depth <= 1)
2133 cb_sub_div, cqt_depth, mtt_depth, depth_offset, tree_type, mode_type);
2143 ret =
hls_coding_unit(lc, x0, y0, cb_width, cb_height, cqt_depth, tree_type_curr, mode_type_curr);
2152 const int x0,
const int y0,
const int cb_size,
const int cqt_depth)
2157 const int cb_subdiv = 2 * cqt_depth;
2161 #define DUAL_TREE(x, y) do { \
2162 ret = dual_tree_implicit_qt_split(lc, x, y, cb_size / 2, cqt_depth + 1); \
2167 const int x1 = x0 + (cb_size / 2);
2168 const int y1 = y0 + (cb_size / 2);
2169 if (
pps->r->pps_cu_qp_delta_enabled_flag && cb_subdiv <= sh->cu_qp_delta_subdiv) {
2179 if (x1 < pps->
width)
2187 #define CODING_TREE(tree_type) do { \
2188 const int qg_on_y = tree_type == DUAL_TREE_LUMA; \
2189 ret = hls_coding_tree(lc, x0, y0, cb_size, cb_size, qg_on_y, !qg_on_y, \
2190 cb_subdiv, cqt_depth, 0, 0, 0, SPLIT_NONE, tree_type, MODE_TYPE_ALL); \
2201 #define SET_SAO(elem, value) \
2203 if (!sao_merge_up_flag && !sao_merge_left_flag) \
2204 sao->elem = value; \
2205 else if (sao_merge_left_flag) \
2206 sao->elem = CTB(fc->tab.sao, rx-1, ry).elem; \
2207 else if (sao_merge_up_flag) \
2208 sao->elem = CTB(fc->tab.sao, rx, ry-1).elem; \
2217 int sao_merge_left_flag = 0;
2218 int sao_merge_up_flag = 0;
2227 if (ry > 0 && !sao_merge_left_flag) {
2233 for (c_idx = 0; c_idx < (
fc->ps.sps->r->sps_chroma_format_idc ? 3 : 1); c_idx++) {
2235 if (!sao_used_flag) {
2250 for (
i = 0;
i < 4;
i++)
2254 for (
i = 0;
i < 4;
i++) {
2263 }
else if (c_idx != 2) {
2269 for (
i = 0;
i < 4;
i++) {
2277 sao->
offset_val[c_idx][
i + 1] *= 1 << (
fc->ps.sps->bit_depth -
FFMIN(10,
fc->ps.sps->bit_depth));
2292 uint8_t alf_use_aps_flag = 0;
2295 if (alf_use_aps_flag) {
2303 for (
int c_idx =
CB; c_idx <=
CR; c_idx++) {
2304 const uint8_t alf_enabled_flag =
2306 if (alf_enabled_flag) {
2310 if (alf->
ctb_flag[c_idx] &&
aps->num_chroma_filters > 1)
2315 if (
fc->ps.sps->r->sps_ccalf_enabled_flag) {
2318 for (
int i = 0;
i < 2;
i++) {
2320 if (cc_enabled[
i]) {
2336 const int x0,
const int y0,
const int ctu_idx,
const int rx,
const int ry)
2343 const unsigned int ctb_size =
sps->ctb_size_y;
2348 hls_sao(lc, x0 >>
sps->ctb_log2_size_y, y0 >>
sps->ctb_log2_size_y);
2352 if (
IS_I(rsh) &&
sps->r->sps_qtbtt_dual_tree_intra_flag)
2360 if (rx ==
pps->ctb_to_col_bd[rx + 1] - 1) {
2363 if (!end_of_slice_one_bit)
2366 if (ry ==
pps->ctb_to_row_bd[ry + 1] - 1) {
2368 if (!end_of_tile_one_bit)
2371 if (
fc->ps.sps->r->sps_entropy_coding_sync_enabled_flag) {
2373 if (!end_of_subset_one_bit)
2401 const int idx = mvf->
ref_idx[lx];
2404 max_y[lx][idx] =
FFMAX(max_y[lx][idx], y);
2411 for (
int sby = 0; sby <
mi->num_sb_y; sby++) {
2412 for (
int sbx = 0; sbx <
mi->num_sb_x; sbx++) {
2413 const int x0 = cu->
x0 + sbx * sbw;
2414 const int y0 = cu->
y0 + sby * sbh;
2416 for (
int lx = 0; lx < 2; lx++) {
2419 const int idx = mvf->
ref_idx[lx];
2422 max_y[lx][idx] =
FFMAX(max_y[lx][idx], y + max_dmvr_off);
2434 CTU *ctu =
fc->tab.ctus + rs;
2442 for (
int lx = 0; lx < 2; lx++)
2456 const int ctu_idx,
const int rs,
const int rx,
const int ry)
2461 const int x_ctb = rx <<
sps->ctb_log2_size_y;
2462 const int y_ctb = ry <<
sps->ctb_log2_size_y;
2463 const int ctb_size = 1 <<
sps->ctb_log2_size_y <<
sps->ctb_log2_size_y;
2467 if (rx ==
pps->ctb_to_col_bd[rx]) {
2487 const int rx,
const int ry,
const int rs)
2490 const int ctb_size =
fc->ps.sps->ctb_size_y;
2494 if (
fc->ps.pps->ctb_to_col_bd[rx] !=
fc->ps.pps->ctb_to_col_bd[rx + 1])
2496 if (
fc->ps.pps->ctb_to_row_bd[ry] !=
fc->ps.pps->ctb_to_row_bd[ry + 1])
2500 if (rx > 0 &&
fc->ps.pps->ctb_to_col_bd[rx] !=
fc->ps.pps->ctb_to_col_bd[rx - 1])
2502 if (rx > 0 &&
fc->tab.slice_idx[rs] !=
fc->tab.slice_idx[rs - 1])
2504 if (ry > 0 &&
fc->ps.pps->ctb_to_row_bd[ry] !=
fc->ps.pps->ctb_to_row_bd[ry - 1])
2506 if (ry > 0 &&
fc->tab.slice_idx[rs] !=
fc->tab.slice_idx[rs -
fc->ps.pps->ctb_width])
2515 (
fc->ps.pps->ctb_to_row_bd[ry] ==
fc->ps.pps->ctb_to_row_bd[ry - 1]);
2520 const int x0,
const int y0,
const int w,
const int h)
2555 const int min_cb_log2_size_y =
fc->ps.sps->min_cb_log2_size_y;
2556 const int x = xc >> min_cb_log2_size_y;
2557 const int y = yc >> min_cb_log2_size_y;
2558 return fc->tab.qp[
LUMA][x + y *
fc->ps.pps->min_cb_width];
2562 const int bit_depth,
const int persistent_rice_adaptation_enabled_flag)
2566 persistent_rice_adaptation_enabled_flag ? 2 * (
av_log2(
bit_depth - 10)) : 0;