OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 | 11 |
12 #ifndef DBOOLHUFF_H | 12 #ifndef DBOOLHUFF_H_ |
13 #define DBOOLHUFF_H | 13 #define DBOOLHUFF_H_ |
| 14 |
14 #include <stddef.h> | 15 #include <stddef.h> |
15 #include <limits.h> | 16 #include <limits.h> |
| 17 |
16 #include "vpx_config.h" | 18 #include "vpx_config.h" |
17 #include "vpx_ports/mem.h" | 19 #include "vpx_ports/mem.h" |
18 #include "vpx/vpx_integer.h" | 20 #include "vpx/vpx_integer.h" |
19 | 21 |
20 typedef size_t VP8_BD_VALUE; | 22 typedef size_t VP8_BD_VALUE; |
21 | 23 |
22 # define VP8_BD_VALUE_SIZE ((int)sizeof(VP8_BD_VALUE)*CHAR_BIT) | 24 #define VP8_BD_VALUE_SIZE ((int)sizeof(VP8_BD_VALUE)*CHAR_BIT) |
| 25 |
23 /*This is meant to be a large, positive constant that can still be efficiently | 26 /*This is meant to be a large, positive constant that can still be efficiently |
24 loaded as an immediate (on platforms like ARM, for example). | 27 loaded as an immediate (on platforms like ARM, for example). |
25 Even relatively modest values like 100 would work fine.*/ | 28 Even relatively modest values like 100 would work fine.*/ |
26 # define VP8_LOTS_OF_BITS (0x40000000) | 29 #define VP8_LOTS_OF_BITS (0x40000000) |
27 | 30 |
28 typedef struct | 31 typedef struct |
29 { | 32 { |
30 const unsigned char *user_buffer_end; | 33 const unsigned char *user_buffer_end; |
31 const unsigned char *user_buffer; | 34 const unsigned char *user_buffer; |
32 VP8_BD_VALUE value; | 35 VP8_BD_VALUE value; |
33 int count; | 36 int count; |
34 unsigned int range; | 37 unsigned int range; |
35 } BOOL_DECODER; | 38 } BOOL_DECODER; |
36 | 39 |
37 DECLARE_ALIGNED(16, extern const unsigned char, vp8_norm[256]); | 40 DECLARE_ALIGNED(16, extern const unsigned char, vp8_norm[256]); |
38 | 41 |
39 int vp8dx_start_decode(BOOL_DECODER *br, | 42 int vp8dx_start_decode(BOOL_DECODER *br, |
40 const unsigned char *source, | 43 const unsigned char *source, |
41 unsigned int source_sz); | 44 unsigned int source_sz); |
42 | 45 |
43 void vp8dx_bool_decoder_fill(BOOL_DECODER *br); | 46 void vp8dx_bool_decoder_fill(BOOL_DECODER *br); |
44 | 47 |
45 /*The refill loop is used in several places, so define it in a macro to make | |
46 sure they're all consistent. | |
47 An inline function would be cleaner, but has a significant penalty, because | |
48 multiple BOOL_DECODER fields must be modified, and the compiler is not smart | |
49 enough to eliminate the stores to those fields and the subsequent reloads | |
50 from them when inlining the function.*/ | |
51 #define VP8DX_BOOL_DECODER_FILL(_count,_value,_bufptr,_bufend) \ | |
52 do \ | |
53 { \ | |
54 int shift = VP8_BD_VALUE_SIZE - 8 - ((_count) + 8); \ | |
55 int loop_end, x; \ | |
56 size_t bits_left = ((_bufend)-(_bufptr))*CHAR_BIT; \ | |
57 \ | |
58 x = (int)(shift + CHAR_BIT - bits_left); \ | |
59 loop_end = 0; \ | |
60 if(x >= 0) \ | |
61 { \ | |
62 (_count) += VP8_LOTS_OF_BITS; \ | |
63 loop_end = x; \ | |
64 if(!bits_left) break; \ | |
65 } \ | |
66 while(shift >= loop_end) \ | |
67 { \ | |
68 (_count) += CHAR_BIT; \ | |
69 (_value) |= (VP8_BD_VALUE)*(_bufptr)++ << shift; \ | |
70 shift -= CHAR_BIT; \ | |
71 } \ | |
72 } \ | |
73 while(0) \ | |
74 | |
75 | 48 |
76 static int vp8dx_decode_bool(BOOL_DECODER *br, int probability) { | 49 static int vp8dx_decode_bool(BOOL_DECODER *br, int probability) { |
77 unsigned int bit = 0; | 50 unsigned int bit = 0; |
78 VP8_BD_VALUE value; | 51 VP8_BD_VALUE value; |
79 unsigned int split; | 52 unsigned int split; |
80 VP8_BD_VALUE bigsplit; | 53 VP8_BD_VALUE bigsplit; |
81 int count; | 54 int count; |
82 unsigned int range; | 55 unsigned int range; |
83 | 56 |
84 split = 1 + (((br->range - 1) * probability) >> 8); | 57 split = 1 + (((br->range - 1) * probability) >> 8); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 { | 117 { |
145 /* We have tried to decode bits after the end of | 118 /* We have tried to decode bits after the end of |
146 * stream was encountered. | 119 * stream was encountered. |
147 */ | 120 */ |
148 return 1; | 121 return 1; |
149 } | 122 } |
150 | 123 |
151 /* No error. */ | 124 /* No error. */ |
152 return 0; | 125 return 0; |
153 } | 126 } |
154 #endif | 127 |
| 128 #endif // DBOOLHUFF_H_ |
OLD | NEW |