From 5bcdc099f313d46d0725050cba45a2c51b08f403 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Sun, 24 Jul 2011 19:36:18 +0100 Subject: [PATCH] dnxhddec: cache luma/chroma_weight*qscale tables for last qscale --- libavcodec/dnxhddec.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/libavcodec/dnxhddec.c b/libavcodec/dnxhddec.c index d8fb076bd4..b8f7291f87 100644 --- a/libavcodec/dnxhddec.c +++ b/libavcodec/dnxhddec.c @@ -49,6 +49,9 @@ typedef struct DNXHDContext { int bit_depth; // 8, 10 or 0 if not initialized at all. void (*decode_dct_block)(struct DNXHDContext *ctx, DCTELEM *block, int n, int qscale); + int last_qscale; + int luma_scale[64]; + int chroma_scale[64]; } DNXHDContext; #define DNXHD_VLC_BITS 9 @@ -181,6 +184,7 @@ static av_always_inline void dnxhd_decode_dct_block(DNXHDContext *ctx, { int i, j, index1, index2, len, flags; int level, component, sign; + const int *scale; const uint8_t *weight_matrix; const uint8_t *ac_level = ctx->cid_table->ac_level; const uint8_t *ac_flags = ctx->cid_table->ac_flags; @@ -189,9 +193,11 @@ static av_always_inline void dnxhd_decode_dct_block(DNXHDContext *ctx, if (n&2) { component = 1 + (n&1); + scale = ctx->chroma_scale; weight_matrix = ctx->cid_table->chroma_weight; } else { component = 0; + scale = ctx->luma_scale; weight_matrix = ctx->cid_table->luma_weight; } @@ -240,7 +246,7 @@ static av_always_inline void dnxhd_decode_dct_block(DNXHDContext *ctx, j = ctx->scantable.permutated[i]; //av_log(ctx->avctx, AV_LOG_DEBUG, "j %d\n", j); //av_log(ctx->avctx, AV_LOG_DEBUG, "level %d, weight %d\n", level, weight_matrix[i]); - level *= qscale * weight_matrix[i]; + level *= scale[i]; if (level_bias < 32 || weight_matrix[i] != level_bias) level += level_bias; level >>= level_shift; @@ -281,6 +287,14 @@ static int dnxhd_decode_macroblock(DNXHDContext *ctx, int x, int y) skip_bits1(&ctx->gb); //av_log(ctx->avctx, AV_LOG_DEBUG, "qscale %d\n", qscale); + if (qscale != ctx->last_qscale) { + for (i = 0; i < 64; i++) { + ctx->luma_scale[i] = qscale * ctx->cid_table->luma_weight[i]; + ctx->chroma_scale[i] = qscale * ctx->cid_table->chroma_weight[i]; + } + ctx->last_qscale = qscale; + } + for (i = 0; i < 8; i++) { ctx->dsp.clear_block(ctx->blocks[i]); ctx->decode_dct_block(ctx, ctx->blocks[i], i, qscale);