comparison common.h @ 840:4c22dcf3ba65 libavcodec

cleanup
author michaelni
date Wed, 06 Nov 2002 09:30:47 +0000
parents 5344ecb2c677
children f3c369b8ddca
comparison
equal deleted inserted replaced
839:b7e2b8129211 840:4c22dcf3ba65
106 typedef signed char INT8; 106 typedef signed char INT8;
107 typedef signed int INT32; 107 typedef signed int INT32;
108 typedef signed long long INT64; 108 typedef signed long long INT64;
109 109
110 # ifdef HAVE_AV_CONFIG_H 110 # ifdef HAVE_AV_CONFIG_H
111
112 # ifndef INT64_C 111 # ifndef INT64_C
113 # define INT64_C(c) (c ## LL) 112 # define INT64_C(c) (c ## LL)
114 # define UINT64_C(c) (c ## ULL) 113 # define UINT64_C(c) (c ## ULL)
115 # endif 114 # endif
116 115
117 # ifdef USE_FASTMEMCPY 116 # ifdef USE_FASTMEMCPY
118 # include "fastmemcpy.h" 117 # include "fastmemcpy.h"
119 # endif 118 # endif
120
121 # endif /* HAVE_AV_CONFIG_H */ 119 # endif /* HAVE_AV_CONFIG_H */
122 120
123 #endif /* !CONFIG_WIN32 */ 121 #endif /* !CONFIG_WIN32 */
124 122
125 #ifdef HAVE_AV_CONFIG_H 123 #ifdef HAVE_AV_CONFIG_H
217 215
218 INT64 get_bit_count(PutBitContext *s); /* XXX: change function name */ 216 INT64 get_bit_count(PutBitContext *s); /* XXX: change function name */
219 void align_put_bits(PutBitContext *s); 217 void align_put_bits(PutBitContext *s);
220 void flush_put_bits(PutBitContext *s); 218 void flush_put_bits(PutBitContext *s);
221 void put_string(PutBitContext * pbc, char *s); 219 void put_string(PutBitContext * pbc, char *s);
222
223 /* jpeg specific put_bits */
224 void jflush_put_bits(PutBitContext *s);
225 220
226 /* bit input */ 221 /* bit input */
227 222
228 typedef struct GetBitContext { 223 typedef struct GetBitContext {
229 UINT8 *buffer, *buffer_end; 224 UINT8 *buffer, *buffer_end;
381 # endif 376 # endif
382 # endif //!ALIGNED_BITSTREAM_WRITER 377 # endif //!ALIGNED_BITSTREAM_WRITER
383 } 378 }
384 #endif 379 #endif
385 380
386 #ifndef ALT_BITSTREAM_WRITER
387 /* for jpeg : escape 0xff with 0x00 after it */
388 static inline void jput_bits(PutBitContext *s, int n, unsigned int value)
389 {
390 unsigned int bit_buf, b;
391 int bit_left, i;
392
393 assert(n == 32 || value < (1U << n));
394
395 bit_buf = s->bit_buf;
396 bit_left = s->bit_left;
397
398 //printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf);
399 /* XXX: optimize */
400 if (n < bit_left) {
401 bit_buf = (bit_buf<<n) | value;
402 bit_left-=n;
403 } else {
404 bit_buf<<=bit_left;
405 bit_buf |= value >> (n - bit_left);
406 /* handle escape */
407 for(i=0;i<4;i++) {
408 b = (bit_buf >> 24);
409 *(s->buf_ptr++) = b;
410 if (b == 0xff)
411 *(s->buf_ptr++) = 0;
412 bit_buf <<= 8;
413 }
414
415 bit_left+= 32 - n;
416 bit_buf = value;
417 }
418
419 s->bit_buf = bit_buf;
420 s->bit_left = bit_left;
421 }
422 #endif
423
424
425 #ifdef ALT_BITSTREAM_WRITER
426 static inline void jput_bits(PutBitContext *s, int n, int value)
427 {
428 int index= s->index;
429 uint32_t *ptr= (uint32_t*)(((uint8_t *)s->buf)+(index>>3));
430 int v= ptr[0];
431 //if(n>24) printf("%d %d\n", n, value);
432
433 v |= be2me_32(value<<(32-n-(index&7) ));
434 if(((v+0x01010101)^0xFFFFFFFF)&v&0x80808080)
435 {
436 /* handle idiotic (m)jpeg escapes */
437 uint8_t *bPtr= (uint8_t*)ptr;
438 int numChecked= ((index+n)>>3) - (index>>3);
439
440 v= be2me_32(v);
441
442 *(bPtr++)= v>>24;
443 if((v&0xFF000000)==0xFF000000 && numChecked>0){
444 *(bPtr++)= 0x00;
445 index+=8;
446 }
447 *(bPtr++)= (v>>16)&0xFF;
448 if((v&0x00FF0000)==0x00FF0000 && numChecked>1){
449 *(bPtr++)= 0x00;
450 index+=8;
451 }
452 *(bPtr++)= (v>>8)&0xFF;
453 if((v&0x0000FF00)==0x0000FF00 && numChecked>2){
454 *(bPtr++)= 0x00;
455 index+=8;
456 }
457 *(bPtr++)= v&0xFF;
458 if((v&0x000000FF)==0x000000FF && numChecked>3){
459 *(bPtr++)= 0x00;
460 index+=8;
461 }
462 *((uint32_t*)bPtr)= 0;
463 }
464 else
465 {
466 ptr[0] = v;
467 ptr[1] = 0;
468 }
469
470 index+= n;
471 s->index= index;
472 }
473 #endif
474 381
475 static inline uint8_t* pbBufPtr(PutBitContext *s) 382 static inline uint8_t* pbBufPtr(PutBitContext *s)
476 { 383 {
477 #ifdef ALT_BITSTREAM_WRITER 384 #ifdef ALT_BITSTREAM_WRITER
478 return s->buf + (s->index>>3); 385 return s->buf + (s->index>>3);