media/libvpx/vp9/decoder/vp9_dboolhuff.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/libvpx/vp9/decoder/vp9_dboolhuff.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,93 @@
     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 +#ifndef VP9_DECODER_VP9_DBOOLHUFF_H_
    1.15 +#define VP9_DECODER_VP9_DBOOLHUFF_H_
    1.16 +
    1.17 +#include <stddef.h>
    1.18 +#include <limits.h>
    1.19 +
    1.20 +#include "./vpx_config.h"
    1.21 +#include "vpx_ports/mem.h"
    1.22 +#include "vpx/vpx_integer.h"
    1.23 +
    1.24 +typedef size_t VP9_BD_VALUE;
    1.25 +
    1.26 +#define BD_VALUE_SIZE ((int)sizeof(VP9_BD_VALUE)*CHAR_BIT)
    1.27 +
    1.28 +typedef struct {
    1.29 +  const uint8_t *buffer_end;
    1.30 +  const uint8_t *buffer;
    1.31 +  VP9_BD_VALUE value;
    1.32 +  int count;
    1.33 +  unsigned int range;
    1.34 +} vp9_reader;
    1.35 +
    1.36 +DECLARE_ALIGNED(16, extern const uint8_t, vp9_norm[256]);
    1.37 +
    1.38 +int vp9_reader_init(vp9_reader *r, const uint8_t *buffer, size_t size);
    1.39 +
    1.40 +void vp9_reader_fill(vp9_reader *r);
    1.41 +
    1.42 +const uint8_t *vp9_reader_find_end(vp9_reader *r);
    1.43 +
    1.44 +static int vp9_read(vp9_reader *br, int probability) {
    1.45 +  unsigned int bit = 0;
    1.46 +  VP9_BD_VALUE value;
    1.47 +  VP9_BD_VALUE bigsplit;
    1.48 +  int count;
    1.49 +  unsigned int range;
    1.50 +  unsigned int split = ((br->range * probability) + (256 - probability)) >> 8;
    1.51 +
    1.52 +  if (br->count < 0)
    1.53 +    vp9_reader_fill(br);
    1.54 +
    1.55 +  value = br->value;
    1.56 +  count = br->count;
    1.57 +
    1.58 +  bigsplit = (VP9_BD_VALUE)split << (BD_VALUE_SIZE - 8);
    1.59 +
    1.60 +  range = split;
    1.61 +
    1.62 +  if (value >= bigsplit) {
    1.63 +    range = br->range - split;
    1.64 +    value = value - bigsplit;
    1.65 +    bit = 1;
    1.66 +  }
    1.67 +
    1.68 +  {
    1.69 +    register unsigned int shift = vp9_norm[range];
    1.70 +    range <<= shift;
    1.71 +    value <<= shift;
    1.72 +    count -= shift;
    1.73 +  }
    1.74 +  br->value = value;
    1.75 +  br->count = count;
    1.76 +  br->range = range;
    1.77 +
    1.78 +  return bit;
    1.79 +}
    1.80 +
    1.81 +static int vp9_read_bit(vp9_reader *r) {
    1.82 +  return vp9_read(r, 128);  // vp9_prob_half
    1.83 +}
    1.84 +
    1.85 +static int vp9_read_literal(vp9_reader *br, int bits) {
    1.86 +  int z = 0, bit;
    1.87 +
    1.88 +  for (bit = bits - 1; bit >= 0; bit--)
    1.89 +    z |= vp9_read_bit(br) << bit;
    1.90 +
    1.91 +  return z;
    1.92 +}
    1.93 +
    1.94 +int vp9_reader_has_error(vp9_reader *r);
    1.95 +
    1.96 +#endif  // VP9_DECODER_VP9_DBOOLHUFF_H_

mercurial