2010-05-18 17:58:33 +02:00
|
|
|
/*
|
2010-09-09 14:16:39 +02:00
|
|
|
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
|
2010-05-18 17:58:33 +02:00
|
|
|
*
|
2010-06-18 18:39:21 +02:00
|
|
|
* Use of this source code is governed by a BSD-style license
|
2010-06-04 22:19:40 +02:00
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
2010-06-18 18:39:21 +02:00
|
|
|
* in the file PATENTS. All contributing project authors may
|
2010-06-04 22:19:40 +02:00
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
2010-05-18 17:58:33 +02:00
|
|
|
*/
|
|
|
|
|
2012-11-30 01:36:10 +01:00
|
|
|
#ifndef VP9_DECODER_VP9_DBOOLHUFF_H_
|
|
|
|
#define VP9_DECODER_VP9_DBOOLHUFF_H_
|
2012-12-19 00:31:19 +01:00
|
|
|
|
2010-05-05 23:58:19 +02:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <limits.h>
|
2013-03-05 23:12:16 +01:00
|
|
|
|
2012-12-23 16:20:10 +01:00
|
|
|
#include "./vpx_config.h"
|
2010-05-18 17:58:33 +02:00
|
|
|
#include "vpx_ports/mem.h"
|
2010-05-24 17:39:59 +02:00
|
|
|
#include "vpx/vpx_integer.h"
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
typedef size_t VP9_BD_VALUE;
|
2010-05-05 23:58:19 +02:00
|
|
|
|
2013-08-23 03:40:34 +02:00
|
|
|
#define BD_VALUE_SIZE ((int)sizeof(VP9_BD_VALUE)*CHAR_BIT)
|
2013-04-15 23:54:19 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
typedef struct {
|
2013-04-15 23:54:19 +02:00
|
|
|
const uint8_t *buffer_end;
|
|
|
|
const uint8_t *buffer;
|
|
|
|
VP9_BD_VALUE value;
|
|
|
|
int count;
|
|
|
|
unsigned int range;
|
2013-04-19 19:37:24 +02:00
|
|
|
} vp9_reader;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-12-19 00:31:19 +01:00
|
|
|
DECLARE_ALIGNED(16, extern const uint8_t, vp9_norm[256]);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-04-19 19:37:24 +02:00
|
|
|
int vp9_reader_init(vp9_reader *r, const uint8_t *buffer, size_t size);
|
2011-02-04 22:00:00 +01:00
|
|
|
|
2013-04-19 19:37:24 +02:00
|
|
|
void vp9_reader_fill(vp9_reader *r);
|
2010-05-05 23:58:19 +02:00
|
|
|
|
2013-04-19 19:37:24 +02:00
|
|
|
const uint8_t *vp9_reader_find_end(vp9_reader *r);
|
2013-04-15 23:54:19 +02:00
|
|
|
|
2013-04-19 19:37:24 +02:00
|
|
|
static int vp9_read(vp9_reader *br, int probability) {
|
2012-07-14 00:21:29 +02:00
|
|
|
unsigned int bit = 0;
|
2012-10-31 22:40:53 +01:00
|
|
|
VP9_BD_VALUE value;
|
|
|
|
VP9_BD_VALUE bigsplit;
|
2012-07-14 00:21:29 +02:00
|
|
|
int count;
|
|
|
|
unsigned int range;
|
2013-11-04 23:56:37 +01:00
|
|
|
unsigned int split = ((br->range * probability) + (256 - probability)) >> 8;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
if (br->count < 0)
|
2013-04-15 23:54:19 +02:00
|
|
|
vp9_reader_fill(br);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
value = br->value;
|
|
|
|
count = br->count;
|
|
|
|
|
2013-08-23 03:40:34 +02:00
|
|
|
bigsplit = (VP9_BD_VALUE)split << (BD_VALUE_SIZE - 8);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
range = split;
|
|
|
|
|
|
|
|
if (value >= bigsplit) {
|
|
|
|
range = br->range - split;
|
|
|
|
value = value - bigsplit;
|
|
|
|
bit = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2012-10-31 01:12:12 +01:00
|
|
|
register unsigned int shift = vp9_norm[range];
|
2012-07-14 00:21:29 +02:00
|
|
|
range <<= shift;
|
|
|
|
value <<= shift;
|
|
|
|
count -= shift;
|
|
|
|
}
|
|
|
|
br->value = value;
|
|
|
|
br->count = count;
|
|
|
|
br->range = range;
|
|
|
|
|
|
|
|
return bit;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2013-04-19 19:37:24 +02:00
|
|
|
static int vp9_read_bit(vp9_reader *r) {
|
2013-04-15 23:54:19 +02:00
|
|
|
return vp9_read(r, 128); // vp9_prob_half
|
|
|
|
}
|
|
|
|
|
2013-04-19 19:37:24 +02:00
|
|
|
static int vp9_read_literal(vp9_reader *br, int bits) {
|
2013-04-15 23:54:19 +02:00
|
|
|
int z = 0, bit;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-04-19 19:37:24 +02:00
|
|
|
for (bit = bits - 1; bit >= 0; bit--)
|
2013-04-15 23:54:19 +02:00
|
|
|
z |= vp9_read_bit(br) << bit;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
return z;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
2010-12-16 16:46:31 +01:00
|
|
|
|
2013-07-15 21:26:58 +02:00
|
|
|
int vp9_reader_has_error(vp9_reader *r);
|
2012-04-12 18:24:03 +02:00
|
|
|
|
2012-12-19 00:31:19 +01:00
|
|
|
#endif // VP9_DECODER_VP9_DBOOLHUFF_H_
|