media/libvpx/vp8/encoder/tokenize.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/libvpx/vp8/encoder/tokenize.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,604 @@
     1.4 +/*
     1.5 + *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
     1.6 + *
     1.7 + *  Use of this source code is governed by a BSD-style license
     1.8 + *  that can be found in the LICENSE file in the root of the source
     1.9 + *  tree. An additional intellectual property rights grant can be found
    1.10 + *  in the file PATENTS.  All contributing project authors may
    1.11 + *  be found in the AUTHORS file in the root of the source tree.
    1.12 + */
    1.13 +
    1.14 +
    1.15 +#include <math.h>
    1.16 +#include <stdio.h>
    1.17 +#include <string.h>
    1.18 +#include <assert.h>
    1.19 +#include "onyx_int.h"
    1.20 +#include "tokenize.h"
    1.21 +#include "vpx_mem/vpx_mem.h"
    1.22 +
    1.23 +/* Global event counters used for accumulating statistics across several
    1.24 +   compressions, then generating context.c = initial stats. */
    1.25 +
    1.26 +#ifdef VP8_ENTROPY_STATS
    1.27 +_int64 context_counters[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS];
    1.28 +#endif
    1.29 +void vp8_stuff_mb(VP8_COMP *cpi, MACROBLOCK *x, TOKENEXTRA **t) ;
    1.30 +void vp8_fix_contexts(MACROBLOCKD *x);
    1.31 +
    1.32 +#include "dct_value_tokens.h"
    1.33 +#include "dct_value_cost.h"
    1.34 +
    1.35 +const TOKENVALUE *const vp8_dct_value_tokens_ptr = dct_value_tokens +
    1.36 +        DCT_MAX_VALUE;
    1.37 +const short *const vp8_dct_value_cost_ptr = dct_value_cost + DCT_MAX_VALUE;
    1.38 +
    1.39 +#if 0
    1.40 +int skip_true_count = 0;
    1.41 +int skip_false_count = 0;
    1.42 +#endif
    1.43 +
    1.44 +/* function used to generate dct_value_tokens and dct_value_cost tables */
    1.45 +/*
    1.46 +static void fill_value_tokens()
    1.47 +{
    1.48 +
    1.49 +    TOKENVALUE *t = dct_value_tokens + DCT_MAX_VALUE;
    1.50 +    const vp8_extra_bit_struct *e = vp8_extra_bits;
    1.51 +
    1.52 +    int i = -DCT_MAX_VALUE;
    1.53 +    int sign = 1;
    1.54 +
    1.55 +    do
    1.56 +    {
    1.57 +        if (!i)
    1.58 +            sign = 0;
    1.59 +
    1.60 +        {
    1.61 +            const int a = sign ? -i : i;
    1.62 +            int eb = sign;
    1.63 +
    1.64 +            if (a > 4)
    1.65 +            {
    1.66 +                int j = 4;
    1.67 +
    1.68 +                while (++j < 11  &&  e[j].base_val <= a) {}
    1.69 +
    1.70 +                t[i].Token = --j;
    1.71 +                eb |= (a - e[j].base_val) << 1;
    1.72 +            }
    1.73 +            else
    1.74 +                t[i].Token = a;
    1.75 +
    1.76 +            t[i].Extra = eb;
    1.77 +        }
    1.78 +
    1.79 +        // initialize the cost for extra bits for all possible coefficient value.
    1.80 +        {
    1.81 +            int cost = 0;
    1.82 +            const vp8_extra_bit_struct *p = vp8_extra_bits + t[i].Token;
    1.83 +
    1.84 +            if (p->base_val)
    1.85 +            {
    1.86 +                const int extra = t[i].Extra;
    1.87 +                const int Length = p->Len;
    1.88 +
    1.89 +                if (Length)
    1.90 +                    cost += vp8_treed_cost(p->tree, p->prob, extra >> 1, Length);
    1.91 +
    1.92 +                cost += vp8_cost_bit(vp8_prob_half, extra & 1); // sign
    1.93 +                dct_value_cost[i + DCT_MAX_VALUE] = cost;
    1.94 +            }
    1.95 +
    1.96 +        }
    1.97 +
    1.98 +    }
    1.99 +    while (++i < DCT_MAX_VALUE);
   1.100 +
   1.101 +    vp8_dct_value_tokens_ptr = dct_value_tokens + DCT_MAX_VALUE;
   1.102 +    vp8_dct_value_cost_ptr   = dct_value_cost + DCT_MAX_VALUE;
   1.103 +}
   1.104 +*/
   1.105 +
   1.106 +static void tokenize2nd_order_b
   1.107 +(
   1.108 +    MACROBLOCK *x,
   1.109 +    TOKENEXTRA **tp,
   1.110 +    VP8_COMP *cpi
   1.111 +)
   1.112 +{
   1.113 +    MACROBLOCKD *xd = &x->e_mbd;
   1.114 +    int pt;             /* near block/prev token context index */
   1.115 +    int c;              /* start at DC */
   1.116 +    TOKENEXTRA *t = *tp;/* store tokens starting here */
   1.117 +    const BLOCKD *b;
   1.118 +    const short *qcoeff_ptr;
   1.119 +    ENTROPY_CONTEXT * a;
   1.120 +    ENTROPY_CONTEXT * l;
   1.121 +    int band, rc, v, token;
   1.122 +    int eob;
   1.123 +
   1.124 +    b = xd->block + 24;
   1.125 +    qcoeff_ptr = b->qcoeff;
   1.126 +    a = (ENTROPY_CONTEXT *)xd->above_context + 8;
   1.127 +    l = (ENTROPY_CONTEXT *)xd->left_context + 8;
   1.128 +    eob = xd->eobs[24];
   1.129 +    VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l);
   1.130 +
   1.131 +    if(!eob)
   1.132 +    {
   1.133 +        /* c = band for this case */
   1.134 +        t->Token = DCT_EOB_TOKEN;
   1.135 +        t->context_tree = cpi->common.fc.coef_probs [1] [0] [pt];
   1.136 +        t->skip_eob_node = 0;
   1.137 +
   1.138 +        ++x->coef_counts       [1] [0] [pt] [DCT_EOB_TOKEN];
   1.139 +        t++;
   1.140 +        *tp = t;
   1.141 +        *a = *l = 0;
   1.142 +        return;
   1.143 +    }
   1.144 +
   1.145 +    v = qcoeff_ptr[0];
   1.146 +    t->Extra = vp8_dct_value_tokens_ptr[v].Extra;
   1.147 +    token    = vp8_dct_value_tokens_ptr[v].Token;
   1.148 +    t->Token = token;
   1.149 +
   1.150 +    t->context_tree = cpi->common.fc.coef_probs [1] [0] [pt];
   1.151 +    t->skip_eob_node = 0;
   1.152 +    ++x->coef_counts       [1] [0] [pt] [token];
   1.153 +    pt = vp8_prev_token_class[token];
   1.154 +    t++;
   1.155 +    c = 1;
   1.156 +
   1.157 +    for (; c < eob; c++)
   1.158 +    {
   1.159 +        rc = vp8_default_zig_zag1d[c];
   1.160 +        band = vp8_coef_bands[c];
   1.161 +        v = qcoeff_ptr[rc];
   1.162 +
   1.163 +        t->Extra = vp8_dct_value_tokens_ptr[v].Extra;
   1.164 +        token    = vp8_dct_value_tokens_ptr[v].Token;
   1.165 +
   1.166 +        t->Token = token;
   1.167 +        t->context_tree = cpi->common.fc.coef_probs [1] [band] [pt];
   1.168 +
   1.169 +        t->skip_eob_node = ((pt == 0));
   1.170 +
   1.171 +        ++x->coef_counts       [1] [band] [pt] [token];
   1.172 +
   1.173 +        pt = vp8_prev_token_class[token];
   1.174 +        t++;
   1.175 +    }
   1.176 +    if (c < 16)
   1.177 +    {
   1.178 +        band = vp8_coef_bands[c];
   1.179 +        t->Token = DCT_EOB_TOKEN;
   1.180 +        t->context_tree = cpi->common.fc.coef_probs [1] [band] [pt];
   1.181 +
   1.182 +        t->skip_eob_node = 0;
   1.183 +
   1.184 +        ++x->coef_counts       [1] [band] [pt] [DCT_EOB_TOKEN];
   1.185 +
   1.186 +        t++;
   1.187 +    }
   1.188 +
   1.189 +    *tp = t;
   1.190 +    *a = *l = 1;
   1.191 +
   1.192 +}
   1.193 +
   1.194 +static void tokenize1st_order_b
   1.195 +(
   1.196 +    MACROBLOCK *x,
   1.197 +    TOKENEXTRA **tp,
   1.198 +    int type,           /* which plane: 0=Y no DC, 1=Y2, 2=UV, 3=Y with DC */
   1.199 +    VP8_COMP *cpi
   1.200 +)
   1.201 +{
   1.202 +    MACROBLOCKD *xd = &x->e_mbd;
   1.203 +    unsigned int block;
   1.204 +    const BLOCKD *b;
   1.205 +    int pt;             /* near block/prev token context index */
   1.206 +    int c;
   1.207 +    int token;
   1.208 +    TOKENEXTRA *t = *tp;/* store tokens starting here */
   1.209 +    const short *qcoeff_ptr;
   1.210 +    ENTROPY_CONTEXT * a;
   1.211 +    ENTROPY_CONTEXT * l;
   1.212 +    int band, rc, v;
   1.213 +    int tmp1, tmp2;
   1.214 +
   1.215 +    b = xd->block;
   1.216 +    /* Luma */
   1.217 +    for (block = 0; block < 16; block++, b++)
   1.218 +    {
   1.219 +        tmp1 = vp8_block2above[block];
   1.220 +        tmp2 = vp8_block2left[block];
   1.221 +        qcoeff_ptr = b->qcoeff;
   1.222 +        a = (ENTROPY_CONTEXT *)xd->above_context + tmp1;
   1.223 +        l = (ENTROPY_CONTEXT *)xd->left_context + tmp2;
   1.224 +
   1.225 +        VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l);
   1.226 +
   1.227 +        c = type ? 0 : 1;
   1.228 +
   1.229 +        if(c >= *b->eob)
   1.230 +        {
   1.231 +            /* c = band for this case */
   1.232 +            t->Token = DCT_EOB_TOKEN;
   1.233 +            t->context_tree = cpi->common.fc.coef_probs [type] [c] [pt];
   1.234 +            t->skip_eob_node = 0;
   1.235 +
   1.236 +            ++x->coef_counts       [type] [c] [pt] [DCT_EOB_TOKEN];
   1.237 +            t++;
   1.238 +            *tp = t;
   1.239 +            *a = *l = 0;
   1.240 +            continue;
   1.241 +        }
   1.242 +
   1.243 +        v = qcoeff_ptr[c];
   1.244 +
   1.245 +        t->Extra = vp8_dct_value_tokens_ptr[v].Extra;
   1.246 +        token    = vp8_dct_value_tokens_ptr[v].Token;
   1.247 +        t->Token = token;
   1.248 +
   1.249 +        t->context_tree = cpi->common.fc.coef_probs [type] [c] [pt];
   1.250 +        t->skip_eob_node = 0;
   1.251 +        ++x->coef_counts       [type] [c] [pt] [token];
   1.252 +        pt = vp8_prev_token_class[token];
   1.253 +        t++;
   1.254 +        c++;
   1.255 +
   1.256 +        for (; c < *b->eob; c++)
   1.257 +        {
   1.258 +            rc = vp8_default_zig_zag1d[c];
   1.259 +            band = vp8_coef_bands[c];
   1.260 +            v = qcoeff_ptr[rc];
   1.261 +
   1.262 +            t->Extra = vp8_dct_value_tokens_ptr[v].Extra;
   1.263 +            token    = vp8_dct_value_tokens_ptr[v].Token;
   1.264 +
   1.265 +            t->Token = token;
   1.266 +            t->context_tree = cpi->common.fc.coef_probs [type] [band] [pt];
   1.267 +
   1.268 +            t->skip_eob_node = (pt == 0);
   1.269 +            ++x->coef_counts       [type] [band] [pt] [token];
   1.270 +
   1.271 +            pt = vp8_prev_token_class[token];
   1.272 +            t++;
   1.273 +        }
   1.274 +        if (c < 16)
   1.275 +        {
   1.276 +            band = vp8_coef_bands[c];
   1.277 +            t->Token = DCT_EOB_TOKEN;
   1.278 +            t->context_tree = cpi->common.fc.coef_probs [type] [band] [pt];
   1.279 +
   1.280 +            t->skip_eob_node = 0;
   1.281 +            ++x->coef_counts       [type] [band] [pt] [DCT_EOB_TOKEN];
   1.282 +
   1.283 +            t++;
   1.284 +        }
   1.285 +        *tp = t;
   1.286 +        *a = *l = 1;
   1.287 +    }
   1.288 +
   1.289 +    /* Chroma */
   1.290 +    for (block = 16; block < 24; block++, b++)
   1.291 +    {
   1.292 +        tmp1 = vp8_block2above[block];
   1.293 +        tmp2 = vp8_block2left[block];
   1.294 +        qcoeff_ptr = b->qcoeff;
   1.295 +        a = (ENTROPY_CONTEXT *)xd->above_context + tmp1;
   1.296 +        l = (ENTROPY_CONTEXT *)xd->left_context + tmp2;
   1.297 +
   1.298 +        VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l);
   1.299 +
   1.300 +        if(!(*b->eob))
   1.301 +        {
   1.302 +            /* c = band for this case */
   1.303 +            t->Token = DCT_EOB_TOKEN;
   1.304 +            t->context_tree = cpi->common.fc.coef_probs [2] [0] [pt];
   1.305 +            t->skip_eob_node = 0;
   1.306 +
   1.307 +            ++x->coef_counts       [2] [0] [pt] [DCT_EOB_TOKEN];
   1.308 +            t++;
   1.309 +            *tp = t;
   1.310 +            *a = *l = 0;
   1.311 +            continue;
   1.312 +        }
   1.313 +
   1.314 +        v = qcoeff_ptr[0];
   1.315 +
   1.316 +        t->Extra = vp8_dct_value_tokens_ptr[v].Extra;
   1.317 +        token    = vp8_dct_value_tokens_ptr[v].Token;
   1.318 +        t->Token = token;
   1.319 +
   1.320 +        t->context_tree = cpi->common.fc.coef_probs [2] [0] [pt];
   1.321 +        t->skip_eob_node = 0;
   1.322 +        ++x->coef_counts       [2] [0] [pt] [token];
   1.323 +        pt = vp8_prev_token_class[token];
   1.324 +        t++;
   1.325 +        c = 1;
   1.326 +
   1.327 +        for (; c < *b->eob; c++)
   1.328 +        {
   1.329 +            rc = vp8_default_zig_zag1d[c];
   1.330 +            band = vp8_coef_bands[c];
   1.331 +            v = qcoeff_ptr[rc];
   1.332 +
   1.333 +            t->Extra = vp8_dct_value_tokens_ptr[v].Extra;
   1.334 +            token    = vp8_dct_value_tokens_ptr[v].Token;
   1.335 +
   1.336 +            t->Token = token;
   1.337 +            t->context_tree = cpi->common.fc.coef_probs [2] [band] [pt];
   1.338 +
   1.339 +            t->skip_eob_node = (pt == 0);
   1.340 +
   1.341 +            ++x->coef_counts       [2] [band] [pt] [token];
   1.342 +
   1.343 +            pt = vp8_prev_token_class[token];
   1.344 +            t++;
   1.345 +        }
   1.346 +        if (c < 16)
   1.347 +        {
   1.348 +            band = vp8_coef_bands[c];
   1.349 +            t->Token = DCT_EOB_TOKEN;
   1.350 +            t->context_tree = cpi->common.fc.coef_probs [2] [band] [pt];
   1.351 +
   1.352 +            t->skip_eob_node = 0;
   1.353 +
   1.354 +            ++x->coef_counts       [2] [band] [pt] [DCT_EOB_TOKEN];
   1.355 +
   1.356 +            t++;
   1.357 +        }
   1.358 +        *tp = t;
   1.359 +        *a = *l = 1;
   1.360 +    }
   1.361 +}
   1.362 +
   1.363 +
   1.364 +static int mb_is_skippable(MACROBLOCKD *x, int has_y2_block)
   1.365 +{
   1.366 +    int skip = 1;
   1.367 +    int i = 0;
   1.368 +
   1.369 +    if (has_y2_block)
   1.370 +    {
   1.371 +        for (i = 0; i < 16; i++)
   1.372 +            skip &= (x->eobs[i] < 2);
   1.373 +    }
   1.374 +
   1.375 +    for (; i < 24 + has_y2_block; i++)
   1.376 +        skip &= (!x->eobs[i]);
   1.377 +
   1.378 +    return skip;
   1.379 +}
   1.380 +
   1.381 +
   1.382 +void vp8_tokenize_mb(VP8_COMP *cpi, MACROBLOCK *x, TOKENEXTRA **t)
   1.383 +{
   1.384 +    MACROBLOCKD *xd = &x->e_mbd;
   1.385 +    int plane_type;
   1.386 +    int has_y2_block;
   1.387 +
   1.388 +    has_y2_block = (xd->mode_info_context->mbmi.mode != B_PRED
   1.389 +                    && xd->mode_info_context->mbmi.mode != SPLITMV);
   1.390 +
   1.391 +    xd->mode_info_context->mbmi.mb_skip_coeff =
   1.392 +        mb_is_skippable(xd, has_y2_block);
   1.393 +    if (xd->mode_info_context->mbmi.mb_skip_coeff)
   1.394 +    {
   1.395 +        if (!cpi->common.mb_no_coeff_skip)
   1.396 +        {
   1.397 +            vp8_stuff_mb(cpi, x, t);
   1.398 +        }
   1.399 +        else
   1.400 +        {
   1.401 +            vp8_fix_contexts(xd);
   1.402 +            x->skip_true_count++;
   1.403 +        }
   1.404 +
   1.405 +        return;
   1.406 +    }
   1.407 +
   1.408 +    plane_type = 3;
   1.409 +    if(has_y2_block)
   1.410 +    {
   1.411 +        tokenize2nd_order_b(x, t, cpi);
   1.412 +        plane_type = 0;
   1.413 +    }
   1.414 +
   1.415 +    tokenize1st_order_b(x, t, plane_type, cpi);
   1.416 +}
   1.417 +
   1.418 +
   1.419 +#ifdef VP8_ENTROPY_STATS
   1.420 +
   1.421 +void init_context_counters(void)
   1.422 +{
   1.423 +    vpx_memset(context_counters, 0, sizeof(context_counters));
   1.424 +}
   1.425 +
   1.426 +void print_context_counters()
   1.427 +{
   1.428 +
   1.429 +    int type, band, pt, t;
   1.430 +
   1.431 +    FILE *const f = fopen("context.c", "w");
   1.432 +
   1.433 +    fprintf(f, "#include \"entropy.h\"\n");
   1.434 +
   1.435 +    fprintf(f, "\n/* *** GENERATED FILE: DO NOT EDIT *** */\n\n");
   1.436 +
   1.437 +    fprintf(f, "int Contexts[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS];\n\n");
   1.438 +
   1.439 +    fprintf(f, "const int default_contexts[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS] = {");
   1.440 +
   1.441 +# define Comma( X) (X? ",":"")
   1.442 +
   1.443 +    type = 0;
   1.444 +
   1.445 +    do
   1.446 +    {
   1.447 +        fprintf(f, "%s\n  { /* block Type %d */", Comma(type), type);
   1.448 +
   1.449 +        band = 0;
   1.450 +
   1.451 +        do
   1.452 +        {
   1.453 +            fprintf(f, "%s\n    { /* Coeff Band %d */", Comma(band), band);
   1.454 +
   1.455 +            pt = 0;
   1.456 +
   1.457 +            do
   1.458 +            {
   1.459 +                fprintf(f, "%s\n      {", Comma(pt));
   1.460 +
   1.461 +                t = 0;
   1.462 +
   1.463 +                do
   1.464 +                {
   1.465 +                    const _int64 x = context_counters [type] [band] [pt] [t];
   1.466 +                    const int y = (int) x;
   1.467 +
   1.468 +                    assert(x == (_int64) y);  /* no overflow handling yet */
   1.469 +                    fprintf(f, "%s %d", Comma(t), y);
   1.470 +
   1.471 +                }
   1.472 +                while (++t < MAX_ENTROPY_TOKENS);
   1.473 +
   1.474 +                fprintf(f, "}");
   1.475 +            }
   1.476 +            while (++pt < PREV_COEF_CONTEXTS);
   1.477 +
   1.478 +            fprintf(f, "\n    }");
   1.479 +
   1.480 +        }
   1.481 +        while (++band < COEF_BANDS);
   1.482 +
   1.483 +        fprintf(f, "\n  }");
   1.484 +    }
   1.485 +    while (++type < BLOCK_TYPES);
   1.486 +
   1.487 +    fprintf(f, "\n};\n");
   1.488 +    fclose(f);
   1.489 +}
   1.490 +#endif
   1.491 +
   1.492 +
   1.493 +static void stuff2nd_order_b
   1.494 +(
   1.495 +    TOKENEXTRA **tp,
   1.496 +    ENTROPY_CONTEXT *a,
   1.497 +    ENTROPY_CONTEXT *l,
   1.498 +    VP8_COMP *cpi,
   1.499 +    MACROBLOCK *x
   1.500 +)
   1.501 +{
   1.502 +    int pt; /* near block/prev token context index */
   1.503 +    TOKENEXTRA *t = *tp;        /* store tokens starting here */
   1.504 +    VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l);
   1.505 +
   1.506 +    t->Token = DCT_EOB_TOKEN;
   1.507 +    t->context_tree = cpi->common.fc.coef_probs [1] [0] [pt];
   1.508 +    t->skip_eob_node = 0;
   1.509 +    ++x->coef_counts       [1] [0] [pt] [DCT_EOB_TOKEN];
   1.510 +    ++t;
   1.511 +
   1.512 +    *tp = t;
   1.513 +    pt = 0;
   1.514 +    *a = *l = pt;
   1.515 +}
   1.516 +
   1.517 +static void stuff1st_order_b
   1.518 +(
   1.519 +    TOKENEXTRA **tp,
   1.520 +    ENTROPY_CONTEXT *a,
   1.521 +    ENTROPY_CONTEXT *l,
   1.522 +    int type,
   1.523 +    VP8_COMP *cpi,
   1.524 +    MACROBLOCK *x
   1.525 +)
   1.526 +{
   1.527 +    int pt; /* near block/prev token context index */
   1.528 +    int band;
   1.529 +    TOKENEXTRA *t = *tp;        /* store tokens starting here */
   1.530 +    VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l);
   1.531 +    band = type ? 0 : 1;
   1.532 +    t->Token = DCT_EOB_TOKEN;
   1.533 +    t->context_tree = cpi->common.fc.coef_probs [type] [band] [pt];
   1.534 +    t->skip_eob_node = 0;
   1.535 +    ++x->coef_counts       [type] [band] [pt] [DCT_EOB_TOKEN];
   1.536 +    ++t;
   1.537 +    *tp = t;
   1.538 +    pt = 0; /* 0 <-> all coeff data is zero */
   1.539 +    *a = *l = pt;
   1.540 +}
   1.541 +
   1.542 +static
   1.543 +void stuff1st_order_buv
   1.544 +(
   1.545 +    TOKENEXTRA **tp,
   1.546 +    ENTROPY_CONTEXT *a,
   1.547 +    ENTROPY_CONTEXT *l,
   1.548 +    VP8_COMP *cpi,
   1.549 +    MACROBLOCK *x
   1.550 +)
   1.551 +{
   1.552 +    int pt; /* near block/prev token context index */
   1.553 +    TOKENEXTRA *t = *tp;        /* store tokens starting here */
   1.554 +    VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l);
   1.555 +
   1.556 +    t->Token = DCT_EOB_TOKEN;
   1.557 +    t->context_tree = cpi->common.fc.coef_probs [2] [0] [pt];
   1.558 +    t->skip_eob_node = 0;
   1.559 +    ++x->coef_counts[2] [0] [pt] [DCT_EOB_TOKEN];
   1.560 +    ++t;
   1.561 +    *tp = t;
   1.562 +    pt = 0; /* 0 <-> all coeff data is zero */
   1.563 +    *a = *l = pt;
   1.564 +}
   1.565 +
   1.566 +void vp8_stuff_mb(VP8_COMP *cpi, MACROBLOCK *x, TOKENEXTRA **t)
   1.567 +{
   1.568 +    MACROBLOCKD *xd = &x->e_mbd;
   1.569 +    ENTROPY_CONTEXT * A = (ENTROPY_CONTEXT *)xd->above_context;
   1.570 +    ENTROPY_CONTEXT * L = (ENTROPY_CONTEXT *)xd->left_context;
   1.571 +    int plane_type;
   1.572 +    int b;
   1.573 +    plane_type = 3;
   1.574 +    if((xd->mode_info_context->mbmi.mode != B_PRED
   1.575 +                        && xd->mode_info_context->mbmi.mode != SPLITMV))
   1.576 +    {
   1.577 +        stuff2nd_order_b(t,
   1.578 +                     A + vp8_block2above[24], L + vp8_block2left[24], cpi, x);
   1.579 +        plane_type = 0;
   1.580 +    }
   1.581 +
   1.582 +    for (b = 0; b < 16; b++)
   1.583 +        stuff1st_order_b(t,
   1.584 +                         A + vp8_block2above[b],
   1.585 +                         L + vp8_block2left[b], plane_type, cpi, x);
   1.586 +
   1.587 +    for (b = 16; b < 24; b++)
   1.588 +        stuff1st_order_buv(t,
   1.589 +                           A + vp8_block2above[b],
   1.590 +                           L + vp8_block2left[b], cpi, x);
   1.591 +
   1.592 +}
   1.593 +void vp8_fix_contexts(MACROBLOCKD *x)
   1.594 +{
   1.595 +    /* Clear entropy contexts for Y2 blocks */
   1.596 +    if (x->mode_info_context->mbmi.mode != B_PRED && x->mode_info_context->mbmi.mode != SPLITMV)
   1.597 +    {
   1.598 +        vpx_memset(x->above_context, 0, sizeof(ENTROPY_CONTEXT_PLANES));
   1.599 +        vpx_memset(x->left_context, 0, sizeof(ENTROPY_CONTEXT_PLANES));
   1.600 +    }
   1.601 +    else
   1.602 +    {
   1.603 +        vpx_memset(x->above_context, 0, sizeof(ENTROPY_CONTEXT_PLANES)-1);
   1.604 +        vpx_memset(x->left_context, 0, sizeof(ENTROPY_CONTEXT_PLANES)-1);
   1.605 +    }
   1.606 +
   1.607 +}

mercurial