[Theora-dev] Theora mcomp tuning...

Adam D. Moss adam at gimp.org
Wed Sep 8 10:27:38 PDT 2004


Hi there.

This patch changes the block selection to quantify error
based on the sum of the squared differences of the pixel
values rather than the sum of the absolute differences,
the former conventionally and statistically seeming like
the preferable thing to do.

The patch also const'ifies some parameters (which doesn't
affect code quality on recent GCCs but might help on older/
other compilers).

Finally, it also incorporates Wim's fix for the reference
encoder bug where it counted the summed error twice for a
certain block choice.

The win from this patch is usually only 1-2% improvement
in video bandwidth (compared to a trunk build with Wim's
fix already added, for fair comparison) but I've seen as
much as 20% improvement  (and sometimes the result is
even a fraction of a % bigger, ho hum), most pronounced
at lower quality levels.

Regards,
--Adam

-------------- next part --------------
Index: lib/mcomp.c
===================================================================
--- lib/mcomp.c	(revision 7715)
+++ lib/mcomp.c	(working copy)
@@ -96,10 +96,10 @@
     cpi->MVPixelOffsetY[i] = (cpi->MVOffsetY[i]*LineStepY) + cpi->MVOffsetX[i];
 }
 
-static ogg_uint32_t GetInterErr (unsigned char * NewDataPtr,
-                          unsigned char * RefDataPtr1,
-                          unsigned char * RefDataPtr2,
-                          ogg_uint32_t PixelsPerLine ) {
+static ogg_uint32_t GetInterErr (const unsigned char * NewDataPtr,
+                                 const unsigned char * RefDataPtr1,
+                                 const unsigned char * RefDataPtr2,
+                                 ogg_uint32_t PixelsPerLine ) {
   ogg_uint32_t  i;
   ogg_int32_t   XSum=0;
   ogg_int32_t   XXSum=0;
@@ -204,23 +204,29 @@
   return (( (XXSum<<6) - XSum*XSum ));
 }
 
-static ogg_uint32_t GetSumAbsDiffs  (unsigned char * NewDataPtr,
-                              unsigned char  * RefDataPtr,
-                              ogg_uint32_t PixelsPerLine,
-                              ogg_uint32_t ErrorSoFar) {
+/* We hope that the compiler is sensible enough to inline this.  Usually is. */
+static ogg_uint32_t SquaredDifference(const int a,
+                                      const int b) {
+  return ((a-b)*(a-b));
+}
+
+static ogg_uint32_t GetSumSqrDiffs  (const unsigned char * NewDataPtr,
+                                     const unsigned char * RefDataPtr,
+                                     ogg_uint32_t PixelsPerLine,
+                                     ogg_uint32_t ErrorSoFar) {
   ogg_uint32_t  i;
   ogg_uint32_t  DiffVal = ErrorSoFar;
 
   /* Decide on standard or MMX implementation */
   for ( i=0; i < BLOCK_HEIGHT_WIDTH; i++ ) {
-    DiffVal += abs( ((int)NewDataPtr[0]) - ((int)RefDataPtr[0]) );
-    DiffVal += abs( ((int)NewDataPtr[1]) - ((int)RefDataPtr[1]) );
-    DiffVal += abs( ((int)NewDataPtr[2]) - ((int)RefDataPtr[2]) );
-    DiffVal += abs( ((int)NewDataPtr[3]) - ((int)RefDataPtr[3]) );
-    DiffVal += abs( ((int)NewDataPtr[4]) - ((int)RefDataPtr[4]) );
-    DiffVal += abs( ((int)NewDataPtr[5]) - ((int)RefDataPtr[5]) );
-    DiffVal += abs( ((int)NewDataPtr[6]) - ((int)RefDataPtr[6]) );
-    DiffVal += abs( ((int)NewDataPtr[7]) - ((int)RefDataPtr[7]) );
+    DiffVal += SquaredDifference( NewDataPtr[0], RefDataPtr[0] );
+    DiffVal += SquaredDifference( NewDataPtr[1], RefDataPtr[1] );
+    DiffVal += SquaredDifference( NewDataPtr[2], RefDataPtr[2] );
+    DiffVal += SquaredDifference( NewDataPtr[3], RefDataPtr[3] );
+    DiffVal += SquaredDifference( NewDataPtr[4], RefDataPtr[4] );
+    DiffVal += SquaredDifference( NewDataPtr[5], RefDataPtr[5] );
+    DiffVal += SquaredDifference( NewDataPtr[6], RefDataPtr[6] );
+    DiffVal += SquaredDifference( NewDataPtr[7], RefDataPtr[7] );
 
     /* Step to next row of block. */
     NewDataPtr += PixelsPerLine;
@@ -230,23 +236,23 @@
   return DiffVal;
 }
 
-static ogg_uint32_t GetNextSumAbsDiffs (unsigned char * NewDataPtr,
-                                 unsigned char * RefDataPtr,
-                                 ogg_uint32_t PixelsPerLine,
-                                 ogg_uint32_t ErrorSoFar,
-                                 ogg_uint32_t BestSoFar ) {
+static ogg_uint32_t GetNextSumSqrDiffs (const unsigned char * NewDataPtr,
+                                        const unsigned char * RefDataPtr,
+                                        ogg_uint32_t PixelsPerLine,
+                                        ogg_uint32_t ErrorSoFar,
+                                        ogg_uint32_t BestSoFar ) {
   ogg_uint32_t  i;
   ogg_uint32_t  DiffVal = ErrorSoFar;
 
   for ( i=0; i < BLOCK_HEIGHT_WIDTH; i++ ) {
-    DiffVal += abs( ((int)NewDataPtr[0]) - ((int)RefDataPtr[0]) );
-    DiffVal += abs( ((int)NewDataPtr[1]) - ((int)RefDataPtr[1]) );
-    DiffVal += abs( ((int)NewDataPtr[2]) - ((int)RefDataPtr[2]) );
-    DiffVal += abs( ((int)NewDataPtr[3]) - ((int)RefDataPtr[3]) );
-    DiffVal += abs( ((int)NewDataPtr[4]) - ((int)RefDataPtr[4]) );
-    DiffVal += abs( ((int)NewDataPtr[5]) - ((int)RefDataPtr[5]) );
-    DiffVal += abs( ((int)NewDataPtr[6]) - ((int)RefDataPtr[6]) );
-    DiffVal += abs( ((int)NewDataPtr[7]) - ((int)RefDataPtr[7]) );
+    DiffVal += SquaredDifference( NewDataPtr[0], RefDataPtr[0] );
+    DiffVal += SquaredDifference( NewDataPtr[1], RefDataPtr[1] );
+    DiffVal += SquaredDifference( NewDataPtr[2], RefDataPtr[2] );
+    DiffVal += SquaredDifference( NewDataPtr[3], RefDataPtr[3] );
+    DiffVal += SquaredDifference( NewDataPtr[4], RefDataPtr[4] );
+    DiffVal += SquaredDifference( NewDataPtr[5], RefDataPtr[5] );
+    DiffVal += SquaredDifference( NewDataPtr[6], RefDataPtr[6] );
+    DiffVal += SquaredDifference( NewDataPtr[7], RefDataPtr[7] );
 
     if ( DiffVal > BestSoFar )break;
 
@@ -258,12 +264,12 @@
   return DiffVal;
 }
 
-static ogg_uint32_t GetHalfPixelSumAbsDiffs (unsigned char * SrcData,
-                                      unsigned char * RefDataPtr1,
-                                      unsigned char * RefDataPtr2,
-                                      ogg_uint32_t PixelsPerLine,
-                                      ogg_uint32_t ErrorSoFar,
-                                      ogg_uint32_t BestSoFar ) {
+static ogg_uint32_t GetHalfPixelSumSqrDiffs (const unsigned char * SrcData,
+                                             const unsigned char * RefDataPtr1,
+                                             const unsigned char * RefDataPtr2,
+                                             ogg_uint32_t PixelsPerLine,
+                                             ogg_uint32_t ErrorSoFar,
+                                             ogg_uint32_t BestSoFar ) {
 
   ogg_uint32_t  i;
   ogg_uint32_t  DiffVal = ErrorSoFar;
@@ -272,26 +278,26 @@
 
   if ( RefOffset == 0 ) {
     /* Simple case as for non 0.5 pixel */
-    DiffVal += GetSumAbsDiffs( SrcData, RefDataPtr1, PixelsPerLine,
+    DiffVal = GetSumSqrDiffs( SrcData, RefDataPtr1, PixelsPerLine,
                                ErrorSoFar);
   } else  {
     for ( i=0; i < BLOCK_HEIGHT_WIDTH; i++ ) {
-      DiffVal += abs( ((int)SrcData[0]) - (((int)RefDataPtr1[0] +
-                                            (int)RefDataPtr2[0]) / 2) );
-      DiffVal += abs( ((int)SrcData[1]) - (((int)RefDataPtr1[1] +
-                                            (int)RefDataPtr2[1]) / 2) );
-      DiffVal += abs( ((int)SrcData[2]) - (((int)RefDataPtr1[2] +
-                                            (int)RefDataPtr2[2]) / 2) );
-      DiffVal += abs( ((int)SrcData[3]) - (((int)RefDataPtr1[3] +
-                                            (int)RefDataPtr2[3]) / 2) );
-      DiffVal += abs( ((int)SrcData[4]) - (((int)RefDataPtr1[4] +
-                                            (int)RefDataPtr2[4]) / 2) );
-      DiffVal += abs( ((int)SrcData[5]) - (((int)RefDataPtr1[5] +
-                                            (int)RefDataPtr2[5]) / 2) );
-      DiffVal += abs( ((int)SrcData[6]) - (((int)RefDataPtr1[6] +
-                                            (int)RefDataPtr2[6]) / 2) );
-      DiffVal += abs( ((int)SrcData[7]) - (((int)RefDataPtr1[7] +
-                                            (int)RefDataPtr2[7]) / 2) );
+      DiffVal += SquaredDifference( SrcData[0], ((int)RefDataPtr1[0] +
+                                                 (int)RefDataPtr2[0]) / 2 );
+      DiffVal += SquaredDifference( SrcData[1], ((int)RefDataPtr1[1] +
+                                                 (int)RefDataPtr2[1]) / 2 );
+      DiffVal += SquaredDifference( SrcData[2], ((int)RefDataPtr1[2] +
+                                                 (int)RefDataPtr2[2]) / 2 );
+      DiffVal += SquaredDifference( SrcData[3], ((int)RefDataPtr1[3] +
+                                                 (int)RefDataPtr2[3]) / 2 );
+      DiffVal += SquaredDifference( SrcData[4], ((int)RefDataPtr1[4] +
+                                                 (int)RefDataPtr2[4]) / 2 );
+      DiffVal += SquaredDifference( SrcData[5], ((int)RefDataPtr1[5] +
+                                                 (int)RefDataPtr2[5]) / 2 );
+      DiffVal += SquaredDifference( SrcData[6], ((int)RefDataPtr1[6] +
+                                                 (int)RefDataPtr2[6]) / 2 );
+      DiffVal += SquaredDifference( SrcData[7], ((int)RefDataPtr1[7] +
+                                                 (int)RefDataPtr2[7]) / 2 );
 
       if ( DiffVal > BestSoFar ) break;
 
@@ -305,12 +311,12 @@
   return DiffVal;
 }
 
-static ogg_uint32_t GetIntraError (unsigned char * DataPtr,
-                            ogg_uint32_t PixelsPerLine ) {
+static ogg_uint32_t GetIntraError (const unsigned char * DataPtr,
+                                   ogg_uint32_t PixelsPerLine ) {
   ogg_uint32_t  i;
   ogg_uint32_t  XSum=0;
   ogg_uint32_t  XXSum=0;
-  unsigned char *DiffPtr;
+  const unsigned char *DiffPtr;
 
   /* Loop expanded out for speed. */
   DiffPtr = DataPtr;
@@ -382,8 +388,8 @@
 }
 
 ogg_uint32_t GetMBInterError (CP_INSTANCE *cpi,
-                              unsigned char * SrcPtr,
-                              unsigned char * RefPtr,
+                              const unsigned char * SrcPtr,
+                              const unsigned char * RefPtr,
                               ogg_uint32_t FragIndex,
                               ogg_int32_t LastXMV,
                               ogg_int32_t LastYMV,
@@ -397,8 +403,8 @@
 
   ogg_uint32_t  InterError = 0;
 
-  unsigned char * SrcPtr1;
-  unsigned char * RefPtr1;
+  const unsigned char * SrcPtr1;
+  const unsigned char * RefPtr1;
 
   /* Work out pixel offset into source buffer. */
   PixelIndex = cpi->pb.pixel_index_table[LocalFragIndex];
@@ -466,7 +472,7 @@
 }
 
 ogg_uint32_t GetMBMVInterError (CP_INSTANCE *cpi,
-                                unsigned char * RefFramePtr,
+                                const unsigned char * RefFramePtr,
                                 ogg_uint32_t FragIndex,
                                 ogg_uint32_t PixelsPerLine,
                                 ogg_int32_t *MVPixelOffset,
@@ -480,10 +486,10 @@
   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;
+  const unsigned char *SrcPtr[4] = {NULL,NULL,NULL,NULL};
+  const unsigned char *RefPtr=NULL;
+  const unsigned char *CandidateBlockPtr=NULL;
+  const unsigned char *BestBlockPtr=NULL;
 
   ogg_uint32_t  RefRow2Offset = cpi->pb.YStride * 8;
 
@@ -493,8 +499,8 @@
   ogg_int32_t   HalfPixelError;
   ogg_int32_t   BestHalfPixelError;
   unsigned char   BestHalfOffset;
-  unsigned char * RefDataPtr1;
-  unsigned char * RefDataPtr2;
+  const unsigned char * RefDataPtr1;
+  const unsigned char * RefDataPtr2;
 
   /* Note which of the four blocks in the macro block are to be
      included in the search. */
@@ -518,19 +524,19 @@
 
   /* Check the 0,0 candidate. */
   if ( MBlockDispFrags[0] ) {
-    Error = GetSumAbsDiffs( SrcPtr[0], RefPtr,
+    Error = GetSumSqrDiffs( SrcPtr[0], RefPtr,
                          PixelsPerLine, Error);
   }
   if ( MBlockDispFrags[1] ) {
-    Error = GetSumAbsDiffs( SrcPtr[1], RefPtr + 8,
+    Error = GetSumSqrDiffs( SrcPtr[1], RefPtr + 8,
                          PixelsPerLine, Error);
   }
   if ( MBlockDispFrags[2] ) {
-    Error = GetSumAbsDiffs( SrcPtr[2], RefPtr + RefRow2Offset,
+    Error = GetSumSqrDiffs( SrcPtr[2], RefPtr + RefRow2Offset,
                          PixelsPerLine, Error);
   }
   if ( MBlockDispFrags[3] ) {
-    Error = GetSumAbsDiffs( SrcPtr[3], RefPtr + RefRow2Offset + 8,
+    Error = GetSumSqrDiffs( SrcPtr[3], RefPtr + RefRow2Offset + 8,
                          PixelsPerLine, Error);
   }
 
@@ -554,22 +560,22 @@
 
       /* Get the score for the current offset */
       if ( MBlockDispFrags[0] ) {
-        Error = GetSumAbsDiffs( SrcPtr[0], CandidateBlockPtr,
+        Error = GetSumSqrDiffs( SrcPtr[0], CandidateBlockPtr,
                              PixelsPerLine, Error);
       }
 
       if ( MBlockDispFrags[1] && (Error < MinError) ) {
-        Error = GetNextSumAbsDiffs( SrcPtr[1], CandidateBlockPtr + 8,
+        Error = GetNextSumSqrDiffs( SrcPtr[1], CandidateBlockPtr + 8,
                                  PixelsPerLine, Error, MinError );
       }
 
       if ( MBlockDispFrags[2] && (Error < MinError) ) {
-        Error = GetNextSumAbsDiffs( SrcPtr[2], CandidateBlockPtr + RefRow2Offset,
+        Error = GetNextSumSqrDiffs( SrcPtr[2], CandidateBlockPtr + RefRow2Offset,
                                  PixelsPerLine, Error, MinError );
       }
 
       if ( MBlockDispFrags[3] && (Error < MinError) ) {
-        Error = GetNextSumAbsDiffs( SrcPtr[3],
+        Error = GetNextSumSqrDiffs( SrcPtr[3],
                                  CandidateBlockPtr + RefRow2Offset + 8,
                                  PixelsPerLine, Error, MinError );
       }
@@ -610,7 +616,7 @@
       RefDataPtr1 = BestBlockPtr;
       RefDataPtr2 = RefDataPtr1 + cpi->HalfPixelRef2Offset[i];
       HalfPixelError =
-        GetHalfPixelSumAbsDiffs( SrcPtr[0], RefDataPtr1, RefDataPtr2,
+        GetHalfPixelSumSqrDiffs( SrcPtr[0], RefDataPtr1, RefDataPtr2,
                          PixelsPerLine, HalfPixelError, BestHalfPixelError );
     }
 
@@ -618,7 +624,7 @@
       RefDataPtr1 = BestBlockPtr + 8;
       RefDataPtr2 = RefDataPtr1 + cpi->HalfPixelRef2Offset[i];
       HalfPixelError =
-        GetHalfPixelSumAbsDiffs( SrcPtr[1], RefDataPtr1, RefDataPtr2,
+        GetHalfPixelSumSqrDiffs( SrcPtr[1], RefDataPtr1, RefDataPtr2,
                          PixelsPerLine, HalfPixelError, BestHalfPixelError );
     }
 
@@ -626,7 +632,7 @@
       RefDataPtr1 = BestBlockPtr + RefRow2Offset;
       RefDataPtr2 = RefDataPtr1 + cpi->HalfPixelRef2Offset[i];
       HalfPixelError =
-        GetHalfPixelSumAbsDiffs( SrcPtr[2], RefDataPtr1, RefDataPtr2,
+        GetHalfPixelSumSqrDiffs( SrcPtr[2], RefDataPtr1, RefDataPtr2,
                          PixelsPerLine, HalfPixelError, BestHalfPixelError );
     }
 
@@ -634,7 +640,7 @@
       RefDataPtr1 = BestBlockPtr + RefRow2Offset + 8;
       RefDataPtr2 = RefDataPtr1 + cpi->HalfPixelRef2Offset[i];
       HalfPixelError =
-        GetHalfPixelSumAbsDiffs( SrcPtr[3], RefDataPtr1, RefDataPtr2,
+        GetHalfPixelSumSqrDiffs( SrcPtr[3], RefDataPtr1, RefDataPtr2,
                          PixelsPerLine, HalfPixelError, BestHalfPixelError );
     }
 
@@ -657,7 +663,7 @@
 }
 
 ogg_uint32_t GetMBMVExhaustiveSearch (CP_INSTANCE *cpi,
-                                      unsigned char * RefFramePtr,
+                                      const unsigned char * RefFramePtr,
                                       ogg_uint32_t FragIndex,
                                       ogg_uint32_t PixelsPerLine,
                                       MOTION_VECTOR *MV ) {
@@ -668,10 +674,10 @@
   ogg_int32_t   i, j;
   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;
+  const unsigned char *SrcPtr[4] = {NULL,NULL,NULL,NULL};
+  const unsigned char *RefPtr;
+  const unsigned char *CandidateBlockPtr=NULL;
+  const unsigned char *BestBlockPtr=NULL;
 
   ogg_uint32_t  RefRow2Offset = cpi->pb.YStride * 8;
 
@@ -681,8 +687,8 @@
   ogg_int32_t   HalfPixelError;
   ogg_int32_t   BestHalfPixelError;
   unsigned char   BestHalfOffset;
-  unsigned char * RefDataPtr1;
-  unsigned char * RefDataPtr2;
+  const unsigned char * RefDataPtr1;
+  const unsigned char * RefDataPtr2;
 
   /* Note which of the four blocks in the macro block are to be
      included in the search. */
@@ -717,19 +723,19 @@
 
       /* Summ errors for each block. */
       if ( MBlockDispFrags[0] ) {
-        Error = GetSumAbsDiffs( SrcPtr[0], CandidateBlockPtr,
+        Error = GetSumSqrDiffs( SrcPtr[0], CandidateBlockPtr,
                              PixelsPerLine, Error);
       }
       if ( MBlockDispFrags[1] ){
-        Error = GetSumAbsDiffs( SrcPtr[1], CandidateBlockPtr + 8,
+        Error = GetSumSqrDiffs( SrcPtr[1], CandidateBlockPtr + 8,
                              PixelsPerLine, Error);
       }
       if ( MBlockDispFrags[2] ){
-        Error = GetSumAbsDiffs( SrcPtr[2], CandidateBlockPtr + RefRow2Offset,
+        Error = GetSumSqrDiffs( SrcPtr[2], CandidateBlockPtr + RefRow2Offset,
                              PixelsPerLine, Error);
       }
       if ( MBlockDispFrags[3] ){
-        Error = GetSumAbsDiffs( SrcPtr[3], CandidateBlockPtr + RefRow2Offset + 8,
+        Error = GetSumSqrDiffs( SrcPtr[3], CandidateBlockPtr + RefRow2Offset + 8,
                              PixelsPerLine, Error);
       }
 
@@ -766,7 +772,7 @@
       RefDataPtr1 = BestBlockPtr;
       RefDataPtr2 = RefDataPtr1 + cpi->HalfPixelRef2Offset[i];
       HalfPixelError =
-        GetHalfPixelSumAbsDiffs( SrcPtr[0], RefDataPtr1, RefDataPtr2,
+        GetHalfPixelSumSqrDiffs( SrcPtr[0], RefDataPtr1, RefDataPtr2,
                          PixelsPerLine, HalfPixelError, BestHalfPixelError );
     }
 
@@ -774,7 +780,7 @@
       RefDataPtr1 = BestBlockPtr + 8;
       RefDataPtr2 = RefDataPtr1 + cpi->HalfPixelRef2Offset[i];
       HalfPixelError =
-        GetHalfPixelSumAbsDiffs( SrcPtr[1], RefDataPtr1, RefDataPtr2,
+        GetHalfPixelSumSqrDiffs( SrcPtr[1], RefDataPtr1, RefDataPtr2,
                          PixelsPerLine, HalfPixelError, BestHalfPixelError );
     }
 
@@ -782,7 +788,7 @@
       RefDataPtr1 = BestBlockPtr + RefRow2Offset;
       RefDataPtr2 = RefDataPtr1 + cpi->HalfPixelRef2Offset[i];
       HalfPixelError =
-        GetHalfPixelSumAbsDiffs( SrcPtr[2], RefDataPtr1, RefDataPtr2,
+        GetHalfPixelSumSqrDiffs( SrcPtr[2], RefDataPtr1, RefDataPtr2,
                          PixelsPerLine, HalfPixelError, BestHalfPixelError );
     }
 
@@ -790,7 +796,7 @@
       RefDataPtr1 = BestBlockPtr + RefRow2Offset + 8;
       RefDataPtr2 = RefDataPtr1 + cpi->HalfPixelRef2Offset[i];
       HalfPixelError =
-        GetHalfPixelSumAbsDiffs( SrcPtr[3], RefDataPtr1, RefDataPtr2,
+        GetHalfPixelSumSqrDiffs( SrcPtr[3], RefDataPtr1, RefDataPtr2,
                          PixelsPerLine, HalfPixelError, BestHalfPixelError );
     }
 
@@ -813,7 +819,7 @@
 }
 
 static ogg_uint32_t GetBMVExhaustiveSearch (CP_INSTANCE *cpi,
-                                            unsigned char * RefFramePtr,
+                                            const unsigned char * RefFramePtr,
                                             ogg_uint32_t FragIndex,
                                             ogg_uint32_t PixelsPerLine,
                                             MOTION_VECTOR *MV ) {
@@ -824,16 +830,16 @@
   ogg_int32_t   i, j;
   ogg_int32_t   x=0, y=0;
 
-  unsigned char *SrcPtr = NULL;
-  unsigned char *RefPtr;
-  unsigned char *CandidateBlockPtr=NULL;
-  unsigned char *BestBlockPtr=NULL;
+  const unsigned char *SrcPtr = NULL;
+  const unsigned char *RefPtr;
+  const unsigned char *CandidateBlockPtr=NULL;
+  const unsigned char *BestBlockPtr=NULL;
 
   /* Half pixel variables */
   ogg_int32_t   HalfPixelError;
   ogg_int32_t   BestHalfPixelError;
   unsigned char   BestHalfOffset;
-  unsigned char * RefDataPtr2;
+  const unsigned char * RefDataPtr2;
 
   /* Set up the source pointer for the block. */
   SrcPtr = &cpi->
@@ -850,7 +856,7 @@
 
     for ( j = 0; j < (ogg_int32_t)MAX_MV_EXTENT; j++ ){
       /* Get the block error score. */
-      Error = GetSumAbsDiffs( SrcPtr, CandidateBlockPtr,
+      Error = GetSumSqrDiffs( SrcPtr, CandidateBlockPtr,
                            PixelsPerLine, 0);
 
       /* Was this the best so far */
@@ -881,7 +887,7 @@
   for ( i=0; i < 9; i++ ) {
     RefDataPtr2 = BestBlockPtr + cpi->HalfPixelRef2Offset[i];
     HalfPixelError =
-      GetHalfPixelSumAbsDiffs( SrcPtr, BestBlockPtr, RefDataPtr2,
+      GetHalfPixelSumSqrDiffs( SrcPtr, BestBlockPtr, RefDataPtr2,
                             PixelsPerLine, 0, BestHalfPixelError );
 
     if ( HalfPixelError < BestHalfPixelError ){
@@ -905,15 +911,15 @@
 }
 
 ogg_uint32_t GetFOURMVExhaustiveSearch (CP_INSTANCE *cpi,
-                                        unsigned char * RefFramePtr,
+                                        const unsigned char * RefFramePtr,
                                         ogg_uint32_t FragIndex,
                                         ogg_uint32_t PixelsPerLine,
                                         MOTION_VECTOR *MV ) {
   ogg_uint32_t  InterMVError;
 
-  /* For the moment the 4MV mode is only deemd to be valid if all four
+  /* 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. */
+  /* This may be adapted later. */
   if ( cpi->pb.display_fragments[FragIndex] &&
        cpi->pb.display_fragments[FragIndex + 1] &&
        cpi->pb.display_fragments[FragIndex + cpi->pb.HFragments] &&
Index: lib/encoder_internal.h
===================================================================
--- lib/encoder_internal.h	(revision 7715)
+++ lib/encoder_internal.h	(working copy)
@@ -755,26 +755,26 @@
 extern ogg_uint32_t GetMBIntraError (CP_INSTANCE *cpi, ogg_uint32_t FragIndex,
                                      ogg_uint32_t PixelsPerLine ) ;
 extern ogg_uint32_t GetMBInterError (CP_INSTANCE *cpi,
-                                     unsigned char * SrcPtr,
-                                     unsigned char * RefPtr,
+                                     const unsigned char * SrcPtr,
+                                     const unsigned char * RefPtr,
                                      ogg_uint32_t FragIndex,
                                      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,
+                                       const unsigned char * RefFramePtr,
                                        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,
+                                             const unsigned char * RefFramePtr,
                                              ogg_uint32_t FragIndex,
                                              ogg_uint32_t PixelsPerLine,
                                              MOTION_VECTOR *MV );
 extern ogg_uint32_t GetFOURMVExhaustiveSearch (CP_INSTANCE *cpi,
-                                               unsigned char * RefFramePtr,
+                                             const unsigned char * RefFramePtr,
                                                ogg_uint32_t FragIndex,
                                                ogg_uint32_t PixelsPerLine,
                                                MOTION_VECTOR *MV ) ;



More information about the Theora-dev mailing list