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

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Tue Nov 27 10:27:40 PST 2007


Author: xiphmont
Date: 2007-11-27 10:27:40 -0800 (Tue, 27 Nov 2007)
New Revision: 14238

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/frinit.c
   branches/theora-thusnelda/lib/enc/mcomp.c
Log:
Continued refactoring of data structures



Modified: branches/theora-thusnelda/lib/enc/codec_internal.h
===================================================================
--- branches/theora-thusnelda/lib/enc/codec_internal.h	2007-11-27 13:40:03 UTC (rev 14237)
+++ branches/theora-thusnelda/lib/enc/codec_internal.h	2007-11-27 18:27:40 UTC (rev 14238)
@@ -160,24 +160,12 @@
 
   ogg_uint32_t  YPlaneSize;
   ogg_uint32_t  UVPlaneSize;
-  ogg_uint32_t  YStride;
-  ogg_uint32_t  UVStride;
   ogg_uint32_t  VFragments;
   ogg_uint32_t  HFragments;
   ogg_uint32_t  UnitFragments;
   ogg_uint32_t  YPlaneFragments;
   ogg_uint32_t  UVPlaneFragments;
 
-  ogg_uint32_t  ReconYPlaneSize;
-  ogg_uint32_t  ReconUVPlaneSize;
-
-  ogg_uint32_t  YDataOffset;
-  ogg_uint32_t  UDataOffset;
-  ogg_uint32_t  VDataOffset;
-  ogg_uint32_t  ReconYDataOffset;
-  ogg_uint32_t  ReconUDataOffset;
-  ogg_uint32_t  ReconVDataOffset;
-
   ogg_uint32_t  YSBRows;        /* Number of rows of SuperBlocks in a
                                    Y frame */
   ogg_uint32_t  YSBCols;        /* Number of cols of SuperBlocks in a
@@ -200,12 +188,6 @@
 
   /**********************************************************************/
   /* Fragment Information */
-  ogg_uint32_t  *pixel_index_table;        /* start address of first
-                                              pixel of fragment in
-                                              source */
-  ogg_uint32_t  *recon_pixel_index_table;  /* start address of first
-                                              pixel in recon buffer */
-
   int            CodedBlockIndex;
   fragment_t   **CodedBlockList;           
 
@@ -275,8 +257,6 @@
   /* how far do we shift the granulepos to seperate out P frame counts? */
   int             keyframe_granule_shift;
 
-
-
   /* Compressor Configuration */
   int              BaseQ;
   int              GoldenFrameEnabled;
@@ -342,6 +322,9 @@
   ogg_uint32_t      super_n[3];
   ogg_uint32_t      super_total;
 
+  ogg_uint32_t      recon_stride[3];
+  ogg_uint32_t      recon_offset[3];
+
   /* Coded flag arrays and counters for them */
   unsigned char    *PartiallyCodedFlags;
   unsigned char    *PartiallyCodedMbPatterns;
@@ -438,13 +421,11 @@
 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,
                                      ogg_uint32_t PixelsPerLine ) ;
@@ -452,20 +433,17 @@
 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 void EncodeData(CP_INSTANCE *cpi);
@@ -482,4 +460,7 @@
                                  ogg_uint32_t UVSuperBlocks,
                                  ogg_uint32_t HFrags, ogg_uint32_t VFrags );
 
+extern void ClearFragmentInfo (CP_INSTANCE *cpi);
+extern void ClearFrameInfo (CP_INSTANCE *cpi);
+
 #endif /* ENCODER_INTERNAL_H */

Modified: branches/theora-thusnelda/lib/enc/dct_decode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/dct_decode.c	2007-11-27 13:40:03 UTC (rev 14237)
+++ branches/theora-thusnelda/lib/enc/dct_decode.c	2007-11-27 18:27:40 UTC (rev 14238)
@@ -38,38 +38,15 @@
 
 static void ExpandBlock ( CP_INSTANCE *cpi, fragment_t *fp, ogg_int32_t FragmentNumber){
   PB_INSTANCE   *pbi = &cpi->pb;
-  ogg_uint32_t   ReconPixelsPerLine; /* Pixels per line */
-  ogg_int32_t    ReconPixelIndex;    /* Offset for block into a
-                                        reconstruction buffer */
-  ogg_int16_t    reconstruct[64];
-  ogg_int16_t  *quantizers;
-  ogg_int16_t   *data = fp->dct;
-
   int            mode = fp->mode;
   int            qi = cpi->BaseQ; // temporary 
-
-  /* Select the appropriate inverse Q matrix and line stride */
-  if ( FragmentNumber<pbi->YPlaneFragments ) {
-    ReconPixelsPerLine = pbi->YStride;
-    if ( mode == CODE_INTRA )
-      quantizers = pbi->quant_tables[0][0][qi];
-    else
-      quantizers = pbi->quant_tables[1][0][qi];
-
-  }else{
-    ReconPixelsPerLine = pbi->UVStride;
-    if ( mode == CODE_INTRA )
-      if ( FragmentNumber < pbi->YPlaneFragments + pbi->UVPlaneFragments )
-	quantizers = pbi->quant_tables[0][1][qi];
-      else
-	quantizers = pbi->quant_tables[0][2][qi];
-    else
-      if ( FragmentNumber < pbi->YPlaneFragments + pbi->UVPlaneFragments )
-	quantizers = pbi->quant_tables[1][1][qi];
-      else
-	quantizers = pbi->quant_tables[1][2][qi];
-  }
-
+  int            plane = (fp<cpi->frag[1] ? 0 : (fp<cpi->frag[2] ? 1 : 2));
+  ogg_uint32_t   ReconPixelsPerLine = cpi->recon_stride[plane];
+  int            inter = (mode != CODE_INTRA);
+  ogg_int16_t    reconstruct[64];
+  ogg_int16_t  *quantizers = pbi->quant_tables[inter][plane][qi];
+  ogg_int16_t   *data = fp->dct;
+  
 #ifdef _TH_DEBUG_
  {
    int i;
@@ -103,57 +80,37 @@
 #endif
 
   /* Convert fragment number to a pixel offset in a reconstruction buffer. */
-  ReconPixelIndex = pbi->recon_pixel_index_table[FragmentNumber];
-  dsp_recon8x8 (pbi->dsp, &pbi->ThisFrameRecon[ReconPixelIndex],
+  dsp_recon8x8 (pbi->dsp, &pbi->ThisFrameRecon[fp->recon_index],
 		reconstruct, ReconPixelsPerLine);
 
 }
 
-static void UpdateUMV_HBorders( PB_INSTANCE *pbi,
-                                unsigned char * DestReconPtr,
-                                ogg_uint32_t  PlaneFragOffset ) {
+static void UpdateUMV_HBorders( CP_INSTANCE *cpi,
+                                unsigned char *DestReconPtr,
+				int plane){
   ogg_uint32_t  i;
   ogg_uint32_t  PixelIndex;
 
-  ogg_uint32_t  PlaneStride;
-  ogg_uint32_t  BlockVStep;
-  ogg_uint32_t  PlaneFragments;
-  ogg_uint32_t  LineFragments;
-  ogg_uint32_t  PlaneBorderWidth;
+  ogg_uint32_t  PlaneStride = cpi->recon_stride[plane];
+  ogg_uint32_t  BlockVStep = cpi->recon_stride[plane] * (VFRAGPIXELS - 1);
+  ogg_uint32_t  PlaneFragments = cpi->frag_n[plane];
+  ogg_uint32_t  LineFragments = cpi->frag_h[plane];
+  ogg_uint32_t  PlaneBorderWidth = (plane ? UMV_BORDER / 2 : UMV_BORDER );
 
   unsigned char   *SrcPtr1;
   unsigned char   *SrcPtr2;
   unsigned char   *DestPtr1;
   unsigned char   *DestPtr2;
+  
+  fragment_t      *fp = cpi->frag[plane];
 
-  /* Work out various plane specific values */
-  if ( PlaneFragOffset == 0 ) {
-    /* Y Plane */
-    BlockVStep = (pbi->YStride *
-                  (VFRAGPIXELS - 1));
-    PlaneStride = pbi->YStride;
-    PlaneBorderWidth = UMV_BORDER;
-    PlaneFragments = pbi->YPlaneFragments;
-    LineFragments = pbi->HFragments;
-  }else{
-    /* U or V plane. */
-    BlockVStep = (pbi->UVStride *
-                  (VFRAGPIXELS - 1));
-    PlaneStride = pbi->UVStride;
-    PlaneBorderWidth = UMV_BORDER / 2;
-    PlaneFragments = pbi->UVPlaneFragments;
-    LineFragments = pbi->HFragments / 2;
-  }
-
   /* Setup the source and destination pointers for the top and bottom
      borders */
-  PixelIndex = pbi->recon_pixel_index_table[PlaneFragOffset];
+  PixelIndex = fp[0].recon_index;
   SrcPtr1 = &DestReconPtr[ PixelIndex - PlaneBorderWidth ];
   DestPtr1 = SrcPtr1 - (PlaneBorderWidth * PlaneStride);
 
-  PixelIndex = pbi->recon_pixel_index_table[PlaneFragOffset +
-                                           PlaneFragments - LineFragments] +
-    BlockVStep;
+  PixelIndex = fp[PlaneFragments - LineFragments].recon_index + BlockVStep;
   SrcPtr2 = &DestReconPtr[ PixelIndex - PlaneBorderWidth];
   DestPtr2 = SrcPtr2 + PlaneStride;
 
@@ -169,45 +126,29 @@
 
 static void UpdateUMV_VBorders( CP_INSTANCE *cpi,
                                 unsigned char * DestReconPtr,
-                                ogg_uint32_t  PlaneFragOffset ){
-  PB_INSTANCE   *pbi = &cpi->pb;
+                                int plane){
   ogg_uint32_t   i;
   ogg_uint32_t   PixelIndex;
 
-  ogg_uint32_t   PlaneStride;
-  ogg_uint32_t   LineFragments;
-  ogg_uint32_t   PlaneBorderWidth;
-  ogg_uint32_t   PlaneHeight;
+  ogg_uint32_t   PlaneStride = cpi->recon_stride[plane];
+  ogg_uint32_t   LineFragments = cpi->frag_h[plane];
+  ogg_uint32_t   PlaneBorderWidth = (plane ? UMV_BORDER / 2 : UMV_BORDER );
+  ogg_uint32_t   PlaneHeight = (plane ? cpi->info.height/2 : cpi->info.height );
 
   unsigned char   *SrcPtr1;
   unsigned char   *SrcPtr2;
   unsigned char   *DestPtr1;
   unsigned char   *DestPtr2;
 
-  /* Work out various plane specific values */
-  if ( PlaneFragOffset == 0 ) {
-    /* Y Plane */
-    PlaneStride = pbi->YStride;
-    PlaneBorderWidth = UMV_BORDER;
-    LineFragments = pbi->HFragments;
-    PlaneHeight = cpi->info.height;
-  }else{
-    /* U or V plane. */
-    PlaneStride = pbi->UVStride;
-    PlaneBorderWidth = UMV_BORDER / 2;
-    LineFragments = pbi->HFragments / 2;
-    PlaneHeight = cpi->info.height / 2;
-  }
+  fragment_t      *fp = cpi->frag[plane];
 
   /* Setup the source data values and destination pointers for the
      left and right edge borders */
-  PixelIndex = pbi->recon_pixel_index_table[PlaneFragOffset];
+  PixelIndex = fp[0].recon_index;
   SrcPtr1 = &DestReconPtr[ PixelIndex ];
   DestPtr1 = &DestReconPtr[ PixelIndex - PlaneBorderWidth ];
 
-  PixelIndex = pbi->recon_pixel_index_table[PlaneFragOffset +
-                                           LineFragments - 1] +
-    (HFRAGPIXELS - 1);
+  PixelIndex = fp[LineFragments - 1].recon_index + (HFRAGPIXELS - 1);
   SrcPtr2 = &DestReconPtr[ PixelIndex ];
   DestPtr2 = &DestReconPtr[ PixelIndex + 1 ];
 
@@ -225,133 +166,59 @@
 
 void UpdateUMVBorder( CP_INSTANCE *cpi,
                       unsigned char * DestReconPtr ) {
-  ogg_uint32_t  PlaneFragOffset;
-  PB_INSTANCE   *pbi = &cpi->pb;
-
   /* Y plane */
-  PlaneFragOffset = 0;
-  UpdateUMV_VBorders( cpi, DestReconPtr, PlaneFragOffset );
-  UpdateUMV_HBorders( pbi, DestReconPtr, PlaneFragOffset );
+  UpdateUMV_VBorders( cpi, DestReconPtr, 0);
+  UpdateUMV_HBorders( cpi, DestReconPtr, 0);
 
   /* Then the U and V Planes */
-  PlaneFragOffset = pbi->YPlaneFragments;
-  UpdateUMV_VBorders( cpi, DestReconPtr, PlaneFragOffset );
-  UpdateUMV_HBorders( pbi, DestReconPtr, PlaneFragOffset );
+  UpdateUMV_VBorders( cpi, DestReconPtr, 1);
+  UpdateUMV_HBorders( cpi, DestReconPtr, 1);
 
-  PlaneFragOffset = pbi->YPlaneFragments + pbi->UVPlaneFragments;
-  UpdateUMV_VBorders( cpi, DestReconPtr, PlaneFragOffset );
-  UpdateUMV_HBorders( pbi, DestReconPtr, PlaneFragOffset );
+  UpdateUMV_VBorders( cpi, DestReconPtr, 2);
+  UpdateUMV_HBorders( cpi, DestReconPtr, 2);
 }
 
 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;
-
+		       unsigned char * SrcReconPtr ) {
+  ogg_uint32_t  i,plane;
+  fragment_t *fp = cpi->frag[0];
+  
   /* Copy over only updated blocks.*/
-
-  /* First Y plane */
-  fp = cpi->frag[0];
-  PlaneLineStep = pbi->YStride;
-  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 ];
-
-      dsp_copy8x8 (pbi->dsp, SrcPtr, DestPtr, PlaneLineStep);
+  for(plane=0;plane<3;plane++){  
+    int PlaneLineStep = cpi->recon_stride[plane];
+    for ( i = 0; i < cpi->frag_n[plane]; i++,fp++ ) {
+      if ( fp->coded ) {
+	int pi= fp->recon_index;
+	unsigned char *src = &SrcReconPtr[ pi ];
+	unsigned char *dst = &DestReconPtr[ pi ];
+	dsp_copy8x8 (cpi->pb.dsp, src, dst, PlaneLineStep);
+      }
     }
   }
-
-  /* Then U and V */
-  fp = cpi->frag[1];
-  PlaneLineStep = pbi->UVStride;
-  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 ];
-
-      dsp_copy8x8 (pbi->dsp, SrcPtr, DestPtr, PlaneLineStep);
-
-    }
-  }
-
-  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( 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;
-
+			  unsigned char * SrcReconPtr ) {
+  ogg_uint32_t  i,plane;
+  fragment_t *fp = cpi->frag[0];
+  
   /* Copy over only updated blocks.*/
-
-  /* First Y plane */
-  fp = cpi->frag[0];
-  PlaneLineStep = pbi->YStride;
-  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 ];
-
-      dsp_copy8x8 (pbi->dsp, SrcPtr, DestPtr, PlaneLineStep);
+  for(plane=0;plane<3;plane++){  
+    int PlaneLineStep = cpi->recon_stride[plane];
+    for ( i = 0; i < cpi->frag_n[plane]; i++,fp++ ) {
+      if ( !fp->coded ) {
+	int pi= fp->recon_index;
+	unsigned char *src = &SrcReconPtr[ pi ];
+	unsigned char *dst = &DestReconPtr[ pi ];
+	dsp_copy8x8 (cpi->pb.dsp, src, dst, PlaneLineStep);
+      }
     }
   }
-
-  /* Then U and V */
-  fp = cpi->frag[1];
-  PlaneLineStep = pbi->UVStride;
-  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 ];
-
-      dsp_copy8x8 (pbi->dsp, SrcPtr, DestPtr, PlaneLineStep);
-
-    }
-  }
-
-  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,
-                        ogg_int32_t LineLength,
-                        ogg_int16_t *BoundingValuePtr){
+			   ogg_int32_t LineLength,
+			   ogg_int16_t *BoundingValuePtr){
   ogg_int32_t j;
   ogg_int32_t FiltVal;
 
@@ -398,56 +265,20 @@
 
 static void LoopFilter(CP_INSTANCE *cpi){
   PB_INSTANCE   *pbi = &cpi->pb;
-  ogg_int32_t i;
 
-  ogg_int16_t * BoundingValuePtr=pbi->FiltBoundingValue+127;
-  int FragsAcross=pbi->HFragments;
-  int FromFragment,ToFragment;
-  int FragsDown = pbi->VFragments;
-  ogg_int32_t LineFragments;
-  ogg_int32_t LineLength;
-  ogg_int32_t FLimit;
+  ogg_int16_t *BoundingValuePtr=pbi->FiltBoundingValue+127;
+  ogg_int32_t FLimit = cpi->pb.quant_info.loop_filter_limits[cpi->BaseQ]; // temp
   int j,m,n;
   fragment_t *fp;
 
-  FLimit = cpi->pb.quant_info.loop_filter_limits[cpi->BaseQ]; // temp
   if ( FLimit == 0 ) return;
   SetupBoundingValueArray_Generic(pbi, FLimit);
 
   for ( j = 0; j < 3 ; j++){
-    switch(j) {
-    case 0: /* y */
-      fp = cpi->frag[0];
-      FromFragment = 0;
-      ToFragment = pbi->YPlaneFragments;
-      FragsAcross = pbi->HFragments;
-      FragsDown = pbi->VFragments;
-      LineLength = pbi->YStride;
-      LineFragments = pbi->HFragments;
-      break;
-    case 1: /* u */
-      fp = cpi->frag[1];
-      FromFragment = pbi->YPlaneFragments;
-      ToFragment = pbi->YPlaneFragments + pbi->UVPlaneFragments ;
-      FragsAcross = pbi->HFragments >> 1;
-      FragsDown = pbi->VFragments >> 1;
-      LineLength = pbi->UVStride;
-      LineFragments = pbi->HFragments / 2;
-      break;
-    /*case 2:  v */
-    default:
-      fp = cpi->frag[2];
-      FromFragment = pbi->YPlaneFragments + pbi->UVPlaneFragments;
-      ToFragment = pbi->YPlaneFragments + (2 * pbi->UVPlaneFragments) ;
-      FragsAcross = pbi->HFragments >> 1;
-      FragsDown = pbi->VFragments >> 1;
-      LineLength = pbi->UVStride;
-      LineFragments = pbi->HFragments / 2;
-      break;
-    }
+    ogg_int32_t LineFragments = cpi->frag_h[j];
+    ogg_int32_t LineLength = cpi->recon_stride[j];
+    fp = cpi->frag[j];
 
-    i=FromFragment;
-
     /**************************************************************
      First Row
     **************************************************************/
@@ -459,44 +290,43 @@
          not coded */
       if ( !fp[1].coded ){
         dsp_FilterHoriz(pbi->dsp,pbi->LastFrameRecon+
-                    pbi->recon_pixel_index_table[i]+6,
-                    LineLength,BoundingValuePtr);
+			fp[0].recon_index+6,
+			LineLength,BoundingValuePtr);
       }
 
       /* Bottom done if next row set */
       if( !fp[LineFragments].coded ){
         dsp_FilterVert(pbi->dsp,pbi->LastFrameRecon+
-                   pbi->recon_pixel_index_table[i+LineFragments],
-                   LineLength, BoundingValuePtr);
+		       fp[LineFragments].recon_index,
+		       LineLength, BoundingValuePtr);
       }
     }
-    i++;
     fp++;
 
     /***************************************************************/
     /* middle columns  */
-    for ( n = 1 ; n < FragsAcross - 1 ; n++, i++, fp++) {
+    for ( n = 1 ; n < cpi->frag_h[j] - 1 ; n++, fp++) {
       if( fp->coded){
         /* Filter Left edge always */
         dsp_FilterHoriz(pbi->dsp,pbi->LastFrameRecon+
-                    pbi->recon_pixel_index_table[i]-2,
-                    LineLength, BoundingValuePtr);
+			fp[0].recon_index-2,
+			LineLength, BoundingValuePtr);
 
         /* Filter right hand border only if the block to the right is
            not coded */
         if ( !fp[1].coded ){
           dsp_FilterHoriz(pbi->dsp,pbi->LastFrameRecon+
-                      pbi->recon_pixel_index_table[i]+6,
-                      LineLength, BoundingValuePtr);
+			  fp[0].recon_index+6,
+			  LineLength, BoundingValuePtr);
         }
 
         /* Bottom done if next row set */
         if( !fp[LineFragments].coded ){
           dsp_FilterVert(pbi->dsp,pbi->LastFrameRecon+
-                     pbi->recon_pixel_index_table[i + LineFragments],
-                     LineLength, BoundingValuePtr);
+			 fp[LineFragments].recon_index,
+			 LineLength, BoundingValuePtr);
         }
-
+	
       }
     }
 
@@ -505,23 +335,22 @@
     if(fp->coded){
       /* Filter Left edge always */
       dsp_FilterHoriz(pbi->dsp,pbi->LastFrameRecon+
-                  pbi->recon_pixel_index_table[i] - 2 ,
-                  LineLength, BoundingValuePtr);
-
+		      fp[0].recon_index - 2 ,
+		      LineLength, BoundingValuePtr);
+      
       /* Bottom done if next row set */
       if( !fp[LineFragments].coded ){
         dsp_FilterVert(pbi->dsp,pbi->LastFrameRecon+
-                   pbi->recon_pixel_index_table[i + LineFragments],
-                   LineLength, BoundingValuePtr);
+		       fp[LineFragments].recon_index,
+		       LineLength, BoundingValuePtr);
       }
     }
-    i++;
     fp++;
 
     /***************************************************************/
     /* Middle Rows */
     /***************************************************************/
-    for ( m = 1 ; m < FragsDown-1 ; m++) {
+    for ( m = 1 ; m < cpi->frag_v[j]-1 ; m++) {
 
       /*****************************************************************/
       /* first column conditions */
@@ -530,54 +359,53 @@
       if( fp->coded){
         /* TopRow is always done */
         dsp_FilterVert(pbi->dsp,pbi->LastFrameRecon+
-                   pbi->recon_pixel_index_table[i],
-                   LineLength, BoundingValuePtr);
+		       fp[0].recon_index,
+		       LineLength, BoundingValuePtr);
 
         /* Filter right hand border only if the block to the right is
            not coded */
         if ( !fp[1].coded ){
           dsp_FilterHoriz(pbi->dsp,pbi->LastFrameRecon+
-                      pbi->recon_pixel_index_table[i] + 6,
-                      LineLength, BoundingValuePtr);
+			  fp[0].recon_index + 6,
+			  LineLength, BoundingValuePtr);
         }
-
+	
         /* Bottom done if next row set */
         if( !fp[LineFragments].coded ){
           dsp_FilterVert(pbi->dsp,pbi->LastFrameRecon+
-                     pbi->recon_pixel_index_table[i + LineFragments],
-                     LineLength, BoundingValuePtr);
+			 fp[LineFragments].recon_index,
+			 LineLength, BoundingValuePtr);
         }
       }
-      i++;
       fp++;
 
       /*****************************************************************/
       /* middle columns  */
-      for ( n = 1 ; n < FragsAcross - 1 ; n++, i++, fp++){
+      for ( n = 1 ; n < cpi->frag_h[j] - 1 ; n++, fp++){
         if( fp->coded){
           /* Filter Left edge always */
           dsp_FilterHoriz(pbi->dsp,pbi->LastFrameRecon+
-                      pbi->recon_pixel_index_table[i] - 2,
-                      LineLength, BoundingValuePtr);
+			  fp[0].recon_index - 2,
+			  LineLength, BoundingValuePtr);
 
           /* TopRow is always done */
           dsp_FilterVert(pbi->dsp,pbi->LastFrameRecon+
-                     pbi->recon_pixel_index_table[i],
-                     LineLength, BoundingValuePtr);
-
+			 fp[0].recon_index,
+			 LineLength, BoundingValuePtr);
+	  
           /* Filter right hand border only if the block to the right
              is not coded */
           if ( !fp[1].coded ){
             dsp_FilterHoriz(pbi->dsp,pbi->LastFrameRecon+
-                        pbi->recon_pixel_index_table[i] + 6,
-                        LineLength, BoundingValuePtr);
+			    fp[0].recon_index + 6,
+			    LineLength, BoundingValuePtr);
           }
 
           /* Bottom done if next row set */
           if( !fp[LineFragments].coded ){
             dsp_FilterVert(pbi->dsp,pbi->LastFrameRecon+
-                       pbi->recon_pixel_index_table[i + LineFragments],
-                       LineLength, BoundingValuePtr);
+			   fp[LineFragments].recon_index,
+			   LineLength, BoundingValuePtr);
           }
         }
       }
@@ -587,22 +415,21 @@
       if(fp->coded){
         /* Filter Left edge always*/
         dsp_FilterHoriz(pbi->dsp,pbi->LastFrameRecon+
-                    pbi->recon_pixel_index_table[i] - 2,
-                    LineLength, BoundingValuePtr);
+			fp[0].recon_index - 2,
+			LineLength, BoundingValuePtr);
 
         /* TopRow is always done */
         dsp_FilterVert(pbi->dsp,pbi->LastFrameRecon+
-                   pbi->recon_pixel_index_table[i],
-                   LineLength, BoundingValuePtr);
-
+		       fp[0].recon_index,		       
+		       LineLength, BoundingValuePtr);
+	
         /* Bottom done if next row set */
         if( !fp[LineFragments].coded ){
           dsp_FilterVert(pbi->dsp,pbi->LastFrameRecon+
-                     pbi->recon_pixel_index_table[i + LineFragments],
-                     LineLength, BoundingValuePtr);
+			 fp[LineFragments].recon_index,
+			 LineLength, BoundingValuePtr);
         }
       }
-      i++;
       fp++;
     }
 
@@ -616,40 +443,39 @@
 
       /* TopRow is always done */
       dsp_FilterVert(pbi->dsp,pbi->LastFrameRecon+
-                 pbi->recon_pixel_index_table[i],
-                 LineLength, BoundingValuePtr);
+		     fp[0].recon_index,
+		     LineLength, BoundingValuePtr);
 
       /* Filter right hand border only if the block to the right is
          not coded */
       if ( !fp[1].coded ){
         dsp_FilterHoriz(pbi->dsp,pbi->LastFrameRecon+
-                    pbi->recon_pixel_index_table[i] + 6,
-                    LineLength, BoundingValuePtr);
+			fp[0].recon_index + 6,
+			LineLength, BoundingValuePtr);
       }
     }
-    i++;
     fp++;
 
     /******************************************************************/
     /* middle columns  */
-    for ( n = 1 ; n < FragsAcross - 1 ; n++, i++, fp++){
+    for ( n = 1 ; n < cpi->frag_h[j] - 1 ; n++, fp++){
       if( fp->coded){
         /* Filter Left edge always */
         dsp_FilterHoriz(pbi->dsp,pbi->LastFrameRecon+
-                    pbi->recon_pixel_index_table[i] - 2,
-                    LineLength, BoundingValuePtr);
-
+			fp[0].recon_index - 2,
+			LineLength, BoundingValuePtr);
+	
         /* TopRow is always done */
         dsp_FilterVert(pbi->dsp,pbi->LastFrameRecon+
-                   pbi->recon_pixel_index_table[i],
-                   LineLength, BoundingValuePtr);
+		       fp[0].recon_index,
+		       LineLength, BoundingValuePtr);
 
         /* Filter right hand border only if the block to the right is
            not coded */
         if ( !fp[1].coded ){
           dsp_FilterHoriz(pbi->dsp,pbi->LastFrameRecon+
-                      pbi->recon_pixel_index_table[i] + 6,
-                      LineLength, BoundingValuePtr);
+			  fp[0].recon_index + 6,
+			  LineLength, BoundingValuePtr);
         }
       }
     }
@@ -659,16 +485,15 @@
     if( fp->coded){
       /* Filter Left edge always */
       dsp_FilterHoriz(pbi->dsp,pbi->LastFrameRecon+
-                  pbi->recon_pixel_index_table[i] - 2,
-                  LineLength, BoundingValuePtr);
+		      fp[0].recon_index - 2,
+		      LineLength, BoundingValuePtr);
 
       /* TopRow is always done */
       dsp_FilterVert(pbi->dsp,pbi->LastFrameRecon+
-                 pbi->recon_pixel_index_table[i],
-                 LineLength, BoundingValuePtr);
-
+		     fp[0].recon_index,
+		     LineLength, BoundingValuePtr);
+      
     }
-    i++;
     fp++;
   }
 }
@@ -771,7 +596,7 @@
 	  /* and the loop filter output, which is a flat struct */
 	  TH_DEBUG("recon %s [%d][%d] = {",plstr,x,y);
 	  for(j=0;j<8;j++){
-	    int l = pbi->recon_pixel_index_table[i] + j*stride;
+	    int l = cpi->frag[0][i].recon_index + j*stride;
 	    TH_DEBUG("\n   ");
 	    for(k=0;k<8;k++,l++)
 	      TH_DEBUG("%d ", pbi->LastFrameRecon[l]);

Modified: branches/theora-thusnelda/lib/enc/dct_encode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/dct_encode.c	2007-11-27 13:40:03 UTC (rev 14237)
+++ branches/theora-thusnelda/lib/enc/dct_encode.c	2007-11-27 18:27:40 UTC (rev 14238)
@@ -253,6 +253,7 @@
 				   ogg_int16_t *DctInputPtr, 
 				   unsigned char *thisrecon,
 				   ogg_int32_t MvDevisor,
+				   fragment_t *fp,
 				   ogg_uint32_t FragIndex,
 				   ogg_uint32_t PixelsPerLine,
 				   ogg_uint32_t ReconPixelsPerLine,
@@ -313,11 +314,9 @@
     }
     
     if ( mode==CODE_GOLDEN_MV ) {
-      ReconPtr1 = &cpi->
-	pb.GoldenFrame[cpi->pb.recon_pixel_index_table[FragIndex]];
+      ReconPtr1 = &cpi->pb.GoldenFrame[fp->recon_index];
     } else {
-      ReconPtr1 = &cpi->
-	pb.LastFrameRecon[cpi->pb.recon_pixel_index_table[FragIndex]];
+      ReconPtr1 = &cpi->pb.LastFrameRecon[fp->recon_index];
     }
     
     ReconPtr1 += MVOffset;
@@ -342,11 +341,9 @@
     if ( ( mode==CODE_INTER_NO_MV ) ||
 	 ( mode==CODE_USING_GOLDEN ) ) {
       if ( mode==CODE_INTER_NO_MV ) {
-	ReconPtr1 = &cpi->
-	  pb.LastFrameRecon[cpi->pb.recon_pixel_index_table[FragIndex]];
+	ReconPtr1 = &cpi->pb.LastFrameRecon[fp->recon_index];
       } else {
-	ReconPtr1 = &cpi->
-	  pb.GoldenFrame[cpi->pb.recon_pixel_index_table[FragIndex]];
+	ReconPtr1 = &cpi->pb.GoldenFrame[fp->recon_index];
       }
       
       dsp_sub8x8(cpi->dsp, FiltPtr, ReconPtr1, DctInputPtr,
@@ -363,25 +360,22 @@
 			     fragment_t *fp,
 			     ogg_int32_t FragIndex,
                              ogg_uint32_t PixelsPerLine) {
-  unsigned char *FiltPtr = &cpi->yuvptr[cpi->pb.pixel_index_table[FragIndex]];
+  unsigned char *FiltPtr = &cpi->yuvptr[fp->raw_index];
   int qi = cpi->BaseQ; // temporary
   int inter = (fp->mode != CODE_INTRA);
   int plane = (fp < cpi->frag[1] ? 0 : (fp < cpi->frag[2] ? 1 : 2)); 
   ogg_int32_t *q = cpi->pb.iquant_tables[inter][plane][qi];
   ogg_int16_t DCTInput[64];
   ogg_int16_t DCTOutput[64];
-  ogg_uint32_t  ReconPixelsPerLine; /* Line length for recon buffers. */
-
+  ogg_uint32_t ReconPixelsPerLine = cpi->recon_stride[plane];
   ogg_int32_t   MvDivisor;      /* Defines MV resolution (2 = 1/2
                                    pixel for Y or 4 = 1/4 for UV) */
-  unsigned char   *ReconPtr1 = &cpi->pb.ThisFrameRecon[cpi->pb.recon_pixel_index_table[FragIndex]];
+  unsigned char   *ReconPtr1 = &cpi->pb.ThisFrameRecon[fp->recon_index];
 
   /* Set plane specific values */
   if (plane == 0){
-    ReconPixelsPerLine = cpi->pb.YStride;
     MvDivisor = 2;                  /* 1/2 pixel accuracy in Y */
   }else{
-    ReconPixelsPerLine = cpi->pb.UVStride;
     MvDivisor = 4;                  /* UV planes at 1/2 resolution of Y */
   }
 
@@ -389,7 +383,7 @@
      the reconstruction buffer, and proces a difference block for
      forward DCT */
   BlockUpdateDifference(cpi, FiltPtr, DCTInput, ReconPtr1,
-			MvDivisor, FragIndex, PixelsPerLine,
+			MvDivisor, fp, FragIndex, PixelsPerLine,
 			ReconPixelsPerLine, fp->mode);
   
   /* Proceed to encode the data into the encode buffer if the encoder

Modified: branches/theora-thusnelda/lib/enc/encode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/encode.c	2007-11-27 13:40:03 UTC (rev 14237)
+++ branches/theora-thusnelda/lib/enc/encode.c	2007-11-27 18:27:40 UTC (rev 14238)
@@ -1011,14 +1011,13 @@
         /* Look at the intra coding error. */
         MBIntraError = GetMBIntraError( cpi, 
 					&cpi->frag[0][YFragIndex],
-					YFragIndex, PixelsPerLine );
+					PixelsPerLine );
         BestError = (BestError > MBIntraError) ? MBIntraError : BestError;
 
         /* Get the golden frame error */
         MBGFError = GetMBInterError( cpi, cpi->yuvptr,
                                      cpi->pb.GoldenFrame, 
 				     &cpi->frag[0][YFragIndex],
-				     YFragIndex,
                                      0, 0, PixelsPerLine );
         BestError = (BestError > MBGFError) ? MBGFError : BestError;
 
@@ -1026,14 +1025,14 @@
         MBInterError = GetMBInterError( cpi, cpi->yuvptr,
                                         cpi->pb.LastFrameRecon,
 					&cpi->frag[0][YFragIndex],
-                                        YFragIndex, 0, 0, PixelsPerLine );
+                                        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.x,
                                              LastInterMVect.y, PixelsPerLine );
         BestError = (BestError > MBLastInterError) ?
           MBLastInterError : BestError;
@@ -1042,7 +1041,6 @@
         MBPriorLastInterError =  GetMBInterError( cpi, cpi->yuvptr,
                                                   cpi->pb.LastFrameRecon,
 						  &cpi->frag[0][YFragIndex],
-                                                  YFragIndex,
                                                   PriorLastInterMVect.x,
                                                   PriorLastInterMVect.y,
                                                   PixelsPerLine );
@@ -1062,7 +1060,6 @@
           if ( cpi->info.quick_p ) {
             MBInterMVError = GetMBMVInterError( cpi, cpi->pb.LastFrameRecon,
 						&cpi->frag[0][YFragIndex],
-                                                YFragIndex, 
 						PixelsPerLine,
                                                 cpi->MVPixelOffsetY,
                                                 &InterMVect );
@@ -1075,7 +1072,7 @@
               MBInterMVExError =
                 GetMBMVExhaustiveSearch( cpi, cpi->pb.LastFrameRecon,
 					 &cpi->frag[0][YFragIndex],
-                                         YFragIndex, PixelsPerLine,
+                                         PixelsPerLine,
                                          &InterMVectEx );
 
               /* Is the Variance measure for the EX search
@@ -1091,7 +1088,7 @@
             MBInterMVError =
               GetMBMVExhaustiveSearch( cpi, cpi->pb.LastFrameRecon,
 				       &cpi->frag[0][YFragIndex],
-                                       YFragIndex, PixelsPerLine,
+                                       PixelsPerLine,
                                        &InterMVect );
           }
 
@@ -1113,14 +1110,14 @@
           /* Do an MV search in the golden reference frame */
           MBGF_MVError = GetMBMVInterError( cpi, cpi->pb.GoldenFrame,
 					    &cpi->frag[0][YFragIndex],
-                                            YFragIndex, PixelsPerLine,
+                                            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.x,
                                                LastGFMVect.y, PixelsPerLine );
 
           /* Check against last GF motion vector and reset if the
@@ -1149,7 +1146,7 @@
           MBInterFOURMVError =
             GetFOURMVExhaustiveSearch( cpi, cpi->pb.LastFrameRecon,
 				       &cpi->frag[0][YFragIndex],
-                                       YFragIndex, PixelsPerLine, FourMVect );
+                                       PixelsPerLine, FourMVect );
 
           /* If the improvement is great enough then use the four MV mode */
           if ( ((MBInterFOURMVError + cpi->MinImprovementForFourMV) <

Modified: branches/theora-thusnelda/lib/enc/encoder_toplevel.c
===================================================================
--- branches/theora-thusnelda/lib/enc/encoder_toplevel.c	2007-11-27 13:40:03 UTC (rev 14237)
+++ branches/theora-thusnelda/lib/enc/encoder_toplevel.c	2007-11-27 18:27:40 UTC (rev 14238)
@@ -31,244 +31,6 @@
 long dframe=0;
 #endif
 
-static void EClearFragmentInfo(CP_INSTANCE * cpi){
-  if(cpi->RunHuffIndices)
-    _ogg_free(cpi->RunHuffIndices);
-  if(cpi->ModeList)
-    _ogg_free(cpi->ModeList);
-  if(cpi->MVList)
-    _ogg_free(cpi->MVList);
-  if(cpi->PartiallyCodedFlags)
-    _ogg_free(cpi->PartiallyCodedFlags);
-  if(cpi->PartiallyCodedMbPatterns)
-    _ogg_free(cpi->PartiallyCodedMbPatterns);
-  if(cpi->BlockCodedFlags)
-    _ogg_free(cpi->BlockCodedFlags);
-
-  cpi->RunHuffIndices = 0;
-  cpi->ModeList = 0;
-  cpi->MVList = 0;
-  cpi->PartiallyCodedFlags = 0;
-  cpi->PartiallyCodedMbPatterns = 0;
-  cpi->BlockCodedFlags = 0;
-}
-
-static void EInitFragmentInfo(CP_INSTANCE * cpi){
-
-  /* clear any existing info */
-  EClearFragmentInfo(cpi);
-
-  /* A note to people reading and wondering why malloc returns aren't
-     checked:
-
-     lines like the following that implement a general strategy of
-     'check the return of malloc; a zero pointer means we're out of
-     memory!'...:
-
-  if(!cpi->extra_fragments) { EDeleteFragmentInfo(cpi); return FALSE; }
-
-     ...are not useful.  It's true that many platforms follow this
-     malloc behavior, but many do not.  The more modern malloc
-     strategy is only to allocate virtual pages, which are not mapped
-     until the memory on that page is touched.  At *that* point, if
-     the machine is out of heap, the page fails to be mapped and a
-     SEGV is generated.
-
-     That means that if we want to deal with out of memory conditions,
-     we *must* be prepared to process a SEGV.  If we implement the
-     SEGV handler, there's no reason to to check malloc return; it is
-     a waste of code. */
-
-  cpi->RunHuffIndices =
-    _ogg_malloc(cpi->pb.UnitFragments*
-                sizeof(*cpi->RunHuffIndices));
-  cpi->BlockCodedFlags =
-    _ogg_malloc(cpi->pb.UnitFragments*
-                sizeof(*cpi->BlockCodedFlags));
-  cpi->ModeList =
-    _ogg_malloc(cpi->pb.UnitFragments*
-                sizeof(*cpi->ModeList));
-  cpi->MVList =
-    _ogg_malloc(cpi->pb.UnitFragments*
-                sizeof(*cpi->MVList));
-  cpi->PartiallyCodedFlags =
-    _ogg_malloc(cpi->pb.MacroBlocks*
-                sizeof(*cpi->PartiallyCodedFlags));
-  cpi->PartiallyCodedMbPatterns =
-    _ogg_malloc(cpi->pb.MacroBlocks*
-                sizeof(*cpi->PartiallyCodedMbPatterns));
-
-}
-
-static void EClearFrameInfo(CP_INSTANCE * cpi) {
-
-  if(cpi->yuvptr)
-    _ogg_free(cpi->yuvptr);
-  cpi->yuvptr = 0;
-
-  if(cpi->OptimisedTokenListEb )
-    _ogg_free(cpi->OptimisedTokenListEb);
-  cpi->OptimisedTokenListEb = 0;
-
-  if(cpi->OptimisedTokenList )
-    _ogg_free(cpi->OptimisedTokenList);
-  cpi->OptimisedTokenList = 0;
-
-  if(cpi->OptimisedTokenListHi )
-    _ogg_free(cpi->OptimisedTokenListHi);
-  cpi->OptimisedTokenListHi = 0;
-
-  if(cpi->OptimisedTokenListPl )
-    _ogg_free(cpi->OptimisedTokenListPl);
-  cpi->OptimisedTokenListPl = 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;
-
-}
-
-static void EInitFrameInfo(CP_INSTANCE * cpi){
-  int FrameSize = cpi->pb.ReconYPlaneSize + 2 * cpi->pb.ReconUVPlaneSize;
-
-  /* clear any existing info */
-  EClearFrameInfo(cpi);
-
-  /* allocate frames */
-  cpi->yuvptr =
-    _ogg_malloc(FrameSize*
-                sizeof(*cpi->yuvptr));
-  cpi->OptimisedTokenListEb =
-    _ogg_malloc(FrameSize*
-                sizeof(*cpi->OptimisedTokenListEb));
-  cpi->OptimisedTokenList =
-    _ogg_malloc(FrameSize*
-                sizeof(*cpi->OptimisedTokenList));
-  cpi->OptimisedTokenListHi =
-    _ogg_malloc(FrameSize*
-                sizeof(*cpi->OptimisedTokenListHi));
-  cpi->OptimisedTokenListPl =
-    _ogg_malloc(FrameSize*
-                sizeof(*cpi->OptimisedTokenListPl));
-
-  /* new block abstraction setup... babysteps... */
-  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->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->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->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->macro = calloc(cpi->macro_total, sizeof(*cpi->macro));
-
-  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; hilbert order */
-  {
-    int row,col,frag,mb;
-    int fhilbertx[16] = {0,1,1,0,0,0,1,1,2,2,3,3,3,2,2,3};
-    int fhilberty[16] = {0,0,1,1,2,3,3,2,2,3,3,2,1,1,0,0};
-    int mhilbertx[4] = {0,0,1,1};
-    int mhilberty[4] = {0,1,1,0};
-    int plane;
-
-    for(plane=0;plane<3;plane++){
-
-      for(row=0;row<cpi->super_v[plane];row++){
-	for(col=0;col<cpi->super_h[plane];col++){
-	  int superindex = row*cpi->super_h[plane] + col;
-	  for(frag=0;frag<16;frag++){
-	    /* translate to fragment index */
-	    int frow = row*4 + fhilberty[frag];
-	    int fcol = col*4 + fhilbertx[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];
-	    }
-	  }
-	}
-      }
-    }
-
-    for(row=0;row<cpi->super_v[0];row++){
-      for(col=0;col<cpi->super_h[0];col++){
-	int superindex = row*cpi->super_h[0] + col;
-	for(mb=0;mb<4;mb++){
-	  /* translate to macroblock index */
-	  int mrow = row*2 + mhilberty[mb];
-	  int mcol = col*2 + mhilbertx[mb];
-	  if(mrow<cpi->macro_v && mcol<cpi->macro_h){
-	    int macroindex = mrow*cpi->macro_h + mcol;
-	    cpi->super[0][superindex].m[mb] = &cpi->macro[macroindex];
-	  }
-	}
-      }
-    }
-  }
-
-  /* fill in macroblock fragment pointers; raster (MV coding) order */
-  {
-    int row,col,frag;
-    int scanx[4] = {0,1,0,1};
-    int scany[4] = {0,1,1,0};
-
-    for(row=0;row<cpi->macro_v;row++){
-      int baserow = row*2;
-      for(col=0;col<cpi->macro_h;col++){
-	int basecol = col*2;
-	int macroindex = row*cpi->macro_h + col;
-	for(frag=0;frag<4;frag++){
-	  /* translate to fragment index */
-	  int frow = baserow + scany[frag];
-	  int fcol = basecol + scanx[frag];
-	  if(frow<cpi->frag_v[0] && fcol<cpi->frag_h[0]){
-	    int fragindex = frow*cpi->frag_h[0] + fcol;
-	    cpi->macro[macroindex].y[frag] = &cpi->frag[0][fragindex];
-	  }
-	}
-
-	if(row<cpi->frag_v[1] && col<cpi->frag_h[1])
-	  cpi->macro[macroindex].u = &cpi->frag[1][macroindex];
-	if(row<cpi->frag_v[2] && col<cpi->frag_h[2])
-	  cpi->macro[macroindex].v = &cpi->frag[2][macroindex];
-
-      }
-    }
-  }
-}
-
 static void SetupKeyFrame(CP_INSTANCE *cpi) {
   int i,j;
 
@@ -490,8 +252,6 @@
 #endif 
 
   InitFrameDetails(cpi);
-  EInitFragmentInfo(cpi);
-  EInitFrameInfo(cpi);
 
   /* Initialise Motion compensation */
   InitMotionCompensation(cpi);
@@ -804,8 +564,8 @@
   if(cpi){
 
     ClearHuffmanSet(&cpi->pb);
-    EClearFragmentInfo(cpi);
-    EClearFrameInfo(cpi);
+    ClearFragmentInfo(cpi);
+    ClearFrameInfo(cpi);
 
     oggpackB_writeclear(cpi->oggbuffer);
     _ogg_free(cpi->oggbuffer);

Modified: branches/theora-thusnelda/lib/enc/frinit.c
===================================================================
--- branches/theora-thusnelda/lib/enc/frinit.c	2007-11-27 13:40:03 UTC (rev 14237)
+++ branches/theora-thusnelda/lib/enc/frinit.c	2007-11-27 18:27:40 UTC (rev 14238)
@@ -19,76 +19,28 @@
 #include "codec_internal.h"
 
 
-static void CalcPixelIndexTable( CP_INSTANCE *cpi){
-  PB_INSTANCE *pbi = &cpi->pb;
-  ogg_uint32_t i;
-  ogg_uint32_t * PixelIndexTablePtr;
+static void CalcPixelIndexTable(CP_INSTANCE *cpi){
+  ogg_uint32_t plane,row,col;
+  fragment_t *fp = cpi->frag[0];
+  ogg_uint32_t raw=0;
 
-  /* Calculate the pixel index table for normal image buffers */
-  PixelIndexTablePtr = pbi->pixel_index_table;
-  for ( i = 0; i < pbi->YPlaneFragments; i++ ) {
-    PixelIndexTablePtr[ i ] =
-      ((i / pbi->HFragments) * VFRAGPIXELS *
-       cpi->info.width);
-    PixelIndexTablePtr[ i ] +=
-      ((i % pbi->HFragments) * HFRAGPIXELS);
+  for(plane=0;plane<3;plane++){
+    ogg_uint32_t recon = cpi->recon_offset[plane];
+    for(row=0;row<cpi->frag_v[plane];row++){
+      for(col=0;col<cpi->frag_h[plane];col++,fp++){
+	fp->raw_index = raw+col*8;
+	fp->recon_index = recon+col*8;
+      }
+      raw += col*8*8;
+      recon += cpi->recon_stride[plane]*8;
+    }
   }
-
-  PixelIndexTablePtr = &pbi->pixel_index_table[pbi->YPlaneFragments];
-  for ( i = 0; i < ((pbi->HFragments >> 1) * pbi->VFragments); i++ ) {
-    PixelIndexTablePtr[ i ] =
-      ((i / (pbi->HFragments / 2) ) *
-       (VFRAGPIXELS *
-        (cpi->info.width / 2)) );
-    PixelIndexTablePtr[ i ] +=
-      ((i % (pbi->HFragments / 2) ) *
-       HFRAGPIXELS) + pbi->YPlaneSize;
-  }
-
-  /************************************************************************/
-  /* Now calculate the pixel index table for image reconstruction buffers */
-
-  PixelIndexTablePtr = pbi->recon_pixel_index_table;
-  for ( i = 0; i < pbi->YPlaneFragments; i++ ){
-    PixelIndexTablePtr[ i ] =
-      ((i / pbi->HFragments) * VFRAGPIXELS *
-       pbi->YStride);
-    PixelIndexTablePtr[ i ] +=
-      ((i % pbi->HFragments) * HFRAGPIXELS) +
-      pbi->ReconYDataOffset;
-  }
-
-  /* U blocks */
-  PixelIndexTablePtr = &pbi->recon_pixel_index_table[pbi->YPlaneFragments];
-  for ( i = 0; i < pbi->UVPlaneFragments; i++ ) {
-    PixelIndexTablePtr[ i ] =
-      ((i / (pbi->HFragments / 2) ) *
-       (VFRAGPIXELS * (pbi->UVStride)) );
-    PixelIndexTablePtr[ i ] +=
-      ((i % (pbi->HFragments / 2) ) *
-       HFRAGPIXELS) + pbi->ReconUDataOffset;
-  }
-
-  /* V blocks */
-  PixelIndexTablePtr =
-    &pbi->recon_pixel_index_table[pbi->YPlaneFragments +
-                                 pbi->UVPlaneFragments];
-
-  for ( i = 0; i < pbi->UVPlaneFragments; i++ ) {
-    PixelIndexTablePtr[ i ] =
-      ((i / (pbi->HFragments / 2) ) *
-       (VFRAGPIXELS * (pbi->UVStride)) );
-    PixelIndexTablePtr[ i ] +=
-      ((i % (pbi->HFragments / 2) ) * HFRAGPIXELS) +
-      pbi->ReconVDataOffset;
-  }
 }
 
-static void ClearFragmentInfo(PB_INSTANCE * pbi){
+void ClearFragmentInfo(CP_INSTANCE *cpi){
+  PB_INSTANCE *pbi = &cpi->pb;
 
   /* free prior allocs if present */
-  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->CodedBlockList) _ogg_free(pbi->CodedBlockList);
   if(pbi->FragMVect) _ogg_free(pbi->FragMVect);
 #ifdef _TH_DEBUG_
@@ -106,8 +58,6 @@
   if(pbi->MBFullyFlags) _ogg_free(pbi->MBFullyFlags);
   if(pbi->MBCodedFlags) _ogg_free(pbi->MBCodedFlags);
 
-  pbi->pixel_index_table = 0;
-  pbi->recon_pixel_index_table = 0;
   pbi->CodedBlockList = 0;
   pbi->FragMVect = 0;
   pbi->MBCodedFlags = 0;
@@ -116,20 +66,75 @@
 
   pbi->SBCodedFlags = 0;
   pbi->SBFullyFlags = 0;
+
+  if(cpi->RunHuffIndices)
+    _ogg_free(cpi->RunHuffIndices);
+  if(cpi->ModeList)
+    _ogg_free(cpi->ModeList);
+  if(cpi->MVList)
+    _ogg_free(cpi->MVList);
+  if(cpi->PartiallyCodedFlags)
+    _ogg_free(cpi->PartiallyCodedFlags);
+  if(cpi->PartiallyCodedMbPatterns)
+    _ogg_free(cpi->PartiallyCodedMbPatterns);
+  if(cpi->BlockCodedFlags)
+    _ogg_free(cpi->BlockCodedFlags);
+
+  cpi->RunHuffIndices = 0;
+  cpi->ModeList = 0;
+  cpi->MVList = 0;
+  cpi->PartiallyCodedFlags = 0;
+  cpi->PartiallyCodedMbPatterns = 0;
+  cpi->BlockCodedFlags = 0;
+
 }
 
-static void InitFragmentInfo(PB_INSTANCE * pbi){
+static void InitFragmentInfo(CP_INSTANCE * cpi){
+  PB_INSTANCE *pbi = &cpi->pb;
 
   /* clear any existing info */
-  ClearFragmentInfo(pbi);
+  ClearFragmentInfo(cpi);
 
-  /* Perform Fragment Allocations */
-  pbi->pixel_index_table =
-    _ogg_malloc(pbi->UnitFragments * sizeof(*pbi->pixel_index_table));
+  /* A note to people reading and wondering why malloc returns aren't
+     checked:
 
-  pbi->recon_pixel_index_table =
-    _ogg_malloc(pbi->UnitFragments * sizeof(*pbi->recon_pixel_index_table));
+     lines like the following that implement a general strategy of
+     'check the return of malloc; a zero pointer means we're out of
+     memory!'...:
 
+     if(!cpi->extra_fragments) { EDeleteFragmentInfo(cpi); return FALSE; }
+     
+     ...are not useful.  It's true that many platforms follow this
+     malloc behavior, but many do not.  The more modern malloc
+     strategy is only to allocate virtual pages, which are not mapped
+     until the memory on that page is touched.  At *that* point, if
+     the machine is out of heap, the page fails to be mapped and a
+     SEGV is generated.
+
+     That means that if we want to deal with out of memory conditions,
+     we *must* be prepared to process a SEGV.  If we implement the
+     SEGV handler, there's no reason to to check malloc return; it is
+     a waste of code. */
+
+  cpi->RunHuffIndices =
+    _ogg_malloc(cpi->pb.UnitFragments*
+                sizeof(*cpi->RunHuffIndices));
+  cpi->BlockCodedFlags =
+    _ogg_malloc(cpi->pb.UnitFragments*
+                sizeof(*cpi->BlockCodedFlags));
+  cpi->ModeList =
+    _ogg_malloc(cpi->pb.UnitFragments*
+                sizeof(*cpi->ModeList));
+  cpi->MVList =
+    _ogg_malloc(cpi->pb.UnitFragments*
+                sizeof(*cpi->MVList));
+  cpi->PartiallyCodedFlags =
+    _ogg_malloc(cpi->pb.MacroBlocks*
+                sizeof(*cpi->PartiallyCodedFlags));
+  cpi->PartiallyCodedMbPatterns =
+    _ogg_malloc(cpi->pb.MacroBlocks*
+                sizeof(*cpi->PartiallyCodedMbPatterns));
+
   pbi->CodedBlockList =
     _ogg_malloc(pbi->UnitFragments * sizeof(*pbi->CodedBlockList));
 
@@ -168,7 +173,40 @@
 
 }
 
-static void ClearFrameInfo(PB_INSTANCE * pbi){
+void ClearFrameInfo(CP_INSTANCE *cpi){
+  PB_INSTANCE *pbi = &cpi->pb;
+
+  if(cpi->yuvptr)
+    _ogg_free(cpi->yuvptr);
+  cpi->yuvptr = 0;
+
+  if(cpi->OptimisedTokenListEb )
+    _ogg_free(cpi->OptimisedTokenListEb);
+  cpi->OptimisedTokenListEb = 0;
+
+  if(cpi->OptimisedTokenList )
+    _ogg_free(cpi->OptimisedTokenList);
+  cpi->OptimisedTokenList = 0;
+
+  if(cpi->OptimisedTokenListHi )
+    _ogg_free(cpi->OptimisedTokenListHi);
+  cpi->OptimisedTokenListHi = 0;
+
+  if(cpi->OptimisedTokenListPl )
+    _ogg_free(cpi->OptimisedTokenListPl);
+  cpi->OptimisedTokenListPl = 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;
+
   if(pbi->ThisFrameRecon )
     _ogg_free(pbi->ThisFrameRecon );
   if(pbi->GoldenFrame)
@@ -181,10 +219,11 @@
   pbi->LastFrameRecon = 0;
 }
 
-static void InitFrameInfo(PB_INSTANCE * pbi, unsigned int FrameSize){
+static void InitFrameInfo(CP_INSTANCE *cpi, unsigned int FrameSize){
+  PB_INSTANCE *pbi = &cpi->pb;
 
   /* clear any existing info */
-  ClearFrameInfo(pbi);
+  ClearFrameInfo(cpi);
 
   /* allocate frames */
   pbi->ThisFrameRecon =
@@ -196,6 +235,133 @@
   pbi->LastFrameRecon =
     _ogg_malloc(FrameSize*sizeof(*pbi->LastFrameRecon));
 
+  /* allocate frames */
+  cpi->yuvptr =
+    _ogg_malloc(FrameSize*
+                sizeof(*cpi->yuvptr));
+  cpi->OptimisedTokenListEb =
+    _ogg_malloc(FrameSize*
+                sizeof(*cpi->OptimisedTokenListEb));
+  cpi->OptimisedTokenList =
+    _ogg_malloc(FrameSize*
+                sizeof(*cpi->OptimisedTokenList));
+  cpi->OptimisedTokenListHi =
+    _ogg_malloc(FrameSize*
+                sizeof(*cpi->OptimisedTokenListHi));
+  cpi->OptimisedTokenListPl =
+    _ogg_malloc(FrameSize*
+                sizeof(*cpi->OptimisedTokenListPl));
+
+  /* new block abstraction setup... babysteps... */
+  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->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->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->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->macro = calloc(cpi->macro_total, sizeof(*cpi->macro));
+
+  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; hilbert order */
+  {
+    int row,col,frag,mb;
+    int fhilbertx[16] = {0,1,1,0,0,0,1,1,2,2,3,3,3,2,2,3};
+    int fhilberty[16] = {0,0,1,1,2,3,3,2,2,3,3,2,1,1,0,0};
+    int mhilbertx[4] = {0,0,1,1};
+    int mhilberty[4] = {0,1,1,0};
+    int plane;
+
+    for(plane=0;plane<3;plane++){
+
+      for(row=0;row<cpi->super_v[plane];row++){
+	for(col=0;col<cpi->super_h[plane];col++){
+	  int superindex = row*cpi->super_h[plane] + col;
+	  for(frag=0;frag<16;frag++){
+	    /* translate to fragment index */
+	    int frow = row*4 + fhilberty[frag];
+	    int fcol = col*4 + fhilbertx[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];
+	    }
+	  }
+	}
+      }
+    }
+
+    for(row=0;row<cpi->super_v[0];row++){
+      for(col=0;col<cpi->super_h[0];col++){
+	int superindex = row*cpi->super_h[0] + col;
+	for(mb=0;mb<4;mb++){
+	  /* translate to macroblock index */
+	  int mrow = row*2 + mhilberty[mb];
+	  int mcol = col*2 + mhilbertx[mb];
+	  if(mrow<cpi->macro_v && mcol<cpi->macro_h){
+	    int macroindex = mrow*cpi->macro_h + mcol;
+	    cpi->super[0][superindex].m[mb] = &cpi->macro[macroindex];
+	  }
+	}
+      }
+    }
+  }
+
+  /* fill in macroblock fragment pointers; raster (MV coding) order */
+  {
+    int row,col,frag;
+    int scanx[4] = {0,1,0,1};
+    int scany[4] = {0,1,1,0};
+
+    for(row=0;row<cpi->macro_v;row++){
+      int baserow = row*2;
+      for(col=0;col<cpi->macro_h;col++){
+	int basecol = col*2;
+	int macroindex = row*cpi->macro_h + col;
+	for(frag=0;frag<4;frag++){
+	  /* translate to fragment index */
+	  int frow = baserow + scany[frag];
+	  int fcol = basecol + scanx[frag];
+	  if(frow<cpi->frag_v[0] && fcol<cpi->frag_h[0]){
+	    int fragindex = frow*cpi->frag_h[0] + fcol;
+	    cpi->macro[macroindex].y[frag] = &cpi->frag[0][fragindex];
+	  }
+	}
+
+	if(row<cpi->frag_v[1] && col<cpi->frag_h[1])
+	  cpi->macro[macroindex].u = &cpi->frag[1][macroindex];
+	if(row<cpi->frag_v[2] && col<cpi->frag_h[2])
+	  cpi->macro[macroindex].v = &cpi->frag[2][macroindex];
+
+      }
+    }
+  }
+
 }
 
 void InitFrameDetails(CP_INSTANCE *cpi){
@@ -213,23 +379,20 @@
   pbi->YPlaneFragments = pbi->HFragments * pbi->VFragments;
   pbi->UVPlaneFragments = pbi->YPlaneFragments / 4;
 
-  pbi->YStride = (cpi->info.width + STRIDE_EXTRA);
-  pbi->UVStride = pbi->YStride / 2;
-  pbi->ReconYPlaneSize = pbi->YStride *
-    (cpi->info.height + STRIDE_EXTRA);
-  pbi->ReconUVPlaneSize = pbi->ReconYPlaneSize / 4;
-  FrameSize = pbi->ReconYPlaneSize + 2 * pbi->ReconUVPlaneSize;
+  cpi->recon_stride[0] = (cpi->info.width + STRIDE_EXTRA);
+  cpi->recon_stride[1] = (cpi->info.width + STRIDE_EXTRA) / 2;
+  cpi->recon_stride[2] = (cpi->info.width + STRIDE_EXTRA) / 2;
 
-  pbi->YDataOffset = 0;
-  pbi->UDataOffset = pbi->YPlaneSize;
-  pbi->VDataOffset = pbi->YPlaneSize + pbi->UVPlaneSize;
-  pbi->ReconYDataOffset =
-    (pbi->YStride * UMV_BORDER) + UMV_BORDER;
-  pbi->ReconUDataOffset = pbi->ReconYPlaneSize +
-    (pbi->UVStride * (UMV_BORDER/2)) + (UMV_BORDER/2);
-  pbi->ReconVDataOffset = pbi->ReconYPlaneSize + pbi->ReconUVPlaneSize +
-    (pbi->UVStride * (UMV_BORDER/2)) + (UMV_BORDER/2);
+  {
+    ogg_uint32_t ry_size = cpi->recon_stride[0] * (cpi->info.height + STRIDE_EXTRA);
+    ogg_uint32_t ruv_size = ry_size / 4;
+    FrameSize = ry_size + 2 * ruv_size;
 
+    cpi->recon_offset[0] = (cpi->recon_stride[0] * UMV_BORDER) + UMV_BORDER;
+    cpi->recon_offset[1] = ry_size + cpi->recon_stride[1] * (UMV_BORDER/2) + (UMV_BORDER/2);
+    cpi->recon_offset[2] = ry_size + ruv_size + cpi->recon_stride[2] * (UMV_BORDER/2) + (UMV_BORDER/2);
+  }
+
   /* Image dimensions in Super-Blocks */
   pbi->YSBRows = (cpi->info.height/32)  +
     ( cpi->info.height%32 ? 1 : 0 );
@@ -248,8 +411,8 @@
   /* Useful externals */
   pbi->MacroBlocks = ((pbi->VFragments+1)/2)*((pbi->HFragments+1)/2);
 
-  InitFragmentInfo(pbi);
-  InitFrameInfo(pbi, FrameSize);
+  InitFragmentInfo(cpi);
+  InitFrameInfo(cpi, FrameSize);
 
   /* Configure mapping between quad-tree and fragments */
   CreateBlockMapping ( pbi->BlockMap, pbi->YSuperBlocks,

Modified: branches/theora-thusnelda/lib/enc/mcomp.c
===================================================================
--- branches/theora-thusnelda/lib/enc/mcomp.c	2007-11-27 13:40:03 UTC (rev 14237)
+++ branches/theora-thusnelda/lib/enc/mcomp.c	2007-11-27 18:27:40 UTC (rev 14238)
@@ -24,11 +24,10 @@
   int i;
   int SearchSite=0;
   int Len;
-  int LineStepY = (ogg_int32_t)cpi->pb.YStride;
+  int LineStepY = cpi->recon_stride[0];
 
   Len=((MAX_MV_EXTENT/2)+1)/2;
 
-
   /* How many search stages are there. */
   cpi->MVSearchSteps = 0;
 
@@ -146,50 +145,26 @@
 
 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;
 
+  ogg_uint32_t  IntraError = 0;
   dsp_save_fpu (cpi->dsp);
 
   /* Add together the intra errors for those blocks in the macro block
      that are coded (Y only) */
-  if ( fp->coded )
-    IntraError +=
-      dsp_intra8x8_err (cpi->dsp, &cpi->
-                    yuvptr[cpi->pb.pixel_index_table[LocalFragIndex]],
-                    PixelsPerLine);
+  if ( fp[0].coded )
+    IntraError += dsp_intra8x8_err (cpi->dsp, &cpi->yuvptr[fp[0].raw_index],PixelsPerLine);
+  if ( fp[1].coded )
+    IntraError += dsp_intra8x8_err (cpi->dsp, &cpi->yuvptr[fp[1].raw_index],PixelsPerLine);
+  
+  fp += cpi->pb.HFragments;
 
-  LocalFragIndex++;
-  fp++;
+  if ( fp[0].coded )
+    IntraError += dsp_intra8x8_err (cpi->dsp, &cpi->yuvptr[fp[0].raw_index],PixelsPerLine);
+  if ( fp[1].coded )
+    IntraError += dsp_intra8x8_err (cpi->dsp, &cpi->yuvptr[fp[1].raw_index],PixelsPerLine);
 
-  if ( fp->coded )
-    IntraError +=
-      dsp_intra8x8_err (cpi->dsp, &cpi->
-                    yuvptr[cpi->pb.pixel_index_table[LocalFragIndex]],
-                    PixelsPerLine);
-
-  LocalFragIndex = FragIndex + cpi->pb.HFragments;
-  fp += cpi->pb.HFragments-1;
-
-  if ( fp->coded )
-    IntraError +=
-      dsp_intra8x8_err (cpi->dsp, &cpi->
-                     yuvptr[cpi->pb.pixel_index_table[LocalFragIndex]],
-                    PixelsPerLine);
-
-  LocalFragIndex++;
-  fp++;
-
-  if ( fp->coded )
-    IntraError +=
-      dsp_intra8x8_err (cpi->dsp, &cpi->
-                    yuvptr[cpi->pb.pixel_index_table[LocalFragIndex]],
-                    PixelsPerLine);
-
   dsp_restore_fpu (cpi->dsp);
-
   return IntraError;
 }
 
@@ -197,34 +172,21 @@
                               unsigned char * SrcPtr,
                               unsigned char * RefPtr,
 			      fragment_t *fp,
-			      ogg_uint32_t FragIndex,
                               ogg_int32_t LastXMV,
                               ogg_int32_t LastYMV,
                               ogg_uint32_t PixelsPerLine ) {
-  ogg_uint32_t  RefPixelsPerLine = cpi->pb.YStride;
-  ogg_uint32_t  LocalFragIndex = FragIndex;
-  ogg_int32_t   PixelIndex;
-  ogg_int32_t   RefPixelIndex;
-  ogg_int32_t   RefPixelOffset;
-  ogg_int32_t   RefPtr2Offset;
-
+  ogg_uint32_t  RefPixelsPerLine = cpi->recon_stride[0];
+  ogg_int32_t   RefPixelOffset = ((LastYMV/2) * RefPixelsPerLine) + (LastXMV/2);
+  ogg_int32_t   RefPtr2Offset = 0;
+  
   ogg_uint32_t  InterError = 0;
-
+  
   unsigned char * SrcPtr1;
   unsigned char * RefPtr1;
-
+  
   dsp_save_fpu (cpi->dsp);
-
-  /* Work out pixel offset into source buffer. */
-  PixelIndex = cpi->pb.pixel_index_table[LocalFragIndex];
-
-  /* Work out the pixel offset in reference buffer for the default
-     motion vector */
-  RefPixelIndex = cpi->pb.recon_pixel_index_table[LocalFragIndex];
-  RefPixelOffset = ((LastYMV/2) * RefPixelsPerLine) + (LastXMV/2);
-
+  
   /* Work out the second reference pointer offset. */
-  RefPtr2Offset = 0;
   if ( LastXMV % 2 ) {
     if ( LastXMV > 0 )
       RefPtr2Offset += 1;
@@ -240,59 +202,45 @@
 
   /* Add together the errors for those blocks in the macro block that
      are coded (Y only) */
-  if ( fp->coded ) {
-    SrcPtr1 = &SrcPtr[PixelIndex];
-    RefPtr1 = &RefPtr[RefPixelIndex + RefPixelOffset];
+  if ( fp[0].coded ) {
+    SrcPtr1 = &SrcPtr[fp[0].raw_index];
+    RefPtr1 = &RefPtr[fp[0].recon_index + RefPixelOffset];
     InterError += GetInterErr(cpi, SrcPtr1, RefPtr1,
                                  &RefPtr1[RefPtr2Offset], PixelsPerLine );
   }
 
-  LocalFragIndex++;
-  fp++;
-
-  if ( fp->coded ) {
-    PixelIndex = cpi->pb.pixel_index_table[LocalFragIndex];
-    RefPixelIndex = cpi->pb.recon_pixel_index_table[LocalFragIndex];
-    SrcPtr1 = &SrcPtr[PixelIndex];
-    RefPtr1 = &RefPtr[RefPixelIndex + RefPixelOffset];
+  if ( fp[1].coded ) {
+    SrcPtr1 = &SrcPtr[fp[1].raw_index];
+    RefPtr1 = &RefPtr[fp[1].recon_index + RefPixelOffset];
     InterError += GetInterErr(cpi, SrcPtr1, RefPtr1,
-                                 &RefPtr1[RefPtr2Offset], PixelsPerLine );
-
+			      &RefPtr1[RefPtr2Offset], PixelsPerLine );
+    
   }
+  
+  fp += cpi->pb.HFragments;
 
-  LocalFragIndex = FragIndex + cpi->pb.HFragments;
-  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];
-    RefPtr1 = &RefPtr[RefPixelIndex + RefPixelOffset];
+  if ( fp[0].coded ) {
+    SrcPtr1 = &SrcPtr[fp[0].raw_index];
+    RefPtr1 = &RefPtr[fp[0].recon_index + RefPixelOffset];
     InterError += GetInterErr(cpi, SrcPtr1, RefPtr1,
                                  &RefPtr1[RefPtr2Offset], PixelsPerLine );
   }
 
-  LocalFragIndex++;
-  fp++;
-
-  if ( fp->coded ) {
-    PixelIndex = cpi->pb.pixel_index_table[LocalFragIndex];
-    RefPixelIndex = cpi->pb.recon_pixel_index_table[LocalFragIndex];
-    SrcPtr1 = &SrcPtr[PixelIndex];
-    RefPtr1 = &RefPtr[RefPixelIndex + RefPixelOffset];
+  if ( fp[1].coded ) {
+    SrcPtr1 = &SrcPtr[fp[1].raw_index];
+    RefPtr1 = &RefPtr[fp[1].recon_index + RefPixelOffset];
     InterError += GetInterErr(cpi, SrcPtr1, RefPtr1,
-                                 &RefPtr1[RefPtr2Offset], PixelsPerLine );
+			      &RefPtr1[RefPtr2Offset], PixelsPerLine );
   }
-
+  
   dsp_restore_fpu (cpi->dsp);
-
+  
   return InterError;
 }
 
 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 ) {
@@ -310,7 +258,7 @@
   unsigned char *CandidateBlockPtr=NULL;
   unsigned char *BestBlockPtr=NULL;
 
-  ogg_uint32_t  RefRow2Offset = cpi->pb.YStride * 8;
+  ogg_uint32_t  RefRow2Offset = cpi->recon_stride[0] * 8;
 
   int    MBlockDispFrags[4];
 
@@ -327,17 +275,17 @@
      included in the search. */
   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;
+  MBlockDispFrags[2] = fp[cpi->frag_h[0]].coded;
+  MBlockDispFrags[3] = fp[cpi->frag_h[0] + 1].coded;
 
   /* Set up the source pointers for the four source blocks.  */
-  SrcPtr[0] = &cpi->yuvptr[cpi->pb.pixel_index_table[FragIndex]];
+  SrcPtr[0] = &cpi->yuvptr[fp->raw_index];
   SrcPtr[1] = SrcPtr[0] + 8;
   SrcPtr[2] = SrcPtr[0] + (PixelsPerLine * 8);
   SrcPtr[3] = SrcPtr[2] + 8;
 
   /* Set starting reference point for search. */
-  RefPtr = &RefFramePtr[cpi->pb.recon_pixel_index_table[FragIndex]];
+  RefPtr = &RefFramePtr[fp->recon_index];
 
   /* Check the 0,0 candidate. */
   if ( MBlockDispFrags[0] ) {
@@ -472,18 +420,17 @@
 
   /* Get the error score for the chosen 1/2 pixel offset as a variance. */
   InterMVError = GetMBInterError( cpi, cpi->yuvptr, RefFramePtr, fp,
-                                  FragIndex, MV->x, MV->y, PixelsPerLine );
-
+                                  MV->x, MV->y, PixelsPerLine );
+  
   dsp_restore_fpu (cpi->dsp);
-
+  
   /* Return score of best matching block. */
   return InterMVError;
 }
 
 ogg_uint32_t GetMBMVExhaustiveSearch (CP_INSTANCE *cpi,
-                                      unsigned char * RefFramePtr,
+                                      unsigned char *RefFramePtr,
 				      fragment_t *fp,
-                                      ogg_uint32_t FragIndex,
                                       ogg_uint32_t PixelsPerLine,
                                       MOTION_VECTOR *MV ) {
   ogg_uint32_t  Error = 0;
@@ -498,7 +445,7 @@
   unsigned char *CandidateBlockPtr=NULL;
   unsigned char *BestBlockPtr=NULL;
 
-  ogg_uint32_t  RefRow2Offset = cpi->pb.YStride * 8;
+  ogg_uint32_t  RefRow2Offset = cpi->recon_stride[0] * 8;
 
   int    MBlockDispFrags[4];
 
@@ -515,20 +462,18 @@
      included in the search. */
   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;
+  MBlockDispFrags[2] = fp[cpi->frag_h[0]].coded;
+  MBlockDispFrags[3] = fp[cpi->frag_h[0] + 1].coded;
 
   /* Set up the source pointers for the four source blocks. */
-  SrcPtr[0] = &cpi->
-    yuvptr[cpi->pb.pixel_index_table[FragIndex]];
+  SrcPtr[0] = &cpi->yuvptr[fp->raw_index];
   SrcPtr[1] = SrcPtr[0] + 8;
   SrcPtr[2] = SrcPtr[0] + (PixelsPerLine * 8);
   SrcPtr[3] = SrcPtr[2] + 8;
+  
+  RefPtr = &RefFramePtr[fp->recon_index];
+  RefPtr = RefPtr - ((MAX_MV_EXTENT/2) * cpi->recon_stride[0]) - (MAX_MV_EXTENT/2);
 
-  RefPtr = &RefFramePtr[cpi->pb.recon_pixel_index_table[FragIndex]];
-  RefPtr = RefPtr - ((MAX_MV_EXTENT/2) * cpi->
-                     pb.YStride) - (MAX_MV_EXTENT/2);
-
   /* Search each pixel alligned site */
   for ( i = 0; i < (ogg_int32_t)MAX_MV_EXTENT; i ++ ) {
     /* Starting position in row */
@@ -569,7 +514,7 @@
     }
 
     /* Move on to the next row. */
-    RefPtr += cpi->pb.YStride;
+    RefPtr += cpi->recon_stride[0];
 
   }
 
@@ -629,7 +574,7 @@
 
   /* Get the error score for the chosen 1/2 pixel offset as a variance. */
   InterMVError = GetMBInterError( cpi, cpi->yuvptr, RefFramePtr, fp,
-                                  FragIndex, MV->x, MV->y, PixelsPerLine );
+                                  MV->x, MV->y, PixelsPerLine );
 
   dsp_restore_fpu (cpi->dsp);
 
@@ -639,7 +584,7 @@
 
 static ogg_uint32_t GetBMVExhaustiveSearch (CP_INSTANCE *cpi,
                                             unsigned char * RefFramePtr,
-                                            ogg_uint32_t FragIndex,
+					    fragment_t *fp,
                                             ogg_uint32_t PixelsPerLine,
                                             MOTION_VECTOR *MV ) {
   ogg_uint32_t  Error = 0;
@@ -661,18 +606,15 @@
   unsigned char * RefDataPtr2;
 
   /* Set up the source pointer for the block. */
-  SrcPtr = &cpi->
-    yuvptr[cpi->pb.pixel_index_table[FragIndex]];
-
-  RefPtr = &RefFramePtr[cpi->pb.recon_pixel_index_table[FragIndex]];
-  RefPtr = RefPtr - ((MAX_MV_EXTENT/2) *
-                     cpi->pb.YStride) - (MAX_MV_EXTENT/2);
-
+  SrcPtr = &cpi->yuvptr[fp->raw_index];
+  RefPtr = &RefFramePtr[fp->recon_index];
+  RefPtr = RefPtr - ((MAX_MV_EXTENT/2) * cpi->recon_stride[0]) - (MAX_MV_EXTENT/2);
+  
   /* Search each pixel alligned site */
   for ( i = 0; i < (ogg_int32_t)MAX_MV_EXTENT; i ++ ) {
     /* Starting position in row */
     CandidateBlockPtr = RefPtr;
-
+    
     for ( j = 0; j < (ogg_int32_t)MAX_MV_EXTENT; j++ ){
       /* Get the block error score. */
       Error = dsp_sad8x8 (cpi->dsp, SrcPtr, PixelsPerLine, CandidateBlockPtr,
@@ -691,7 +633,7 @@
     }
 
     /* Move on to the next row. */
-    RefPtr += cpi->pb.YStride;
+    RefPtr += cpi->recon_stride[0];
   }
 
   /* Factor vectors to 1/2 pixel resoultion. */
@@ -707,8 +649,8 @@
     RefDataPtr2 = BestBlockPtr + cpi->HalfPixelRef2Offset[i];
     HalfPixelError =
       GetHalfPixelSumAbsDiffs(cpi, SrcPtr, BestBlockPtr, RefDataPtr2,
-                            PixelsPerLine, 0, BestHalfPixelError );
-
+			      PixelsPerLine, 0, BestHalfPixelError );
+    
     if ( HalfPixelError < BestHalfPixelError ){
       BestHalfOffset = (unsigned char)i;
       BestHalfPixelError = HalfPixelError;
@@ -732,11 +674,10 @@
 ogg_uint32_t GetFOURMVExhaustiveSearch (CP_INSTANCE *cpi,
                                         unsigned char * RefFramePtr,
 					fragment_t *fp,
-                                        ogg_uint32_t FragIndex,
                                         ogg_uint32_t PixelsPerLine,
                                         MOTION_VECTOR *MV ) {
   ogg_uint32_t  InterMVError;
-
+  
   dsp_save_fpu (cpi->dsp);
 
   /* For the moment the 4MV mode is only deemed to be valid 
@@ -744,31 +685,29 @@
   /* This may be adapted later. */
   if ( fp[0].coded &&
        fp[1].coded &&
-       fp[cpi->pb.HFragments].coded &&
-       fp[cpi->pb.HFragments + 1].coded ) {
-
+       fp[cpi->frag_h[0]].coded &&
+       fp[cpi->frag_h[0]+1].coded ) {
+    
     /* Reset the error score. */
     InterMVError = 0;
-
+    
     /* Get the error component from each coded block */
     InterMVError +=
-      GetBMVExhaustiveSearch(cpi, RefFramePtr, FragIndex,
+      GetBMVExhaustiveSearch(cpi, RefFramePtr, fp,
                              PixelsPerLine, &(MV[0]) );
     InterMVError +=
-      GetBMVExhaustiveSearch(cpi, RefFramePtr, (FragIndex + 1),
+      GetBMVExhaustiveSearch(cpi, RefFramePtr, &fp[1],
                              PixelsPerLine, &(MV[1]) );
     InterMVError +=
-      GetBMVExhaustiveSearch(cpi, RefFramePtr,
-                             (FragIndex + cpi->pb.HFragments),
+      GetBMVExhaustiveSearch(cpi, RefFramePtr, &fp[cpi->frag_h[0]],
                              PixelsPerLine, &(MV[2]) );
     InterMVError +=
-      GetBMVExhaustiveSearch(cpi, RefFramePtr,
-                             (FragIndex + cpi->pb.HFragments + 1),
+      GetBMVExhaustiveSearch(cpi, RefFramePtr, &fp[cpi->frag_h[0]+1],
                              PixelsPerLine, &(MV[3]) );
   }else{
     InterMVError = HUGE_ERROR;
   }
-
+  
   dsp_restore_fpu (cpi->dsp);
 
   /* Return score of best matching block. */



More information about the commits mailing list