| 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 #include "boolhuff.h" | 12 #include "boolhuff.h" | 
| 13 #include "vp8/common/blockd.h" |  | 
| 14 |  | 
| 15 |  | 
| 16 | 13 | 
| 17 #if defined(SECTIONBITS_OUTPUT) | 14 #if defined(SECTIONBITS_OUTPUT) | 
| 18 unsigned __int64 Sectionbits[500]; | 15 unsigned __int64 Sectionbits[500]; | 
| 19 | 16 | 
| 20 #endif | 17 #endif | 
| 21 | 18 | 
| 22 #ifdef ENTROPY_STATS | 19 #ifdef ENTROPY_STATS | 
| 23 unsigned int active_section = 0; | 20 unsigned int active_section = 0; | 
| 24 #endif | 21 #endif | 
| 25 | 22 | 
| (...skipping 29 matching lines...) Expand all  Loading... | 
| 55 } | 52 } | 
| 56 | 53 | 
| 57 void vp8_stop_encode(BOOL_CODER *br) | 54 void vp8_stop_encode(BOOL_CODER *br) | 
| 58 { | 55 { | 
| 59     int i; | 56     int i; | 
| 60 | 57 | 
| 61     for (i = 0; i < 32; i++) | 58     for (i = 0; i < 32; i++) | 
| 62         vp8_encode_bool(br, 0, 128); | 59         vp8_encode_bool(br, 0, 128); | 
| 63 } | 60 } | 
| 64 | 61 | 
| 65 DECLARE_ALIGNED(16, static const unsigned int, norm[256]) = |  | 
| 66 { |  | 
| 67     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, |  | 
| 68     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, |  | 
| 69     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, |  | 
| 70     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, |  | 
| 71     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, |  | 
| 72     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, |  | 
| 73     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, |  | 
| 74     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 |  | 
| 75 }; |  | 
| 76 |  | 
| 77 void vp8_encode_bool(BOOL_CODER *br, int bit, int probability) |  | 
| 78 { |  | 
| 79     unsigned int split; |  | 
| 80     int count = br->count; |  | 
| 81     unsigned int range = br->range; |  | 
| 82     unsigned int lowvalue = br->lowvalue; |  | 
| 83     register unsigned int shift; |  | 
| 84 |  | 
| 85 #ifdef ENTROPY_STATS |  | 
| 86 #if defined(SECTIONBITS_OUTPUT) |  | 
| 87 |  | 
| 88     if (bit) |  | 
| 89         Sectionbits[active_section] += vp8_prob_cost[255-probability]; |  | 
| 90     else |  | 
| 91         Sectionbits[active_section] += vp8_prob_cost[probability]; |  | 
| 92 |  | 
| 93 #endif |  | 
| 94 #endif |  | 
| 95 |  | 
| 96     split = 1 + (((range - 1) * probability) >> 8); |  | 
| 97 |  | 
| 98     range = split; |  | 
| 99 |  | 
| 100     if (bit) |  | 
| 101     { |  | 
| 102         lowvalue += split; |  | 
| 103         range = br->range - split; |  | 
| 104     } |  | 
| 105 |  | 
| 106     shift = norm[range]; |  | 
| 107 |  | 
| 108     range <<= shift; |  | 
| 109     count += shift; |  | 
| 110 |  | 
| 111     if (count >= 0) |  | 
| 112     { |  | 
| 113         int offset = shift - count; |  | 
| 114 |  | 
| 115         if ((lowvalue << (offset - 1)) & 0x80000000) |  | 
| 116         { |  | 
| 117             int x = br->pos - 1; |  | 
| 118 |  | 
| 119             while (x >= 0 && br->buffer[x] == 0xff) |  | 
| 120             { |  | 
| 121                 br->buffer[x] = (unsigned char)0; |  | 
| 122                 x--; |  | 
| 123             } |  | 
| 124 |  | 
| 125             br->buffer[x] += 1; |  | 
| 126         } |  | 
| 127 |  | 
| 128         br->buffer[br->pos++] = (lowvalue >> (24 - offset)); |  | 
| 129         lowvalue <<= offset; |  | 
| 130         shift = count; |  | 
| 131         lowvalue &= 0xffffff; |  | 
| 132         count -= 8 ; |  | 
| 133     } |  | 
| 134 |  | 
| 135     lowvalue <<= shift; |  | 
| 136     br->count = count; |  | 
| 137     br->lowvalue = lowvalue; |  | 
| 138     br->range = range; |  | 
| 139 } |  | 
| 140 | 62 | 
| 141 void vp8_encode_value(BOOL_CODER *br, int data, int bits) | 63 void vp8_encode_value(BOOL_CODER *br, int data, int bits) | 
| 142 { | 64 { | 
| 143     int bit; | 65     int bit; | 
| 144 | 66 | 
| 145     for (bit = bits - 1; bit >= 0; bit--) | 67     for (bit = bits - 1; bit >= 0; bit--) | 
| 146         vp8_encode_bool(br, (1 & (data >> bit)), 0x80); | 68         vp8_encode_bool(br, (1 & (data >> bit)), 0x80); | 
| 147 | 69 | 
| 148 } | 70 } | 
| OLD | NEW | 
|---|