From 2451e47dcafc0f607baa23a023963f057d5fd52f Mon Sep 17 00:00:00 2001 From: skal Date: Wed, 15 May 2013 20:03:15 +0200 Subject: [PATCH] misc code cleanup * remove dec->skip_ * fix some naming (no speed diff observed) Change-Id: I12545ef79d29dd6f893c344d8fb171b0a8c7cc46 --- src/dec/frame.c | 22 +++++++++++----------- src/dec/vp8.c | 32 ++++++++++++++++---------------- src/dec/vp8i.h | 7 +++---- 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/src/dec/frame.c b/src/dec/frame.c index 5163daaf..316dde79 100644 --- a/src/dec/frame.c +++ b/src/dec/frame.c @@ -534,7 +534,7 @@ static const int kScan[16] = { 0 + 12 * BPS, 4 + 12 * BPS, 8 + 12 * BPS, 12 + 12 * BPS }; -static WEBP_INLINE int CheckMode(int mb_x, int mb_y, int mode) { +static int CheckMode(int mb_x, int mb_y, int mode) { if (mode == B_DC_PRED) { if (mb_x == 0) { return (mb_y == 0) ? B_DC_PRED_NOTOPLEFT : B_DC_PRED_NOLEFT; @@ -545,11 +545,11 @@ static WEBP_INLINE int CheckMode(int mb_x, int mb_y, int mode) { return mode; } -static WEBP_INLINE void Copy32b(uint8_t* dst, uint8_t* src) { - *(uint32_t*)dst = *(uint32_t*)src; +static void Copy32b(uint8_t* dst, uint8_t* src) { + memcpy(dst, src, 4); } -void VP8ReconstructBlock(VP8Decoder* const dec) { +void VP8ReconstructBlock(const VP8Decoder* const dec) { int j; uint8_t* const y_dst = dec->yuv_b_ + Y_OFF; uint8_t* const u_dst = dec->yuv_b_ + U_OFF; @@ -583,7 +583,7 @@ void VP8ReconstructBlock(VP8Decoder* const dec) { uint8_t* const top_y = dec->y_t_ + dec->mb_x_ * 16; uint8_t* const top_u = dec->u_t_ + dec->mb_x_ * 8; uint8_t* const top_v = dec->v_t_ + dec->mb_x_ * 8; - const int16_t* coeffs = dec->coeffs_; + const int16_t* const coeffs = dec->coeffs_; int n; if (dec->mb_y_ > 0) { @@ -659,13 +659,13 @@ void VP8ReconstructBlock(VP8Decoder* const dec) { VP8TransformDCUV(v_coeffs, v_dst); } } + } - // stash away top samples for next block - if (dec->mb_y_ < dec->mb_h_ - 1) { - memcpy(top_y, y_dst + 15 * BPS, 16); - memcpy(top_u, u_dst + 7 * BPS, 8); - memcpy(top_v, v_dst + 7 * BPS, 8); - } + // stash away top samples for next block + if (dec->mb_y_ < dec->mb_h_ - 1) { + memcpy(top_y, y_dst + 15 * BPS, 16); + memcpy(top_u, u_dst + 7 * BPS, 8); + memcpy(top_v, v_dst + 7 * BPS, 8); } } // Transfer reconstructed samples from yuv_b_ cache to final destination. diff --git a/src/dec/vp8.c b/src/dec/vp8.c index 6fb6ce02..225b4f75 100644 --- a/src/dec/vp8.c +++ b/src/dec/vp8.c @@ -524,11 +524,11 @@ static const PackedNz kUnpackTab[16] = { #endif #define PACK(X, S) ((((X).i32 * PACK_CST) & 0xff000000) >> (S)) -static void ParseResiduals(VP8Decoder* const dec, - VP8MB* const mb, VP8BitReader* const token_br) { +static int ParseResiduals(VP8Decoder* const dec, + VP8MB* const mb, VP8BitReader* const token_br) { int out_t_nz, out_l_nz, first; ProbaArray ac_prob; - const VP8QuantMatrix* q = &dec->dqm_[dec->segment_]; + const VP8QuantMatrix* const q = &dec->dqm_[dec->segment_]; int16_t* dst = dec->coeffs_; VP8MB* const left_mb = dec->mb_info_ - 1; PackedNz nz_ac, nz_dc; @@ -537,12 +537,11 @@ static void ParseResiduals(VP8Decoder* const dec, uint32_t non_zero_dc = 0; int x, y, ch; - nz_dc.i32 = nz_ac.i32 = 0; memset(dst, 0, 384 * sizeof(*dst)); if (!dec->is_i4x4_) { // parse DC int16_t dc[16] = { 0 }; - const int ctx = mb->dc_nz_ + left_mb->dc_nz_; - mb->dc_nz_ = left_mb->dc_nz_ = + const int ctx = mb->nz_dc_ + left_mb->nz_dc_; + mb->nz_dc_ = left_mb->nz_dc_ = (GetCoeffs(token_br, (ProbaArray)dec->proba_.coeffs_[1], ctx, q->y2_mat_, 0, dc) > 0); first = 1; @@ -600,7 +599,7 @@ static void ParseResiduals(VP8Decoder* const dec, dec->non_zero_ac_ = non_zero_ac; dec->non_zero_ = non_zero_ac | non_zero_dc; - mb->skip_ = !dec->non_zero_; + return !dec->non_zero_; // will be used for further optimization } #undef PACK @@ -610,7 +609,8 @@ static void ParseResiduals(VP8Decoder* const dec, int VP8DecodeMB(VP8Decoder* const dec, VP8BitReader* const token_br) { VP8BitReader* const br = &dec->br_; VP8MB* const left = dec->mb_info_ - 1; - VP8MB* const info = dec->mb_info_ + dec->mb_x_; + VP8MB* const mb = dec->mb_info_ + dec->mb_x_; + int skip; // Note: we don't save segment map (yet), as we don't expect // to decode more than 1 keyframe. @@ -620,19 +620,19 @@ int VP8DecodeMB(VP8Decoder* const dec, VP8BitReader* const token_br) { VP8GetBit(br, dec->proba_.segments_[1]) : 2 + VP8GetBit(br, dec->proba_.segments_[2]); } - info->skip_ = dec->use_skip_proba_ ? VP8GetBit(br, dec->skip_p_) : 0; + skip = dec->use_skip_proba_ ? VP8GetBit(br, dec->skip_p_) : 0; VP8ParseIntraMode(br, dec); if (br->eof_) { return 0; } - if (!info->skip_) { - ParseResiduals(dec, info, token_br); + if (!skip) { + skip = ParseResiduals(dec, mb, token_br); } else { - left->nz_ = info->nz_ = 0; + left->nz_ = mb->nz_ = 0; if (!dec->is_i4x4_) { - left->dc_nz_ = info->dc_nz_ = 0; + left->nz_dc_ = mb->nz_dc_ = 0; } dec->non_zero_ = 0; dec->non_zero_ac_ = 0; @@ -641,16 +641,16 @@ int VP8DecodeMB(VP8Decoder* const dec, VP8BitReader* const token_br) { if (dec->filter_type_ > 0) { // store filter info VP8FInfo* const finfo = dec->f_info_ + dec->mb_x_; *finfo = dec->fstrengths_[dec->segment_][dec->is_i4x4_]; - finfo->f_inner_ = (!info->skip_ || dec->is_i4x4_); + finfo->f_inner_ = !skip || dec->is_i4x4_; } - return (!token_br->eof_); + return !token_br->eof_; } void VP8InitScanline(VP8Decoder* const dec) { VP8MB* const left = dec->mb_info_ - 1; left->nz_ = 0; - left->dc_nz_ = 0; + left->nz_dc_ = 0; memset(dec->intra_l_, B_DC_PRED, sizeof(dec->intra_l_)); dec->filter_row_ = (dec->filter_type_ > 0) && diff --git a/src/dec/vp8i.h b/src/dec/vp8i.h index f26943f2..ae91c6d8 100644 --- a/src/dec/vp8i.h +++ b/src/dec/vp8i.h @@ -159,9 +159,8 @@ typedef struct { // filter specs typedef struct { // used for syntax-parsing unsigned int nz_:24; // non-zero AC/DC coeffs (24bit) - unsigned int dc_nz_:1; // non-zero DC coeffs - unsigned int skip_:1; // block type - unsigned int pad_:6; + unsigned int nz_dc_:1; // non-zero DC coeffs + unsigned int pad_:7; } VP8MB; // Dequantization matrices @@ -304,7 +303,7 @@ void VP8ParseQuant(VP8Decoder* const dec); // in frame.c int VP8InitFrame(VP8Decoder* const dec, VP8Io* io); // Predict a block and add residual -void VP8ReconstructBlock(VP8Decoder* const dec); +void VP8ReconstructBlock(const VP8Decoder* const dec); // Call io->setup() and finish setting up scan parameters. // After this call returns, one must always call VP8ExitCritical() with the // same parameters. Both functions should be used in pair. Returns VP8_STATUS_OK