OLD | NEW |
(Empty) | |
| 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 /**************************************************************************** |
| 13 * |
| 14 * Module Title : vp9_boolhuff.h |
| 15 * |
| 16 * Description : Bool Coder header file. |
| 17 * |
| 18 ****************************************************************************/ |
| 19 #ifndef VP9_ENCODER_VP9_BOOLHUFF_H_ |
| 20 #define VP9_ENCODER_VP9_BOOLHUFF_H_ |
| 21 |
| 22 #include "vpx_ports/mem.h" |
| 23 |
| 24 typedef struct { |
| 25 unsigned int lowvalue; |
| 26 unsigned int range; |
| 27 unsigned int value; |
| 28 int count; |
| 29 unsigned int pos; |
| 30 unsigned char *buffer; |
| 31 |
| 32 // Variables used to track bit costs without outputing to the bitstream |
| 33 unsigned int measure_cost; |
| 34 unsigned long bit_counter; |
| 35 } BOOL_CODER; |
| 36 |
| 37 extern void vp9_start_encode(BOOL_CODER *bc, unsigned char *buffer); |
| 38 |
| 39 extern void vp9_encode_value(BOOL_CODER *br, int data, int bits); |
| 40 extern void vp9_encode_unsigned_max(BOOL_CODER *br, int data, int max); |
| 41 extern void vp9_stop_encode(BOOL_CODER *bc); |
| 42 extern const unsigned int vp9_prob_cost[256]; |
| 43 |
| 44 extern void vp9_encode_uniform(BOOL_CODER *bc, int v, int n); |
| 45 extern void vp9_encode_term_subexp(BOOL_CODER *bc, int v, int k, int n); |
| 46 extern int vp9_count_uniform(int v, int n); |
| 47 extern int vp9_count_term_subexp(int v, int k, int n); |
| 48 extern int vp9_recenter_nonneg(int v, int m); |
| 49 |
| 50 DECLARE_ALIGNED(16, extern const unsigned char, vp9_norm[256]); |
| 51 |
| 52 |
| 53 static void encode_bool(BOOL_CODER *br, int bit, int probability) { |
| 54 unsigned int split; |
| 55 int count = br->count; |
| 56 unsigned int range = br->range; |
| 57 unsigned int lowvalue = br->lowvalue; |
| 58 register unsigned int shift; |
| 59 |
| 60 #ifdef ENTROPY_STATS |
| 61 #if defined(SECTIONBITS_OUTPUT) |
| 62 |
| 63 if (bit) |
| 64 Sectionbits[active_section] += vp9_prob_cost[255 - probability]; |
| 65 else |
| 66 Sectionbits[active_section] += vp9_prob_cost[probability]; |
| 67 |
| 68 #endif |
| 69 #endif |
| 70 |
| 71 split = 1 + (((range - 1) * probability) >> 8); |
| 72 |
| 73 range = split; |
| 74 |
| 75 if (bit) { |
| 76 lowvalue += split; |
| 77 range = br->range - split; |
| 78 } |
| 79 |
| 80 shift = vp9_norm[range]; |
| 81 |
| 82 range <<= shift; |
| 83 count += shift; |
| 84 |
| 85 if (count >= 0) { |
| 86 int offset = shift - count; |
| 87 |
| 88 if ((lowvalue << (offset - 1)) & 0x80000000) { |
| 89 int x = br->pos - 1; |
| 90 |
| 91 while (x >= 0 && br->buffer[x] == 0xff) { |
| 92 br->buffer[x] = (unsigned char)0; |
| 93 x--; |
| 94 } |
| 95 |
| 96 br->buffer[x] += 1; |
| 97 } |
| 98 |
| 99 br->buffer[br->pos++] = (lowvalue >> (24 - offset)); |
| 100 lowvalue <<= offset; |
| 101 shift = count; |
| 102 lowvalue &= 0xffffff; |
| 103 count -= 8; |
| 104 } |
| 105 |
| 106 lowvalue <<= shift; |
| 107 br->count = count; |
| 108 br->lowvalue = lowvalue; |
| 109 br->range = range; |
| 110 } |
| 111 |
| 112 #endif |
OLD | NEW |