LCOV - code coverage report
Current view: top level - media/libvpx/libvpx/vp8/decoder - detokenize.c (source / functions) Hit Total Coverage
Test: output.info Lines: 0 97 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 4 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
       3             :  *
       4             :  *  Use of this source code is governed by a BSD-style license
       5             :  *  that can be found in the LICENSE file in the root of the source
       6             :  *  tree. An additional intellectual property rights grant can be found
       7             :  *  in the file PATENTS.  All contributing project authors may
       8             :  *  be found in the AUTHORS file in the root of the source tree.
       9             :  */
      10             : 
      11             : #include "vp8/common/blockd.h"
      12             : #include "onyxd_int.h"
      13             : #include "vpx_mem/vpx_mem.h"
      14             : #include "vpx_ports/mem.h"
      15             : #include "detokenize.h"
      16             : 
      17           0 : void vp8_reset_mb_tokens_context(MACROBLOCKD *x) {
      18           0 :   ENTROPY_CONTEXT *a_ctx = ((ENTROPY_CONTEXT *)x->above_context);
      19           0 :   ENTROPY_CONTEXT *l_ctx = ((ENTROPY_CONTEXT *)x->left_context);
      20             : 
      21           0 :   memset(a_ctx, 0, sizeof(ENTROPY_CONTEXT_PLANES) - 1);
      22           0 :   memset(l_ctx, 0, sizeof(ENTROPY_CONTEXT_PLANES) - 1);
      23             : 
      24             :   /* Clear entropy contexts for Y2 blocks */
      25           0 :   if (!x->mode_info_context->mbmi.is_4x4) {
      26           0 :     a_ctx[8] = l_ctx[8] = 0;
      27             :   }
      28           0 : }
      29             : 
      30             : /*
      31             :     ------------------------------------------------------------------------------
      32             :     Residual decoding (Paragraph 13.2 / 13.3)
      33             : */
      34             : static const uint8_t kBands[16 + 1] = {
      35             :   0, 1, 2, 3, 6, 4, 5, 6, 6,
      36             :   6, 6, 6, 6, 6, 6, 7, 0 /* extra entry as sentinel */
      37             : };
      38             : 
      39             : static const uint8_t kCat3[] = { 173, 148, 140, 0 };
      40             : static const uint8_t kCat4[] = { 176, 155, 140, 135, 0 };
      41             : static const uint8_t kCat5[] = { 180, 157, 141, 134, 130, 0 };
      42             : static const uint8_t kCat6[] = { 254, 254, 243, 230, 196, 177,
      43             :                                  153, 140, 133, 130, 129, 0 };
      44             : static const uint8_t *const kCat3456[] = { kCat3, kCat4, kCat5, kCat6 };
      45             : static const uint8_t kZigzag[16] = { 0, 1,  4,  8,  5, 2,  3,  6,
      46             :                                      9, 12, 13, 10, 7, 11, 14, 15 };
      47             : 
      48             : #define VP8GetBit vp8dx_decode_bool
      49             : #define NUM_PROBAS 11
      50             : #define NUM_CTX 3
      51             : 
      52             : /* for const-casting */
      53             : typedef const uint8_t (*ProbaArray)[NUM_CTX][NUM_PROBAS];
      54             : 
      55           0 : static int GetSigned(BOOL_DECODER *br, int value_to_sign) {
      56           0 :   int split = (br->range + 1) >> 1;
      57           0 :   VP8_BD_VALUE bigsplit = (VP8_BD_VALUE)split << (VP8_BD_VALUE_SIZE - 8);
      58             :   int v;
      59             : 
      60           0 :   if (br->count < 0) vp8dx_bool_decoder_fill(br);
      61             : 
      62           0 :   if (br->value < bigsplit) {
      63           0 :     br->range = split;
      64           0 :     v = value_to_sign;
      65             :   } else {
      66           0 :     br->range = br->range - split;
      67           0 :     br->value = br->value - bigsplit;
      68           0 :     v = -value_to_sign;
      69             :   }
      70           0 :   br->range += br->range;
      71           0 :   br->value += br->value;
      72           0 :   br->count--;
      73             : 
      74           0 :   return v;
      75             : }
      76             : /*
      77             :    Returns the position of the last non-zero coeff plus one
      78             :    (and 0 if there's no coeff at all)
      79             : */
      80           0 : static int GetCoeffs(BOOL_DECODER *br, ProbaArray prob, int ctx, int n,
      81             :                      int16_t *out) {
      82           0 :   const uint8_t *p = prob[n][ctx];
      83           0 :   if (!VP8GetBit(br, p[0])) { /* first EOB is more a 'CBP' bit. */
      84           0 :     return 0;
      85             :   }
      86             :   while (1) {
      87           0 :     ++n;
      88           0 :     if (!VP8GetBit(br, p[1])) {
      89           0 :       p = prob[kBands[n]][0];
      90             :     } else { /* non zero coeff */
      91             :       int v, j;
      92           0 :       if (!VP8GetBit(br, p[2])) {
      93           0 :         p = prob[kBands[n]][1];
      94           0 :         v = 1;
      95             :       } else {
      96           0 :         if (!VP8GetBit(br, p[3])) {
      97           0 :           if (!VP8GetBit(br, p[4])) {
      98           0 :             v = 2;
      99             :           } else {
     100           0 :             v = 3 + VP8GetBit(br, p[5]);
     101             :           }
     102             :         } else {
     103           0 :           if (!VP8GetBit(br, p[6])) {
     104           0 :             if (!VP8GetBit(br, p[7])) {
     105           0 :               v = 5 + VP8GetBit(br, 159);
     106             :             } else {
     107           0 :               v = 7 + 2 * VP8GetBit(br, 165);
     108           0 :               v += VP8GetBit(br, 145);
     109             :             }
     110             :           } else {
     111             :             const uint8_t *tab;
     112           0 :             const int bit1 = VP8GetBit(br, p[8]);
     113           0 :             const int bit0 = VP8GetBit(br, p[9 + bit1]);
     114           0 :             const int cat = 2 * bit1 + bit0;
     115           0 :             v = 0;
     116           0 :             for (tab = kCat3456[cat]; *tab; ++tab) {
     117           0 :               v += v + VP8GetBit(br, *tab);
     118             :             }
     119           0 :             v += 3 + (8 << cat);
     120             :           }
     121             :         }
     122           0 :         p = prob[kBands[n]][2];
     123             :       }
     124           0 :       j = kZigzag[n - 1];
     125             : 
     126           0 :       out[j] = GetSigned(br, v);
     127             : 
     128           0 :       if (n == 16 || !VP8GetBit(br, p[0])) { /* EOB */
     129           0 :         return n;
     130             :       }
     131             :     }
     132           0 :     if (n == 16) {
     133           0 :       return 16;
     134             :     }
     135             :   }
     136             : }
     137             : 
     138           0 : int vp8_decode_mb_tokens(VP8D_COMP *dx, MACROBLOCKD *x) {
     139           0 :   BOOL_DECODER *bc = x->current_bc;
     140           0 :   const FRAME_CONTEXT *const fc = &dx->common.fc;
     141           0 :   char *eobs = x->eobs;
     142             : 
     143             :   int i;
     144             :   int nonzeros;
     145           0 :   int eobtotal = 0;
     146             : 
     147             :   short *qcoeff_ptr;
     148             :   ProbaArray coef_probs;
     149           0 :   ENTROPY_CONTEXT *a_ctx = ((ENTROPY_CONTEXT *)x->above_context);
     150           0 :   ENTROPY_CONTEXT *l_ctx = ((ENTROPY_CONTEXT *)x->left_context);
     151             :   ENTROPY_CONTEXT *a;
     152             :   ENTROPY_CONTEXT *l;
     153           0 :   int skip_dc = 0;
     154             : 
     155           0 :   qcoeff_ptr = &x->qcoeff[0];
     156             : 
     157           0 :   if (!x->mode_info_context->mbmi.is_4x4) {
     158           0 :     a = a_ctx + 8;
     159           0 :     l = l_ctx + 8;
     160             : 
     161           0 :     coef_probs = fc->coef_probs[1];
     162             : 
     163           0 :     nonzeros = GetCoeffs(bc, coef_probs, (*a + *l), 0, qcoeff_ptr + 24 * 16);
     164           0 :     *a = *l = (nonzeros > 0);
     165             : 
     166           0 :     eobs[24] = nonzeros;
     167           0 :     eobtotal += nonzeros - 16;
     168             : 
     169           0 :     coef_probs = fc->coef_probs[0];
     170           0 :     skip_dc = 1;
     171             :   } else {
     172           0 :     coef_probs = fc->coef_probs[3];
     173           0 :     skip_dc = 0;
     174             :   }
     175             : 
     176           0 :   for (i = 0; i < 16; ++i) {
     177           0 :     a = a_ctx + (i & 3);
     178           0 :     l = l_ctx + ((i & 0xc) >> 2);
     179             : 
     180           0 :     nonzeros = GetCoeffs(bc, coef_probs, (*a + *l), skip_dc, qcoeff_ptr);
     181           0 :     *a = *l = (nonzeros > 0);
     182             : 
     183           0 :     nonzeros += skip_dc;
     184           0 :     eobs[i] = nonzeros;
     185           0 :     eobtotal += nonzeros;
     186           0 :     qcoeff_ptr += 16;
     187             :   }
     188             : 
     189           0 :   coef_probs = fc->coef_probs[2];
     190             : 
     191           0 :   a_ctx += 4;
     192           0 :   l_ctx += 4;
     193           0 :   for (i = 16; i < 24; ++i) {
     194           0 :     a = a_ctx + ((i > 19) << 1) + (i & 1);
     195           0 :     l = l_ctx + ((i > 19) << 1) + ((i & 3) > 1);
     196             : 
     197           0 :     nonzeros = GetCoeffs(bc, coef_probs, (*a + *l), 0, qcoeff_ptr);
     198           0 :     *a = *l = (nonzeros > 0);
     199             : 
     200           0 :     eobs[i] = nonzeros;
     201           0 :     eobtotal += nonzeros;
     202           0 :     qcoeff_ptr += 16;
     203             :   }
     204             : 
     205           0 :   return eobtotal;
     206             : }

Generated by: LCOV version 1.13