comparison interplayvideo.c @ 9273:42c63846b321 libavcodec

Replace many tiny loops in the interplayvideo decoder by memset, memcpy or initializers.
author reimar
date Sun, 29 Mar 2009 17:23:40 +0000
parents bb2fa003a336
children b0dcca654e18
comparison
equal deleted inserted replaced
9272:bb2fa003a336 9273:42c63846b321
481 unsigned char pix; 481 unsigned char pix;
482 482
483 /* 4-color encoding */ 483 /* 4-color encoding */
484 CHECK_STREAM_PTR(4); 484 CHECK_STREAM_PTR(4);
485 485
486 for (y = 0; y < 4; y++) 486 memcpy(P, s->stream_ptr, 4);
487 P[y] = *s->stream_ptr++; 487 s->stream_ptr += 4;
488 488
489 if ((P[0] <= P[1]) && (P[2] <= P[3])) { 489 if ((P[0] <= P[1]) && (P[2] <= P[3])) {
490 490
491 /* 1 of 4 colors for each pixel, need 16 more bytes */ 491 /* 1 of 4 colors for each pixel, need 16 more bytes */
492 CHECK_STREAM_PTR(16); 492 CHECK_STREAM_PTR(16);
575 575
576 /* 4-color encoding for each 4x4 quadrant, or 4-color encoding on 576 /* 4-color encoding for each 4x4 quadrant, or 4-color encoding on
577 * either top and bottom or left and right halves */ 577 * either top and bottom or left and right halves */
578 CHECK_STREAM_PTR(4); 578 CHECK_STREAM_PTR(4);
579 579
580 for (y = 0; y < 4; y++) 580 memcpy(P, s->stream_ptr, 4);
581 P[y] = *s->stream_ptr++; 581 s->stream_ptr += 4;
582 582
583 if (P[0] <= P[1]) { 583 if (P[0] <= P[1]) {
584 584
585 /* 4-color encoding for each quadrant; need 28 more bytes */ 585 /* 4-color encoding for each quadrant; need 28 more bytes */
586 CHECK_STREAM_PTR(28); 586 CHECK_STREAM_PTR(28);
587 587
588 for (y = 0; y < 4; y++) 588 memcpy(B, s->stream_ptr, 4);
589 B[y] = *s->stream_ptr++; 589 s->stream_ptr += 4;
590 for (y = 4; y < 16; y += 4) { 590 for (y = 4; y < 16; y += 4) {
591 for (x = y; x < y + 4; x++) 591 memcpy(P + y, s->stream_ptr, 4);
592 P[x] = *s->stream_ptr++; 592 s->stream_ptr += 4;
593 for (x = y; x < y + 4; x++) 593 memcpy(B + y, s->stream_ptr, 4);
594 B[x] = *s->stream_ptr++; 594 s->stream_ptr += 4;
595 } 595 }
596 596
597 for (y = 0; y < 8; y++) { 597 for (y = 0; y < 8; y++) {
598 598
599 lower_half = (y >= 4) ? 4 : 0; 599 lower_half = (y >= 4) ? 4 : 0;
612 612
613 /* 4-color encoding for either left and right or top and bottom 613 /* 4-color encoding for either left and right or top and bottom
614 * halves; need 20 more bytes */ 614 * halves; need 20 more bytes */
615 CHECK_STREAM_PTR(20); 615 CHECK_STREAM_PTR(20);
616 616
617 for (y = 0; y < 8; y++) 617 memcpy(B, s->stream_ptr, 8);
618 B[y] = *s->stream_ptr++; 618 s->stream_ptr += 8;
619 for (y = 4; y < 8; y++) 619 memcpy(P + 4, s->stream_ptr, 4);
620 P[y] = *s->stream_ptr++; 620 s->stream_ptr += 4;
621 for (y = 8; y < 16; y++) 621 memcpy(B + 8, s->stream_ptr, 8);
622 B[y] = *s->stream_ptr++; 622 s->stream_ptr += 8;
623 623
624 if (P[4] <= P[5]) { 624 if (P[4] <= P[5]) {
625 625
626 /* block is divided into left and right halves */ 626 /* block is divided into left and right halves */
627 for (y = 0; y < 8; y++) { 627 for (y = 0; y < 8; y++) {
660 return 0; 660 return 0;
661 } 661 }
662 662
663 static int ipvideo_decode_block_opcode_0xB(IpvideoContext *s) 663 static int ipvideo_decode_block_opcode_0xB(IpvideoContext *s)
664 { 664 {
665 int x, y; 665 int y;
666 666
667 /* 64-color encoding (each pixel in block is a different color) */ 667 /* 64-color encoding (each pixel in block is a different color) */
668 CHECK_STREAM_PTR(64); 668 CHECK_STREAM_PTR(64);
669 669
670 for (y = 0; y < 8; y++) { 670 for (y = 0; y < 8; y++) {
671 for (x = 0; x < 8; x++) { 671 memcpy(s->pixel_ptr, s->stream_ptr, 8);
672 *s->pixel_ptr++ = *s->stream_ptr++; 672 s->stream_ptr += 8;
673 } 673 s->pixel_ptr += s->stride;
674 s->pixel_ptr += s->line_inc;
675 } 674 }
676 675
677 /* report success */ 676 /* report success */
678 return 0; 677 return 0;
679 } 678 }
701 return 0; 700 return 0;
702 } 701 }
703 702
704 static int ipvideo_decode_block_opcode_0xD(IpvideoContext *s) 703 static int ipvideo_decode_block_opcode_0xD(IpvideoContext *s)
705 { 704 {
706 int x, y; 705 int y;
707 unsigned char P[4]; 706 unsigned char P[4];
708 unsigned char index = 0; 707 unsigned char index = 0;
709 708
710 /* 4-color block encoding: each 4x4 block is a different color */ 709 /* 4-color block encoding: each 4x4 block is a different color */
711 CHECK_STREAM_PTR(4); 710 CHECK_STREAM_PTR(4);
712 711
713 for (y = 0; y < 4; y++) 712 memcpy(P, s->stream_ptr, 4);
714 P[y] = *s->stream_ptr++; 713 s->stream_ptr += 4;
715 714
716 for (y = 0; y < 8; y++) { 715 for (y = 0; y < 8; y++) {
717 if (y < 4) 716 if (y < 4)
718 index = 0; 717 index = 0;
719 else 718 else
720 index = 2; 719 index = 2;
721 720
722 for (x = 0; x < 8; x++) { 721 memset(s->pixel_ptr , P[index ], 4);
723 if (x == 4) 722 memset(s->pixel_ptr + 4, P[index + 1], 4);
724 index++; 723 s->pixel_ptr += s->stride;
725 *s->pixel_ptr++ = P[index];
726 }
727 s->pixel_ptr += s->line_inc;
728 } 724 }
729 725
730 /* report success */ 726 /* report success */
731 return 0; 727 return 0;
732 } 728 }
733 729
734 static int ipvideo_decode_block_opcode_0xE(IpvideoContext *s) 730 static int ipvideo_decode_block_opcode_0xE(IpvideoContext *s)
735 { 731 {
736 int x, y; 732 int y;
737 unsigned char pix; 733 unsigned char pix;
738 734
739 /* 1-color encoding: the whole block is 1 solid color */ 735 /* 1-color encoding: the whole block is 1 solid color */
740 CHECK_STREAM_PTR(1); 736 CHECK_STREAM_PTR(1);
741 pix = *s->stream_ptr++; 737 pix = *s->stream_ptr++;
742 738
743 for (y = 0; y < 8; y++) { 739 for (y = 0; y < 8; y++) {
744 for (x = 0; x < 8; x++) { 740 memset(s->pixel_ptr, pix, 8);
745 *s->pixel_ptr++ = pix; 741 s->pixel_ptr += s->stride;
746 }
747 s->pixel_ptr += s->line_inc;
748 } 742 }
749 743
750 /* report success */ 744 /* report success */
751 return 0; 745 return 0;
752 } 746 }
793 { 787 {
794 int x, y; 788 int x, y;
795 int index = 0; 789 int index = 0;
796 unsigned char opcode; 790 unsigned char opcode;
797 int ret; 791 int ret;
798 int code_counts[16]; 792 int code_counts[16] = {0};
799 static int frame = 0; 793 static int frame = 0;
800 794
801 debug_interplay("------------------ frame %d\n", frame); 795 debug_interplay("------------------ frame %d\n", frame);
802 frame++; 796 frame++;
803
804 for (x = 0; x < 16; x++)
805 code_counts[x] = 0;
806 797
807 /* this is PAL8, so make the palette available */ 798 /* this is PAL8, so make the palette available */
808 memcpy(s->current_frame.data[1], s->avctx->palctrl->palette, PALETTE_COUNT * 4); 799 memcpy(s->current_frame.data[1], s->avctx->palctrl->palette, PALETTE_COUNT * 4);
809 800
810 s->stride = s->current_frame.linesize[0]; 801 s->stride = s->current_frame.linesize[0];