Mercurial > libavcodec.hg
comparison mjpeg.c @ 840:4c22dcf3ba65 libavcodec
cleanup
author | michaelni |
---|---|
date | Wed, 06 Nov 2002 09:30:47 +0000 |
parents | ff66fdb1d092 |
children | 4033915880d9 |
comparison
equal
deleted
inserted
replaced
839:b7e2b8129211 | 840:4c22dcf3ba65 |
---|---|
468 put_bits(&s->pb, 8, 0); /* Ss (not used) */ | 468 put_bits(&s->pb, 8, 0); /* Ss (not used) */ |
469 put_bits(&s->pb, 8, 63); /* Se (not used) */ | 469 put_bits(&s->pb, 8, 63); /* Se (not used) */ |
470 put_bits(&s->pb, 8, 0); /* Ah/Al (not used) */ | 470 put_bits(&s->pb, 8, 0); /* Ah/Al (not used) */ |
471 } | 471 } |
472 | 472 |
473 static void escape_FF(MpegEncContext *s) | |
474 { | |
475 int size= get_bit_count(&s->pb) - s->header_bits; | |
476 int i, ff_count; | |
477 uint8_t *buf= s->pb.buf + (s->header_bits>>3); | |
478 int align= (-(int)(buf))&3; | |
479 | |
480 assert((size&7) == 0); | |
481 size >>= 3; | |
482 | |
483 ff_count=0; | |
484 for(i=0; i<size && i<align; i++){ | |
485 if(buf[i]==0xFF) ff_count++; | |
486 } | |
487 for(; i<size-15; i+=16){ | |
488 int acc, v; | |
489 | |
490 v= *(uint32_t*)(&buf[i]); | |
491 acc= (((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010; | |
492 v= *(uint32_t*)(&buf[i+4]); | |
493 acc+=(((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010; | |
494 v= *(uint32_t*)(&buf[i+8]); | |
495 acc+=(((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010; | |
496 v= *(uint32_t*)(&buf[i+12]); | |
497 acc+=(((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010; | |
498 | |
499 acc>>=4; | |
500 acc+= (acc>>16); | |
501 acc+= (acc>>8); | |
502 ff_count+= acc&0xFF; | |
503 } | |
504 for(; i<size; i++){ | |
505 if(buf[i]==0xFF) ff_count++; | |
506 } | |
507 | |
508 if(ff_count==0) return; | |
509 | |
510 /* skip put bits */ | |
511 for(i=0; i<ff_count-3; i+=4) | |
512 put_bits(&s->pb, 32, 0); | |
513 put_bits(&s->pb, (ff_count-i)*8, 0); | |
514 flush_put_bits(&s->pb); | |
515 | |
516 for(i=size-1; ff_count; i--){ | |
517 int v= buf[i]; | |
518 | |
519 if(v==0xFF){ | |
520 //printf("%d %d\n", i, ff_count); | |
521 buf[i+ff_count]= 0; | |
522 ff_count--; | |
523 } | |
524 | |
525 buf[i+ff_count]= v; | |
526 } | |
527 } | |
528 | |
473 void mjpeg_picture_trailer(MpegEncContext *s) | 529 void mjpeg_picture_trailer(MpegEncContext *s) |
474 { | 530 { |
475 jflush_put_bits(&s->pb); | 531 int pad= (-get_bit_count(&s->pb))&7; |
532 | |
533 put_bits(&s->pb, pad,0xFF>>(8-pad)); | |
534 flush_put_bits(&s->pb); | |
535 | |
536 escape_FF(s); | |
537 | |
476 put_marker(&s->pb, EOI); | 538 put_marker(&s->pb, EOI); |
477 } | 539 } |
478 | 540 |
479 static inline void mjpeg_encode_dc(MpegEncContext *s, int val, | 541 static inline void mjpeg_encode_dc(MpegEncContext *s, int val, |
480 UINT8 *huff_size, UINT16 *huff_code) | 542 UINT8 *huff_size, UINT16 *huff_code) |
481 { | 543 { |
482 int mant, nbits; | 544 int mant, nbits; |
483 | 545 |
484 if (val == 0) { | 546 if (val == 0) { |
485 jput_bits(&s->pb, huff_size[0], huff_code[0]); | 547 put_bits(&s->pb, huff_size[0], huff_code[0]); |
486 } else { | 548 } else { |
487 mant = val; | 549 mant = val; |
488 if (val < 0) { | 550 if (val < 0) { |
489 val = -val; | 551 val = -val; |
490 mant--; | 552 mant--; |
495 while (val != 0) { | 557 while (val != 0) { |
496 val = val >> 1; | 558 val = val >> 1; |
497 nbits++; | 559 nbits++; |
498 } | 560 } |
499 | 561 |
500 jput_bits(&s->pb, huff_size[nbits], huff_code[nbits]); | 562 put_bits(&s->pb, huff_size[nbits], huff_code[nbits]); |
501 | 563 |
502 jput_bits(&s->pb, nbits, mant & ((1 << nbits) - 1)); | 564 put_bits(&s->pb, nbits, mant & ((1 << nbits) - 1)); |
503 } | 565 } |
504 } | 566 } |
505 | 567 |
506 static void encode_block(MpegEncContext *s, DCTELEM *block, int n) | 568 static void encode_block(MpegEncContext *s, DCTELEM *block, int n) |
507 { | 569 { |
535 val = block[j]; | 597 val = block[j]; |
536 if (val == 0) { | 598 if (val == 0) { |
537 run++; | 599 run++; |
538 } else { | 600 } else { |
539 while (run >= 16) { | 601 while (run >= 16) { |
540 jput_bits(&s->pb, huff_size_ac[0xf0], huff_code_ac[0xf0]); | 602 put_bits(&s->pb, huff_size_ac[0xf0], huff_code_ac[0xf0]); |
541 run -= 16; | 603 run -= 16; |
542 } | 604 } |
543 mant = val; | 605 mant = val; |
544 if (val < 0) { | 606 if (val < 0) { |
545 val = -val; | 607 val = -val; |
552 val = val >> 1; | 614 val = val >> 1; |
553 nbits++; | 615 nbits++; |
554 } | 616 } |
555 code = (run << 4) | nbits; | 617 code = (run << 4) | nbits; |
556 | 618 |
557 jput_bits(&s->pb, huff_size_ac[code], huff_code_ac[code]); | 619 put_bits(&s->pb, huff_size_ac[code], huff_code_ac[code]); |
558 | 620 |
559 jput_bits(&s->pb, nbits, mant & ((1 << nbits) - 1)); | 621 put_bits(&s->pb, nbits, mant & ((1 << nbits) - 1)); |
560 run = 0; | 622 run = 0; |
561 } | 623 } |
562 } | 624 } |
563 | 625 |
564 /* output EOB only if not already 64 values */ | 626 /* output EOB only if not already 64 values */ |
565 if (last_index < 63 || run != 0) | 627 if (last_index < 63 || run != 0) |
566 jput_bits(&s->pb, huff_size_ac[0], huff_code_ac[0]); | 628 put_bits(&s->pb, huff_size_ac[0], huff_code_ac[0]); |
567 } | 629 } |
568 | 630 |
569 void mjpeg_encode_mb(MpegEncContext *s, | 631 void mjpeg_encode_mb(MpegEncContext *s, |
570 DCTELEM block[6][64]) | 632 DCTELEM block[6][64]) |
571 { | 633 { |
1314 break; | 1376 break; |
1315 #endif | 1377 #endif |
1316 *(dst++) = x; | 1378 *(dst++) = x; |
1317 if (x == 0xff) | 1379 if (x == 0xff) |
1318 { | 1380 { |
1381 while(*src == 0xff) src++; | |
1382 | |
1319 x = *(src++); | 1383 x = *(src++); |
1320 if (x >= 0xd0 && x <= 0xd7) | 1384 if (x >= 0xd0 && x <= 0xd7) |
1321 *(dst++) = x; | 1385 *(dst++) = x; |
1322 else if (x) | 1386 else if (x) |
1323 break; | 1387 break; |