media/libvpx/vp9/decoder/vp9_dboolhuff.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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  */
    11 #ifndef VP9_DECODER_VP9_DBOOLHUFF_H_
    12 #define VP9_DECODER_VP9_DBOOLHUFF_H_
    14 #include <stddef.h>
    15 #include <limits.h>
    17 #include "./vpx_config.h"
    18 #include "vpx_ports/mem.h"
    19 #include "vpx/vpx_integer.h"
    21 typedef size_t VP9_BD_VALUE;
    23 #define BD_VALUE_SIZE ((int)sizeof(VP9_BD_VALUE)*CHAR_BIT)
    25 typedef struct {
    26   const uint8_t *buffer_end;
    27   const uint8_t *buffer;
    28   VP9_BD_VALUE value;
    29   int count;
    30   unsigned int range;
    31 } vp9_reader;
    33 DECLARE_ALIGNED(16, extern const uint8_t, vp9_norm[256]);
    35 int vp9_reader_init(vp9_reader *r, const uint8_t *buffer, size_t size);
    37 void vp9_reader_fill(vp9_reader *r);
    39 const uint8_t *vp9_reader_find_end(vp9_reader *r);
    41 static int vp9_read(vp9_reader *br, int probability) {
    42   unsigned int bit = 0;
    43   VP9_BD_VALUE value;
    44   VP9_BD_VALUE bigsplit;
    45   int count;
    46   unsigned int range;
    47   unsigned int split = ((br->range * probability) + (256 - probability)) >> 8;
    49   if (br->count < 0)
    50     vp9_reader_fill(br);
    52   value = br->value;
    53   count = br->count;
    55   bigsplit = (VP9_BD_VALUE)split << (BD_VALUE_SIZE - 8);
    57   range = split;
    59   if (value >= bigsplit) {
    60     range = br->range - split;
    61     value = value - bigsplit;
    62     bit = 1;
    63   }
    65   {
    66     register unsigned int shift = vp9_norm[range];
    67     range <<= shift;
    68     value <<= shift;
    69     count -= shift;
    70   }
    71   br->value = value;
    72   br->count = count;
    73   br->range = range;
    75   return bit;
    76 }
    78 static int vp9_read_bit(vp9_reader *r) {
    79   return vp9_read(r, 128);  // vp9_prob_half
    80 }
    82 static int vp9_read_literal(vp9_reader *br, int bits) {
    83   int z = 0, bit;
    85   for (bit = bits - 1; bit >= 0; bit--)
    86     z |= vp9_read_bit(br) << bit;
    88   return z;
    89 }
    91 int vp9_reader_has_error(vp9_reader *r);
    93 #endif  // VP9_DECODER_VP9_DBOOLHUFF_H_

mercurial