32 #define CABAC_MAX_BIN 31
35 #define CABAC_ELEMS(ELEM) \
36 ELEM(SAO_MERGE_FLAG, 1) \
37 ELEM(SAO_TYPE_IDX, 1) \
38 ELEM(SAO_EO_CLASS, 0) \
39 ELEM(SAO_BAND_POSITION, 0) \
40 ELEM(SAO_OFFSET_ABS, 0) \
41 ELEM(SAO_OFFSET_SIGN, 0) \
42 ELEM(END_OF_SLICE_FLAG, 0) \
43 ELEM(SPLIT_CODING_UNIT_FLAG, 3) \
44 ELEM(CU_TRANSQUANT_BYPASS_FLAG, 1) \
46 ELEM(CU_QP_DELTA, 3) \
47 ELEM(PRED_MODE_FLAG, 1) \
50 ELEM(PREV_INTRA_LUMA_PRED_FLAG, 1) \
52 ELEM(REM_INTRA_LUMA_PRED_MODE, 0) \
53 ELEM(INTRA_CHROMA_PRED_MODE, 2) \
56 ELEM(INTER_PRED_IDC, 5) \
59 ELEM(ABS_MVD_GREATER0_FLAG, 2) \
60 ELEM(ABS_MVD_GREATER1_FLAG, 2) \
61 ELEM(ABS_MVD_MINUS2, 0) \
62 ELEM(MVD_SIGN_FLAG, 0) \
63 ELEM(MVP_LX_FLAG, 1) \
64 ELEM(NO_RESIDUAL_DATA_FLAG, 1) \
65 ELEM(SPLIT_TRANSFORM_FLAG, 3) \
68 ELEM(TRANSFORM_SKIP_FLAG, 2) \
69 ELEM(EXPLICIT_RDPCM_FLAG, 2) \
70 ELEM(EXPLICIT_RDPCM_DIR_FLAG, 2) \
71 ELEM(LAST_SIGNIFICANT_COEFF_X_PREFIX, 18) \
72 ELEM(LAST_SIGNIFICANT_COEFF_Y_PREFIX, 18) \
73 ELEM(LAST_SIGNIFICANT_COEFF_X_SUFFIX, 0) \
74 ELEM(LAST_SIGNIFICANT_COEFF_Y_SUFFIX, 0) \
75 ELEM(SIGNIFICANT_COEFF_GROUP_FLAG, 4) \
76 ELEM(SIGNIFICANT_COEFF_FLAG, 44) \
77 ELEM(COEFF_ABS_LEVEL_GREATER1_FLAG, 24) \
78 ELEM(COEFF_ABS_LEVEL_GREATER2_FLAG, 6) \
79 ELEM(COEFF_ABS_LEVEL_REMAINING, 0) \
80 ELEM(COEFF_SIGN_FLAG, 0) \
81 ELEM(LOG2_RES_SCALE_ABS, 8) \
82 ELEM(RES_SCALE_SIGN_FLAG, 2) \
83 ELEM(CU_CHROMA_QP_OFFSET_FLAG, 1) \
84 ELEM(CU_CHROMA_QP_OFFSET_IDX, 1) \
90 #define OFFSET(NAME, NUM_BINS) \
92 NAME ## _END = NAME ## _OFFSET + NUM_BINS - 1,
144 94, 138, 182, 154, 154,
152 110, 110, 124, 125, 140, 153, 125, 127, 140, 109, 111, 143, 127, 111,
155 110, 110, 124, 125, 140, 153, 125, 127, 140, 109, 111, 143, 127, 111,
160 111, 111, 125, 110, 110, 94, 124, 108, 124, 107, 125, 141, 179, 153,
161 125, 107, 125, 141, 179, 153, 125, 107, 125, 141, 179, 153, 125, 140,
162 139, 182, 182, 152, 136, 152, 136, 153, 136, 139, 111, 136, 139, 111,
165 140, 92, 137, 138, 140, 152, 138, 139, 153, 74, 149, 92, 139, 107,
166 122, 152, 140, 179, 166, 182, 140, 227, 122, 197,
168 138, 153, 136, 167, 152, 152,
170 154, 154, 154, 154, 154, 154, 154, 154,
221 149, 107, 167, 154, 154,
229 125, 110, 94, 110, 95, 79, 125, 111, 110, 78, 110, 111, 111, 95,
232 125, 110, 94, 110, 95, 79, 125, 111, 110, 78, 110, 111, 111, 95,
237 155, 154, 139, 153, 139, 123, 123, 63, 153, 166, 183, 140, 136, 153,
238 154, 166, 183, 140, 136, 153, 154, 166, 183, 140, 136, 153, 154, 170,
239 153, 123, 123, 107, 121, 107, 121, 167, 151, 183, 140, 151, 183, 140,
242 154, 196, 196, 167, 154, 152, 167, 182, 182, 134, 149, 136, 153, 121,
243 136, 137, 169, 194, 166, 167, 154, 167, 137, 182,
245 107, 167, 91, 122, 107, 167,
247 154, 154, 154, 154, 154, 154, 154, 154,
298 149, 92, 167, 154, 154,
306 125, 110, 124, 110, 95, 94, 125, 111, 111, 79, 125, 126, 111, 111,
309 125, 110, 124, 110, 95, 94, 125, 111, 111, 79, 125, 126, 111, 111,
314 170, 154, 139, 153, 139, 123, 123, 63, 124, 166, 183, 140, 136, 153,
315 154, 166, 183, 140, 136, 153, 154, 166, 183, 140, 136, 153, 154, 170,
316 153, 138, 138, 122, 121, 122, 121, 167, 151, 183, 140, 151, 183, 140,
319 154, 196, 167, 167, 154, 152, 167, 182, 182, 134, 149, 136, 153, 121,
320 136, 122, 169, 208, 166, 167, 154, 152, 167, 182,
322 107, 167, 91, 107, 107, 167,
324 154, 154, 154, 154, 154, 154, 154, 154,
361 { 0, 1, 2, 3, 16, 17, 18, 19, },
362 { 4, 5, 6, 7, 20, 21, 22, 23, },
363 { 8, 9, 10, 11, 24, 25, 26, 27, },
364 { 12, 13, 14, 15, 28, 29, 30, 31, },
365 { 32, 33, 34, 35, 48, 49, 50, 51, },
366 { 36, 37, 38, 39, 52, 53, 54, 55, },
367 { 40, 41, 42, 43, 56, 57, 58, 59, },
368 { 44, 45, 46, 47, 60, 61, 62, 63, },
392 { 0, 2, 5, 9, 14, 20, 27, 35, },
393 { 1, 4, 8, 13, 19, 26, 34, 42, },
394 { 3, 7, 12, 18, 25, 33, 41, 48, },
395 { 6, 11, 17, 24, 32, 40, 47, 53, },
396 { 10, 16, 23, 31, 39, 46, 52, 57, },
397 { 15, 22, 30, 38, 45, 51, 56, 60, },
398 { 21, 29, 37, 44, 50, 55, 59, 62, },
399 { 28, 36, 43, 49, 54, 58, 61, 63, },
406 if (
pps->entropy_coding_sync_enabled_flag &&
407 (ctb_addr_ts %
sps->ctb_width == 2 ||
408 (
sps->ctb_width == 2 &&
409 ctb_addr_ts %
sps->ctb_width == 0))) {
411 if (
sps->persistent_rice_adaptation_enabled) {
420 if (
sps->persistent_rice_adaptation_enabled) {
432 int init_type = 2 -
s->sh.slice_type;
440 int m = (init_value >> 4) * 5 - 45;
441 int n = ((init_value & 15) << 3) - 16;
442 int pre = 2 * (((m *
av_clip(
s->sh.slice_qp, 0, 51)) >> 4) + n) - 127;
446 pre = 124 + (pre & 1);
450 for (
i = 0;
i < 4;
i++)
455 int ctb_addr_ts,
const uint8_t *
data,
size_t size,
461 if (ctb_addr_ts ==
pps->ctb_addr_rs_to_ts[
s->sh.slice_ctb_addr_rs]) {
465 if (
s->sh.dependent_slice_segment_flag == 0 ||
466 (
pps->tiles_enabled_flag &&
467 pps->tile_id[ctb_addr_ts] !=
pps->tile_id[ctb_addr_ts - 1]))
470 if (!
s->sh.first_slice_in_pic_flag &&
471 pps->entropy_coding_sync_enabled_flag) {
472 if (ctb_addr_ts %
sps->ctb_width == 0) {
473 if (
sps->ctb_width == 1)
475 else if (
s->sh.dependent_slice_segment_flag == 1)
480 if (
pps->tiles_enabled_flag &&
481 pps->tile_id[ctb_addr_ts] !=
pps->tile_id[ctb_addr_ts - 1]) {
492 if (
pps->entropy_coding_sync_enabled_flag) {
493 if (ctb_addr_ts %
sps->ctb_width == 0) {
504 if (
sps->ctb_width == 1)
514 #define GET_CABAC(ctx) get_cabac(&lc->cc, &lc->cabac_state[ctx])
536 for (
i = 0;
i < 4;
i++)
570 return GET_CABAC(CU_TRANSQUANT_BYPASS_FLAG_OFFSET);
574 int x0,
int y0,
int x_cb,
int y_cb,
int min_cb_width)
592 while (prefix_val < 5 &&
GET_CABAC(CU_QP_DELTA_OFFSET +
inc)) {
596 if (prefix_val >= 5) {
599 suffix_val += 1 << k;
610 return prefix_val + suffix_val;
620 return GET_CABAC(CU_CHROMA_QP_OFFSET_FLAG_OFFSET);
625 int c_max=
FFMAX(5, chroma_qp_offset_list_len_minus1);
628 while (
i < c_max &&
GET_CABAC(CU_CHROMA_QP_OFFSET_IDX_OFFSET))
641 int ct_depth,
int x0,
int y0)
643 int inc = 0, depth_left = 0, depth_top = 0;
646 int x_cb = x0 >>
sps->log2_min_cb_size;
647 int y_cb = y0 >>
sps->log2_min_cb_size;
650 depth_left = tab_ct_depth[(y_cb) *
sps->min_cb_width + x_cb - 1];
652 depth_top = tab_ct_depth[(y_cb - 1) *
sps->min_cb_width + x_cb];
654 inc += (depth_left > ct_depth);
655 inc += (depth_top > ct_depth);
664 if (log2_cb_size ==
sps->log2_min_cb_size) {
669 if (log2_cb_size == 3)
676 if (!
sps->amp_enabled) {
704 return GET_CABAC(PREV_INTRA_LUMA_PRED_FLAG_OFFSET);
720 for (
i = 0;
i < 4;
i++)
728 if (!
GET_CABAC(INTRA_CHROMA_PRED_MODE_OFFSET))
754 if (nPbW + nPbH == 12)
755 return GET_CABAC(INTER_PRED_IDC_OFFSET + 4);
759 return GET_CABAC(INTER_PRED_IDC_OFFSET + 4);
765 int max = num_ref_idx_lx - 1;
768 while (
i < max_ctx &&
GET_CABAC(REF_IDX_L0_OFFSET +
i))
785 return GET_CABAC(NO_RESIDUAL_DATA_FLAG_OFFSET);
790 return GET_CABAC(ABS_MVD_GREATER0_FLAG_OFFSET);
795 return GET_CABAC(ABS_MVD_GREATER1_FLAG_OFFSET + 1);
823 return GET_CABAC(SPLIT_TRANSFORM_FLAG_OFFSET + 5 - log2_trafo_size);
828 return GET_CABAC(CBF_CB_CR_OFFSET + trafo_depth);
833 return GET_CABAC(CBF_LUMA_OFFSET + !trafo_depth);
838 return GET_CABAC(TRANSFORM_SKIP_FLAG_OFFSET + !!c_idx);
843 return GET_CABAC(EXPLICIT_RDPCM_FLAG_OFFSET + !!c_idx);
848 return GET_CABAC(EXPLICIT_RDPCM_DIR_FLAG_OFFSET + !!c_idx);
855 while (
i < 4 &&
GET_CABAC(LOG2_RES_SCALE_ABS_OFFSET + 4 * idx +
i))
863 return GET_CABAC(RES_SCALE_SIGN_FLAG_OFFSET + idx);
867 int log2_size,
int *last_scx_prefix,
int *last_scy_prefix)
870 int max = (log2_size << 1) - 1;
871 int ctx_offset, ctx_shift;
874 ctx_offset = 3 * (log2_size - 2) + ((log2_size - 1) >> 2);
875 ctx_shift = (log2_size + 1) >> 2;
878 ctx_shift = log2_size - 2;
881 GET_CABAC(LAST_SIGNIFICANT_COEFF_X_PREFIX_OFFSET + (
i >> ctx_shift) + ctx_offset))
883 *last_scx_prefix =
i;
887 GET_CABAC(LAST_SIGNIFICANT_COEFF_Y_PREFIX_OFFSET + (
i >> ctx_shift) + ctx_offset))
889 *last_scy_prefix =
i;
893 int last_significant_coeff_prefix)
896 int length = (last_significant_coeff_prefix >> 1) - 1;
899 for (
i = 1;
i < length;
i++)
908 inc =
FFMIN(ctx_cg, 1) + (c_idx>0 ? 2 : 0);
910 return GET_CABAC(SIGNIFICANT_COEFF_GROUP_FLAG_OFFSET +
inc);
913 int offset,
const uint8_t *ctx_idx_map)
915 int inc = ctx_idx_map[(y_c << 2) + x_c] +
offset;
930 return GET_CABAC(COEFF_ABS_LEVEL_GREATER1_FLAG_OFFSET +
inc);
938 return GET_CABAC(COEFF_ABS_LEVEL_GREATER2_FLAG_OFFSET +
inc);
945 int last_coeff_abs_level_remaining;
952 for (
i = 0;
i < rc_rice_param;
i++)
954 last_coeff_abs_level_remaining = (prefix << rc_rice_param) +
suffix;
956 int prefix_minus3 = prefix - 3;
958 if (prefix ==
CABAC_MAX_BIN || prefix_minus3 + rc_rice_param > 16 + 6) {
963 for (
i = 0;
i < prefix_minus3 + rc_rice_param;
i++)
965 last_coeff_abs_level_remaining = (((1 << prefix_minus3) + 3 - 1)
966 << rc_rice_param) +
suffix;
968 return last_coeff_abs_level_remaining;
976 for (
i = 0;
i < nb;
i++)
983 int log2_trafo_size,
enum ScanType scan_idx,
986 #define GET_COORD(offset, n) \
988 x_c = (x_cg << 2) + scan_x_off[n]; \
989 y_c = (y_cg << 2) + scan_y_off[n]; \
993 int transform_skip_flag = 0;
995 int last_significant_coeff_x, last_significant_coeff_y;
999 int greater1_ctx = 1;
1001 int num_last_subset;
1002 int x_cg_last_sig, y_cg_last_sig;
1004 const uint8_t *scan_x_cg, *scan_y_cg, *scan_x_off, *scan_y_off;
1006 ptrdiff_t
stride =
s->cur_frame->f->linesize[c_idx];
1007 int hshift =
sps->hshift[c_idx];
1010 ((x0 >> hshift) <<
sps->pixel_shift)];
1012 uint8_t significant_coeff_group_flag[8][8] = {{0}};
1013 int explicit_rdpcm_flag = 0;
1014 int explicit_rdpcm_dir_flag;
1016 int trafo_size = 1 << log2_trafo_size;
1019 static const uint8_t level_scale[] = { 40, 45, 51, 57, 64, 72 };
1020 const uint8_t *scale_matrix =
NULL;
1025 memset(coeffs, 0, trafo_size * trafo_size *
sizeof(int16_t));
1029 static const int qp_c[] = { 29, 30, 31, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37 };
1030 static const uint8_t rem6[51 + 4 * 6 + 1] = {
1031 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2,
1032 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5,
1033 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3,
1034 4, 5, 0, 1, 2, 3, 4, 5, 0, 1
1037 static const uint8_t div6[51 + 4 * 6 + 1] = {
1038 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3,
1039 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6,
1040 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10,
1041 10, 10, 11, 11, 11, 11, 11, 11, 12, 12
1043 int qp_y = lc->
qp_y;
1045 if (
pps->transform_skip_enabled_flag &&
1046 log2_trafo_size <= pps->log2_max_transform_skip_block_size) {
1051 qp = qp_y +
sps->qp_bd_offset;
1056 offset =
pps->cb_qp_offset +
s->sh.slice_cb_qp_offset +
1059 offset =
pps->cr_qp_offset +
s->sh.slice_cr_qp_offset +
1063 if (
sps->chroma_format_idc == 1) {
1069 qp = qp_c[qp_i - 30];
1077 qp +=
sps->qp_bd_offset;
1080 shift =
sps->bit_depth + log2_trafo_size - 5;
1081 add = 1 << (
shift-1);
1082 scale = level_scale[rem6[qp]] << (div6[qp]);
1086 if (
sps->scaling_list_enabled && !(transform_skip_flag && log2_trafo_size > 2)) {
1088 &
pps->scaling_list : &
sps->scaling_list;
1091 matrix_id = 3 * matrix_id + c_idx;
1093 scale_matrix = sl->
sl[log2_trafo_size - 2][matrix_id];
1094 if (log2_trafo_size >= 4)
1095 dc_scale = sl->
sl_dc[log2_trafo_size - 4][matrix_id];
1107 if (explicit_rdpcm_flag) {
1113 &last_significant_coeff_x, &last_significant_coeff_y);
1115 if (last_significant_coeff_x > 3) {
1117 last_significant_coeff_x = (1 << ((last_significant_coeff_x >> 1) - 1)) *
1118 (2 + (last_significant_coeff_x & 1)) +
1122 if (last_significant_coeff_y > 3) {
1124 last_significant_coeff_y = (1 << ((last_significant_coeff_y >> 1) - 1)) *
1125 (2 + (last_significant_coeff_y & 1)) +
1130 FFSWAP(
int, last_significant_coeff_x, last_significant_coeff_y);
1132 x_cg_last_sig = last_significant_coeff_x >> 2;
1133 y_cg_last_sig = last_significant_coeff_y >> 2;
1137 int last_x_c = last_significant_coeff_x & 3;
1138 int last_y_c = last_significant_coeff_y & 3;
1143 if (trafo_size == 4) {
1146 }
else if (trafo_size == 8) {
1150 }
else if (trafo_size == 16) {
1166 num_coeff =
horiz_scan8x8_inv[last_significant_coeff_y][last_significant_coeff_x];
1173 num_coeff =
horiz_scan8x8_inv[last_significant_coeff_x][last_significant_coeff_y];
1177 num_last_subset = (num_coeff - 1) >> 4;
1179 for (
i = num_last_subset;
i >= 0;
i--) {
1181 int x_cg, y_cg, x_c, y_c,
pos;
1182 int implicit_non_zero_coeff = 0;
1188 uint8_t significant_coeff_flag_idx[16];
1189 uint8_t nb_significant_coeff_flag = 0;
1191 x_cg = scan_x_cg[
i];
1192 y_cg = scan_y_cg[
i];
1194 if ((
i < num_last_subset) && (
i > 0)) {
1196 if (x_cg < (1 << (log2_trafo_size - 2)) - 1)
1197 ctx_cg += significant_coeff_group_flag[x_cg + 1][y_cg];
1198 if (y_cg < (1 << (log2_trafo_size - 2)) - 1)
1199 ctx_cg += significant_coeff_group_flag[x_cg][y_cg + 1];
1201 significant_coeff_group_flag[x_cg][y_cg] =
1203 implicit_non_zero_coeff = 1;
1205 significant_coeff_group_flag[x_cg][y_cg] =
1206 ((x_cg == x_cg_last_sig && y_cg == y_cg_last_sig) ||
1207 (x_cg == 0 && y_cg == 0));
1210 last_scan_pos = num_coeff -
offset - 1;
1212 if (
i == num_last_subset) {
1213 n_end = last_scan_pos - 1;
1214 significant_coeff_flag_idx[0] = last_scan_pos;
1215 nb_significant_coeff_flag = 1;
1220 if (x_cg < ((1 << log2_trafo_size) - 1) >> 2)
1221 prev_sig = !!significant_coeff_group_flag[x_cg + 1][y_cg];
1222 if (y_cg < ((1 << log2_trafo_size) - 1) >> 2)
1223 prev_sig += (!!significant_coeff_group_flag[x_cg][y_cg + 1] << 1);
1225 if (significant_coeff_group_flag[x_cg][y_cg] && n_end >= 0) {
1226 static const uint8_t ctx_idx_map[] = {
1227 0, 1, 4, 5, 2, 3, 4, 5, 6, 6, 8, 8, 7, 7, 8, 8,
1228 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
1229 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
1230 2, 1, 0, 0, 2, 1, 0, 0, 2, 1, 0, 0, 2, 1, 0, 0,
1231 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
1233 const uint8_t *ctx_idx_map_p;
1235 if (
sps->transform_skip_context_enabled &&
1237 ctx_idx_map_p = &ctx_idx_map[4 * 16];
1241 scf_offset = 14 + 27;
1246 if (log2_trafo_size == 2) {
1247 ctx_idx_map_p = &ctx_idx_map[0];
1249 ctx_idx_map_p = &ctx_idx_map[(prev_sig + 1) << 4];
1251 if ((x_cg > 0 || y_cg > 0))
1253 if (log2_trafo_size == 3) {
1254 scf_offset += (scan_idx ==
SCAN_DIAG) ? 9 : 15;
1259 if (log2_trafo_size == 3)
1266 for (n = n_end; n > 0; n--) {
1267 x_c = scan_x_off[n];
1268 y_c = scan_y_off[n];
1270 significant_coeff_flag_idx[nb_significant_coeff_flag] = n;
1271 nb_significant_coeff_flag++;
1272 implicit_non_zero_coeff = 0;
1275 if (implicit_non_zero_coeff == 0) {
1276 if (
sps->transform_skip_context_enabled &&
1281 scf_offset = 16 + 27;
1290 scf_offset = 2 + scf_offset;
1294 significant_coeff_flag_idx[nb_significant_coeff_flag] = 0;
1295 nb_significant_coeff_flag++;
1298 significant_coeff_flag_idx[nb_significant_coeff_flag] = 0;
1299 nb_significant_coeff_flag++;
1303 n_end = nb_significant_coeff_flag;
1307 int first_nz_pos_in_cg;
1308 int last_nz_pos_in_cg;
1309 int c_rice_param = 0;
1310 int first_greater1_coeff_idx = -1;
1311 uint8_t coeff_abs_level_greater1_flag[8];
1312 uint16_t coeff_sign_flag;
1319 int ctx_set = (
i > 0 && c_idx == 0) ? 2 : 0;
1321 if (
sps->persistent_rice_adaptation_enabled) {
1323 sb_type = 2 * (c_idx == 0 ? 1 : 0);
1325 sb_type = 2 * (c_idx == 0 ? 1 : 0) + 1;
1329 if (!(
i == num_last_subset) && greater1_ctx == 0)
1332 last_nz_pos_in_cg = significant_coeff_flag_idx[0];
1334 for (m = 0; m < (n_end > 8 ? 8 : n_end); m++) {
1335 int inc = (ctx_set << 2) + greater1_ctx;
1336 coeff_abs_level_greater1_flag[m] =
1338 if (coeff_abs_level_greater1_flag[m]) {
1340 if (first_greater1_coeff_idx == -1)
1341 first_greater1_coeff_idx = m;
1342 }
else if (greater1_ctx > 0 && greater1_ctx < 3) {
1346 first_nz_pos_in_cg = significant_coeff_flag_idx[n_end - 1];
1350 sps->implicit_rdpcm_enabled && transform_skip_flag &&
1351 (pred_mode_intra == 10 || pred_mode_intra == 26 )) ||
1352 explicit_rdpcm_flag)
1355 sign_hidden = (last_nz_pos_in_cg - first_nz_pos_in_cg >= 4);
1357 if (first_greater1_coeff_idx != -1) {
1360 if (!
pps->sign_data_hiding_flag || !sign_hidden ) {
1361 coeff_sign_flag =
coeff_sign_flag_decode(lc, nb_significant_coeff_flag) << (16 - nb_significant_coeff_flag);
1363 coeff_sign_flag =
coeff_sign_flag_decode(lc, nb_significant_coeff_flag - 1) << (16 - (nb_significant_coeff_flag - 1));
1366 for (m = 0; m < n_end; m++) {
1367 n = significant_coeff_flag_idx[m];
1370 trans_coeff_level = 1 + coeff_abs_level_greater1_flag[m];
1371 if (trans_coeff_level == ((m == first_greater1_coeff_idx) ? 3 : 2)) {
1374 trans_coeff_level += last_coeff_abs_level_remaining;
1375 if (trans_coeff_level > (3 << c_rice_param))
1376 c_rice_param =
sps->persistent_rice_adaptation_enabled ? c_rice_param + 1 :
FFMIN(c_rice_param + 1, 4);
1377 if (
sps->persistent_rice_adaptation_enabled && !rice_init) {
1378 int c_rice_p_init = lc->
stat_coeff[sb_type] / 4;
1379 if (last_coeff_abs_level_remaining >= (3 << c_rice_p_init))
1381 else if (2 * last_coeff_abs_level_remaining < (1 << c_rice_p_init))
1390 trans_coeff_level = 1 + last_coeff_abs_level_remaining;
1391 if (trans_coeff_level > (3 << c_rice_param))
1392 c_rice_param =
sps->persistent_rice_adaptation_enabled ? c_rice_param + 1 :
FFMIN(c_rice_param + 1, 4);
1393 if (
sps->persistent_rice_adaptation_enabled && !rice_init) {
1394 int c_rice_p_init = lc->
stat_coeff[sb_type] / 4;
1395 if (last_coeff_abs_level_remaining >= (3 << c_rice_p_init))
1397 else if (2 * last_coeff_abs_level_remaining < (1 << c_rice_p_init))
1403 if (
pps->sign_data_hiding_flag && sign_hidden) {
1404 sum_abs += trans_coeff_level;
1405 if (n == first_nz_pos_in_cg && (sum_abs&1))
1406 trans_coeff_level = -trans_coeff_level;
1408 if (coeff_sign_flag >> 15)
1409 trans_coeff_level = -trans_coeff_level;
1410 coeff_sign_flag <<= 1;
1412 if (
sps->scaling_list_enabled && !(transform_skip_flag && log2_trafo_size > 2)) {
1413 if(y_c || x_c || log2_trafo_size < 4) {
1414 switch(log2_trafo_size) {
1415 case 3:
pos = (y_c << 3) + x_c;
break;
1416 case 4:
pos = ((y_c >> 1) << 3) + (x_c >> 1);
break;
1417 case 5:
pos = ((y_c >> 2) << 3) + (x_c >> 2);
break;
1418 default:
pos = (y_c << 2) + x_c;
break;
1420 scale_m = scale_matrix[
pos];
1426 if(trans_coeff_level < 0) {
1427 if((~trans_coeff_level) & 0xFffffffffff8000)
1428 trans_coeff_level = -32768;
1430 if(trans_coeff_level & 0xffffffffffff8000)
1431 trans_coeff_level = 32767;
1434 coeffs[y_c * trafo_size + x_c] = trans_coeff_level;
1440 if (explicit_rdpcm_flag || (
sps->implicit_rdpcm_enabled &&
1441 (pred_mode_intra == 10 || pred_mode_intra == 26))) {
1442 int mode =
sps->implicit_rdpcm_enabled ? (pred_mode_intra == 26) : explicit_rdpcm_dir_flag;
1444 s->hevcdsp.transform_rdpcm(coeffs, log2_trafo_size,
mode);
1447 if (transform_skip_flag) {
1448 int rot =
sps->transform_skip_rotation_enabled &&
1449 log2_trafo_size == 2 &&
1452 for (
i = 0;
i < 8;
i++)
1453 FFSWAP(int16_t, coeffs[
i], coeffs[16 -
i - 1]);
1456 s->hevcdsp.dequant(coeffs, log2_trafo_size);
1458 if (explicit_rdpcm_flag || (
sps->implicit_rdpcm_enabled &&
1460 (pred_mode_intra == 10 || pred_mode_intra == 26))) {
1461 int mode = explicit_rdpcm_flag ? explicit_rdpcm_dir_flag : (pred_mode_intra == 26);
1463 s->hevcdsp.transform_rdpcm(coeffs, log2_trafo_size,
mode);
1466 s->hevcdsp.transform_4x4_luma(coeffs);
1468 int max_xy =
FFMAX(last_significant_coeff_x, last_significant_coeff_y);
1470 s->hevcdsp.idct_dc[log2_trafo_size - 2](coeffs);
1472 int col_limit = last_significant_coeff_x + last_significant_coeff_y + 4;
1474 col_limit =
FFMIN(4, col_limit);
1475 else if (max_xy < 8)
1476 col_limit =
FFMIN(8, col_limit);
1477 else if (max_xy < 12)
1478 col_limit =
FFMIN(24, col_limit);
1479 s->hevcdsp.idct[log2_trafo_size - 2](coeffs, col_limit);
1486 for (
i = 0;
i < (trafo_size * trafo_size);
i++) {
1490 s->hevcdsp.add_residual[log2_trafo_size-2](
dst, coeffs,
stride);
1506 case 0: lc->
pu.
mvd.
x = 0;
break;
1512 case 0: lc->
pu.
mvd.
y = 0;
break;