LCOV - app.info - media/libvpx/vp8/decoder/detokenize.c

LCOV - code coverage report
| Current view: | directory - media/libvpx/vp8/decoder - detokenize.c (source / functions) |  | Found | Hit | Coverage |
| Test: | app.info | Lines: | 116 | 0 | 0.0 %
| Date: | 2012-04-21 | Functions: | 2 | 0 | 0.0 %

           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                 :
          12                 : #include "vp8/common/type_aliases.h"
          13                 : #include "vp8/common/blockd.h"
          14                 : #include "onyxd_int.h"
          15                 : #include "vpx_mem/vpx_mem.h"
          16                 : #include "vpx_ports/mem.h"
          17                 : #include "detokenize.h"
          18                 :
          19                 : #define BOOL_DATA UINT8
          20                 :
          21                 : #define OCB_X PREV_COEF_CONTEXTS * ENTROPY_NODES
          22                 : DECLARE_ALIGNED(16, static const unsigned char, coef_bands_x[16]) =
          23                 : {
          24                 :     0 * OCB_X, 1 * OCB_X, 2 * OCB_X, 3 * OCB_X,
          25                 :     6 * OCB_X, 4 * OCB_X, 5 * OCB_X, 6 * OCB_X,
          26                 :     6 * OCB_X, 6 * OCB_X, 6 * OCB_X, 6 * OCB_X,
          27                 :     6 * OCB_X, 6 * OCB_X, 6 * OCB_X, 7 * OCB_X
          28                 : };
          29                 : #define EOB_CONTEXT_NODE            0
          30                 : #define ZERO_CONTEXT_NODE           1
          31                 : #define ONE_CONTEXT_NODE            2
          32                 : #define LOW_VAL_CONTEXT_NODE        3
          33                 : #define TWO_CONTEXT_NODE            4
          34                 : #define THREE_CONTEXT_NODE          5
          35                 : #define HIGH_LOW_CONTEXT_NODE       6
          36                 : #define CAT_ONE_CONTEXT_NODE        7
          37                 : #define CAT_THREEFOUR_CONTEXT_NODE  8
          38                 : #define CAT_THREE_CONTEXT_NODE      9
          39                 : #define CAT_FIVE_CONTEXT_NODE       10
          40                 :
          41                 : #define CAT1_MIN_VAL    5
          42                 : #define CAT2_MIN_VAL    7
          43                 : #define CAT3_MIN_VAL   11
          44                 : #define CAT4_MIN_VAL   19
          45                 : #define CAT5_MIN_VAL   35
          46                 : #define CAT6_MIN_VAL   67
          47                 :
          48                 : #define CAT1_PROB0    159
          49                 : #define CAT2_PROB0    145
          50                 : #define CAT2_PROB1    165
          51                 :
          52                 : #define CAT3_PROB0 140
          53                 : #define CAT3_PROB1 148
          54                 : #define CAT3_PROB2 173
          55                 :
          56                 : #define CAT4_PROB0 135
          57                 : #define CAT4_PROB1 140
          58                 : #define CAT4_PROB2 155
          59                 : #define CAT4_PROB3 176
          60                 :
          61                 : #define CAT5_PROB0 130
          62                 : #define CAT5_PROB1 134
          63                 : #define CAT5_PROB2 141
          64                 : #define CAT5_PROB3 157
          65                 : #define CAT5_PROB4 180
          66                 :
          67                 : static const unsigned char cat6_prob[12] =
          68                 : { 129, 130, 133, 140, 153, 177, 196, 230, 243, 254, 254, 0 };
          69                 :
          70                 :
          71               0 : void vp8_reset_mb_tokens_context(MACROBLOCKD *x)
          72                 : {
          73                 :     /* Clear entropy contexts for Y2 blocks */
          74               0 :     if (x->mode_info_context->mbmi.mode != B_PRED &&
          75               0 :         x->mode_info_context->mbmi.mode != SPLITMV)
          76                 :     {
          77               0 :         vpx_memset(x->above_context, 0, sizeof(ENTROPY_CONTEXT_PLANES));
          78               0 :         vpx_memset(x->left_context, 0, sizeof(ENTROPY_CONTEXT_PLANES));
          79                 :     }
          80                 :     else
          81                 :     {
          82               0 :         vpx_memset(x->above_context, 0, sizeof(ENTROPY_CONTEXT_PLANES)-1);
          83               0 :         vpx_memset(x->left_context, 0, sizeof(ENTROPY_CONTEXT_PLANES)-1);
          84                 :     }
          85               0 : }
          86                 :
          87                 : DECLARE_ALIGNED(16, extern const unsigned char, vp8_norm[256]);
          88                 : #define FILL \
          89                 :     if(count < 0) \
          90                 :         VP8DX_BOOL_DECODER_FILL(count, value, bufptr, bufend);
          91                 :
          92                 : #define NORMALIZE \
          93                 :     /*if(range < 0x80)*/                            \
          94                 :     { \
          95                 :         shift = vp8_norm[range]; \
          96                 :         range <<= shift; \
          97                 :         value <<= shift; \
          98                 :         count -= shift; \
          99                 :     }
         100                 :
         101                 : #define DECODE_AND_APPLYSIGN(value_to_sign) \
         102                 :     split = (range + 1) >> 1; \
         103                 :     bigsplit = (VP8_BD_VALUE)split << (VP8_BD_VALUE_SIZE - 8); \
         104                 :     FILL \
         105                 :     if ( value < bigsplit ) \
         106                 :     { \
         107                 :         range = split; \
         108                 :         v= value_to_sign; \
         109                 :     } \
         110                 :     else \
         111                 :     { \
         112                 :         range = range-split; \
         113                 :         value = value-bigsplit; \
         114                 :         v = -value_to_sign; \
         115                 :     } \
         116                 :     range +=range;                   \
         117                 :     value +=value;                   \
         118                 :     count--;
         119                 :
         120                 : #define DECODE_AND_BRANCH_IF_ZERO(probability,branch) \
         121                 :     { \
         122                 :         split = 1 +  ((( probability*(range-1) ) )>> 8); \
         123                 :         bigsplit = (VP8_BD_VALUE)split << (VP8_BD_VALUE_SIZE - 8); \
         124                 :         FILL \
         125                 :         if ( value < bigsplit ) \
         126                 :         { \
         127                 :             range = split; \
         128                 :             NORMALIZE \
         129                 :             goto branch; \
         130                 :         } \
         131                 :         value -= bigsplit; \
         132                 :         range = range - split; \
         133                 :         NORMALIZE \
         134                 :     }
         135                 :
         136                 : #define DECODE_AND_LOOP_IF_ZERO(probability,branch) \
         137                 :     { \
         138                 :         split = 1 + ((( probability*(range-1) ) ) >> 8); \
         139                 :         bigsplit = (VP8_BD_VALUE)split << (VP8_BD_VALUE_SIZE - 8); \
         140                 :         FILL \
         141                 :         if ( value < bigsplit ) \
         142                 :         { \
         143                 :             range = split; \
         144                 :             NORMALIZE \
         145                 :             Prob = coef_probs; \
         146                 :             if(c<15) {\
         147                 :             ++c; \
         148                 :             Prob += coef_bands_x[c]; \
         149                 :             goto branch; \
         150                 :             } goto BLOCK_FINISHED; /*for malformed input */\
         151                 :         } \
         152                 :         value -= bigsplit; \
         153                 :         range = range - split; \
         154                 :         NORMALIZE \
         155                 :     }
         156                 :
         157                 : #define DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(val) \
         158                 :     DECODE_AND_APPLYSIGN(val) \
         159                 :     Prob = coef_probs + (ENTROPY_NODES*2); \
         160                 :     if(c < 15){\
         161                 :         qcoeff_ptr [ scan[c] ] = (INT16) v; \
         162                 :         ++c; \
         163                 :         goto DO_WHILE; }\
         164                 :     qcoeff_ptr [ 15 ] = (INT16) v; \
         165                 :     goto BLOCK_FINISHED;
         166                 :
         167                 :
         168                 : #define DECODE_EXTRABIT_AND_ADJUST_VAL(prob, bits_count)\
         169                 :     split = 1 +  (((range-1) * prob) >> 8); \
         170                 :     bigsplit = (VP8_BD_VALUE)split << (VP8_BD_VALUE_SIZE - 8); \
         171                 :     FILL \
         172                 :     if(value >= bigsplit)\
         173                 :     {\
         174                 :         range = range-split;\
         175                 :         value = value-bigsplit;\
         176                 :         val += ((UINT16)1<<bits_count);\
         177                 :     }\
         178                 :     else\
         179                 :     {\
         180                 :         range = split;\
         181                 :     }\
         182                 :     NORMALIZE
         183                 :
         184               0 : int vp8_decode_mb_tokens(VP8D_COMP *dx, MACROBLOCKD *x)
         185                 : {
         186               0 :     ENTROPY_CONTEXT *A = (ENTROPY_CONTEXT *)x->above_context;
         187               0 :     ENTROPY_CONTEXT *L = (ENTROPY_CONTEXT *)x->left_context;
         188               0 :     const FRAME_CONTEXT * const fc = &dx->common.fc;
         189                 :
         190               0 :     BOOL_DECODER *bc = x->current_bc;
         191                 :
         192               0 :     char *eobs = x->eobs;
         193                 :
         194                 :     ENTROPY_CONTEXT *a;
         195                 :     ENTROPY_CONTEXT *l;
         196                 :     int i;
         197                 :
         198               0 :     int eobtotal = 0;
         199                 :
         200                 :     register int count;
         201                 :
         202                 :     const BOOL_DATA *bufptr;
         203                 :     const BOOL_DATA *bufend;
         204                 :     register unsigned int range;
         205                 :     VP8_BD_VALUE value;
         206                 :     const int *scan;
         207                 :     register unsigned int shift;
         208                 :     UINT32 split;
         209                 :     VP8_BD_VALUE bigsplit;
         210                 :     INT16 *qcoeff_ptr;
         211                 :
         212                 :     const vp8_prob *coef_probs;
         213                 :     int type;
         214                 :     int stop;
         215                 :     INT16 val, bits_count;
         216                 :     INT16 c;
         217                 :     INT16 v;
         218                 :     const vp8_prob *Prob;
         219                 :
         220               0 :     type = 3;
         221               0 :     i = 0;
         222               0 :     stop = 16;
         223                 :
         224               0 :     scan = vp8_default_zig_zag1d;
         225               0 :     qcoeff_ptr = &x->qcoeff[0];
         226                 :
         227               0 :     if (x->mode_info_context->mbmi.mode != B_PRED &&
         228               0 :         x->mode_info_context->mbmi.mode != SPLITMV)
         229                 :     {
         230               0 :         i = 24;
         231               0 :         stop = 24;
         232               0 :         type = 1;
         233               0 :         qcoeff_ptr += 24*16;
         234               0 :         eobtotal -= 16;
         235                 :     }
         236                 :
         237               0 :     bufend  = bc->user_buffer_end;
         238               0 :     bufptr  = bc->user_buffer;
         239               0 :     value   = bc->value;
         240               0 :     count   = bc->count;
         241               0 :     range   = bc->range;
         242                 :
         243                 :
         244               0 :     coef_probs = fc->coef_probs [type] [ 0 ] [0];
         245                 :
         246                 : BLOCK_LOOP:
         247               0 :     a = A + vp8_block2above[i];
         248               0 :     l = L + vp8_block2left[i];
         249                 :
         250               0 :     c = (INT16)(!type);
         251                 :
         252                 :     /*Dest = ((A)!=0) + ((B)!=0);*/
         253               0 :     VP8_COMBINEENTROPYCONTEXTS(v, *a, *l);
         254               0 :     Prob = coef_probs;
         255               0 :     Prob += v * ENTROPY_NODES;
         256                 :
         257                 : DO_WHILE:
         258               0 :     Prob += coef_bands_x[c];
         259               0 :     DECODE_AND_BRANCH_IF_ZERO(Prob[EOB_CONTEXT_NODE], BLOCK_FINISHED);
         260                 :
         261                 : CHECK_0_:
         262               0 :     DECODE_AND_LOOP_IF_ZERO(Prob[ZERO_CONTEXT_NODE], CHECK_0_);
         263               0 :     DECODE_AND_BRANCH_IF_ZERO(Prob[ONE_CONTEXT_NODE], ONE_CONTEXT_NODE_0_);
         264               0 :     DECODE_AND_BRANCH_IF_ZERO(Prob[LOW_VAL_CONTEXT_NODE],
         265                 :                               LOW_VAL_CONTEXT_NODE_0_);
         266               0 :     DECODE_AND_BRANCH_IF_ZERO(Prob[HIGH_LOW_CONTEXT_NODE],
         267                 :                               HIGH_LOW_CONTEXT_NODE_0_);
         268               0 :     DECODE_AND_BRANCH_IF_ZERO(Prob[CAT_THREEFOUR_CONTEXT_NODE],
         269                 :                               CAT_THREEFOUR_CONTEXT_NODE_0_);
         270               0 :     DECODE_AND_BRANCH_IF_ZERO(Prob[CAT_FIVE_CONTEXT_NODE],
         271                 :                               CAT_FIVE_CONTEXT_NODE_0_);
         272                 :
         273               0 :     val = CAT6_MIN_VAL;
         274               0 :     bits_count = 10;
         275                 :
         276                 :     do
         277                 :     {
         278               0 :         DECODE_EXTRABIT_AND_ADJUST_VAL(cat6_prob[bits_count], bits_count);
         279               0 :         bits_count -- ;
         280                 :     }
         281               0 :     while (bits_count >= 0);
         282                 :
         283               0 :     DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(val);
         284                 :
         285                 : CAT_FIVE_CONTEXT_NODE_0_:
         286               0 :     val = CAT5_MIN_VAL;
         287               0 :     DECODE_EXTRABIT_AND_ADJUST_VAL(CAT5_PROB4, 4);
         288               0 :     DECODE_EXTRABIT_AND_ADJUST_VAL(CAT5_PROB3, 3);
         289               0 :     DECODE_EXTRABIT_AND_ADJUST_VAL(CAT5_PROB2, 2);
         290               0 :     DECODE_EXTRABIT_AND_ADJUST_VAL(CAT5_PROB1, 1);
         291               0 :     DECODE_EXTRABIT_AND_ADJUST_VAL(CAT5_PROB0, 0);
         292               0 :     DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(val);
         293                 :
         294                 : CAT_THREEFOUR_CONTEXT_NODE_0_:
         295               0 :     DECODE_AND_BRANCH_IF_ZERO(Prob[CAT_THREE_CONTEXT_NODE],
         296                 :                               CAT_THREE_CONTEXT_NODE_0_);
         297               0 :     val = CAT4_MIN_VAL;
         298               0 :     DECODE_EXTRABIT_AND_ADJUST_VAL(CAT4_PROB3, 3);
         299               0 :     DECODE_EXTRABIT_AND_ADJUST_VAL(CAT4_PROB2, 2);
         300               0 :     DECODE_EXTRABIT_AND_ADJUST_VAL(CAT4_PROB1, 1);
         301               0 :     DECODE_EXTRABIT_AND_ADJUST_VAL(CAT4_PROB0, 0);
         302               0 :     DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(val);
         303                 :
         304                 : CAT_THREE_CONTEXT_NODE_0_:
         305               0 :     val = CAT3_MIN_VAL;
         306               0 :     DECODE_EXTRABIT_AND_ADJUST_VAL(CAT3_PROB2, 2);
         307               0 :     DECODE_EXTRABIT_AND_ADJUST_VAL(CAT3_PROB1, 1);
         308               0 :     DECODE_EXTRABIT_AND_ADJUST_VAL(CAT3_PROB0, 0);
         309               0 :     DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(val);
         310                 :
         311                 : HIGH_LOW_CONTEXT_NODE_0_:
         312               0 :     DECODE_AND_BRANCH_IF_ZERO(Prob[CAT_ONE_CONTEXT_NODE],
         313                 :                               CAT_ONE_CONTEXT_NODE_0_);
         314                 :
         315               0 :     val = CAT2_MIN_VAL;
         316               0 :     DECODE_EXTRABIT_AND_ADJUST_VAL(CAT2_PROB1, 1);
         317               0 :     DECODE_EXTRABIT_AND_ADJUST_VAL(CAT2_PROB0, 0);
         318               0 :     DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(val);
         319                 :
         320                 : CAT_ONE_CONTEXT_NODE_0_:
         321               0 :     val = CAT1_MIN_VAL;
         322               0 :     DECODE_EXTRABIT_AND_ADJUST_VAL(CAT1_PROB0, 0);
         323               0 :     DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(val);
         324                 :
         325                 : LOW_VAL_CONTEXT_NODE_0_:
         326               0 :     DECODE_AND_BRANCH_IF_ZERO(Prob[TWO_CONTEXT_NODE], TWO_CONTEXT_NODE_0_);
         327               0 :     DECODE_AND_BRANCH_IF_ZERO(Prob[THREE_CONTEXT_NODE], THREE_CONTEXT_NODE_0_);
         328               0 :     DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(4);
         329                 :
         330                 : THREE_CONTEXT_NODE_0_:
         331               0 :     DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(3);
         332                 :
         333                 : TWO_CONTEXT_NODE_0_:
         334               0 :     DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(2);
         335                 :
         336                 : ONE_CONTEXT_NODE_0_:
         337               0 :     DECODE_AND_APPLYSIGN(1);
         338               0 :     Prob = coef_probs + ENTROPY_NODES;
         339                 :
         340               0 :     if (c < 15)
         341                 :     {
         342               0 :         qcoeff_ptr [ scan[c] ] = (INT16) v;
         343               0 :         ++c;
         344               0 :         goto DO_WHILE;
         345                 :     }
         346                 :
         347               0 :     qcoeff_ptr [ 15 ] = (INT16) v;
         348                 : BLOCK_FINISHED:
         349               0 :     *a = *l = ((eobs[i] = c) != !type);   /* any nonzero data? */
         350               0 :     eobtotal += c;
         351               0 :     qcoeff_ptr += 16;
         352                 :
         353               0 :     i++;
         354                 :
         355               0 :     if (i < stop)
         356               0 :         goto BLOCK_LOOP;
         357                 :
         358               0 :     if (i == 25)
         359                 :     {
         360               0 :         type = 0;
         361               0 :         i = 0;
         362               0 :         stop = 16;
         363               0 :         coef_probs = fc->coef_probs [type] [ 0 ] [0];
         364               0 :         qcoeff_ptr -= (24*16 + 16);
         365               0 :         goto BLOCK_LOOP;
         366                 :     }
         367                 :
         368               0 :     if (i == 16)
         369                 :     {
         370               0 :         type = 2;
         371               0 :         coef_probs = fc->coef_probs [type] [ 0 ] [0];
         372               0 :         stop = 24;
         373               0 :         goto BLOCK_LOOP;
         374                 :     }
         375                 :
         376               0 :     FILL
         377               0 :     bc->user_buffer = bufptr;
         378               0 :     bc->value = value;
         379               0 :     bc->count = count;
         380               0 :     bc->range = range;
         381               0 :     return eobtotal;
         382                 :
         383                 : }

Generated by: LCOV version 1.7