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;
57 memset(
fc->tab.tb_width [is_chroma] + off,
tb->tb_width,
width);
58 memset(
fc->tab.tb_height[is_chroma] + off,
tb->tb_height,
width);
65 const int width =
tb->tb_width <<
fc->ps.sps->hshift[
tb->c_idx];
66 const int height =
tb->tb_height <<
fc->ps.sps->vshift[
tb->c_idx];
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 x_ctb = cu->
x0 >> ctb_log2_size;
91 const int y_ctb = cu->
y0 >> ctb_log2_size;
92 const int in_same_ctb_a = ((xQg - 1) >> ctb_log2_size) == x_ctb && (yQg >> ctb_log2_size) == y_ctb;
93 const int in_same_ctb_b = (xQg >> ctb_log2_size) == x_ctb && ((yQg - 1) >> ctb_log2_size) == y_ctb;
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;
182 const int idx = is_jcbcr ?
JCBCR :
tb->c_idx;
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)
258 tb->tb_width = tb_width;
259 tb->tb_height = tb_height;
263 tb->max_scan_x =
tb->max_scan_y = 0;
264 tb->min_scan_x =
tb->min_scan_y = 0;
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);
381 const int is_chroma =
tb->c_idx !=
LUMA;
383 if (
tb->has_coeffs && is_chroma)
385 if (
tb->has_coeffs) {
387 if (
sps->r->sps_transform_skip_enabled_flag && !cu->
bdpcm_flag[
tb->c_idx] &&
388 tb->tb_width <=
sps->max_ts_size &&
tb->tb_height <=
sps->max_ts_size &&
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)
1098 && cb_width <= sps->max_tb_size_y && cb_height <= sps->max_tb_size_y) {
1099 const int sbt_ver_h = cb_width >= 8;
1100 const int sbt_hor_h = cb_height >= 8;
1102 if (sbt_ver_h || sbt_hor_h)
1105 const int sbt_ver_q = cb_width >= 16;
1106 const int sbt_hor_q = cb_height >= 16;
1107 int cu_sbt_quad_flag = 0;
1109 if ((sbt_ver_h || sbt_hor_h) && (sbt_ver_q || sbt_hor_q))
1111 if (cu_sbt_quad_flag) {
1113 if (sbt_ver_q && sbt_hor_q)
1117 if (sbt_ver_h && sbt_hor_h)
1123 const int sbt_min = cu_sbt_quad_flag ? 1 : 2;
1150 const int log2_min_cb_size =
sps->min_cb_log2_size_y;
1151 const int x_cb = cu->
x0 >> log2_min_cb_size;
1152 const int y_cb = cu->
y0 >> log2_min_cb_size;
1153 const int ch_type = cu->
ch_type;
1156 x = y_cb *
pps->min_cb_width + x_cb;
1157 for (y = 0; y < (cu->
cb_height >> log2_min_cb_size); y++) {
1161 fc->tab.cb_pos_x[ch_type][x +
i] = cu->
x0;
1162 fc->tab.cb_pos_y[ch_type][x +
i] = cu->
y0;
1168 x +=
pps->min_cb_width;
1177 const int rx = x0 >>
sps->ctb_log2_size_y;
1178 const int ry = y0 >>
sps->ctb_log2_size_y;
1179 CTU *ctu =
fc->tab.ctus + ry *
pps->ctb_width + rx;
1196 const int cb_width,
const int cb_height,
const int cqt_depth,
const VVCTreeType tree_type)
1205 memset(&cu->
pu, 0,
sizeof(cu->
pu));
1245 for (
int j = 0; j < tu->
nb_tbs; j++) {
1265 const int diff[] = {
1272 mmvd[1] = mmvd[0] = *mmvd_offset;
1277 mmvd[
i] = *mmvd_offset;
1282 mmvd[o].
x = sign ? -mmvd[
i].
x : mmvd[
i].
x;
1283 mmvd[o].
y = sign ? -mmvd[
i].
y : mmvd[
i].
y;
1286 mvf->
mv[0].
x += mmvd[0].
x;
1287 mvf->
mv[0].
y += mmvd[0].
y;
1288 mvf->
mv[1].
x += mmvd[1].
x;
1289 mvf->
mv[1].
y += mmvd[1].
y;
1292 mvf->
mv[idx].
x += mmvd_offset->
x;
1293 mvf->
mv[idx].
y += mmvd_offset->
y;
1303 for (
int i = 0;
i < 2;
i++) {
1306 mi->mv[
i][0] = mvf->
mv[
i];
1327 int merge_subblock_idx = 0;
1330 if (
ph->max_num_subblock_merge_cand > 1) {
1347 if (
sps->r->sps_mmvd_enabled_flag)
1350 int mmvd_cand_flag = 0;
1351 if (
sps->max_num_merge_cand > 1)
1354 merge_idx = mmvd_cand_flag;
1355 }
else if (
sps->max_num_merge_cand > 1) {
1372 if (ciip_avaiable && gpm_avaiable)
1374 return sps->r->sps_ciip_enabled_flag && !cu->
skip_flag &&
1383 int merge_gpm_idx[2];
1388 merge_gpm_idx[1] = 0;
1389 if (
sps->max_num_gpm_merge_cand > 2)
1405 if (
sps->max_num_merge_cand > 1)
1425 const int is_128 = cb_width == 128 || cb_height == 128;
1426 const int ciip_avaiable =
sps->r->sps_ciip_enabled_flag &&
1427 !cu->
skip_flag && (cb_width * cb_height >= 64);
1428 const int gpm_avaiable =
sps->r->sps_gpm_enabled_flag &&
IS_B(rsh) &&
1429 (cb_width >= 8) && (cb_height >=8) &&
1430 (cb_width < 8 * cb_height) && (cb_height < 8 *cb_width);
1432 int regular_merge_flag = 1;
1434 if (!is_128 && (ciip_avaiable || gpm_avaiable))
1436 if (regular_merge_flag) {
1456 if (
sps->max_num_ibc_merge_cand > 1)
1489 for (
int i = 0;
i < 2;
i++) {
1493 for (
int i = 0;
i < 2;
i++) {
1498 for (
int i = 0;
i < 2;
i++) {
1519 if (
sps->r->sps_bcw_enabled_flag &&
mi->pred_flag ==
PF_BI &&
1520 !
w->weight_flag[
L0][
LUMA][
mi->ref_idx[0]] &&
1521 !
w->weight_flag[
L1][
LUMA][
mi->ref_idx[1]] &&
1524 cb_width * cb_height >= 256) {
1537 else if (sym_mvd_flag)
1543 const int num_cp_mv,
const int lx)
1549 int has_no_zero_mvd = 0;
1551 if (lx ==
L1 &&
ph->r->ph_mvd_l1_zero_flag &&
mi->pred_flag ==
PF_BI) {
1552 for (
int j = 0; j < num_cp_mv; j++)
1555 Mv *mvd0 = &mvds[lx][0];
1557 mvd0->
x = -mvds[
L0][0].x;
1558 mvd0->
y = -mvds[
L0][0].y;
1562 has_no_zero_mvd |= (mvd0->
x || mvd0->
y);
1563 for (
int j = 1; j < num_cp_mv; j++) {
1564 Mv *mvd = &mvds[lx][j];
1568 has_no_zero_mvd |= (mvd->
x || mvd->
y);
1571 return has_no_zero_mvd;
1577 for (
int i = 0;
i < 2;
i++) {
1579 if (
mi->pred_flag &
mask) {
1580 for (
int j = 0; j < num_cp_mv; j++) {
1581 const Mv *mvd = &mvds[
i][j];
1582 mi->mv[
i][j].x += mvd->
x * (1 << amvr_shift);
1583 mi->mv[
i][j].y += mvd->
y * (1 << amvr_shift);
1596 int mvp_l0_flag = 0;
1605 if (
sps->max_num_ibc_merge_cand > 1)
1607 if (
sps->r->sps_amvr_enabled_flag && (
mv->x ||
mv->y))
1629 int mvp_lx_flag[2] = {0};
1630 int cu_affine_type_flag = 0;
1632 int amvr_enabled, has_no_zero_mvd = 0, amvr_shift;
1636 if (
sps->r->sps_affine_enabled_flag && cb_width >= 16 && cb_height >= 16) {
1643 num_cp_mv =
mi->motion_model_idc + 1;
1645 if (
sps->r->sps_smvd_enabled_flag && !
ph->r->ph_mvd_l1_zero_flag &&
1650 for (
int i =
L0;
i <=
L1;
i++) {
1652 if (
mi->pred_flag != pred_flag) {
1654 has_no_zero_mvd |=
mvds_decode(lc, mvds, num_cp_mv,
i);
1660 sps->r->sps_amvr_enabled_flag :
sps->r->sps_affine_amvr_enabled_flag;
1661 amvr_enabled &= has_no_zero_mvd;
1665 mi->hpel_if_idx = amvr_shift == 3;
1668 if (
mi->motion_model_idc)
1675 if (
mi->motion_model_idc)
1691 const int poc =
ph->poc;
1702 (poc - rpl0->
list[ref_idx[
L0]] == rpl1->
list[ref_idx[
L1]] - poc) &&
1711 if (!
ph->r->ph_bdof_disabled_flag &&
1716 if (!
ph->r->ph_dmvr_disabled_flag &&
1750 MvField *dmvr_mvf =
fc->ref->tab_dmvr_mvf + idx;
1752 memcpy(dmvr_mvf, mvf,
sizeof(
MvField) *
w);
1797 const int is_128 = cb_width > 64 || cb_height > 64;
1798 int pred_mode_plt_flag = 0;
1801 CodingUnit *cu =
add_cu(lc, x0, y0, cb_width, cb_height, cqt_depth, tree_type);
1808 if (
IS_I(rsh) && is_128)
1817 if (pred_mode_plt_flag) {
1828 if (pred_mode_plt_flag) {
1840 }
else if (!pred_mode_plt_flag) {
1885 const int area = cb_width * cb_height;
1887 if ((
IS_I(rsh) &&
sps->r->sps_qtbtt_dual_tree_intra_flag) ||
1897 return 1 + !
IS_I(rsh);
1903 const int cb_width,
const int cb_height,
const VVCSplitMode split,
const int ch_type,
1909 if (mode_type_condition == 1)
1911 else if (mode_type_condition == 2) {
1914 mode_type = mode_type_curr;
1921 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
1922 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
int part_idx,
1926 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
1927 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
1930 #define CODING_TREE(x, idx) do { \
1931 ret = hls_coding_tree(lc, x, y0, cb_width / 2, cb_height, \
1932 qg_on_y, qg_on_c, cb_sub_div + 1, cqt_depth, mtt_depth + 1, \
1933 depth_offset, idx, SPLIT_BT_VER, tree_type, mode_type); \
1939 const int x1 = x0 + cb_width / 2;
1942 depth_offset += (x0 + cb_width >
pps->width) ? 1 : 0;
1944 if (x1 < pps->
width)
1953 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
1954 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
1957 #define CODING_TREE(y, idx) do { \
1958 ret = hls_coding_tree(lc, x0, y, cb_width , cb_height / 2, \
1959 qg_on_y, qg_on_c, cb_sub_div + 1, cqt_depth, mtt_depth + 1, \
1960 depth_offset, idx, SPLIT_BT_HOR, tree_type, mode_type); \
1966 const int y1 = y0 + (cb_height / 2);
1969 depth_offset += (y0 + cb_height >
pps->height) ? 1 : 0;
1980 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
1981 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
1984 #define CODING_TREE(x, w, sub_div, idx) do { \
1985 ret = hls_coding_tree(lc, x, y0, w, cb_height, \
1986 qg_on_y, qg_on_c, sub_div, cqt_depth, mtt_depth + 1, \
1987 depth_offset, idx, SPLIT_TT_VER, tree_type, mode_type); \
1993 const int x1 = x0 + cb_width / 4;
1994 const int x2 = x0 + cb_width * 3 / 4;
2010 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2011 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
2014 #define CODING_TREE(y, h, sub_div, idx) do { \
2015 ret = hls_coding_tree(lc, x0, y, cb_width, h, \
2016 qg_on_y, qg_on_c, sub_div, cqt_depth, mtt_depth + 1, \
2017 depth_offset, idx, SPLIT_TT_HOR, tree_type, mode_type); \
2023 const int y1 = y0 + (cb_height / 4);
2024 const int y2 = y0 + (3 * cb_height / 4);
2030 CODING_TREE(y0, cb_height / 4, cb_sub_div + 2, 0);
2031 CODING_TREE(y1, cb_height / 2, cb_sub_div + 1, 1);
2032 CODING_TREE(y2, cb_height / 4, cb_sub_div + 2, 2);
2040 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2041 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
2044 #define CODING_TREE(x, y, idx) do { \
2045 ret = hls_coding_tree(lc, x, y, cb_width / 2, cb_height / 2, \
2046 qg_on_y, qg_on_c, cb_sub_div + 2, cqt_depth + 1, 0, 0, \
2047 idx, SPLIT_QT, tree_type, mode_type); \
2053 const int x1 = x0 + cb_width / 2;
2054 const int y1 = y0 + cb_height / 2;
2058 if (x1 < pps->
width)
2062 if (x1 < pps->
width &&
2072 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2073 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
2085 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2086 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
int part_idx,
2097 if (
pps->r->pps_cu_qp_delta_enabled_flag && qg_on_y && cb_sub_div <= sh->cu_qp_delta_subdiv) {
2103 cb_sub_div <= sh->cu_chroma_qp_offset_subdiv) {
2108 can_split(lc, x0, y0, cb_width, cb_height, mtt_depth, depth_offset, part_idx,
2109 last_split_mode, tree_type_curr, mode_type_curr, &allowed);
2117 if (!(x0 & 31) && !(y0 & 31) && mtt_depth <= 1)
2121 cb_sub_div, cqt_depth, mtt_depth, depth_offset, tree_type, mode_type);
2131 ret =
hls_coding_unit(lc, x0, y0, cb_width, cb_height, cqt_depth, tree_type_curr, mode_type_curr);
2140 const int x0,
const int y0,
const int cb_size,
const int cqt_depth)
2145 const int cb_subdiv = 2 * cqt_depth;
2149 #define DUAL_TREE(x, y) do { \
2150 ret = dual_tree_implicit_qt_split(lc, x, y, cb_size / 2, cqt_depth + 1); \
2155 const int x1 = x0 + (cb_size / 2);
2156 const int y1 = y0 + (cb_size / 2);
2157 if (
pps->r->pps_cu_qp_delta_enabled_flag && cb_subdiv <= sh->cu_qp_delta_subdiv) {
2167 if (x1 < pps->
width)
2175 #define CODING_TREE(tree_type) do { \
2176 const int qg_on_y = tree_type == DUAL_TREE_LUMA; \
2177 ret = hls_coding_tree(lc, x0, y0, cb_size, cb_size, qg_on_y, !qg_on_y, \
2178 cb_subdiv, cqt_depth, 0, 0, 0, SPLIT_NONE, tree_type, MODE_TYPE_ALL); \
2189 #define SET_SAO(elem, value) \
2191 if (!sao_merge_up_flag && !sao_merge_left_flag) \
2192 sao->elem = value; \
2193 else if (sao_merge_left_flag) \
2194 sao->elem = CTB(fc->tab.sao, rx-1, ry).elem; \
2195 else if (sao_merge_up_flag) \
2196 sao->elem = CTB(fc->tab.sao, rx, ry-1).elem; \
2205 int sao_merge_left_flag = 0;
2206 int sao_merge_up_flag = 0;
2215 if (ry > 0 && !sao_merge_left_flag) {
2221 for (c_idx = 0; c_idx < (
fc->ps.sps->r->sps_chroma_format_idc ? 3 : 1); c_idx++) {
2223 if (!sao_used_flag) {
2238 for (
i = 0;
i < 4;
i++)
2242 for (
i = 0;
i < 4;
i++) {
2251 }
else if (c_idx != 2) {
2257 for (
i = 0;
i < 4;
i++) {
2265 sao->
offset_val[c_idx][
i + 1] *= 1 << (
fc->ps.sps->bit_depth -
FFMIN(10,
fc->ps.sps->bit_depth));
2280 uint8_t alf_use_aps_flag = 0;
2283 if (alf_use_aps_flag) {
2291 for (
int c_idx =
CB; c_idx <=
CR; c_idx++) {
2292 const uint8_t alf_enabled_flag =
2294 if (alf_enabled_flag) {
2298 if (alf->
ctb_flag[c_idx] &&
aps->num_chroma_filters > 1)
2303 if (
fc->ps.sps->r->sps_ccalf_enabled_flag) {
2306 for (
int i = 0;
i < 2;
i++) {
2308 if (cc_enabled[
i]) {
2324 const int x0,
const int y0,
const int ctu_idx,
const int rx,
const int ry)
2331 const unsigned int ctb_size =
sps->ctb_size_y;
2336 hls_sao(lc, x0 >>
sps->ctb_log2_size_y, y0 >>
sps->ctb_log2_size_y);
2340 if (
IS_I(rsh) &&
sps->r->sps_qtbtt_dual_tree_intra_flag)
2348 if (rx ==
pps->ctb_to_col_bd[rx + 1] - 1) {
2351 if (!end_of_slice_one_bit)
2354 if (ry ==
pps->ctb_to_row_bd[ry + 1] - 1) {
2356 if (!end_of_tile_one_bit)
2359 if (
fc->ps.sps->r->sps_entropy_coding_sync_enabled_flag) {
2361 if (!end_of_subset_one_bit)
2389 const int idx = mvf->
ref_idx[lx];
2392 max_y[lx][idx] =
FFMAX(max_y[lx][idx], y);
2399 for (
int sby = 0; sby <
mi->num_sb_y; sby++) {
2400 for (
int sbx = 0; sbx <
mi->num_sb_x; sbx++) {
2401 const int x0 = cu->
x0 + sbx * sbw;
2402 const int y0 = cu->
y0 + sby * sbh;
2404 for (
int lx = 0; lx < 2; lx++) {
2407 const int idx = mvf->
ref_idx[lx];
2410 max_y[lx][idx] =
FFMAX(max_y[lx][idx], y + max_dmvr_off);
2422 CTU *ctu =
fc->tab.ctus + rs;
2428 for (
int lx = 0; lx < 2; lx++)
2442 const int ctu_idx,
const int rs,
const int rx,
const int ry)
2447 const int x_ctb = rx <<
sps->ctb_log2_size_y;
2448 const int y_ctb = ry <<
sps->ctb_log2_size_y;
2449 const int ctb_size = 1 <<
sps->ctb_log2_size_y <<
sps->ctb_log2_size_y;
2453 if (rx ==
pps->ctb_to_col_bd[rx]) {
2473 const int rx,
const int ry,
const int rs)
2476 const int ctb_size =
fc->ps.sps->ctb_size_y;
2480 if (
fc->ps.pps->ctb_to_col_bd[rx] !=
fc->ps.pps->ctb_to_col_bd[rx + 1])
2482 if (
fc->ps.pps->ctb_to_row_bd[ry] !=
fc->ps.pps->ctb_to_row_bd[ry + 1])
2486 if (rx > 0 &&
fc->ps.pps->ctb_to_col_bd[rx] !=
fc->ps.pps->ctb_to_col_bd[rx - 1])
2488 if (rx > 0 &&
fc->tab.slice_idx[rs] !=
fc->tab.slice_idx[rs - 1])
2490 if (ry > 0 &&
fc->ps.pps->ctb_to_row_bd[ry] !=
fc->ps.pps->ctb_to_row_bd[ry - 1])
2492 if (ry > 0 &&
fc->tab.slice_idx[rs] !=
fc->tab.slice_idx[rs -
fc->ps.pps->ctb_width])
2497 (
fc->ps.pps->ctb_to_row_bd[ry] ==
fc->ps.pps->ctb_to_row_bd[ry - 1]);
2502 const int x0,
const int y0,
const int w,
const int h)
2538 const int min_cb_log2_size_y =
fc->ps.sps->min_cb_log2_size_y;
2539 const int x = xc >> min_cb_log2_size_y;
2540 const int y = yc >> min_cb_log2_size_y;
2541 return fc->tab.qp[
LUMA][x + y *
fc->ps.pps->min_cb_width];
2545 const int bit_depth,
const int persistent_rice_adaptation_enabled_flag)
2549 persistent_rice_adaptation_enabled_flag ? 2 * (
av_log2(
bit_depth - 10)) : 0;