comparison golomb.h @ 2967:ef2149182f1c libavcodec

COSMETICS: Remove all trailing whitespace.
author diego
date Sat, 17 Dec 2005 18:14:38 +0000
parents 926ea374947f
children bfabfdf9ce55
comparison
equal deleted inserted replaced
2966:564788471dd4 2967:ef2149182f1c
16 * You should have received a copy of the GNU Lesser General Public 16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software 17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * 19 *
20 */ 20 */
21 21
22 /** 22 /**
23 * @file golomb.h 23 * @file golomb.h
24 * @brief 24 * @brief
25 * exp golomb vlc stuff 25 * exp golomb vlc stuff
26 * @author Michael Niedermayer <michaelni@gmx.at> and Alex Beregszaszi 26 * @author Michael Niedermayer <michaelni@gmx.at> and Alex Beregszaszi
27 */ 27 */
28 28
29 #define INVALID_VLC 0x80000000 29 #define INVALID_VLC 0x80000000
35 35
36 extern const uint8_t ff_interleaved_golomb_vlc_len[256]; 36 extern const uint8_t ff_interleaved_golomb_vlc_len[256];
37 extern const uint8_t ff_interleaved_ue_golomb_vlc_code[256]; 37 extern const uint8_t ff_interleaved_ue_golomb_vlc_code[256];
38 extern const int8_t ff_interleaved_se_golomb_vlc_code[256]; 38 extern const int8_t ff_interleaved_se_golomb_vlc_code[256];
39 39
40 40
41 /** 41 /**
42 * read unsigned exp golomb code. 42 * read unsigned exp golomb code.
43 */ 43 */
44 static inline int get_ue_golomb(GetBitContext *gb){ 44 static inline int get_ue_golomb(GetBitContext *gb){
45 unsigned int buf; 45 unsigned int buf;
46 int log; 46 int log;
47 47
48 OPEN_READER(re, gb); 48 OPEN_READER(re, gb);
49 UPDATE_CACHE(re, gb); 49 UPDATE_CACHE(re, gb);
50 buf=GET_CACHE(re, gb); 50 buf=GET_CACHE(re, gb);
51 51
52 if(buf >= (1<<27)){ 52 if(buf >= (1<<27)){
53 buf >>= 32 - 9; 53 buf >>= 32 - 9;
54 LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]); 54 LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]);
55 CLOSE_READER(re, gb); 55 CLOSE_READER(re, gb);
56 56
57 return ff_ue_golomb_vlc_code[buf]; 57 return ff_ue_golomb_vlc_code[buf];
58 }else{ 58 }else{
59 log= 2*av_log2(buf) - 31; 59 log= 2*av_log2(buf) - 31;
60 buf>>= log; 60 buf>>= log;
61 buf--; 61 buf--;
62 LAST_SKIP_BITS(re, gb, 32 - log); 62 LAST_SKIP_BITS(re, gb, 32 - log);
63 CLOSE_READER(re, gb); 63 CLOSE_READER(re, gb);
64 64
65 return buf; 65 return buf;
66 } 66 }
67 } 67 }
68 68
69 static inline int svq3_get_ue_golomb(GetBitContext *gb){ 69 static inline int svq3_get_ue_golomb(GetBitContext *gb){
71 int log; 71 int log;
72 72
73 OPEN_READER(re, gb); 73 OPEN_READER(re, gb);
74 UPDATE_CACHE(re, gb); 74 UPDATE_CACHE(re, gb);
75 buf=GET_CACHE(re, gb); 75 buf=GET_CACHE(re, gb);
76 76
77 if(buf&0xAA800000){ 77 if(buf&0xAA800000){
78 buf >>= 32 - 8; 78 buf >>= 32 - 8;
79 LAST_SKIP_BITS(re, gb, ff_interleaved_golomb_vlc_len[buf]); 79 LAST_SKIP_BITS(re, gb, ff_interleaved_golomb_vlc_len[buf]);
80 CLOSE_READER(re, gb); 80 CLOSE_READER(re, gb);
81 81
82 return ff_interleaved_ue_golomb_vlc_code[buf]; 82 return ff_interleaved_ue_golomb_vlc_code[buf];
83 }else{ 83 }else{
84 LAST_SKIP_BITS(re, gb, 8); 84 LAST_SKIP_BITS(re, gb, 8);
85 UPDATE_CACHE(re, gb); 85 UPDATE_CACHE(re, gb);
86 buf |= 1 | (GET_CACHE(re, gb) >> 8); 86 buf |= 1 | (GET_CACHE(re, gb) >> 8);
102 /** 102 /**
103 * read unsigned truncated exp golomb code. 103 * read unsigned truncated exp golomb code.
104 */ 104 */
105 static inline int get_te0_golomb(GetBitContext *gb, int range){ 105 static inline int get_te0_golomb(GetBitContext *gb, int range){
106 assert(range >= 1); 106 assert(range >= 1);
107 107
108 if(range==1) return 0; 108 if(range==1) return 0;
109 else if(range==2) return get_bits1(gb)^1; 109 else if(range==2) return get_bits1(gb)^1;
110 else return get_ue_golomb(gb); 110 else return get_ue_golomb(gb);
111 } 111 }
112 112
113 /** 113 /**
114 * read unsigned truncated exp golomb code. 114 * read unsigned truncated exp golomb code.
115 */ 115 */
116 static inline int get_te_golomb(GetBitContext *gb, int range){ 116 static inline int get_te_golomb(GetBitContext *gb, int range){
117 assert(range >= 1); 117 assert(range >= 1);
118 118
119 if(range==2) return get_bits1(gb)^1; 119 if(range==2) return get_bits1(gb)^1;
120 else return get_ue_golomb(gb); 120 else return get_ue_golomb(gb);
121 } 121 }
122 122
123 123
125 * read signed exp golomb code. 125 * read signed exp golomb code.
126 */ 126 */
127 static inline int get_se_golomb(GetBitContext *gb){ 127 static inline int get_se_golomb(GetBitContext *gb){
128 unsigned int buf; 128 unsigned int buf;
129 int log; 129 int log;
130 130
131 OPEN_READER(re, gb); 131 OPEN_READER(re, gb);
132 UPDATE_CACHE(re, gb); 132 UPDATE_CACHE(re, gb);
133 buf=GET_CACHE(re, gb); 133 buf=GET_CACHE(re, gb);
134 134
135 if(buf >= (1<<27)){ 135 if(buf >= (1<<27)){
136 buf >>= 32 - 9; 136 buf >>= 32 - 9;
137 LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]); 137 LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]);
138 CLOSE_READER(re, gb); 138 CLOSE_READER(re, gb);
139 139
140 return ff_se_golomb_vlc_code[buf]; 140 return ff_se_golomb_vlc_code[buf];
141 }else{ 141 }else{
142 log= 2*av_log2(buf) - 31; 142 log= 2*av_log2(buf) - 31;
143 buf>>= log; 143 buf>>= log;
144 144
145 LAST_SKIP_BITS(re, gb, 32 - log); 145 LAST_SKIP_BITS(re, gb, 32 - log);
146 CLOSE_READER(re, gb); 146 CLOSE_READER(re, gb);
147 147
148 if(buf&1) buf= -(buf>>1); 148 if(buf&1) buf= -(buf>>1);
149 else buf= (buf>>1); 149 else buf= (buf>>1);
150 150
151 return buf; 151 return buf;
152 } 152 }
162 162
163 if(buf&0xAA800000){ 163 if(buf&0xAA800000){
164 buf >>= 32 - 8; 164 buf >>= 32 - 8;
165 LAST_SKIP_BITS(re, gb, ff_interleaved_golomb_vlc_len[buf]); 165 LAST_SKIP_BITS(re, gb, ff_interleaved_golomb_vlc_len[buf]);
166 CLOSE_READER(re, gb); 166 CLOSE_READER(re, gb);
167 167
168 return ff_interleaved_se_golomb_vlc_code[buf]; 168 return ff_interleaved_se_golomb_vlc_code[buf];
169 }else{ 169 }else{
170 LAST_SKIP_BITS(re, gb, 8); 170 LAST_SKIP_BITS(re, gb, 8);
171 UPDATE_CACHE(re, gb); 171 UPDATE_CACHE(re, gb);
172 buf |= 1 | (GET_CACHE(re, gb) >> 8); 172 buf |= 1 | (GET_CACHE(re, gb) >> 8);
189 * read unsigned golomb rice code (ffv1). 189 * read unsigned golomb rice code (ffv1).
190 */ 190 */
191 static inline int get_ur_golomb(GetBitContext *gb, int k, int limit, int esc_len){ 191 static inline int get_ur_golomb(GetBitContext *gb, int k, int limit, int esc_len){
192 unsigned int buf; 192 unsigned int buf;
193 int log; 193 int log;
194 194
195 OPEN_READER(re, gb); 195 OPEN_READER(re, gb);
196 UPDATE_CACHE(re, gb); 196 UPDATE_CACHE(re, gb);
197 buf=GET_CACHE(re, gb); 197 buf=GET_CACHE(re, gb);
198 198
199 log= av_log2(buf); 199 log= av_log2(buf);
201 if(log > 31-limit){ 201 if(log > 31-limit){
202 buf >>= log - k; 202 buf >>= log - k;
203 buf += (30-log)<<k; 203 buf += (30-log)<<k;
204 LAST_SKIP_BITS(re, gb, 32 + k - log); 204 LAST_SKIP_BITS(re, gb, 32 + k - log);
205 CLOSE_READER(re, gb); 205 CLOSE_READER(re, gb);
206 206
207 return buf; 207 return buf;
208 }else{ 208 }else{
209 buf >>= 32 - limit - esc_len; 209 buf >>= 32 - limit - esc_len;
210 LAST_SKIP_BITS(re, gb, esc_len + limit); 210 LAST_SKIP_BITS(re, gb, esc_len + limit);
211 CLOSE_READER(re, gb); 211 CLOSE_READER(re, gb);
212 212
213 return buf + limit - 1; 213 return buf + limit - 1;
214 } 214 }
215 } 215 }
216 216
217 /** 217 /**
218 * read unsigned golomb rice code (jpegls). 218 * read unsigned golomb rice code (jpegls).
219 */ 219 */
220 static inline int get_ur_golomb_jpegls(GetBitContext *gb, int k, int limit, int esc_len){ 220 static inline int get_ur_golomb_jpegls(GetBitContext *gb, int k, int limit, int esc_len){
221 unsigned int buf; 221 unsigned int buf;
222 int log; 222 int log;
223 223
224 OPEN_READER(re, gb); 224 OPEN_READER(re, gb);
225 UPDATE_CACHE(re, gb); 225 UPDATE_CACHE(re, gb);
226 buf=GET_CACHE(re, gb); 226 buf=GET_CACHE(re, gb);
227 227
228 log= av_log2(buf); 228 log= av_log2(buf);
229 229
230 if(log > 31-11){ 230 if(log > 31-11){
231 buf >>= log - k; 231 buf >>= log - k;
232 buf += (30-log)<<k; 232 buf += (30-log)<<k;
233 LAST_SKIP_BITS(re, gb, 32 + k - log); 233 LAST_SKIP_BITS(re, gb, 32 + k - log);
234 CLOSE_READER(re, gb); 234 CLOSE_READER(re, gb);
235 235
236 return buf; 236 return buf;
237 }else{ 237 }else{
238 int i; 238 int i;
239 for(i=0; SHOW_UBITS(re, gb, 1) == 0; i++){ 239 for(i=0; SHOW_UBITS(re, gb, 1) == 0; i++){
240 LAST_SKIP_BITS(re, gb, 1); 240 LAST_SKIP_BITS(re, gb, 1);
254 return buf + (i<<k); 254 return buf + (i<<k);
255 }else if(i == limit - 1){ 255 }else if(i == limit - 1){
256 buf = SHOW_UBITS(re, gb, esc_len); 256 buf = SHOW_UBITS(re, gb, esc_len);
257 LAST_SKIP_BITS(re, gb, esc_len); 257 LAST_SKIP_BITS(re, gb, esc_len);
258 CLOSE_READER(re, gb); 258 CLOSE_READER(re, gb);
259 259
260 return buf + 1; 260 return buf + 1;
261 }else 261 }else
262 return -1; 262 return -1;
263 } 263 }
264 } 264 }
266 /** 266 /**
267 * read signed golomb rice code (ffv1). 267 * read signed golomb rice code (ffv1).
268 */ 268 */
269 static inline int get_sr_golomb(GetBitContext *gb, int k, int limit, int esc_len){ 269 static inline int get_sr_golomb(GetBitContext *gb, int k, int limit, int esc_len){
270 int v= get_ur_golomb(gb, k, limit, esc_len); 270 int v= get_ur_golomb(gb, k, limit, esc_len);
271 271
272 v++; 272 v++;
273 if (v&1) return v>>1; 273 if (v&1) return v>>1;
274 else return -(v>>1); 274 else return -(v>>1);
275 275
276 // return (v>>1) ^ -(v&1); 276 // return (v>>1) ^ -(v&1);
277 } 277 }
278 278
279 /** 279 /**
280 * read signed golomb rice code (flac). 280 * read signed golomb rice code (flac).
311 int show= show_bits(s, 24); 311 int show= show_bits(s, 24);
312 int pos= get_bits_count(s); 312 int pos= get_bits_count(s);
313 int i= get_ue_golomb(s); 313 int i= get_ue_golomb(s);
314 int len= get_bits_count(s) - pos; 314 int len= get_bits_count(s) - pos;
315 int bits= show>>(24-len); 315 int bits= show>>(24-len);
316 316
317 print_bin(bits, len); 317 print_bin(bits, len);
318 318
319 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d ue @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line); 319 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d ue @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line);
320 320
321 return i; 321 return i;
322 } 322 }
323 323
324 static inline int get_se(GetBitContext *s, char *file, const char *func, int line){ 324 static inline int get_se(GetBitContext *s, char *file, const char *func, int line){
325 int show= show_bits(s, 24); 325 int show= show_bits(s, 24);
326 int pos= get_bits_count(s); 326 int pos= get_bits_count(s);
327 int i= get_se_golomb(s); 327 int i= get_se_golomb(s);
328 int len= get_bits_count(s) - pos; 328 int len= get_bits_count(s) - pos;
329 int bits= show>>(24-len); 329 int bits= show>>(24-len);
330 330
331 print_bin(bits, len); 331 print_bin(bits, len);
332 332
333 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d se @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line); 333 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d se @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line);
334 334
335 return i; 335 return i;
336 } 336 }
337 337
338 static inline int get_te(GetBitContext *s, int r, char *file, const char *func, int line){ 338 static inline int get_te(GetBitContext *s, int r, char *file, const char *func, int line){
339 int show= show_bits(s, 24); 339 int show= show_bits(s, 24);
340 int pos= get_bits_count(s); 340 int pos= get_bits_count(s);
341 int i= get_te0_golomb(s, r); 341 int i= get_te0_golomb(s, r);
342 int len= get_bits_count(s) - pos; 342 int len= get_bits_count(s) - pos;
343 int bits= show>>(24-len); 343 int bits= show>>(24-len);
344 344
345 print_bin(bits, len); 345 print_bin(bits, len);
346 346
347 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d te @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line); 347 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d te @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line);
348 348
349 return i; 349 return i;
350 } 350 }
351 351
352 #define get_ue_golomb(a) get_ue(a, __FILE__, __PRETTY_FUNCTION__, __LINE__) 352 #define get_ue_golomb(a) get_ue(a, __FILE__, __PRETTY_FUNCTION__, __LINE__)
353 #define get_se_golomb(a) get_se(a, __FILE__, __PRETTY_FUNCTION__, __LINE__) 353 #define get_se_golomb(a) get_se(a, __FILE__, __PRETTY_FUNCTION__, __LINE__)
359 /** 359 /**
360 * write unsigned exp golomb code. 360 * write unsigned exp golomb code.
361 */ 361 */
362 static inline void set_ue_golomb(PutBitContext *pb, int i){ 362 static inline void set_ue_golomb(PutBitContext *pb, int i){
363 int e; 363 int e;
364 364
365 assert(i>=0); 365 assert(i>=0);
366 366
367 #if 0 367 #if 0
368 if(i=0){ 368 if(i=0){
369 put_bits(pb, 1, 1); 369 put_bits(pb, 1, 1);
372 #endif 372 #endif
373 if(i<256) 373 if(i<256)
374 put_bits(pb, ff_ue_golomb_len[i], i+1); 374 put_bits(pb, ff_ue_golomb_len[i], i+1);
375 else{ 375 else{
376 e= av_log2(i+1); 376 e= av_log2(i+1);
377 377
378 put_bits(pb, 2*e+1, i+1); 378 put_bits(pb, 2*e+1, i+1);
379 } 379 }
380 } 380 }
381 381
382 /** 382 /**
394 * write signed exp golomb code. 16 bits at most. 394 * write signed exp golomb code. 16 bits at most.
395 */ 395 */
396 static inline void set_se_golomb(PutBitContext *pb, int i){ 396 static inline void set_se_golomb(PutBitContext *pb, int i){
397 // if (i>32767 || i<-32767) 397 // if (i>32767 || i<-32767)
398 // av_log(NULL,AV_LOG_ERROR,"value out of range %d\n", i); 398 // av_log(NULL,AV_LOG_ERROR,"value out of range %d\n", i);
399 #if 0 399 #if 0
400 if(i<=0) i= -2*i; 400 if(i<=0) i= -2*i;
401 else i= 2*i-1; 401 else i= 2*i-1;
402 #elif 1 402 #elif 1
403 i= 2*i-1; 403 i= 2*i-1;
404 if(i<0) i^= -1; //FIXME check if gcc does the right thing 404 if(i<0) i^= -1; //FIXME check if gcc does the right thing
412 /** 412 /**
413 * write unsigned golomb rice code (ffv1). 413 * write unsigned golomb rice code (ffv1).
414 */ 414 */
415 static inline void set_ur_golomb(PutBitContext *pb, int i, int k, int limit, int esc_len){ 415 static inline void set_ur_golomb(PutBitContext *pb, int i, int k, int limit, int esc_len){
416 int e; 416 int e;
417 417
418 assert(i>=0); 418 assert(i>=0);
419 419
420 e= i>>k; 420 e= i>>k;
421 if(e<limit){ 421 if(e<limit){
422 put_bits(pb, e + k + 1, (1<<k) + (i&((1<<k)-1))); 422 put_bits(pb, e + k + 1, (1<<k) + (i&((1<<k)-1)));
423 }else{ 423 }else{
424 put_bits(pb, limit + esc_len, i - limit + 1); 424 put_bits(pb, limit + esc_len, i - limit + 1);
428 /** 428 /**
429 * write unsigned golomb rice code (jpegls). 429 * write unsigned golomb rice code (jpegls).
430 */ 430 */
431 static inline void set_ur_golomb_jpegls(PutBitContext *pb, int i, int k, int limit, int esc_len){ 431 static inline void set_ur_golomb_jpegls(PutBitContext *pb, int i, int k, int limit, int esc_len){
432 int e; 432 int e;
433 433
434 assert(i>=0); 434 assert(i>=0);
435 435
436 e= (i>>k) + 1; 436 e= (i>>k) + 1;
437 if(e<limit){ 437 if(e<limit){
438 put_bits(pb, e, 1); 438 put_bits(pb, e, 1);
439 if(k) 439 if(k)
440 put_bits(pb, k, i&((1<<k)-1)); 440 put_bits(pb, k, i&((1<<k)-1));