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) {
1887 const int area = cb_width * cb_height;
1889 if ((
IS_I(rsh) &&
sps->r->sps_qtbtt_dual_tree_intra_flag) ||
1899 return 1 + !
IS_I(rsh);
1905 const int cb_width,
const int cb_height,
const VVCSplitMode split,
const int ch_type,
1911 if (mode_type_condition == 1)
1913 else if (mode_type_condition == 2) {
1916 mode_type = mode_type_curr;
1923 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
1924 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
int part_idx,
1928 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
1929 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
1932 #define CODING_TREE(x, idx) do { \
1933 ret = hls_coding_tree(lc, x, y0, cb_width / 2, cb_height, \
1934 qg_on_y, qg_on_c, cb_sub_div + 1, cqt_depth, mtt_depth + 1, \
1935 depth_offset, idx, SPLIT_BT_VER, tree_type, mode_type); \
1941 const int x1 = x0 + cb_width / 2;
1944 depth_offset += (x0 + cb_width >
pps->width) ? 1 : 0;
1946 if (x1 < pps->
width)
1955 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
1956 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
1959 #define CODING_TREE(y, idx) do { \
1960 ret = hls_coding_tree(lc, x0, y, cb_width , cb_height / 2, \
1961 qg_on_y, qg_on_c, cb_sub_div + 1, cqt_depth, mtt_depth + 1, \
1962 depth_offset, idx, SPLIT_BT_HOR, tree_type, mode_type); \
1968 const int y1 = y0 + (cb_height / 2);
1971 depth_offset += (y0 + cb_height >
pps->height) ? 1 : 0;
1982 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
1983 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
1986 #define CODING_TREE(x, w, sub_div, idx) do { \
1987 ret = hls_coding_tree(lc, x, y0, w, cb_height, \
1988 qg_on_y, qg_on_c, sub_div, cqt_depth, mtt_depth + 1, \
1989 depth_offset, idx, SPLIT_TT_VER, tree_type, mode_type); \
1995 const int x1 = x0 + cb_width / 4;
1996 const int x2 = x0 + cb_width * 3 / 4;
2012 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2013 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
2016 #define CODING_TREE(y, h, sub_div, idx) do { \
2017 ret = hls_coding_tree(lc, x0, y, cb_width, h, \
2018 qg_on_y, qg_on_c, sub_div, cqt_depth, mtt_depth + 1, \
2019 depth_offset, idx, SPLIT_TT_HOR, tree_type, mode_type); \
2025 const int y1 = y0 + (cb_height / 4);
2026 const int y2 = y0 + (3 * cb_height / 4);
2032 CODING_TREE(y0, cb_height / 4, cb_sub_div + 2, 0);
2033 CODING_TREE(y1, cb_height / 2, cb_sub_div + 1, 1);
2034 CODING_TREE(y2, cb_height / 4, cb_sub_div + 2, 2);
2042 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2043 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
2046 #define CODING_TREE(x, y, idx) do { \
2047 ret = hls_coding_tree(lc, x, y, cb_width / 2, cb_height / 2, \
2048 qg_on_y, qg_on_c, cb_sub_div + 2, cqt_depth + 1, 0, 0, \
2049 idx, SPLIT_QT, tree_type, mode_type); \
2055 const int x1 = x0 + cb_width / 2;
2056 const int y1 = y0 + cb_height / 2;
2060 if (x1 < pps->
width)
2064 if (x1 < pps->
width &&
2074 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2075 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
2087 int x0,
int y0,
int cb_width,
int cb_height,
int qg_on_y,
int qg_on_c,
2088 int cb_sub_div,
int cqt_depth,
int mtt_depth,
int depth_offset,
int part_idx,
2099 if (
pps->r->pps_cu_qp_delta_enabled_flag && qg_on_y && cb_sub_div <= sh->cu_qp_delta_subdiv) {
2105 cb_sub_div <= sh->cu_chroma_qp_offset_subdiv) {
2110 can_split(lc, x0, y0, cb_width, cb_height, mtt_depth, depth_offset, part_idx,
2111 last_split_mode, tree_type_curr, mode_type_curr, &allowed);
2119 if (!(x0 & 31) && !(y0 & 31) && mtt_depth <= 1)
2123 cb_sub_div, cqt_depth, mtt_depth, depth_offset, tree_type, mode_type);
2133 ret =
hls_coding_unit(lc, x0, y0, cb_width, cb_height, cqt_depth, tree_type_curr, mode_type_curr);
2142 const int x0,
const int y0,
const int cb_size,
const int cqt_depth)
2147 const int cb_subdiv = 2 * cqt_depth;
2151 #define DUAL_TREE(x, y) do { \
2152 ret = dual_tree_implicit_qt_split(lc, x, y, cb_size / 2, cqt_depth + 1); \
2157 const int x1 = x0 + (cb_size / 2);
2158 const int y1 = y0 + (cb_size / 2);
2159 if (
pps->r->pps_cu_qp_delta_enabled_flag && cb_subdiv <= sh->cu_qp_delta_subdiv) {
2169 if (x1 < pps->
width)
2177 #define CODING_TREE(tree_type) do { \
2178 const int qg_on_y = tree_type == DUAL_TREE_LUMA; \
2179 ret = hls_coding_tree(lc, x0, y0, cb_size, cb_size, qg_on_y, !qg_on_y, \
2180 cb_subdiv, cqt_depth, 0, 0, 0, SPLIT_NONE, tree_type, MODE_TYPE_ALL); \
2191 #define SET_SAO(elem, value) \
2193 if (!sao_merge_up_flag && !sao_merge_left_flag) \
2194 sao->elem = value; \
2195 else if (sao_merge_left_flag) \
2196 sao->elem = CTB(fc->tab.sao, rx-1, ry).elem; \
2197 else if (sao_merge_up_flag) \
2198 sao->elem = CTB(fc->tab.sao, rx, ry-1).elem; \
2207 int sao_merge_left_flag = 0;
2208 int sao_merge_up_flag = 0;
2217 if (ry > 0 && !sao_merge_left_flag) {
2223 for (c_idx = 0; c_idx < (
fc->ps.sps->r->sps_chroma_format_idc ? 3 : 1); c_idx++) {
2225 if (!sao_used_flag) {
2240 for (
i = 0;
i < 4;
i++)
2244 for (
i = 0;
i < 4;
i++) {
2253 }
else if (c_idx != 2) {
2259 for (
i = 0;
i < 4;
i++) {
2267 sao->
offset_val[c_idx][
i + 1] *= 1 << (
fc->ps.sps->bit_depth -
FFMIN(10,
fc->ps.sps->bit_depth));
2282 uint8_t alf_use_aps_flag = 0;
2285 if (alf_use_aps_flag) {
2293 for (
int c_idx =
CB; c_idx <=
CR; c_idx++) {
2294 const uint8_t alf_enabled_flag =
2296 if (alf_enabled_flag) {
2300 if (alf->
ctb_flag[c_idx] &&
aps->num_chroma_filters > 1)
2305 if (
fc->ps.sps->r->sps_ccalf_enabled_flag) {
2308 for (
int i = 0;
i < 2;
i++) {
2310 if (cc_enabled[
i]) {
2326 const int x0,
const int y0,
const int ctu_idx,
const int rx,
const int ry)
2333 const unsigned int ctb_size =
sps->ctb_size_y;
2338 hls_sao(lc, x0 >>
sps->ctb_log2_size_y, y0 >>
sps->ctb_log2_size_y);
2342 if (
IS_I(rsh) &&
sps->r->sps_qtbtt_dual_tree_intra_flag)
2350 if (rx ==
pps->ctb_to_col_bd[rx + 1] - 1) {
2353 if (!end_of_slice_one_bit)
2356 if (ry ==
pps->ctb_to_row_bd[ry + 1] - 1) {
2358 if (!end_of_tile_one_bit)
2361 if (
fc->ps.sps->r->sps_entropy_coding_sync_enabled_flag) {
2363 if (!end_of_subset_one_bit)
2391 const int idx = mvf->
ref_idx[lx];
2394 max_y[lx][idx] =
FFMAX(max_y[lx][idx], y);
2401 for (
int sby = 0; sby <
mi->num_sb_y; sby++) {
2402 for (
int sbx = 0; sbx <
mi->num_sb_x; sbx++) {
2403 const int x0 = cu->
x0 + sbx * sbw;
2404 const int y0 = cu->
y0 + sby * sbh;
2406 for (
int lx = 0; lx < 2; lx++) {
2409 const int idx = mvf->
ref_idx[lx];
2412 max_y[lx][idx] =
FFMAX(max_y[lx][idx], y + max_dmvr_off);
2424 CTU *ctu =
fc->tab.ctus + rs;
2430 for (
int lx = 0; lx < 2; lx++)
2444 const int ctu_idx,
const int rs,
const int rx,
const int ry)
2449 const int x_ctb = rx <<
sps->ctb_log2_size_y;
2450 const int y_ctb = ry <<
sps->ctb_log2_size_y;
2451 const int ctb_size = 1 <<
sps->ctb_log2_size_y <<
sps->ctb_log2_size_y;
2455 if (rx ==
pps->ctb_to_col_bd[rx]) {
2475 const int rx,
const int ry,
const int rs)
2478 const int ctb_size =
fc->ps.sps->ctb_size_y;
2482 if (
fc->ps.pps->ctb_to_col_bd[rx] !=
fc->ps.pps->ctb_to_col_bd[rx + 1])
2484 if (
fc->ps.pps->ctb_to_row_bd[ry] !=
fc->ps.pps->ctb_to_row_bd[ry + 1])
2488 if (rx > 0 &&
fc->ps.pps->ctb_to_col_bd[rx] !=
fc->ps.pps->ctb_to_col_bd[rx - 1])
2490 if (rx > 0 &&
fc->tab.slice_idx[rs] !=
fc->tab.slice_idx[rs - 1])
2492 if (ry > 0 &&
fc->ps.pps->ctb_to_row_bd[ry] !=
fc->ps.pps->ctb_to_row_bd[ry - 1])
2494 if (ry > 0 &&
fc->tab.slice_idx[rs] !=
fc->tab.slice_idx[rs -
fc->ps.pps->ctb_width])
2499 (
fc->ps.pps->ctb_to_row_bd[ry] ==
fc->ps.pps->ctb_to_row_bd[ry - 1]);
2504 const int x0,
const int y0,
const int w,
const int h)
2540 const int min_cb_log2_size_y =
fc->ps.sps->min_cb_log2_size_y;
2541 const int x = xc >> min_cb_log2_size_y;
2542 const int y = yc >> min_cb_log2_size_y;
2543 return fc->tab.qp[
LUMA][x + y *
fc->ps.pps->min_cb_width];
2547 const int bit_depth,
const int persistent_rice_adaptation_enabled_flag)
2551 persistent_rice_adaptation_enabled_flag ? 2 * (
av_log2(
bit_depth - 10)) : 0;