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

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Tue Nov 27 14:12:51 PST 2007


Author: xiphmont
Date: 2007-11-27 14:12:50 -0800 (Tue, 27 Nov 2007)
New Revision: 14240

Modified:
   branches/theora-thusnelda/lib/enc/codec_internal.h
   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:
Motion comp work, macroblock addressing bugfix



Modified: branches/theora-thusnelda/lib/enc/codec_internal.h
===================================================================
--- branches/theora-thusnelda/lib/enc/codec_internal.h	2007-11-27 19:11:53 UTC (rev 14239)
+++ branches/theora-thusnelda/lib/enc/codec_internal.h	2007-11-27 22:12:50 UTC (rev 14240)
@@ -77,11 +77,6 @@
 
 #define MAX_MV_EXTENT 31  /* Max search distance in half pixel increments */
 
-typedef struct{
-  ogg_int32_t   x;
-  ogg_int32_t   y;
-} MOTION_VECTOR;
-
 /** block coding modes */
 typedef enum{
   CODE_INTER_NO_MV        = 0x0, /* INTER prediction, (0,0) motion
@@ -191,8 +186,6 @@
   int            CodedBlockIndex;
   fragment_t   **CodedBlockList;           
 
-  MOTION_VECTOR *FragMVect;                /* Frag motion vectors */
-
   /***********************************************************************/
   /* Macro Block and SuperBlock Information */
   ogg_int32_t  (*BlockMap)[4][4];               /* super block + sub macro
@@ -208,7 +201,6 @@
   /**********************************************************************/
   ogg_uint32_t   EOB_Run;
 
-  MOTION_VECTOR  MVector;
   ogg_int32_t    ReconPtr2Offset;       /* Offset for second reconstruction
                                            in half pixel MC */
   ogg_uint32_t   DcHuffChoice;          /* Huffman table selection variables */
@@ -297,8 +289,6 @@
   ogg_uint32_t      RunPlaneIndex;        /* The plane (Y=0 UV=1) to
                                              which the first token in
                                              an EOB run belonged. */
-
-
   ogg_uint32_t      TotTokenCount;
   ogg_int32_t       TokensToBeCoded;
   ogg_int32_t       TokensCoded;
@@ -334,7 +324,6 @@
                                           updated. */
   ogg_uint32_t     *RunHuffIndices;
   ogg_uint32_t     *ModeList;
-  MOTION_VECTOR    *MVList;
 
   unsigned char    *BlockCodedFlags;
 
@@ -344,6 +333,8 @@
 
   unsigned char    *DataOutputBuffer;
   /*********************************************************************/
+  mv_t             *MVList;
+  ogg_uint32_t      MVListCount;
 
   ogg_uint32_t      RunLength;
 
@@ -360,7 +351,6 @@
   signed char       HalfPixelXOffset[9];    /* Half pixel MV offsets for X */
   signed char       HalfPixelYOffset[9];    /* Half pixel MV offsets for Y */
 
-  MOTION_VECTOR     MVector;
   /* instances (used for reconstructing buffers and to hold tokens etc.) */
   PB_INSTANCE       pb;   /* playback */
 
@@ -408,7 +398,7 @@
 extern void fdct_short ( ogg_int16_t * InputData, ogg_int16_t * OutputData );
 extern ogg_uint32_t DPCMTokenizeBlock (CP_INSTANCE *cpi,
 				       fragment_t *fp);
-extern void TransformQuantizeBlock (CP_INSTANCE *cpi, fragment_t *fp, ogg_int32_t FragIndex,
+extern void TransformQuantizeBlock (CP_INSTANCE *cpi, fragment_t *fp, 
                                     ogg_uint32_t PixelsPerLine ) ;
 extern void InitFrameDetails(CP_INSTANCE *cpi);
 extern void WriteQTables(PB_INSTANCE *pbi,oggpack_buffer *opb);
@@ -420,32 +410,32 @@
 extern void PackAndWriteDFArray( CP_INSTANCE *cpi );
 extern void InitMotionCompensation ( CP_INSTANCE *cpi );
 extern ogg_uint32_t GetMBIntraError (CP_INSTANCE *cpi, 
-				     fragment_t *fp,
+				     macroblock_t *mp,
                                      ogg_uint32_t PixelsPerLine ) ;
 extern ogg_uint32_t GetMBInterError (CP_INSTANCE *cpi,
                                      unsigned char * SrcPtr,
                                      unsigned char * RefPtr,
-				     fragment_t *fp,
+				     macroblock_t *mp,
                                      ogg_int32_t LastXMV,
                                      ogg_int32_t LastYMV,
                                      ogg_uint32_t PixelsPerLine ) ;
 extern void WriteFrameHeader( CP_INSTANCE *cpi) ;
 extern ogg_uint32_t GetMBMVInterError (CP_INSTANCE *cpi,
                                        unsigned char * RefFramePtr,
-				       fragment_t *fp,
+				       macroblock_t *mp,
                                        ogg_uint32_t PixelsPerLine,
                                        ogg_int32_t *MVPixelOffset,
-                                       MOTION_VECTOR *MV );
+                                       mv_t *MV );
 extern ogg_uint32_t GetMBMVExhaustiveSearch (CP_INSTANCE *cpi,
                                              unsigned char * RefFramePtr,
-					     fragment_t *fp,
+					     macroblock_t *mp,
                                              ogg_uint32_t PixelsPerLine,
-                                             MOTION_VECTOR *MV );
+                                             mv_t *MV );
 extern ogg_uint32_t GetFOURMVExhaustiveSearch (CP_INSTANCE *cpi,
                                                unsigned char * RefFramePtr,
-					       fragment_t *fp,
+					       macroblock_t *mp,
                                                ogg_uint32_t PixelsPerLine,
-                                               MOTION_VECTOR *MV ) ;
+                                               mv_t *MV ) ;
 extern void EncodeData(CP_INSTANCE *cpi);
 extern ogg_uint32_t PickIntra( CP_INSTANCE *cpi );
 extern ogg_uint32_t PickModes(CP_INSTANCE *cpi,

Modified: branches/theora-thusnelda/lib/enc/dct_encode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/dct_encode.c	2007-11-27 19:11:53 UTC (rev 14239)
+++ branches/theora-thusnelda/lib/enc/dct_encode.c	2007-11-27 22:12:50 UTC (rev 14240)
@@ -254,7 +254,6 @@
 				   unsigned char *thisrecon,
 				   ogg_int32_t MvDevisor,
 				   fragment_t *fp,
-				   ogg_uint32_t FragIndex,
 				   ogg_uint32_t PixelsPerLine,
 				   ogg_uint32_t ReconPixelsPerLine,
 				   int mode) {
@@ -269,7 +268,8 @@
                                    half pixel MC */
   unsigned char  *ReconPtr1;    /* DCT reconstructed image pointers */
   unsigned char  *ReconPtr2;    /* Pointer used in half pixel MC */
-   
+  mv_t mv;
+
   if ( ModeUsesMC[mode] ){
     switch(MvDevisor) {
     case 2:
@@ -284,30 +284,28 @@
       break;
     }
     
-    cpi->MVector.x = cpi->pb.FragMVect[FragIndex].x;
-    cpi->MVector.y = cpi->pb.FragMVect[FragIndex].y;
+    mv = fp->mv;
     
     /* Set up the baseline offset for the motion vector. */
-    MVOffset = ((cpi->MVector.y / MvDevisor) * ReconPixelsPerLine) +
-      (cpi->MVector.x / MvDevisor);
+    MVOffset = ((mv.y / MvDevisor) * ReconPixelsPerLine) + (mv.x / MvDevisor);
     
     /* Work out the offset of the second reference position for 1/2
        pixel interpolation.  For the U and V planes the MV specifies 1/4
        pixel accuracy. This is adjusted to 1/2 pixel as follows ( 0->0,
        1/4->1/2, 1/2->1/2, 3/4->1/2 ). */
     ReconPtr2Offset = 0;
-    AbsXOffset = cpi->MVector.x % MvDevisor;
-    AbsYOffset = cpi->MVector.y % MvDevisor;
+    AbsXOffset = mv.x % MvDevisor;
+    AbsYOffset = mv.y % MvDevisor;
     
     if ( AbsXOffset ) {
-      if ( cpi->MVector.x > 0 )
+      if ( mv.x > 0 )
 	ReconPtr2Offset += 1;
       else
 	ReconPtr2Offset -= 1;
     }
     
     if ( AbsYOffset ) {
-      if ( cpi->MVector.y > 0 )
+      if ( mv.y > 0 )
 	ReconPtr2Offset += ReconPixelsPerLine;
       else
 	ReconPtr2Offset -= ReconPixelsPerLine;
@@ -358,7 +356,6 @@
 
 void TransformQuantizeBlock (CP_INSTANCE *cpi, 
 			     fragment_t *fp,
-			     ogg_int32_t FragIndex,
                              ogg_uint32_t PixelsPerLine) {
   unsigned char *FiltPtr = &cpi->yuvptr[fp->raw_index];
   int qi = cpi->BaseQ; // temporary
@@ -383,7 +380,7 @@
      the reconstruction buffer, and proces a difference block for
      forward DCT */
   BlockUpdateDifference(cpi, FiltPtr, DCTInput, ReconPtr1,
-			MvDivisor, fp, FragIndex, PixelsPerLine,
+			MvDivisor, fp, 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 19:11:53 UTC (rev 14239)
+++ branches/theora-thusnelda/lib/enc/encode.c	2007-11-27 22:12:50 UTC (rev 14240)
@@ -163,10 +163,9 @@
 
 	/* 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 );
+	  TransformQuantizeBlock( cpi, fp, PixelsPerLine );
 	  
 	  /* Has the block got struck off (no MV and no data
 	     generated after DCT) If not then mark it and the
@@ -799,9 +798,9 @@
  {
    int j;
    for ( i = 0; i < cpi->pb.CodedBlockIndex; i++ ) {
-     FragIndex = cpi->pb.CodedBlockList[i];
+     fragment_t *fp = cpi->frag[0][i];
      for(j=0;j<64;j++)
-       cpi->pb.QFragQUAN[FragIndex][j] = cpi->pb.QFragData[FragIndex][j];
+       fp->QUAN[j] = fp->dct[j];
    }
  }
 #endif
@@ -829,35 +828,26 @@
   return 0;
 }
 
-static void AddMotionVector(CP_INSTANCE *cpi,
-                     MOTION_VECTOR *ThisMotionVector) {
-  cpi->MVList[cpi->MvListCount].x = ThisMotionVector->x;
-  cpi->MVList[cpi->MvListCount].y = ThisMotionVector->y;
-  cpi->MvListCount++;
+static void AddMotionVector(CP_INSTANCE *cpi, mv_t *mv) {
+  cpi->MVList[cpi->MvListCount++] = *mv;
 }
 
-static void SetFragMotionVectorAndMode(CP_INSTANCE *cpi,
-				       fragment_t *fp,
-				       MOTION_VECTOR *ThisMotionVector,
+static void SetFragMotionVectorAndMode(fragment_t *fp,
+				       mv_t *mv,
 				       int mode){
-  int FragIndex = fp - cpi->frag[0];
-
-  /* Note the coding mode and vector for each block */
-  cpi->pb.FragMVect[FragIndex].x = ThisMotionVector->x;
-  cpi->pb.FragMVect[FragIndex].y = ThisMotionVector->y;
+  fp->mv = *mv;
   fp->mode = mode;
 }
 
-static void SetMBMotionVectorsAndMode(CP_INSTANCE *cpi,
-				      macroblock_t *mp,
-				      MOTION_VECTOR *ThisMotionVector,
+static void SetMBMotionVectorsAndMode(macroblock_t *mp,
+				      mv_t *mv,
 				      int mode){
-  SetFragMotionVectorAndMode(cpi, mp->y[0], ThisMotionVector,mode);
-  SetFragMotionVectorAndMode(cpi, mp->y[1], ThisMotionVector,mode);
-  SetFragMotionVectorAndMode(cpi, mp->y[2], ThisMotionVector,mode);
-  SetFragMotionVectorAndMode(cpi, mp->y[3], ThisMotionVector,mode);
-  SetFragMotionVectorAndMode(cpi, mp->u, ThisMotionVector,mode);
-  SetFragMotionVectorAndMode(cpi, mp->v, ThisMotionVector,mode);
+  SetFragMotionVectorAndMode(mp->y[0], mv, mode);
+  SetFragMotionVectorAndMode(mp->y[1], mv, mode);
+  SetFragMotionVectorAndMode(mp->y[2], mv, mode);
+  SetFragMotionVectorAndMode(mp->y[3], mv, mode);
+  SetFragMotionVectorAndMode(mp->u, mv, mode);
+  SetFragMotionVectorAndMode(mp->v, mv, mode);
 }
 
 ogg_uint32_t PickModes(CP_INSTANCE *cpi,
@@ -890,20 +880,20 @@
                                            block */
   ogg_uint32_t  BestError;              /* Best error so far. */
 
-  MOTION_VECTOR FourMVect[6];     /* storage for last used vectors (one
+  mv_t          FourMVect[6];     /* storage for last used vectors (one
                                      entry for each block in MB) */
-  MOTION_VECTOR LastInterMVect;   /* storage for last used Inter frame
+  mv_t          LastInterMVect;   /* storage for last used Inter frame
                                      MB motion vector */
-  MOTION_VECTOR PriorLastInterMVect;  /* storage for prior last used
+  mv_t          PriorLastInterMVect;  /* storage for prior last used
                                          Inter frame MB motion vector */
-  MOTION_VECTOR TmpMVect;         /* Temporary MV storage */
-  MOTION_VECTOR LastGFMVect;      /* storage for last used Golden
+  mv_t          TmpMVect;         /* Temporary MV storage */
+  mv_t          LastGFMVect;      /* storage for last used Golden
                                      Frame MB motion vector */
-  MOTION_VECTOR InterMVect;       /* storage for motion vector */
-  MOTION_VECTOR InterMVectEx;     /* storage for motion vector result
+  mv_t          InterMVect;       /* storage for motion vector */
+  mv_t          InterMVectEx;     /* storage for motion vector result
                                      from exhaustive search */
-  MOTION_VECTOR GFMVect;          /* storage for motion vector */
-  MOTION_VECTOR ZeroVect;
+  mv_t          GFMVect;          /* storage for motion vector */
+  mv_t          ZeroVect;
 
   ogg_uint32_t UVRow;
   ogg_uint32_t UVColumn;
@@ -1010,28 +1000,28 @@
 
         /* Look at the intra coding error. */
         MBIntraError = GetMBIntraError( cpi, 
-					&cpi->frag[0][YFragIndex],
+					mp,
 					PixelsPerLine );
         BestError = (BestError > MBIntraError) ? MBIntraError : BestError;
 
         /* Get the golden frame error */
         MBGFError = GetMBInterError( cpi, cpi->yuvptr,
                                      cpi->pb.GoldenFrame, 
-				     &cpi->frag[0][YFragIndex],
+				     mp,
                                      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],
+					mp,
                                         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],
+					     mp,
                                              LastInterMVect.x,
                                              LastInterMVect.y, PixelsPerLine );
         BestError = (BestError > MBLastInterError) ?
@@ -1040,7 +1030,7 @@
         /* Measure error for prior last MV */
         MBPriorLastInterError =  GetMBInterError( cpi, cpi->yuvptr,
                                                   cpi->pb.LastFrameRecon,
-						  &cpi->frag[0][YFragIndex],
+						  mp,
                                                   PriorLastInterMVect.x,
                                                   PriorLastInterMVect.y,
                                                   PixelsPerLine );
@@ -1059,7 +1049,7 @@
              quick mode. */
           if ( cpi->info.quick_p ) {
             MBInterMVError = GetMBMVInterError( cpi, cpi->pb.LastFrameRecon,
-						&cpi->frag[0][YFragIndex],
+						mp,
 						PixelsPerLine,
                                                 cpi->MVPixelOffsetY,
                                                 &InterMVect );
@@ -1071,7 +1061,7 @@
 
               MBInterMVExError =
                 GetMBMVExhaustiveSearch( cpi, cpi->pb.LastFrameRecon,
-					 &cpi->frag[0][YFragIndex],
+					 mp,
                                          PixelsPerLine,
                                          &InterMVectEx );
 
@@ -1087,7 +1077,7 @@
             /* Use an exhaustive search */
             MBInterMVError =
               GetMBMVExhaustiveSearch( cpi, cpi->pb.LastFrameRecon,
-				       &cpi->frag[0][YFragIndex],
+				       mp,
                                        PixelsPerLine,
                                        &InterMVect );
           }
@@ -1109,14 +1099,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],
+					    mp,
                                             PixelsPerLine,
                                             cpi->MVPixelOffsetY, &GFMVect );
 
           /* Measure error for last GFMV */
           LastMBGF_MVError =  GetMBInterError( cpi, cpi->yuvptr,
                                                cpi->pb.GoldenFrame,
-					       &cpi->frag[0][YFragIndex],
+					       mp,
                                                LastGFMVect.x,
                                                LastGFMVect.y, PixelsPerLine );
 
@@ -1145,7 +1135,7 @@
           /* Get the 4MV error. */
           MBInterFOURMVError =
             GetFOURMVExhaustiveSearch( cpi, cpi->pb.LastFrameRecon,
-				       &cpi->frag[0][YFragIndex],
+				       mp,
                                        PixelsPerLine, FourMVect );
 
           /* If the improvement is great enough then use the four MV mode */
@@ -1167,27 +1157,24 @@
 
         if ( (BestError > cpi->InterTripOutThresh) &&
              (10 * BestError > MBIntraError * 7 ) ) {
-          SetMBMotionVectorsAndMode(cpi,mp,&ZeroVect,CODE_INTRA);
+          SetMBMotionVectorsAndMode(mp,&ZeroVect,CODE_INTRA);
         } else if ( BestError == MBInterError ) {
-          SetMBMotionVectorsAndMode(cpi,mp,&ZeroVect,CODE_INTER_NO_MV);
+          SetMBMotionVectorsAndMode(mp,&ZeroVect,CODE_INTER_NO_MV);
         } else if ( BestError == MBGFError ) {
-          SetMBMotionVectorsAndMode(cpi,mp,&ZeroVect,CODE_USING_GOLDEN);
+          SetMBMotionVectorsAndMode(mp,&ZeroVect,CODE_USING_GOLDEN);
         } else if ( BestError == MBLastInterError ) {
-          SetMBMotionVectorsAndMode(cpi,mp,&LastInterMVect,CODE_INTER_LAST_MV);
+          SetMBMotionVectorsAndMode(mp,&LastInterMVect,CODE_INTER_LAST_MV);
         } else if ( BestError == MBPriorLastInterError ) {
-          SetMBMotionVectorsAndMode(cpi,mp,&PriorLastInterMVect,CODE_INTER_PRIOR_LAST);
+          SetMBMotionVectorsAndMode(mp,&PriorLastInterMVect,CODE_INTER_PRIOR_LAST);
 
           /* Swap the prior and last MV cases over */
-          TmpMVect.x = PriorLastInterMVect.x;
-          TmpMVect.y = PriorLastInterMVect.y;
-          PriorLastInterMVect.x = LastInterMVect.x;
-          PriorLastInterMVect.y = LastInterMVect.y;
-          LastInterMVect.x = TmpMVect.x;
-          LastInterMVect.y = TmpMVect.y;
+          TmpMVect = PriorLastInterMVect;
+          PriorLastInterMVect = LastInterMVect;
+          LastInterMVect = TmpMVect;
 
         } else if ( BestError == MBInterMVError ) {
 
-          SetMBMotionVectorsAndMode(cpi,mp,&InterMVect,CODE_INTER_PLUS_MV);
+          SetMBMotionVectorsAndMode(mp,&InterMVect,CODE_INTER_PLUS_MV);
 
           /* Update Prior last mv with last mv */
           PriorLastInterMVect.x = LastInterMVect.x;
@@ -1201,7 +1188,7 @@
 
         } else if ( BestError == MBGF_MVError ) {
 
-          SetMBMotionVectorsAndMode(cpi,mp,&GFMVect,CODE_GOLDEN_MV);
+          SetMBMotionVectorsAndMode(mp,&GFMVect,CODE_GOLDEN_MV);
 
           /* Note last inter GF MV for future use */
           LastGFMVect.x = GFMVect.x;
@@ -1229,12 +1216,12 @@
             FourMVect[4].y = (FourMVect[4].y - 2) / 4;
           FourMVect[5].y = FourMVect[4].y;
 
-          SetFragMotionVectorAndMode(cpi, mp->y[0], &FourMVect[0],CODE_INTER_FOURMV);
-          SetFragMotionVectorAndMode(cpi, mp->y[1], &FourMVect[1],CODE_INTER_FOURMV);
-          SetFragMotionVectorAndMode(cpi, mp->y[2], &FourMVect[2],CODE_INTER_FOURMV);
-          SetFragMotionVectorAndMode(cpi, mp->y[3], &FourMVect[3],CODE_INTER_FOURMV);
-          SetFragMotionVectorAndMode(cpi, mp->u, &FourMVect[4],CODE_INTER_FOURMV);
-          SetFragMotionVectorAndMode(cpi, mp->v, &FourMVect[5],CODE_INTER_FOURMV);
+          SetFragMotionVectorAndMode(mp->y[0], &FourMVect[0],CODE_INTER_FOURMV);
+          SetFragMotionVectorAndMode(mp->y[1], &FourMVect[1],CODE_INTER_FOURMV);
+          SetFragMotionVectorAndMode(mp->y[2], &FourMVect[2],CODE_INTER_FOURMV);
+          SetFragMotionVectorAndMode(mp->y[3], &FourMVect[3],CODE_INTER_FOURMV);
+          SetFragMotionVectorAndMode(mp->u, &FourMVect[4],CODE_INTER_FOURMV);
+          SetFragMotionVectorAndMode(mp->v, &FourMVect[5],CODE_INTER_FOURMV);
 
           /* Note the four MVs values for current macro-block. */
           AddMotionVector( cpi, &FourMVect[0]);
@@ -1243,16 +1230,14 @@
           AddMotionVector( cpi, &FourMVect[3]);
 
           /* Update Prior last mv with last mv */
-          PriorLastInterMVect.x = LastInterMVect.x;
-          PriorLastInterMVect.y = LastInterMVect.y;
+          PriorLastInterMVect = LastInterMVect;
 
           /* Note last inter MV for future use */
-          LastInterMVect.x = FourMVect[3].x;
-          LastInterMVect.y = FourMVect[3].y;
+          LastInterMVect = FourMVect[3];
 
         } else {
 
-          SetMBMotionVectorsAndMode(cpi,mp,&ZeroVect,CODE_INTRA);
+          SetMBMotionVectorsAndMode(mp,&ZeroVect,CODE_INTRA);
         }
 
 

Modified: branches/theora-thusnelda/lib/enc/encoder_toplevel.c
===================================================================
--- branches/theora-thusnelda/lib/enc/encoder_toplevel.c	2007-11-27 19:11:53 UTC (rev 14239)
+++ branches/theora-thusnelda/lib/enc/encoder_toplevel.c	2007-11-27 22:12:50 UTC (rev 14240)
@@ -105,12 +105,13 @@
 static int CompressFrame( CP_INSTANCE *cpi ) {
   ogg_uint32_t  i,j;
   ogg_uint32_t  KFIndicator = 0;
+  fragment_t *fp = cpi->frag[0];
 
   /* Clear down the macro block level mode and MV arrays. */
-  for ( i = 0; i < cpi->pb.UnitFragments; i++ ) {
-    cpi->frag[0][i].mode = CODE_INTER_NO_MV;  /* Default coding mode */
-    cpi->pb.FragMVect[i].x = 0;
-    cpi->pb.FragMVect[i].y = 0;
+  for ( i = 0; i < cpi->pb.UnitFragments; i++, fp++ ) {
+    fp->mode = CODE_INTER_NO_MV;  /* Default coding mode */
+    fp->mv.x=0;
+    fp->mv.y=0;
   }
 
   /* Default to delta frames. */

Modified: branches/theora-thusnelda/lib/enc/frinit.c
===================================================================
--- branches/theora-thusnelda/lib/enc/frinit.c	2007-11-27 19:11:53 UTC (rev 14239)
+++ branches/theora-thusnelda/lib/enc/frinit.c	2007-11-27 22:12:50 UTC (rev 14240)
@@ -42,7 +42,6 @@
 
   /* free prior allocs if present */
   if(pbi->CodedBlockList) _ogg_free(pbi->CodedBlockList);
-  if(pbi->FragMVect) _ogg_free(pbi->FragMVect);
 #ifdef _TH_DEBUG_
   if(pbi->QFragTIME) _ogg_free(pbi->QFragTIME);
   if(pbi->QFragFREQ) _ogg_free(pbi->QFragFREQ);
@@ -59,7 +58,6 @@
   if(pbi->MBCodedFlags) _ogg_free(pbi->MBCodedFlags);
 
   pbi->CodedBlockList = 0;
-  pbi->FragMVect = 0;
   pbi->MBCodedFlags = 0;
   pbi->MBFullyFlags = 0;
   pbi->BlockMap = 0;
@@ -138,9 +136,6 @@
   pbi->CodedBlockList =
     _ogg_malloc(pbi->UnitFragments * sizeof(*pbi->CodedBlockList));
 
-  pbi->FragMVect =
-    _ogg_malloc(pbi->UnitFragments * sizeof(*pbi->FragMVect));
-
 #ifdef _TH_DEBUG_
 
   pbi->QFragTIME =
@@ -336,7 +331,7 @@
   {
     int row,col,frag;
     int scanx[4] = {0,1,0,1};
-    int scany[4] = {0,1,1,0};
+    int scany[4] = {0,0,1,1};
 
     for(row=0;row<cpi->macro_v;row++){
       int baserow = row*2;

Modified: branches/theora-thusnelda/lib/enc/mcomp.c
===================================================================
--- branches/theora-thusnelda/lib/enc/mcomp.c	2007-11-27 19:11:53 UTC (rev 14239)
+++ branches/theora-thusnelda/lib/enc/mcomp.c	2007-11-27 22:12:50 UTC (rev 14240)
@@ -95,10 +95,11 @@
     cpi->MVPixelOffsetY[i] = (cpi->MVOffsetY[i]*LineStepY) + cpi->MVOffsetX[i];
 }
 
-static ogg_uint32_t GetInterErr (CP_INSTANCE *cpi, unsigned char * NewDataPtr,
-                          unsigned char * RefDataPtr1,
-                          unsigned char * RefDataPtr2,
-                          ogg_uint32_t PixelsPerLine ) {
+static ogg_uint32_t GetInterErr (CP_INSTANCE *cpi, 
+				 unsigned char * NewDataPtr,
+				 unsigned char * RefDataPtr1,
+				 unsigned char * RefDataPtr2,
+				 ogg_uint32_t PixelsPerLine ) {
   ogg_int32_t   DiffVal;
   ogg_int32_t   RefOffset = (int)(RefDataPtr1 - RefDataPtr2);
   ogg_uint32_t  RefPixelsPerLine = PixelsPerLine + STRIDE_EXTRA;
@@ -119,13 +120,13 @@
 }
 
 static ogg_uint32_t GetHalfPixelSumAbsDiffs (CP_INSTANCE *cpi,
-                                      unsigned char * SrcData,
-                                      unsigned char * RefDataPtr1,
-                                      unsigned char * RefDataPtr2,
-                                      ogg_uint32_t PixelsPerLine,
-                                      ogg_uint32_t ErrorSoFar,
-                                      ogg_uint32_t BestSoFar ) {
-
+					     unsigned char * SrcData,
+					     unsigned char * RefDataPtr1,
+					     unsigned char * RefDataPtr2,
+					     ogg_uint32_t PixelsPerLine,
+					     ogg_uint32_t ErrorSoFar,
+					     ogg_uint32_t BestSoFar ) {
+  
   ogg_uint32_t  DiffVal = ErrorSoFar;
   ogg_int32_t   RefOffset = (int)(RefDataPtr1 - RefDataPtr2);
   ogg_uint32_t  RefPixelsPerLine = PixelsPerLine + STRIDE_EXTRA;
@@ -144,7 +145,7 @@
 }
 
 ogg_uint32_t GetMBIntraError (CP_INSTANCE *cpi, 
-			      fragment_t *fp,
+			      macroblock_t *mp,
                               ogg_uint32_t PixelsPerLine ) {
 
   ogg_uint32_t  IntraError = 0;
@@ -152,18 +153,15 @@
 
   /* Add together the intra errors for those blocks in the macro block
      that are coded (Y only) */
-  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;
+  if ( mp->y[0] && mp->y[0]->coded )
+    IntraError += dsp_intra8x8_err (cpi->dsp, &cpi->yuvptr[mp->y[0]->raw_index],PixelsPerLine);
+  if ( mp->y[1] && mp->y[1]->coded )
+    IntraError += dsp_intra8x8_err (cpi->dsp, &cpi->yuvptr[mp->y[1]->raw_index],PixelsPerLine);
+  if ( mp->y[2] && mp->y[2]->coded )
+    IntraError += dsp_intra8x8_err (cpi->dsp, &cpi->yuvptr[mp->y[2]->raw_index],PixelsPerLine);
+  if ( mp->y[3] && mp->y[3]->coded )
+    IntraError += dsp_intra8x8_err (cpi->dsp, &cpi->yuvptr[mp->y[3]->raw_index],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);
-
   dsp_restore_fpu (cpi->dsp);
   return IntraError;
 }
@@ -171,7 +169,7 @@
 ogg_uint32_t GetMBInterError (CP_INSTANCE *cpi,
                               unsigned char * SrcPtr,
                               unsigned char * RefPtr,
-			      fragment_t *fp,
+			      macroblock_t *mp,
                               ogg_int32_t LastXMV,
                               ogg_int32_t LastYMV,
                               ogg_uint32_t PixelsPerLine ) {
@@ -202,33 +200,31 @@
 
   /* Add together the errors for those blocks in the macro block that
      are coded (Y only) */
-  if ( fp[0].coded ) {
-    SrcPtr1 = &SrcPtr[fp[0].raw_index];
-    RefPtr1 = &RefPtr[fp[0].recon_index + RefPixelOffset];
+  if ( mp->y[0] && mp->y[0]->coded ) {
+    SrcPtr1 = &SrcPtr[mp->y[0]->raw_index];
+    RefPtr1 = &RefPtr[mp->y[0]->recon_index + RefPixelOffset];
     InterError += GetInterErr(cpi, SrcPtr1, RefPtr1,
                                  &RefPtr1[RefPtr2Offset], PixelsPerLine );
   }
 
-  if ( fp[1].coded ) {
-    SrcPtr1 = &SrcPtr[fp[1].raw_index];
-    RefPtr1 = &RefPtr[fp[1].recon_index + RefPixelOffset];
+  if ( mp->y[1] && mp->y[1]->coded ) {
+    SrcPtr1 = &SrcPtr[mp->y[1]->raw_index];
+    RefPtr1 = &RefPtr[mp->y[1]->recon_index + RefPixelOffset];
     InterError += GetInterErr(cpi, SrcPtr1, RefPtr1,
 			      &RefPtr1[RefPtr2Offset], PixelsPerLine );
     
   }
   
-  fp += cpi->pb.HFragments;
-
-  if ( fp[0].coded ) {
-    SrcPtr1 = &SrcPtr[fp[0].raw_index];
-    RefPtr1 = &RefPtr[fp[0].recon_index + RefPixelOffset];
+  if ( mp->y[2] && mp->y[2]->coded ) {
+    SrcPtr1 = &SrcPtr[mp->y[2]->raw_index];
+    RefPtr1 = &RefPtr[mp->y[2]->recon_index + RefPixelOffset];
     InterError += GetInterErr(cpi, SrcPtr1, RefPtr1,
                                  &RefPtr1[RefPtr2Offset], PixelsPerLine );
   }
 
-  if ( fp[1].coded ) {
-    SrcPtr1 = &SrcPtr[fp[1].raw_index];
-    RefPtr1 = &RefPtr[fp[1].recon_index + RefPixelOffset];
+  if ( mp->y[3] && mp->y[3]->coded ) {
+    SrcPtr1 = &SrcPtr[mp->y[3]->raw_index];
+    RefPtr1 = &RefPtr[mp->y[3]->recon_index + RefPixelOffset];
     InterError += GetInterErr(cpi, SrcPtr1, RefPtr1,
 			      &RefPtr1[RefPtr2Offset], PixelsPerLine );
   }
@@ -240,10 +236,10 @@
 
 ogg_uint32_t GetMBMVInterError (CP_INSTANCE *cpi,
                                 unsigned char * RefFramePtr,
-				fragment_t *fp,
+				macroblock_t *mp,
                                 ogg_uint32_t PixelsPerLine,
                                 ogg_int32_t *MVPixelOffset,
-                                MOTION_VECTOR *MV ) {
+                                mv_t *MV ) {
   ogg_uint32_t  Error = 0;
   ogg_uint32_t  MinError;
   ogg_uint32_t  InterMVError = 0;
@@ -253,14 +249,14 @@
   ogg_int32_t   step;
   ogg_int32_t   SearchSite=0;
 
-  unsigned char *SrcPtr[4] = {NULL,NULL,NULL,NULL};
-  unsigned char *RefPtr=NULL;
-  unsigned char *CandidateBlockPtr=NULL;
-  unsigned char *BestBlockPtr=NULL;
+  unsigned char *SrcPtr[4] = {NULL, NULL, NULL, NULL};
+  unsigned char *RefPtr[4] = {NULL, NULL, NULL, NULL};
+  int            BestBlockOffset=0;
 
   ogg_uint32_t  RefRow2Offset = cpi->recon_stride[0] * 8;
 
-  int    MBlockDispFrags[4];
+  int           disp[4];
+  int           off = 0;
 
   /* Half pixel variables */
   ogg_int32_t   HalfPixelError;
@@ -273,41 +269,39 @@
 
   /* Note which of the four blocks in the macro block are to be
      included in the search. */
-  MBlockDispFrags[0] = fp[0].coded;
-  MBlockDispFrags[1] = fp[1].coded;
-  MBlockDispFrags[2] = fp[cpi->frag_h[0]].coded;
-  MBlockDispFrags[3] = fp[cpi->frag_h[0] + 1].coded;
+  disp[0] = (mp->y[0] && mp->y[0]->coded);
+  disp[1] = (mp->y[1] && mp->y[1]->coded);
+  disp[2] = (mp->y[2] && mp->y[2]->coded);
+  disp[3] = (mp->y[3] && mp->y[3]->coded);
 
-  /* Set up the source pointers for the four source blocks.  */
-  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[fp->recon_index];
-
-  /* Check the 0,0 candidate. */
-  if ( MBlockDispFrags[0] ) {
-    Error += dsp_sad8x8 (cpi->dsp, SrcPtr[0], PixelsPerLine, RefPtr,
+  if(disp[0]){
+    SrcPtr[0] = &cpi->yuvptr[mp->y[0]->raw_index];
+    RefPtr[0] = &RefFramePtr[mp->y[0]->recon_index];
+    Error += dsp_sad8x8 (cpi->dsp, SrcPtr[0], PixelsPerLine, RefPtr[0],
                          PixelsPerLine + STRIDE_EXTRA);
   }
-  if ( MBlockDispFrags[1] ) {
-    Error += dsp_sad8x8 (cpi->dsp, SrcPtr[1], PixelsPerLine, RefPtr + 8,
+  if(disp[1]){
+    SrcPtr[1] = &cpi->yuvptr[mp->y[1]->raw_index];
+    RefPtr[1] = &RefFramePtr[mp->y[1]->recon_index];
+    Error += dsp_sad8x8 (cpi->dsp, SrcPtr[1], PixelsPerLine, RefPtr[1],
                          PixelsPerLine + STRIDE_EXTRA);
   }
-  if ( MBlockDispFrags[2] ) {
-    Error += dsp_sad8x8 (cpi->dsp, SrcPtr[2], PixelsPerLine, RefPtr + RefRow2Offset,
+  if(disp[2]){
+    SrcPtr[2] = &cpi->yuvptr[mp->y[2]->raw_index];
+    RefPtr[2] = &RefFramePtr[mp->y[2]->recon_index];
+    Error += dsp_sad8x8 (cpi->dsp, SrcPtr[2], PixelsPerLine, RefPtr[2],
                          PixelsPerLine + STRIDE_EXTRA);
   }
-  if ( MBlockDispFrags[3] ) {
-    Error += dsp_sad8x8 (cpi->dsp, SrcPtr[3], PixelsPerLine, RefPtr + RefRow2Offset + 8,
+  if(disp[3]){
+    SrcPtr[3] = &cpi->yuvptr[mp->y[3]->raw_index];
+    RefPtr[3] = &RefFramePtr[mp->y[3]->recon_index];
+    Error += dsp_sad8x8 (cpi->dsp, SrcPtr[3], PixelsPerLine, RefPtr[3],
                          PixelsPerLine + STRIDE_EXTRA);
   }
 
   /* Set starting values to results of 0, 0 vector. */
   MinError = Error;
-  BestBlockPtr = RefPtr;
+  BestBlockOffset = 0;
   x = 0;
   y = 0;
   MV->x = 0;
@@ -318,38 +312,32 @@
     /* Search the 8-neighbours at distance pertinent to current step.*/
     for ( i=0; i<8; i++ ) {
       /* Set pointer to next candidate matching block. */
-      CandidateBlockPtr = RefPtr + MVPixelOffset[SearchSite];
-
-      /* Reset error */
+      int loff = off + MVPixelOffset[SearchSite];
       Error = 0;
-
+      
       /* Get the score for the current offset */
-      if ( MBlockDispFrags[0] ) {
-        Error += dsp_sad8x8 (cpi->dsp, SrcPtr[0], PixelsPerLine, CandidateBlockPtr,
+      if ( disp[0] ) 
+        Error += dsp_sad8x8 (cpi->dsp, SrcPtr[0], PixelsPerLine, RefPtr[0] + loff,
                              PixelsPerLine + STRIDE_EXTRA);
-      }
+      
+      if ( disp[1] && (Error < MinError) ) 
+        Error += dsp_sad8x8_thres (cpi->dsp, SrcPtr[1], PixelsPerLine, RefPtr[1] + loff,
+				   PixelsPerLine + STRIDE_EXTRA, MinError);
+      
+      if ( disp[2] && (Error < MinError) ) 
+        Error += dsp_sad8x8_thres (cpi->dsp, SrcPtr[2], PixelsPerLine, RefPtr[2] + loff,
+				   PixelsPerLine + STRIDE_EXTRA, MinError);
+      
+      if ( disp[3] && (Error < MinError) ) 
+        Error += dsp_sad8x8_thres (cpi->dsp, SrcPtr[3], PixelsPerLine, RefPtr[3] + loff,
+				   PixelsPerLine + STRIDE_EXTRA, MinError);
 
-      if ( MBlockDispFrags[1] && (Error < MinError) ) {
-        Error += dsp_sad8x8_thres (cpi->dsp, SrcPtr[1], PixelsPerLine, CandidateBlockPtr + 8,
-                             PixelsPerLine + STRIDE_EXTRA, MinError);
-      }
-
-      if ( MBlockDispFrags[2] && (Error < MinError) ) {
-        Error += dsp_sad8x8_thres (cpi->dsp, SrcPtr[2], PixelsPerLine, CandidateBlockPtr + RefRow2Offset,
-                             PixelsPerLine + STRIDE_EXTRA, MinError);
-      }
-
-      if ( MBlockDispFrags[3] && (Error < MinError) ) {
-        Error += dsp_sad8x8_thres (cpi->dsp, SrcPtr[3], PixelsPerLine, CandidateBlockPtr + RefRow2Offset + 8,
-                             PixelsPerLine + STRIDE_EXTRA, MinError);
-      }
-
       if ( Error < MinError ) {
         /* Remember best match. */
         MinError = Error;
-        BestBlockPtr = CandidateBlockPtr;
-
-                                /* Where is it. */
+        BestBlockOffset = loff;
+	
+	/* Where is it. */
         x = MV->x + cpi->MVOffsetX[SearchSite];
         y = MV->y + cpi->MVOffsetY[SearchSite];
       }
@@ -359,7 +347,7 @@
     }
 
     /* Move to best location this step. */
-    RefPtr = BestBlockPtr;
+    off = BestBlockOffset;
     MV->x = x;
     MV->y = y;
   }
@@ -376,32 +364,32 @@
   for ( i=0; i < 9; i++ ) {
     HalfPixelError = 0;
 
-    if ( MBlockDispFrags[0] ) {
-      RefDataPtr1 = BestBlockPtr;
+    if ( disp[0] ) {
+      RefDataPtr1 = RefPtr[0] + BestBlockOffset;
       RefDataPtr2 = RefDataPtr1 + cpi->HalfPixelRef2Offset[i];
       HalfPixelError =
         GetHalfPixelSumAbsDiffs(cpi, SrcPtr[0], RefDataPtr1, RefDataPtr2,
                          PixelsPerLine, HalfPixelError, BestHalfPixelError );
     }
 
-    if ( MBlockDispFrags[1]  && (HalfPixelError < BestHalfPixelError) ) {
-      RefDataPtr1 = BestBlockPtr + 8;
+    if ( disp[1]  && (HalfPixelError < BestHalfPixelError) ) {
+      RefDataPtr1 = RefPtr[1] + BestBlockOffset;
       RefDataPtr2 = RefDataPtr1 + cpi->HalfPixelRef2Offset[i];
       HalfPixelError =
         GetHalfPixelSumAbsDiffs(cpi, SrcPtr[1], RefDataPtr1, RefDataPtr2,
                          PixelsPerLine, HalfPixelError, BestHalfPixelError );
     }
 
-    if ( MBlockDispFrags[2] && (HalfPixelError < BestHalfPixelError) ) {
-      RefDataPtr1 = BestBlockPtr + RefRow2Offset;
+    if ( disp[2] && (HalfPixelError < BestHalfPixelError) ) {
+      RefDataPtr1 = RefPtr[2] + BestBlockOffset;
       RefDataPtr2 = RefDataPtr1 + cpi->HalfPixelRef2Offset[i];
       HalfPixelError =
         GetHalfPixelSumAbsDiffs(cpi, SrcPtr[2], RefDataPtr1, RefDataPtr2,
                          PixelsPerLine, HalfPixelError, BestHalfPixelError );
     }
 
-    if ( MBlockDispFrags[3] && (HalfPixelError < BestHalfPixelError) ) {
-      RefDataPtr1 = BestBlockPtr + RefRow2Offset + 8;
+    if ( disp[3] && (HalfPixelError < BestHalfPixelError) ) { 
+      RefDataPtr1 = RefPtr[3] + BestBlockOffset;
       RefDataPtr2 = RefDataPtr1 + cpi->HalfPixelRef2Offset[i];
       HalfPixelError =
         GetHalfPixelSumAbsDiffs(cpi, SrcPtr[3], RefDataPtr1, RefDataPtr2,
@@ -419,7 +407,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, fp,
+  InterMVError = GetMBInterError( cpi, cpi->yuvptr, RefFramePtr, mp,
                                   MV->x, MV->y, PixelsPerLine );
   
   dsp_restore_fpu (cpi->dsp);
@@ -430,9 +418,9 @@
 
 ogg_uint32_t GetMBMVExhaustiveSearch (CP_INSTANCE *cpi,
                                       unsigned char *RefFramePtr,
-				      fragment_t *fp,
+				      macroblock_t *mp,
                                       ogg_uint32_t PixelsPerLine,
-                                      MOTION_VECTOR *MV ) {
+                                      mv_t *MV ) {
   ogg_uint32_t  Error = 0;
   ogg_uint32_t  MinError = HUGE_ERROR;
   ogg_uint32_t  InterMVError = 0;
@@ -441,80 +429,87 @@
   ogg_int32_t   x=0, y=0;
 
   unsigned char *SrcPtr[4] = {NULL,NULL,NULL,NULL};
-  unsigned char *RefPtr;
-  unsigned char *CandidateBlockPtr=NULL;
-  unsigned char *BestBlockPtr=NULL;
+  unsigned char *RefPtr[4] = {NULL,NULL,NULL,NULL};
+  int            BestBlockOffset=0;
 
-  ogg_uint32_t  RefRow2Offset = cpi->recon_stride[0] * 8;
+  int            disp[4];
 
-  int    MBlockDispFrags[4];
-
   /* Half pixel variables */
   ogg_int32_t   HalfPixelError;
   ogg_int32_t   BestHalfPixelError;
   unsigned char   BestHalfOffset;
   unsigned char * RefDataPtr1;
   unsigned char * RefDataPtr2;
+  int off;
 
   dsp_save_fpu (cpi->dsp);
 
   /* Note which of the four blocks in the macro block are to be
      included in the search. */
-  MBlockDispFrags[0] = fp[0].coded;
-  MBlockDispFrags[1] = fp[1].coded;
-  MBlockDispFrags[2] = fp[cpi->frag_h[0]].coded;
-  MBlockDispFrags[3] = fp[cpi->frag_h[0] + 1].coded;
+  disp[0] = (mp->y[0] && mp->y[0]->coded);
+  disp[1] = (mp->y[1] && mp->y[1]->coded);
+  disp[2] = (mp->y[2] && mp->y[2]->coded);
+  disp[3] = (mp->y[3] && mp->y[3]->coded);
 
-  /* Set up the source pointers for the four source blocks. */
-  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);
+  if(disp[0]){
+    SrcPtr[0] = &cpi->yuvptr[mp->y[0]->raw_index];
+    RefPtr[0] = &RefFramePtr[mp->y[0]->recon_index];
+  }
+  if(disp[1]){
+    SrcPtr[1] = &cpi->yuvptr[mp->y[1]->raw_index];
+    RefPtr[1] = &RefFramePtr[mp->y[1]->recon_index];
+  }
+  if(disp[2]){
+    SrcPtr[2] = &cpi->yuvptr[mp->y[2]->raw_index];
+    RefPtr[2] = &RefFramePtr[mp->y[2]->recon_index];
+  }
+  if(disp[3]){
+    SrcPtr[3] = &cpi->yuvptr[mp->y[3]->raw_index];
+    RefPtr[3] = &RefFramePtr[mp->y[3]->recon_index];
+  }
 
+  off = - ((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;
-
+    int loff = off;
+    
     for ( j = 0; j < (ogg_int32_t)MAX_MV_EXTENT; j++ ) {
-      /* Reset error */
       Error = 0;
 
       /* Summ errors for each block. */
-      if ( MBlockDispFrags[0] ) {
-        Error += dsp_sad8x8 (cpi->dsp, SrcPtr[0], PixelsPerLine, CandidateBlockPtr,
+      if ( disp[0] ) {
+        Error += dsp_sad8x8 (cpi->dsp, SrcPtr[0], PixelsPerLine, RefPtr[0]+loff,
                              PixelsPerLine + STRIDE_EXTRA);
       }
-      if ( MBlockDispFrags[1] ){
-        Error += dsp_sad8x8 (cpi->dsp, SrcPtr[1], PixelsPerLine, CandidateBlockPtr + 8,
+      if ( disp[1] ){
+        Error += dsp_sad8x8 (cpi->dsp, SrcPtr[1], PixelsPerLine, RefPtr[1]+loff,
                              PixelsPerLine + STRIDE_EXTRA);
       }
-      if ( MBlockDispFrags[2] ){
-        Error += dsp_sad8x8 (cpi->dsp, SrcPtr[2], PixelsPerLine, CandidateBlockPtr + RefRow2Offset,
+      if ( disp[2] ){
+        Error += dsp_sad8x8 (cpi->dsp, SrcPtr[2], PixelsPerLine, RefPtr[2]+loff,
                              PixelsPerLine + STRIDE_EXTRA);
       }
-      if ( MBlockDispFrags[3] ){
-        Error += dsp_sad8x8 (cpi->dsp, SrcPtr[3], PixelsPerLine, CandidateBlockPtr + RefRow2Offset + 8,
+      if ( disp[3] ){
+        Error += dsp_sad8x8 (cpi->dsp, SrcPtr[3], PixelsPerLine, RefPtr[3]+loff,
                              PixelsPerLine + STRIDE_EXTRA);
       }
-
+      
       /* Was this the best so far */
       if ( Error < MinError ) {
         MinError = Error;
-        BestBlockPtr = CandidateBlockPtr;
+        BestBlockOffset = loff;
         x = 16 + j - MAX_MV_EXTENT;
         y = 16 + i - MAX_MV_EXTENT;
       }
-
+      
       /* Move the the next site */
-      CandidateBlockPtr ++;
+      loff ++;
     }
 
     /* Move on to the next row. */
-    RefPtr += cpi->recon_stride[0];
+    off += cpi->recon_stride[0];
 
   }
 
@@ -530,36 +525,36 @@
   for ( i=0; i < 9; i++ ) {
     HalfPixelError = 0;
 
-    if ( MBlockDispFrags[0] ) {
-      RefDataPtr1 = BestBlockPtr;
+    if ( disp[0] ) {
+      RefDataPtr1 = RefPtr[0]+BestBlockOffset;
       RefDataPtr2 = RefDataPtr1 + cpi->HalfPixelRef2Offset[i];
       HalfPixelError =
         GetHalfPixelSumAbsDiffs(cpi, SrcPtr[0], RefDataPtr1, RefDataPtr2,
-                         PixelsPerLine, HalfPixelError, BestHalfPixelError );
+				PixelsPerLine, HalfPixelError, BestHalfPixelError );
     }
 
-    if ( MBlockDispFrags[1]  && (HalfPixelError < BestHalfPixelError) ) {
-      RefDataPtr1 = BestBlockPtr + 8;
+    if ( disp[1]  && (HalfPixelError < BestHalfPixelError) ) {
+      RefDataPtr1 = RefPtr[1]+BestBlockOffset;
       RefDataPtr2 = RefDataPtr1 + cpi->HalfPixelRef2Offset[i];
       HalfPixelError =
         GetHalfPixelSumAbsDiffs(cpi, SrcPtr[1], RefDataPtr1, RefDataPtr2,
-                         PixelsPerLine, HalfPixelError, BestHalfPixelError );
+				PixelsPerLine, HalfPixelError, BestHalfPixelError );
     }
-
-    if ( MBlockDispFrags[2] && (HalfPixelError < BestHalfPixelError) ) {
-      RefDataPtr1 = BestBlockPtr + RefRow2Offset;
+    
+    if ( disp[2] && (HalfPixelError < BestHalfPixelError) ) {
+      RefDataPtr1 = RefPtr[2]+BestBlockOffset;
       RefDataPtr2 = RefDataPtr1 + cpi->HalfPixelRef2Offset[i];
       HalfPixelError =
         GetHalfPixelSumAbsDiffs(cpi, SrcPtr[2], RefDataPtr1, RefDataPtr2,
-                         PixelsPerLine, HalfPixelError, BestHalfPixelError );
+				PixelsPerLine, HalfPixelError, BestHalfPixelError );
     }
-
-    if ( MBlockDispFrags[3] && (HalfPixelError < BestHalfPixelError) ) {
-      RefDataPtr1 = BestBlockPtr + RefRow2Offset + 8;
+    
+    if ( disp[3] && (HalfPixelError < BestHalfPixelError) ) {
+      RefDataPtr1 = RefPtr[3]+BestBlockOffset;
       RefDataPtr2 = RefDataPtr1 + cpi->HalfPixelRef2Offset[i];
       HalfPixelError =
         GetHalfPixelSumAbsDiffs(cpi, SrcPtr[3], RefDataPtr1, RefDataPtr2,
-                         PixelsPerLine, HalfPixelError, BestHalfPixelError );
+				PixelsPerLine, HalfPixelError, BestHalfPixelError );
     }
 
     if ( HalfPixelError < BestHalfPixelError ){
@@ -573,7 +568,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, fp,
+  InterMVError = GetMBInterError( cpi, cpi->yuvptr, RefFramePtr, mp,
                                   MV->x, MV->y, PixelsPerLine );
 
   dsp_restore_fpu (cpi->dsp);
@@ -583,10 +578,10 @@
 }
 
 static ogg_uint32_t GetBMVExhaustiveSearch (CP_INSTANCE *cpi,
-                                            unsigned char * RefFramePtr,
+                                            unsigned char *RefFramePtr,
 					    fragment_t *fp,
                                             ogg_uint32_t PixelsPerLine,
-                                            MOTION_VECTOR *MV ) {
+                                            mv_t *MV ) {
   ogg_uint32_t  Error = 0;
   ogg_uint32_t  MinError = HUGE_ERROR;
   ogg_uint32_t  InterMVError = 0;
@@ -673,36 +668,35 @@
 
 ogg_uint32_t GetFOURMVExhaustiveSearch (CP_INSTANCE *cpi,
                                         unsigned char * RefFramePtr,
-					fragment_t *fp,
+					macroblock_t *mp,
                                         ogg_uint32_t PixelsPerLine,
-                                        MOTION_VECTOR *MV ) {
+                                        mv_t *MV ) {
   ogg_uint32_t  InterMVError;
-  
   dsp_save_fpu (cpi->dsp);
 
   /* 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 ( fp[0].coded &&
-       fp[1].coded &&
-       fp[cpi->frag_h[0]].coded &&
-       fp[cpi->frag_h[0]+1].coded ) {
+  if ( mp->y[0] && mp->y[0]->coded &&
+       mp->y[1] && mp->y[1]->coded &&
+       mp->y[2] && mp->y[2]->coded &&
+       mp->y[3] && mp->y[3]->coded ) {
     
     /* Reset the error score. */
     InterMVError = 0;
     
     /* Get the error component from each coded block */
     InterMVError +=
-      GetBMVExhaustiveSearch(cpi, RefFramePtr, fp,
+      GetBMVExhaustiveSearch(cpi, RefFramePtr, mp->y[0],
                              PixelsPerLine, &(MV[0]) );
     InterMVError +=
-      GetBMVExhaustiveSearch(cpi, RefFramePtr, &fp[1],
+      GetBMVExhaustiveSearch(cpi, RefFramePtr, mp->y[1],
                              PixelsPerLine, &(MV[1]) );
     InterMVError +=
-      GetBMVExhaustiveSearch(cpi, RefFramePtr, &fp[cpi->frag_h[0]],
+      GetBMVExhaustiveSearch(cpi, RefFramePtr, mp->y[2],
                              PixelsPerLine, &(MV[2]) );
     InterMVError +=
-      GetBMVExhaustiveSearch(cpi, RefFramePtr, &fp[cpi->frag_h[0]+1],
+      GetBMVExhaustiveSearch(cpi, RefFramePtr, mp->y[3],
                              PixelsPerLine, &(MV[3]) );
   }else{
     InterMVError = HUGE_ERROR;
@@ -714,3 +708,5 @@
   return InterMVError;
 }
 
+
+



More information about the commits mailing list