comparison rangecoder.c @ 2967:ef2149182f1c libavcodec

COSMETICS: Remove all trailing whitespace.
author diego
date Sat, 17 Dec 2005 18:14:38 +0000
parents 95bac7109ff0
children 0b546eab515d
comparison
equal deleted inserted replaced
2966:564788471dd4 2967:ef2149182f1c
15 * You should have received a copy of the GNU Lesser General Public 15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software 16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * 18 *
19 */ 19 */
20 20
21 /** 21 /**
22 * @file rangecoder.c 22 * @file rangecoder.c
23 * Range coder. 23 * Range coder.
24 * based upon 24 * based upon
25 * "Range encoding: an algorithm for removing redundancy from a digitised 25 * "Range encoding: an algorithm for removing redundancy from a digitised
36 #include "common.h" 36 #include "common.h"
37 #include "rangecoder.h" 37 #include "rangecoder.h"
38 38
39 39
40 void ff_init_range_encoder(RangeCoder *c, uint8_t *buf, int buf_size){ 40 void ff_init_range_encoder(RangeCoder *c, uint8_t *buf, int buf_size){
41 c->bytestream_start= 41 c->bytestream_start=
42 c->bytestream= buf; 42 c->bytestream= buf;
43 c->bytestream_end= buf + buf_size; 43 c->bytestream_end= buf + buf_size;
44 44
45 c->low= 0; 45 c->low= 0;
46 c->range= 0xFF00; 46 c->range= 0xFF00;
64 memset(c->zero_state, 0, sizeof(c->zero_state)); 64 memset(c->zero_state, 0, sizeof(c->zero_state));
65 memset(c-> one_state, 0, sizeof(c-> one_state)); 65 memset(c-> one_state, 0, sizeof(c-> one_state));
66 66
67 #if 0 67 #if 0
68 for(i=1; i<256; i++){ 68 for(i=1; i<256; i++){
69 if(c->one_state[i]) 69 if(c->one_state[i])
70 continue; 70 continue;
71 71
72 p= (i*one + 128) >> 8; 72 p= (i*one + 128) >> 8;
73 last_p8= i; 73 last_p8= i;
74 for(;;){ 74 for(;;){
75 p+= ((one-p)*factor + one/2) >> 32; 75 p+= ((one-p)*factor + one/2) >> 32;
76 p8= (256*p + one/2) >> 32; //FIXME try without the one 76 p8= (256*p + one/2) >> 32; //FIXME try without the one
91 for(i=0; i<128; i++){ 91 for(i=0; i<128; i++){
92 p8= (256*p + one/2) >> 32; //FIXME try without the one 92 p8= (256*p + one/2) >> 32; //FIXME try without the one
93 if(p8 <= last_p8) p8= last_p8+1; 93 if(p8 <= last_p8) p8= last_p8+1;
94 if(last_p8 && last_p8<256 && p8<=max_p) 94 if(last_p8 && last_p8<256 && p8<=max_p)
95 c->one_state[last_p8]= p8; 95 c->one_state[last_p8]= p8;
96 96
97 p+= ((one-p)*factor + one/2) >> 32; 97 p+= ((one-p)*factor + one/2) >> 32;
98 last_p8= p8; 98 last_p8= p8;
99 } 99 }
100 #endif 100 #endif
101 for(i=256-max_p; i<=max_p; i++){ 101 for(i=256-max_p; i<=max_p; i++){
102 if(c->one_state[i]) 102 if(c->one_state[i])
103 continue; 103 continue;
104 104
105 p= (i*one + 128) >> 8; 105 p= (i*one + 128) >> 8;
106 p+= ((one-p)*factor + one/2) >> 32; 106 p+= ((one-p)*factor + one/2) >> 32;
107 p8= (256*p + one/2) >> 32; //FIXME try without the one 107 p8= (256*p + one/2) >> 32; //FIXME try without the one
108 if(p8 <= i) p8= i+1; 108 if(p8 <= i) p8= i+1;
109 if(p8 > max_p) p8= max_p; 109 if(p8 > max_p) p8= max_p;
110 c->one_state[ i]= p8; 110 c->one_state[ i]= p8;
111 } 111 }
112 112
113 for(i=0; i<256; i++) 113 for(i=0; i<256; i++)
114 c->zero_state[i]= 256-c->one_state[256-i]; 114 c->zero_state[i]= 256-c->one_state[256-i];
115 #if 0 115 #if 0
116 for(i=0; i<256; i++) 116 for(i=0; i<256; i++)
117 av_log(NULL, AV_LOG_DEBUG, "%3d %3d\n", i, c->one_state[i]); 117 av_log(NULL, AV_LOG_DEBUG, "%3d %3d\n", i, c->one_state[i]);
141 RangeCoder c; 141 RangeCoder c;
142 uint8_t b[9*SIZE]; 142 uint8_t b[9*SIZE];
143 uint8_t r[9*SIZE]; 143 uint8_t r[9*SIZE];
144 int i; 144 int i;
145 uint8_t state[10]= {0}; 145 uint8_t state[10]= {0};
146 146
147 ff_init_range_encoder(&c, b, SIZE); 147 ff_init_range_encoder(&c, b, SIZE);
148 ff_build_rac_states(&c, 0.05*(1LL<<32), 128+64+32+16); 148 ff_build_rac_states(&c, 0.05*(1LL<<32), 128+64+32+16);
149 149
150 memset(state, 128, sizeof(state)); 150 memset(state, 128, sizeof(state));
151 151
152 for(i=0; i<SIZE; i++){ 152 for(i=0; i<SIZE; i++){
153 r[i]= random()%7; 153 r[i]= random()%7;
154 } 154 }
155 155
156 156
157 for(i=0; i<SIZE; i++){ 157 for(i=0; i<SIZE; i++){
158 START_TIMER 158 START_TIMER
159 put_rac(&c, state, r[i]&1); 159 put_rac(&c, state, r[i]&1);
160 STOP_TIMER("put_rac") 160 STOP_TIMER("put_rac")
161 } 161 }
162 162
163 ff_put_rac_terminate(&c); 163 ff_put_rac_terminate(&c);
164 164
165 ff_init_range_decoder(&c, b, SIZE); 165 ff_init_range_decoder(&c, b, SIZE);
166 166
167 memset(state, 128, sizeof(state)); 167 memset(state, 128, sizeof(state));
168 168
169 for(i=0; i<SIZE; i++){ 169 for(i=0; i<SIZE; i++){
170 START_TIMER 170 START_TIMER
171 if( (r[i]&1) != get_rac(&c, state) ) 171 if( (r[i]&1) != get_rac(&c, state) )
172 av_log(NULL, AV_LOG_DEBUG, "rac failure at %d\n", i); 172 av_log(NULL, AV_LOG_DEBUG, "rac failure at %d\n", i);
173 STOP_TIMER("get_rac") 173 STOP_TIMER("get_rac")
174 } 174 }
175 175
176 return 0; 176 return 0;
177 } 177 }
178 178
179 #endif 179 #endif