28 #define CABAC_MAX_BIN 31
114 62, 39, 39, 54, 39, 39, 31, 39, 39,
128 19, 28, 38, 27, 29, 38, 20, 30, 31,
130 27, 6, 15, 25, 19, 37,
212 50, 37, 45, 30, 46, 45, 38, 46,
250 13, 5, 4, 21, 14, 4, 6, 14, 21, 11, 14, 7, 14, 5, 11, 21,
251 30, 22, 13, 42, 12, 4, 3,
253 13, 5, 4, 6, 13, 11, 14, 6, 5, 3, 14, 22, 6, 4, 3, 6,
254 22, 29, 20, 34, 12, 4, 3,
256 18, 31, 25, 15, 18, 20, 38,
258 25, 19, 28, 14, 25, 20, 29, 30, 19, 37, 30, 38, 11, 38, 46, 54,
259 27, 39, 39, 39, 44, 39, 39, 39, 18, 39, 39, 39, 27, 39, 39, 39,
260 0, 39, 39, 39, 25, 27, 28, 37, 34, 53, 53, 46, 19, 46, 38, 39,
261 52, 39, 39, 39, 11, 39, 39, 39, 19, 39, 39, 39, 25, 28, 38,
263 33, 25, 18, 26, 34, 27, 25, 26, 19, 42, 35, 33, 19, 27, 35, 35,
264 34, 42, 20, 43, 20, 33, 25, 26, 42, 19, 27, 26, 50, 35, 20, 43,
267 25, 25, 11, 27, 20, 21, 33, 12, 28, 21, 22, 34, 28, 29, 29, 30,
268 36, 29, 45, 30, 23, 40, 33, 27, 28, 21, 37, 36, 37, 45, 38, 46,
269 25, 1, 40, 25, 33, 11, 17, 25, 25, 18, 4, 17, 33, 26, 19, 13,
270 33, 19, 20, 28, 22, 40, 9, 25, 18, 26, 35, 25, 26, 35, 28, 37,
271 11, 5, 5, 14, 10, 3, 3, 3,
273 12, 17, 46, 28, 25, 46,
277 13, 23, 46, 4, 61, 54, 19, 46, 54,
291 11, 35, 53, 12, 6, 30, 13, 15, 31,
293 20, 14, 23, 18, 19, 6,
375 51, 30, 30, 38, 23, 38, 53, 46,
413 6, 13, 12, 6, 6, 12, 14, 14, 13, 12, 29, 7, 6, 13, 36, 28,
414 14, 13, 5, 26, 12, 4, 18,
416 5, 5, 12, 6, 6, 4, 6, 14, 5, 12, 14, 7, 13, 5, 13, 21,
417 14, 20, 12, 34, 11, 4, 18,
419 25, 30, 25, 45, 18, 12, 29,
421 17, 41, 42, 29, 25, 49, 43, 37, 33, 58, 51, 30, 19, 38, 38, 46,
422 34, 54, 54, 39, 6, 39, 39, 39, 19, 39, 54, 39, 19, 39, 39, 39,
423 56, 39, 39, 39, 17, 34, 35, 21, 41, 59, 60, 38, 35, 45, 53, 54,
424 44, 39, 39, 39, 34, 38, 62, 39, 26, 39, 39, 39, 40, 35, 44,
426 18, 17, 33, 18, 26, 42, 25, 33, 26, 42, 27, 25, 34, 42, 42, 35,
427 26, 27, 42, 20, 20, 25, 25, 26, 11, 19, 27, 33, 42, 35, 35, 43,
430 0, 17, 26, 19, 35, 21, 25, 34, 20, 28, 29, 33, 27, 28, 29, 22,
431 34, 28, 44, 37, 38, 0, 25, 19, 20, 13, 14, 57, 44, 30, 30, 23,
432 17, 0, 1, 17, 25, 18, 0, 9, 25, 33, 34, 9, 25, 18, 26, 20,
433 25, 18, 19, 27, 29, 17, 9, 25, 10, 18, 4, 17, 33, 19, 20, 29,
434 18, 11, 4, 28, 2, 10, 3, 3,
436 5, 10, 53, 43, 25, 46,
440 33, 52, 46, 25, 61, 54, 25, 61, 54,
454 18, 27, 15, 18, 28, 45, 26, 7, 23,
456 26, 36, 38, 18, 34, 21,
538 58, 45, 45, 30, 38, 45, 38, 46,
576 6, 6, 12, 14, 6, 4, 14, 7, 6, 4, 29, 7, 6, 6, 12, 28,
577 7, 13, 13, 35, 19, 5, 4,
579 5, 5, 20, 13, 13, 19, 21, 6, 12, 12, 14, 14, 5, 4, 12, 13,
580 7, 13, 12, 41, 11, 5, 27,
582 25, 45, 25, 14, 18, 35, 45,
584 17, 41, 49, 36, 1, 49, 50, 37, 48, 51, 58, 45, 26, 45, 53, 46,
585 49, 54, 61, 39, 35, 39, 39, 39, 19, 54, 39, 39, 50, 39, 39, 39,
586 0, 39, 39, 39, 9, 49, 50, 36, 48, 59, 59, 38, 34, 45, 38, 31,
587 58, 39, 39, 39, 34, 38, 54, 39, 41, 39, 39, 39, 25, 50, 37,
589 33, 40, 25, 41, 26, 42, 25, 33, 26, 34, 27, 25, 41, 42, 42, 35,
590 33, 27, 35, 42, 43, 33, 25, 26, 34, 19, 27, 33, 42, 43, 35, 43,
593 0, 0, 33, 34, 35, 21, 25, 34, 35, 28, 29, 40, 42, 43, 29, 30,
594 49, 36, 37, 45, 38, 0, 40, 34, 43, 36, 37, 57, 52, 45, 38, 46,
595 25, 0, 0, 17, 25, 26, 0, 9, 25, 33, 19, 0, 25, 33, 26, 20,
596 25, 33, 27, 35, 22, 25, 1, 25, 33, 26, 12, 25, 33, 27, 28, 37,
597 19, 11, 4, 6, 3, 4, 4, 5,
599 35, 25, 46, 28, 33, 38,
604 0, 0, 0, 4, 0, 0, 1, 0, 0,
618 12, 13, 8, 8, 13, 12, 5, 9, 9,
702 9, 6, 9, 10, 5, 0, 9, 5,
740 8, 5, 4, 5, 4, 4, 5, 4, 1, 0, 4, 1, 0, 0, 0, 0,
743 8, 5, 8, 5, 5, 4, 5, 5, 4, 0, 5, 4, 1, 0, 0, 1,
748 12, 9, 9, 10, 9, 9, 9, 10, 8, 8, 8, 10, 9, 13, 8, 8,
749 8, 8, 8, 5, 8, 0, 0, 0, 8, 8, 8, 8, 8, 0, 4, 4,
750 0, 0, 0, 0, 12, 12, 9, 13, 4, 5, 8, 9, 8, 12, 12, 8,
751 4, 0, 0, 0, 8, 8, 8, 8, 4, 0, 0, 0, 13, 13, 8,
753 8, 9, 12, 13, 13, 13, 10, 13, 13, 13, 13, 13, 13, 13, 13, 13,
754 10, 13, 13, 13, 13, 8, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13,
757 9, 5, 10, 13, 13, 10, 9, 10, 13, 13, 13, 9, 10, 10, 10, 13,
758 8, 9, 10, 10, 13, 8, 8, 9, 12, 12, 10, 5, 9, 9, 9, 13,
759 1, 5, 9, 9, 9, 6, 5, 9, 10, 10, 9, 9, 9, 9, 9, 9,
760 6, 8, 9, 9, 10, 1, 5, 8, 8, 9, 6, 6, 9, 8, 8, 9,
761 4, 2, 1, 6, 1, 1, 1, 1,
767 #define MAX_SUB_BLOCKS 16
768 #define MAX_SUB_BLOCK_SIZE 4
769 #define MAX_TB_SIZE 64
831 const int m = (init_value >> 3) - 4;
832 const int n = ((init_value & 7) * 18) + 1;
833 const int pre =
av_clip(((m * (qp - 16)) >> 1) + n, 1, 127);
835 state->state[0] = pre << 3;
836 state->state[1] = pre << 7;
837 state->shift[0] = (shift_idx >> 2 ) + 2;
838 state->shift[1] = (shift_idx & 3 ) + 3 +
state->shift[0];
843 const int ctu_idx,
const int rx,
const int ry)
847 const int first_ctb_in_slice = !ctu_idx;
848 const int first_ctb_in_tile = rx ==
pps->ctb_to_col_bd[rx] && ry ==
pps->ctb_to_row_bd[ry];
850 if (first_ctb_in_slice|| first_ctb_in_tile) {
851 if (lc->
sc->
nb_eps == 1 && !first_ctb_in_slice)
864 x =
c->low ^ (
c->low - 1);
873 x += (
c->bytestream[0] << 9) + (
c->bytestream[1] << 1);
875 x +=
c->bytestream[0] << 1;
879 #if !UNCHECKED_BITSTREAM_READER
880 if (
c->bytestream <
c->bytestream_end)
888 const int qRangeIdx =
c->range >> 5;
889 const int pState =
s->state[1] + (
s->state[0] << 4);
890 const int valMps = pState >> 14;
891 const int RangeLPS = (qRangeIdx * ((valMps ? 32767 - pState : pState) >> 9 ) >> 1) + 4;
894 c->range -= RangeLPS;
898 c->range += (RangeLPS -
c->range) & lps_mask;
900 bit = valMps ^ (lps_mask & 1);
903 c->range <<= lps_mask;
908 s->state[0] =
s->state[0] - (
s->state[0] >>
s->shift[0]) + (1023 *
bit >>
s->shift[0]);
909 s->state[1] =
s->state[1] - (
s->state[1] >>
s->shift[1]) + (16383 *
bit >>
s->shift[1]);
913 #define GET_CABAC(ctx) vvc_get_cabac(&lc->ep->cc, lc->ep->cabac_state, ctx)
918 const int n = c_max + 1;
920 const int u = (1 << (k+1)) - n;
922 for (
int i = 0;
i < k;
i++)
939 if (pre_ext_len == max_pre_ext_len)
940 escape_length = trunc_suffix_len;
942 escape_length = pre_ext_len + k;
943 while (escape_length-- > 0) {
946 val += ((1 << pre_ext_len) - 1) << k;
952 const int x0,
const int y0,
const uint8_t *left_ctx,
const uint8_t *top_ctx)
956 const int min_cb_width =
fc->ps.pps->min_cb_width;
959 const int x_cb = x0 >>
sps->min_cb_log2_size_y;
960 const int y_cb = y0 >>
sps->min_cb_log2_size_y;
971 uint8_t
left = 0, top = 0;
995 for (
int i = 0;
i < 4;
i++)
1024 int inc = c_idx * 3;
1028 inc +=
left->ctb_flag[c_idx];
1055 const int length = num_chroma_filters - 1;
1069 inc +=
left->ctb_cc_idc[idx] != 0;
1085 const int cb_width,
const int cb_height,
const int is_chroma,
const VVCAllowedSplit *
a)
1089 const int is_inside = (x0 + cb_width <=
pps->width) && (y0 + cb_height <= pps->
height);
1091 if ((
a->btv ||
a->bth ||
a->ttv ||
a->tth ||
a->qt) &&
is_inside)
1093 uint8_t inc = 0, left_height = cb_height, top_width = cb_width;
1095 get_left_top(lc, &left_height, &top_width, x0, y0,
fc->tab.cb_height[is_chroma],
fc->tab.cb_width[is_chroma]);
1096 inc += left_height < cb_height;
1097 inc += top_width < cb_width;
1098 inc += (
a->btv +
a->bth +
a->ttv +
a->tth + 2 *
a->qt - 1) / 2 * 3;
1110 uint8_t depth_left = 0, depth_top = 0;
1112 get_left_top(lc, &depth_left, &depth_top, x0, y0,
fc->tab.cqt_depth[ch_type],
fc->tab.cqt_depth[ch_type]);
1113 inc += depth_left > cqt_depth;
1114 inc += depth_top > cqt_depth;
1115 inc += (cqt_depth >= 2) * 3;
1121 const int cb_width,
const int cb_height,
const int ch_type,
const VVCAllowedSplit*
a)
1123 if ((
a->bth ||
a->tth) && (
a->btv ||
a->ttv)) {
1125 const int v =
a->btv +
a->ttv;
1126 const int h =
a->bth +
a->tth;
1134 const int min_cb_width =
fc->ps.pps->min_cb_width;
1137 const int x_cb = x0 >>
sps->min_cb_log2_size_y;
1138 const int y_cb = y0 >>
sps->min_cb_log2_size_y;
1141 const int da = cb_width / (available_a ?
SAMPLE_CTB(
fc->tab.cb_width[ch_type], x_cb, y_cb - 1) : 1);
1142 const int dl = cb_height / (available_l ?
SAMPLE_CTB(
fc->tab.cb_height[ch_type], x_cb - 1, y_cb) : 1);
1144 if (da == dl || !available_a || !available_l)
1153 return !(
a->bth ||
a->tth);
1158 const int inc = (2 * mtt_split_cu_vertical_flag) + ((mtt_depth <= 1) ? 1 : 0);
1163 const int cqt_depth,
const int mtt_depth,
const int ch_type,
const VVCAllowedSplit *
a)
1165 const int allow_no_qt =
a->btv ||
a->bth ||
a->ttv ||
a->tth;
1167 int mtt_split_cu_vertical_flag;
1168 int mtt_split_cu_binary_flag;
1172 if (allow_no_qt &&
a->qt) {
1175 split_qt_flag = !allow_no_qt ||
a->qt;
1180 if ((
a->btv &&
a->ttv && mtt_split_cu_vertical_flag) ||
1181 (
a->bth &&
a->tth && !mtt_split_cu_vertical_flag)) {
1184 if (!
a->btv && !
a->bth)
1185 mtt_split_cu_binary_flag = 0;
1186 else if (!
a->ttv && !
a->tth)
1187 mtt_split_cu_binary_flag = 1;
1188 else if (
a->bth &&
a->ttv)
1189 mtt_split_cu_binary_flag = 1 - mtt_split_cu_vertical_flag;
1191 mtt_split_cu_binary_flag = mtt_split_cu_vertical_flag;
1193 return mtt_split_modes[(mtt_split_cu_vertical_flag << 1) + mtt_split_cu_binary_flag];
1244 const int inc =
get_inc(lc, cu_skip_flag);
1255 get_left_top(lc, &left_mode, &top_mode, cu->
x0, cu->
y0,
fc->tab.cpm[is_chroma],
fc->tab.cpm[is_chroma]);
1264 const int inc = (
w >
h * 2 ||
h >
w * 2) ? 3 :
get_inc(lc, intra_mip_flag);
1277 const int c_max = (
w == 4 &&
h == 4) ? 15 :
1278 ((
w == 4 ||
h == 4) || (
w == 8 &&
h == 8)) ? 7: 5;
1285 for (
i = 0;
i < 2;
i++) {
1299 if (!intra_subpartitions_mode_flag)
1353 uint8_t left_merge = 0, top_merge = 0;
1354 uint8_t left_affine = 0, top_affine = 0;
1357 get_left_top(lc, &left_merge, &top_merge, x0, y0,
fc->tab.msf,
fc->tab.msf);
1358 get_left_top(lc, &left_affine, &top_affine, x0, y0,
fc->tab.iaf,
fc->tab.iaf);
1359 return (left_merge || left_affine) + (top_merge + top_affine);
1380 int inc = !cu_skip_flag;
1411 const int shift = ph_mmvd_fullpel_only_flag ? 4 : 2;
1414 const int mmvd_signs[][2] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };
1415 mmvd_offset->
x = mmvd_distance * mmvd_signs[mmvd_direction_idx][0];
1416 mmvd_offset->
y = mmvd_distance * mmvd_signs[mmvd_direction_idx][1];
1428 const int x_cb = cu->
x0 >>
fc->ps.sps->min_cb_log2_size_y;
1429 const int y_cb = cu->
y0 >>
fc->ps.sps->min_cb_log2_size_y;
1430 const int min_cb_width =
fc->ps.pps->min_cb_width;
1440 const int c_max = (is_ibc ?
sps->max_num_ibc_merge_cand :
sps->max_num_merge_cand) - 1;
1455 for (
int j = 0; j < 6; j++)
1488 const int inc = 7 - ((1 +
log2)>>1);
1513 const int c_max = nb_refs - 1;
1514 const int max_ctx =
FFMIN(c_max, 2);
1568 const PredMode pred_mode,
const int has_amvr_flag)
1571 if (has_amvr_flag) {
1574 if (inter_affine_flag) {
1576 amvr_shift = idx * 4;
1577 }
else if (pred_mode ==
MODE_IBC) {
1579 amvr_shift = 4 + idx * 2;
1581 static const int shifts[] = {3, 4, 6};
1583 amvr_shift =
shifts[idx];
1592 const int c_max = no_backward_pred_flag ? 4 : 2;
1673 const int log2_tb_size,
const int log2_zo_tb_size,
const int c_idx,
const int ctx)
1676 int max = (log2_zo_tb_size << 1) - 1;
1677 int ctx_offset, ctx_shift;
1681 const int offset_y[] = {0, 0, 3, 6, 10, 15};
1682 ctx_offset = offset_y[log2_tb_size - 1];
1683 ctx_shift = (log2_tb_size + 1) >> 2;
1685 const int shifts[] = {0, 0, 0, 1, 2, 2, 2};
1687 ctx_shift =
shifts[log2_tb_size];
1695 const int log2_tb_width,
const int log2_zo_tb_width,
const int c_idx)
1701 const int log2_tb_height,
const int log2_zo_tb_height,
const int c_idx)
1707 const int last_significant_coeff_y_prefix)
1709 const int length = (last_significant_coeff_y_prefix >> 1) - 1;
1712 for (
int i = 1;
i < length;
i++)
1729 const int xc,
const int yc,
const int hist_value)
1731 int loc_sum = 3 * hist_value;
1734 loc_sum +=
level[1];
1736 loc_sum +=
level[2] - hist_value;
1738 loc_sum +=
level[
w + 1] - hist_value;
1743 loc_sum +=
level[
w << 1] - hist_value;
1754 loc_sum +=
level[-1];
1765 const int incs[] = {0, 21, 21};
1766 inc = incs[
tb->c_idx];
1768 const int d = xc + yc;
1773 const int offset =
FFMIN(loc_sum_abs_pass1 - local_sum_sig, 4);
1776 inc = 1 +
offset + (!
d ? 15 : (
d < 3 ? 10 : (
d < 10 ? 5 : 0)));
1778 inc = 22 +
offset + (!
d ? 5 : 0);
1809 const int left =
xs > 0 ? sb_coded_flag[-1] : 0;
1810 const int above = ys > 0 ? sb_coded_flag[-
w] : 0;
1811 inc =
left + above + 4;
1813 const int right = (
xs <
w - 1) ? sb_coded_flag[1] : 0;
1814 const int bottom = (ys <
h - 1) ? sb_coded_flag[
w] : 0;
1815 inc = (right | bottom) + (
tb->c_idx ? 2 : 0);
1828 inc = 60 + local_num_sig;
1830 const int d = xc + yc;
1832 tb->tb_width,
tb->tb_height, xc, yc, 0);
1835 inc = 12 *
FFMAX(0, rc->
qstate - 1) +
FFMIN((loc_sum_abs_pass1 + 1) >> 1, 3) + ((
d < 2) ? 8 : (
d < 5 ? 4 : 0));
1837 inc = 36 + 8 *
FFMAX(0, rc->
qstate - 1) +
FFMIN((loc_sum_abs_pass1 + 1) >> 1, 3) + (
d < 2 ? 4 : 0);
1844 const int xc,
const int yc,
const int base_level)
1848 const int rice_params[] = {
1849 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2,
1850 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3,
1858 if (!
sps->r->sps_rrc_rice_extension_flag) {
1864 loc_sum_abs =
av_clip_uintp2((loc_sum_abs >> shift_val) - base_level * 5, 5);
1866 return rice_params[loc_sum_abs] + shift_val;
1872 const int MAX_BIN = 6;
1878 if (prefix < MAX_BIN) {
1879 for (
int i = 0;
i < c_rice_param;
i++) {
1885 26 -
sps->log2_transform_range,
1886 sps->log2_transform_range);
1888 return suffix + (prefix << c_rice_param);
1895 const int base_level[][2][2] = {
1900 base_level[
sps->r->sps_rrc_rice_extension_flag][
sps->bit_depth > 12][
IS_I(rsh)]);
1901 const int rem =
abs_decode(lc, c_rice_param);
1910 const int rem =
abs_decode(lc, c_rice_param);
1924 const int w =
tb->tb_width;
1926 const int left_sign = xc ?
level[-1] : 0;
1927 const int above_sign = yc ?
level[-
w] : 0;
1931 if (left_sign == -above_sign)
1932 inc = bdpcm_flag ? 3 : 0;
1933 else if (left_sign >= 0 && above_sign >= 0)
1934 inc = bdpcm_flag ? 4 : 1;
1936 inc = bdpcm_flag ? 5 : 2;
1949 const int l = xc > 0 ? sig_coeff_flag[-1] : 0;
1950 const int a = yc > 0 ? sig_coeff_flag[-
tb->tb_width] : 0;
1958 const int inc = 67 + j;
1963 { 0, 2 }, { 2, 0 }, { 1, 3 }, { 3, 1 }
1967 const int xc,
const int yc,
int *abs_level)
1970 const int dec_abs_level =
abs_decode(lc, c_rice_param);
1971 const int zero_pos = (rc->
qstate < 2 ? 1 : 2) << c_rice_param;
1974 if (dec_abs_level != zero_pos) {
1975 *abs_level = dec_abs_level;
1976 if (dec_abs_level < zero_pos)
1979 return dec_abs_level;
1983 const int remainder,
const int addin)
1987 *stat = (*stat +
av_log2(remainder) + addin) >> 1;
1993 const int log2_zo_tb_width,
const int log2_zo_tb_height,
1997 int log2_sb_w = (
FFMIN(log2_zo_tb_width, log2_zo_tb_height ) < 2 ? 1 : 2 );
1998 int log2_sb_h = log2_sb_w;
2000 if ( log2_zo_tb_width + log2_zo_tb_height > 3 ) {
2001 if ( log2_zo_tb_width < 2 ) {
2002 log2_sb_w = log2_zo_tb_width;
2003 log2_sb_h = 4 - log2_sb_w;
2004 }
else if ( log2_zo_tb_height < 2 ) {
2005 log2_sb_h = log2_zo_tb_height;
2006 log2_sb_w = 4 - log2_sb_h;
2012 rc->
last_sub_block = ( 1 << ( log2_zo_tb_width + log2_zo_tb_height - (log2_sb_w + log2_sb_h))) - 1;
2014 rc->
update_hist =
sps->r->sps_persistent_rice_adaptation_enabled_flag ? 1 : 0;
2015 rc->
rem_bins_pass1 = (( 1 << ( log2_zo_tb_width + log2_zo_tb_height)) * 7 ) >> 2;
2026 rc->
width_in_sbs = (1 << (log2_zo_tb_width - log2_sb_w));
2044 int infer_sb_sig_coeff_flag = 1;
2045 int last_scan_pos_pass1 = -1, last_scan_pos_pass2 = -1, n;
2053 if (*sb_coded_flag && i < rc->last_sub_block)
2060 const int off = yc *
tb->tb_width + xc;
2064 int par_level_flag = 0;
2066 abs_level_gtx_flag[n] = 0;
2067 last_scan_pos_pass1 = n;
2068 if (*sb_coded_flag && (n != rc->
num_sb_coeff - 1 || !infer_sb_sig_coeff_flag)) {
2071 if (*sig_coeff_flag)
2072 infer_sb_sig_coeff_flag = 0;
2074 *sig_coeff_flag = (n == rc->
num_sb_coeff - 1) && infer_sb_sig_coeff_flag && *sb_coded_flag;
2076 *coeff_sign_level = 0;
2077 if (*sig_coeff_flag) {
2081 if (abs_level_gtx_flag[n]) {
2086 *abs_level_pass1 = *sig_coeff_flag + par_level_flag + abs_level_gtx_flag[n];
2093 const int off = yc *
tb->tb_width + xc;
2096 for (
int j = 1; j < 5 && abs_level_gtx_flag[n]; j++) {
2098 abs_level_pass2[n] += abs_level_gtx_flag[n] << 1;
2101 last_scan_pos_pass2 = n;
2108 const int off = yc *
tb->tb_width + xc;
2112 int abs_remainder = 0;
2114 if ((n <= last_scan_pos_pass2 && abs_level_pass2[n] >= 10) ||
2115 (n > last_scan_pos_pass2 && n <= last_scan_pos_pass1 &&
2116 *abs_level_pass1 >= 2) ||
2117 (n > last_scan_pos_pass1 && *sb_coded_flag))
2119 if (n <= last_scan_pos_pass2) {
2120 *abs_level = abs_level_pass2[n] + 2 * abs_remainder;
2121 }
else if (n <= last_scan_pos_pass1) {
2122 *abs_level = *abs_level_pass1 + 2 * abs_remainder;
2124 *abs_level = abs_remainder;
2125 if (abs_remainder) {
2130 if (!bdpcm_flag && n <= last_scan_pos_pass1) {
2131 const int left = xc > 0 ? abs_level[-1] : 0;
2132 const int above = yc > 0 ? abs_level[-
tb->tb_width] : 0;
2135 if (*abs_level == 1 &&
pred > 0)
2137 else if (*abs_level > 0 && *abs_level <=
pred)
2141 tb->coeffs[off] = *coeff_sign_level * *abs_level;
2142 tb->max_scan_x =
FFMAX(xc,
tb->max_scan_x);
2143 tb->max_scan_y =
FFMAX(yc,
tb->max_scan_y);
2144 tb->min_scan_x =
FFMIN(xc,
tb->min_scan_x);
2145 tb->min_scan_y =
FFMIN(yc,
tb->min_scan_y);
2147 tb->coeffs[off] = 0;
2157 tb->min_scan_x =
tb->min_scan_y = INT_MAX;
2172 int first_sig_scan_pos_sb, last_sig_scan_pos_sb;
2173 int first_pos_mode0, first_pos_mode1;
2174 int infer_sb_dc_sig_coeff_flag = 0;
2175 int n, sig_hidden_flag, sum = 0;
2177 const int start_qstate_sb = rc->
qstate;
2184 if (i < rc->last_sub_block &&
i > 0) {
2186 infer_sb_dc_sig_coeff_flag = 1;
2190 if (*sb_coded_flag && (
xs > 3 || ys > 3) && !
tb->c_idx)
2193 if (!*sb_coded_flag)
2197 last_sig_scan_pos_sb = -1;
2199 first_pos_mode1 = first_pos_mode0;
2200 for (n = first_pos_mode0; n >= 0 && rc->
rem_bins_pass1 >= 4; n--) {
2207 if ((n > 0 || !infer_sb_dc_sig_coeff_flag ) && !last) {
2210 if (*sig_coeff_flag)
2211 infer_sb_dc_sig_coeff_flag = 0;
2214 infer_sb_dc_sig_coeff_flag);
2216 *abs_level_pass1 = 0;
2217 if (*sig_coeff_flag) {
2218 int abs_level_gt1_flag, par_level_flag = 0;
2222 if (abs_level_gt1_flag) {
2227 abs_level_gt2_flag[n] = 0;
2229 if (last_sig_scan_pos_sb == -1)
2230 last_sig_scan_pos_sb = n;
2231 first_sig_scan_pos_sb = n;
2234 1 + par_level_flag + abs_level_gt1_flag + (abs_level_gt2_flag[n] << 1);
2236 abs_level_gt2_flag[n] = 0;
2242 first_pos_mode1 = n - 1;
2244 for (n = first_pos_mode0; n > first_pos_mode1; n--) {
2248 int *abs_level = rc->
abs_level + yc *
tb->tb_width + xc;
2250 *abs_level = *abs_level_pass1;
2251 if (abs_level_gt2_flag[n]) {
2254 *abs_level += 2 * abs_remainder;
2257 for (n = first_pos_mode1; n >= 0; n--) {
2260 int *abs_level = rc->
abs_level + yc *
tb->tb_width + xc;
2262 if (*sb_coded_flag) {
2266 if (*abs_level > 0) {
2267 if (last_sig_scan_pos_sb == -1)
2268 last_sig_scan_pos_sb = n;
2269 first_sig_scan_pos_sb = n;
2275 (last_sig_scan_pos_sb - first_sig_scan_pos_sb > 3 ? 1 : 0);
2278 rc->
qstate = start_qstate_sb;
2280 for (; n >= 0; n--) {
2281 int trans_coeff_level;
2284 const int off = yc *
tb->tb_width + xc;
2285 const int *abs_level = rc->
abs_level + off;
2287 if (*abs_level > 0) {
2289 if (!sig_hidden_flag || (n != first_sig_scan_pos_sb))
2292 trans_coeff_level = (2 * *abs_level - (rc->
qstate > 1)) * sign;
2294 trans_coeff_level = *abs_level * sign;
2295 if (sig_hidden_flag) {
2297 if (n == first_sig_scan_pos_sb && (sum % 2))
2298 trans_coeff_level = -trans_coeff_level;
2301 tb->coeffs[off] = trans_coeff_level;
2302 tb->max_scan_x =
FFMAX(xc,
tb->max_scan_x);
2303 tb->max_scan_y =
FFMAX(yc,
tb->max_scan_y);
2329 const int log2_zo_tb_width,
const int log2_zo_tb_height)
2333 int last_significant_coeff_x, last_significant_coeff_y;
2336 tb->log2_tb_width, log2_zo_tb_width,
tb->c_idx);
2339 tb->log2_tb_height, log2_zo_tb_height,
tb->c_idx);
2341 if (last_significant_coeff_x > 3) {
2343 last_significant_coeff_x = (1 << ((last_significant_coeff_x >> 1) - 1)) *
2344 (2 + (last_significant_coeff_x & 1)) +
suffix;
2346 if (last_significant_coeff_y > 3) {
2348 last_significant_coeff_y = (1 << ((last_significant_coeff_y >> 1) - 1)) *
2349 (2 + (last_significant_coeff_y & 1)) +
suffix;
2352 last_significant_coeff_x = (1 << log2_zo_tb_width) - 1 - last_significant_coeff_x;
2353 last_significant_coeff_y = (1 << log2_zo_tb_height) - 1 - last_significant_coeff_y;
2363 const int log2_tb_width =
tb->log2_tb_width;
2364 const int log2_tb_height =
tb->log2_tb_height;
2365 const int c_idx =
tb->c_idx;
2366 int log2_zo_tb_width, log2_zo_tb_height;
2369 if (
sps->r->sps_mts_enabled_flag && cu->
sbt_flag && !c_idx && log2_tb_width == 5 && log2_tb_height < 6)
2370 log2_zo_tb_width = 4;
2372 log2_zo_tb_width =
FFMIN(log2_tb_width, 5 );
2374 if (
sps->r->sps_mts_enabled_flag && cu->
sbt_flag && !c_idx && log2_tb_width < 6 && log2_tb_height == 5 )
2375 log2_zo_tb_height = 4;
2377 log2_zo_tb_height =
FFMIN(log2_tb_height, 5);
2385 if ((rc.
last_sub_block > 0 && log2_tb_width >= 2 && log2_tb_height >= 2 ) ||
2386 (rc.
last_scan_pos > 7 && (log2_tb_width == 2 || log2_tb_width == 3 ) &&
2387 log2_tb_width == log2_tb_height))
2392 memset(
tb->coeffs, 0,
tb->tb_width *
tb->tb_height *
sizeof(*
tb->coeffs));
2424 const int inc =
w *
h <= 256;
2437 const int inc = (
w ==
h) ? 0 : ((
w <
h) ? 1 : 2);
2458 for (
i = 0;
i < 4;
i++) {