[xiph-commits] r14235 - branches/theora-thusnelda/lib/enc

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Mon Nov 26 18:06:57 PST 2007


Author: xiphmont
Date: 2007-11-26 18:06:56 -0800 (Mon, 26 Nov 2007)
New Revision: 14235

Modified:
   branches/theora-thusnelda/lib/enc/codec_internal.h
   branches/theora-thusnelda/lib/enc/dct_decode.c
   branches/theora-thusnelda/lib/enc/dct_encode.c
   branches/theora-thusnelda/lib/enc/encode.c
   branches/theora-thusnelda/lib/enc/encoder_toplevel.c
   branches/theora-thusnelda/lib/enc/frarray.c
   branches/theora-thusnelda/lib/enc/frinit.c
   branches/theora-thusnelda/lib/enc/mcomp.c
Log:
Continued babysteps toward abstracting blocks/macroblocks/superblocks 
into non-flat abstractions



Modified: branches/theora-thusnelda/lib/enc/codec_internal.h
===================================================================
--- branches/theora-thusnelda/lib/enc/codec_internal.h	2007-11-26 19:02:35 UTC (rev 14234)
+++ branches/theora-thusnelda/lib/enc/codec_internal.h	2007-11-27 02:06:56 UTC (rev 14235)
@@ -126,7 +126,7 @@
   fragment_t *f[4]; // hilbert order
 } macroblock_t;
 
-#define SB_MB_ULFRAG(sb,mbnum) (sb->f[ ((mbnum)<2? ((mbnum)==0?3:5) : ((mbnum)==2?9:13)) ])
+#define SB_MB_BLFRAG(sb,mbnum) ((sb).f[ ((mbnum)<2? ((mbnum)==0?0:4) : ((mbnum)==2?8:14)) ])
 typedef struct superblock {
   fragment_t *f[16]; // hilbert order
 } superblock_t;
@@ -176,7 +176,12 @@
                                    U or V frame */
   ogg_uint32_t  UVSBCols;       /* Number of cols of SuperBlocks in a
                                    U or V frame */
+  ogg_uint32_t SuperBlocks;
+  ogg_uint32_t YSuperBlocks;
+  ogg_uint32_t UVSuperBlocks;
+  ogg_uint32_t MacroBlocks;
 
+  
   /**********************************************************************/
   /* Frames  */
   unsigned char *ThisFrameRecon;
@@ -191,7 +196,6 @@
   ogg_uint32_t  *recon_pixel_index_table;  /* start address of first
                                               pixel in recon buffer */
 
-  unsigned char *display_fragments;        /* Fragment update map */
   int            CodedBlockIndex;
   ogg_int32_t   *CodedBlockList;           /* A list of fragment indices for
                                               coded blocks. */
@@ -322,33 +326,23 @@
   ogg_int32_t       TokensCoded;
   /********************************************************************/
   /* SuperBlock, MacroBLock and Fragment Information */
-  fragment_t       *yfrag;
-  fragment_t       *ufrag;
-  fragment_t       *vfrag;
-  macroblock_t     *macrob;
-  superblock_t     *ysuper;
-  superblock_t     *usuper;
-  superblock_t     *vsuper;
+  fragment_t       *frag[3];
+  macroblock_t     *macro;
+  superblock_t     *super[3];
 
-  ogg_uint32_t      yfrag_h;
-  ogg_uint32_t      yfrag_v;
-  ogg_uint32_t      yfrag_n;
-  ogg_uint32_t      uvfrag_h;
-  ogg_uint32_t      uvfrag_v;
-  ogg_uint32_t      uvfrag_n;
-  ogg_uint32_t      frag_n;
+  ogg_uint32_t      frag_h[3];
+  ogg_uint32_t      frag_v[3];
+  ogg_uint32_t      frag_n[3];
+  ogg_uint32_t      frag_total;
 
-  ogg_uint32_t      macrob_h;
-  ogg_uint32_t      macrob_v;
-  ogg_uint32_t      macrob_n;
+  ogg_uint32_t      macro_h;
+  ogg_uint32_t      macro_v;
+  ogg_uint32_t      macro_total;
   
-  ogg_uint32_t      ysuper_h;
-  ogg_uint32_t      ysuper_v;
-  ogg_uint32_t      ysuper_n;
-  ogg_uint32_t      uvsuper_h;
-  ogg_uint32_t      uvsuper_v;
-  ogg_uint32_t      uvsuper_n;
-  ogg_uint32_t      super_n;
+  ogg_uint32_t      super_h[3];
+  ogg_uint32_t      super_v[3];
+  ogg_uint32_t      super_n[3];
+  ogg_uint32_t      super_total;
 
   /* Coded flag arrays and counters for them */
   unsigned char    *PartiallyCodedFlags;
@@ -445,7 +439,7 @@
 extern void fdct_short ( ogg_int16_t * InputData, ogg_int16_t * OutputData );
 extern ogg_uint32_t DPCMTokenizeBlock (CP_INSTANCE *cpi,
                                        ogg_int32_t FragIndex);
-extern void TransformQuantizeBlock (CP_INSTANCE *cpi, ogg_int32_t FragIndex,
+extern void TransformQuantizeBlock (CP_INSTANCE *cpi, fragment_t *fp, ogg_int32_t FragIndex,
                                     ogg_uint32_t PixelsPerLine ) ;
 extern void InitFrameDetails(CP_INSTANCE *cpi);
 extern void WriteQTables(PB_INSTANCE *pbi,oggpack_buffer *opb);
@@ -457,11 +451,13 @@
 extern void PackAndWriteDFArray( CP_INSTANCE *cpi );
 extern void InitMotionCompensation ( CP_INSTANCE *cpi );
 extern ogg_uint32_t GetMBIntraError (CP_INSTANCE *cpi, 
+				     fragment_t *fp,
 				     ogg_uint32_t FragIndex,
                                      ogg_uint32_t PixelsPerLine ) ;
 extern ogg_uint32_t GetMBInterError (CP_INSTANCE *cpi,
                                      unsigned char * SrcPtr,
                                      unsigned char * RefPtr,
+				     fragment_t *fp,
                                      ogg_uint32_t FragIndex,
                                      ogg_int32_t LastXMV,
                                      ogg_int32_t LastYMV,
@@ -469,21 +465,24 @@
 extern void WriteFrameHeader( CP_INSTANCE *cpi) ;
 extern ogg_uint32_t GetMBMVInterError (CP_INSTANCE *cpi,
                                        unsigned char * RefFramePtr,
+				       fragment_t *fp,
                                        ogg_uint32_t FragIndex,
                                        ogg_uint32_t PixelsPerLine,
                                        ogg_int32_t *MVPixelOffset,
                                        MOTION_VECTOR *MV );
 extern ogg_uint32_t GetMBMVExhaustiveSearch (CP_INSTANCE *cpi,
                                              unsigned char * RefFramePtr,
+					     fragment_t *fp,
                                              ogg_uint32_t FragIndex,
                                              ogg_uint32_t PixelsPerLine,
                                              MOTION_VECTOR *MV );
 extern ogg_uint32_t GetFOURMVExhaustiveSearch (CP_INSTANCE *cpi,
                                                unsigned char * RefFramePtr,
+					       fragment_t *fp,
                                                ogg_uint32_t FragIndex,
                                                ogg_uint32_t PixelsPerLine,
                                                MOTION_VECTOR *MV ) ;
-extern ogg_uint32_t EncodeData(CP_INSTANCE *cpi);
+extern void EncodeData(CP_INSTANCE *cpi);
 extern ogg_uint32_t PickIntra( CP_INSTANCE *cpi,
                                ogg_uint32_t SBRows,
                                ogg_uint32_t SBCols);

Modified: branches/theora-thusnelda/lib/enc/dct_decode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/dct_decode.c	2007-11-26 19:02:35 UTC (rev 14234)
+++ branches/theora-thusnelda/lib/enc/dct_decode.c	2007-11-27 02:06:56 UTC (rev 14235)
@@ -243,21 +243,24 @@
   UpdateUMV_HBorders( pbi, DestReconPtr, PlaneFragOffset );
 }
 
-static void CopyRecon( PB_INSTANCE *pbi, unsigned char * DestReconPtr,
+static void CopyRecon( CP_INSTANCE *cpi, unsigned char * DestReconPtr,
                 unsigned char * SrcReconPtr ) {
+  PB_INSTANCE   *pbi = &cpi->pb;
   ogg_uint32_t  i;
   ogg_uint32_t  PlaneLineStep; /* Pixels per line */
   ogg_uint32_t  PixelIndex;
 
   unsigned char  *SrcPtr;      /* Pointer to line of source image data */
   unsigned char  *DestPtr;     /* Pointer to line of destination image data */
+  fragment_t *fp;
 
   /* Copy over only updated blocks.*/
 
   /* First Y plane */
+  fp = cpi->frag[0];
   PlaneLineStep = pbi->YStride;
-  for ( i = 0; i < pbi->YPlaneFragments; i++ ) {
-    if ( pbi->display_fragments[i] ) {
+  for ( i = 0; i < cpi->frag_n[0]; i++,fp++ ) {
+    if ( fp->coded ) {
       PixelIndex = pbi->recon_pixel_index_table[i];
       SrcPtr = &SrcReconPtr[ PixelIndex ];
       DestPtr = &DestReconPtr[ PixelIndex ];
@@ -267,9 +270,10 @@
   }
 
   /* Then U and V */
+  fp = cpi->frag[1];
   PlaneLineStep = pbi->UVStride;
-  for ( i = pbi->YPlaneFragments; i < pbi->UnitFragments; i++ ) {
-    if ( pbi->display_fragments[i] ) {
+  for ( ; i < cpi->frag_n[0]+cpi->frag_n[1]; i++,fp++ ) {
+    if ( fp->coded ) {
       PixelIndex = pbi->recon_pixel_index_table[i];
       SrcPtr = &SrcReconPtr[ PixelIndex ];
       DestPtr = &DestReconPtr[ PixelIndex ];
@@ -278,23 +282,38 @@
 
     }
   }
+
+  fp = cpi->frag[2];
+  for ( ; i < cpi->frag_total; i++,fp++ ) {
+    if ( fp->coded ) {
+      PixelIndex = pbi->recon_pixel_index_table[i];
+      SrcPtr = &SrcReconPtr[ PixelIndex ];
+      DestPtr = &DestReconPtr[ PixelIndex ];
+
+      dsp_copy8x8 (pbi->dsp, SrcPtr, DestPtr, PlaneLineStep);
+
+    }
+  }
 }
 
-static void CopyNotRecon( PB_INSTANCE *pbi, unsigned char * DestReconPtr,
-                   unsigned char * SrcReconPtr ) {
+static void CopyNotRecon( CP_INSTANCE *cpi, unsigned char * DestReconPtr,
+                unsigned char * SrcReconPtr ) {
+  PB_INSTANCE   *pbi = &cpi->pb;
   ogg_uint32_t  i;
   ogg_uint32_t  PlaneLineStep; /* Pixels per line */
   ogg_uint32_t  PixelIndex;
 
   unsigned char  *SrcPtr;      /* Pointer to line of source image data */
-  unsigned char  *DestPtr;     /* Pointer to line of destination image data*/
+  unsigned char  *DestPtr;     /* Pointer to line of destination image data */
+  fragment_t *fp;
 
-  /* Copy over only updated blocks. */
+  /* Copy over only updated blocks.*/
 
   /* First Y plane */
+  fp = cpi->frag[0];
   PlaneLineStep = pbi->YStride;
-  for ( i = 0; i < pbi->YPlaneFragments; i++ ) {
-    if ( !pbi->display_fragments[i] ) {
+  for ( i = 0; i < cpi->frag_n[0]; i++,fp++ ) {
+    if ( !fp->coded ) {
       PixelIndex = pbi->recon_pixel_index_table[i];
       SrcPtr = &SrcReconPtr[ PixelIndex ];
       DestPtr = &DestReconPtr[ PixelIndex ];
@@ -304,9 +323,10 @@
   }
 
   /* Then U and V */
+  fp = cpi->frag[1];
   PlaneLineStep = pbi->UVStride;
-  for ( i = pbi->YPlaneFragments; i < pbi->UnitFragments; i++ ) {
-    if ( !pbi->display_fragments[i] ) {
+  for ( ; i < cpi->frag_n[0]+cpi->frag_n[1]; i++,fp++ ) {
+    if ( !fp->coded ) {
       PixelIndex = pbi->recon_pixel_index_table[i];
       SrcPtr = &SrcReconPtr[ PixelIndex ];
       DestPtr = &DestReconPtr[ PixelIndex ];
@@ -315,6 +335,18 @@
 
     }
   }
+
+  fp = cpi->frag[2];
+  for ( ; i < cpi->frag_total; i++,fp++ ) {
+    if ( !fp->coded ) {
+      PixelIndex = pbi->recon_pixel_index_table[i];
+      SrcPtr = &SrcReconPtr[ PixelIndex ];
+      DestPtr = &DestReconPtr[ PixelIndex ];
+
+      dsp_copy8x8 (pbi->dsp, SrcPtr, DestPtr, PlaneLineStep);
+
+    }
+  }
 }
 
 static void FilterHoriz__c(unsigned char * PixelPtr,
@@ -376,6 +408,7 @@
   ogg_int32_t LineLength;
   ogg_int32_t FLimit;
   int j,m,n;
+  fragment_t *fp;
 
   FLimit = cpi->pb.quant_info.loop_filter_limits[cpi->BaseQ]; // temp
   if ( FLimit == 0 ) return;
@@ -384,6 +417,7 @@
   for ( j = 0; j < 3 ; j++){
     switch(j) {
     case 0: /* y */
+      fp = cpi->frag[0];
       FromFragment = 0;
       ToFragment = pbi->YPlaneFragments;
       FragsAcross = pbi->HFragments;
@@ -392,6 +426,7 @@
       LineFragments = pbi->HFragments;
       break;
     case 1: /* u */
+      fp = cpi->frag[1];
       FromFragment = pbi->YPlaneFragments;
       ToFragment = pbi->YPlaneFragments + pbi->UVPlaneFragments ;
       FragsAcross = pbi->HFragments >> 1;
@@ -401,6 +436,7 @@
       break;
     /*case 2:  v */
     default:
+      fp = cpi->frag[2];
       FromFragment = pbi->YPlaneFragments + pbi->UVPlaneFragments;
       ToFragment = pbi->YPlaneFragments + (2 * pbi->UVPlaneFragments) ;
       FragsAcross = pbi->HFragments >> 1;
@@ -418,28 +454,29 @@
     /* first column conditions */
     /* only do 2 prediction if fragment coded and on non intra or if
        all fragments are intra */
-    if( pbi->display_fragments[i]){
+    if( fp->coded){
       /* Filter right hand border only if the block to the right is
          not coded */
-      if ( !pbi->display_fragments[ i + 1 ] ){
+      if ( !fp[1].coded ){
         dsp_FilterHoriz(pbi->dsp,pbi->LastFrameRecon+
                     pbi->recon_pixel_index_table[i]+6,
                     LineLength,BoundingValuePtr);
       }
 
       /* Bottom done if next row set */
-      if( !pbi->display_fragments[ i + LineFragments] ){
+      if( !fp[LineFragments].coded ){
         dsp_FilterVert(pbi->dsp,pbi->LastFrameRecon+
                    pbi->recon_pixel_index_table[i+LineFragments],
                    LineLength, BoundingValuePtr);
       }
     }
     i++;
+    fp++;
 
     /***************************************************************/
     /* middle columns  */
-    for ( n = 1 ; n < FragsAcross - 1 ; n++, i++) {
-      if( pbi->display_fragments[i]){
+    for ( n = 1 ; n < FragsAcross - 1 ; n++, i++, fp++) {
+      if( fp->coded){
         /* Filter Left edge always */
         dsp_FilterHoriz(pbi->dsp,pbi->LastFrameRecon+
                     pbi->recon_pixel_index_table[i]-2,
@@ -447,14 +484,14 @@
 
         /* Filter right hand border only if the block to the right is
            not coded */
-        if ( !pbi->display_fragments[ i + 1 ] ){
+        if ( !fp[1].coded ){
           dsp_FilterHoriz(pbi->dsp,pbi->LastFrameRecon+
                       pbi->recon_pixel_index_table[i]+6,
                       LineLength, BoundingValuePtr);
         }
 
         /* Bottom done if next row set */
-        if( !pbi->display_fragments[ i + LineFragments] ){
+        if( !fp[LineFragments].coded ){
           dsp_FilterVert(pbi->dsp,pbi->LastFrameRecon+
                      pbi->recon_pixel_index_table[i + LineFragments],
                      LineLength, BoundingValuePtr);
@@ -465,20 +502,21 @@
 
     /***************************************************************/
     /* Last Column */
-    if( pbi->display_fragments[i]){
+    if(fp->coded){
       /* Filter Left edge always */
       dsp_FilterHoriz(pbi->dsp,pbi->LastFrameRecon+
                   pbi->recon_pixel_index_table[i] - 2 ,
                   LineLength, BoundingValuePtr);
 
       /* Bottom done if next row set */
-      if( !pbi->display_fragments[ i + LineFragments] ){
+      if( !fp[LineFragments].coded ){
         dsp_FilterVert(pbi->dsp,pbi->LastFrameRecon+
                    pbi->recon_pixel_index_table[i + LineFragments],
                    LineLength, BoundingValuePtr);
       }
     }
     i++;
+    fp++;
 
     /***************************************************************/
     /* Middle Rows */
@@ -489,7 +527,7 @@
       /* first column conditions */
       /* only do 2 prediction if fragment coded and on non intra or if
          all fragments are intra */
-      if( pbi->display_fragments[i]){
+      if( fp->coded){
         /* TopRow is always done */
         dsp_FilterVert(pbi->dsp,pbi->LastFrameRecon+
                    pbi->recon_pixel_index_table[i],
@@ -497,25 +535,26 @@
 
         /* Filter right hand border only if the block to the right is
            not coded */
-        if ( !pbi->display_fragments[ i + 1 ] ){
+        if ( !fp[1].coded ){
           dsp_FilterHoriz(pbi->dsp,pbi->LastFrameRecon+
                       pbi->recon_pixel_index_table[i] + 6,
                       LineLength, BoundingValuePtr);
         }
 
         /* Bottom done if next row set */
-        if( !pbi->display_fragments[ i + LineFragments] ){
+        if( !fp[LineFragments].coded ){
           dsp_FilterVert(pbi->dsp,pbi->LastFrameRecon+
                      pbi->recon_pixel_index_table[i + LineFragments],
                      LineLength, BoundingValuePtr);
         }
       }
       i++;
+      fp++;
 
       /*****************************************************************/
       /* middle columns  */
-      for ( n = 1 ; n < FragsAcross - 1 ; n++, i++){
-        if( pbi->display_fragments[i]){
+      for ( n = 1 ; n < FragsAcross - 1 ; n++, i++, fp++){
+        if( fp->coded){
           /* Filter Left edge always */
           dsp_FilterHoriz(pbi->dsp,pbi->LastFrameRecon+
                       pbi->recon_pixel_index_table[i] - 2,
@@ -528,14 +567,14 @@
 
           /* Filter right hand border only if the block to the right
              is not coded */
-          if ( !pbi->display_fragments[ i + 1 ] ){
+          if ( !fp[1].coded ){
             dsp_FilterHoriz(pbi->dsp,pbi->LastFrameRecon+
                         pbi->recon_pixel_index_table[i] + 6,
                         LineLength, BoundingValuePtr);
           }
 
           /* Bottom done if next row set */
-          if( !pbi->display_fragments[ i + LineFragments] ){
+          if( !fp[LineFragments].coded ){
             dsp_FilterVert(pbi->dsp,pbi->LastFrameRecon+
                        pbi->recon_pixel_index_table[i + LineFragments],
                        LineLength, BoundingValuePtr);
@@ -545,7 +584,7 @@
 
       /******************************************************************/
       /* Last Column */
-      if( pbi->display_fragments[i]){
+      if(fp->coded){
         /* Filter Left edge always*/
         dsp_FilterHoriz(pbi->dsp,pbi->LastFrameRecon+
                     pbi->recon_pixel_index_table[i] - 2,
@@ -557,14 +596,14 @@
                    LineLength, BoundingValuePtr);
 
         /* Bottom done if next row set */
-        if( !pbi->display_fragments[ i + LineFragments] ){
+        if( !fp[LineFragments].coded ){
           dsp_FilterVert(pbi->dsp,pbi->LastFrameRecon+
                      pbi->recon_pixel_index_table[i + LineFragments],
                      LineLength, BoundingValuePtr);
         }
       }
       i++;
-
+      fp++;
     }
 
     /*******************************************************************/
@@ -573,7 +612,7 @@
     /* first column conditions */
     /* only do 2 prediction if fragment coded and on non intra or if
        all fragments are intra */
-    if( pbi->display_fragments[i]){
+    if(fp->coded){
 
       /* TopRow is always done */
       dsp_FilterVert(pbi->dsp,pbi->LastFrameRecon+
@@ -582,18 +621,19 @@
 
       /* Filter right hand border only if the block to the right is
          not coded */
-      if ( !pbi->display_fragments[ i + 1 ] ){
+      if ( !fp[1].coded ){
         dsp_FilterHoriz(pbi->dsp,pbi->LastFrameRecon+
                     pbi->recon_pixel_index_table[i] + 6,
                     LineLength, BoundingValuePtr);
       }
     }
     i++;
+    fp++;
 
     /******************************************************************/
     /* middle columns  */
-    for ( n = 1 ; n < FragsAcross - 1 ; n++, i++){
-      if( pbi->display_fragments[i]){
+    for ( n = 1 ; n < FragsAcross - 1 ; n++, i++, fp++){
+      if( fp->coded){
         /* Filter Left edge always */
         dsp_FilterHoriz(pbi->dsp,pbi->LastFrameRecon+
                     pbi->recon_pixel_index_table[i] - 2,
@@ -606,7 +646,7 @@
 
         /* Filter right hand border only if the block to the right is
            not coded */
-        if ( !pbi->display_fragments[ i + 1 ] ){
+        if ( !fp[1].coded ){
           dsp_FilterHoriz(pbi->dsp,pbi->LastFrameRecon+
                       pbi->recon_pixel_index_table[i] + 6,
                       LineLength, BoundingValuePtr);
@@ -616,7 +656,7 @@
 
     /******************************************************************/
     /* Last Column */
-    if( pbi->display_fragments[i]){
+    if( fp->coded){
       /* Filter Left edge always */
       dsp_FilterHoriz(pbi->dsp,pbi->LastFrameRecon+
                   pbi->recon_pixel_index_table[i] - 2,
@@ -629,6 +669,7 @@
 
     }
     i++;
+    fp++;
   }
 }
 
@@ -646,9 +687,9 @@
     SwapReconBuffersTemp = pbi->ThisFrameRecon;
     pbi->ThisFrameRecon = pbi->LastFrameRecon;
     pbi->LastFrameRecon = SwapReconBuffersTemp;
-    CopyNotRecon( pbi, pbi->LastFrameRecon, pbi->ThisFrameRecon );
+    CopyNotRecon( cpi, pbi->LastFrameRecon, pbi->ThisFrameRecon );
   }else{
-    CopyRecon( pbi, pbi->LastFrameRecon, pbi->ThisFrameRecon );
+    CopyRecon( cpi, pbi->LastFrameRecon, pbi->ThisFrameRecon );
   }
 
   /* Apply a loop filter to edge pixels of updated blocks */
@@ -748,7 +789,7 @@
   /* Reconstruct the golden frame if necessary.
      For VFW codec only on key frames */
   if ( pbi->FrameType == KEY_FRAME ){
-    CopyRecon( pbi, pbi->GoldenFrame, pbi->LastFrameRecon );
+    CopyRecon( cpi, pbi->GoldenFrame, pbi->LastFrameRecon );
     /* We may need to update the UMV border */
     UpdateUMVBorder(cpi, pbi->GoldenFrame);
   }

Modified: branches/theora-thusnelda/lib/enc/dct_encode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/dct_encode.c	2007-11-26 19:02:35 UTC (rev 14234)
+++ branches/theora-thusnelda/lib/enc/dct_encode.c	2007-11-27 02:06:56 UTC (rev 14235)
@@ -364,6 +364,7 @@
 }
 
 void TransformQuantizeBlock (CP_INSTANCE *cpi, 
+			     fragment_t *frag,
 			     ogg_int32_t FragIndex,
                              ogg_uint32_t PixelsPerLine) {
   unsigned char *FiltPtr;     /* Pointers to srf filtered pixels */
@@ -446,7 +447,7 @@
 
   if ( (mode == CODE_INTER_NO_MV) &&
        ( AllZeroDctData(cpi->pb.QFragData[FragIndex]) ) ) {
-    cpi->pb.display_fragments[FragIndex] = 0;
+    frag->coded = 0;
   }
 
 }

Modified: branches/theora-thusnelda/lib/enc/encode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/encode.c	2007-11-26 19:02:35 UTC (rev 14234)
+++ branches/theora-thusnelda/lib/enc/encode.c	2007-11-27 02:06:56 UTC (rev 14235)
@@ -49,15 +49,19 @@
 
   /* for y,u,v */
   for ( j = 0; j < 3 ; j++) {
+    fragment_t *fp;
+
     /* pick which fragments based on Y, U, V */
     switch(j){
     case 0: /* y */
+      fp = cpi->frag[0];
       FromFragment = 0;
       ToFragment = cpi->pb.YPlaneFragments;
       FragsAcross = cpi->pb.HFragments;
       FragsDown = cpi->pb.VFragments;
       break;
     case 1: /* u */
+      fp = cpi->frag[1];
       FromFragment = cpi->pb.YPlaneFragments;
       ToFragment = cpi->pb.YPlaneFragments + cpi->pb.UVPlaneFragments ;
       FragsAcross = cpi->pb.HFragments >> 1;
@@ -65,6 +69,7 @@
       break;
     /*case 2:  v */
     default:
+      fp = cpi->frag[2];
       FromFragment = cpi->pb.YPlaneFragments + cpi->pb.UVPlaneFragments;
       ToFragment = cpi->pb.YPlaneFragments + (2 * cpi->pb.UVPlaneFragments) ;
       FragsAcross = cpi->pb.HFragments >> 1;
@@ -74,17 +79,22 @@
 
     /* initialize our array of last used DC Components */
     for(k=0;k<3;k++)Last[k]=0;
+
     i=FromFragment;
+    fn[0]=1;
+    fn[1]=FragsAcross+1;
+    fn[2]=FragsAcross;
+    fn[3]=FragsAcross-1;
+    
 
     /* do prediction on all of Y, U or V */
     for ( m = 0 ; m < FragsDown ; m++) {
-      for ( n = 0 ; n < FragsAcross ; n++, i++) {
+      for ( n = 0 ; n < FragsAcross ; n++, i++, fp++) {
         predicted[i] = cpi->pb.QFragData[i][0];
 
         /* only do 2 prediction if fragment coded and on non intra or
            if all fragments are intra */
-        if( cpi->pb.display_fragments[i] ||
-            (cpi->pb.FrameType == KEY_FRAME) ) {
+        if( fp->coded || cpi->pb.FrameType == KEY_FRAME ) {
           /* Type of Fragment */
 
           WhichFrame = Mode2Frame[cpi->pb.FragCodingMethod[i]];
@@ -92,23 +102,21 @@
           /* Check Borderline Cases */
           WhichCase = (n==0) + ((m==0) << 1) + ((n+1 == FragsAcross) << 2);
 
-          fn[0]=i-1;
-          fn[1]=i-FragsAcross-1;
-          fn[2]=i-FragsAcross;
-          fn[3]=i-FragsAcross+1;
-
           /* fragment valid for prediction use if coded and it comes
              from same frame as the one we are predicting */
           for(k=pcount=wpc=0; k<4; k++) {
             int pflag;
             pflag=1<<k;
-            if((bc_mask[WhichCase]&pflag) &&
-               cpi->pb.display_fragments[fn[k]] &&
-               (Mode2Frame[cpi->pb.FragCodingMethod[fn[k]]] == WhichFrame)){
-              v[pcount]=cpi->pb.QFragData[fn[k]][0];
-              wpc|=pflag;
-              pcount++;
-            }
+            if((bc_mask[WhichCase]&pflag)){
+	      fragment_t *fnp=fp - fn[k];
+	      
+	      if(fnp->coded &&
+		 (Mode2Frame[cpi->pb.FragCodingMethod[i-fn[k]]] == WhichFrame)){
+		v[pcount]=cpi->pb.QFragData[i-fn[k]][0];
+		wpc|=pflag;
+		pcount++;
+	      }
+	    }
           }
 
           if(wpc==0) {
@@ -159,81 +167,63 @@
 }
 
 
-static ogg_uint32_t QuadCodeComponent ( CP_INSTANCE *cpi,
-					ogg_uint32_t FirstSB,
-					ogg_uint32_t SBRows,
-					ogg_uint32_t SBCols,
-					ogg_uint32_t PixelsPerLine){
+static ogg_uint32_t CodePlane ( CP_INSTANCE *cpi,
+				int plane,
+				ogg_uint32_t PixelsPerLine){
 
-  ogg_int32_t   FragIndex;      /* Fragment number */
-  ogg_uint32_t  MB, B;          /* Macro-Block, Block indices */
-  ogg_uint32_t  SBrow;          /* Super-Block row number */
-  ogg_uint32_t  SBcol;          /* Super-Block row number */
-  ogg_uint32_t  SB=FirstSB;     /* Super-Block index, initialised to first
-                                   of this component */
-  ogg_uint32_t  coded_pixels=0; /* Number of pixels coded */
-  int           MBCodedFlag;
-
+  ogg_uint32_t SBs = cpi->super_n[plane];
+  ogg_uint32_t SB, MB, B;
+  
   /* actually transform and quantize the image now that we've decided
      on the modes Parse in quad-tree ordering */
 
-  for ( SBrow=0; SBrow<SBRows; SBrow++ ) {
-    for ( SBcol=0; SBcol<SBCols; SBcol++ ) {
-      /* Check its four Macro-Blocks  */
-      /* 'Macro-Block' is a misnomer in the chroma planes; this is
-	 really just a Hilbert curve iterator */
-      for ( MB=0; MB<4; MB++ ) {
+  for ( SB=0; SB<SBs; SB++ ){
+    superblock_t *sp = &cpi->super[plane][SB];
+    int frag=0;
 
-        if ( QuadMapToMBTopLeft(cpi->pb.BlockMap,SB,MB) >= 0 ) {
+    int SBi = SB;
+    if(plane>0)SBi+=cpi->super_n[0];
+    if(plane>1)SBi+=cpi->super_n[1];
 
-          MBCodedFlag = 0;
+    for ( MB=0; MB<4; MB++ ) {
+      int MBCodedFlag = 0;
 
-          /*  Now actually code the blocks */
-          for ( B=0; B<4; B++ ) {
-            FragIndex = QuadMapToIndex1( cpi->pb.BlockMap, SB, MB, B );
+      for ( B=0; B<4; B++, frag++ ) {
+	fragment_t *fp = sp->f[frag];
 
-            /* Does Block lie in frame: */
-            if ( FragIndex >= 0 ) {
-
-              /* In Frame: Is it coded: */
-              if ( cpi->pb.display_fragments[FragIndex] ) {
-
-                /* transform and quantize block */
-                TransformQuantizeBlock( cpi, FragIndex, PixelsPerLine );
-
-                /* Has the block got struck off (no MV and no data
-                   generated after DCT) If not then mark it and the
-                   assosciated MB as coded. */
-                if ( cpi->pb.display_fragments[FragIndex] ) {
-                  /* Create linear list of coded block indices */
-                  cpi->pb.CodedBlockList[cpi->pb.CodedBlockIndex] = FragIndex;
-                  cpi->pb.CodedBlockIndex++;
-
-                  /* MB is still coded */
-                  MBCodedFlag = 1;
-                  cpi->MBCodingMode = cpi->pb.FragCodingMethod[FragIndex];
-
-                }
-              }
-            }
-          }
-          /* If the MB is marked as coded and we are in the Y plane then */
-          /* the mode list needs to be updated. */
-          if ( MBCodedFlag && (FirstSB == 0) ){
-            /* Make a note of the selected mode in the mode list */
-            cpi->ModeList[cpi->ModeListCount] = cpi->MBCodingMode;
-            cpi->ModeListCount++;
-          }
-        }
+	/* Does Block lie in frame: */
+	if ( fp && fp->coded ) {
+	  int FragIndex = QuadMapToIndex1( cpi->pb.BlockMap, SBi, MB, B );
+	  
+	  /* transform and quantize block */
+	  TransformQuantizeBlock( cpi, fp, FragIndex, PixelsPerLine );
+	  
+	  /* Has the block got struck off (no MV and no data
+	     generated after DCT) If not then mark it and the
+	     assosciated MB as coded. */
+	  if ( fp->coded ) {
+	    /* Create linear list of coded block indices */
+	    cpi->pb.CodedBlockList[cpi->pb.CodedBlockIndex] = FragIndex;
+	    cpi->pb.CodedBlockIndex++;
+	    
+	    /* MB is still coded */
+	    MBCodedFlag = 1;
+	    cpi->MBCodingMode = cpi->pb.FragCodingMethod[FragIndex];
+	    
+	  }
+	}
       }
-
-      SB++;
-
-    }
+     
+      /* If the MB is marked as coded and we are in the Y plane then */
+      /* the mode list needs to be updated. */
+      if ( MBCodedFlag && (plane == 0) ){
+	/* Make a note of the selected mode in the mode list */
+	cpi->ModeList[cpi->ModeListCount] = cpi->MBCodingMode;
+	cpi->ModeListCount++;
+      }
+    }  
   }
-
-  /* Return number of pixels coded */
-  return coded_pixels;
+  return 0;
 }
 
 static void EncodeDcTokenList (CP_INSTANCE *cpi) {
@@ -814,9 +804,8 @@
 
 }
 
-ogg_uint32_t EncodeData(CP_INSTANCE *cpi){
+void EncodeData(CP_INSTANCE *cpi){
   ogg_int32_t   i;
-  ogg_uint32_t  coded_pixels=0;
 
   /* Zero the count of tokens so far this frame. */
   cpi->TotTokenCount = 0;
@@ -835,17 +824,10 @@
   dsp_save_fpu (cpi->dsp);
 
   /* Encode and tokenise the Y, U and V components */
-  coded_pixels = QuadCodeComponent(cpi, 0, cpi->pb.YSBRows, cpi->pb.YSBCols,
-                                   cpi->info.width );
-  coded_pixels += QuadCodeComponent(cpi, cpi->pb.YSuperBlocks,
-                                    cpi->pb.UVSBRows,
-                                    cpi->pb.UVSBCols,
-                                    cpi->info.width>>1 );
-  coded_pixels += QuadCodeComponent(cpi,
-                                    cpi->pb.YSuperBlocks+cpi->pb.UVSuperBlocks,
-                                    cpi->pb.UVSBRows, cpi->pb.UVSBCols,
-                                    cpi->info.width>>1 );
-
+  CodePlane(cpi, 0, cpi->info.width );
+  CodePlane(cpi, 1, cpi->info.width>>1 );
+  CodePlane(cpi, 2, cpi->info.width>>1 );
+  
   PredictDC(cpi, cpi->PredictedDC);
 
 #ifdef _TH_DEBUG_
@@ -861,7 +843,7 @@
 
   /* Pack DCT tokens */
   for ( i = 0; i < cpi->pb.CodedBlockIndex; i++ ) 
-    coded_pixels += DPCMTokenizeBlock ( cpi, cpi->pb.CodedBlockList[i] );
+    DPCMTokenizeBlock ( cpi, cpi->pb.CodedBlockList[i] );
 
   /* Bit pack the video data data */
   PackCodedVideo(cpi);
@@ -870,9 +852,6 @@
   ReconRefFrames(cpi);
 
   dsp_restore_fpu (cpi->dsp);
-
-  /* Return total number of coded pixels */
-  return coded_pixels;
 }
 
 ogg_uint32_t PickIntra( CP_INSTANCE *cpi,
@@ -1065,29 +1044,21 @@
   /* decide what block type and motion vectors to use on all of the frames */
   for ( SBrow=0; SBrow<SBRows; SBrow++ ) {
     for ( SBcol=0; SBcol<SBCols; SBcol++ ) {
+      superblock_t *sp = &cpi->super[0][SBrow*SBCols+SBcol];
+      int fragi = 0;
       /* Check its four Macro-Blocks */
-      for ( MB=0; MB<4; MB++ ) {
-        /* There may be MB's lying out of frame which must be
-           ignored. For these MB's Top left block will have a negative
-           Fragment Index. */
-        if ( QuadMapToMBTopLeft(cpi->pb.BlockMap,SB,MB) < 0 ) continue;
-
+      for ( MB=0; MB<4; MB++, fragi+=4 ) {
+	
         /* Is the current macro block coded (in part or in whole) */
         MBCodedFlag = 0;
         for ( B=0; B<4; B++ ) {
-          YFragIndex = QuadMapToIndex1( cpi->pb.BlockMap, SB, MB, B );
-
-          /* Does Block lie in frame: */
-          if ( YFragIndex >= 0 ) {
-            /* In Frame: Is it coded: */
-            if ( cpi->pb.display_fragments[YFragIndex] ) {
-              MBCodedFlag = 1;
-              break;
-            }
-          } else
-            MBCodedFlag = 0;
-        }
-
+	  fragment_t *fp = sp->f[fragi+B];
+          if ( fp && fp->coded ){
+	    MBCodedFlag = 1;
+	    break;
+	  }
+	}
+	
         /* This one isn't coded go to the next one */
         if(!MBCodedFlag) continue;
 
@@ -1113,24 +1084,30 @@
 
 
         /* Look at the intra coding error. */
-        MBIntraError = GetMBIntraError( cpi, YFragIndex, PixelsPerLine );
+        MBIntraError = GetMBIntraError( cpi, 
+					&cpi->frag[0][YFragIndex],
+					YFragIndex, PixelsPerLine );
         BestError = (BestError > MBIntraError) ? MBIntraError : BestError;
 
         /* Get the golden frame error */
         MBGFError = GetMBInterError( cpi, cpi->yuvptr,
-                                     cpi->pb.GoldenFrame, YFragIndex,
+                                     cpi->pb.GoldenFrame, 
+				     &cpi->frag[0][YFragIndex],
+				     YFragIndex,
                                      0, 0, PixelsPerLine );
         BestError = (BestError > MBGFError) ? MBGFError : BestError;
 
         /* Calculate the 0,0 case. */
         MBInterError = GetMBInterError( cpi, cpi->yuvptr,
                                         cpi->pb.LastFrameRecon,
+					&cpi->frag[0][YFragIndex],
                                         YFragIndex, 0, 0, PixelsPerLine );
         BestError = (BestError > MBInterError) ? MBInterError : BestError;
 
         /* Measure error for last MV */
         MBLastInterError =  GetMBInterError( cpi, cpi->yuvptr,
                                              cpi->pb.LastFrameRecon,
+					     &cpi->frag[0][YFragIndex],
                                              YFragIndex, LastInterMVect.x,
                                              LastInterMVect.y, PixelsPerLine );
         BestError = (BestError > MBLastInterError) ?
@@ -1139,6 +1116,7 @@
         /* Measure error for prior last MV */
         MBPriorLastInterError =  GetMBInterError( cpi, cpi->yuvptr,
                                                   cpi->pb.LastFrameRecon,
+						  &cpi->frag[0][YFragIndex],
                                                   YFragIndex,
                                                   PriorLastInterMVect.x,
                                                   PriorLastInterMVect.y,
@@ -1158,7 +1136,9 @@
              quick mode. */
           if ( cpi->info.quick_p ) {
             MBInterMVError = GetMBMVInterError( cpi, cpi->pb.LastFrameRecon,
-                                                YFragIndex, PixelsPerLine,
+						&cpi->frag[0][YFragIndex],
+                                                YFragIndex, 
+						PixelsPerLine,
                                                 cpi->MVPixelOffsetY,
                                                 &InterMVect );
 
@@ -1169,6 +1149,7 @@
 
               MBInterMVExError =
                 GetMBMVExhaustiveSearch( cpi, cpi->pb.LastFrameRecon,
+					 &cpi->frag[0][YFragIndex],
                                          YFragIndex, PixelsPerLine,
                                          &InterMVectEx );
 
@@ -1184,6 +1165,7 @@
             /* Use an exhaustive search */
             MBInterMVError =
               GetMBMVExhaustiveSearch( cpi, cpi->pb.LastFrameRecon,
+				       &cpi->frag[0][YFragIndex],
                                        YFragIndex, PixelsPerLine,
                                        &InterMVect );
           }
@@ -1205,12 +1187,14 @@
         if ( BestError > cpi->MinImprovementForNewMV && cpi->MotionCompensation) {
           /* Do an MV search in the golden reference frame */
           MBGF_MVError = GetMBMVInterError( cpi, cpi->pb.GoldenFrame,
+					    &cpi->frag[0][YFragIndex],
                                             YFragIndex, PixelsPerLine,
                                             cpi->MVPixelOffsetY, &GFMVect );
 
           /* Measure error for last GFMV */
           LastMBGF_MVError =  GetMBInterError( cpi, cpi->yuvptr,
                                                cpi->pb.GoldenFrame,
+					       &cpi->frag[0][YFragIndex],
                                                YFragIndex, LastGFMVect.x,
                                                LastGFMVect.y, PixelsPerLine );
 
@@ -1239,6 +1223,7 @@
           /* Get the 4MV error. */
           MBInterFOURMVError =
             GetFOURMVExhaustiveSearch( cpi, cpi->pb.LastFrameRecon,
+				       &cpi->frag[0][YFragIndex],
                                        YFragIndex, PixelsPerLine, FourMVect );
 
           /* If the improvement is great enough then use the four MV mode */

Modified: branches/theora-thusnelda/lib/enc/encoder_toplevel.c
===================================================================
--- branches/theora-thusnelda/lib/enc/encoder_toplevel.c	2007-11-26 19:02:35 UTC (rev 14234)
+++ branches/theora-thusnelda/lib/enc/encoder_toplevel.c	2007-11-27 02:06:56 UTC (rev 14235)
@@ -156,20 +156,16 @@
     _ogg_free(cpi->OptimisedTokenListPl);
   cpi->OptimisedTokenListPl = 0;
 
-  if(cpi->yfrag)_ogg_free(cpi->yfrag);
-  if(cpi->ufrag)_ogg_free(cpi->ufrag);
-  if(cpi->vfrag)_ogg_free(cpi->vfrag);
-  if(cpi->macrob)_ogg_free(cpi->macrob);
-  if(cpi->ysuper)_ogg_free(cpi->ysuper);
-  if(cpi->usuper)_ogg_free(cpi->usuper);
-  if(cpi->vsuper)_ogg_free(cpi->vsuper);
-  cpi->yfrag = 0;
-  cpi->ufrag = 0;
-  cpi->vfrag = 0;
-  cpi->macrob = 0;
-  cpi->ysuper = 0;
-  cpi->usuper = 0;
-  cpi->vsuper = 0;
+  if(cpi->frag[0])_ogg_free(cpi->frag[0]);
+  if(cpi->macro)_ogg_free(cpi->macro);
+  if(cpi->super[0])_ogg_free(cpi->super[0]);
+  cpi->frag[0] = 0;
+  cpi->frag[1] = 0;
+  cpi->frag[2] = 0;
+  cpi->macro = 0;
+  cpi->super[0] = 0;
+  cpi->super[1] = 0;
+  cpi->super[2] = 0;
 
 }
 
@@ -197,35 +193,41 @@
                 sizeof(*cpi->OptimisedTokenListPl));
 
   /* new block abstraction setup... babysteps... */
-  cpi->yfrag_h = (cpi->info.width >> 3);
-  cpi->yfrag_v = (cpi->info.height >> 3);
-  cpi->yfrag_n = cpi->yfrag_h * cpi->yfrag_v;
-  cpi->uvfrag_h = (cpi->yfrag_h >> 1);
-  cpi->uvfrag_v = (cpi->yfrag_v >> 1);
-  cpi->uvfrag_n = cpi->uvfrag_h * cpi->uvfrag_v;
-  cpi->frag_n = cpi->yfrag_n + cpi->uvfrag_n*2;
+  cpi->frag_h[0] = (cpi->info.width >> 3);
+  cpi->frag_v[0] = (cpi->info.height >> 3);
+  cpi->frag_n[0] = cpi->frag_h[0] * cpi->frag_v[0];
+  cpi->frag_h[1] = (cpi->info.width >> 4);
+  cpi->frag_v[1] = (cpi->info.height >> 4);
+  cpi->frag_n[1] = cpi->frag_h[1] * cpi->frag_v[1];
+  cpi->frag_h[2] = (cpi->info.width >> 4);
+  cpi->frag_v[2] = (cpi->info.height >> 4);
+  cpi->frag_n[2] = cpi->frag_h[2] * cpi->frag_v[2];
+  cpi->frag_total = cpi->frag_n[0] + cpi->frag_n[1] + cpi->frag_n[2];
 
-  cpi->macrob_h = (cpi->yfrag_h >> 1);
-  cpi->macrob_v = (cpi->yfrag_v >> 1);
-  cpi->macrob_n = cpi->macrob_h * cpi->macrob_v;
+  cpi->macro_h = (cpi->frag_h[0] >> 1);
+  cpi->macro_v = (cpi->frag_v[0] >> 1);
+  cpi->macro_total = cpi->macro_h * cpi->macro_v;
 
-  cpi->ysuper_h = (cpi->info.width >> 5) + ((cpi->info.width & 0x1f) ? 1 : 0);
-  cpi->ysuper_v = (cpi->info.height >> 5) + ((cpi->info.height & 0x1f) ? 1 : 0);
-  cpi->ysuper_n = cpi->ysuper_h * cpi->ysuper_v;
-  cpi->uvsuper_h = (cpi->info.width >> 6) + ((cpi->info.width & 0x3f) ? 1 : 0);
-  cpi->uvsuper_v = (cpi->info.height >> 6) + ((cpi->info.height & 0x3f) ? 1 : 0);
-  cpi->uvsuper_n = cpi->uvsuper_h * cpi->uvsuper_v;
-  cpi->super_n = cpi->ysuper_n + cpi->uvsuper_n*2;
+  cpi->super_h[0] = (cpi->info.width >> 5) + ((cpi->info.width & 0x1f) ? 1 : 0);
+  cpi->super_v[0] = (cpi->info.height >> 5) + ((cpi->info.height & 0x1f) ? 1 : 0);
+  cpi->super_n[0] = cpi->super_h[0] * cpi->super_v[0];
+  cpi->super_h[1] = (cpi->info.width >> 6) + ((cpi->info.width & 0x3f) ? 1 : 0);
+  cpi->super_v[1] = (cpi->info.height >> 6) + ((cpi->info.height & 0x3f) ? 1 : 0);
+  cpi->super_n[1] = cpi->super_h[1] * cpi->super_v[1];
+  cpi->super_h[2] = (cpi->info.width >> 6) + ((cpi->info.width & 0x3f) ? 1 : 0);
+  cpi->super_v[2] = (cpi->info.height >> 6) + ((cpi->info.height & 0x3f) ? 1 : 0);
+  cpi->super_n[2] = cpi->super_h[2] * cpi->super_v[2];
+  cpi->super_total = cpi->super_n[0] + cpi->super_n[1] + cpi->super_n[2];
 
-  cpi->yfrag = calloc(cpi->yfrag_n, sizeof(*cpi->yfrag));
-  cpi->ufrag = calloc(cpi->uvfrag_n, sizeof(*cpi->ufrag));
-  cpi->vfrag = calloc(cpi->uvfrag_n, sizeof(*cpi->vfrag));
+  cpi->frag[0] = calloc(cpi->frag_total, sizeof(**cpi->frag));
+  cpi->frag[1] = cpi->frag[0] + cpi->frag_n[0];
+  cpi->frag[2] = cpi->frag[1] + cpi->frag_n[1];
 
-  cpi->macrob = calloc(cpi->macrob_n, sizeof(*cpi->macrob));
+  cpi->macro = calloc(cpi->macro_total, sizeof(*cpi->macro));
 
-  cpi->ysuper = calloc(cpi->ysuper_n, sizeof(*cpi->ysuper));
-  cpi->usuper = calloc(cpi->uvsuper_n, sizeof(*cpi->usuper));
-  cpi->vsuper = calloc(cpi->uvsuper_n, sizeof(*cpi->vsuper));
+  cpi->super[0] = calloc(cpi->super_total, sizeof(**cpi->super));
+  cpi->super[1] = cpi->super[0] + cpi->super_n[0];
+  cpi->super[2] = cpi->super[1] + cpi->super_n[1];
 
   /* fill in superblock fragment pointers */
 
@@ -238,13 +240,24 @@
     int row,col,frag;
     int hilbertx[16] = {0,1,1,0,0,0,1,1,2,2,3,3,3,2,2,3};
     int hilberty[16] = {0,0,1,1,2,3,3,2,2,3,3,2,1,1,0,0};
+    int plane;
 
-    /* Y */
-    for(row=0;row<cpi->ysuper_v;row++){
-      for(col=0;row<cpi->ysuper_h;col++){
-	for(frag=0;frag<16;frag++){
-	  /* translate to fragment index */
-	  
+    for(plane=0;plane<3;plane++){
+
+      for(row=0;row<cpi->super_v[plane];row++){
+	int baserow = row*4;
+	for(col=0;col<cpi->super_h[plane];col++){
+	  int basecol = col*4;
+	  int superindex = row*cpi->super_h[plane] + col;
+	  for(frag=0;frag<16;frag++){
+	    /* translate to fragment index */
+	    int frow = baserow + hilberty[frag];
+	    int fcol = basecol + hilbertx[frag];
+	    if(frow<cpi->frag_v[plane] && fcol<cpi->frag_h[plane]){
+	      int fragindex = frow*cpi->frag_h[plane] + fcol;
+	      cpi->super[plane][superindex].f[frag] = &cpi->frag[plane][fragindex];
+	    }
+	  }
 	}
       }
     }
@@ -252,10 +265,13 @@
 }
 
 static void SetupKeyFrame(CP_INSTANCE *cpi) {
-  /* Initialise the cpi->pb.display_fragments and other fragment
-     structures for the first frame. */
-  memset( cpi->pb.display_fragments, 1, cpi->pb.UnitFragments );
+  int i,j;
 
+  /* code all blocks */
+  for(i=0;i<3;i++)
+    for(j=0;j<cpi->frag_n[i];j++)
+      cpi->frag[i][j].coded=1;
+  
   /* Set up for a KEY FRAME */
   cpi->pb.FrameType = KEY_FRAME;
 }
@@ -320,7 +336,7 @@
 }
 
 static int CompressFrame( CP_INSTANCE *cpi ) {
-  ogg_uint32_t  i;
+  ogg_uint32_t  i,j;
   ogg_uint32_t  KFIndicator = 0;
 
   /* Clear down the macro block level mode and MV arrays. */
@@ -334,7 +350,9 @@
   cpi->pb.FrameType = DELTA_FRAME;
 
   /* Clear down the difference arrays for the current frame. */
-  memset( cpi->pb.display_fragments, 0, cpi->pb.UnitFragments );
+  for(i=0;i<3;i++)
+    for(j=0;j<cpi->frag_n[i];j++)
+      cpi->frag[i][j].coded=0;
 
   {
     /*  pick all the macroblock modes and motion vectors */
@@ -342,8 +360,10 @@
     ogg_uint32_t IntraError;
     
     /* for now, mark all blocks to be coded... */
-    for(i=0;i<cpi->pb.UnitFragments;i++)
-      cpi->pb.display_fragments[i]=1;
+    /* TEMPORARY */
+    for(i=0;i<3;i++)
+      for(j=0;j<cpi->frag_n[i];j++)
+	cpi->frag[i][j].coded=1;
     
     /* Select modes and motion vectors for each of the blocks : return
        an error score for inter and intra */

Modified: branches/theora-thusnelda/lib/enc/frarray.c
===================================================================
--- branches/theora-thusnelda/lib/enc/frarray.c	2007-11-26 19:02:35 UTC (rev 14234)
+++ branches/theora-thusnelda/lib/enc/frarray.c	2007-11-27 02:06:56 UTC (rev 14235)
@@ -112,10 +112,9 @@
   unsigned char val;
   ogg_uint32_t  run_count;
 
-  ogg_uint32_t  SB, MB, B;   /* Block, MB and SB loop variables */
+  ogg_uint32_t  SB, B;
   ogg_uint32_t  BListIndex = 0;
   ogg_uint32_t  LastSbBIndex = 0;
-  ogg_int32_t   DfBlockIndex;  /* Block index in display_fragments */
 
   /* Initialise workspaces */
   memset( cpi->pb.SBFullyFlags, 1, cpi->pb.SuperBlocks);
@@ -129,36 +128,33 @@
 #endif
 
   for( SB = 0; SB < cpi->pb.SuperBlocks; SB++ ) {
-    /* Check for coded blocks and macro-blocks */
-    for ( MB=0; MB<4; MB++ ) {
-      /* If MB in frame */
-      if ( QuadMapToMBTopLeft(cpi->pb.BlockMap,SB,MB) >= 0 ) {
-        for ( B=0; B<4; B++ ) {
-          DfBlockIndex = QuadMapToIndex1( cpi->pb.BlockMap,SB, MB, B );
+    superblock_t *sp = &cpi->super[0][SB];
 
-          /* Does Block lie in frame: */
-          if ( DfBlockIndex >= 0 ) {
-            /* In Frame: If it is not coded then this SB is only
-               partly coded.: */
-            if ( cpi->pb.display_fragments[DfBlockIndex] ) {
-              cpi->pb.SBCodedFlags[SB] = 1; /* SB at least partly coded */
-              cpi->BlockCodedFlags[BListIndex] = 1; /* Block is coded */
-
+    /* Check for blocks and macro-blocks */
+    for ( B=0; B<16; B++ ) {
+      fragment_t *fp = sp->f[B];
+      
+      if ( fp ) {
+	/* In Frame: If it is not coded then this SB is only
+	   partly coded.: */
+	if ( fp->coded ) {
+	  cpi->pb.SBCodedFlags[SB] = 1; /* SB at least partly coded */
+	  cpi->BlockCodedFlags[BListIndex] = 1; /* Block is coded */
+	  
 #ifdef _TH_DEBUG_
-	      blockraster[DfBlockIndex]=1;
+	  blockraster[fp - cpi->frag[0]]=1;
 #endif	      
-
-            }else{
-              cpi->pb.SBFullyFlags[SB] = 0; /* SB not fully coded */
-              cpi->BlockCodedFlags[BListIndex] = 0; /* Block is not coded */
-            }
-
-            BListIndex++;
-          }
-        }
+	  
+	}else{
+	  cpi->pb.SBFullyFlags[SB] = 0; /* SB not fully coded */
+	  cpi->BlockCodedFlags[BListIndex] = 0; /* Block is not coded */
+	}
+	
+	BListIndex++;
+	
       }
     }
-
+    
     /* Is the SB fully coded or uncoded.
        If so then backup BListIndex and MBListIndex */
     if ( cpi->pb.SBFullyFlags[SB] || !cpi->pb.SBCodedFlags[SB] ) {

Modified: branches/theora-thusnelda/lib/enc/frinit.c
===================================================================
--- branches/theora-thusnelda/lib/enc/frinit.c	2007-11-26 19:02:35 UTC (rev 14234)
+++ branches/theora-thusnelda/lib/enc/frinit.c	2007-11-27 02:06:56 UTC (rev 14235)
@@ -87,7 +87,6 @@
 static void ClearFragmentInfo(PB_INSTANCE * pbi){
 
   /* free prior allocs if present */
-  if(pbi->display_fragments) _ogg_free(pbi->display_fragments);
   if(pbi->pixel_index_table) _ogg_free(pbi->pixel_index_table);
   if(pbi->recon_pixel_index_table) _ogg_free(pbi->recon_pixel_index_table);
   if(pbi->FragTokenCounts) _ogg_free(pbi->FragTokenCounts);
@@ -118,7 +117,6 @@
   pbi->TokenList = 0;
   pbi->FragCoeffs = 0;
   pbi->FragCoefEOB = 0;
-  pbi->display_fragments = 0;
   pbi->pixel_index_table = 0;
   pbi->recon_pixel_index_table = 0;
   pbi->FragTokenCounts = 0;
@@ -131,17 +129,6 @@
 
   pbi->SBCodedFlags = 0;
   pbi->SBFullyFlags = 0;
-  pbi->QFragData = 0;
-  pbi->TokenList = 0;
-  pbi->FragCoeffs = 0;
-  pbi->FragCoefEOB = 0;
-  pbi->display_fragments = 0;
-  pbi->pixel_index_table = 0;
-  pbi->recon_pixel_index_table = 0;
-  pbi->FragTokenCounts = 0;
-  pbi->CodedBlockList = 0;
-  pbi->FragCodingMethod = 0;
-  pbi->FragMVect = 0;
 }
 
 static void InitFragmentInfo(PB_INSTANCE * pbi){
@@ -150,9 +137,6 @@
   ClearFragmentInfo(pbi);
 
   /* Perform Fragment Allocations */
-  pbi->display_fragments =
-    _ogg_malloc(pbi->UnitFragments * sizeof(*pbi->display_fragments));
-
   pbi->pixel_index_table =
     _ogg_malloc(pbi->UnitFragments * sizeof(*pbi->pixel_index_table));
 

Modified: branches/theora-thusnelda/lib/enc/mcomp.c
===================================================================
--- branches/theora-thusnelda/lib/enc/mcomp.c	2007-11-26 19:02:35 UTC (rev 14234)
+++ branches/theora-thusnelda/lib/enc/mcomp.c	2007-11-27 02:06:56 UTC (rev 14235)
@@ -144,7 +144,9 @@
   return DiffVal;
 }
 
-ogg_uint32_t GetMBIntraError (CP_INSTANCE *cpi, ogg_uint32_t FragIndex,
+ogg_uint32_t GetMBIntraError (CP_INSTANCE *cpi, 
+			      fragment_t *fp,
+			      ogg_uint32_t FragIndex,
                               ogg_uint32_t PixelsPerLine ) {
   ogg_uint32_t  LocalFragIndex = FragIndex;
   ogg_uint32_t  IntraError = 0;
@@ -153,28 +155,34 @@
 
   /* Add together the intra errors for those blocks in the macro block
      that are coded (Y only) */
-  if ( cpi->pb.display_fragments[LocalFragIndex] )
+  if ( fp->coded )
     IntraError +=
       dsp_intra8x8_err (cpi->dsp, &cpi->
                     yuvptr[cpi->pb.pixel_index_table[LocalFragIndex]],
                     PixelsPerLine);
 
   LocalFragIndex++;
-  if ( cpi->pb.display_fragments[LocalFragIndex] )
+  fp++;
+
+  if ( fp->coded )
     IntraError +=
       dsp_intra8x8_err (cpi->dsp, &cpi->
                     yuvptr[cpi->pb.pixel_index_table[LocalFragIndex]],
                     PixelsPerLine);
 
   LocalFragIndex = FragIndex + cpi->pb.HFragments;
-  if ( cpi->pb.display_fragments[LocalFragIndex] )
+  fp += cpi->pb.HFragments-1;
+
+  if ( fp->coded )
     IntraError +=
       dsp_intra8x8_err (cpi->dsp, &cpi->
                      yuvptr[cpi->pb.pixel_index_table[LocalFragIndex]],
                     PixelsPerLine);
 
   LocalFragIndex++;
-  if ( cpi->pb.display_fragments[LocalFragIndex] )
+  fp++;
+
+  if ( fp->coded )
     IntraError +=
       dsp_intra8x8_err (cpi->dsp, &cpi->
                     yuvptr[cpi->pb.pixel_index_table[LocalFragIndex]],
@@ -188,7 +196,8 @@
 ogg_uint32_t GetMBInterError (CP_INSTANCE *cpi,
                               unsigned char * SrcPtr,
                               unsigned char * RefPtr,
-                              ogg_uint32_t FragIndex,
+			      fragment_t *fp,
+			      ogg_uint32_t FragIndex,
                               ogg_int32_t LastXMV,
                               ogg_int32_t LastYMV,
                               ogg_uint32_t PixelsPerLine ) {
@@ -231,7 +240,7 @@
 
   /* Add together the errors for those blocks in the macro block that
      are coded (Y only) */
-  if ( cpi->pb.display_fragments[LocalFragIndex] ) {
+  if ( fp->coded ) {
     SrcPtr1 = &SrcPtr[PixelIndex];
     RefPtr1 = &RefPtr[RefPixelIndex + RefPixelOffset];
     InterError += GetInterErr(cpi, SrcPtr1, RefPtr1,
@@ -239,7 +248,9 @@
   }
 
   LocalFragIndex++;
-  if ( cpi->pb.display_fragments[LocalFragIndex] ) {
+  fp++;
+
+  if ( fp->coded ) {
     PixelIndex = cpi->pb.pixel_index_table[LocalFragIndex];
     RefPixelIndex = cpi->pb.recon_pixel_index_table[LocalFragIndex];
     SrcPtr1 = &SrcPtr[PixelIndex];
@@ -250,7 +261,9 @@
   }
 
   LocalFragIndex = FragIndex + cpi->pb.HFragments;
-  if ( cpi->pb.display_fragments[LocalFragIndex] ) {
+  fp += cpi->pb.HFragments-1;
+
+  if ( fp->coded ) {
     PixelIndex = cpi->pb.pixel_index_table[LocalFragIndex];
     RefPixelIndex = cpi->pb.recon_pixel_index_table[LocalFragIndex];
     SrcPtr1 = &SrcPtr[PixelIndex];
@@ -260,7 +273,9 @@
   }
 
   LocalFragIndex++;
-  if ( cpi->pb.display_fragments[LocalFragIndex] ) {
+  fp++;
+
+  if ( fp->coded ) {
     PixelIndex = cpi->pb.pixel_index_table[LocalFragIndex];
     RefPixelIndex = cpi->pb.recon_pixel_index_table[LocalFragIndex];
     SrcPtr1 = &SrcPtr[PixelIndex];
@@ -276,6 +291,7 @@
 
 ogg_uint32_t GetMBMVInterError (CP_INSTANCE *cpi,
                                 unsigned char * RefFramePtr,
+				fragment_t *fp,
                                 ogg_uint32_t FragIndex,
                                 ogg_uint32_t PixelsPerLine,
                                 ogg_int32_t *MVPixelOffset,
@@ -309,14 +325,10 @@
 
   /* Note which of the four blocks in the macro block are to be
      included in the search. */
-  MBlockDispFrags[0] =
-    cpi->pb.display_fragments[FragIndex];
-  MBlockDispFrags[1] =
-    cpi->pb.display_fragments[FragIndex + 1];
-  MBlockDispFrags[2] =
-    cpi->pb.display_fragments[FragIndex + cpi->pb.HFragments];
-  MBlockDispFrags[3] =
-    cpi->pb.display_fragments[FragIndex + cpi->pb.HFragments + 1];
+  MBlockDispFrags[0] = fp[0].coded;
+  MBlockDispFrags[1] = fp[1].coded;
+  MBlockDispFrags[2] = fp[cpi->pb.HFragments].coded;
+  MBlockDispFrags[3] = fp[cpi->pb.HFragments + 1].coded;
 
   /* Set up the source pointers for the four source blocks.  */
   SrcPtr[0] = &cpi->yuvptr[cpi->pb.pixel_index_table[FragIndex]];
@@ -459,7 +471,7 @@
   MV->y += cpi->HalfPixelYOffset[BestHalfOffset];
 
   /* Get the error score for the chosen 1/2 pixel offset as a variance. */
-  InterMVError = GetMBInterError( cpi, cpi->yuvptr, RefFramePtr,
+  InterMVError = GetMBInterError( cpi, cpi->yuvptr, RefFramePtr, fp,
                                   FragIndex, MV->x, MV->y, PixelsPerLine );
 
   dsp_restore_fpu (cpi->dsp);
@@ -470,6 +482,7 @@
 
 ogg_uint32_t GetMBMVExhaustiveSearch (CP_INSTANCE *cpi,
                                       unsigned char * RefFramePtr,
+				      fragment_t *fp,
                                       ogg_uint32_t FragIndex,
                                       ogg_uint32_t PixelsPerLine,
                                       MOTION_VECTOR *MV ) {
@@ -500,14 +513,10 @@
 
   /* Note which of the four blocks in the macro block are to be
      included in the search. */
-  MBlockDispFrags[0] = cpi->
-    pb.display_fragments[FragIndex];
-  MBlockDispFrags[1] = cpi->
-    pb.display_fragments[FragIndex + 1];
-  MBlockDispFrags[2] = cpi->
-    pb.display_fragments[FragIndex + cpi->pb.HFragments];
-  MBlockDispFrags[3] = cpi->
-    pb.display_fragments[FragIndex + cpi->pb.HFragments + 1];
+  MBlockDispFrags[0] = fp[0].coded;
+  MBlockDispFrags[1] = fp[1].coded;
+  MBlockDispFrags[2] = fp[cpi->pb.HFragments].coded;
+  MBlockDispFrags[3] = fp[cpi->pb.HFragments + 1].coded;
 
   /* Set up the source pointers for the four source blocks. */
   SrcPtr[0] = &cpi->
@@ -619,7 +628,7 @@
   MV->y += cpi->HalfPixelYOffset[BestHalfOffset];
 
   /* Get the error score for the chosen 1/2 pixel offset as a variance. */
-  InterMVError = GetMBInterError( cpi, cpi->yuvptr, RefFramePtr,
+  InterMVError = GetMBInterError( cpi, cpi->yuvptr, RefFramePtr, fp,
                                   FragIndex, MV->x, MV->y, PixelsPerLine );
 
   dsp_restore_fpu (cpi->dsp);
@@ -722,6 +731,7 @@
 
 ogg_uint32_t GetFOURMVExhaustiveSearch (CP_INSTANCE *cpi,
                                         unsigned char * RefFramePtr,
+					fragment_t *fp,
                                         ogg_uint32_t FragIndex,
                                         ogg_uint32_t PixelsPerLine,
                                         MOTION_VECTOR *MV ) {
@@ -732,10 +742,10 @@
   /* For the moment the 4MV mode is only deemed to be valid 
      if all four Y blocks are to be updated */
   /* This may be adapted later. */
-  if ( cpi->pb.display_fragments[FragIndex] &&
-       cpi->pb.display_fragments[FragIndex + 1] &&
-       cpi->pb.display_fragments[FragIndex + cpi->pb.HFragments] &&
-       cpi->pb.display_fragments[FragIndex + cpi->pb.HFragments + 1] ) {
+  if ( fp[0].coded &&
+       fp[1].coded &&
+       fp[cpi->pb.HFragments].coded &&
+       fp[cpi->pb.HFragments + 1].coded ) {
 
     /* Reset the error score. */
     InterMVError = 0;



More information about the commits mailing list