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

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Thu Dec 27 09:34:32 PST 2007


Author: xiphmont
Date: 2007-12-27 09:34:30 -0800 (Thu, 27 Dec 2007)
New Revision: 14327

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
Log:
Move MVs to macroblock; have one temp hack toeliminate (requires MB addressing in CodePlane)



Modified: branches/theora-thusnelda/lib/enc/codec_internal.h
===================================================================
--- branches/theora-thusnelda/lib/enc/codec_internal.h	2007-12-27 15:26:33 UTC (rev 14326)
+++ branches/theora-thusnelda/lib/enc/codec_internal.h	2007-12-27 17:34:30 UTC (rev 14327)
@@ -119,6 +119,7 @@
   coding_mode_t mode;
   mv_t mv[4];
 
+  char coded;
 } macroblock_t;
 
 #define SB_MB_BLFRAG(sb,mbnum) ((sb).f[ ((mbnum)<2? ((mbnum)==0?0:4) : ((mbnum)==2?8:14)) ])
@@ -157,7 +158,6 @@
   /* SuperBlock, MacroBLock and Fragment Information */
   unsigned char   *frag_coded;
   ogg_uint32_t    *frag_buffer_index;
-  mv_t            *frag_mv;
   unsigned char   *frag_nonzero;
   ogg_int16_t     *frag_dc;
   dct_t           *frag_dct;
@@ -277,7 +277,7 @@
 
 extern void DPCMTokenize (CP_INSTANCE *cpi);
 
-extern void TransformQuantizeBlock (CP_INSTANCE *cpi, coding_mode_t mode, int fi) ;
+extern void TransformQuantizeBlock (CP_INSTANCE *cpi, coding_mode_t mode, int fi, mv_t mv) ;
 
 extern void WriteQTables(CP_INSTANCE *cpi,oggpack_buffer *opb);
 

Modified: branches/theora-thusnelda/lib/enc/dct_encode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/dct_encode.c	2007-12-27 15:26:33 UTC (rev 14326)
+++ branches/theora-thusnelda/lib/enc/dct_encode.c	2007-12-27 17:34:30 UTC (rev 14327)
@@ -427,7 +427,8 @@
 				   ogg_int32_t MvDivisor,
 				   int fi,
 				   ogg_uint32_t PixelsPerLine,
-				   int mode) {
+				   int mode,
+				   mv_t mv) {
 
   ogg_int32_t MvShift;
   ogg_int32_t MvModMask;
@@ -439,7 +440,6 @@
                                    half pixel MC */
   unsigned char  *ReconPtr1;    /* DCT reconstructed image pointers */
   unsigned char  *ReconPtr2;    /* Pointer used in half pixel MC */
-  mv_t mv = cpi->frag_mv[fi];
   int bi = cpi->frag_buffer_index[fi];
   unsigned char *thisrecon = &cpi->recon[bi];
 
@@ -524,7 +524,8 @@
 
 void TransformQuantizeBlock (CP_INSTANCE *cpi, 
 			     coding_mode_t mode,
-			     int fi){
+			     int fi,
+			     mv_t mv){
 
   unsigned char *cp = &cpi->frag_coded[fi];
 
@@ -550,7 +551,7 @@
      the reconstruction buffer, and proces a difference block for
      forward DCT */
   BlockUpdateDifference(cpi, FiltPtr, DCTInput, 
-			MvDivisor, fi, cpi->stride[plane], mode);
+			MvDivisor, fi, cpi->stride[plane], mode, mv);
   
   /* Proceed to encode the data into the encode buffer if the encoder
      is enabled. */

Modified: branches/theora-thusnelda/lib/enc/encode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/encode.c	2007-12-27 15:26:33 UTC (rev 14326)
+++ branches/theora-thusnelda/lib/enc/encode.c	2007-12-27 17:34:30 UTC (rev 14327)
@@ -153,6 +153,8 @@
   }
 }
 
+/* temporary hack; going to MB addressing */
+static int hmap4[16]={0,1,3,2,0,2,3,1,0,2,3,1,3,2,0,1};
 static ogg_uint32_t CodePlane ( CP_INSTANCE *cpi, int plane, int subsample){
   ogg_uint32_t n = cpi->super_n[plane];
   ogg_uint32_t SB, MB, B;
@@ -163,20 +165,20 @@
   case 1:
     for ( SB=0; SB<n; SB++,sp++ ){
       int frag = 0;
-      
+     
       for ( MB=0; MB<4; MB++ ) {
 	macroblock_t *mp = &cpi->macro[sp->m[MB]];
-	unsigned char coded = 0;
 	
 	for ( B=0; B<4; B++, frag++ ) {
 	  int fi = sp->f[frag];
 	  
 	  if ( cp[fi] ) {
-	    TransformQuantizeBlock( cpi, mp->mode, fi );
-	    coded |= cp[fi];
+	    TransformQuantizeBlock( cpi, mp->mode, fi, mp->mv[hmap4[frag]] );
+	    if(cp[fi] && plane == 0)
+	      mp->coded |= (1<<hmap4[frag]);
 	  }
 	}
-	if ( plane == 0 && coded ) 
+	if ( plane == 0 && mp->coded ) 
 	  cpi->ModeCount[mp->mode] ++;
 	
       }  
@@ -189,8 +191,26 @@
     for ( SB=0; SB<n; SB++,sp++ ){
       for ( MB=0; MB<16; MB++ ) { /* MB:B :: 1:1 */
 	int fi = sp->f[MB];
-	if ( cp[fi] ) 
-	  TransformQuantizeBlock( cpi, cpi->macro[sp->m[MB]].mode, fi );
+	if ( cp[fi] ) {
+	  macroblock_t *mp = &cpi->macro[sp->m[MB]];
+	  mv_t mv;
+
+	  /* Calculate motion vector as the average of the Y plane ones. */
+	  /* Uncoded members are 0,0 and not special-cased */
+	  mv.x = mp->mv[0].x + mp->mv[1].x + mp->mv[2].x + mp->mv[3].x;
+	  mv.y = mp->mv[0].y + mp->mv[1].y + mp->mv[2].y + mp->mv[3].y;
+
+	  if ( mv.x >= 0 )
+	    mv.x = (mv.x + 2) / 4;
+	  else
+	    mv.x = (mv.x - 2) / 4;
+	  if ( mv.y >= 0 )
+	    mv.y = (mv.y + 2) / 4;
+	  else
+	    mv.y = (mv.y - 2) / 4;
+	  
+	  TransformQuantizeBlock( cpi, mp->mode, fi, mv );
+	}
       }  
     }
     return 0;
@@ -307,10 +327,8 @@
   const ogg_uint32_t *ModeWords;
   const ogg_int32_t *ModeBits;
   const unsigned char  *ModeScheme;
+  int SB,MB;
 
-  unsigned char *cp = cpi->frag_coded;
-  int SB,MB,B;
-
   oggpack_buffer *opb=cpi->oggbuffer;
   for(i=0;i<MAX_MODES;i++)
     modes+=cpi->ModeCount[i];
@@ -388,11 +406,7 @@
     superblock_t *sp = &cpi->super[0][SB];
     for ( MB=0; MB<4; MB++ ) {
       macroblock_t *mbp = &cpi->macro[sp->m[MB]];
-      int fi = mbp->y[0];
-
-      for(B=1; !cp[fi] && B<4; B++ ) fi = mbp->y[B];
-  
-      if(cp[fi]){
+      if(mbp->coded){
 	/* Add the appropriate mode entropy token. */
 	int index = ModeScheme[mbp->mode];
 	oggpackB_write( opb, ModeWords[index],
@@ -407,9 +421,6 @@
   const ogg_uint32_t * MvBitsPtr;
 
   ogg_uint32_t SB, MB, B;
-  unsigned char *cp = cpi->frag_coded;
-  mv_t          *mv = cpi->frag_mv;
-
   oggpack_buffer *opb=cpi->oggbuffer;
 
   /* Choose the coding method */
@@ -429,22 +440,18 @@
     superblock_t *sp = &cpi->super[0][SB];
     for ( MB=0; MB<4; MB++ ) {
       macroblock_t *mbp = &cpi->macro[sp->m[MB]];
-      int fi = mbp->y[0];
- 
-      for(B=1; !cp[fi] && B<4; B++ ) fi = mbp->y[B];
-      if(B==4) continue;
+      if(!mbp->coded) continue;
 
       if(mbp->mode==CODE_INTER_PLUS_MV || mbp->mode==CODE_GOLDEN_MV){
 	/* One MV for the macroblock */
-	oggpackB_write( opb, MvPatternPtr[mv[fi].x], MvBitsPtr[mv[fi].x] );
-	oggpackB_write( opb, MvPatternPtr[mv[fi].y], MvBitsPtr[mv[fi].y] );
+	oggpackB_write( opb, MvPatternPtr[mbp->mv[0].x], MvBitsPtr[mbp->mv[0].x] );
+	oggpackB_write( opb, MvPatternPtr[mbp->mv[0].y], MvBitsPtr[mbp->mv[0].y] );
       }else if (mbp->mode == CODE_INTER_FOURMV){
 	/* MV for each codedblock */
 	for(B=0; B<4; B++ ){
-	  fi = mbp->y[B];
-	  if(cp[fi]){
-	    oggpackB_write( opb, MvPatternPtr[mv[fi].x], MvBitsPtr[mv[fi].x] );
-	    oggpackB_write( opb, MvPatternPtr[mv[fi].y], MvBitsPtr[mv[fi].y] );
+	  if(mbp->coded & (1<<B)){
+	    oggpackB_write( opb, MvPatternPtr[mbp->mv[B].x], MvBitsPtr[mbp->mv[B].x] );
+	    oggpackB_write( opb, MvPatternPtr[mbp->mv[B].y], MvBitsPtr[mbp->mv[B].y] );
 	  }
 	}
       }
@@ -504,24 +511,15 @@
   cpi->MVBits_1 += 12; /* Simple six bits per mv component fallback */
 }
 
-static void SetFragMotionVector(CP_INSTANCE *cpi,
-				int fi,
-				mv_t *mv){
-  cpi->frag_mv[fi] = *mv;
-}
-
 static void SetMBMotionVectorsAndMode(CP_INSTANCE *cpi,
 				      macroblock_t *mp,
 				      mv_t *mv,
 				      int mode){
   mp->mode = mode;
   mp->mv[0] = *mv;
-  SetFragMotionVector(cpi, mp->y[0], mv);
-  SetFragMotionVector(cpi, mp->y[1], mv);
-  SetFragMotionVector(cpi, mp->y[2], mv);
-  SetFragMotionVector(cpi, mp->y[3], mv);
-  SetFragMotionVector(cpi, mp->u, mv);
-  SetFragMotionVector(cpi, mp->v, mv);
+  mp->mv[1] = *mv;
+  mp->mv[2] = *mv;
+  mp->mv[3] = *mv;
 }
 
 ogg_uint32_t PickModes(CP_INSTANCE *cpi,
@@ -545,7 +543,7 @@
                                            block */
   ogg_uint32_t  BestError;              /* Best error so far. */
 
-  mv_t          FourMVect[6] = {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}};
+  mv_t          FourMVect[4] = {{0,0},{0,0},{0,0},{0,0}};
   mv_t          LastInterMVect = {0,0};
   mv_t          PriorLastInterMVect = {0,0};
   mv_t          TmpMVect = {0,0};  
@@ -796,36 +794,11 @@
 	CountMotionVector( cpi, &GFMVect);
       } else if ( BestError == MBInterFOURMVError ) {
 
-	/* Calculate the UV vectors as the average of the Y plane ones. */
-	/* First .x component */
-	FourMVect[4].x = FourMVect[0].x + FourMVect[1].x +
-	  FourMVect[2].x + FourMVect[3].x;
-	if ( FourMVect[4].x >= 0 )
-	  FourMVect[4].x = (FourMVect[4].x + 2) / 4;
-	else
-	  FourMVect[4].x = (FourMVect[4].x - 2) / 4;
-	FourMVect[5].x = FourMVect[4].x;
-
-	/* Then .y component */
-	FourMVect[4].y = FourMVect[0].y + FourMVect[1].y +
-	  FourMVect[2].y + FourMVect[3].y;
-	if ( FourMVect[4].y >= 0 )
-	  FourMVect[4].y = (FourMVect[4].y + 2) / 4;
-	else
-	  FourMVect[4].y = (FourMVect[4].y - 2) / 4;
-	FourMVect[5].y = FourMVect[4].y;
-
 	mbp->mode = CODE_INTER_FOURMV;
 	mbp->mv[0] = FourMVect[0];
 	mbp->mv[1] = FourMVect[1];
 	mbp->mv[2] = FourMVect[2];
 	mbp->mv[3] = FourMVect[3];
-	SetFragMotionVector(cpi,mbp->y[0], &FourMVect[0]);
-	SetFragMotionVector(cpi,mbp->y[1], &FourMVect[1]);
-	SetFragMotionVector(cpi,mbp->y[2], &FourMVect[2]);
-	SetFragMotionVector(cpi,mbp->y[3], &FourMVect[3]);
-	SetFragMotionVector(cpi,mbp->u, &FourMVect[4]);
-	SetFragMotionVector(cpi,mbp->v, &FourMVect[5]);
 
 	/* Note the four MVs values for current macro-block. */
 	CountMotionVector( cpi, &FourMVect[0]);

Modified: branches/theora-thusnelda/lib/enc/encoder_toplevel.c
===================================================================
--- branches/theora-thusnelda/lib/enc/encoder_toplevel.c	2007-12-27 15:26:33 UTC (rev 14326)
+++ branches/theora-thusnelda/lib/enc/encoder_toplevel.c	2007-12-27 17:34:30 UTC (rev 14327)
@@ -77,15 +77,14 @@
   ogg_uint32_t  KFIndicator = 0;
   int fi = 0;
 
-  for ( i = 0; i < cpi->macro_total; i++) 
+  for ( i = 0; i < cpi->macro_total; i++) {
     cpi->macro[i].mode = CODE_INTER_NO_MV;  /* Default coding mode */
+    cpi->macro[i].coded = 0; 
+  }
 
   /* Clear down the macro block level mode and MV arrays. */
-  for ( i = 0; i < cpi->frag_total; i++, fi++ ) {
+  for ( i = 0; i < cpi->frag_total; i++, fi++ ) 
     cpi->frag_coded[fi] = 1; /* TEMPORARY */
-    cpi->frag_mv[fi].x=0;
-    cpi->frag_mv[fi].y=0;
-  }
 
   /* Default to delta frames. */
   cpi->FrameType = DELTA_FRAME;

Modified: branches/theora-thusnelda/lib/enc/frinit.c
===================================================================
--- branches/theora-thusnelda/lib/enc/frinit.c	2007-12-27 15:26:33 UTC (rev 14326)
+++ branches/theora-thusnelda/lib/enc/frinit.c	2007-12-27 17:34:30 UTC (rev 14327)
@@ -49,9 +49,6 @@
   if(cpi->frag_buffer_index) _ogg_free(cpi->frag_buffer_index);
   cpi->frag_buffer_index = 0;
 
-  if(cpi->frag_mv) _ogg_free(cpi->frag_mv);
-  cpi->frag_mv = 0;
-
   if(cpi->frag_nonzero) _ogg_free(cpi->frag_nonzero);
   cpi->frag_nonzero = 0;
 
@@ -137,7 +134,6 @@
   /* +1; the last entry is the 'invalid' frag, which is always set to not coded as it doesn't really exist */
   cpi->frag_coded = calloc(cpi->frag_total+1, sizeof(*cpi->frag_coded)); 
   cpi->frag_buffer_index = calloc(cpi->frag_total, sizeof(*cpi->frag_buffer_index));
-  cpi->frag_mv = calloc(cpi->frag_total, sizeof(*cpi->frag_mv));
   cpi->frag_nonzero = calloc(cpi->frag_total, sizeof(*cpi->frag_nonzero));
   cpi->frag_dct = calloc(cpi->frag_total, sizeof(*cpi->frag_dct));
   cpi->frag_dc = calloc(cpi->frag_total, sizeof(*cpi->frag_dc));



More information about the commits mailing list