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;
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];
1255 get_left_top(lc, &left_mode, &top_mode, cu->
x0, cu->
y0,
fc->tab.cpm[is_chroma],
fc->tab.cpm[is_chroma]);
1263 uint8_t
left = 0, top = 0;
1265 return (
left & 1) + (top & 1);
1285 const int c_max = (
w == 4 &&
h == 4) ? 15 :
1286 ((
w == 4 ||
h == 4) || (
w == 8 &&
h == 8)) ? 7: 5;
1293 for (
i = 0;
i < 2;
i++) {
1307 if (!intra_subpartitions_mode_flag)
1361 uint8_t left_merge = 0, top_merge = 0;
1362 uint8_t left_affine = 0, top_affine = 0;
1365 get_left_top(lc, &left_merge, &top_merge, x0, y0,
fc->tab.msf,
fc->tab.msf);
1366 get_left_top(lc, &left_affine, &top_affine, x0, y0,
fc->tab.iaf,
fc->tab.iaf);
1367 return (left_merge || left_affine) + (top_merge + top_affine);
1388 int inc = !cu_skip_flag;
1419 const int shift = ph_mmvd_fullpel_only_flag ? 4 : 2;
1422 const int mmvd_signs[][2] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };
1423 mmvd_offset->
x = mmvd_distance * mmvd_signs[mmvd_direction_idx][0];
1424 mmvd_offset->
y = mmvd_distance * mmvd_signs[mmvd_direction_idx][1];
1436 const int x_cb = cu->
x0 >>
fc->ps.sps->min_cb_log2_size_y;
1437 const int y_cb = cu->
y0 >>
fc->ps.sps->min_cb_log2_size_y;
1438 const int min_cb_width =
fc->ps.pps->min_cb_width;
1448 const int c_max = (is_ibc ?
sps->max_num_ibc_merge_cand :
sps->max_num_merge_cand) - 1;
1463 for (
int j = 0; j < 6; j++)
1496 const int inc = 7 - ((1 +
log2)>>1);
1521 const int c_max = nb_refs - 1;
1522 const int max_ctx =
FFMIN(c_max, 2);
1576 const PredMode pred_mode,
const int has_amvr_flag)
1579 if (has_amvr_flag) {
1582 if (inter_affine_flag) {
1584 amvr_shift = idx * 4;
1585 }
else if (pred_mode ==
MODE_IBC) {
1587 amvr_shift = 4 + idx * 2;
1589 static const int shifts[] = {3, 4, 6};
1591 amvr_shift =
shifts[idx];
1600 const int c_max = no_backward_pred_flag ? 4 : 2;
1681 const int log2_tb_size,
const int log2_zo_tb_size,
const int c_idx,
const int ctx)
1684 int max = (log2_zo_tb_size << 1) - 1;
1685 int ctx_offset, ctx_shift;
1689 const int offset_y[] = {0, 0, 3, 6, 10, 15};
1690 ctx_offset = offset_y[log2_tb_size - 1];
1691 ctx_shift = (log2_tb_size + 1) >> 2;
1693 const int shifts[] = {0, 0, 0, 1, 2, 2, 2};
1695 ctx_shift =
shifts[log2_tb_size];
1703 const int log2_tb_width,
const int log2_zo_tb_width,
const int c_idx)
1709 const int log2_tb_height,
const int log2_zo_tb_height,
const int c_idx)
1715 const int last_significant_coeff_y_prefix)
1717 const int length = (last_significant_coeff_y_prefix >> 1) - 1;
1720 for (
int i = 1;
i < length;
i++)
1737 const int xc,
const int yc,
const int hist_value)
1739 int loc_sum = 3 * hist_value;
1742 loc_sum +=
level[1];
1744 loc_sum +=
level[2] - hist_value;
1746 loc_sum +=
level[
w + 1] - hist_value;
1751 loc_sum +=
level[
w << 1] - hist_value;
1762 loc_sum +=
level[-1];
1773 const int incs[] = {0, 21, 21};
1776 const int d = xc + yc;
1781 const int offset =
FFMIN(loc_sum_abs_pass1 - local_sum_sig, 4);
1784 inc = 1 +
offset + (!d ? 15 : (d < 3 ? 10 : (d < 10 ? 5 : 0)));
1817 const int left =
xs > 0 ? sb_coded_flag[-1] : 0;
1818 const int above = ys > 0 ? sb_coded_flag[-
w] : 0;
1821 const int right = (
xs <
w - 1) ? sb_coded_flag[1] : 0;
1822 const int bottom = (ys <
h - 1) ? sb_coded_flag[
w] : 0;
1823 inc = (right | bottom) + (tb->
c_idx ? 2 : 0);
1836 inc = 60 + local_num_sig;
1838 const int d = xc + yc;
1843 inc = 12 *
FFMAX(0, rc->
qstate - 1) +
FFMIN((loc_sum_abs_pass1 + 1) >> 1, 3) + ((d < 2) ? 8 : (d < 5 ? 4 : 0));
1845 inc = 36 + 8 *
FFMAX(0, rc->
qstate - 1) +
FFMIN((loc_sum_abs_pass1 + 1) >> 1, 3) + (d < 2 ? 4 : 0);
1852 const int xc,
const int yc,
const int base_level)
1856 const int rice_params[] = {
1857 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2,
1858 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3,
1866 if (!
sps->r->sps_rrc_rice_extension_flag) {
1872 loc_sum_abs =
av_clip_uintp2((loc_sum_abs >> shift_val) - base_level * 5, 5);
1874 return rice_params[loc_sum_abs] + shift_val;
1880 const int MAX_BIN = 6;
1886 if (prefix < MAX_BIN) {
1887 for (
int i = 0;
i < c_rice_param;
i++) {
1893 26 -
sps->log2_transform_range,
1894 sps->log2_transform_range);
1896 return suffix + (prefix << c_rice_param);
1903 const int base_level[][2][2] = {
1908 base_level[
sps->r->sps_rrc_rice_extension_flag][
sps->bit_depth > 12][
IS_I(rsh)]);
1909 const int rem =
abs_decode(lc, c_rice_param);
1918 const int rem =
abs_decode(lc, c_rice_param);
1934 const int left_sign = xc ?
level[-1] : 0;
1935 const int above_sign = yc ?
level[-
w] : 0;
1939 if (left_sign == -above_sign)
1940 inc = bdpcm_flag ? 3 : 0;
1941 else if (left_sign >= 0 && above_sign >= 0)
1942 inc = bdpcm_flag ? 4 : 1;
1944 inc = bdpcm_flag ? 5 : 2;
1957 const int l = xc > 0 ? sig_coeff_flag[-1] : 0;
1958 const int a = yc > 0 ? sig_coeff_flag[-tb->
tb_width] : 0;
1966 const int inc = 67 + j;
1971 { 0, 2 }, { 2, 0 }, { 1, 3 }, { 3, 1 }
1975 const int xc,
const int yc,
int *abs_level)
1978 const int dec_abs_level =
abs_decode(lc, c_rice_param);
1979 const int zero_pos = (rc->
qstate < 2 ? 1 : 2) << c_rice_param;
1982 if (dec_abs_level != zero_pos) {
1983 *abs_level = dec_abs_level;
1984 if (dec_abs_level < zero_pos)
1987 return dec_abs_level;
1991 const int remainder,
const int addin)
1995 *stat = (*stat +
av_log2(remainder) + addin) >> 1;
2001 const int log2_zo_tb_width,
const int log2_zo_tb_height,
2005 int log2_sb_w = (
FFMIN(log2_zo_tb_width, log2_zo_tb_height ) < 2 ? 1 : 2 );
2006 int log2_sb_h = log2_sb_w;
2008 if ( log2_zo_tb_width + log2_zo_tb_height > 3 ) {
2009 if ( log2_zo_tb_width < 2 ) {
2010 log2_sb_w = log2_zo_tb_width;
2011 log2_sb_h = 4 - log2_sb_w;
2012 }
else if ( log2_zo_tb_height < 2 ) {
2013 log2_sb_h = log2_zo_tb_height;
2014 log2_sb_w = 4 - log2_sb_h;
2020 rc->
last_sub_block = ( 1 << ( log2_zo_tb_width + log2_zo_tb_height - (log2_sb_w + log2_sb_h))) - 1;
2022 rc->
update_hist =
sps->r->sps_persistent_rice_adaptation_enabled_flag ? 1 : 0;
2023 rc->
rem_bins_pass1 = (( 1 << ( log2_zo_tb_width + log2_zo_tb_height)) * 7 ) >> 2;
2034 rc->
width_in_sbs = (1 << (log2_zo_tb_width - log2_sb_w));
2052 int infer_sb_sig_coeff_flag = 1;
2053 int last_scan_pos_pass1 = -1, last_scan_pos_pass2 = -1, n;
2061 if (*sb_coded_flag && i < rc->last_sub_block)
2068 const int off = yc * tb->
tb_width + xc;
2072 int par_level_flag = 0;
2074 abs_level_gtx_flag[n] = 0;
2075 last_scan_pos_pass1 = n;
2076 if (*sb_coded_flag && (n != rc->
num_sb_coeff - 1 || !infer_sb_sig_coeff_flag)) {
2079 if (*sig_coeff_flag)
2080 infer_sb_sig_coeff_flag = 0;
2082 *sig_coeff_flag = (n == rc->
num_sb_coeff - 1) && infer_sb_sig_coeff_flag && *sb_coded_flag;
2084 *coeff_sign_level = 0;
2085 if (*sig_coeff_flag) {
2089 if (abs_level_gtx_flag[n]) {
2094 *abs_level_pass1 = *sig_coeff_flag + par_level_flag + abs_level_gtx_flag[n];
2101 const int off = yc * tb->
tb_width + xc;
2104 for (
int j = 1; j < 5 && abs_level_gtx_flag[n]; j++) {
2106 abs_level_pass2[n] += abs_level_gtx_flag[n] << 1;
2109 last_scan_pos_pass2 = n;
2116 const int off = yc * tb->
tb_width + xc;
2120 int abs_remainder = 0;
2122 if ((n <= last_scan_pos_pass2 && abs_level_pass2[n] >= 10) ||
2123 (n > last_scan_pos_pass2 && n <= last_scan_pos_pass1 &&
2124 *abs_level_pass1 >= 2) ||
2125 (n > last_scan_pos_pass1 && *sb_coded_flag))
2127 if (n <= last_scan_pos_pass2) {
2128 *abs_level = abs_level_pass2[n] + 2 * abs_remainder;
2129 }
else if (n <= last_scan_pos_pass1) {
2130 *abs_level = *abs_level_pass1 + 2 * abs_remainder;
2132 *abs_level = abs_remainder;
2133 if (abs_remainder) {
2138 if (!bdpcm_flag && n <= last_scan_pos_pass1) {
2139 const int left = xc > 0 ? abs_level[-1] : 0;
2140 const int above = yc > 0 ? abs_level[-tb->
tb_width] : 0;
2143 if (*abs_level == 1 &&
pred > 0)
2145 else if (*abs_level > 0 && *abs_level <=
pred)
2149 tb->
coeffs[off] = *coeff_sign_level * *abs_level;
2180 int first_sig_scan_pos_sb, last_sig_scan_pos_sb;
2181 int first_pos_mode0, first_pos_mode1;
2182 int infer_sb_dc_sig_coeff_flag = 0;
2183 int n, sig_hidden_flag, sum = 0;
2185 const int start_qstate_sb = rc->
qstate;
2192 if (i < rc->last_sub_block &&
i > 0) {
2194 infer_sb_dc_sig_coeff_flag = 1;
2198 if (*sb_coded_flag && (
xs > 3 || ys > 3) && !tb->
c_idx)
2201 if (!*sb_coded_flag)
2205 last_sig_scan_pos_sb = -1;
2207 first_pos_mode1 = first_pos_mode0;
2208 for (n = first_pos_mode0; n >= 0 && rc->
rem_bins_pass1 >= 4; n--) {
2215 if ((n > 0 || !infer_sb_dc_sig_coeff_flag ) && !last) {
2218 if (*sig_coeff_flag)
2219 infer_sb_dc_sig_coeff_flag = 0;
2222 infer_sb_dc_sig_coeff_flag);
2224 *abs_level_pass1 = 0;
2225 if (*sig_coeff_flag) {
2226 int abs_level_gt1_flag, par_level_flag = 0;
2230 if (abs_level_gt1_flag) {
2235 abs_level_gt2_flag[n] = 0;
2237 if (last_sig_scan_pos_sb == -1)
2238 last_sig_scan_pos_sb = n;
2239 first_sig_scan_pos_sb = n;
2242 1 + par_level_flag + abs_level_gt1_flag + (abs_level_gt2_flag[n] << 1);
2244 abs_level_gt2_flag[n] = 0;
2250 first_pos_mode1 = n - 1;
2252 for (n = first_pos_mode0; n > first_pos_mode1; n--) {
2258 *abs_level = *abs_level_pass1;
2259 if (abs_level_gt2_flag[n]) {
2262 *abs_level += 2 * abs_remainder;
2265 for (n = first_pos_mode1; n >= 0; n--) {
2270 if (*sb_coded_flag) {
2274 if (*abs_level > 0) {
2275 if (last_sig_scan_pos_sb == -1)
2276 last_sig_scan_pos_sb = n;
2277 first_sig_scan_pos_sb = n;
2283 (last_sig_scan_pos_sb - first_sig_scan_pos_sb > 3 ? 1 : 0);
2286 rc->
qstate = start_qstate_sb;
2288 for (; n >= 0; n--) {
2289 int trans_coeff_level;
2292 const int off = yc * tb->
tb_width + xc;
2293 const int *abs_level = rc->
abs_level + off;
2295 if (*abs_level > 0) {
2297 if (!sig_hidden_flag || (n != first_sig_scan_pos_sb))
2300 trans_coeff_level = (2 * *abs_level - (rc->
qstate > 1)) * sign;
2302 trans_coeff_level = *abs_level * sign;
2303 if (sig_hidden_flag) {
2305 if (n == first_sig_scan_pos_sb && (sum % 2))
2306 trans_coeff_level = -trans_coeff_level;
2309 tb->
coeffs[off] = trans_coeff_level;
2337 const int log2_zo_tb_width,
const int log2_zo_tb_height)
2341 int last_significant_coeff_x, last_significant_coeff_y;
2349 if (last_significant_coeff_x > 3) {
2351 last_significant_coeff_x = (1 << ((last_significant_coeff_x >> 1) - 1)) *
2352 (2 + (last_significant_coeff_x & 1)) +
suffix;
2354 if (last_significant_coeff_y > 3) {
2356 last_significant_coeff_y = (1 << ((last_significant_coeff_y >> 1) - 1)) *
2357 (2 + (last_significant_coeff_y & 1)) +
suffix;
2360 last_significant_coeff_x = (1 << log2_zo_tb_width) - 1 - last_significant_coeff_x;
2361 last_significant_coeff_y = (1 << log2_zo_tb_height) - 1 - last_significant_coeff_y;
2373 const int c_idx = tb->
c_idx;
2374 int log2_zo_tb_width, log2_zo_tb_height;
2377 if (
sps->r->sps_mts_enabled_flag && cu->
sbt_flag && !c_idx && log2_tb_width == 5 && log2_tb_height < 6)
2378 log2_zo_tb_width = 4;
2380 log2_zo_tb_width =
FFMIN(log2_tb_width, 5 );
2382 if (
sps->r->sps_mts_enabled_flag && cu->
sbt_flag && !c_idx && log2_tb_width < 6 && log2_tb_height == 5 )
2383 log2_zo_tb_height = 4;
2385 log2_zo_tb_height =
FFMIN(log2_tb_height, 5);
2393 if ((rc.
last_sub_block > 0 && log2_tb_width >= 2 && log2_tb_height >= 2 ) ||
2394 (rc.
last_scan_pos > 7 && (log2_tb_width == 2 || log2_tb_width == 3 ) &&
2395 log2_tb_width == log2_tb_height))
2432 const int inc =
w *
h <= 256;
2445 const int inc = (
w ==
h) ? 0 : ((
w <
h) ? 1 : 2);
2466 for (
i = 0;
i < 4;
i++) {