Browse code

dnxhddec: cache luma/chroma_weight*qscale tables for last qscale

Mans Rullgard authored on 2011/07/25 03:36:18
Showing 1 changed files
... ...
@@ -49,6 +49,9 @@ typedef struct DNXHDContext {
49 49
     int bit_depth; // 8, 10 or 0 if not initialized at all.
50 50
     void (*decode_dct_block)(struct DNXHDContext *ctx, DCTELEM *block,
51 51
                              int n, int qscale);
52
+    int last_qscale;
53
+    int luma_scale[64];
54
+    int chroma_scale[64];
52 55
 } DNXHDContext;
53 56
 
54 57
 #define DNXHD_VLC_BITS 9
... ...
@@ -181,6 +184,7 @@ static av_always_inline void dnxhd_decode_dct_block(DNXHDContext *ctx,
181 181
 {
182 182
     int i, j, index1, index2, len, flags;
183 183
     int level, component, sign;
184
+    const int *scale;
184 185
     const uint8_t *weight_matrix;
185 186
     const uint8_t *ac_level = ctx->cid_table->ac_level;
186 187
     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,
189 189
 
190 190
     if (n&2) {
191 191
         component = 1 + (n&1);
192
+        scale = ctx->chroma_scale;
192 193
         weight_matrix = ctx->cid_table->chroma_weight;
193 194
     } else {
194 195
         component = 0;
196
+        scale = ctx->luma_scale;
195 197
         weight_matrix = ctx->cid_table->luma_weight;
196 198
     }
197 199
 
... ...
@@ -240,7 +246,7 @@ static av_always_inline void dnxhd_decode_dct_block(DNXHDContext *ctx,
240 240
         j = ctx->scantable.permutated[i];
241 241
         //av_log(ctx->avctx, AV_LOG_DEBUG, "j %d\n", j);
242 242
         //av_log(ctx->avctx, AV_LOG_DEBUG, "level %d, weight %d\n", level, weight_matrix[i]);
243
-        level *= qscale * weight_matrix[i];
243
+        level *= scale[i];
244 244
         if (level_bias < 32 || weight_matrix[i] != level_bias)
245 245
             level += level_bias;
246 246
         level >>= level_shift;
... ...
@@ -281,6 +287,14 @@ static int dnxhd_decode_macroblock(DNXHDContext *ctx, int x, int y)
281 281
     skip_bits1(&ctx->gb);
282 282
     //av_log(ctx->avctx, AV_LOG_DEBUG, "qscale %d\n", qscale);
283 283
 
284
+    if (qscale != ctx->last_qscale) {
285
+        for (i = 0; i < 64; i++) {
286
+            ctx->luma_scale[i]   = qscale * ctx->cid_table->luma_weight[i];
287
+            ctx->chroma_scale[i] = qscale * ctx->cid_table->chroma_weight[i];
288
+        }
289
+        ctx->last_qscale = qscale;
290
+    }
291
+
284 292
     for (i = 0; i < 8; i++) {
285 293
         ctx->dsp.clear_block(ctx->blocks[i]);
286 294
         ctx->decode_dct_block(ctx, ctx->blocks[i], i, qscale);