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 "dboolhuff.h"
13 #include "vpx_ports/mem.h"
14 #include "vpx_mem/vpx_mem.h"
15
16 DECLARE_ALIGNED(16, const unsigned char, vp8dx_bitreader_norm[256]) =
17 {
18 0, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
19 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
20 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
21 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
22 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
23 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
24 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
25 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
26 };
27
28
vp8dx_start_decode(BOOL_DECODER * br,const unsigned char * source,unsigned int source_sz)29 int vp8dx_start_decode(BOOL_DECODER *br,
30 const unsigned char *source,
31 unsigned int source_sz)
32 {
33 br->user_buffer_end = source+source_sz;
34 br->user_buffer = source;
35 br->value = 0;
36 br->count = -8;
37 br->range = 255;
38
39 if (source_sz && !source)
40 return 1;
41
42 /* Populate the buffer */
43 vp8dx_bool_decoder_fill(br);
44
45 return 0;
46 }
47
48
vp8dx_bool_decoder_fill(BOOL_DECODER * br)49 void vp8dx_bool_decoder_fill(BOOL_DECODER *br)
50 {
51 const unsigned char *bufptr;
52 const unsigned char *bufend;
53 VP8_BD_VALUE value;
54 int count;
55 bufend = br->user_buffer_end;
56 bufptr = br->user_buffer;
57 value = br->value;
58 count = br->count;
59
60 VP8DX_BOOL_DECODER_FILL(count, value, bufptr, bufend);
61
62 br->user_buffer = bufptr;
63 br->value = value;
64 br->count = count;
65 }
66