[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mono-patches
Subject:    [Mono-patches] r135099 - branches/cscodec/Video/cstheora
From:       "olivier dufour (olivier.duff () gmail ! com)"
Date:       2009-05-31 18:20:07
Message-ID: 20090531182007.002B39472C () mono-cvs ! ximian ! com
[Download RAW message or body]

Author: olivier
Date: 2009-05-31 14:20:07 -0400 (Sun, 31 May 2009)
New Revision: 135099

Modified:
   branches/cscodec/Video/cstheora/Frame.cs
   branches/cscodec/Video/cstheora/HuffmanCode.cs
   branches/cscodec/Video/cstheora/Info.cs
   branches/cscodec/Video/cstheora/QuantizationInfo.cs
Log:
dtc coeff


Modified: branches/cscodec/Video/cstheora/Frame.cs
===================================================================
--- branches/cscodec/Video/cstheora/Frame.cs	2009-05-31 13:56:11 UTC (rev 135098)
+++ branches/cscodec/Video/cstheora/Frame.cs	2009-05-31 18:20:07 UTC (rev 135099)
@@ -12,12 +12,14 @@
         public bool isIntra;
         //bool[] bcoded;
         Decoder dec;
-        uint referenceFrameLumWidth;
-        uint referenceFrameLumHeight;
-        uint referenceFrameChromWidth;
-        uint referenceFrameChromHeight;
-        SuperBlock[] superblocks;
-        MacroBlock[] macroBlocks;//todo init
+        int referenceFrameLumWidth;
+        int referenceFrameLumHeight;
+        int referenceFrameChromWidth;
+        int referenceFrameChromHeight;
+        List<SuperBlock> superblocks;
+        List<MacroBlock> macroBlocks;
+        List<Block> Blocks;
+        int[] ncoeffs;
 
         static Frame()
         {
@@ -90,6 +92,7 @@
         public Frame(Decoder dec)
         {
             this.dec = dec;
+            ncoeffs = new int[dec.info.FrameBlockCount];
             //bcoded = new bool[dec.info.FrameBlockCount];
         }
         internal void Parse(csBuffer buf, byte code)
@@ -112,7 +115,7 @@
                 qis.Add(63);
                 
                 //set all block to not coded!
-                for (uint sbi = 0; sbi < dec.info.FrameSuperBlockCount; sbi++)
+                for (int sbi = 0; sbi < dec.info.FrameSuperBlockCount; sbi++)
                 {
                     for (int quadi = 0; quadi < 4; quadi++)
                     {
@@ -179,7 +182,7 @@
             if (isIntra)
             {
                 //set all block to coded!
-                for (uint sbi = 0; sbi < dec.info.FrameSuperBlockCount; sbi++)
+                for (int sbi = 0; sbi < dec.info.FrameSuperBlockCount; sbi++)
                 {
                     for (int quadi = 0; quadi < 4; quadi++)
                     {
@@ -196,14 +199,13 @@
             {
                 //partial coded super block
                 csBuffer bits = buf.ReadBitString(dec.info.FrameSuperBlockCount, \
                false);
-                superblocks = new SuperBlock[dec.info.FrameSuperBlockCount];
-                csBuffer reader = new csBuffer();
+                superblocks = new List<SuperBlock> (dec.info.FrameSuperBlockCount);
                 int partialCount = 0;
-                reader.readinit(bits.buf(), 0, bits.bytes());
+                bits.readinit();
 
-                for (uint sbi = 0; sbi < dec.info.FrameSuperBlockCount; sbi++)
+                for (int sbi = 0; sbi < dec.info.FrameSuperBlockCount; sbi++)
                 {
-                    if (reader.read1() == 0)
+                    if (bits.read1() == 0)
                     {
                         superblocks[sbi].codedPartially = false;
                         partialCount++;
@@ -213,15 +215,14 @@
                 }
                 //full coded super block
                 bits = buf.ReadBitString(partialCount, false);//write mode
-                reader = new csBuffer();
                 int fullCount = 0;
-                reader.readinit(bits.buf(), 0, bits.bytes());
+                bits.readinit();
 
-                for (uint sbi = 0; sbi < dec.info.FrameSuperBlockCount; sbi++)
+                for (int sbi = 0; sbi < dec.info.FrameSuperBlockCount; sbi++)
                 {
                     if (!superblocks[sbi].codedPartially)
                     {
-                        if (reader.read1() == 1)
+                        if (bits.read1() == 1)
                         {
                             superblocks[sbi].codedFully = true;
                             fullCount++;
@@ -232,9 +233,8 @@
                 }
                 //todo warning because fullCount might not be equal to 16 times \
partialCount  bits = buf.ReadBitString(fullCount, true);//write mode
-                reader = new csBuffer();
-                reader.readinit(bits.buf(), 0, bits.bytes());
-                for (uint sbi = 0; sbi < dec.info.FrameSuperBlockCount; sbi++)
+                bits.readinit();
+                for (int sbi = 0; sbi < dec.info.FrameSuperBlockCount; sbi++)
                 {
                     for (int quadi = 0; quadi < 4; quadi++)
                     {
@@ -243,7 +243,7 @@
                             if (!superblocks[sbi].codedPartially)
                                 superblocks[sbi].fragments[quadi][bi].coded = \
superblocks[sbi].codedFully;  else
-                                superblocks[sbi].fragments[quadi][bi].coded = \
(reader.read1() == 1); +                                \
superblocks[sbi].fragments[quadi][bi].coded = (bits.read1() == 1);  }
                     }
                 }
@@ -263,7 +263,7 @@
         {
             if (isIntra)
             {
-                for (uint mbi = 0; mbi < dec.info.FrameMacroBlockCount; mbi++)
+                for (int mbi = 0; mbi < dec.info.FrameMacroBlockCount; mbi++)
                 {
                     macroBlocks[mbi].mode = 1;
                 }
@@ -437,16 +437,144 @@
 
         private void ParseBlockLevel(csBuffer buf)
         {
-            //7.6
-            throw new NotImplementedException();
+            foreach (MacroBlock mb in this.macroBlocks)
+            {
+                for (int i = 0; i < 3; i++)
+                foreach(Block bl in mb.fragments[i])
+                {
+                    bl.qii = 0;
+                }
+            }
+            for(int qii = 0; qii < qis.Count-1; qii++)
+            {
+                int nbits = 0;
+                foreach(Block bl in Blocks)
+                {
+                    if (bl.coded && bl.qii == qii)
+                    	nbits++;
+                }
+                csBuffer bits = buf.ReadBitString(nbits, false);
+                bits.readinit();
+                foreach(Block bl in Blocks)
+                {
+                    if (bl.coded && bl.qii == qii)
+                    {
+                        bl.qii += bits.read1();                        
+                    }
+                }
+            }
         }
 
-        private void ParseDCTCoefficients(csBuffer buf)
+        //TODO audit the code to change for loop image order to regular order and \
reverse +        //TODO init every list!
+        private void ParseDCTCoefficients(csBuffer buf)//7.7.3
         {
-            //7.7.3
-            throw new NotImplementedException();
+            int[] tis = new int[dec.info.FrameBlockCount];
+            for(uint bi = 0; bi < dec.info.FrameBlockCount; bi++)
+            {
+                tis[bi] = 0;
+            }
+            int eobs = 0;
+            int htil = 0;
+            int htic = 0;
+            for(int ti = 0; ti < 64; ti++)
+            {
+                if(ti == 0 || ti == 1)
+                {
+                    htil = buf.read(4);
+                    htic = buf.read(4);
+                }
+                for(int bi = 0; bi < dec.info.FrameBlockCount; bi++)
+            	{
+                    if (!Blocks[bi].coded || tis[bi] != ti)
+                        continue;
+                    Blocks[bi].coeffs = new short[64];
+                    if (eobs > 0)
+                    {
+                        for(int tj = ti; tj < 64; tj++)
+                            Blocks[bi].coeffs[tj] =0;
+                        tis[bi] = 64;
+                    		eobs--;
+                    }
+                    else
+                    {
+                        int hg = 0;
+                        if (ti == 0)
+                        	hg = 0;
+                        else if (ti <= 5)
+                            hg = 1;
+                        else if (ti <= 14)
+                            hg = 2;
+                        else if (ti <= 27)
+                            hg = 3;
+                        else if (ti <= 63)
+                            hg = 4;
+                        int hti;
+                        if (bi < macroBlocks.Count * 4)
+                            hti = 16 * hg + htil;
+                        else
+                            hti = 16 * hg + htic;
+                        
+                        
+                        int a = buf.read1();
+                        HuffmanCode code = dec.qinfo.HuffmanTables[hti];
+                        while (true)
+                        {
+                            int tkn = code.Find(a);
+                            if (tkn != -1)
+                            {
+                                if (tkn < 7)
+                                {
+                                    //7.7.1
+                                    switch(tkn) 
+						            {
+						                case 0:
+						                case 1:
+						                case 2:
+						                	eobs = tkn + 1;
+						            	break;
+										case 3:
+						                	eobs = buf.read(2) + 4;
+						            	break;
+						                case 4:
+						                	eobs = buf.read(3) + 8;
+						            	break;
+						                case 5:
+						                	eobs = buf.read(4) + 16;
+						            	break;
+						                case 6:
+						                	eobs = buf.read(12);
+						                if (eobs == 0)
+						                {
+						                	for(int bj = 0; bj < dec.info.FrameBlockCount; bj++)
+							            	{
+							                    if (Blocks[bj].coded && tis[bj] < 64)
+							                        eobs++;
+						                    }
+						                }
+						            	break;
+						            }
+						            for(int tj = ti; tj < 64; tj++)
+							        {
+						                Blocks[bi].coeffs[tj] = 0;
+						            }
+						            ncoeffs[bi] = tis[bi];
+						            tis[bi] = 64;
+						            eobs--;
+                                }
+                                else
+                                {
+                                    //7.7.2
+                                }
+                                return;
+                            }
+                            a = (a << 1) | buf.read1();
+                        } 
+                    }
+                }
+            }
         }
-
+        
         private void UndoDCPrediction(csBuffer buf)
         {
             //7.8.2

Modified: branches/cscodec/Video/cstheora/HuffmanCode.cs
===================================================================
--- branches/cscodec/Video/cstheora/HuffmanCode.cs	2009-05-31 13:56:11 UTC (rev \
                135098)
+++ branches/cscodec/Video/cstheora/HuffmanCode.cs	2009-05-31 18:20:07 UTC (rev \
135099) @@ -54,6 +54,19 @@
                 nodes.Add(c);
                 RemoveLast();
             }
+        }
+        public int Find(int a)//do i need level?
+        {
+            foreach(HuffmanCode c in nodes)
+            {
+                int tkn = c.Find(a);
+                if (tkn != -1)
+                    return tkn;
+            }
+            if (this.code == a)
+                return token;
+            else
+                return -1;
         }
     }
 }

Modified: branches/cscodec/Video/cstheora/Info.cs
===================================================================
--- branches/cscodec/Video/cstheora/Info.cs	2009-05-31 13:56:11 UTC (rev 135098)
+++ branches/cscodec/Video/cstheora/Info.cs	2009-05-31 18:20:07 UTC (rev 135099)
@@ -12,11 +12,11 @@
         public int VersionMajor;
         public int VersionMinor;
         public int VersionRevision;
-        public uint FrameMacroBlockWidth;
-        public uint FrameMacroBlockHeight;
-        public uint FrameSuperBlockCount;
-        public ulong FrameBlockCount;
-        public uint FrameMacroBlockCount;
+        public int FrameMacroBlockWidth;
+        public int FrameMacroBlockHeight;
+        public int FrameSuperBlockCount;
+        public int FrameBlockCount;
+        public int FrameMacroBlockCount;
         public int PictureRegionWidth;//in pixel
         public int PictureRegionHeight;//in pixel
         public int PictureXOffset;
@@ -114,7 +114,7 @@
                     break;
                 case 3:
                     FrameSuperBlockCount = 3 * ((FrameMacroBlockWidth+1)/2) \
                *((FrameMacroBlockHeight+1)/2);
-                    FrameBlockCount = 12uL * FrameMacroBlockWidth * \
FrameMacroBlockHeight; +                    FrameBlockCount = 12 * \
FrameMacroBlockWidth * FrameMacroBlockHeight;  break;
             }
             FrameMacroBlockCount = FrameMacroBlockWidth * FrameMacroBlockHeight;

Modified: branches/cscodec/Video/cstheora/QuantizationInfo.cs
===================================================================
--- branches/cscodec/Video/cstheora/QuantizationInfo.cs	2009-05-31 13:56:11 UTC (rev \
                135098)
+++ branches/cscodec/Video/cstheora/QuantizationInfo.cs	2009-05-31 18:20:07 UTC (rev \
135099) @@ -13,14 +13,26 @@
         public QuantizationInfo()
         {
         }
-        public List<int> loopFilterLimits;
-        public List<int> aScales;
-        public List<int> dScales;
+        public int[] loopFilterLimits;//64
+        public int[] aScales;//64
+        public int[] dScales;//64
         public byte[,] matrix;
         public byte[,] quantRangeNumber;
         public byte[,][] quantRangeSize;
         public int[,][] quantRangeBaseMatrixIndex;
-        public List<HuffmanCode> HuffmanTables;
+        public HuffmanCode[] HuffmanTables;
+        
+        public void Init()
+        {
+			loopFilterLimits = new int[64] ;
+	        aScales = new int[64] ;
+	        dScales = new int[64] ;
+            quantRangeNumber = new byte[2, 3];
+            quantRangeSize = new byte[2, 3] [];
+            quantRangeBaseMatrixIndex = new int[2, 3] [];
+            HuffmanCode[] HuffmanTables = new HuffmanCode[80] ;
+        }
+        
         public void ParseSetupHeader(csBuffer buf)
         {
             ParseLoopFilterLimit(buf);
@@ -31,27 +43,24 @@
         private void ParseLoopFilterLimit(csBuffer buf)
         {
             int size = buf.read(3);
-            loopFilterLimits = new List<int>(64);
             for (int i = 0; i < 64; i++)
             {
-                loopFilterLimits.Add(buf.read(size));
+                loopFilterLimits[i] = buf.read(size);
             }
         }
         
         private void ParseQuantizationParams(csBuffer buf)
         {
             int size = buf.read(4) + 1;
-            aScales = new List<int>(64);
             int qti;
             for (qti = 0; qti < 64; qti++)
             {
-                aScales.Add(buf.read(size));
+                aScales[qti] = buf.read(size);
             }
             size = buf.read(4) + 1;
-            dScales = new List<int>(64);
             for (qti = 0; qti < 64; qti++)
             {
-                dScales.Add(buf.read(size));
+                dScales[qti] = buf.read(size);
             }
             
             int baseMatrixCount = buf.read(9) + 1;
@@ -70,10 +79,7 @@
             int rpqr;
             int plj;
             int qtj;
-            quantRangeNumber = new byte[2, 3];
-            quantRangeSize = new byte[2, 3] [];
-            quantRangeBaseMatrixIndex = new int[2, 3] [];
-
+            
             for (qti = 0; qti <= 1; qti++)
             {
                 for (int pli = 0; pli <= 2; pli++)
@@ -187,13 +193,13 @@
 
         private void ParseDCTTokenHuffman(csBuffer buf)
         {
-            HuffmanTables = new List<HuffmanCode>(80);
+            HuffmanTables = new HuffmanCode[80];
             
             for (int i = 0; i < 80; i++)
             {
                 HuffmanCode c = new HuffmanCode();
                 c.Parse(buf);
-                HuffmanTables.Add(c);
+                HuffmanTables[i] = c;
             }
         }
     }

_______________________________________________
Mono-patches maillist  -  Mono-patches@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-patches


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic