comparison vc9.c @ 2459:7a875ef7597b libavcodec

fixing many bugs in bitplane_decoding() spliting row/colskip cases into their own functions as these will be needed for NORM/DIFF-6
author michael
date Mon, 24 Jan 2005 00:35:18 +0000
parents 915094e3da5d
children 42077bb89a53
comparison
equal deleted inserted replaced
2458:915094e3da5d 2459:7a875ef7597b
697 #define IMODE_NORM6 3 697 #define IMODE_NORM6 3
698 #define IMODE_DIFF6 4 698 #define IMODE_DIFF6 4
699 #define IMODE_ROWSKIP 5 699 #define IMODE_ROWSKIP 5
700 #define IMODE_COLSKIP 6 700 #define IMODE_COLSKIP 6
701 701
702 static void decode_rowskip(uint8_t* plane, int width, int height, int stride, VC9Context *v){
703 int x, y;
704
705 for (y=0; y<height; y++){
706 if (!get_bits(&v->gb, 1)) //rowskip
707 memset(plane, 0, width);
708 else
709 for (x=0; x<width; x++)
710 plane[x] = get_bits(&v->gb, 1);
711 plane += stride;
712 }
713 }
714
715 static void decode_colskip(uint8_t* plane, int width, int height, int stride, VC9Context *v){
716 int x, y;
717
718 for (x=0; x<width; x++){
719 if (!get_bits(&v->gb, 1)) //colskip
720 for (y=0; y<height; y++)
721 plane[y*stride] = 0;
722 else
723 for (y=0; y<height; y++)
724 plane[y*stride] = get_bits(&v->gb, 1);
725 plane ++;
726 }
727 }
728
702 //FIXME optimize 729 //FIXME optimize
730 //FIXME is this supposed to set elements to 0/FF or 0/1?
703 static int bitplane_decoding(uint8_t* plane, int width, int height, VC9Context *v) 731 static int bitplane_decoding(uint8_t* plane, int width, int height, VC9Context *v)
704 { 732 {
705 int imode, x, y, code; 733 int imode, x, y, i, code, use_vertical_tile;
706 uint8_t invert, *planep = plane; 734 uint8_t invert, *planep = plane;
735 int stride= width;
707 736
708 invert = get_bits(&v->gb, 1); 737 invert = get_bits(&v->gb, 1);
709 imode = get_vlc2(&v->gb, vc9_imode_vlc.table, VC9_IMODE_VLC_BITS, 2); 738 imode = get_vlc2(&v->gb, vc9_imode_vlc.table, VC9_IMODE_VLC_BITS, 2);
710 av_log(v->avctx, AV_LOG_DEBUG, "Bitplane: imode=%i, invert=%i\n", 739 av_log(v->avctx, AV_LOG_DEBUG, "Bitplane: imode=%i, invert=%i\n",
711 imode, invert); 740 imode, invert);
715 case IMODE_RAW: 744 case IMODE_RAW:
716 for (y=0; y<height; y++) 745 for (y=0; y<height; y++)
717 { 746 {
718 for (x=0; x<width; x++) 747 for (x=0; x<width; x++)
719 planep[x] = (-get_bits(&v->gb, 1)); //-1=0xFF 748 planep[x] = (-get_bits(&v->gb, 1)); //-1=0xFF
720 planep += width; 749 planep += stride;
721 } 750 }
751 invert=0; //spec says ignore invert if raw
722 break; 752 break;
723 case IMODE_DIFF2: 753 case IMODE_DIFF2:
724 case IMODE_NORM2: 754 case IMODE_NORM2:
725 if ((height*width) & 1) *(++planep) = get_bits(&v->gb, 1); 755 if ((height*width) & 1) *(++planep) = get_bits(&v->gb, 1);
726 code = get_vlc2(&v->gb, vc9_norm2_vlc.table, VC9_NORM2_VLC_BITS, 2); 756 for(i=0; i<(height*width)>>1; i++){
727 *(++planep) = code&1; //lsb => left 757 code = get_vlc2(&v->gb, vc9_norm2_vlc.table, VC9_NORM2_VLC_BITS, 2);
728 *(++planep) = code&2; //msb => right - this is a bitplane, so only !0 matters 758 *(++planep) = code&1; //lsb => left
759 *(++planep) = code&2; //msb => right - this is a bitplane, so only !0 matters
760 //FIXME width->stride
761 }
729 break; 762 break;
730 case IMODE_DIFF6: 763 case IMODE_DIFF6:
731 case IMODE_NORM6: 764 case IMODE_NORM6:
765 use_vertical_tile= height%3==0 && width%3!=0;
766 if(use_vertical_tile){
767 }else{
768 }
769
732 av_log(v->avctx, AV_LOG_ERROR, "Imode using Norm-6 isn't supported\n"); 770 av_log(v->avctx, AV_LOG_ERROR, "Imode using Norm-6 isn't supported\n");
733 return -1; 771 return -1;
734 break; 772 break;
735 case IMODE_ROWSKIP: 773 case IMODE_ROWSKIP:
736 for (y=0; y<height; y++) 774 decode_rowskip(plane, width, height, stride, v);
737 {
738 if (get_bits(&v->gb, 1)) //rowskip
739 memset(planep, 0, width);
740 else for (x=0; x<width; x++) planep[x] = get_bits(&v->gb, 1);
741 planep += width;
742 }
743 break; 775 break;
744 case IMODE_COLSKIP: //Teh ugly 776 case IMODE_COLSKIP: //Teh ugly
745 for (x=0; x<width; x++) 777 decode_rowskip(plane, width, height, stride, v);
746 {
747 planep = plane;
748 if (get_bits(&v->gb, 1)) //colskip
749 {
750 for (y=0; y<height; y++)
751 {
752 planep[x] = 0;
753 planep += width;
754 }
755 }
756 else
757 {
758 for (y=0; y<height; y++)
759 {
760 planep[x] = get_bits(&v->gb, 1);
761 planep += width;
762 }
763 }
764 }
765 break; 778 break;
766 default: break; 779 default: break;
767 } 780 }
768 781
769 /* Applying diff operator */ 782 /* Applying diff operator */
770 if (imode == IMODE_DIFF2 || imode == IMODE_DIFF2) 783 if (imode == IMODE_DIFF2 || imode == IMODE_DIFF6)
771 { 784 {
772 /* And what about j=0 !? */ 785 planep = plane;
773 planep = plane + width; 786 planep[0] ^= invert;
774 memset(plane, invert, width); 787 for (x=1; x<width; x++)
775 for (y=0; y<height; y++) 788 planep[x] ^= planep[x-1];
776 { 789 for (y=1; y<height; y++)
777 planep[0] = planep[-width]; 790 {
791 planep += stride;
792 planep[0] ^= planep[-stride];
778 for (x=1; x<width; x++) 793 for (x=1; x<width; x++)
779 { 794 {
780 if (planep[x-1] != planep[-width]) planep[x] = invert; 795 if (planep[x-1] != planep[x-stride]) planep[x] ^= invert;
781 else planep[x] = planep[x-1]; 796 else planep[x] ^= planep[x-1];
782 } 797 }
783 planep += width;
784 } 798 }
785 } 799 }
786 else if (invert) 800 else if (invert)
787 { 801 {
788 planep = plane; 802 planep = plane;
789 for (x=0; x<width*height; x++) planep[x] = !planep[x]; 803 for (x=0; x<width*height; x++) planep[x] = !planep[x]; //FIXME stride
790 } 804 }
791 return 0; 805 return 0;
792 } 806 }
793 807
794 /*****************************************************************************/ 808 /*****************************************************************************/