diff --git a/libavcodec/hevc.c b/libavcodec/hevc.c index e88798b3b7..324ba2ab3b 100644 --- a/libavcodec/hevc.c +++ b/libavcodec/hevc.c @@ -112,8 +112,10 @@ static int pic_arrays_init(HEVCContext *s, const HEVCSPS *sps) goto fail; s->filter_slice_edges = av_malloc(ctb_count); - s->tab_slice_address = av_malloc(pic_size_in_ctb * sizeof(*s->tab_slice_address)); - s->qp_y_tab = av_malloc(pic_size_in_ctb * sizeof(*s->qp_y_tab)); + s->tab_slice_address = av_malloc(pic_size_in_ctb * + sizeof(*s->tab_slice_address)); + s->qp_y_tab = av_malloc(pic_size_in_ctb * + sizeof(*s->qp_y_tab)); if (!s->qp_y_tab || !s->filter_slice_edges || !s->tab_slice_address) goto fail; @@ -130,6 +132,7 @@ static int pic_arrays_init(HEVCContext *s, const HEVCSPS *sps) goto fail; return 0; + fail: pic_arrays_free(s); return AVERROR(ENOMEM); @@ -308,6 +311,7 @@ static int set_sps(HEVCContext *s, const HEVCSPS *sps) s->sps = sps; s->vps = s->vps_list[s->sps->vps_id]; return 0; + fail: pic_arrays_free(s); s->sps = NULL; @@ -366,7 +370,8 @@ static int hls_slice_header(HEVCContext *s) s->sps->ctb_height); sh->slice_segment_addr = get_bits(gb, slice_address_length); if (sh->slice_segment_addr >= s->sps->ctb_width * s->sps->ctb_height) { - av_log(s->avctx, AV_LOG_ERROR, "Invalid slice segment address: %u.\n", + av_log(s->avctx, AV_LOG_ERROR, + "Invalid slice segment address: %u.\n", sh->slice_segment_addr); return AVERROR_INVALIDDATA; } @@ -388,7 +393,8 @@ static int hls_slice_header(HEVCContext *s) skip_bits(gb, 1); // slice_reserved_undetermined_flag[] sh->slice_type = get_ue_golomb_long(gb); - if (!(sh->slice_type == I_SLICE || sh->slice_type == P_SLICE || + if (!(sh->slice_type == I_SLICE || + sh->slice_type == P_SLICE || sh->slice_type == B_SLICE)) { av_log(s->avctx, AV_LOG_ERROR, "Unknown slice type: %d.\n", sh->slice_type); @@ -453,7 +459,7 @@ static int hls_slice_header(HEVCContext *s) sh->slice_temporal_mvp_enabled_flag = 0; } else { s->sh.short_term_rps = NULL; - s->poc = 0; + s->poc = 0; } /* 8.3.1 */ @@ -537,7 +543,8 @@ static int hls_slice_header(HEVCContext *s) sh->collocated_ref_idx = get_ue_golomb_long(gb); if (sh->collocated_ref_idx >= sh->nb_refs[sh->collocated_list]) { av_log(s->avctx, AV_LOG_ERROR, - "Invalid collocated_ref_idx: %d.\n", sh->collocated_ref_idx); + "Invalid collocated_ref_idx: %d.\n", + sh->collocated_ref_idx); return AVERROR_INVALIDDATA; } } @@ -580,13 +587,13 @@ static int hls_slice_header(HEVCContext *s) } } else { sh->disable_deblocking_filter_flag = s->pps->disable_dbf; - sh->beta_offset = s->pps->beta_offset; - sh->tc_offset = s->pps->tc_offset; + sh->beta_offset = s->pps->beta_offset; + sh->tc_offset = s->pps->tc_offset; } } else { sh->disable_deblocking_filter_flag = 0; - sh->beta_offset = 0; - sh->tc_offset = 0; + sh->beta_offset = 0; + sh->tc_offset = 0; } if (s->pps->seq_loop_filter_across_slices_enabled_flag && @@ -714,7 +721,8 @@ static void hls_sao_param(HEVCContext *s, int rx, int ry) if (sao->type_idx[c_idx] == SAO_BAND) { for (i = 0; i < 4; i++) { if (sao->offset_abs[c_idx][i]) { - SET_SAO(offset_sign[c_idx][i], ff_hevc_sao_offset_sign_decode(s)); + SET_SAO(offset_sign[c_idx][i], + ff_hevc_sao_offset_sign_decode(s)); } else { sao->offset_sign[c_idx][i] = 0; } @@ -741,7 +749,6 @@ static void hls_sao_param(HEVCContext *s, int rx, int ry) #undef SET_SAO #undef CTB - static void hls_transform_unit(HEVCContext *s, int x0, int y0, int xBase, int yBase, int cb_xBase, int cb_yBase, int log2_cb_size, int log2_trafo_size, @@ -761,7 +768,8 @@ static void hls_transform_unit(HEVCContext *s, int x0, int y0, s->hpc.intra_pred(s, x0, y0, log2_trafo_size - 1, 2); } else if (blk_idx == 3) { trafo_size = trafo_size << (s->sps->hshift[1]); - ff_hevc_set_neighbour_available(s, xBase, yBase, trafo_size, trafo_size); + ff_hevc_set_neighbour_available(s, xBase, yBase, + trafo_size, trafo_size); s->hpc.intra_pred(s, xBase, yBase, log2_trafo_size, 1); s->hpc.intra_pred(s, xBase, yBase, log2_trafo_size, 2); } @@ -791,7 +799,7 @@ static void hls_transform_unit(HEVCContext *s, int x0, int y0, scan_idx = SCAN_HORIZ; } - if (lc->pu.intra_pred_mode_c >= 6 && + if (lc->pu.intra_pred_mode_c >= 6 && lc->pu.intra_pred_mode_c <= 14) { scan_idx_c = SCAN_VERT; } else if (lc->pu.intra_pred_mode_c >= 22 && @@ -821,7 +829,7 @@ static void set_deblocking_bypass(HEVCContext *s, int x0, int y0, int log2_cb_si int cb_size = 1 << log2_cb_size; int log2_min_pu_size = s->sps->log2_min_pu_size; - int min_pu_width = s->sps->min_pu_width; + int min_pu_width = s->sps->min_pu_width; int x_end = FFMIN(x0 + cb_size, s->sps->width); int y_end = FFMIN(y0 + cb_size, s->sps->height); int i, j; @@ -859,18 +867,19 @@ static void hls_transform_tree(HEVCContext *s, int x0, int y0, lc->tt.cbf_luma = 1; lc->tt.inter_split_flag = (s->sps->max_transform_hierarchy_depth_inter == 0 && - lc->cu.pred_mode == MODE_INTER && - lc->cu.part_mode != PART_2Nx2N && trafo_depth == 0); + lc->cu.pred_mode == MODE_INTER && + lc->cu.part_mode != PART_2Nx2N && + trafo_depth == 0); if (log2_trafo_size <= s->sps->log2_max_trafo_size && - log2_trafo_size > s->sps->log2_min_tb_size && - trafo_depth < lc->cu.max_trafo_depth && + log2_trafo_size > s->sps->log2_min_tb_size && + trafo_depth < lc->cu.max_trafo_depth && !(lc->cu.intra_split_flag && trafo_depth == 0)) { split_transform_flag = ff_hevc_split_transform_flag_decode(s, log2_trafo_size); } else { split_transform_flag = (log2_trafo_size > s->sps->log2_max_trafo_size || - (lc->cu.intra_split_flag && (trafo_depth == 0)) || - lc->tt.inter_split_flag); + (lc->cu.intra_split_flag && (trafo_depth == 0)) || + lc->tt.inter_split_flag); } if (log2_trafo_size > 2) { @@ -880,7 +889,8 @@ static void hls_transform_tree(HEVCContext *s, int x0, int y0, ff_hevc_cbf_cb_cr_decode(s, trafo_depth); } - if (trafo_depth == 0 || SAMPLE_CBF(lc->tt.cbf_cr[trafo_depth - 1], xBase, yBase)) { + if (trafo_depth == 0 || + SAMPLE_CBF(lc->tt.cbf_cr[trafo_depth - 1], xBase, yBase)) { SAMPLE_CBF(lc->tt.cbf_cr[trafo_depth], x0, y0) = ff_hevc_cbf_cb_cr_decode(s, trafo_depth); } @@ -926,7 +936,8 @@ static void hls_transform_tree(HEVCContext *s, int x0, int y0, ff_hevc_deblocking_boundary_strengths(s, x0, y0, log2_trafo_size, lc->slice_or_tiles_up_boundary, lc->slice_or_tiles_left_boundary); - if (s->pps->transquant_bypass_enable_flag && lc->cu.cu_transquant_bypass_flag) + if (s->pps->transquant_bypass_enable_flag && + lc->cu.cu_transquant_bypass_flag) set_deblocking_bypass(s, x0, y0, log2_trafo_size); } } @@ -957,7 +968,7 @@ static int hls_pcm_sample(HEVCContext *s, int x0, int y0, int log2_cb_size) if (ret < 0) return ret; - s->hevcdsp.put_pcm(dst0, stride0, cb_size, &gb, s->sps->pcm.bit_depth); + s->hevcdsp.put_pcm(dst0, stride0, cb_size, &gb, s->sps->pcm.bit_depth); s->hevcdsp.put_pcm(dst1, stride1, cb_size / 2, &gb, s->sps->pcm.bit_depth_chroma); s->hevcdsp.put_pcm(dst2, stride2, cb_size / 2, &gb, s->sps->pcm.bit_depth_chroma); return 0; @@ -1001,7 +1012,8 @@ static void luma_mc(HEVCContext *s, int16_t *dst, ptrdiff_t dststride, int offset = extra_top * srcstride + (extra_left << s->sps->pixel_shift); s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, srcstride, src - offset, srcstride, - block_w + ff_hevc_qpel_extra[mx], block_h + ff_hevc_qpel_extra[my], + block_w + ff_hevc_qpel_extra[mx], + block_h + ff_hevc_qpel_extra[my], x_off - extra_left, y_off - extra_top, pic_width, pic_height); src = lc->edge_emu_buffer + offset; @@ -1024,8 +1036,9 @@ static void luma_mc(HEVCContext *s, int16_t *dst, ptrdiff_t dststride, * @param block_w width of block * @param block_h height of block */ -static void chroma_mc(HEVCContext *s, int16_t *dst1, int16_t *dst2, ptrdiff_t dststride, AVFrame *ref, - const Mv *mv, int x_off, int y_off, int block_w, int block_h) +static void chroma_mc(HEVCContext *s, int16_t *dst1, int16_t *dst2, + ptrdiff_t dststride, AVFrame *ref, const Mv *mv, + int x_off, int y_off, int block_w, int block_h) { HEVCLocalContext *lc = s->HEVClc; uint8_t *src1 = ref->data[1]; @@ -1124,8 +1137,11 @@ static void hls_prediction_unit(HEVCContext *s, int x0, int y0, else merge_idx = 0; - ff_hevc_luma_mv_merge_mode(s, x0, y0, 1 << log2_cb_size, 1 << log2_cb_size, - log2_cb_size, partIdx, merge_idx, ¤t_mv); + ff_hevc_luma_mv_merge_mode(s, x0, y0, + 1 << log2_cb_size, + 1 << log2_cb_size, + log2_cb_size, partIdx, + merge_idx, ¤t_mv); x_pu = x0 >> s->sps->log2_min_pu_size; y_pu = y0 >> s->sps->log2_min_pu_size; @@ -1163,7 +1179,8 @@ static void hls_prediction_unit(HEVCContext *s, int x0, int y0, ff_hevc_hls_mvd_coding(s, x0, y0, 0); mvp_flag[0] = ff_hevc_mvp_lx_flag_decode(s); ff_hevc_luma_mv_mvp_mode(s, x0, y0, nPbW, nPbH, log2_cb_size, - partIdx, merge_idx, ¤t_mv, mvp_flag[0], 0); + partIdx, merge_idx, ¤t_mv, + mvp_flag[0], 0); current_mv.mv[0].x += lc->pu.mvd.x; current_mv.mv[0].y += lc->pu.mvd.y; } @@ -1184,7 +1201,8 @@ static void hls_prediction_unit(HEVCContext *s, int x0, int y0, current_mv.pred_flag[1] = 1; mvp_flag[1] = ff_hevc_mvp_lx_flag_decode(s); ff_hevc_luma_mv_mvp_mode(s, x0, y0, nPbW, nPbH, log2_cb_size, - partIdx, merge_idx, ¤t_mv, mvp_flag[1], 1); + partIdx, merge_idx, ¤t_mv, + mvp_flag[1], 1); current_mv.mv[1].x += lc->pu.mvd.x; current_mv.mv[1].y += lc->pu.mvd.y; } @@ -1212,7 +1230,7 @@ static void hls_prediction_unit(HEVCContext *s, int x0, int y0, } if (current_mv.pred_flag[0] && !current_mv.pred_flag[1]) { - DECLARE_ALIGNED(16, int16_t, tmp [MAX_PB_SIZE * MAX_PB_SIZE]); + DECLARE_ALIGNED(16, int16_t, tmp[MAX_PB_SIZE * MAX_PB_SIZE]); DECLARE_ALIGNED(16, int16_t, tmp2[MAX_PB_SIZE * MAX_PB_SIZE]); luma_mc(s, tmp, tmpstride, ref0->frame, @@ -1520,14 +1538,14 @@ static int hls_coding_unit(HEVCContext *s, int x0, int y0, int log2_cb_size) int y_cb = y0 >> log2_min_cb_size; int x, y; - lc->cu.x = x0; - lc->cu.y = y0; - lc->cu.rqt_root_cbf = 1; + lc->cu.x = x0; + lc->cu.y = y0; + lc->cu.rqt_root_cbf = 1; + lc->cu.pred_mode = MODE_INTRA; + lc->cu.part_mode = PART_2Nx2N; + lc->cu.intra_split_flag = 0; + lc->cu.pcm_flag = 0; - lc->cu.pred_mode = MODE_INTRA; - lc->cu.part_mode = PART_2Nx2N; - lc->cu.intra_split_flag = 0; - lc->cu.pcm_flag = 0; SAMPLE_CTB(s->skip_flag, x_cb, y_cb) = 0; for (x = 0; x < 4; x++) lc->pu.intra_pred_mode[x] = 1; @@ -1593,33 +1611,33 @@ static int hls_coding_unit(HEVCContext *s, int x0, int y0, int log2_cb_size) hls_prediction_unit(s, x0, y0, cb_size, cb_size, log2_cb_size, 0); break; case PART_2NxN: - hls_prediction_unit(s, x0, y0, cb_size, cb_size / 2, log2_cb_size, 0); - hls_prediction_unit(s, x0, y0 + cb_size / 2, cb_size, cb_size/2, log2_cb_size, 1); + hls_prediction_unit(s, x0, y0, cb_size, cb_size / 2, log2_cb_size, 0); + hls_prediction_unit(s, x0, y0 + cb_size / 2, cb_size, cb_size / 2, log2_cb_size, 1); break; case PART_Nx2N: - hls_prediction_unit(s, x0, y0, cb_size / 2, cb_size, log2_cb_size, 0); + hls_prediction_unit(s, x0, y0, cb_size / 2, cb_size, log2_cb_size, 0); hls_prediction_unit(s, x0 + cb_size / 2, y0, cb_size / 2, cb_size, log2_cb_size, 1); break; case PART_2NxnU: - hls_prediction_unit(s, x0, y0, cb_size, cb_size / 4, log2_cb_size, 0); + hls_prediction_unit(s, x0, y0, cb_size, cb_size / 4, log2_cb_size, 0); hls_prediction_unit(s, x0, y0 + cb_size / 4, cb_size, cb_size * 3 / 4, log2_cb_size, 1); break; case PART_2NxnD: - hls_prediction_unit(s, x0, y0, cb_size, cb_size * 3 / 4, log2_cb_size, 0); - hls_prediction_unit(s, x0, y0 + cb_size * 3 / 4, cb_size, cb_size / 4, log2_cb_size, 1); + hls_prediction_unit(s, x0, y0, cb_size, cb_size * 3 / 4, log2_cb_size, 0); + hls_prediction_unit(s, x0, y0 + cb_size * 3 / 4, cb_size, cb_size / 4, log2_cb_size, 1); break; case PART_nLx2N: - hls_prediction_unit(s, x0, y0, cb_size / 4, cb_size, log2_cb_size,0); + hls_prediction_unit(s, x0, y0, cb_size / 4, cb_size, log2_cb_size, 0); hls_prediction_unit(s, x0 + cb_size / 4, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 1); break; case PART_nRx2N: - hls_prediction_unit(s, x0, y0, cb_size * 3 / 4, cb_size, log2_cb_size,0); - hls_prediction_unit(s, x0 + cb_size * 3 / 4, y0, cb_size/4, cb_size, log2_cb_size, 1); + hls_prediction_unit(s, x0, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 0); + hls_prediction_unit(s, x0 + cb_size * 3 / 4, y0, cb_size / 4, cb_size, log2_cb_size, 1); break; case PART_NxN: - hls_prediction_unit(s, x0, y0, cb_size / 2, cb_size / 2, log2_cb_size, 0); - hls_prediction_unit(s, x0 + cb_size / 2, y0, cb_size / 2, cb_size / 2, log2_cb_size, 1); - hls_prediction_unit(s, x0, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 2); + hls_prediction_unit(s, x0, y0, cb_size / 2, cb_size / 2, log2_cb_size, 0); + hls_prediction_unit(s, x0 + cb_size / 2, y0, cb_size / 2, cb_size / 2, log2_cb_size, 1); + hls_prediction_unit(s, x0, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 2); hls_prediction_unit(s, x0 + cb_size / 2, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 3); break; } @@ -1725,7 +1743,8 @@ static int hls_coding_quadtree(HEVCContext *s, int x0, int y0, return 0; } -static void hls_decode_neighbour(HEVCContext *s, int x_ctb, int y_ctb, int ctb_addr_ts) +static void hls_decode_neighbour(HEVCContext *s, int x_ctb, int y_ctb, + int ctb_addr_ts) { HEVCLocalContext *lc = s->HEVClc; int ctb_size = 1 << s->sps->log2_ctb_size; @@ -2009,7 +2028,7 @@ static int hls_nal_unit(HEVCContext *s) static void restore_tqb_pixels(HEVCContext *s) { - int min_pu_size = 1 << s->sps->log2_min_pu_size; + int min_pu_size = 1 << s->sps->log2_min_pu_size; int x, y, c_idx; for (c_idx = 0; c_idx < 3; c_idx++) { @@ -2076,6 +2095,7 @@ static int hevc_frame_start(HEVCContext *s) ff_thread_finish_setup(s->avctx); return 0; + fail: if (s->ref && s->threads_type == FF_THREAD_FRAME) ff_thread_report_progress(&s->ref->tf, INT_MAX, 0); @@ -2316,8 +2336,8 @@ int ff_hevc_extract_rbsp(HEVCContext *s, const uint8_t *src, int length, } while (si < length) dst[di++] = src[si++]; -nsc: +nsc: memset(dst + di, 0, FF_INPUT_BUFFER_PADDING_SIZE); nal->data = dst; @@ -2359,8 +2379,8 @@ static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length) if (length < 4) { av_log(s->avctx, AV_LOG_ERROR, "No start code is found.\n"); ret = AVERROR_INVALIDDATA; - goto fail; - } + goto fail; + } } buf += 3; @@ -2378,7 +2398,8 @@ static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length) goto fail; } s->nals = tmp; - memset(s->nals + s->nals_allocated, 0, (new_size - s->nals_allocated) * sizeof(*tmp)); + memset(s->nals + s->nals_allocated, 0, + (new_size - s->nals_allocated) * sizeof(*tmp)); av_reallocp_array(&s->skipped_bytes_nal, new_size, sizeof(*s->skipped_bytes_nal)); av_reallocp_array(&s->skipped_bytes_pos_size_nal, new_size, sizeof(*s->skipped_bytes_pos_size_nal)); av_reallocp_array(&s->skipped_bytes_pos_nal, new_size, sizeof(*s->skipped_bytes_pos_nal)); @@ -2437,7 +2458,7 @@ fail: return ret; } -static void print_md5(void *log_ctx, int level, uint8_t md5[16]) +static void print_md5(void *log_ctx, int level, uint8_t md5[16]) { int i; for (i = 0; i < 16; i++) @@ -2526,7 +2547,7 @@ static int hevc_decode_frame(AVCodecContext *avctx, void *data, int *got_output, } s->ref = NULL; - ret = decode_nal_units(s, avpkt->data, avpkt->size); + ret = decode_nal_units(s, avpkt->data, avpkt->size); if (ret < 0) return ret; @@ -2691,6 +2712,7 @@ static av_cold int hevc_init_context(AVCodecContext *avctx) s->context_initialized = 1; return 0; + fail: hevc_decode_free(avctx); return AVERROR(ENOMEM); @@ -2803,7 +2825,8 @@ static int hevc_decode_extradata(HEVCContext *s) ret = decode_nal_units(s, gb.buffer, nalsize); if (ret < 0) { av_log(avctx, AV_LOG_ERROR, - "Decoding nal unit %d %d from hvcC failed\n", type, i); + "Decoding nal unit %d %d from hvcC failed\n", + type, i); return ret; } bytestream2_skip(&gb, nalsize); @@ -2907,5 +2930,6 @@ AVCodec ff_hevc_decoder = { .flush = hevc_decode_flush, .update_thread_context = hevc_update_thread_context, .init_thread_copy = hevc_init_thread_copy, - .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_SLICE_THREADS | CODEC_CAP_FRAME_THREADS, + .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY | + CODEC_CAP_SLICE_THREADS | CODEC_CAP_FRAME_THREADS, }; diff --git a/libavcodec/hevc_cabac.c b/libavcodec/hevc_cabac.c index 1b66c6fc7f..a8cf9a78fa 100644 --- a/libavcodec/hevc_cabac.c +++ b/libavcodec/hevc_cabac.c @@ -33,94 +33,94 @@ * number of bin by SyntaxElement. */ static const int8_t num_bins_in_se[] = { - 1, // sao_merge_flag - 1, // sao_type_idx - 0, // sao_eo_class - 0, // sao_band_position - 0, // sao_offset_abs - 0, // sao_offset_sign - 0, // end_of_slice_flag - 3, // split_coding_unit_flag - 1, // cu_transquant_bypass_flag - 3, // skip_flag - 3, // cu_qp_delta - 1, // pred_mode - 4, // part_mode - 0, // pcm_flag - 1, // prev_intra_luma_pred_mode - 0, // mpm_idx - 0, // rem_intra_luma_pred_mode - 2, // intra_chroma_pred_mode - 1, // merge_flag - 1, // merge_idx - 5, // inter_pred_idc - 2, // ref_idx_l0 - 2, // ref_idx_l1 - 2, // abs_mvd_greater0_flag - 2, // abs_mvd_greater1_flag - 0, // abs_mvd_minus2 - 0, // mvd_sign_flag - 1, // mvp_lx_flag - 1, // no_residual_data_flag - 3, // split_transform_flag - 2, // cbf_luma - 4, // cbf_cb, cbf_cr - 2, // transform_skip_flag[][] - 18, // last_significant_coeff_x_prefix - 18, // last_significant_coeff_y_prefix - 0, // last_significant_coeff_x_suffix - 0, // last_significant_coeff_y_suffix - 4, // significant_coeff_group_flag - 42, // significant_coeff_flag - 24, // coeff_abs_level_greater1_flag - 6, // coeff_abs_level_greater2_flag - 0, // coeff_abs_level_remaining - 0, // coeff_sign_flag + 1, // sao_merge_flag + 1, // sao_type_idx + 0, // sao_eo_class + 0, // sao_band_position + 0, // sao_offset_abs + 0, // sao_offset_sign + 0, // end_of_slice_flag + 3, // split_coding_unit_flag + 1, // cu_transquant_bypass_flag + 3, // skip_flag + 3, // cu_qp_delta + 1, // pred_mode + 4, // part_mode + 0, // pcm_flag + 1, // prev_intra_luma_pred_mode + 0, // mpm_idx + 0, // rem_intra_luma_pred_mode + 2, // intra_chroma_pred_mode + 1, // merge_flag + 1, // merge_idx + 5, // inter_pred_idc + 2, // ref_idx_l0 + 2, // ref_idx_l1 + 2, // abs_mvd_greater0_flag + 2, // abs_mvd_greater1_flag + 0, // abs_mvd_minus2 + 0, // mvd_sign_flag + 1, // mvp_lx_flag + 1, // no_residual_data_flag + 3, // split_transform_flag + 2, // cbf_luma + 4, // cbf_cb, cbf_cr + 2, // transform_skip_flag[][] + 18, // last_significant_coeff_x_prefix + 18, // last_significant_coeff_y_prefix + 0, // last_significant_coeff_x_suffix + 0, // last_significant_coeff_y_suffix + 4, // significant_coeff_group_flag + 42, // significant_coeff_flag + 24, // coeff_abs_level_greater1_flag + 6, // coeff_abs_level_greater2_flag + 0, // coeff_abs_level_remaining + 0, // coeff_sign_flag }; /** * Offset to ctxIdx 0 in init_values and states, indexed by SyntaxElement. */ static const int elem_offset[sizeof(num_bins_in_se)] = { - 0, - 1, - 2, - 2, - 2, - 2, - 2, - 2, - 5, - 6, - 9, - 12, - 13, - 17, - 17, - 18, - 18, - 18, - 20, - 21, - 22, - 27, - 29, - 31, - 33, - 35, - 35, - 35, - 36, - 37, - 40, - 42, - 46, - 48, - 66, - 84, - 84, - 84, - 88, + 0, + 1, + 2, + 2, + 2, + 2, + 2, + 2, + 5, + 6, + 9, + 12, + 13, + 17, + 17, + 18, + 18, + 18, + 20, + 21, + 22, + 27, + 29, + 31, + 33, + 35, + 35, + 35, + 36, + 37, + 40, + 42, + 46, + 48, + 66, + 84, + 84, + 84, + 88, 130, 154, 160, @@ -132,200 +132,195 @@ static const int elem_offset[sizeof(num_bins_in_se)] = { * Indexed by init_type */ static const uint8_t init_values[3][HEVC_CONTEXTS] = { - { - // sao_merge_flag - 153, - // sao_type_idx - 200, - // split_coding_unit_flag - 139, 141, 157, - // cu_transquant_bypass_flag - 154, - // skip_flag - CNU, CNU, CNU, - // cu_qp_delta - 154, 154, 154, - // pred_mode - CNU, - // part_mode - 184, CNU, CNU, CNU, - // prev_intra_luma_pred_mode - 184, - // intra_chroma_pred_mode - 63, 139, - // merge_flag - CNU, - // merge_idx - CNU, - // inter_pred_idc - CNU, CNU, CNU, CNU, CNU, - // ref_idx_l0 - CNU, CNU, - // ref_idx_l1 - CNU, CNU, - // abs_mvd_greater1_flag - CNU, CNU, - // abs_mvd_greater1_flag - CNU, CNU, - // mvp_lx_flag - CNU, - // no_residual_data_flag - CNU, - // split_transform_flag - 153, 138, 138, - // cbf_luma - 111, 141, - // cbf_cb, cbf_cr - 94, 138, 182, 154, - // transform_skip_flag - 139, 139, - // last_significant_coeff_x_prefix - 110, 110, 124, 125, 140, 153, 125, 127, 140, 109, 111, 143, 127, 111, - 79, 108, 123, 63, - // last_significant_coeff_y_prefix - 110, 110, 124, 125, 140, 153, 125, 127, 140, 109, 111, 143, 127, 111, - 79, 108, 123, 63, - // significant_coeff_group_flag - 91, 171, 134, 141, - // significant_coeff_flag - 111, 111, 125, 110, 110, 94, 124, 108, 124, 107, 125, 141, 179, 153, - 125, 107, 125, 141, 179, 153, 125, 107, 125, 141, 179, 153, 125, 140, - 139, 182, 182, 152, 136, 152, 136, 153, 136, 139, 111, 136, 139, 111, - // coeff_abs_level_greater1_flag - 140, 92, 137, 138, 140, 152, 138, 139, 153, 74, 149, 92, 139, 107, - 122, 152, 140, 179, 166, 182, 140, 227, 122, 197, - // coeff_abs_level_greater2_flag - 138, 153, 136, 167, 152, 152, - }, - { - // sao_merge_flag - 153, - // sao_type_idx - 185, - // split_coding_unit_flag - 107, 139, 126, - // cu_transquant_bypass_flag - 154, - // skip_flag - 197, 185, 201, - // cu_qp_delta - 154, 154, 154, - // pred_mode - 149, - // part_mode - 154, 139, 154, 154, - // prev_intra_luma_pred_mode - 154, - // intra_chroma_pred_mode - 152, 139, - // merge_flag - 110, - // merge_idx - 122, - // inter_pred_idc - 95, 79, 63, 31, 31, - // ref_idx_l0 - 153, 153, - // ref_idx_l1 - 153, 153, - // abs_mvd_greater1_flag - 140, 198, - // abs_mvd_greater1_flag - 140, 198, - // mvp_lx_flag - 168, - // no_residual_data_flag - 79, - // split_transform_flag - 124, 138, 94, - // cbf_luma - 153, 111, - // cbf_cb, cbf_cr - 149, 107, 167, 154, - // transform_skip_flag - 139, 139, - // last_significant_coeff_x_prefix - 125, 110, 94, 110, 95, 79, 125, 111, 110, 78, 110, 111, 111, 95, - 94, 108, 123, 108, - // last_significant_coeff_y_prefix - 125, 110, 94, 110, 95, 79, 125, 111, 110, 78, 110, 111, 111, 95, - 94, 108, 123, 108, - // significant_coeff_group_flag - 121, 140, 61, 154, - // significant_coeff_flag - 155, 154, 139, 153, 139, 123, 123, 63, 153, 166, 183, 140, 136, 153, - 154, 166, 183, 140, 136, 153, 154, 166, 183, 140, 136, 153, 154, 170, - 153, 123, 123, 107, 121, 107, 121, 167, 151, 183, 140, 151, 183, 140, - // coeff_abs_level_greater1_flag - 154, 196, 196, 167, 154, 152, 167, 182, 182, 134, 149, 136, 153, 121, - 136, 137, 169, 194, 166, 167, 154, 167, 137, 182, - // coeff_abs_level_greater2_flag - 107, 167, 91, 122, 107, 167, - }, - { - // sao_merge_flag - 153, - // sao_type_idx - 160, - // split_coding_unit_flag - 107, 139, 126, - // cu_transquant_bypass_flag - 154, - // skip_flag - 197, 185, 201, - // cu_qp_delta - 154, 154, 154, - // pred_mode - 134, - // part_mode - 154, 139, 154, 154, - // prev_intra_luma_pred_mode - 183, - // intra_chroma_pred_mode - 152, 139, - // merge_flag - 154, - // merge_idx - 137, - // inter_pred_idc - 95, 79, 63, 31, 31, - // ref_idx_l0 - 153, 153, - // ref_idx_l1 - 153, 153, - // abs_mvd_greater1_flag - 169, 198, - // abs_mvd_greater1_flag - 169, 198, - // mvp_lx_flag - 168, - // no_residual_data_flag - 79, - // split_transform_flag - 224, 167, 122, - // cbf_luma - 153, 111, - // cbf_cb, cbf_cr - 149, 92, 167, 154, - // transform_skip_flag - 139, 139, - // last_significant_coeff_x_prefix - 125, 110, 124, 110, 95, 94, 125, 111, 111, 79, 125, 126, 111, 111, - 79, 108, 123, 93, - // last_significant_coeff_y_prefix - 125, 110, 124, 110, 95, 94, 125, 111, 111, 79, 125, 126, 111, 111, - 79, 108, 123, 93, - // significant_coeff_group_flag - 121, 140, 61, 154, - // significant_coeff_flag - 170, 154, 139, 153, 139, 123, 123, 63, 124, 166, 183, 140, 136, 153, - 154, 166, 183, 140, 136, 153, 154, 166, 183, 140, 136, 153, 154, 170, - 153, 138, 138, 122, 121, 122, 121, 167, 151, 183, 140, 151, 183, 140, - // coeff_abs_level_greater1_flag - 154, 196, 167, 167, 154, 152, 167, 182, 182, 134, 149, 136, 153, 121, - 136, 122, 169, 208, 166, 167, 154, 152, 167, 182, - // coeff_abs_level_greater2_flag - 107, 167, 91, 107, 107, 167, + { // sao_merge_flag + 153, + // sao_type_idx + 200, + // split_coding_unit_flag + 139, 141, 157, + // cu_transquant_bypass_flag + 154, + // skip_flag + CNU, CNU, CNU, + // cu_qp_delta + 154, 154, 154, + // pred_mode + CNU, + // part_mode + 184, CNU, CNU, CNU, + // prev_intra_luma_pred_mode + 184, + // intra_chroma_pred_mode + 63, 139, + // merge_flag + CNU, + // merge_idx + CNU, + // inter_pred_idc + CNU, CNU, CNU, CNU, CNU, + // ref_idx_l0 + CNU, CNU, + // ref_idx_l1 + CNU, CNU, + // abs_mvd_greater1_flag + CNU, CNU, + // abs_mvd_greater1_flag + CNU, CNU, + // mvp_lx_flag + CNU, + // no_residual_data_flag + CNU, + // split_transform_flag + 153, 138, 138, + // cbf_luma + 111, 141, + // cbf_cb, cbf_cr + 94, 138, 182, 154, + // transform_skip_flag + 139, 139, + // last_significant_coeff_x_prefix + 110, 110, 124, 125, 140, 153, 125, 127, 140, 109, 111, 143, 127, 111, + 79, 108, 123, 63, + // last_significant_coeff_y_prefix + 110, 110, 124, 125, 140, 153, 125, 127, 140, 109, 111, 143, 127, 111, + 79, 108, 123, 63, + // significant_coeff_group_flag + 91, 171, 134, 141, + // significant_coeff_flag + 111, 111, 125, 110, 110, 94, 124, 108, 124, 107, 125, 141, 179, 153, + 125, 107, 125, 141, 179, 153, 125, 107, 125, 141, 179, 153, 125, 140, + 139, 182, 182, 152, 136, 152, 136, 153, 136, 139, 111, 136, 139, 111, + // coeff_abs_level_greater1_flag + 140, 92, 137, 138, 140, 152, 138, 139, 153, 74, 149, 92, 139, 107, + 122, 152, 140, 179, 166, 182, 140, 227, 122, 197, + // coeff_abs_level_greater2_flag + 138, 153, 136, 167, 152, 152, }, + { // sao_merge_flag + 153, + // sao_type_idx + 185, + // split_coding_unit_flag + 107, 139, 126, + // cu_transquant_bypass_flag + 154, + // skip_flag + 197, 185, 201, + // cu_qp_delta + 154, 154, 154, + // pred_mode + 149, + // part_mode + 154, 139, 154, 154, + // prev_intra_luma_pred_mode + 154, + // intra_chroma_pred_mode + 152, 139, + // merge_flag + 110, + // merge_idx + 122, + // inter_pred_idc + 95, 79, 63, 31, 31, + // ref_idx_l0 + 153, 153, + // ref_idx_l1 + 153, 153, + // abs_mvd_greater1_flag + 140, 198, + // abs_mvd_greater1_flag + 140, 198, + // mvp_lx_flag + 168, + // no_residual_data_flag + 79, + // split_transform_flag + 124, 138, 94, + // cbf_luma + 153, 111, + // cbf_cb, cbf_cr + 149, 107, 167, 154, + // transform_skip_flag + 139, 139, + // last_significant_coeff_x_prefix + 125, 110, 94, 110, 95, 79, 125, 111, 110, 78, 110, 111, 111, 95, + 94, 108, 123, 108, + // last_significant_coeff_y_prefix + 125, 110, 94, 110, 95, 79, 125, 111, 110, 78, 110, 111, 111, 95, + 94, 108, 123, 108, + // significant_coeff_group_flag + 121, 140, 61, 154, + // significant_coeff_flag + 155, 154, 139, 153, 139, 123, 123, 63, 153, 166, 183, 140, 136, 153, + 154, 166, 183, 140, 136, 153, 154, 166, 183, 140, 136, 153, 154, 170, + 153, 123, 123, 107, 121, 107, 121, 167, 151, 183, 140, 151, 183, 140, + // coeff_abs_level_greater1_flag + 154, 196, 196, 167, 154, 152, 167, 182, 182, 134, 149, 136, 153, 121, + 136, 137, 169, 194, 166, 167, 154, 167, 137, 182, + // coeff_abs_level_greater2_flag + 107, 167, 91, 122, 107, 167, }, + { // sao_merge_flag + 153, + // sao_type_idx + 160, + // split_coding_unit_flag + 107, 139, 126, + // cu_transquant_bypass_flag + 154, + // skip_flag + 197, 185, 201, + // cu_qp_delta + 154, 154, 154, + // pred_mode + 134, + // part_mode + 154, 139, 154, 154, + // prev_intra_luma_pred_mode + 183, + // intra_chroma_pred_mode + 152, 139, + // merge_flag + 154, + // merge_idx + 137, + // inter_pred_idc + 95, 79, 63, 31, 31, + // ref_idx_l0 + 153, 153, + // ref_idx_l1 + 153, 153, + // abs_mvd_greater1_flag + 169, 198, + // abs_mvd_greater1_flag + 169, 198, + // mvp_lx_flag + 168, + // no_residual_data_flag + 79, + // split_transform_flag + 224, 167, 122, + // cbf_luma + 153, 111, + // cbf_cb, cbf_cr + 149, 92, 167, 154, + // transform_skip_flag + 139, 139, + // last_significant_coeff_x_prefix + 125, 110, 124, 110, 95, 94, 125, 111, 111, 79, 125, 126, 111, 111, + 79, 108, 123, 93, + // last_significant_coeff_y_prefix + 125, 110, 124, 110, 95, 94, 125, 111, 111, 79, 125, 126, 111, 111, + 79, 108, 123, 93, + // significant_coeff_group_flag + 121, 140, 61, 154, + // significant_coeff_flag + 170, 154, 139, 153, 139, 123, 123, 63, 124, 166, 183, 140, 136, 153, + 154, 166, 183, 140, 136, 153, 154, 166, 183, 140, 136, 153, 154, 170, + 153, 138, 138, 122, 121, 122, 121, 167, 151, 183, 140, 151, 183, 140, + // coeff_abs_level_greater1_flag + 154, 196, 167, 167, 154, 152, 167, 182, 182, 134, 149, 136, 153, 121, + 136, 122, 169, 208, 166, 167, 154, 152, 167, 182, + // coeff_abs_level_greater2_flag + 107, 167, 91, 107, 107, 167, }, }; @@ -548,7 +543,7 @@ static void cabac_init_state(HEVCContext *s) pre ^= pre >> 31; if (pre > 124) pre = 124 + (pre & 1); - s->HEVClc->cabac_state[i] = pre; + s->HEVClc->cabac_state[i] = pre; } } @@ -561,7 +556,8 @@ void ff_hevc_cabac_init(HEVCContext *s, int ctb_addr_ts) (s->pps->tile_id[ctb_addr_ts] != s->pps->tile_id[ctb_addr_ts - 1]))) cabac_init_state(s); - if (!s->sh.first_slice_in_pic_flag && s->pps->entropy_coding_sync_enabled_flag) { + if (!s->sh.first_slice_in_pic_flag && + s->pps->entropy_coding_sync_enabled_flag) { if ((ctb_addr_ts % s->sps->ctb_width) == 0) { if (s->sps->ctb_width == 1) cabac_init_state(s); @@ -640,7 +636,7 @@ int ff_hevc_sao_offset_sign_decode(HEVCContext *s) int ff_hevc_sao_eo_class_decode(HEVCContext *s) { int ret = (get_cabac_bypass(&s->HEVClc->cc) << 1); - ret |= get_cabac_bypass(&s->HEVClc->cc); + ret |= get_cabac_bypass(&s->HEVClc->cc); return ret; } @@ -662,9 +658,9 @@ int ff_hevc_skip_flag_decode(HEVCContext *s, int x0, int y0, int x_cb, int y_cb) int y0b = y0 & ((1 << s->sps->log2_ctb_size) - 1); if (s->HEVClc->ctb_left_flag || x0b) - inc = !!SAMPLE_CTB(s->skip_flag, x_cb-1, y_cb); + inc = !!SAMPLE_CTB(s->skip_flag, x_cb - 1, y_cb); if (s->HEVClc->ctb_up_flag || y0b) - inc += !!SAMPLE_CTB(s->skip_flag, x_cb, y_cb-1); + inc += !!SAMPLE_CTB(s->skip_flag, x_cb, y_cb - 1); return GET_CABAC(elem_offset[SKIP_FLAG] + inc); } @@ -707,18 +703,19 @@ int ff_hevc_pred_mode_decode(HEVCContext *s) int ff_hevc_split_coding_unit_flag_decode(HEVCContext *s, int ct_depth, int x0, int y0) { int inc = 0, depth_left = 0, depth_top = 0; - int x0b = x0 & ((1 << s->sps->log2_ctb_size) - 1); - int y0b = y0 & ((1 << s->sps->log2_ctb_size) - 1); + int x0b = x0 & ((1 << s->sps->log2_ctb_size) - 1); + int y0b = y0 & ((1 << s->sps->log2_ctb_size) - 1); int x_cb = x0 >> s->sps->log2_min_cb_size; int y_cb = y0 >> s->sps->log2_min_cb_size; if (s->HEVClc->ctb_left_flag || x0b) - depth_left = s->tab_ct_depth[(y_cb)*s->sps->min_cb_width + x_cb-1]; + depth_left = s->tab_ct_depth[(y_cb) * s->sps->min_cb_width + x_cb - 1]; if (s->HEVClc->ctb_up_flag || y0b) - depth_top = s->tab_ct_depth[(y_cb-1)*s->sps->min_cb_width + x_cb]; + depth_top = s->tab_ct_depth[(y_cb - 1) * s->sps->min_cb_width + x_cb]; inc += (depth_left > ct_depth); - inc += (depth_top > ct_depth); + inc += (depth_top > ct_depth); + return GET_CABAC(elem_offset[SPLIT_CODING_UNIT_FLAG] + inc); } @@ -756,7 +753,7 @@ int ff_hevc_part_mode_decode(HEVCContext *s, int log2_cb_size) return PART_Nx2N; if (get_cabac_bypass(&s->HEVClc->cc)) // 0001 return PART_nRx2N; - return PART_nLx2N; // 0000 + return PART_nLx2N; // 0000 } int ff_hevc_pcm_flag_decode(HEVCContext *s) @@ -794,7 +791,7 @@ int ff_hevc_intra_chroma_pred_mode_decode(HEVCContext *s) return 4; ret = (get_cabac_bypass(&s->HEVClc->cc) << 1); - ret |= get_cabac_bypass(&s->HEVClc->cc); + ret |= get_cabac_bypass(&s->HEVClc->cc); return ret; } diff --git a/libavcodec/hevc_filter.c b/libavcodec/hevc_filter.c index 0a6d7c9fb5..a2b4f68a62 100644 --- a/libavcodec/hevc_filter.c +++ b/libavcodec/hevc_filter.c @@ -35,20 +35,22 @@ #define CR 2 static const uint8_t tctable[54] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, // QP 0...18 - 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, // QP 19...37 - 5, 5, 6, 6, 7, 8, 9,10,11,13,14,16,18,20,22,24 // QP 38...53 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, // QP 0...18 + 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, // QP 19...37 + 5, 5, 6, 6, 7, 8, 9, 10, 11, 13, 14, 16, 18, 20, 22, 24 // QP 38...53 }; static const uint8_t betatable[52] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 8, // QP 0...18 - 9,10,11,12,13,14,15,16,17,18,20,22,24,26,28,30,32,34,36, // QP 19...37 - 38,40,42,44,46,48,50,52,54,56,58,60,62,64 // QP 38...51 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 8, // QP 0...18 + 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, // QP 19...37 + 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64 // QP 38...51 }; static int chroma_tc(HEVCContext *s, int qp_y, int c_idx, int tc_offset) { - static const int qp_c[] = { 29, 30, 31, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37 }; + static const int qp_c[] = { + 29, 30, 31, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37 + }; int qp_i, offset; int qp; int idxt; @@ -71,19 +73,23 @@ static int chroma_tc(HEVCContext *s, int qp_y, int c_idx, int tc_offset) return tctable[idxt]; } -static int get_qPy_pred(HEVCContext *s, int xC, int yC, int xBase, int yBase, int log2_cb_size) +static int get_qPy_pred(HEVCContext *s, int xC, int yC, + int xBase, int yBase, int log2_cb_size) { HEVCLocalContext *lc = s->HEVClc; int ctb_size_mask = (1 << s->sps->log2_ctb_size) - 1; - int MinCuQpDeltaSizeMask = (1 << (s->sps->log2_ctb_size - s->pps->diff_cu_qp_delta_depth)) - 1; - int xQgBase = xBase - ( xBase & MinCuQpDeltaSizeMask ); - int yQgBase = yBase - ( yBase & MinCuQpDeltaSizeMask ); + int MinCuQpDeltaSizeMask = (1 << (s->sps->log2_ctb_size - + s->pps->diff_cu_qp_delta_depth)) - 1; + int xQgBase = xBase - (xBase & MinCuQpDeltaSizeMask); + int yQgBase = yBase - (yBase & MinCuQpDeltaSizeMask); int min_cb_width = s->sps->min_cb_width; int min_cb_height = s->sps->min_cb_height; int x_cb = xQgBase >> s->sps->log2_min_cb_size; int y_cb = yQgBase >> s->sps->log2_min_cb_size; - int availableA = (xBase & ctb_size_mask) && (xQgBase & ctb_size_mask); - int availableB = (yBase & ctb_size_mask) && (yQgBase & ctb_size_mask); + int availableA = (xBase & ctb_size_mask) && + (xQgBase & ctb_size_mask); + int availableB = (yBase & ctb_size_mask) && + (yQgBase & ctb_size_mask); int qPy_pred; int qPy_a; int qPy_b; @@ -94,31 +100,32 @@ static int get_qPy_pred(HEVCContext *s, int xC, int yC, int xBase, int yBase, in qPy_pred = s->sh.slice_qp; } else { qPy_pred = lc->qp_y; - if (log2_cb_size < s->sps->log2_ctb_size - s->pps->diff_cu_qp_delta_depth) { + if (log2_cb_size < s->sps->log2_ctb_size - + s->pps->diff_cu_qp_delta_depth) { static const int offsetX[8][8] = { - {-1, 1, 3, 1, 7, 1, 3, 1}, - { 0, 0, 0, 0, 0, 0, 0, 0}, - { 1, 3, 1, 3, 1, 3, 1, 3}, - { 2, 2, 2, 2, 2, 2, 2, 2}, - { 3, 5, 7, 5, 3, 5, 7, 5}, - { 4, 4, 4, 4, 4, 4, 4, 4}, - { 5, 7, 5, 7, 5, 7, 5, 7}, - { 6, 6, 6, 6, 6, 6, 6, 6} + { -1, 1, 3, 1, 7, 1, 3, 1 }, + { 0, 0, 0, 0, 0, 0, 0, 0 }, + { 1, 3, 1, 3, 1, 3, 1, 3 }, + { 2, 2, 2, 2, 2, 2, 2, 2 }, + { 3, 5, 7, 5, 3, 5, 7, 5 }, + { 4, 4, 4, 4, 4, 4, 4, 4 }, + { 5, 7, 5, 7, 5, 7, 5, 7 }, + { 6, 6, 6, 6, 6, 6, 6, 6 } }; static const int offsetY[8][8] = { - { 7, 0, 1, 2, 3, 4, 5, 6}, - { 0, 1, 2, 3, 4, 5, 6, 7}, - { 1, 0, 3, 2, 5, 4, 7, 6}, - { 0, 1, 2, 3, 4, 5, 6, 7}, - { 3, 0, 1, 2, 7, 4, 5, 6}, - { 0, 1, 2, 3, 4, 5, 6, 7}, - { 1, 0, 3, 2, 5, 4, 7, 6}, - { 0, 1, 2, 3, 4, 5, 6, 7} + { 7, 0, 1, 2, 3, 4, 5, 6 }, + { 0, 1, 2, 3, 4, 5, 6, 7 }, + { 1, 0, 3, 2, 5, 4, 7, 6 }, + { 0, 1, 2, 3, 4, 5, 6, 7 }, + { 3, 0, 1, 2, 7, 4, 5, 6 }, + { 0, 1, 2, 3, 4, 5, 6, 7 }, + { 1, 0, 3, 2, 5, 4, 7, 6 }, + { 0, 1, 2, 3, 4, 5, 6, 7 } }; int xC0b = (xC - (xC & ctb_size_mask)) >> s->sps->log2_min_cb_size; int yC0b = (yC - (yC & ctb_size_mask)) >> s->sps->log2_min_cb_size; - int idxX = (xQgBase & ctb_size_mask) >> s->sps->log2_min_cb_size; - int idxY = (yQgBase & ctb_size_mask) >> s->sps->log2_min_cb_size; + int idxX = (xQgBase & ctb_size_mask) >> s->sps->log2_min_cb_size; + int idxY = (yQgBase & ctb_size_mask) >> s->sps->log2_min_cb_size; int idx_mask = ctb_size_mask >> s->sps->log2_min_cb_size; int x, y; @@ -149,13 +156,15 @@ static int get_qPy_pred(HEVCContext *s, int xC, int yC, int xBase, int yBase, in return (qPy_a + qPy_b + 1) >> 1; } -void ff_hevc_set_qPy(HEVCContext *s, int xC, int yC, int xBase, int yBase, int log2_cb_size) +void ff_hevc_set_qPy(HEVCContext *s, int xC, int yC, + int xBase, int yBase, int log2_cb_size) { int qp_y = get_qPy_pred(s, xC, yC, xBase, yBase, log2_cb_size); if (s->HEVClc->tu.cu_qp_delta != 0) { int off = s->sps->qp_bd_offset; - s->HEVClc->qp_y = ((qp_y + s->HEVClc->tu.cu_qp_delta + 52 + 2 * off) % (52 + off)) - off; + s->HEVClc->qp_y = ((qp_y + s->HEVClc->tu.cu_qp_delta + 52 + 2 * off) % + (52 + off)) - off; } else s->HEVClc->qp_y = qp_y; } @@ -168,11 +177,12 @@ static int get_qPy(HEVCContext *s, int xC, int yC) return s->qp_y_tab[x + y * s->sps->min_cb_width]; } -static void copy_CTB(uint8_t *dst, uint8_t *src, int width, int height, int stride) +static void copy_CTB(uint8_t *dst, uint8_t *src, + int width, int height, int stride) { int i; - for(i=0; i< height; i++){ + for (i = 0; i < height; i++) { memcpy(dst, src, width); dst += stride; src += stride; @@ -187,28 +197,29 @@ static void sao_filter_CTB(HEVCContext *s, int x, int y) // TODO: skip CBs when (cu_transquant_bypass_flag || (pcm_loop_filter_disable_flag && pcm_flag)) int c_idx = 0; int class = 1, class_index; - int edges[4]; // 0 left 1 top 2 right 3 bottom + int edges[4]; // 0 left 1 top 2 right 3 bottom SAOParams *sao[4]; int classes[4]; int x_shift = 0, y_shift = 0; - int x_ctb = x>>s->sps->log2_ctb_size; - int y_ctb = y>>s->sps->log2_ctb_size; + int x_ctb = x >> s->sps->log2_ctb_size; + int y_ctb = y >> s->sps->log2_ctb_size; int ctb_addr_rs = y_ctb * s->sps->ctb_width + x_ctb; int ctb_addr_ts = s->pps->ctb_addr_rs_to_ts[ctb_addr_rs]; // flags indicating unfilterable edges - uint8_t vert_edge[] = {0,0,0,0}; - uint8_t horiz_edge[] = {0,0,0,0}; - uint8_t diag_edge[] = {0,0,0,0}; + uint8_t vert_edge[] = { 0, 0, 0, 0 }; + uint8_t horiz_edge[] = { 0, 0, 0, 0 }; + uint8_t diag_edge[] = { 0, 0, 0, 0 }; uint8_t lfase[3]; // current, above, left - uint8_t no_tile_filter = s->pps->tiles_enabled_flag && !s->pps->loop_filter_across_tiles_enabled_flag; + uint8_t no_tile_filter = s->pps->tiles_enabled_flag && + !s->pps->loop_filter_across_tiles_enabled_flag; uint8_t left_tile_edge = 0; uint8_t up_tile_edge = 0; sao[0] = &CTB(s->sao, x_ctb, y_ctb); edges[0] = x_ctb == 0; edges[1] = y_ctb == 0; - edges[2] = x_ctb == (s->sps->ctb_width - 1); + edges[2] = x_ctb == (s->sps->ctb_width - 1); edges[3] = y_ctb == (s->sps->ctb_height - 1); lfase[0] = CTB(s->filter_slice_edges, x_ctb, y_ctb); classes[0] = 0; @@ -249,10 +260,12 @@ static void sao_filter_CTB(HEVCContext *s, int x, int y) diag_edge[3] = diag_edge[0]; // Does left CTB comes after above CTB? - if(CTB(s->tab_slice_address, x_ctb - 1, y_ctb) > CTB(s->tab_slice_address, x_ctb, y_ctb - 1)) { + if (CTB(s->tab_slice_address, x_ctb - 1, y_ctb) > + CTB(s->tab_slice_address, x_ctb, y_ctb - 1)) { diag_edge[2] = !lfase[2] || left_tile_edge || up_tile_edge; diag_edge[1] = diag_edge[2]; - } else if(CTB(s->tab_slice_address, x_ctb - 1, y_ctb) < CTB(s->tab_slice_address, x_ctb, y_ctb - 1)) { + } else if (CTB(s->tab_slice_address, x_ctb - 1, y_ctb) < + CTB(s->tab_slice_address, x_ctb, y_ctb - 1)) { diag_edge[1] = !lfase[1] || left_tile_edge || up_tile_edge; diag_edge[2] = diag_edge[1]; } else { @@ -286,10 +299,21 @@ static void sao_filter_CTB(HEVCContext *s, int x, int y) switch (sao[class_index]->type_idx[c_idx]) { case SAO_BAND: - s->hevcdsp.sao_band_filter[classes[class_index]](dst, src, stride, sao[class_index], edges, width, height, c_idx); - break; + s->hevcdsp.sao_band_filter[classes[class_index]](dst, src, + stride, + sao[class_index], + edges, width, + height, c_idx); + break; case SAO_EDGE: - s->hevcdsp.sao_edge_filter[classes[class_index]](dst, src, stride, sao[class_index], edges, width, height, c_idx, vert_edge[classes[class_index]], horiz_edge[classes[class_index]], diag_edge[classes[class_index]]); + s->hevcdsp.sao_edge_filter[classes[class_index]](dst, src, + stride, + sao[class_index], + edges, width, + height, c_idx, + vert_edge[classes[class_index]], + horiz_edge[classes[class_index]], + diag_edge[classes[class_index]]); break; } } @@ -318,33 +342,35 @@ static void deblocking_filter_CTB(HEVCContext *s, int x0, int y0) int c_tc[2]; int beta[2]; int tc[2]; - uint8_t no_p[2] = {0}; - uint8_t no_q[2] = {0}; + uint8_t no_p[2] = { 0 }; + uint8_t no_q[2] = { 0 }; - int log2_ctb_size = s->sps->log2_ctb_size; + int log2_ctb_size = s->sps->log2_ctb_size; int x_end, y_end; - int ctb_size = 1<> log2_ctb_size) + (y0 >> log2_ctb_size) * s->sps->ctb_width; + int ctb_size = 1 << log2_ctb_size; + int ctb = (x0 >> log2_ctb_size) + + (y0 >> log2_ctb_size) * s->sps->ctb_width; int cur_tc_offset = s->deblock[ctb].tc_offset; int cur_beta_offset = s->deblock[ctb].beta_offset; int left_tc_offset, left_beta_offset; int tc_offset, beta_offset; - int pcmf = (s->sps->pcm_enabled_flag && s->sps->pcm.loop_filter_disable_flag) || - s->pps->transquant_bypass_enable_flag; + int pcmf = (s->sps->pcm_enabled_flag && + s->sps->pcm.loop_filter_disable_flag) || + s->pps->transquant_bypass_enable_flag; if (x0) { - left_tc_offset = s->deblock[ctb-1].tc_offset; - left_beta_offset = s->deblock[ctb-1].beta_offset; + left_tc_offset = s->deblock[ctb - 1].tc_offset; + left_beta_offset = s->deblock[ctb - 1].beta_offset; } - x_end = x0+ctb_size; + x_end = x0 + ctb_size; if (x_end > s->sps->width) x_end = s->sps->width; - y_end = y0+ctb_size; + y_end = y0 + ctb_size; if (y_end > s->sps->height) y_end = s->sps->height; - tc_offset = cur_tc_offset; + tc_offset = cur_tc_offset; beta_offset = cur_beta_offset; // vertical filtering luma @@ -353,22 +379,26 @@ static void deblocking_filter_CTB(HEVCContext *s, int x0, int y0) const int bs0 = s->vertical_bs[(x >> 3) + (y >> 2) * s->bs_width]; const int bs1 = s->vertical_bs[(x >> 3) + ((y + 4) >> 2) * s->bs_width]; if (bs0 || bs1) { - const int qp0 = (get_qPy(s, x - 1, y) + get_qPy(s, x, y) + 1) >> 1; + const int qp0 = (get_qPy(s, x - 1, y) + get_qPy(s, x, y) + 1) >> 1; const int qp1 = (get_qPy(s, x - 1, y + 4) + get_qPy(s, x, y + 4) + 1) >> 1; beta[0] = betatable[av_clip(qp0 + ((beta_offset >> 1) << 1), 0, MAX_QP)]; beta[1] = betatable[av_clip(qp1 + ((beta_offset >> 1) << 1), 0, MAX_QP)]; - tc[0] = bs0 ? TC_CALC(qp0, bs0) : 0; - tc[1] = bs1 ? TC_CALC(qp1, bs1) : 0; - src = &s->frame->data[LUMA][y * s->frame->linesize[LUMA] + (x << s->sps->pixel_shift)]; + tc[0] = bs0 ? TC_CALC(qp0, bs0) : 0; + tc[1] = bs1 ? TC_CALC(qp1, bs1) : 0; + src = &s->frame->data[LUMA][y * s->frame->linesize[LUMA] + (x << s->sps->pixel_shift)]; if (pcmf) { no_p[0] = get_pcm(s, x - 1, y); no_p[1] = get_pcm(s, x - 1, y + 4); no_q[0] = get_pcm(s, x, y); no_q[1] = get_pcm(s, x, y + 4); - s->hevcdsp.hevc_v_loop_filter_luma_c(src, s->frame->linesize[LUMA], beta, tc, no_p, no_q); + s->hevcdsp.hevc_v_loop_filter_luma_c(src, + s->frame->linesize[LUMA], + beta, tc, no_p, no_q); } else - s->hevcdsp.hevc_v_loop_filter_luma(src, s->frame->linesize[LUMA], beta, tc, no_p, no_q); + s->hevcdsp.hevc_v_loop_filter_luma(src, + s->frame->linesize[LUMA], + beta, tc, no_p, no_q); } } } @@ -376,24 +406,28 @@ static void deblocking_filter_CTB(HEVCContext *s, int x0, int y0) // vertical filtering chroma for (chroma = 1; chroma <= 2; chroma++) { for (y = y0; y < y_end; y += 16) { - for (x = x0 ? x0:16; x < x_end; x += 16) { - const int bs0 = s->vertical_bs[(x >> 3) + (y >> 2) * s->bs_width]; + for (x = x0 ? x0 : 16; x < x_end; x += 16) { + const int bs0 = s->vertical_bs[(x >> 3) + (y >> 2) * s->bs_width]; const int bs1 = s->vertical_bs[(x >> 3) + ((y + 8) >> 2) * s->bs_width]; if ((bs0 == 2) || (bs1 == 2)) { - const int qp0 = (get_qPy(s, x - 1, y) + get_qPy(s, x, y) + 1) >> 1; + const int qp0 = (get_qPy(s, x - 1, y) + get_qPy(s, x, y) + 1) >> 1; const int qp1 = (get_qPy(s, x - 1, y + 8) + get_qPy(s, x, y + 8) + 1) >> 1; c_tc[0] = (bs0 == 2) ? chroma_tc(s, qp0, chroma, tc_offset) : 0; c_tc[1] = (bs1 == 2) ? chroma_tc(s, qp1, chroma, tc_offset) : 0; - src = &s->frame->data[chroma][(y / 2) * s->frame->linesize[chroma] + ((x / 2) << s->sps->pixel_shift)]; + src = &s->frame->data[chroma][(y / 2) * s->frame->linesize[chroma] + ((x / 2) << s->sps->pixel_shift)]; if (pcmf) { no_p[0] = get_pcm(s, x - 1, y); no_p[1] = get_pcm(s, x - 1, y + 8); no_q[0] = get_pcm(s, x, y); no_q[1] = get_pcm(s, x, y + 8); - s->hevcdsp.hevc_v_loop_filter_chroma_c(src, s->frame->linesize[chroma], c_tc, no_p, no_q); + s->hevcdsp.hevc_v_loop_filter_chroma_c(src, + s->frame->linesize[chroma], + c_tc, no_p, no_q); } else - s->hevcdsp.hevc_v_loop_filter_chroma(src, s->frame->linesize[chroma], c_tc, no_p, no_q); + s->hevcdsp.hevc_v_loop_filter_chroma(src, + s->frame->linesize[chroma], + c_tc, no_p, no_q); } } } @@ -410,22 +444,26 @@ static void deblocking_filter_CTB(HEVCContext *s, int x0, int y0) const int qp0 = (get_qPy(s, x, y - 1) + get_qPy(s, x, y) + 1) >> 1; const int qp1 = (get_qPy(s, x + 4, y - 1) + get_qPy(s, x + 4, y) + 1) >> 1; - tc_offset = x >= x0 ? cur_tc_offset : left_tc_offset; + tc_offset = x >= x0 ? cur_tc_offset : left_tc_offset; beta_offset = x >= x0 ? cur_beta_offset : left_beta_offset; - beta[0] = betatable[av_clip(qp0 + ((beta_offset >> 1) << 1), 0, MAX_QP)]; - beta[1] = betatable[av_clip(qp1 + ((beta_offset >> 1) << 1), 0, MAX_QP)]; - tc[0] = bs0 ? TC_CALC(qp0, bs0) : 0; - tc[1] = bs1 ? TC_CALC(qp1, bs1) : 0; - src = &s->frame->data[LUMA][y * s->frame->linesize[LUMA] + (x << s->sps->pixel_shift)]; + beta[0] = betatable[av_clip(qp0 + ((beta_offset >> 1) << 1), 0, MAX_QP)]; + beta[1] = betatable[av_clip(qp1 + ((beta_offset >> 1) << 1), 0, MAX_QP)]; + tc[0] = bs0 ? TC_CALC(qp0, bs0) : 0; + tc[1] = bs1 ? TC_CALC(qp1, bs1) : 0; + src = &s->frame->data[LUMA][y * s->frame->linesize[LUMA] + (x << s->sps->pixel_shift)]; if (pcmf) { no_p[0] = get_pcm(s, x, y - 1); no_p[1] = get_pcm(s, x + 4, y - 1); no_q[0] = get_pcm(s, x, y); no_q[1] = get_pcm(s, x + 4, y); - s->hevcdsp.hevc_h_loop_filter_luma_c(src, s->frame->linesize[LUMA], beta, tc, no_p, no_q); + s->hevcdsp.hevc_h_loop_filter_luma_c(src, + s->frame->linesize[LUMA], + beta, tc, no_p, no_q); } else - s->hevcdsp.hevc_h_loop_filter_luma(src, s->frame->linesize[LUMA], beta, tc, no_p, no_q); + s->hevcdsp.hevc_h_loop_filter_luma(src, + s->frame->linesize[LUMA], + beta, tc, no_p, no_q); } } } @@ -441,29 +479,33 @@ static void deblocking_filter_CTB(HEVCContext *s, int x0, int y0) bs0 = 0; bs1 = s->horizontal_bs[(x + 8 + y * s->bs_width) >> 2]; } else if (x >= x_end - 8) { - bs0 = s->horizontal_bs[(x + y * s->bs_width) >> 2]; + bs0 = s->horizontal_bs[(x + y * s->bs_width) >> 2]; bs1 = 0; } else { - bs0 = s->horizontal_bs[(x + y * s->bs_width) >> 2]; + bs0 = s->horizontal_bs[(x + y * s->bs_width) >> 2]; bs1 = s->horizontal_bs[(x + 8 + y * s->bs_width) >> 2]; } if ((bs0 == 2) || (bs1 == 2)) { - const int qp0 = (bs0 == 2) ? ((get_qPy(s, x, y - 1) + get_qPy(s, x, y) + 1) >> 1) : 0; + const int qp0 = (bs0 == 2) ? ((get_qPy(s, x, y - 1) + get_qPy(s, x, y) + 1) >> 1) : 0; const int qp1 = (bs1 == 2) ? ((get_qPy(s, x + 8, y - 1) + get_qPy(s, x + 8, y) + 1) >> 1) : 0; tc_offset = x >= x0 ? cur_tc_offset : left_tc_offset; - c_tc[0] = (bs0 == 2) ? chroma_tc(s, qp0, chroma, tc_offset) : 0; + c_tc[0] = (bs0 == 2) ? chroma_tc(s, qp0, chroma, tc_offset) : 0; c_tc[1] = (bs1 == 2) ? chroma_tc(s, qp1, chroma, cur_tc_offset) : 0; - src = &s->frame->data[chroma][(y / 2) * s->frame->linesize[chroma] + ((x / 2) << s->sps->pixel_shift)]; + src = &s->frame->data[chroma][(y / 2) * s->frame->linesize[chroma] + ((x / 2) << s->sps->pixel_shift)]; if (pcmf) { no_p[0] = get_pcm(s, x, y - 1); no_p[1] = get_pcm(s, x + 8, y - 1); no_q[0] = get_pcm(s, x, y); no_q[1] = get_pcm(s, x + 8, y); - s->hevcdsp.hevc_h_loop_filter_chroma_c(src, s->frame->linesize[chroma], c_tc, no_p, no_q); + s->hevcdsp.hevc_h_loop_filter_chroma_c(src, + s->frame->linesize[chroma], + c_tc, no_p, no_q); } else - s->hevcdsp.hevc_h_loop_filter_chroma(src, s->frame->linesize[chroma], c_tc, no_p, no_q); + s->hevcdsp.hevc_h_loop_filter_chroma(src, + s->frame->linesize[chroma], + c_tc, no_p, no_q); } } } @@ -472,7 +514,8 @@ static void deblocking_filter_CTB(HEVCContext *s, int x0, int y0) static int boundary_strength(HEVCContext *s, MvField *curr, uint8_t curr_cbf_luma, MvField *neigh, - uint8_t neigh_cbf_luma, RefPicList *neigh_refPicList, + uint8_t neigh_cbf_luma, + RefPicList *neigh_refPicList, int tu_border) { int mvs = curr->pred_flag[0] + curr->pred_flag[1]; @@ -487,7 +530,7 @@ static int boundary_strength(HEVCContext *s, MvField *curr, if (mvs == neigh->pred_flag[0] + neigh->pred_flag[1]) { if (mvs == 2) { // same L0 and L1 - if (s->ref->refPicList[0].list[curr->ref_idx[0]] == neigh_refPicList[0].list[neigh->ref_idx[0]] && + if (s->ref->refPicList[0].list[curr->ref_idx[0]] == neigh_refPicList[0].list[neigh->ref_idx[0]] && s->ref->refPicList[0].list[curr->ref_idx[0]] == s->ref->refPicList[1].list[curr->ref_idx[1]] && neigh_refPicList[0].list[neigh->ref_idx[0]] == neigh_refPicList[1].list[neigh->ref_idx[1]]) { if ((abs(neigh->mv[0].x - curr->mv[0].x) >= 4 || abs(neigh->mv[0].y - curr->mv[0].y) >= 4 || @@ -520,18 +563,18 @@ static int boundary_strength(HEVCContext *s, MvField *curr, int ref_B; if (curr->pred_flag[0]) { - A = curr->mv[0]; + A = curr->mv[0]; ref_A = s->ref->refPicList[0].list[curr->ref_idx[0]]; } else { - A = curr->mv[1]; + A = curr->mv[1]; ref_A = s->ref->refPicList[1].list[curr->ref_idx[1]]; } if (neigh->pred_flag[0]) { - B = neigh->mv[0]; + B = neigh->mv[0]; ref_B = neigh_refPicList[0].list[neigh->ref_idx[0]]; } else { - B = neigh->mv[1]; + B = neigh->mv[1]; ref_B = neigh_refPicList[1].list[neigh->ref_idx[1]]; } @@ -548,24 +591,26 @@ static int boundary_strength(HEVCContext *s, MvField *curr, return 1; } -void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0, int log2_trafo_size, - int slice_or_tiles_up_boundary, int slice_or_tiles_left_boundary) +void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0, + int log2_trafo_size, + int slice_or_tiles_up_boundary, + int slice_or_tiles_left_boundary) { MvField *tab_mvf = s->ref->tab_mvf; int log2_min_pu_size = s->sps->log2_min_pu_size; int log2_min_tu_size = s->sps->log2_min_tb_size; int min_pu_width = s->sps->min_pu_width; int min_tu_width = s->sps->min_tb_width; - int is_intra = tab_mvf[(y0 >> log2_min_pu_size) * min_pu_width + (x0 >> log2_min_pu_size)].is_intra; - + int is_intra = tab_mvf[(y0 >> log2_min_pu_size) * min_pu_width + + (x0 >> log2_min_pu_size)].is_intra; int i, j; int bs; if (y0 > 0 && (y0 & 7) == 0) { int yp_pu = (y0 - 1) >> log2_min_pu_size; - int yq_pu = y0 >> log2_min_pu_size; + int yq_pu = y0 >> log2_min_pu_size; int yp_tu = (y0 - 1) >> log2_min_tu_size; - int yq_tu = y0 >> log2_min_tu_size; + int yq_tu = y0 >> log2_min_tu_size; for (i = 0; i < (1 << log2_trafo_size); i += 4) { int x_pu = (x0 + i) >> log2_min_pu_size; @@ -574,12 +619,18 @@ void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0, int l MvField *curr = &tab_mvf[yq_pu * min_pu_width + x_pu]; uint8_t top_cbf_luma = s->cbf_luma[yp_tu * min_tu_width + x_tu]; uint8_t curr_cbf_luma = s->cbf_luma[yq_tu * min_tu_width + x_tu]; - RefPicList* top_refPicList = ff_hevc_get_ref_list(s, s->ref, x0 + i, y0 - 1); - - bs = boundary_strength(s, curr, curr_cbf_luma, top, top_cbf_luma, top_refPicList, 1); - if (!s->sh.slice_loop_filter_across_slices_enabled_flag && (slice_or_tiles_up_boundary & 1) && (y0 % (1 << s->sps->log2_ctb_size)) == 0) + RefPicList *top_refPicList = ff_hevc_get_ref_list(s, s->ref, + x0 + i, y0 - 1); + + bs = boundary_strength(s, curr, curr_cbf_luma, + top, top_cbf_luma, top_refPicList, 1); + if (!s->sh.slice_loop_filter_across_slices_enabled_flag && + (slice_or_tiles_up_boundary & 1) && + (y0 % (1 << s->sps->log2_ctb_size)) == 0) bs = 0; - else if (!s->pps->loop_filter_across_tiles_enabled_flag && (slice_or_tiles_up_boundary & 2) && (y0 % (1 << s->sps->log2_ctb_size)) == 0) + else if (!s->pps->loop_filter_across_tiles_enabled_flag && + (slice_or_tiles_up_boundary & 2) && + (y0 % (1 << s->sps->log2_ctb_size)) == 0) bs = 0; if (y0 == 0 || s->sh.disable_deblocking_filter_flag == 1) bs = 0; @@ -596,17 +647,19 @@ void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0, int l int yp_tu = (y0 + j - 1) >> log2_min_tu_size; int yq_tu = (y0 + j) >> log2_min_tu_size; - - for (i = 0; i < (1<> log2_min_pu_size; int x_tu = (x0 + i) >> log2_min_tu_size; MvField *top = &tab_mvf[yp_pu * min_pu_width + x_pu]; MvField *curr = &tab_mvf[yq_pu * min_pu_width + x_pu]; uint8_t top_cbf_luma = s->cbf_luma[yp_tu * min_tu_width + x_tu]; uint8_t curr_cbf_luma = s->cbf_luma[yq_tu * min_tu_width + x_tu]; - RefPicList* top_refPicList = ff_hevc_get_ref_list(s, s->ref, x0 + i, y0 + j - 1); + RefPicList *top_refPicList = ff_hevc_get_ref_list(s, s->ref, + x0 + i, + y0 + j - 1); - bs = boundary_strength(s, curr, curr_cbf_luma, top, top_cbf_luma, top_refPicList, 0); + bs = boundary_strength(s, curr, curr_cbf_luma, + top, top_cbf_luma, top_refPicList, 0); if (s->sh.disable_deblocking_filter_flag == 1) bs = 0; if (bs) @@ -622,19 +675,25 @@ void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0, int l int xq_tu = x0 >> log2_min_tu_size; for (i = 0; i < (1 << log2_trafo_size); i += 4) { - int y_pu = (y0 + i) >> log2_min_pu_size; - int y_tu = (y0 + i) >> log2_min_tu_size; + int y_pu = (y0 + i) >> log2_min_pu_size; + int y_tu = (y0 + i) >> log2_min_tu_size; MvField *left = &tab_mvf[y_pu * min_pu_width + xp_pu]; MvField *curr = &tab_mvf[y_pu * min_pu_width + xq_pu]; uint8_t left_cbf_luma = s->cbf_luma[y_tu * min_tu_width + xp_tu]; uint8_t curr_cbf_luma = s->cbf_luma[y_tu * min_tu_width + xq_tu]; - RefPicList* left_refPicList = ff_hevc_get_ref_list(s, s->ref, x0 - 1, y0 + i); - - bs = boundary_strength(s, curr, curr_cbf_luma, left, left_cbf_luma, left_refPicList, 1); - if (!s->sh.slice_loop_filter_across_slices_enabled_flag && (slice_or_tiles_left_boundary & 1) && (x0 % (1 << s->sps->log2_ctb_size)) == 0) + RefPicList *left_refPicList = ff_hevc_get_ref_list(s, s->ref, + x0 - 1, y0 + i); + + bs = boundary_strength(s, curr, curr_cbf_luma, + left, left_cbf_luma, left_refPicList, 1); + if (!s->sh.slice_loop_filter_across_slices_enabled_flag && + (slice_or_tiles_left_boundary & 1) && + (x0 % (1 << s->sps->log2_ctb_size)) == 0) bs = 0; - else if (!s->pps->loop_filter_across_tiles_enabled_flag && (slice_or_tiles_left_boundary & 2) && (x0 % (1 << s->sps->log2_ctb_size)) == 0) + else if (!s->pps->loop_filter_across_tiles_enabled_flag && + (slice_or_tiles_left_boundary & 2) && + (x0 % (1 << s->sps->log2_ctb_size)) == 0) bs = 0; if (x0 == 0 || s->sh.disable_deblocking_filter_flag == 1) bs = 0; @@ -651,16 +710,19 @@ void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0, int l for (i = 8; i < (1 << log2_trafo_size); i += 8) { int xp_pu = (x0 + i - 1) >> log2_min_pu_size; - int xq_pu = (x0 + i) >> log2_min_pu_size; + int xq_pu = (x0 + i) >> log2_min_pu_size; int xp_tu = (x0 + i - 1) >> log2_min_tu_size; - int xq_tu = (x0 + i) >> log2_min_tu_size; + int xq_tu = (x0 + i) >> log2_min_tu_size; MvField *left = &tab_mvf[y_pu * min_pu_width + xp_pu]; MvField *curr = &tab_mvf[y_pu * min_pu_width + xq_pu]; uint8_t left_cbf_luma = s->cbf_luma[y_tu * min_tu_width + xp_tu]; uint8_t curr_cbf_luma = s->cbf_luma[y_tu * min_tu_width + xq_tu]; - RefPicList* left_refPicList = ff_hevc_get_ref_list(s, s->ref, x0 + i - 1, y0 + j); + RefPicList *left_refPicList = ff_hevc_get_ref_list(s, s->ref, + x0 + i - 1, + y0 + j); - bs = boundary_strength(s, curr, curr_cbf_luma, left, left_cbf_luma, left_refPicList, 0); + bs = boundary_strength(s, curr, curr_cbf_luma, + left, left_cbf_luma, left_refPicList, 0); if (s->sh.disable_deblocking_filter_flag == 1) bs = 0; if (bs) @@ -668,6 +730,7 @@ void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0, int l } } } + #undef LUMA #undef CB #undef CR diff --git a/libavcodec/hevc_mvs.c b/libavcodec/hevc_mvs.c index d26de514a0..6b3a8da143 100644 --- a/libavcodec/hevc_mvs.c +++ b/libavcodec/hevc_mvs.c @@ -38,7 +38,8 @@ static const uint8_t l0_l1_cand_idx[12][2] = { { 3, 2, }, }; -void ff_hevc_set_neighbour_available(HEVCContext *s, int x0, int y0, int nPbW, int nPbH) +void ff_hevc_set_neighbour_available(HEVCContext *s, int x0, int y0, + int nPbW, int nPbH) { HEVCLocalContext *lc = s->HEVClc; int x0b = x0 & ((1 << s->sps->log2_ctb_size) - 1); @@ -65,8 +66,8 @@ static int z_scan_block_avail(HEVCContext *s, int xCurr, int yCurr, { #define MIN_TB_ADDR_ZS(x, y) \ s->pps->min_tb_addr_zs[(y) * s->sps->min_tb_width + (x)] - int Curr = MIN_TB_ADDR_ZS(xCurr >> s->sps->log2_min_tb_size, - yCurr >> s->sps->log2_min_tb_size); + int Curr = MIN_TB_ADDR_ZS(xCurr >> s->sps->log2_min_tb_size, + yCurr >> s->sps->log2_min_tb_size); int N; if ((xN < 0) || (yN < 0) || @@ -80,7 +81,6 @@ static int z_scan_block_avail(HEVCContext *s, int xCurr, int yCurr, return N <= Curr; } - static int same_prediction_block(HEVCLocalContext *lc, int log2_cb_size, int x0, int y0, int nPbW, int nPbH, int xA1, int yA1, int partIdx) @@ -169,7 +169,7 @@ static int check_mvset(Mv *mvLXCol, Mv *mvCol, cur_poc_diff = poc - refPicList[X].list[refIdxLx]; if (!col_poc_diff) - col_poc_diff = 1; // error resilience + col_poc_diff = 1; // error resilience if (cur_lt || col_poc_diff == cur_poc_diff) { mvLXCol->x = mvCol->x; @@ -180,16 +180,16 @@ static int check_mvset(Mv *mvLXCol, Mv *mvCol, return 1; } -#define CHECK_MVSET(l) \ - check_mvset(mvLXCol, temp_col.mv + l, \ - colPic, s->poc, \ - refPicList, X, refIdxLx, \ - refPicList_col, L##l, temp_col.ref_idx[l]) +#define CHECK_MVSET(l) \ + check_mvset(mvLXCol, temp_col.mv + l, \ + colPic, s->poc, \ + refPicList, X, refIdxLx, \ + refPicList_col, L ## l, temp_col.ref_idx[l]) // derive the motion vectors section 8.5.3.1.8 static int derive_temporal_colocated_mvs(HEVCContext *s, MvField temp_col, - int refIdxLx, Mv* mvLXCol, int X, - int colPic, RefPicList* refPicList_col) + int refIdxLx, Mv *mvLXCol, int X, + int colPic, RefPicList *refPicList_col) { RefPicList *refPicList = s->ref->refPicList; @@ -229,15 +229,15 @@ static int derive_temporal_colocated_mvs(HEVCContext *s, MvField temp_col, return 0; } -#define TAB_MVF(x, y) \ +#define TAB_MVF(x, y) \ tab_mvf[(y) * min_pu_width + x] -#define TAB_MVF_PU(v) \ - TAB_MVF(x##v##_pu, y##v##_pu) +#define TAB_MVF_PU(v) \ + TAB_MVF(x ## v ## _pu, y ## v ## _pu) -#define DERIVE_TEMPORAL_COLOCATED_MVS \ - derive_temporal_colocated_mvs(s, temp_col, \ - refIdxLx, mvLXCol, X, colPic, \ +#define DERIVE_TEMPORAL_COLOCATED_MVS \ + derive_temporal_colocated_mvs(s, temp_col, \ + refIdxLx, mvLXCol, X, colPic, \ ff_hevc_get_ref_list(s, ref, x, y)) /* @@ -245,7 +245,7 @@ static int derive_temporal_colocated_mvs(HEVCContext *s, MvField temp_col, */ static int temporal_luma_motion_vector(HEVCContext *s, int x0, int y0, int nPbW, int nPbH, int refIdxLx, - Mv* mvLXCol, int X) + Mv *mvLXCol, int X) { MvField *tab_mvf; MvField temp_col; @@ -273,44 +273,45 @@ static int temporal_luma_motion_vector(HEVCContext *s, int x0, int y0, (y0 >> s->sps->log2_ctb_size) == (y >> s->sps->log2_ctb_size) && y < s->sps->height && x < s->sps->width) { - x = ((x >> 4) << 4); - y = ((y >> 4) << 4); - x_pu = x >> s->sps->log2_min_pu_size; - y_pu = y >> s->sps->log2_min_pu_size; - temp_col = TAB_MVF(x_pu, y_pu); + x = ((x >> 4) << 4); + y = ((y >> 4) << 4); + x_pu = x >> s->sps->log2_min_pu_size; + y_pu = y >> s->sps->log2_min_pu_size; + temp_col = TAB_MVF(x_pu, y_pu); availableFlagLXCol = DERIVE_TEMPORAL_COLOCATED_MVS; } // derive center collocated motion vector if (tab_mvf && !availableFlagLXCol) { - x = x0 + (nPbW >> 1); - y = y0 + (nPbH >> 1); - x = ((x >> 4) << 4); - y = ((y >> 4) << 4); - x_pu = x >> s->sps->log2_min_pu_size; - y_pu = y >> s->sps->log2_min_pu_size; - temp_col = TAB_MVF(x_pu, y_pu); + x = x0 + (nPbW >> 1); + y = y0 + (nPbH >> 1); + x = ((x >> 4) << 4); + y = ((y >> 4) << 4); + x_pu = x >> s->sps->log2_min_pu_size; + y_pu = y >> s->sps->log2_min_pu_size; + temp_col = TAB_MVF(x_pu, y_pu); availableFlagLXCol = DERIVE_TEMPORAL_COLOCATED_MVS; } return availableFlagLXCol; } -#define AVAILABLE(cand, v) \ +#define AVAILABLE(cand, v) \ (cand && !TAB_MVF_PU(v).is_intra) -#define PRED_BLOCK_AVAILABLE(v) \ - check_prediction_block_available(s, log2_cb_size, \ - x0, y0, nPbW, nPbH, \ - x##v, y##v, part_idx) +#define PRED_BLOCK_AVAILABLE(v) \ + check_prediction_block_available(s, log2_cb_size, \ + x0, y0, nPbW, nPbH, \ + x ## v, y ## v, part_idx) -#define COMPARE_MV_REFIDX(a, b) \ +#define COMPARE_MV_REFIDX(a, b) \ compareMVrefidx(TAB_MVF_PU(a), TAB_MVF_PU(b)) /* * 8.5.3.1.2 Derivation process for spatial merging candidates */ static void derive_spatial_merge_candidates(HEVCContext *s, int x0, int y0, - int nPbW, int nPbH, int log2_cb_size, + int nPbW, int nPbH, + int log2_cb_size, int singleMCLFlag, int part_idx, struct MvField mergecandlist[]) { @@ -318,7 +319,7 @@ static void derive_spatial_merge_candidates(HEVCContext *s, int x0, int y0, RefPicList *refPicList = s->ref->refPicList; MvField *tab_mvf = s->ref->tab_mvf; - const int min_pu_width = s->sps->min_pu_width; + const int min_pu_width = s->sps->min_pu_width; const int cand_bottom_left = lc->na.cand_bottom_left; const int cand_left = lc->na.cand_left; @@ -402,7 +403,7 @@ static void derive_spatial_merge_candidates(HEVCContext *s, int x0, int y0, // above right spatial merge candidate check_MER = 1; - check_B0 = PRED_BLOCK_AVAILABLE(B0); + check_B0 = PRED_BLOCK_AVAILABLE(B0); is_available_b0 = check_B0 && AVAILABLE(cand_up_right, B0); @@ -417,7 +418,7 @@ static void derive_spatial_merge_candidates(HEVCContext *s, int x0, int y0, // left bottom spatial merge candidate check_MER = 1; - check_A0 = PRED_BLOCK_AVAILABLE(A0); + check_A0 = PRED_BLOCK_AVAILABLE(A0); is_available_a0 = check_A0 && AVAILABLE(cand_bottom_left, A0); @@ -539,11 +540,11 @@ void ff_hevc_luma_mv_merge_mode(HEVCContext *s, int x0, int y0, int nPbW, if (s->pps->log2_parallel_merge_level > 2 && nCS == 8) { singleMCLFlag = 1; - x0 = lc->cu.x; - y0 = lc->cu.y; - nPbW = nCS; - nPbH = nCS; - part_idx = 0; + x0 = lc->cu.x; + y0 = lc->cu.y; + nPbW = nCS; + nPbH = nCS; + part_idx = 0; } ff_hevc_set_neighbour_available(s, x0, y0, nPbW, nPbH); @@ -553,21 +554,21 @@ void ff_hevc_luma_mv_merge_mode(HEVCContext *s, int x0, int y0, int nPbW, if (mergecand_list[merge_idx].pred_flag[0] == 1 && mergecand_list[merge_idx].pred_flag[1] == 1 && (nPbW2 + nPbH2) == 12) { - mergecand_list[merge_idx].ref_idx[1] = -1; + mergecand_list[merge_idx].ref_idx[1] = -1; mergecand_list[merge_idx].pred_flag[1] = 0; } *mv = mergecand_list[merge_idx]; } -static av_always_inline void dist_scale(HEVCContext *s, Mv * mv, +static av_always_inline void dist_scale(HEVCContext *s, Mv *mv, int min_pu_width, int x, int y, int elist, int ref_idx_curr, int ref_idx) { RefPicList *refPicList = s->ref->refPicList; - MvField *tab_mvf = s->ref->tab_mvf; - int ref_pic_elist = refPicList[elist].list[TAB_MVF(x, y).ref_idx[elist]]; - int ref_pic_curr = refPicList[ref_idx_curr].list[ref_idx]; + MvField *tab_mvf = s->ref->tab_mvf; + int ref_pic_elist = refPicList[elist].list[TAB_MVF(x, y).ref_idx[elist]]; + int ref_pic_curr = refPicList[ref_idx_curr].list[ref_idx]; if (ref_pic_elist != ref_pic_curr) mv_scale(mv, mv, s->poc - ref_pic_elist, s->poc - ref_pic_curr); @@ -589,7 +590,6 @@ static int mv_mp_mode_mx(HEVCContext *s, int x, int y, int pred_flag_index, return 0; } - static int mv_mp_mode_mx_lt(HEVCContext *s, int x, int y, int pred_flag_index, Mv *mv, int ref_idx_curr, int ref_idx) { @@ -597,25 +597,27 @@ static int mv_mp_mode_mx_lt(HEVCContext *s, int x, int y, int pred_flag_index, int min_pu_width = s->sps->min_pu_width; RefPicList *refPicList = s->ref->refPicList; - int currIsLongTerm = refPicList[ref_idx_curr].isLongTerm[ref_idx]; + int currIsLongTerm = refPicList[ref_idx_curr].isLongTerm[ref_idx]; int colIsLongTerm = refPicList[pred_flag_index].isLongTerm[(TAB_MVF(x, y).ref_idx[pred_flag_index])]; - if (TAB_MVF(x, y).pred_flag[pred_flag_index] && colIsLongTerm == currIsLongTerm) { + if (TAB_MVF(x, y).pred_flag[pred_flag_index] && + colIsLongTerm == currIsLongTerm) { *mv = TAB_MVF(x, y).mv[pred_flag_index]; if (!currIsLongTerm) - dist_scale(s, mv, min_pu_width, x, y, pred_flag_index, ref_idx_curr, ref_idx); + dist_scale(s, mv, min_pu_width, x, y, + pred_flag_index, ref_idx_curr, ref_idx); return 1; } return 0; } -#define MP_MX(v, pred, mx) \ - mv_mp_mode_mx(s, x##v##_pu, y##v##_pu, pred, &mx, ref_idx_curr, ref_idx) +#define MP_MX(v, pred, mx) \ + mv_mp_mode_mx(s, x ## v ## _pu, y ## v ## _pu, pred, &mx, ref_idx_curr, ref_idx) -#define MP_MX_LT(v, pred, mx) \ - mv_mp_mode_mx_lt(s, x##v##_pu, y##v##_pu, pred, &mx, ref_idx_curr, ref_idx) +#define MP_MX_LT(v, pred, mx) \ + mv_mp_mode_mx_lt(s, x ## v ## _pu, y ## v ## _pu, pred, &mx, ref_idx_curr, ref_idx) void ff_hevc_luma_mv_mvp_mode(HEVCContext *s, int x0, int y0, int nPbW, int nPbH, int log2_cb_size, int part_idx, @@ -683,8 +685,8 @@ void ff_hevc_luma_mv_mvp_mode(HEVCContext *s, int x0, int y0, int nPbW, is_available_a0 = PRED_BLOCK_AVAILABLE(A0) && AVAILABLE(cand_bottom_left, A0); //left spatial merge candidate - xA1 = x0 - 1; - yA1 = y0 + nPbH - 1; + xA1 = x0 - 1; + yA1 = y0 + nPbH - 1; xA1_pu = xA1 >> s->sps->log2_min_pu_size; yA1_pu = yA1 >> s->sps->log2_min_pu_size; @@ -719,8 +721,8 @@ void ff_hevc_luma_mv_mvp_mode(HEVCContext *s, int x0, int y0, int nPbW, // B candidates // above right spatial merge candidate - xB0 = x0 + nPbW; - yB0 = y0 - 1; + xB0 = x0 + nPbW; + yB0 = y0 - 1; xB0_pu = xB0 >> s->sps->log2_min_pu_size; yB0_pu = yB0 >> s->sps->log2_min_pu_size; @@ -734,8 +736,8 @@ void ff_hevc_luma_mv_mvp_mode(HEVCContext *s, int x0, int y0, int nPbW, if (!availableFlagLXB0) { // above spatial merge candidate - xB1 = x0 + nPbW - 1; - yB1 = y0 - 1; + xB1 = x0 + nPbW - 1; + yB1 = y0 - 1; xB1_pu = xB1 >> s->sps->log2_min_pu_size; yB1_pu = yB1 >> s->sps->log2_min_pu_size; @@ -800,7 +802,8 @@ void ff_hevc_luma_mv_mvp_mode(HEVCContext *s, int x0, int y0, int nPbW, if (numMVPCandLX < 2 && s->sh.slice_temporal_mvp_enabled_flag) { Mv mv_col; int available_col = temporal_luma_motion_vector(s, x0, y0, nPbW, - nPbH, ref_idx, &mv_col, LX); + nPbH, ref_idx, + &mv_col, LX); if (available_col) mvpcand_list[numMVPCandLX++] = mv_col; } diff --git a/libavcodec/hevc_parser.c b/libavcodec/hevc_parser.c index aacf3431dc..c8af881809 100644 --- a/libavcodec/hevc_parser.c +++ b/libavcodec/hevc_parser.c @@ -21,6 +21,7 @@ */ #include "libavutil/common.h" + #include "parser.h" #include "hevc.h" #include "golomb.h" @@ -36,7 +37,8 @@ typedef struct HEVCParseContext { * Find the end of the current frame in the bitstream. * @return the position of the first byte of the next frame, or END_NOT_FOUND */ -static int hevc_find_frame_end(AVCodecParserContext *s, const uint8_t *buf, int buf_size) +static int hevc_find_frame_end(AVCodecParserContext *s, const uint8_t *buf, + int buf_size) { int i; ParseContext *pc = &((HEVCParseContext *)s->priv_data)->pc; @@ -82,9 +84,8 @@ static int hevc_find_frame_end(AVCodecParserContext *s, const uint8_t *buf, int * @param buf buffer with field/frame data. * @param buf_size size of the buffer. */ -static inline int parse_nal_units(AVCodecParserContext *s, - AVCodecContext *avctx, - const uint8_t *buf, int buf_size) +static inline int parse_nal_units(AVCodecParserContext *s, AVCodecContext *avctx, + const uint8_t *buf, int buf_size) { HEVCContext *h = &((HEVCParseContext *)s->priv_data)->h; GetBitContext *gb = &h->HEVClc->gb; @@ -269,7 +270,7 @@ static int hevc_parse(AVCodecParserContext *s, } else { next = hevc_find_frame_end(s, buf, buf_size); if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { - *poutbuf = NULL; + *poutbuf = NULL; *poutbuf_size = 0; return buf_size; } @@ -299,9 +300,9 @@ static int hevc_split(AVCodecContext *avctx, const uint8_t *buf, int buf_size) return i - 3; } else { // no parameter set at the beginning of the stream return 0; - } } } + } return 0; } diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c index 50de015dbc..3e84692273 100644 --- a/libavcodec/hevc_ps.c +++ b/libavcodec/hevc_ps.c @@ -229,7 +229,7 @@ static int decode_profile_tier_level(HEVCContext *s, PTL *ptl, } if (max_num_sub_layers - 1 > 0) for (i = max_num_sub_layers - 1; i < 8; i++) - skip_bits(gb, 2); // reserved_zero_2bits[i] + skip_bits(gb, 2); // reserved_zero_2bits[i] for (i = 0; i < max_num_sub_layers - 1; i++) { if (ptl->sub_layer_profile_present_flag[i]) { ptl->sub_layer_profile_space[i] = get_bits(gb, 2); @@ -273,7 +273,8 @@ static void decode_sublayer_hrd(HEVCContext *s, int nb_cpb, } } -static void decode_hrd(HEVCContext *s, int common_inf_present, int max_sublayers) +static void decode_hrd(HEVCContext *s, int common_inf_present, + int max_sublayers) { GetBitContext *gb = &s->HEVClc->gb; int nal_params_present = 0, vcl_params_present = 0; @@ -298,7 +299,7 @@ static void decode_hrd(HEVCContext *s, int common_inf_present, int max_sublayers skip_bits(gb, 4); // cpb_size_scale if (subpic_params_present) - skip_bits(gb, 4); // cpb_size_du_scale + skip_bits(gb, 4); // cpb_size_du_scale skip_bits(gb, 5); // initial_cpb_removal_delay_length_minus1 skip_bits(gb, 5); // au_cpb_removal_delay_length_minus1 @@ -315,7 +316,7 @@ static void decode_hrd(HEVCContext *s, int common_inf_present, int max_sublayers fixed_rate = get_bits1(gb); if (fixed_rate) - get_ue_golomb_long(gb); // elemental_duration_in_tc_minus1 + get_ue_golomb_long(gb); // elemental_duration_in_tc_minus1 else low_delay = get_bits1(gb); @@ -396,7 +397,7 @@ int ff_hevc_decode_nal_vps(HEVCContext *s) vps->vps_num_layer_sets = get_ue_golomb_long(gb) + 1; for (i = 1; i < vps->vps_num_layer_sets; i++) for (j = 0; j <= vps->vps_max_layer_id; j++) - skip_bits(gb, 1); // layer_id_included_flag[i][j] + skip_bits(gb, 1); // layer_id_included_flag[i][j] vps->vps_timing_info_present_flag = get_bits1(gb); if (vps->vps_timing_info_present_flag) { @@ -582,7 +583,7 @@ static int scaling_list_data(HEVCContext *s, ScalingList *sl) int32_t scaling_list_delta_coef; next_coef = 8; - coef_num = FFMIN(64, 1 << (4 + (size_id << 1))); + coef_num = FFMIN(64, 1 << (4 + (size_id << 1))); if (size_id > 1) { scaling_list_dc_coef[size_id - 2][matrix_id] = get_se_golomb(gb) + 8; next_coef = scaling_list_dc_coef[size_id - 2][matrix_id]; @@ -643,7 +644,8 @@ int ff_hevc_decode_nal_sps(HEVCContext *s) } skip_bits1(gb); // temporal_id_nesting_flag - if (decode_profile_tier_level(s, &sps->ptl, sps->max_sub_layers) < 0) { + if (decode_profile_tier_level(s, &sps->ptl, + sps->max_sub_layers) < 0) { av_log(s->avctx, AV_LOG_ERROR, "error decoding profile tier level\n"); ret = AVERROR_INVALIDDATA; goto err; @@ -820,11 +822,12 @@ int ff_hevc_decode_nal_sps(HEVCContext *s) sps->nb_st_rps = get_ue_golomb_long(gb); if (sps->nb_st_rps > MAX_SHORT_TERM_RPS_COUNT) { - av_log(s->avctx, AV_LOG_ERROR, "Too many short term RPS: %d.\n", + av_log(s->avctx, AV_LOG_ERROR, + "Too many short term RPS: %d.\n", sps->nb_st_rps); ret = AVERROR_INVALIDDATA; - goto err; - } + goto err; + } for (i = 0; i < sps->nb_st_rps; i++) { if ((ret = ff_hevc_decode_short_term_rps(s, &sps->st_rps[i], sps, 0)) < 0) @@ -870,10 +873,9 @@ int ff_hevc_decode_nal_sps(HEVCContext *s) sps->output_width, sps->output_height); if (s->avctx->err_recognition & AV_EF_EXPLODE) { ret = AVERROR_INVALIDDATA; - goto err; - } - av_log(s->avctx, AV_LOG_WARNING, - "Displaying the whole video surface.\n"); + goto err; + } + av_log(s->avctx, AV_LOG_WARNING, "Displaying the whole video surface.\n"); sps->pic_conf_win.left_offset = sps->pic_conf_win.right_offset = sps->pic_conf_win.top_offset = @@ -1016,8 +1018,8 @@ int ff_hevc_decode_nal_pps(HEVCContext *s) if (pps_id >= MAX_PPS_COUNT) { av_log(s->avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id); ret = AVERROR_INVALIDDATA; - goto err; - } + goto err; + } pps->sps_id = get_ue_golomb_long(gb); if (pps->sps_id >= MAX_SPS_COUNT) { av_log(s->avctx, AV_LOG_ERROR, "SPS id out of range: %d\n", pps->sps_id); @@ -1080,11 +1082,11 @@ int ff_hevc_decode_nal_pps(HEVCContext *s) pps->num_tile_rows = get_ue_golomb_long(gb) + 1; if (pps->num_tile_columns == 0 || pps->num_tile_columns >= sps->width) { - av_log(s->avctx, AV_LOG_ERROR, "num_tile_columns_minus1 out of range: %d\n", + av_log(s->avctx, AV_LOG_ERROR, "num_tile_columns_minus1 out of range: %d\n", pps->num_tile_columns - 1); ret = AVERROR_INVALIDDATA; - goto err; - } + goto err; + } if (pps->num_tile_rows == 0 || pps->num_tile_rows >= sps->height) { av_log(s->avctx, AV_LOG_ERROR, "num_tile_rows_minus1 out of range: %d\n", @@ -1110,8 +1112,8 @@ int ff_hevc_decode_nal_pps(HEVCContext *s) if (sum >= sps->ctb_width) { av_log(s->avctx, AV_LOG_ERROR, "Invalid tile widths.\n"); ret = AVERROR_INVALIDDATA; - goto err; - } + goto err; + } pps->column_width[pps->num_tile_columns - 1] = sps->ctb_width - sum; sum = 0; @@ -1166,8 +1168,8 @@ int ff_hevc_decode_nal_pps(HEVCContext *s) av_log(s->avctx, AV_LOG_ERROR, "log2_parallel_merge_level_minus2 out of range: %d\n", pps->log2_parallel_merge_level - 2); ret = AVERROR_INVALIDDATA; - goto err; - } + goto err; + } pps->slice_header_extension_present_flag = get_bits1(gb); pps->pps_extension_flag = get_bits1(gb); @@ -1187,9 +1189,9 @@ int ff_hevc_decode_nal_pps(HEVCContext *s) pps->row_height = av_malloc_array(pps->num_tile_rows, sizeof(*pps->row_height)); } if (!pps->column_width || !pps->row_height) { - ret = AVERROR(ENOMEM); - goto err; - } + ret = AVERROR(ENOMEM); + goto err; + } for (i = 0; i < pps->num_tile_columns; i++) { pps->column_width[i] = ((i + 1) * sps->ctb_width) / pps->num_tile_columns - @@ -1230,9 +1232,9 @@ int ff_hevc_decode_nal_pps(HEVCContext *s) pps->min_tb_addr_zs = av_malloc_array(pic_area_in_min_tbs, sizeof(*pps->min_tb_addr_zs)); if (!pps->ctb_addr_rs_to_ts || !pps->ctb_addr_ts_to_rs || !pps->tile_id || !pps->min_cb_addr_zs || !pps->min_tb_addr_zs) { - ret = AVERROR(ENOMEM); - goto err; - } + ret = AVERROR(ENOMEM); + goto err; + } for (ctb_addr_rs = 0; ctb_addr_rs < pic_area_in_ctbs; ctb_addr_rs++) { int tb_x = ctb_addr_rs % sps->ctb_width; diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c index bf3d953d1f..0ca3f403af 100644 --- a/libavcodec/hevc_refs.c +++ b/libavcodec/hevc_refs.c @@ -49,16 +49,17 @@ void ff_hevc_unref_frame(HEVCContext *s, HEVCFrame *frame, int flags) } } -RefPicList* ff_hevc_get_ref_list(HEVCContext *s, HEVCFrame *ref, int x0, int y0) +RefPicList *ff_hevc_get_ref_list(HEVCContext *s, HEVCFrame *ref, int x0, int y0) { if (x0 < 0 || y0 < 0) { return s->ref->refPicList; } else { int x_cb = x0 >> s->sps->log2_ctb_size; int y_cb = y0 >> s->sps->log2_ctb_size; - int pic_width_cb = (s->sps->width + (1<sps->log2_ctb_size)-1 ) >> s->sps->log2_ctb_size; + int pic_width_cb = (s->sps->width + (1 << s->sps->log2_ctb_size) - 1) >> + s->sps->log2_ctb_size; int ctb_addr_ts = s->pps->ctb_addr_rs_to_ts[y_cb * pic_width_cb + x_cb]; - return (RefPicList*) ref->rpl_tab[ctb_addr_ts]; + return (RefPicList *)ref->rpl_tab[ctb_addr_ts]; } } @@ -67,7 +68,8 @@ void ff_hevc_clear_refs(HEVCContext *s) int i; for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) ff_hevc_unref_frame(s, &s->DPB[i], - HEVC_FRAME_FLAG_SHORT_REF | HEVC_FRAME_FLAG_LONG_REF); + HEVC_FRAME_FLAG_SHORT_REF | + HEVC_FRAME_FLAG_LONG_REF); } void ff_hevc_flush_dpb(HEVCContext *s) @@ -85,7 +87,8 @@ static HEVCFrame *alloc_frame(HEVCContext *s) if (frame->frame->buf[0]) continue; - ret = ff_thread_get_buffer(s->avctx, &frame->tf, AV_GET_BUFFER_FLAG_REF); + ret = ff_thread_get_buffer(s->avctx, &frame->tf, + AV_GET_BUFFER_FLAG_REF); if (ret < 0) return NULL; @@ -96,15 +99,15 @@ static HEVCFrame *alloc_frame(HEVCContext *s) frame->tab_mvf_buf = av_buffer_pool_get(s->tab_mvf_pool); if (!frame->tab_mvf_buf) goto fail; - frame->tab_mvf = (MvField*)frame->tab_mvf_buf->data; + frame->tab_mvf = (MvField *)frame->tab_mvf_buf->data; frame->rpl_tab_buf = av_buffer_pool_get(s->rpl_tab_pool); if (!frame->rpl_tab_buf) goto fail; - frame->rpl_tab = (RefPicListTab**)frame->rpl_tab_buf->data; + frame->rpl_tab = (RefPicListTab **)frame->rpl_tab_buf->data; frame->ctb_count = s->sps->ctb_width * s->sps->ctb_height; for (j = 0; j < frame->ctb_count; j++) - frame->rpl_tab[j] = (RefPicListTab*)frame->rpl_buf->data; + frame->rpl_tab[j] = (RefPicListTab *)frame->rpl_buf->data; frame->frame->top_field_first = s->picture_struct == AV_PICTURE_STRUCTURE_TOP_FIELD; frame->frame->interlaced_frame = (s->picture_struct == AV_PICTURE_STRUCTURE_TOP_FIELD) || (s->picture_struct == AV_PICTURE_STRUCTURE_BOTTOM_FIELD); @@ -138,13 +141,13 @@ int ff_hevc_set_new_ref(HEVCContext *s, AVFrame **frame, int poc) if (!ref) return AVERROR(ENOMEM); - *frame = ref->frame; - s->ref = ref; - ref->poc = poc; + *frame = ref->frame; + s->ref = ref; - ref->flags = HEVC_FRAME_FLAG_OUTPUT | HEVC_FRAME_FLAG_SHORT_REF; - ref->sequence = s->seq_decode; - ref->window = s->sps->output_window; + ref->poc = poc; + ref->flags = HEVC_FRAME_FLAG_OUTPUT | HEVC_FRAME_FLAG_SHORT_REF; + ref->sequence = s->seq_decode; + ref->window = s->sps->output_window; return 0; } @@ -192,7 +195,8 @@ int ff_hevc_output_frame(HEVCContext *s, AVFrame *out, int flush) (frame->window.top_offset >> vshift) * dst->linesize[j]; dst->data[j] += off; } - av_log(s->avctx, AV_LOG_DEBUG, "Output frame with POC %d.\n", frame->poc); + av_log(s->avctx, AV_LOG_DEBUG, + "Output frame with POC %d.\n", frame->poc); return 1; } @@ -208,17 +212,17 @@ int ff_hevc_output_frame(HEVCContext *s, AVFrame *out, int flush) static int init_slice_rpl(HEVCContext *s) { HEVCFrame *frame = s->ref; - int ctb_count = frame->ctb_count; - int ctb_addr_ts = s->pps->ctb_addr_rs_to_ts[s->sh.slice_segment_addr]; + int ctb_count = frame->ctb_count; + int ctb_addr_ts = s->pps->ctb_addr_rs_to_ts[s->sh.slice_segment_addr]; int i; if (s->slice_idx >= frame->rpl_buf->size / sizeof(RefPicListTab)) return AVERROR_INVALIDDATA; for (i = ctb_addr_ts; i < ctb_count; i++) - frame->rpl_tab[i] = (RefPicListTab*)frame->rpl_buf->data + s->slice_idx; + frame->rpl_tab[i] = (RefPicListTab *)frame->rpl_buf->data + s->slice_idx; - frame->refPicList = (RefPicList*)frame->rpl_tab[ctb_addr_ts]; + frame->refPicList = (RefPicList *)frame->rpl_tab[ctb_addr_ts]; return 0; } @@ -247,8 +251,7 @@ int ff_hevc_slice_rpl(HEVCContext *s) /* The order of the elements is * ST_CURR_BEF - ST_CURR_AFT - LT_CURR for the L0 and - * ST_CURR_AFT - ST_CURR_BEF - LT_CURR for the L1 - */ + * ST_CURR_AFT - ST_CURR_BEF - LT_CURR for the L1 */ int cand_lists[3] = { list_idx ? ST_CURR_AFT : ST_CURR_BEF, list_idx ? ST_CURR_BEF : ST_CURR_AFT, LT_CURR }; @@ -258,8 +261,8 @@ int ff_hevc_slice_rpl(HEVCContext *s) for (i = 0; i < FF_ARRAY_ELEMS(cand_lists); i++) { RefPicList *rps = &s->rps[cand_lists[i]]; for (j = 0; j < rps->nb_refs && rpl_tmp.nb_refs < MAX_REFS; j++) { - rpl_tmp.list[rpl_tmp.nb_refs] = rps->list[j]; - rpl_tmp.ref[rpl_tmp.nb_refs] = rps->ref[j]; + rpl_tmp.list[rpl_tmp.nb_refs] = rps->list[j]; + rpl_tmp.ref[rpl_tmp.nb_refs] = rps->ref[j]; rpl_tmp.isLongTerm[rpl_tmp.nb_refs] = (i == 2); rpl_tmp.nb_refs++; } @@ -331,15 +334,14 @@ static HEVCFrame *generate_missing_ref(HEVCContext *s, int poc) HEVCFrame *frame; int i, x, y; - frame = alloc_frame(s); if (!frame) return NULL; if (!s->sps->pixel_shift) { for (i = 0; frame->frame->buf[i]; i++) - memset(frame->frame->buf[i]->data, 1 << (s->sps->bit_depth - 1), - frame->frame->buf[i]->size); + memset(frame->frame->buf[i]->data, 1 << (s->sps->bit_depth - 1), + frame->frame->buf[i]->size); } else { for (i = 0; frame->frame->data[i]; i++) for (y = 0; y < (s->sps->height >> s->sps->vshift[i]); y++) @@ -456,7 +458,7 @@ int ff_hevc_compute_poc(HEVCContext *s, int poc_lsb) poc_msb = prev_poc_msb; // For BLA picture types, POCmsb is set to 0. - if (s->nal_unit_type == NAL_BLA_W_LP || + if (s->nal_unit_type == NAL_BLA_W_LP || s->nal_unit_type == NAL_BLA_W_RADL || s->nal_unit_type == NAL_BLA_N_LP) poc_msb = 0; diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c index 5c404a3cdc..24f27c88b5 100644 --- a/libavcodec/hevc_sei.c +++ b/libavcodec/hevc_sei.c @@ -25,7 +25,8 @@ #include "hevc.h" #include "golomb.h" -static void decode_nal_sei_decoded_picture_hash(HEVCContext *s, int payload_size) +static void decode_nal_sei_decoded_picture_hash(HEVCContext *s, + int payload_size) { int cIdx, i; uint8_t hash_type; @@ -34,17 +35,16 @@ static void decode_nal_sei_decoded_picture_hash(HEVCContext *s, int payload_size GetBitContext *gb = &s->HEVClc->gb; hash_type = get_bits(gb, 8); - - for( cIdx = 0; cIdx < 3/*((s->sps->chroma_format_idc == 0) ? 1 : 3)*/; cIdx++ ) { - if ( hash_type == 0 ) { + for (cIdx = 0; cIdx < 3/*((s->sps->chroma_format_idc == 0) ? 1 : 3)*/; cIdx++) { + if (hash_type == 0) { s->is_md5 = 1; - for( i = 0; i < 16; i++) { + for (i = 0; i < 16; i++) { s->md5[cIdx][i] = get_bits(gb, 8); - } - } else if( hash_type == 1 ) { + } + } else if( hash_type == 1) { // picture_crc = get_bits(gb, 16); skip_bits(gb, 16); - } else if( hash_type == 2 ) { + } else if (hash_type == 2) { // picture_checksum = get_bits(gb, 32); skip_bits(gb, 32); } @@ -101,7 +101,8 @@ static int decode_pic_timing(HEVCContext *s) return 1; } -static void active_parameter_sets(HEVCContext *s) { +static void active_parameter_sets(HEVCContext *s) +{ GetBitContext *gb = &s->HEVClc->gb; int num_sps_ids_minus1; int i; diff --git a/libavcodec/hevcdsp.c b/libavcodec/hevcdsp.c index 5ea774ed69..6c40caf0ac 100644 --- a/libavcodec/hevcdsp.c +++ b/libavcodec/hevcdsp.c @@ -24,80 +24,80 @@ #include "hevcdsp.h" static const int8_t transform[32][32] = { - { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, - { 90, 90, 88, 85, 82, 78, 73, 67, 61, 54, 46, 38, 31, 22, 13, 4, - -4, -13, -22, -31, -38, -46, -54, -61, -67, -73, -78, -82, -85, -88, -90, -90 }, - { 90, 87, 80, 70, 57, 43, 25, 9, -9, -25, -43, -57, -70, -80, -87, -90, - -90, -87, -80, -70, -57, -43, -25, -9, 9, 25, 43, 57, 70, 80, 87, 90 }, - { 90, 82, 67, 46, 22, -4, -31, -54, -73, -85, -90, -88, -78, -61, -38, -13, - 13, 38, 61, 78, 88, 90, 85, 73, 54, 31, 4, -22, -46, -67, -82, -90 }, - { 89, 75, 50, 18, -18, -50, -75, -89, -89, -75, -50, -18, 18, 50, 75, 89, - 89, 75, 50, 18, -18, -50, -75, -89, -89, -75, -50, -18, 18, 50, 75, 89 }, - { 88, 67, 31, -13, -54, -82, -90, -78, -46, -4, 38, 73, 90, 85, 61, 22, - -22, -61, -85, -90, -73, -38, 4, 46, 78, 90, 82, 54, 13, -31, -67, -88 }, - { 87, 57, 9, -43, -80, -90, -70, -25, 25, 70, 90, 80, 43, -9, -57, -87, - -87, -57, -9, 43, 80, 90, 70, 25, -25, -70, -90, -80, -43, 9, 57, 87 }, - { 85, 46, -13, -67, -90, -73, -22, 38, 82, 88, 54, -4, -61, -90, -78, -31, - 31, 78, 90, 61, 4, -54, -88, -82, -38, 22, 73, 90, 67, 13, -46, -85 }, - { 83, 36, -36, -83, -83, -36, 36, 83, 83, 36, -36, -83, -83, -36, 36, 83, - 83, 36, -36, -83, -83, -36, 36, 83, 83, 36, -36, -83, -83, -36, 36, 83 }, - { 82, 22, -54, -90, -61, 13, 78, 85, 31, -46, -90, -67, 4, 73, 88, 38, - -38, -88, -73, -4, 67, 90, 46, -31, -85, -78, -13, 61, 90, 54, -22, -82 }, - { 80, 9, -70, -87, -25, 57, 90, 43, -43, -90, -57, 25, 87, 70, -9, -80, - -80, -9, 70, 87, 25, -57, -90, -43, 43, 90, 57, -25, -87, -70, 9, 80 }, - { 78, -4, -82, -73, 13, 85, 67, -22, -88, -61, 31, 90, 54, -38, -90, -46, - 46, 90, 38, -54, -90, -31, 61, 88, 22, -67, -85, -13, 73, 82, 4, -78 }, - { 75, -18, -89, -50, 50, 89, 18, -75, -75, 18, 89, 50, -50, -89, -18, 75, - 75, -18, -89, -50, 50, 89, 18, -75, -75, 18, 89, 50, -50, -89, -18, 75 }, - { 73, -31, -90, -22, 78, 67, -38, -90, -13, 82, 61, -46, -88, -4, 85, 54, - -54, -85, 4, 88, 46, -61, -82, 13, 90, 38, -67, -78, 22, 90, 31, -73 }, - { 70, -43, -87, 9, 90, 25, -80, -57, 57, 80, -25, -90, -9, 87, 43, -70, - -70, 43, 87, -9, -90, -25, 80, 57, -57, -80, 25, 90, 9, -87, -43, 70 }, - { 67, -54, -78, 38, 85, -22, -90, 4, 90, 13, -88, -31, 82, 46, -73, -61, - 61, 73, -46, -82, 31, 88, -13, -90, -4, 90, 22, -85, -38, 78, 54, -67 }, - { 64, -64, -64, 64, 64, -64, -64, 64, 64, -64, -64, 64, 64, -64, -64, 64, - 64, -64, -64, 64, 64, -64, -64, 64, 64, -64, -64, 64, 64, -64, -64, 64 }, - { 61, -73, -46, 82, 31, -88, -13, 90, -4, -90, 22, 85, -38, -78, 54, 67, - -67, -54, 78, 38, -85, -22, 90, 4, -90, 13, 88, -31, -82, 46, 73, -61 }, - { 57, -80, -25, 90, -9, -87, 43, 70, -70, -43, 87, 9, -90, 25, 80, -57, - -57, 80, 25, -90, 9, 87, -43, -70, 70, 43, -87, -9, 90, -25, -80, 57 }, - { 54, -85, -4, 88, -46, -61, 82, 13, -90, 38, 67, -78, -22, 90, -31, -73, - 73, 31, -90, 22, 78, -67, -38, 90, -13, -82, 61, 46, -88, 4, 85, -54 }, - { 50, -89, 18, 75, -75, -18, 89, -50, -50, 89, -18, -75, 75, 18, -89, 50, - 50, -89, 18, 75, -75, -18, 89, -50, -50, 89, -18, -75, 75, 18, -89, 50 }, - { 46, -90, 38, 54, -90, 31, 61, -88, 22, 67, -85, 13, 73, -82, 4, 78, - -78, -4, 82, -73, -13, 85, -67, -22, 88, -61, -31, 90, -54, -38, 90, -46 }, - { 43, -90, 57, 25, -87, 70, 9, -80, 80, -9, -70, 87, -25, -57, 90, -43, - -43, 90, -57, -25, 87, -70, -9, 80, -80, 9, 70, -87, 25, 57, -90, 43 }, - { 38, -88, 73, -4, -67, 90, -46, -31, 85, -78, 13, 61, -90, 54, 22, -82, - 82, -22, -54, 90, -61, -13, 78, -85, 31, 46, -90, 67, 4, -73, 88, -38 }, - { 36, -83, 83, -36, -36, 83, -83, 36, 36, -83, 83, -36, -36, 83, -83, 36, - 36, -83, 83, -36, -36, 83, -83, 36, 36, -83, 83, -36, -36, 83, -83, 36 }, - { 31, -78, 90, -61, 4, 54, -88, 82, -38, -22, 73, -90, 67, -13, -46, 85, - -85, 46, 13, -67, 90, -73, 22, 38, -82, 88, -54, -4, 61, -90, 78, -31 }, - { 25, -70, 90, -80, 43, 9, -57, 87, -87, 57, -9, -43, 80, -90, 70, -25, - -25, 70, -90, 80, -43, -9, 57, -87, 87, -57, 9, 43, -80, 90, -70, 25 }, - { 22, -61, 85, -90, 73, -38, -4, 46, -78, 90, -82, 54, -13, -31, 67, -88, - 88, -67, 31, 13, -54, 82, -90, 78, -46, 4, 38, -73, 90, -85, 61, -22 }, - { 18, -50, 75, -89, 89, -75, 50, -18, -18, 50, -75, 89, -89, 75, -50, 18, - 18, -50, 75, -89, 89, -75, 50, -18, -18, 50, -75, 89, -89, 75, -50, 18 }, - { 13, -38, 61, -78, 88, -90, 85, -73, 54, -31, 4, 22, -46, 67, -82, 90, - -90, 82, -67, 46, -22, -4, 31, -54, 73, -85, 90, -88, 78, -61, 38, -13 }, - { 9, -25, 43, -57, 70, -80, 87, -90, 90, -87, 80, -70, 57, -43, 25, -9, - -9, 25, -43, 57, -70, 80, -87, 90, -90, 87, -80, 70, -57, 43, -25, 9 }, - { 4, -13, 22, -31, 38, -46, 54, -61, 67, -73, 78, -82, 85, -88, 90, -90, - 90, -90, 88, -85, 82, -78, 73, -67, 61, -54, 46, -38, 31, -22, 13, -4 }, + { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, + { 90, 90, 88, 85, 82, 78, 73, 67, 61, 54, 46, 38, 31, 22, 13, 4, + -4, -13, -22, -31, -38, -46, -54, -61, -67, -73, -78, -82, -85, -88, -90, -90 }, + { 90, 87, 80, 70, 57, 43, 25, 9, -9, -25, -43, -57, -70, -80, -87, -90, + -90, -87, -80, -70, -57, -43, -25, -9, 9, 25, 43, 57, 70, 80, 87, 90 }, + { 90, 82, 67, 46, 22, -4, -31, -54, -73, -85, -90, -88, -78, -61, -38, -13, + 13, 38, 61, 78, 88, 90, 85, 73, 54, 31, 4, -22, -46, -67, -82, -90 }, + { 89, 75, 50, 18, -18, -50, -75, -89, -89, -75, -50, -18, 18, 50, 75, 89, + 89, 75, 50, 18, -18, -50, -75, -89, -89, -75, -50, -18, 18, 50, 75, 89 }, + { 88, 67, 31, -13, -54, -82, -90, -78, -46, -4, 38, 73, 90, 85, 61, 22, + -22, -61, -85, -90, -73, -38, 4, 46, 78, 90, 82, 54, 13, -31, -67, -88 }, + { 87, 57, 9, -43, -80, -90, -70, -25, 25, 70, 90, 80, 43, -9, -57, -87, + -87, -57, -9, 43, 80, 90, 70, 25, -25, -70, -90, -80, -43, 9, 57, 87 }, + { 85, 46, -13, -67, -90, -73, -22, 38, 82, 88, 54, -4, -61, -90, -78, -31, + 31, 78, 90, 61, 4, -54, -88, -82, -38, 22, 73, 90, 67, 13, -46, -85 }, + { 83, 36, -36, -83, -83, -36, 36, 83, 83, 36, -36, -83, -83, -36, 36, 83, + 83, 36, -36, -83, -83, -36, 36, 83, 83, 36, -36, -83, -83, -36, 36, 83 }, + { 82, 22, -54, -90, -61, 13, 78, 85, 31, -46, -90, -67, 4, 73, 88, 38, + -38, -88, -73, -4, 67, 90, 46, -31, -85, -78, -13, 61, 90, 54, -22, -82 }, + { 80, 9, -70, -87, -25, 57, 90, 43, -43, -90, -57, 25, 87, 70, -9, -80, + -80, -9, 70, 87, 25, -57, -90, -43, 43, 90, 57, -25, -87, -70, 9, 80 }, + { 78, -4, -82, -73, 13, 85, 67, -22, -88, -61, 31, 90, 54, -38, -90, -46, + 46, 90, 38, -54, -90, -31, 61, 88, 22, -67, -85, -13, 73, 82, 4, -78 }, + { 75, -18, -89, -50, 50, 89, 18, -75, -75, 18, 89, 50, -50, -89, -18, 75, + 75, -18, -89, -50, 50, 89, 18, -75, -75, 18, 89, 50, -50, -89, -18, 75 }, + { 73, -31, -90, -22, 78, 67, -38, -90, -13, 82, 61, -46, -88, -4, 85, 54, + -54, -85, 4, 88, 46, -61, -82, 13, 90, 38, -67, -78, 22, 90, 31, -73 }, + { 70, -43, -87, 9, 90, 25, -80, -57, 57, 80, -25, -90, -9, 87, 43, -70, + -70, 43, 87, -9, -90, -25, 80, 57, -57, -80, 25, 90, 9, -87, -43, 70 }, + { 67, -54, -78, 38, 85, -22, -90, 4, 90, 13, -88, -31, 82, 46, -73, -61, + 61, 73, -46, -82, 31, 88, -13, -90, -4, 90, 22, -85, -38, 78, 54, -67 }, + { 64, -64, -64, 64, 64, -64, -64, 64, 64, -64, -64, 64, 64, -64, -64, 64, + 64, -64, -64, 64, 64, -64, -64, 64, 64, -64, -64, 64, 64, -64, -64, 64 }, + { 61, -73, -46, 82, 31, -88, -13, 90, -4, -90, 22, 85, -38, -78, 54, 67, + -67, -54, 78, 38, -85, -22, 90, 4, -90, 13, 88, -31, -82, 46, 73, -61 }, + { 57, -80, -25, 90, -9, -87, 43, 70, -70, -43, 87, 9, -90, 25, 80, -57, + -57, 80, 25, -90, 9, 87, -43, -70, 70, 43, -87, -9, 90, -25, -80, 57 }, + { 54, -85, -4, 88, -46, -61, 82, 13, -90, 38, 67, -78, -22, 90, -31, -73, + 73, 31, -90, 22, 78, -67, -38, 90, -13, -82, 61, 46, -88, 4, 85, -54 }, + { 50, -89, 18, 75, -75, -18, 89, -50, -50, 89, -18, -75, 75, 18, -89, 50, + 50, -89, 18, 75, -75, -18, 89, -50, -50, 89, -18, -75, 75, 18, -89, 50 }, + { 46, -90, 38, 54, -90, 31, 61, -88, 22, 67, -85, 13, 73, -82, 4, 78, + -78, -4, 82, -73, -13, 85, -67, -22, 88, -61, -31, 90, -54, -38, 90, -46 }, + { 43, -90, 57, 25, -87, 70, 9, -80, 80, -9, -70, 87, -25, -57, 90, -43, + -43, 90, -57, -25, 87, -70, -9, 80, -80, 9, 70, -87, 25, 57, -90, 43 }, + { 38, -88, 73, -4, -67, 90, -46, -31, 85, -78, 13, 61, -90, 54, 22, -82, + 82, -22, -54, 90, -61, -13, 78, -85, 31, 46, -90, 67, 4, -73, 88, -38 }, + { 36, -83, 83, -36, -36, 83, -83, 36, 36, -83, 83, -36, -36, 83, -83, 36, + 36, -83, 83, -36, -36, 83, -83, 36, 36, -83, 83, -36, -36, 83, -83, 36 }, + { 31, -78, 90, -61, 4, 54, -88, 82, -38, -22, 73, -90, 67, -13, -46, 85, + -85, 46, 13, -67, 90, -73, 22, 38, -82, 88, -54, -4, 61, -90, 78, -31 }, + { 25, -70, 90, -80, 43, 9, -57, 87, -87, 57, -9, -43, 80, -90, 70, -25, + -25, 70, -90, 80, -43, -9, 57, -87, 87, -57, 9, 43, -80, 90, -70, 25 }, + { 22, -61, 85, -90, 73, -38, -4, 46, -78, 90, -82, 54, -13, -31, 67, -88, + 88, -67, 31, 13, -54, 82, -90, 78, -46, 4, 38, -73, 90, -85, 61, -22 }, + { 18, -50, 75, -89, 89, -75, 50, -18, -18, 50, -75, 89, -89, 75, -50, 18, + 18, -50, 75, -89, 89, -75, 50, -18, -18, 50, -75, 89, -89, 75, -50, 18 }, + { 13, -38, 61, -78, 88, -90, 85, -73, 54, -31, 4, 22, -46, 67, -82, 90, + -90, 82, -67, 46, -22, -4, 31, -54, 73, -85, 90, -88, 78, -61, 38, -13 }, + { 9, -25, 43, -57, 70, -80, 87, -90, 90, -87, 80, -70, 57, -43, 25, -9, + -9, 25, -43, 57, -70, 80, -87, 90, -90, 87, -80, 70, -57, 43, -25, 9 }, + { 4, -13, 22, -31, 38, -46, 54, -61, 67, -73, 78, -82, 85, -88, 90, -90, + 90, -90, 88, -85, 82, -78, 73, -67, 61, -54, 46, -38, 31, -22, 13, -4 }, }; DECLARE_ALIGNED(16, const int8_t, ff_hevc_epel_filters[7][16]) = { - { -2, 58, 10, -2,-2, 58, 10, -2,-2, 58, 10, -2,-2, 58, 10, -2 }, - { -4, 54, 16, -2,-4, 54, 16, -2,-4, 54, 16, -2,-4, 54, 16, -2 }, - { -6, 46, 28, -4,-6, 46, 28, -4,-6, 46, 28, -4,-6, 46, 28, -4 }, - { -4, 36, 36, -4,-4, 36, 36, -4,-4, 36, 36, -4,-4, 36, 36, -4 }, - { -4, 28, 46, -6,-4, 28, 46, -6,-4, 28, 46, -6,-4, 28, 46, -6 }, - { -2, 16, 54, -4,-2, 16, 54, -4,-2, 16, 54, -4,-2, 16, 54, -4 }, - { -2, 10, 58, -2,-2, 10, 58, -2,-2, 10, 58, -2,-2, 10, 58, -2 }, + { -2, 58, 10, -2, -2, 58, 10, -2, -2, 58, 10, -2, -2, 58, 10, -2 }, + { -4, 54, 16, -2, -4, 54, 16, -2, -4, 54, 16, -2, -4, 54, 16, -2 }, + { -6, 46, 28, -4, -6, 46, 28, -4, -6, 46, 28, -4, -6, 46, 28, -4 }, + { -4, 36, 36, -4, -4, 36, 36, -4, -4, 36, 36, -4, -4, 36, 36, -4 }, + { -4, 28, 46, -6, -4, 28, 46, -6, -4, 28, 46, -6, -4, 28, 46, -6 }, + { -2, 16, 54, -4, -2, 16, 54, -4, -2, 16, 54, -4, -2, 16, 54, -4 }, + { -2, 10, 58, -2, -2, 10, 58, -2, -2, 10, 58, -2, -2, 10, 58, -2 }, }; #define BIT_DEPTH 8 @@ -117,67 +117,66 @@ void ff_hevc_dsp_init(HEVCDSPContext *hevcdsp, int bit_depth) #undef FUNC #define FUNC(a, depth) a ## _ ## depth -#define HEVC_DSP(depth) \ - hevcdsp->put_pcm = FUNC(put_pcm, depth); \ - hevcdsp->transquant_bypass[0] = FUNC(transquant_bypass4x4, depth); \ - hevcdsp->transquant_bypass[1] = FUNC(transquant_bypass8x8, depth); \ - hevcdsp->transquant_bypass[2] = FUNC(transquant_bypass16x16, depth); \ - hevcdsp->transquant_bypass[3] = FUNC(transquant_bypass32x32, depth); \ - hevcdsp->transform_skip = FUNC(transform_skip, depth); \ - hevcdsp->transform_4x4_luma_add = FUNC(transform_4x4_luma_add, depth); \ - hevcdsp->transform_add[0] = FUNC(transform_4x4_add, depth); \ - hevcdsp->transform_add[1] = FUNC(transform_8x8_add, depth); \ - hevcdsp->transform_add[2] = FUNC(transform_16x16_add, depth); \ - hevcdsp->transform_add[3] = FUNC(transform_32x32_add, depth); \ +#define HEVC_DSP(depth) \ + hevcdsp->put_pcm = FUNC(put_pcm, depth); \ + hevcdsp->transquant_bypass[0] = FUNC(transquant_bypass4x4, depth); \ + hevcdsp->transquant_bypass[1] = FUNC(transquant_bypass8x8, depth); \ + hevcdsp->transquant_bypass[2] = FUNC(transquant_bypass16x16, depth); \ + hevcdsp->transquant_bypass[3] = FUNC(transquant_bypass32x32, depth); \ + hevcdsp->transform_skip = FUNC(transform_skip, depth); \ + hevcdsp->transform_4x4_luma_add = FUNC(transform_4x4_luma_add, depth); \ + hevcdsp->transform_add[0] = FUNC(transform_4x4_add, depth); \ + hevcdsp->transform_add[1] = FUNC(transform_8x8_add, depth); \ + hevcdsp->transform_add[2] = FUNC(transform_16x16_add, depth); \ + hevcdsp->transform_add[3] = FUNC(transform_32x32_add, depth); \ + \ + hevcdsp->sao_band_filter[0] = FUNC(sao_band_filter_0, depth); \ + hevcdsp->sao_band_filter[1] = FUNC(sao_band_filter_1, depth); \ + hevcdsp->sao_band_filter[2] = FUNC(sao_band_filter_2, depth); \ + hevcdsp->sao_band_filter[3] = FUNC(sao_band_filter_3, depth); \ + \ + hevcdsp->sao_edge_filter[0] = FUNC(sao_edge_filter_0, depth); \ + hevcdsp->sao_edge_filter[1] = FUNC(sao_edge_filter_1, depth); \ + hevcdsp->sao_edge_filter[2] = FUNC(sao_edge_filter_2, depth); \ + hevcdsp->sao_edge_filter[3] = FUNC(sao_edge_filter_3, depth); \ + \ + hevcdsp->put_hevc_qpel[0][0] = FUNC(put_hevc_qpel_pixels, depth); \ + hevcdsp->put_hevc_qpel[0][1] = FUNC(put_hevc_qpel_h1, depth); \ + hevcdsp->put_hevc_qpel[0][2] = FUNC(put_hevc_qpel_h2, depth); \ + hevcdsp->put_hevc_qpel[0][3] = FUNC(put_hevc_qpel_h3, depth); \ + hevcdsp->put_hevc_qpel[1][0] = FUNC(put_hevc_qpel_v1, depth); \ + hevcdsp->put_hevc_qpel[1][1] = FUNC(put_hevc_qpel_h1v1, depth); \ + hevcdsp->put_hevc_qpel[1][2] = FUNC(put_hevc_qpel_h2v1, depth); \ + hevcdsp->put_hevc_qpel[1][3] = FUNC(put_hevc_qpel_h3v1, depth); \ + hevcdsp->put_hevc_qpel[2][0] = FUNC(put_hevc_qpel_v2, depth); \ + hevcdsp->put_hevc_qpel[2][1] = FUNC(put_hevc_qpel_h1v2, depth); \ + hevcdsp->put_hevc_qpel[2][2] = FUNC(put_hevc_qpel_h2v2, depth); \ + hevcdsp->put_hevc_qpel[2][3] = FUNC(put_hevc_qpel_h3v2, depth); \ + hevcdsp->put_hevc_qpel[3][0] = FUNC(put_hevc_qpel_v3, depth); \ + hevcdsp->put_hevc_qpel[3][1] = FUNC(put_hevc_qpel_h1v3, depth); \ + hevcdsp->put_hevc_qpel[3][2] = FUNC(put_hevc_qpel_h2v3, depth); \ + hevcdsp->put_hevc_qpel[3][3] = FUNC(put_hevc_qpel_h3v3, depth); \ + \ + hevcdsp->put_hevc_epel[0][0] = FUNC(put_hevc_epel_pixels, depth); \ + hevcdsp->put_hevc_epel[0][1] = FUNC(put_hevc_epel_h, depth); \ + hevcdsp->put_hevc_epel[1][0] = FUNC(put_hevc_epel_v, depth); \ + hevcdsp->put_hevc_epel[1][1] = FUNC(put_hevc_epel_hv, depth); \ \ - hevcdsp->sao_band_filter[0] = FUNC(sao_band_filter_0, depth); \ - hevcdsp->sao_band_filter[1] = FUNC(sao_band_filter_1, depth); \ - hevcdsp->sao_band_filter[2] = FUNC(sao_band_filter_2, depth); \ - hevcdsp->sao_band_filter[3] = FUNC(sao_band_filter_3, depth); \ \ - hevcdsp->sao_edge_filter[0] = FUNC(sao_edge_filter_0, depth); \ - hevcdsp->sao_edge_filter[1] = FUNC(sao_edge_filter_1, depth); \ - hevcdsp->sao_edge_filter[2] = FUNC(sao_edge_filter_2, depth); \ - hevcdsp->sao_edge_filter[3] = FUNC(sao_edge_filter_3, depth); \ - \ - hevcdsp->put_hevc_qpel[0][0] = FUNC(put_hevc_qpel_pixels, depth); \ - hevcdsp->put_hevc_qpel[0][1] = FUNC(put_hevc_qpel_h1, depth); \ - hevcdsp->put_hevc_qpel[0][2] = FUNC(put_hevc_qpel_h2, depth); \ - hevcdsp->put_hevc_qpel[0][3] = FUNC(put_hevc_qpel_h3, depth); \ - hevcdsp->put_hevc_qpel[1][0] = FUNC(put_hevc_qpel_v1, depth); \ - hevcdsp->put_hevc_qpel[1][1] = FUNC(put_hevc_qpel_h1v1, depth); \ - hevcdsp->put_hevc_qpel[1][2] = FUNC(put_hevc_qpel_h2v1, depth); \ - hevcdsp->put_hevc_qpel[1][3] = FUNC(put_hevc_qpel_h3v1, depth); \ - hevcdsp->put_hevc_qpel[2][0] = FUNC(put_hevc_qpel_v2, depth); \ - hevcdsp->put_hevc_qpel[2][1] = FUNC(put_hevc_qpel_h1v2, depth); \ - hevcdsp->put_hevc_qpel[2][2] = FUNC(put_hevc_qpel_h2v2, depth); \ - hevcdsp->put_hevc_qpel[2][3] = FUNC(put_hevc_qpel_h3v2, depth); \ - hevcdsp->put_hevc_qpel[3][0] = FUNC(put_hevc_qpel_v3, depth); \ - hevcdsp->put_hevc_qpel[3][1] = FUNC(put_hevc_qpel_h1v3, depth); \ - hevcdsp->put_hevc_qpel[3][2] = FUNC(put_hevc_qpel_h2v3, depth); \ - hevcdsp->put_hevc_qpel[3][3] = FUNC(put_hevc_qpel_h3v3, depth); \ - \ - hevcdsp->put_hevc_epel[0][0] = FUNC(put_hevc_epel_pixels, depth); \ - hevcdsp->put_hevc_epel[0][1] = FUNC(put_hevc_epel_h, depth); \ - hevcdsp->put_hevc_epel[1][0] = FUNC(put_hevc_epel_v, depth); \ - hevcdsp->put_hevc_epel[1][1] = FUNC(put_hevc_epel_hv, depth); \ - \ - \ - hevcdsp->put_unweighted_pred = FUNC(put_unweighted_pred, depth); \ - hevcdsp->put_weighted_pred_avg = FUNC(put_weighted_pred_avg, depth); \ - \ - hevcdsp->weighted_pred = FUNC(weighted_pred, depth); \ - hevcdsp->weighted_pred_avg = FUNC(weighted_pred_avg, depth); \ - hevcdsp->hevc_h_loop_filter_luma = FUNC(hevc_h_loop_filter_luma, depth); \ - hevcdsp->hevc_v_loop_filter_luma = FUNC(hevc_v_loop_filter_luma, depth); \ - hevcdsp->hevc_h_loop_filter_chroma = FUNC(hevc_h_loop_filter_chroma, depth); \ - hevcdsp->hevc_v_loop_filter_chroma = FUNC(hevc_v_loop_filter_chroma, depth); \ - hevcdsp->hevc_h_loop_filter_luma_c = FUNC(hevc_h_loop_filter_luma, depth); \ - hevcdsp->hevc_v_loop_filter_luma_c = FUNC(hevc_v_loop_filter_luma, depth); \ + hevcdsp->put_unweighted_pred = FUNC(put_unweighted_pred, depth); \ + hevcdsp->put_weighted_pred_avg = FUNC(put_weighted_pred_avg, depth); \ + \ + hevcdsp->weighted_pred = FUNC(weighted_pred, depth); \ + hevcdsp->weighted_pred_avg = FUNC(weighted_pred_avg, depth); \ + hevcdsp->hevc_h_loop_filter_luma = FUNC(hevc_h_loop_filter_luma, depth); \ + hevcdsp->hevc_v_loop_filter_luma = FUNC(hevc_v_loop_filter_luma, depth); \ + hevcdsp->hevc_h_loop_filter_chroma = FUNC(hevc_h_loop_filter_chroma, depth); \ + hevcdsp->hevc_v_loop_filter_chroma = FUNC(hevc_v_loop_filter_chroma, depth); \ + hevcdsp->hevc_h_loop_filter_luma_c = FUNC(hevc_h_loop_filter_luma, depth); \ + hevcdsp->hevc_v_loop_filter_luma_c = FUNC(hevc_v_loop_filter_luma, depth); \ hevcdsp->hevc_h_loop_filter_chroma_c = FUNC(hevc_h_loop_filter_chroma, depth); \ hevcdsp->hevc_v_loop_filter_chroma_c = FUNC(hevc_v_loop_filter_chroma, depth); - switch (bit_depth) { case 9: HEVC_DSP(9); diff --git a/libavcodec/hevcdsp_template.c b/libavcodec/hevcdsp_template.c index bda1dee757..b91ed3dfa9 100644 --- a/libavcodec/hevcdsp_template.c +++ b/libavcodec/hevcdsp_template.c @@ -23,9 +23,10 @@ #include "get_bits.h" #include "bit_depth_template.c" #include "hevcdsp.h" + #include "hevc.h" -#define SET(dst, x) (dst) = (x) +#define SET(dst, x) (dst) = (x) #define SCALE(dst, x) (dst) = av_clip_int16(((x) + add) >> shift) #define ADD_AND_SCALE(dst, x) (dst) = av_clip_pixel((dst) + av_clip_int16(((x) + add) >> shift)) @@ -46,7 +47,7 @@ static void FUNC(put_pcm)(uint8_t *_dst, ptrdiff_t _stride, int size, static void FUNC(transquant_bypass4x4)(uint8_t *_dst, int16_t *coeffs, ptrdiff_t _stride) { int x, y; - pixel *dst = (pixel*)_dst; + pixel *dst = (pixel *)_dst; ptrdiff_t stride = _stride / sizeof(pixel); for (y = 0; y < 4; y++) { @@ -163,8 +164,8 @@ static void FUNC(transform_4x4_luma_add)(uint8_t *_dst, int16_t *coeffs, ptrdiff #undef TR_4x4_LUMA } -#define TR_4(dst, src, dstep, sstep, assign) \ - do { \ +#define TR_4(dst, src, dstep, sstep, assign) \ + do { \ const int e0 = transform[8*0][0] * src[0*sstep] + \ transform[8*2][0] * src[2*sstep]; \ const int e1 = transform[8*0][1] * src[0*sstep] + \ @@ -207,48 +208,50 @@ static void FUNC(transform_4x4_add)(uint8_t *_dst, int16_t *coeffs, ptrdiff_t _s #define TR_8(dst, src, dstep, sstep, assign) \ do { \ - int i, j; \ - int e_8[4]; \ - int o_8[4] = { 0 }; \ - for (i = 0; i < 4; i++) \ - for (j = 1; j < 8; j += 2) \ - o_8[i] += transform[4*j][i] * src[j*sstep]; \ - TR_4(e_8, src, 1, 2*sstep, SET); \ - \ - for (i = 0; i < 4; i++) { \ - assign(dst[i*dstep], e_8[i] + o_8[i]); \ - assign(dst[(7-i)*dstep], e_8[i] - o_8[i]); \ - } \ + int i, j; \ + int e_8[4]; \ + int o_8[4] = { 0 }; \ + for (i = 0; i < 4; i++) \ + for (j = 1; j < 8; j += 2) \ + o_8[i] += transform[4 * j][i] * src[j * sstep]; \ + TR_4(e_8, src, 1, 2 * sstep, SET); \ + \ + for (i = 0; i < 4; i++) { \ + assign(dst[i * dstep], e_8[i] + o_8[i]); \ + assign(dst[(7 - i) * dstep], e_8[i] - o_8[i]); \ + } \ } while (0) -#define TR_16(dst, src, dstep, sstep, assign) \ - do { \ - int i, j; \ - int e_16[8]; \ - int o_16[8] = { 0 }; \ - for (i = 0; i < 8; i++) \ - for (j = 1; j < 16; j += 2) \ - o_16[i] += transform[2*j][i] * src[j*sstep]; \ - TR_8(e_16, src, 1, 2*sstep, SET); \ - \ - for (i = 0; i < 8; i++) { \ - assign(dst[i*dstep], e_16[i] + o_16[i]); \ - assign(dst[(15-i)*dstep], e_16[i] - o_16[i]); \ - } \ + +#define TR_16(dst, src, dstep, sstep, assign) \ + do { \ + int i, j; \ + int e_16[8]; \ + int o_16[8] = { 0 }; \ + for (i = 0; i < 8; i++) \ + for (j = 1; j < 16; j += 2) \ + o_16[i] += transform[2 * j][i] * src[j * sstep]; \ + TR_8(e_16, src, 1, 2 * sstep, SET); \ + \ + for (i = 0; i < 8; i++) { \ + assign(dst[i * dstep], e_16[i] + o_16[i]); \ + assign(dst[(15 - i) * dstep], e_16[i] - o_16[i]); \ + } \ } while (0) -#define TR_32(dst, src, dstep, sstep, assign) \ - do { \ - int i, j; \ - int e_32[16]; \ - int o_32[16] = { 0 }; \ - for (i = 0; i < 16; i++) \ - for (j = 1; j < 32; j += 2) \ - o_32[i] += transform[j][i] * src[j*sstep]; \ - TR_16(e_32, src, 1, 2*sstep, SET); \ - \ - for (i = 0; i < 16; i++) { \ - assign(dst[i*dstep], e_32[i] + o_32[i]); \ - assign(dst[(31-i)*dstep], e_32[i] - o_32[i]); \ - } \ + +#define TR_32(dst, src, dstep, sstep, assign) \ + do { \ + int i, j; \ + int e_32[16]; \ + int o_32[16] = { 0 }; \ + for (i = 0; i < 16; i++) \ + for (j = 1; j < 32; j += 2) \ + o_32[i] += transform[j][i] * src[j * sstep]; \ + TR_16(e_32, src, 1, 2 * sstep, SET); \ + \ + for (i = 0; i < 16; i++) { \ + assign(dst[i * dstep], e_32[i] + o_32[i]); \ + assign(dst[(31 - i) * dstep], e_32[i] - o_32[i]); \ + } \ } while (0) #define TR_8_1(dst, src) TR_8(dst, src, 8, 8, SCALE) @@ -262,7 +265,7 @@ static void FUNC(transform_4x4_add)(uint8_t *_dst, int16_t *coeffs, ptrdiff_t _s static void FUNC(transform_8x8_add)(uint8_t *_dst, int16_t *coeffs, ptrdiff_t _stride) { int i; - pixel *dst = (pixel*)_dst; + pixel *dst = (pixel *)_dst; ptrdiff_t stride = _stride / sizeof(pixel); int shift = 7; int add = 1 << (shift - 1); @@ -344,7 +347,7 @@ static void FUNC(transform_32x32_add)(uint8_t *_dst, int16_t *coeffs, ptrdiff_t static void FUNC(sao_band_filter)(uint8_t *_dst, uint8_t *_src, ptrdiff_t _stride, SAOParams *sao, - int *borders, int width, int height, + int *borders, int width, int height, int c_idx, int class) { pixel *dst = (pixel*)_dst; @@ -402,7 +405,8 @@ static void FUNC(sao_band_filter_0)(uint8_t *dst, uint8_t *src, int *borders, int width, int height, int c_idx) { - FUNC(sao_band_filter)(dst, src, stride, sao, borders, width, height, c_idx, 0); + FUNC(sao_band_filter)(dst, src, stride, sao, borders, + width, height, c_idx, 0); } static void FUNC(sao_band_filter_1)(uint8_t *dst, uint8_t *src, @@ -410,7 +414,8 @@ static void FUNC(sao_band_filter_1)(uint8_t *dst, uint8_t *src, int *borders, int width, int height, int c_idx) { - FUNC(sao_band_filter)(dst, src, stride, sao, borders, width, height, c_idx, 1); + FUNC(sao_band_filter)(dst, src, stride, sao, borders, + width, height, c_idx, 1); } static void FUNC(sao_band_filter_2)(uint8_t *dst, uint8_t *src, @@ -444,10 +449,10 @@ static void FUNC(sao_edge_filter_0)(uint8_t *_dst, uint8_t *_src, int sao_eo_class = sao->eo_class[c_idx]; static const int8_t pos[4][2][2] = { - {{ -1, 0}, { 1, 0}}, // horizontal - {{ 0, -1}, { 0, 1}}, // vertical - {{ -1, -1}, { 1, 1}}, // 45 degree - {{ 1, -1}, {-1, 1}}, // 135 degree + { { -1, 0 }, { 1, 0 } }, // horizontal + { { 0, -1 }, { 0, 1 } }, // vertical + { { -1, -1 }, { 1, 1 } }, // 45 degree + { { 1, -1 }, { -1, 1 } }, // 135 degree }; static const uint8_t edge_idx[] = { 1, 2, 0, 3, 4 }; @@ -469,7 +474,7 @@ static void FUNC(sao_edge_filter_0)(uint8_t *_dst, uint8_t *_src, int y_stride = 0; for (y = 0; y < height; y++) { dst[y_stride] = av_clip_pixel(src[y_stride] + offset_val); - y_stride += stride; + y_stride += stride; } init_x = 1; } @@ -478,21 +483,20 @@ static void FUNC(sao_edge_filter_0)(uint8_t *_dst, uint8_t *_src, int x_stride = width - 1; for (x = 0; x < height; x++) { dst[x_stride] = av_clip_pixel(src[x_stride] + offset_val); - x_stride += stride; + x_stride += stride; } - width --; + width--; } - } - if (sao_eo_class != SAO_EO_HORIZ ) { - if (borders[1]){ + if (sao_eo_class != SAO_EO_HORIZ) { + if (borders[1]) { int offset_val = sao_offset_val[0]; for (x = init_x; x < width; x++) { dst[x] = av_clip_pixel(src[x] + offset_val); } init_y = 1; } - if (borders[3]){ + if (borders[3]) { int offset_val = sao_offset_val[0]; int y_stride = stride * (height - 1); for (x = init_x; x < width; x++) { @@ -502,11 +506,11 @@ static void FUNC(sao_edge_filter_0)(uint8_t *_dst, uint8_t *_src, } } { - int y_stride = init_y * stride; - int pos_0_0 = pos[sao_eo_class][0][0]; - int pos_0_1 = pos[sao_eo_class][0][1]; - int pos_1_0 = pos[sao_eo_class][1][0]; - int pos_1_1 = pos[sao_eo_class][1][1]; + int y_stride = init_y * stride; + int pos_0_0 = pos[sao_eo_class][0][0]; + int pos_0_1 = pos[sao_eo_class][0][1]; + int pos_1_0 = pos[sao_eo_class][1][0]; + int pos_1_1 = pos[sao_eo_class][1][1]; int y_stride_0_1 = (init_y + pos_0_1) * stride; int y_stride_1_1 = (init_y + pos_1_1) * stride; @@ -542,22 +546,22 @@ static void FUNC(sao_edge_filter_0)(uint8_t *_dst, uint8_t *_src, static void FUNC(sao_edge_filter_1)(uint8_t *_dst, uint8_t *_src, ptrdiff_t _stride, SAOParams *sao, int *borders, int _width, int _height, - int c_idx, - uint8_t vert_edge, uint8_t horiz_edge, uint8_t diag_edge) + int c_idx, uint8_t vert_edge, + uint8_t horiz_edge, uint8_t diag_edge) { int x, y; - pixel *dst = (pixel*)_dst; - pixel *src = (pixel*)_src; + pixel *dst = (pixel *)_dst; + pixel *src = (pixel *)_src; ptrdiff_t stride = _stride / sizeof(pixel); int chroma = !!c_idx; int *sao_offset_val = sao->offset_val[c_idx]; - int sao_eo_class = sao->eo_class[c_idx]; + int sao_eo_class = sao->eo_class[c_idx]; static const int8_t pos[4][2][2] = { - {{ -1, 0}, { 1, 0 }}, // horizontal - {{ 0, -1}, { 0, 1 }}, // vertical - {{ -1, -1}, { 1, 1 }}, // 45 degree - {{ 1, -1}, {-1, 1 }}, // 135 degree + { { -1, 0 }, { 1, 0 } }, // horizontal + { { 0, -1 }, { 0, 1 } }, // vertical + { { -1, -1 }, { 1, 1 } }, // 45 degree + { { 1, -1 }, { -1, 1 } }, // 135 degree }; static const uint8_t edge_idx[] = { 1, 2, 0, 3, 4 }; @@ -579,7 +583,7 @@ static void FUNC(sao_edge_filter_1)(uint8_t *_dst, uint8_t *_src, int y_stride = 0; for (y = 0; y < height; y++) { dst[y_stride] = av_clip_pixel(src[y_stride] + offset_val); - y_stride += stride; + y_stride += stride; } init_x = 1; } @@ -588,18 +592,17 @@ static void FUNC(sao_edge_filter_1)(uint8_t *_dst, uint8_t *_src, int x_stride = width - 1; for (x = 0; x < height; x++) { dst[x_stride] = av_clip_pixel(src[x_stride] + offset_val); - x_stride += stride; + x_stride += stride; } width--; } - } { - int y_stride = init_y * stride; - int pos_0_0 = pos[sao_eo_class][0][0]; - int pos_0_1 = pos[sao_eo_class][0][1]; - int pos_1_0 = pos[sao_eo_class][1][0]; - int pos_1_1 = pos[sao_eo_class][1][1]; + int y_stride = init_y * stride; + int pos_0_0 = pos[sao_eo_class][0][0]; + int pos_0_1 = pos[sao_eo_class][0][1]; + int pos_1_0 = pos[sao_eo_class][1][0]; + int pos_1_1 = pos[sao_eo_class][1][1]; int y_stride_0_1 = (init_y + pos_0_1) * stride; int y_stride_1_1 = (init_y + pos_1_1) * stride; @@ -635,22 +638,22 @@ static void FUNC(sao_edge_filter_1)(uint8_t *_dst, uint8_t *_src, static void FUNC(sao_edge_filter_2)(uint8_t *_dst, uint8_t *_src, ptrdiff_t _stride, SAOParams *sao, int *borders, int _width, int _height, - int c_idx, - uint8_t vert_edge, uint8_t horiz_edge, uint8_t diag_edge) + int c_idx, uint8_t vert_edge, + uint8_t horiz_edge, uint8_t diag_edge) { int x, y; - pixel *dst = (pixel*)_dst; - pixel *src = (pixel*)_src; + pixel *dst = (pixel *)_dst; + pixel *src = (pixel *)_src; ptrdiff_t stride = _stride / sizeof(pixel); int chroma = !!c_idx; int *sao_offset_val = sao->offset_val[c_idx]; - int sao_eo_class = sao->eo_class[c_idx]; + int sao_eo_class = sao->eo_class[c_idx]; static const int8_t pos[4][2][2] = { - {{ -1, 0}, { 1, 0}}, // horizontal - {{ 0, -1}, { 0, 1}}, // vertical - {{ -1, -1}, { 1, 1}}, // 45 degree - {{ 1, -1}, {-1, 1}}, // 135 degree + { { -1, 0 }, { 1, 0 } }, // horizontal + { { 0, -1 }, { 0, 1 } }, // vertical + { { -1, -1 }, { 1, 1 } }, // 45 degree + { { 1, -1 }, { -1, 1 } }, // 135 degree }; static const uint8_t edge_idx[] = { 1, 2, 0, 3, 4 }; @@ -667,14 +670,14 @@ static void FUNC(sao_edge_filter_2)(uint8_t *_dst, uint8_t *_src, src = src + (init_y * stride + init_x); init_y = init_x = 0; if (sao_eo_class != SAO_EO_HORIZ) { - if (borders[1]){ + if (borders[1]) { int offset_val = sao_offset_val[0]; for (x = init_x; x < width; x++) { dst[x] = av_clip_pixel(src[x] + offset_val); } init_y = 1; } - if (borders[3]){ + if (borders[3]) { int offset_val = sao_offset_val[0]; int y_stride = stride * (height - 1); for (x = init_x; x < width; x++) { @@ -684,11 +687,11 @@ static void FUNC(sao_edge_filter_2)(uint8_t *_dst, uint8_t *_src, } } { - int y_stride = init_y * stride; - int pos_0_0 = pos[sao_eo_class][0][0]; - int pos_0_1 = pos[sao_eo_class][0][1]; - int pos_1_0 = pos[sao_eo_class][1][0]; - int pos_1_1 = pos[sao_eo_class][1][1]; + int y_stride = init_y * stride; + int pos_0_0 = pos[sao_eo_class][0][0]; + int pos_0_1 = pos[sao_eo_class][0][1]; + int pos_1_0 = pos[sao_eo_class][1][0]; + int pos_1_1 = pos[sao_eo_class][1][1]; int y_stride_0_1 = (init_y + pos_0_1) * stride; int y_stride_1_1 = (init_y + pos_1_1) * stride; @@ -723,22 +726,22 @@ static void FUNC(sao_edge_filter_2)(uint8_t *_dst, uint8_t *_src, static void FUNC(sao_edge_filter_3)(uint8_t *_dst, uint8_t *_src, ptrdiff_t _stride, SAOParams *sao, int *borders, int _width, int _height, - int c_idx, - uint8_t vert_edge, uint8_t horiz_edge, uint8_t diag_edge) + int c_idx, uint8_t vert_edge, + uint8_t horiz_edge, uint8_t diag_edge) { int x, y; - pixel *dst = (pixel*)_dst; - pixel *src = (pixel*)_src; + pixel *dst = (pixel *)_dst; + pixel *src = (pixel *)_src; ptrdiff_t stride = _stride / sizeof(pixel); int chroma = !!c_idx; int *sao_offset_val = sao->offset_val[c_idx]; int sao_eo_class = sao->eo_class[c_idx]; static const int8_t pos[4][2][2] = { - {{ -1, 0}, { 1, 0}}, // horizontal - {{ 0, -1}, { 0, 1}}, // vertical - {{ -1, -1}, { 1, 1}}, // 45 degree - {{ 1, -1}, {-1, 1}}, // 135 degree + { { -1, 0 }, { 1, 0 } }, // horizontal + { { 0, -1 }, { 0, 1 } }, // vertical + { { -1, -1 }, { 1, 1 } }, // 45 degree + { { 1, -1 }, { -1, 1 } }, // 135 degree }; static const uint8_t edge_idx[] = { 1, 2, 0, 3, 4 }; @@ -752,16 +755,16 @@ static void FUNC(sao_edge_filter_3)(uint8_t *_dst, uint8_t *_src, height = (4 >> chroma) + 2; - dst = dst + (init_y * stride + init_x); - src = src + (init_y * stride + init_x); + dst = dst + (init_y * stride + init_x); + src = src + (init_y * stride + init_x); init_y = init_x = 0; { - int y_stride = init_y * stride; - int pos_0_0 = pos[sao_eo_class][0][0]; - int pos_0_1 = pos[sao_eo_class][0][1]; - int pos_1_0 = pos[sao_eo_class][1][0]; - int pos_1_1 = pos[sao_eo_class][1][1]; + int y_stride = init_y * stride; + int pos_0_0 = pos[sao_eo_class][0][0]; + int pos_0_1 = pos[sao_eo_class][0][1]; + int pos_1_0 = pos[sao_eo_class][1][0]; + int pos_1_1 = pos[sao_eo_class][1][1]; int y_stride_0_1 = (init_y + pos_0_1) * stride; int y_stride_1_1 = (init_y + pos_1_1) * stride; @@ -815,7 +818,7 @@ static void FUNC(put_hevc_qpel_pixels)(int16_t *dst, ptrdiff_t dststride, int width, int height, int16_t* mcbuffer) { int x, y; - pixel *src = (pixel*)_src; + pixel *src = (pixel *)_src; ptrdiff_t srcstride = _srcstride / sizeof(pixel); for (y = 0; y < height; y++) { @@ -826,15 +829,17 @@ static void FUNC(put_hevc_qpel_pixels)(int16_t *dst, ptrdiff_t dststride, } } -#define QPEL_FILTER_1(src, stride) \ - (-src[x-3*stride] + 4*src[x-2*stride] - 10*src[x-stride] + 58*src[x] + \ - 17*src[x+stride] - 5*src[x+2*stride] + 1*src[x+3*stride]) -#define QPEL_FILTER_2(src, stride) \ - (-src[x-3*stride] + 4*src[x-2*stride] - 11*src[x-stride] + 40*src[x] + \ - 40*src[x+stride] - 11*src[x+2*stride] + 4*src[x+3*stride] - src[x+4*stride]) -#define QPEL_FILTER_3(src, stride) \ - (src[x-2*stride] - 5*src[x-stride] + 17*src[x] + 58*src[x+stride] \ - - 10*src[x+2*stride] + 4*src[x+3*stride] - src[x+4*stride]) +#define QPEL_FILTER_1(src, stride) \ + (-src[x - 3 * stride] + 4 * src[x - 2 * stride] - 10 * src[x - stride] + 58 * src[x] + \ + 17 * src[x + stride] - 5 * src[x + 2 * stride] + 1 * src[x + 3 * stride]) + +#define QPEL_FILTER_2(src, stride) \ + (-src[x - 3 * stride] + 4 * src[x - 2 * stride] - 11 * src[x - stride] + 40 * src[x] + \ + 40 * src[x + stride] - 11 * src[x + 2 * stride] + 4 * src[x + 3 * stride] - src[x + 4 * stride]) + +#define QPEL_FILTER_3(src, stride) \ + (src[x - 2 * stride] - 5 * src[x - stride] + 17 * src[x] + 58 * src[x + stride] \ + - 10 * src[x + 2 * stride] + 4 * src[x + 3 * stride] - src[x + 4 * stride]) #define PUT_HEVC_QPEL_H(H) \ @@ -849,7 +854,7 @@ static void FUNC(put_hevc_qpel_h ## H)(int16_t *dst, ptrdiff_t dststride, \ \ for (y = 0; y < height; y++) { \ for (x = 0; x < width; x++) \ - dst[x] = QPEL_FILTER_ ## H (src, 1) >> (BIT_DEPTH - 8); \ + dst[x] = QPEL_FILTER_ ## H(src, 1) >> (BIT_DEPTH - 8); \ src += srcstride; \ dst += dststride; \ } \ @@ -867,42 +872,42 @@ static void FUNC(put_hevc_qpel_v ## V)(int16_t *dst, ptrdiff_t dststride, \ \ for (y = 0; y < height; y++) { \ for (x = 0; x < width; x++) \ - dst[x] = QPEL_FILTER_ ## V (src, srcstride) >> (BIT_DEPTH - 8); \ + dst[x] = QPEL_FILTER_ ## V(src, srcstride) >> (BIT_DEPTH - 8); \ src += srcstride; \ dst += dststride; \ } \ } -#define PUT_HEVC_QPEL_HV(H, V) \ +#define PUT_HEVC_QPEL_HV(H, V) \ static void FUNC(put_hevc_qpel_h ## H ## v ## V)(int16_t *dst, ptrdiff_t dststride, \ uint8_t *_src, ptrdiff_t _srcstride,\ - int width, int height, \ - int16_t* mcbuffer) \ -{ \ - int x, y; \ - pixel *src = (pixel*)_src; \ - ptrdiff_t srcstride = _srcstride / sizeof(pixel); \ - \ - int16_t tmp_array[(MAX_PB_SIZE + 7)*MAX_PB_SIZE]; \ - int16_t *tmp = tmp_array; \ - \ - src -= ff_hevc_qpel_extra_before[V] * srcstride; \ - \ - for (y = 0; y < height + ff_hevc_qpel_extra[V]; y++) { \ - for (x = 0; x < width; x++) \ - tmp[x] = QPEL_FILTER_ ## H (src, 1) >> (BIT_DEPTH - 8); \ - src += srcstride; \ - tmp += MAX_PB_SIZE; \ - } \ - \ - tmp = tmp_array + ff_hevc_qpel_extra_before[V] * MAX_PB_SIZE; \ - \ - for (y = 0; y < height; y++) { \ - for (x = 0; x < width; x++) \ - dst[x] = QPEL_FILTER_ ## V (tmp, MAX_PB_SIZE) >> 6; \ - tmp += MAX_PB_SIZE; \ - dst += dststride; \ - } \ + int width, int height, \ + int16_t* mcbuffer) \ +{ \ + int x, y; \ + pixel *src = (pixel*)_src; \ + ptrdiff_t srcstride = _srcstride / sizeof(pixel); \ + \ + int16_t tmp_array[(MAX_PB_SIZE + 7) * MAX_PB_SIZE]; \ + int16_t *tmp = tmp_array; \ + \ + src -= ff_hevc_qpel_extra_before[V] * srcstride; \ + \ + for (y = 0; y < height + ff_hevc_qpel_extra[V]; y++) { \ + for (x = 0; x < width; x++) \ + tmp[x] = QPEL_FILTER_ ## H(src, 1) >> (BIT_DEPTH - 8); \ + src += srcstride; \ + tmp += MAX_PB_SIZE; \ + } \ + \ + tmp = tmp_array + ff_hevc_qpel_extra_before[V] * MAX_PB_SIZE; \ + \ + for (y = 0; y < height; y++) { \ + for (x = 0; x < width; x++) \ + dst[x] = QPEL_FILTER_ ## V(tmp, MAX_PB_SIZE) >> 6; \ + tmp += MAX_PB_SIZE; \ + dst += dststride; \ + } \ } PUT_HEVC_QPEL_H(1) @@ -927,7 +932,7 @@ static void FUNC(put_hevc_epel_pixels)(int16_t *dst, ptrdiff_t dststride, int16_t* mcbuffer) { int x, y; - pixel *src = (pixel*)_src; + pixel *src = (pixel *)_src; ptrdiff_t srcstride = _srcstride / sizeof(pixel); for (y = 0; y < height; y++) { @@ -939,8 +944,8 @@ static void FUNC(put_hevc_epel_pixels)(int16_t *dst, ptrdiff_t dststride, } } -#define EPEL_FILTER(src, stride) \ - (filter_0*src[x-stride] + filter_1*src[x] + filter_2*src[x+stride] + filter_3*src[x+2*stride]) +#define EPEL_FILTER(src, stride) \ + (filter_0 * src[x - stride] + filter_1 * src[x] + filter_2 * src[x + stride] + filter_3 * src[x + 2 * stride]) static void FUNC(put_hevc_epel_h)(int16_t *dst, ptrdiff_t dststride, uint8_t *_src, ptrdiff_t _srcstride, @@ -948,8 +953,8 @@ static void FUNC(put_hevc_epel_h)(int16_t *dst, ptrdiff_t dststride, int16_t* mcbuffer) { int x, y; - pixel *src = (pixel*)_src; - ptrdiff_t srcstride = _srcstride / sizeof(pixel); + pixel *src = (pixel *)_src; + ptrdiff_t srcstride = _srcstride / sizeof(pixel); const int8_t *filter = ff_hevc_epel_filters[mx - 1]; int8_t filter_0 = filter[0]; int8_t filter_1 = filter[1]; @@ -970,9 +975,9 @@ static void FUNC(put_hevc_epel_v)(int16_t *dst, ptrdiff_t dststride, int16_t* mcbuffer) { int x, y; - pixel *src = (pixel*)_src; + pixel *src = (pixel *)_src; ptrdiff_t srcstride = _srcstride / sizeof(pixel); - const int8_t *filter = ff_hevc_epel_filters[my-1]; + const int8_t *filter = ff_hevc_epel_filters[my - 1]; int8_t filter_0 = filter[0]; int8_t filter_1 = filter[1]; int8_t filter_2 = filter[2]; @@ -993,15 +998,15 @@ static void FUNC(put_hevc_epel_hv)(int16_t *dst, ptrdiff_t dststride, int16_t* mcbuffer) { int x, y; - pixel *src = (pixel*)_src; + pixel *src = (pixel *)_src; ptrdiff_t srcstride = _srcstride / sizeof(pixel); - const int8_t *filter_h = ff_hevc_epel_filters[mx-1]; - const int8_t *filter_v = ff_hevc_epel_filters[my-1]; + const int8_t *filter_h = ff_hevc_epel_filters[mx - 1]; + const int8_t *filter_v = ff_hevc_epel_filters[my - 1]; int8_t filter_0 = filter_h[0]; int8_t filter_1 = filter_h[1]; int8_t filter_2 = filter_h[2]; int8_t filter_3 = filter_h[3]; - int16_t tmp_array[(MAX_PB_SIZE + 3)*MAX_PB_SIZE]; + int16_t tmp_array[(MAX_PB_SIZE + 3) * MAX_PB_SIZE]; int16_t *tmp = tmp_array; src -= EPEL_EXTRA_BEFORE * srcstride; @@ -1014,7 +1019,7 @@ static void FUNC(put_hevc_epel_hv)(int16_t *dst, ptrdiff_t dststride, tmp += MAX_PB_SIZE; } - tmp = tmp_array + EPEL_EXTRA_BEFORE * MAX_PB_SIZE; + tmp = tmp_array + EPEL_EXTRA_BEFORE * MAX_PB_SIZE; filter_0 = filter_v[0]; filter_1 = filter_v[1]; filter_2 = filter_v[2]; @@ -1033,7 +1038,7 @@ static void FUNC(put_unweighted_pred)(uint8_t *_dst, ptrdiff_t _dststride, int width, int height) { int x, y; - pixel *dst = (pixel*)_dst; + pixel *dst = (pixel *)_dst; ptrdiff_t dststride = _dststride / sizeof(pixel); int shift = 14 - BIT_DEPTH; @@ -1057,7 +1062,7 @@ static void FUNC(put_weighted_pred_avg)(uint8_t *_dst, ptrdiff_t _dststride, int width, int height) { int x, y; - pixel *dst = (pixel*)_dst; + pixel *dst = (pixel *)_dst; ptrdiff_t dststride = _dststride / sizeof(pixel); int shift = 14 + 1 - BIT_DEPTH; @@ -1088,14 +1093,14 @@ static void FUNC(weighted_pred)(uint8_t denom, int16_t wlxFlag, int16_t olxFlag, int ox; int x , y; int offset; - pixel *dst = (pixel*)_dst; + pixel *dst = (pixel *)_dst; ptrdiff_t dststride = _dststride / sizeof(pixel); shift = 14 - BIT_DEPTH; log2Wd = denom + shift; offset = 1 << (log2Wd - 1); - wx = wlxFlag; - ox = olxFlag * (1 << (BIT_DEPTH - 8)); + wx = wlxFlag; + ox = olxFlag * (1 << (BIT_DEPTH - 8)); for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { @@ -1105,15 +1110,17 @@ static void FUNC(weighted_pred)(uint8_t denom, int16_t wlxFlag, int16_t olxFlag, dst[x] = av_clip_pixel(src[x] * wx + ox); } } - dst += dststride; - src += srcstride; + dst += dststride; + src += srcstride; } } -static void FUNC(weighted_pred_avg)(uint8_t denom, int16_t wl0Flag, int16_t wl1Flag, +static void FUNC(weighted_pred_avg)(uint8_t denom, + int16_t wl0Flag, int16_t wl1Flag, int16_t ol0Flag, int16_t ol1Flag, uint8_t *_dst, ptrdiff_t _dststride, - int16_t *src1, int16_t *src2, ptrdiff_t srcstride, + int16_t *src1, int16_t *src2, + ptrdiff_t srcstride, int width, int height) { int shift; @@ -1123,13 +1130,13 @@ static void FUNC(weighted_pred_avg)(uint8_t denom, int16_t wl0Flag, int16_t wl1F int o0; int o1; int x , y; - pixel *dst = (pixel*)_dst; + pixel *dst = (pixel *)_dst; ptrdiff_t dststride = _dststride / sizeof(pixel); shift = 14 - BIT_DEPTH; log2Wd = denom + shift; - w0 = wl0Flag; - w1 = wl1Flag; + w0 = wl0Flag; + w1 = wl1Flag; o0 = (ol0Flag) * (1 << (BIT_DEPTH - 8)); o1 = (ol1Flag) * (1 << (BIT_DEPTH - 8)); @@ -1145,43 +1152,44 @@ static void FUNC(weighted_pred_avg)(uint8_t denom, int16_t wl0Flag, int16_t wl1F } // line zero -#define P3 pix[-4*xstride] -#define P2 pix[-3*xstride] -#define P1 pix[-2*xstride] +#define P3 pix[-4 * xstride] +#define P2 pix[-3 * xstride] +#define P1 pix[-2 * xstride] #define P0 pix[-xstride] #define Q0 pix[0] #define Q1 pix[xstride] -#define Q2 pix[2*xstride] -#define Q3 pix[3*xstride] +#define Q2 pix[2 * xstride] +#define Q3 pix[3 * xstride] // line three. used only for deblocking decision -#define TP3 pix[-4*xstride+3*ystride] -#define TP2 pix[-3*xstride+3*ystride] -#define TP1 pix[-2*xstride+3*ystride] -#define TP0 pix[-xstride+3*ystride] -#define TQ0 pix[3*ystride] -#define TQ1 pix[xstride+3*ystride] -#define TQ2 pix[2*xstride+3*ystride] -#define TQ3 pix[3*xstride+3*ystride] - -static void FUNC(hevc_loop_filter_luma)(uint8_t *_pix, ptrdiff_t _xstride, - ptrdiff_t _ystride, int *_beta, int *_tc, +#define TP3 pix[-4 * xstride + 3 * ystride] +#define TP2 pix[-3 * xstride + 3 * ystride] +#define TP1 pix[-2 * xstride + 3 * ystride] +#define TP0 pix[-xstride+3 * ystride] +#define TQ0 pix[3 * ystride] +#define TQ1 pix[xstride+3 * ystride] +#define TQ2 pix[2 * xstride + 3 * ystride] +#define TQ3 pix[3 * xstride + 3 * ystride] + +static void FUNC(hevc_loop_filter_luma)(uint8_t *_pix, + ptrdiff_t _xstride, ptrdiff_t _ystride, + int *_beta, int *_tc, uint8_t *_no_p, uint8_t *_no_q) { int d, j; - pixel *pix = (pixel*)_pix; + pixel *pix = (pixel *)_pix; ptrdiff_t xstride = _xstride / sizeof(pixel); ptrdiff_t ystride = _ystride / sizeof(pixel); for (j = 0; j < 2; j++) { - const int dp0 = abs(P2 - 2 * P1 + P0); - const int dq0 = abs(Q2 - 2 * Q1 + Q0); + const int dp0 = abs(P2 - 2 * P1 + P0); + const int dq0 = abs(Q2 - 2 * Q1 + Q0); const int dp3 = abs(TP2 - 2 * TP1 + TP0); const int dq3 = abs(TQ2 - 2 * TQ1 + TQ0); const int d0 = dp0 + dq0; const int d3 = dp3 + dq3; int beta = _beta[j] << (BIT_DEPTH - 8); - const int tc = _tc[j] << (BIT_DEPTH - 8); + const int tc = _tc[j] << (BIT_DEPTH - 8); const int no_p = _no_p[j]; const int no_q = _no_q[j]; @@ -1191,9 +1199,9 @@ static void FUNC(hevc_loop_filter_luma)(uint8_t *_pix, ptrdiff_t _xstride, } else { const int beta_3 = beta >> 3; const int beta_2 = beta >> 2; - const int tc25 = ((tc * 5 + 1) >> 1); + const int tc25 = ((tc * 5 + 1) >> 1); - if (abs( P3 - P0) + abs( Q3 - Q0) < beta_3 && abs( P0 - Q0) < tc25 && + if (abs(P3 - P0) + abs(Q3 - Q0) < beta_3 && abs(P0 - Q0) < tc25 && abs(TP3 - TP0) + abs(TQ3 - TQ0) < beta_3 && abs(TP0 - TQ0) < tc25 && (d0 << 1) < beta_2 && (d3 << 1) < beta_2) { // strong filtering @@ -1208,14 +1216,14 @@ static void FUNC(hevc_loop_filter_luma)(uint8_t *_pix, ptrdiff_t _xstride, const int q2 = Q2; const int q3 = Q3; if (!no_p) { - P0 = p0 + av_clip((( p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4 ) >> 3) - p0, -tc2, tc2); - P1 = p1 + av_clip((( p2 + p1 + p0 + q0 + 2 ) >> 2) - p1, -tc2, tc2); - P2 = p2 + av_clip((( 2*p3 + 3*p2 + p1 + p0 + q0 + 4 ) >> 3) - p2, -tc2, tc2); + P0 = p0 + av_clip(((p2 + 2 * p1 + 2 * p0 + 2 * q0 + q1 + 4) >> 3) - p0, -tc2, tc2); + P1 = p1 + av_clip(((p2 + p1 + p0 + q0 + 2) >> 2) - p1, -tc2, tc2); + P2 = p2 + av_clip(((2 * p3 + 3 * p2 + p1 + p0 + q0 + 4) >> 3) - p2, -tc2, tc2); } if (!no_q) { - Q0 = q0 + av_clip((( p1 + 2*p0 + 2*q0 + 2*q1 + q2 + 4 ) >> 3) - q0, -tc2, tc2); - Q1 = q1 + av_clip((( p0 + q0 + q1 + q2 + 2 ) >> 2) - q1, -tc2, tc2); - Q2 = q2 + av_clip((( 2*q3 + 3*q2 + q1 + q0 + p0 + 4 ) >> 3) - q2, -tc2, tc2); + Q0 = q0 + av_clip(((p1 + 2 * p0 + 2 * q0 + 2 * q1 + q2 + 4) >> 3) - q0, -tc2, tc2); + Q1 = q1 + av_clip(((p0 + q0 + q1 + q2 + 2) >> 2) - q1, -tc2, tc2); + Q2 = q2 + av_clip(((2 * q3 + 3 * q2 + q1 + q0 + p0 + 4) >> 3) - q2, -tc2, tc2); } pix += ystride; } @@ -1235,7 +1243,7 @@ static void FUNC(hevc_loop_filter_luma)(uint8_t *_pix, ptrdiff_t _xstride, const int q0 = Q0; const int q1 = Q1; const int q2 = Q2; - int delta0 = (9 * (q0 - p0) - 3 * (q1 - p1) + 8) >> 4; + int delta0 = (9 * (q0 - p0) - 3 * (q1 - p1) + 8) >> 4; if (abs(delta0) < 10 * tc) { delta0 = av_clip(delta0, -tc, tc); if (!no_p) @@ -1264,7 +1272,7 @@ static void FUNC(hevc_loop_filter_chroma)(uint8_t *_pix, ptrdiff_t _xstride, { int d, j; int no_p, no_q; - pixel *pix = (pixel*)_pix; + pixel *pix = (pixel *)_pix; ptrdiff_t xstride = _xstride / sizeof(pixel); ptrdiff_t ystride = _ystride / sizeof(pixel); @@ -1294,13 +1302,15 @@ static void FUNC(hevc_loop_filter_chroma)(uint8_t *_pix, ptrdiff_t _xstride, } static void FUNC(hevc_h_loop_filter_chroma)(uint8_t *pix, ptrdiff_t stride, - int *tc, uint8_t *no_p, uint8_t *no_q) + int *tc, uint8_t *no_p, + uint8_t *no_q) { FUNC(hevc_loop_filter_chroma)(pix, stride, sizeof(pixel), tc, no_p, no_q); } static void FUNC(hevc_v_loop_filter_chroma)(uint8_t *pix, ptrdiff_t stride, - int *tc, uint8_t *no_p, uint8_t *no_q) + int *tc, uint8_t *no_p, + uint8_t *no_q) { FUNC(hevc_loop_filter_chroma)(pix, sizeof(pixel), stride, tc, no_p, no_q); } @@ -1309,14 +1319,16 @@ static void FUNC(hevc_h_loop_filter_luma)(uint8_t *pix, ptrdiff_t stride, int *beta, int *tc, uint8_t *no_p, uint8_t *no_q) { - FUNC(hevc_loop_filter_luma)(pix, stride, sizeof(pixel), beta, tc, no_p, no_q); + FUNC(hevc_loop_filter_luma)(pix, stride, sizeof(pixel), + beta, tc, no_p, no_q); } static void FUNC(hevc_v_loop_filter_luma)(uint8_t *pix, ptrdiff_t stride, int *beta, int *tc, uint8_t *no_p, uint8_t *no_q) { - FUNC(hevc_loop_filter_luma)(pix, sizeof(pixel), stride, beta, tc, no_p, no_q); + FUNC(hevc_loop_filter_luma)(pix, sizeof(pixel), stride, + beta, tc, no_p, no_q); } #undef P3 diff --git a/libavcodec/hevcpred.c b/libavcodec/hevcpred.c index b6b3906406..4ab885634d 100644 --- a/libavcodec/hevcpred.c +++ b/libavcodec/hevcpred.c @@ -40,16 +40,16 @@ void ff_hevc_pred_init(HEVCPredContext *hpc, int bit_depth) #undef FUNC #define FUNC(a, depth) a ## _ ## depth -#define HEVC_PRED(depth) \ - hpc->intra_pred = FUNC(intra_pred, depth); \ +#define HEVC_PRED(depth) \ + hpc->intra_pred = FUNC(intra_pred, depth); \ hpc->pred_planar[0] = FUNC(pred_planar_0, depth); \ hpc->pred_planar[1] = FUNC(pred_planar_1, depth); \ hpc->pred_planar[2] = FUNC(pred_planar_2, depth); \ hpc->pred_planar[3] = FUNC(pred_planar_3, depth); \ - hpc->pred_dc = FUNC(pred_dc, depth); \ - hpc->pred_angular[0] = FUNC(pred_angular_0, depth);\ - hpc->pred_angular[1] = FUNC(pred_angular_1, depth);\ - hpc->pred_angular[2] = FUNC(pred_angular_2, depth);\ + hpc->pred_dc = FUNC(pred_dc, depth); \ + hpc->pred_angular[0] = FUNC(pred_angular_0, depth); \ + hpc->pred_angular[1] = FUNC(pred_angular_1, depth); \ + hpc->pred_angular[2] = FUNC(pred_angular_2, depth); \ hpc->pred_angular[3] = FUNC(pred_angular_3, depth); switch (bit_depth) { diff --git a/libavcodec/hevcpred_template.c b/libavcodec/hevcpred_template.c index 8a338499a2..86097234f3 100644 --- a/libavcodec/hevcpred_template.c +++ b/libavcodec/hevcpred_template.c @@ -92,9 +92,9 @@ static void FUNC(intra_pred)(HEVCContext *s, int x0, int y0, int log2_size, int pixel filtered_top_array[2 * MAX_TB_SIZE + 1]; pixel *left = left_array + 1; - pixel *top = top_array + 1; + pixel *top = top_array + 1; pixel *filtered_left = filtered_left_array + 1; - pixel *filtered_top = filtered_top_array + 1; + pixel *filtered_top = filtered_top_array + 1; int cand_bottom_left = lc->na.cand_bottom_left && cur_tb_addr > MIN_TB_ADDR_ZS(x_tb - 1, y_tb + size_in_tbs); int cand_left = lc->na.cand_left; @@ -109,9 +109,9 @@ static void FUNC(intra_pred)(HEVCContext *s, int x0, int y0, int log2_size, int if (s->pps->constrained_intra_pred_flag == 1) { int size_in_luma_pu = PU(size_in_luma); - int on_pu_edge_x = !(x0 & ((1 << s->sps->log2_min_pu_size) - 1)); - int on_pu_edge_y = !(y0 & ((1 << s->sps->log2_min_pu_size) - 1)); - if(!size_in_luma_pu) + int on_pu_edge_x = !(x0 & ((1 << s->sps->log2_min_pu_size) - 1)); + int on_pu_edge_y = !(y0 & ((1 << s->sps->log2_min_pu_size) - 1)); + if (!size_in_luma_pu) size_in_luma_pu++; if (cand_bottom_left == 1 && on_pu_edge_x) { int x_left_pu = PU(x0 - 1); @@ -157,7 +157,8 @@ static void FUNC(intra_pred)(HEVCContext *s, int x0, int y0, int log2_size, int } if (cand_bottom_left) { for (i = size + bottom_left_size; i < (size << 1); i++) - if (IS_INTRA(-1, size + bottom_left_size - 1) || !s->pps->constrained_intra_pred_flag) + if (IS_INTRA(-1, size + bottom_left_size - 1) || + !s->pps->constrained_intra_pred_flag) left[i] = POS(-1, size + bottom_left_size - 1); for (i = size + bottom_left_size - 1; i >= size; i--) if (IS_INTRA(-1, i) || !s->pps->constrained_intra_pred_flag) @@ -178,7 +179,8 @@ static void FUNC(intra_pred)(HEVCContext *s, int x0, int y0, int log2_size, int top[i] = POS(i, -1); if (cand_up_right) { for (i = size + top_right_size; i < (size << 1); i++) - if (IS_INTRA(size + top_right_size - 1, -1) || !s->pps->constrained_intra_pred_flag) + if (IS_INTRA(size + top_right_size - 1, -1) || + !s->pps->constrained_intra_pred_flag) top[i] = POS(size + top_right_size - 1, -1); for (i = size + top_right_size - 1; i >= size; i--) if (IS_INTRA(i, -1) || !s->pps->constrained_intra_pred_flag) @@ -201,29 +203,32 @@ static void FUNC(intra_pred)(HEVCContext *s, int x0, int y0, int log2_size, int size : (s->sps->height - y0) >> vshift; } if (cand_bottom_left || cand_left || cand_up_left) { - while (j>-1 && !IS_INTRA(-1, j)) j--; + while (j > -1 && !IS_INTRA(-1, j)) + j--; if (!IS_INTRA(-1, j)) { j = 0; - while(j < size_max_x && !IS_INTRA(j, -1)) j++; - EXTEND_LEFT_CIP(top, j, j+1); + while (j < size_max_x && !IS_INTRA(j, -1)) + j++; + EXTEND_LEFT_CIP(top, j, j + 1); left[-1] = top[-1]; - j = 0; + j = 0; } } else { j = 0; - while (j < size_max_x && !IS_INTRA(j, -1)) j++; + while (j < size_max_x && !IS_INTRA(j, -1)) + j++; if (j > 0) if (x0 > 0) { - EXTEND_LEFT_CIP(top, j, j+1); + EXTEND_LEFT_CIP(top, j, j + 1); } else { EXTEND_LEFT_CIP(top, j, j); top[-1] = top[0]; } left[-1] = top[-1]; - j = 0; + j = 0; } if (cand_bottom_left || cand_left) { - EXTEND_DOWN_CIP(left, j, size_max_y-j); + EXTEND_DOWN_CIP(left, j, size_max_y - j); } if (!cand_left) { EXTEND_DOWN(left, 0, size); @@ -233,10 +238,10 @@ static void FUNC(intra_pred)(HEVCContext *s, int x0, int y0, int log2_size, int } if (x0 != 0 && y0 != 0) { EXTEND_UP_CIP(left, size_max_y - 1, size_max_y); - } else if( x0 == 0) { + } else if (x0 == 0) { EXTEND_UP_CIP_0(left, size_max_y - 1, size_max_y); - } else{ - EXTEND_UP_CIP(left, size_max_y - 1, size_max_y-1); + } else { + EXTEND_UP_CIP(left, size_max_y - 1, size_max_y - 1); } top[-1] = left[-1]; if (y0 != 0) { @@ -255,14 +260,14 @@ static void FUNC(intra_pred)(HEVCContext *s, int x0, int y0, int log2_size, int left[-1] = top[0]; EXTEND_DOWN(left, 0, 2 * size); cand_up_left = 1; - cand_left = 1; + cand_left = 1; } else if (cand_up_right) { EXTEND_LEFT(top, size, size); left[-1] = top[0]; - EXTEND_DOWN(left ,0 , 2 * size); - cand_up = 1; + EXTEND_DOWN(left, 0, 2 * size); + cand_up = 1; cand_up_left = 1; - cand_left = 1; + cand_left = 1; } else { // No samples available top[0] = left[-1] = (1 << (BIT_DEPTH - 1)); EXTEND_RIGHT(top, 1, 2 * size - 1); @@ -278,7 +283,7 @@ static void FUNC(intra_pred)(HEVCContext *s, int x0, int y0, int log2_size, int } if (!cand_up) { top[0] = left[-1]; - EXTEND_RIGHT(top, 1, size-1); + EXTEND_RIGHT(top, 1, size - 1); } if (!cand_up_right) { EXTEND_RIGHT(top, size, size); @@ -303,13 +308,13 @@ static void FUNC(intra_pred)(HEVCContext *s, int x0, int y0, int log2_size, int // Filtering process if (c_idx == 0 && mode != INTRA_DC && size != 4) { int intra_hor_ver_dist_thresh[] = { 7, 1, 0 }; - int min_dist_vert_hor = FFMIN(FFABS((int)(mode - 26U)), + int min_dist_vert_hor = FFMIN(FFABS((int)(mode - 26U)), FFABS((int)(mode - 10U))); if (min_dist_vert_hor > intra_hor_ver_dist_thresh[log2_size - 3]) { int threshold = 1 << (BIT_DEPTH - 5); if (s->sps->sps_strong_intra_smoothing_enable_flag && log2_size == 5 && - FFABS(top[-1] + top[63] - 2 * top[31]) < threshold && + FFABS(top[-1] + top[63] - 2 * top[31]) < threshold && FFABS(left[-1] + left[63] - 2 * left[31]) < threshold) { // We can't just overwrite values in top because it could be // a pointer into src @@ -328,9 +333,8 @@ static void FUNC(intra_pred)(HEVCContext *s, int x0, int y0, int log2_size, int for (i = 2 * size - 2; i >= 0; i--) filtered_left[i] = (left[i + 1] + 2 * left[i] + left[i - 1] + 2) >> 2; - filtered_top[-1] = - filtered_left[-1] = (left[0] + 2 * left[-1] + - top[0] + 2) >> 2; + filtered_top[-1] = + filtered_left[-1] = (left[0] + 2 * left[-1] + top[0] + 2) >> 2; for (i = 2 * size - 2; i >= 0; i--) filtered_top[i] = (top[i + 1] + 2 * top[i] + top[i - 1] + 2) >> 2; @@ -342,16 +346,17 @@ static void FUNC(intra_pred)(HEVCContext *s, int x0, int y0, int log2_size, int switch (mode) { case INTRA_PLANAR: - s->hpc.pred_planar[log2_size - 2]((uint8_t*)src, (uint8_t*)top, - (uint8_t*)left, stride); + s->hpc.pred_planar[log2_size - 2]((uint8_t *)src, (uint8_t *)top, + (uint8_t *)left, stride); break; case INTRA_DC: - s->hpc.pred_dc((uint8_t*)src, (uint8_t*)top, - (uint8_t*)left, stride, log2_size, c_idx); + s->hpc.pred_dc((uint8_t *)src, (uint8_t *)top, + (uint8_t *)left, stride, log2_size, c_idx); break; default: - s->hpc.pred_angular[log2_size - 2]((uint8_t*)src, (uint8_t*)top, - (uint8_t*)left, stride, c_idx, mode); + s->hpc.pred_angular[log2_size - 2]((uint8_t *)src, (uint8_t *)top, + (uint8_t *)left, stride, c_idx, + mode); break; } } @@ -361,52 +366,52 @@ static void FUNC(pred_planar_0)(uint8_t *_src, const uint8_t *_top, ptrdiff_t stride) { int x, y; - pixel *src = (pixel*)_src; - const pixel *top = (const pixel*)_top; - const pixel *left = (const pixel*)_left; + pixel *src = (pixel *)_src; + const pixel *top = (const pixel *)_top; + const pixel *left = (const pixel *)_left; for (y = 0; y < 4; y++) for (x = 0; x < 4; x++) - POS(x, y) = ((3 - x) * left[y] + (x + 1) * top[4] + - (3 - y) * top[x] + (y + 1) * left[4] + 4) >> 3; + POS(x, y) = ((3 - x) * left[y] + (x + 1) * top[4] + + (3 - y) * top[x] + (y + 1) * left[4] + 4) >> 3; } static void FUNC(pred_planar_1)(uint8_t *_src, const uint8_t *_top, const uint8_t *_left, ptrdiff_t stride) { int x, y; - pixel *src = (pixel*)_src; - const pixel *top = (const pixel*)_top; - const pixel *left = (const pixel*)_left; + pixel *src = (pixel *)_src; + const pixel *top = (const pixel *)_top; + const pixel *left = (const pixel *)_left; for (y = 0; y < 8; y++) for (x = 0; x < 8; x++) - POS(x, y) = ((7 - x) * left[y] + (x + 1) * top[8] + - (7 - y) * top[x] + (y + 1) * left[8] + 8) >> 4; + POS(x, y) = ((7 - x) * left[y] + (x + 1) * top[8] + + (7 - y) * top[x] + (y + 1) * left[8] + 8) >> 4; } static void FUNC(pred_planar_2)(uint8_t *_src, const uint8_t *_top, const uint8_t *_left, ptrdiff_t stride) { int x, y; - pixel *src = (pixel*)_src; - const pixel *top = (const pixel*)_top; - const pixel *left = (const pixel*)_left; + pixel *src = (pixel *)_src; + const pixel *top = (const pixel *)_top; + const pixel *left = (const pixel *)_left; for (y = 0; y < 16; y++) for (x = 0; x < 16; x++) - POS(x, y) = ((15 - x) * left[y] + (x + 1) * top[16] + - (15 - y) * top[x] + (y + 1) * left[16] + 16) >> 5; + POS(x, y) = ((15 - x) * left[y] + (x + 1) * top[16] + + (15 - y) * top[x] + (y + 1) * left[16] + 16) >> 5; } static void FUNC(pred_planar_3)(uint8_t *_src, const uint8_t *_top, const uint8_t *_left, ptrdiff_t stride) { int x, y; - pixel *src = (pixel*)_src; - const pixel *top = (const pixel*)_top; - const pixel *left = (const pixel*)_left; + pixel *src = (pixel *)_src; + const pixel *top = (const pixel *)_top; + const pixel *left = (const pixel *)_left; for (y = 0; y < 32; y++) for (x = 0; x < 32; x++) - POS(x, y) = ((31 - x) * left[y] + (x + 1) * top[32] + - (31 - y) * top[x] + (y + 1) * left[32] + 32) >> 6; + POS(x, y) = ((31 - x) * left[y] + (x + 1) * top[32] + + (31 - y) * top[x] + (y + 1) * left[32] + 32) >> 6; } static void FUNC(pred_dc)(uint8_t *_src, const uint8_t *_top, @@ -414,11 +419,11 @@ static void FUNC(pred_dc)(uint8_t *_src, const uint8_t *_top, ptrdiff_t stride, int log2_size, int c_idx) { int i, j, x, y; - int size = (1 << log2_size); - pixel *src = (pixel*)_src; - const pixel *top = (const pixel*)_top; - const pixel *left = (const pixel*)_left; - int dc = size; + int size = (1 << log2_size); + pixel *src = (pixel *)_src; + const pixel *top = (const pixel *)_top; + const pixel *left = (const pixel *)_left; + int dc = size; pixel4 a; for (i = 0; i < size; i++) dc += left[i] + top[i]; @@ -432,7 +437,7 @@ static void FUNC(pred_dc)(uint8_t *_src, const uint8_t *_top, AV_WN4PA(&POS(j * 4, i), a); if (c_idx == 0 && size < 32) { - POS(0, 0) = (left[0] + 2 * dc + top[0] + 2) >> 2; + POS(0, 0) = (left[0] + 2 * dc + top[0] + 2) >> 2; for (x = 1; x < size; x++) POS(x, 0) = (top[x] + 3 * dc + 2) >> 2; for (y = 1; y < size; y++) @@ -447,13 +452,13 @@ static av_always_inline void FUNC(pred_angular)(uint8_t *_src, int mode, int size) { int x, y; - pixel *src = (pixel*)_src; - const pixel *top = (const pixel*)_top; - const pixel *left = (const pixel*)_left; + pixel *src = (pixel *)_src; + const pixel *top = (const pixel *)_top; + const pixel *left = (const pixel *)_left; static const int intra_pred_angle[] = { - 32, 26, 21, 17, 13, 9, 5, 2, 0, -2, -5, -9, -13, -17, -21, -26, -32, - -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 + 32, 26, 21, 17, 13, 9, 5, 2, 0, -2, -5, -9, -13, -17, -21, -26, -32, + -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 }; static const int inv_angle[] = { -4096, -1638, -910, -630, -482, -390, -315, -256, -315, -390, -482, @@ -472,7 +477,7 @@ static av_always_inline void FUNC(pred_angular)(uint8_t *_src, for (x = 0; x <= size; x++) ref_tmp[x] = top[x - 1]; for (x = last; x <= -1; x++) - ref_tmp[x] = left[-1 + ((x * inv_angle[mode-11] + 128) >> 8)]; + ref_tmp[x] = left[-1 + ((x * inv_angle[mode - 11] + 128) >> 8)]; ref = ref_tmp; } @@ -500,7 +505,7 @@ static av_always_inline void FUNC(pred_angular)(uint8_t *_src, for (x = 0; x <= size; x++) ref_tmp[x] = left[x - 1]; for (x = last; x <= -1; x++) - ref_tmp[x] = top[-1 + ((x * inv_angle[mode-11] + 128) >> 8)]; + ref_tmp[x] = top[-1 + ((x * inv_angle[mode - 11] + 128) >> 8)]; ref = ref_tmp; }