| 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 /**************************************************************************** | 12 /**************************************************************************** | 
| 13 * | 13 * | 
| 14 *   Module Title :     boolhuff.h | 14 *   Module Title :     boolhuff.h | 
| 15 * | 15 * | 
| 16 *   Description  :     Bool Coder header file. | 16 *   Description  :     Bool Coder header file. | 
| 17 * | 17 * | 
| 18 ****************************************************************************/ | 18 ****************************************************************************/ | 
| 19 #ifndef __INC_BOOLHUFF_H | 19 #ifndef __INC_BOOLHUFF_H | 
| 20 #define __INC_BOOLHUFF_H | 20 #define __INC_BOOLHUFF_H | 
| 21 | 21 | 
|  | 22 #include "vpx_ports/mem.h" | 
| 22 | 23 | 
| 23 typedef struct | 24 typedef struct | 
| 24 { | 25 { | 
| 25     unsigned int lowvalue; | 26     unsigned int lowvalue; | 
| 26     unsigned int range; | 27     unsigned int range; | 
| 27     unsigned int value; | 28     unsigned int value; | 
| 28     int count; | 29     int count; | 
| 29     unsigned int pos; | 30     unsigned int pos; | 
| 30     unsigned char *buffer; | 31     unsigned char *buffer; | 
| 31 | 32 | 
| 32     // Variables used to track bit costs without outputing to the bitstream | 33     // Variables used to track bit costs without outputing to the bitstream | 
| 33     unsigned int  measure_cost; | 34     unsigned int  measure_cost; | 
| 34     unsigned long bit_counter; | 35     unsigned long bit_counter; | 
| 35 } BOOL_CODER; | 36 } BOOL_CODER; | 
| 36 | 37 | 
| 37 extern void vp8_start_encode(BOOL_CODER *bc, unsigned char *buffer); | 38 extern void vp8_start_encode(BOOL_CODER *bc, unsigned char *buffer); | 
| 38 extern void vp8_encode_bool(BOOL_CODER *bc, int x, int context); | 39 | 
| 39 extern void vp8_encode_value(BOOL_CODER *br, int data, int bits); | 40 extern void vp8_encode_value(BOOL_CODER *br, int data, int bits); | 
| 40 extern void vp8_stop_encode(BOOL_CODER *bc); | 41 extern void vp8_stop_encode(BOOL_CODER *bc); | 
| 41 extern const unsigned int vp8_prob_cost[256]; | 42 extern const unsigned int vp8_prob_cost[256]; | 
| 42 | 43 | 
|  | 44 | 
|  | 45 DECLARE_ALIGNED(16, extern const unsigned char, vp8_norm[256]); | 
|  | 46 | 
|  | 47 | 
|  | 48 static void vp8_encode_bool(BOOL_CODER *br, int bit, int probability) | 
|  | 49 { | 
|  | 50     unsigned int split; | 
|  | 51     int count = br->count; | 
|  | 52     unsigned int range = br->range; | 
|  | 53     unsigned int lowvalue = br->lowvalue; | 
|  | 54     register unsigned int shift; | 
|  | 55 | 
|  | 56 #ifdef ENTROPY_STATS | 
|  | 57 #if defined(SECTIONBITS_OUTPUT) | 
|  | 58 | 
|  | 59     if (bit) | 
|  | 60         Sectionbits[active_section] += vp8_prob_cost[255-probability]; | 
|  | 61     else | 
|  | 62         Sectionbits[active_section] += vp8_prob_cost[probability]; | 
|  | 63 | 
| 43 #endif | 64 #endif | 
|  | 65 #endif | 
|  | 66 | 
|  | 67     split = 1 + (((range - 1) * probability) >> 8); | 
|  | 68 | 
|  | 69     range = split; | 
|  | 70 | 
|  | 71     if (bit) | 
|  | 72     { | 
|  | 73         lowvalue += split; | 
|  | 74         range = br->range - split; | 
|  | 75     } | 
|  | 76 | 
|  | 77     shift = vp8_norm[range]; | 
|  | 78 | 
|  | 79     range <<= shift; | 
|  | 80     count += shift; | 
|  | 81 | 
|  | 82     if (count >= 0) | 
|  | 83     { | 
|  | 84         int offset = shift - count; | 
|  | 85 | 
|  | 86         if ((lowvalue << (offset - 1)) & 0x80000000) | 
|  | 87         { | 
|  | 88             int x = br->pos - 1; | 
|  | 89 | 
|  | 90             while (x >= 0 && br->buffer[x] == 0xff) | 
|  | 91             { | 
|  | 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 | 
|---|