| 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 #ifndef VP9_DECODER_VP9_DBOOLHUFF_H_ | 11 #ifndef VP9_DECODER_VP9_DBOOLHUFF_H_ |
| 12 #define VP9_DECODER_VP9_DBOOLHUFF_H_ | 12 #define VP9_DECODER_VP9_DBOOLHUFF_H_ |
| 13 | 13 |
| 14 #include <stddef.h> | 14 #include <stddef.h> |
| 15 #include <limits.h> | 15 #include <limits.h> |
| 16 | 16 |
| 17 #include "./vpx_config.h" | 17 #include "./vpx_config.h" |
| 18 #include "vpx_ports/mem.h" | 18 #include "vpx_ports/mem.h" |
| 19 #include "vpx/vpx_integer.h" | 19 #include "vpx/vpx_integer.h" |
| 20 | 20 |
| 21 typedef size_t VP9_BD_VALUE; | 21 #include "vp9/common/vp9_treecoder.h" |
| 22 | 22 |
| 23 #define BD_VALUE_SIZE ((int)sizeof(VP9_BD_VALUE)*CHAR_BIT) | 23 typedef size_t BD_VALUE; |
| 24 |
| 25 #define BD_VALUE_SIZE ((int)sizeof(BD_VALUE) * CHAR_BIT) |
| 26 |
| 27 DECLARE_ALIGNED(16, extern const uint8_t, vp9_norm[256]); |
| 24 | 28 |
| 25 typedef struct { | 29 typedef struct { |
| 26 const uint8_t *buffer_end; | 30 const uint8_t *buffer_end; |
| 27 const uint8_t *buffer; | 31 const uint8_t *buffer; |
| 28 VP9_BD_VALUE value; | 32 BD_VALUE value; |
| 29 int count; | 33 int count; |
| 30 unsigned int range; | 34 unsigned int range; |
| 31 } vp9_reader; | 35 } vp9_reader; |
| 32 | 36 |
| 33 DECLARE_ALIGNED(16, extern const uint8_t, vp9_norm[256]); | |
| 34 | |
| 35 int vp9_reader_init(vp9_reader *r, const uint8_t *buffer, size_t size); | 37 int vp9_reader_init(vp9_reader *r, const uint8_t *buffer, size_t size); |
| 36 | 38 |
| 37 void vp9_reader_fill(vp9_reader *r); | 39 void vp9_reader_fill(vp9_reader *r); |
| 38 | 40 |
| 41 int vp9_reader_has_error(vp9_reader *r); |
| 42 |
| 39 const uint8_t *vp9_reader_find_end(vp9_reader *r); | 43 const uint8_t *vp9_reader_find_end(vp9_reader *r); |
| 40 | 44 |
| 41 static int vp9_read(vp9_reader *br, int probability) { | 45 static int vp9_read(vp9_reader *r, int prob) { |
| 42 unsigned int bit = 0; | 46 unsigned int bit = 0; |
| 43 VP9_BD_VALUE value; | 47 BD_VALUE value; |
| 44 VP9_BD_VALUE bigsplit; | 48 BD_VALUE bigsplit; |
| 45 int count; | 49 int count; |
| 46 unsigned int range; | 50 unsigned int range; |
| 47 unsigned int split = 1 + (((br->range - 1) * probability) >> 8); | 51 unsigned int split = (r->range * prob + (256 - prob)) >> CHAR_BIT; |
| 48 | 52 |
| 49 if (br->count < 0) | 53 if (r->count < 0) |
| 50 vp9_reader_fill(br); | 54 vp9_reader_fill(r); |
| 51 | 55 |
| 52 value = br->value; | 56 value = r->value; |
| 53 count = br->count; | 57 count = r->count; |
| 54 | 58 |
| 55 bigsplit = (VP9_BD_VALUE)split << (BD_VALUE_SIZE - 8); | 59 bigsplit = (BD_VALUE)split << (BD_VALUE_SIZE - CHAR_BIT); |
| 56 | 60 |
| 57 range = split; | 61 range = split; |
| 58 | 62 |
| 59 if (value >= bigsplit) { | 63 if (value >= bigsplit) { |
| 60 range = br->range - split; | 64 range = r->range - split; |
| 61 value = value - bigsplit; | 65 value = value - bigsplit; |
| 62 bit = 1; | 66 bit = 1; |
| 63 } | 67 } |
| 64 | 68 |
| 65 { | 69 { |
| 66 register unsigned int shift = vp9_norm[range]; | 70 register unsigned int shift = vp9_norm[range]; |
| 67 range <<= shift; | 71 range <<= shift; |
| 68 value <<= shift; | 72 value <<= shift; |
| 69 count -= shift; | 73 count -= shift; |
| 70 } | 74 } |
| 71 br->value = value; | 75 r->value = value; |
| 72 br->count = count; | 76 r->count = count; |
| 73 br->range = range; | 77 r->range = range; |
| 74 | 78 |
| 75 return bit; | 79 return bit; |
| 76 } | 80 } |
| 77 | 81 |
| 78 static int vp9_read_bit(vp9_reader *r) { | 82 static int vp9_read_bit(vp9_reader *r) { |
| 79 return vp9_read(r, 128); // vp9_prob_half | 83 return vp9_read(r, 128); // vp9_prob_half |
| 80 } | 84 } |
| 81 | 85 |
| 82 static int vp9_read_literal(vp9_reader *br, int bits) { | 86 static int vp9_read_literal(vp9_reader *r, int bits) { |
| 83 int z = 0, bit; | 87 int literal = 0, bit; |
| 84 | 88 |
| 85 for (bit = bits - 1; bit >= 0; bit--) | 89 for (bit = bits - 1; bit >= 0; bit--) |
| 86 z |= vp9_read_bit(br) << bit; | 90 literal |= vp9_read_bit(r) << bit; |
| 87 | 91 |
| 88 return z; | 92 return literal; |
| 89 } | 93 } |
| 90 | 94 |
| 91 int vp9_reader_has_error(vp9_reader *r); | 95 static int vp9_read_tree(vp9_reader *r, const vp9_tree_index *tree, |
| 96 const vp9_prob *probs) { |
| 97 vp9_tree_index i = 0; |
| 98 |
| 99 while ((i = tree[i + vp9_read(r, probs[i >> 1])]) > 0) |
| 100 continue; |
| 101 |
| 102 return -i; |
| 103 } |
| 92 | 104 |
| 93 #endif // VP9_DECODER_VP9_DBOOLHUFF_H_ | 105 #endif // VP9_DECODER_VP9_DBOOLHUFF_H_ |
| OLD | NEW |