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

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Thu Dec 27 10:11:34 PST 2007


Author: xiphmont
Date: 2007-12-27 10:11:33 -0800 (Thu, 27 Dec 2007)
New Revision: 14328

Modified:
   branches/theora-thusnelda/lib/enc/codec_internal.h
   branches/theora-thusnelda/lib/enc/dct_decode.c
   branches/theora-thusnelda/lib/enc/encode.c
   branches/theora-thusnelda/lib/enc/frinit.c
   branches/theora-thusnelda/lib/enc/mcomp.c
Log:
Go to MB addressing where appropriate; eliminates mixed Hilbert addressing in CodePlane

Add space for non 4:2:0 fragment addressing in MB.



Modified: branches/theora-thusnelda/lib/enc/codec_internal.h
===================================================================
--- branches/theora-thusnelda/lib/enc/codec_internal.h	2007-12-27 17:34:30 UTC (rev 14327)
+++ branches/theora-thusnelda/lib/enc/codec_internal.h	2007-12-27 18:11:33 UTC (rev 14328)
@@ -112,9 +112,7 @@
 
 typedef struct macroblock {
   /* the blocks comprising this macroblock */
-  int y[4]; // raster order
-  int u;
-  int v;
+  int yuv[3][4]; /* [Y,U,V][raster order] */
 
   coding_mode_t mode;
   mv_t mv[4];

Modified: branches/theora-thusnelda/lib/enc/dct_decode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/dct_decode.c	2007-12-27 17:34:30 UTC (rev 14327)
+++ branches/theora-thusnelda/lib/enc/dct_decode.c	2007-12-27 18:11:33 UTC (rev 14328)
@@ -451,22 +451,22 @@
 
   for (i=0; i<cpi->macro_total; i++, mp++ ) {
     coding_mode_t mode = mp->mode;
-    int fi = mp->y[0];
+    int fi = mp->yuv[0][0];
     if ( cp[fi] ) ExpandBlock( cpi, mode, fi );
 
-    fi = mp->y[1];
+    fi = mp->yuv[0][1];
     if ( cp[fi] ) ExpandBlock( cpi, mode, fi );
 
-    fi = mp->y[2];
+    fi = mp->yuv[0][2];
     if ( cp[fi] ) ExpandBlock( cpi, mode, fi );
 
-    fi = mp->y[3];
+    fi = mp->yuv[0][3];
     if ( cp[fi] ) ExpandBlock( cpi, mode, fi );
 
-    fi = mp->u;
+    fi = mp->yuv[1][0];
     if ( cp[fi] ) ExpandBlock( cpi, mode, fi );
 
-    fi = mp->v;
+    fi = mp->yuv[2][0];
     if ( cp[fi] ) ExpandBlock( cpi, mode, fi );
   }
 

Modified: branches/theora-thusnelda/lib/enc/encode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/encode.c	2007-12-27 17:34:30 UTC (rev 14327)
+++ branches/theora-thusnelda/lib/enc/encode.c	2007-12-27 18:11:33 UTC (rev 14328)
@@ -153,64 +153,49 @@
   }
 }
 
-/* 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;
+  int B;
   unsigned char *cp = cpi->frag_coded;
-  superblock_t *sp = cpi->super[plane];
+  macroblock_t *mp = cpi->macro;
+  macroblock_t *mp_end = cpi->macro+cpi->macro_total;
+  int fi;
 
   switch(subsample){
   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]];
-	
-	for ( B=0; B<4; B++, frag++ ) {
-	  int fi = sp->f[frag];
-	  
-	  if ( cp[fi] ) {
-	    TransformQuantizeBlock( cpi, mp->mode, fi, mp->mv[hmap4[frag]] );
-	    if(cp[fi] && plane == 0)
-	      mp->coded |= (1<<hmap4[frag]);
-	  }
+    for ( ; mp<mp_end; mp++ ) {
+      int *yuv = mp->yuv[plane];
+
+      for ( B=0; B<4; B++) {
+	fi = yuv[B];
+	if ( cp[fi] ) {
+	  TransformQuantizeBlock( cpi, mp->mode, fi, mp->mv[B] );
+	  if(cp[fi] && plane == 0)
+	    mp->coded |= (1<<B);
 	}
-	if ( plane == 0 && mp->coded ) 
-	  cpi->ModeCount[mp->mode] ++;
-	
-      }  
+      }
+      if ( plane == 0 && mp->coded ) 
+	cpi->ModeCount[mp->mode] ++; 
     }
     return 0;
   case 2:
     /* fill me in when we need to support 4:2:2 */
     return 1;
   case 4:
-    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] ) {
-	  macroblock_t *mp = &cpi->macro[sp->m[MB]];
-	  mv_t mv;
+    for ( ; mp<mp_end; mp++ ) {
+      int fi = mp->yuv[plane][0];
+      if ( cp[fi] ) {
+	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;
+	/* 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 );
-	}
+	mv.x = ( mv.x >= 0 ? (mv.x + 2) / 4 : (mv.x - 2) / 4);
+	mv.y = ( mv.y >= 0 ? (mv.y + 2) / 4 : (mv.y - 2) / 4);
+	
+	TransformQuantizeBlock( cpi, mp->mode, fi, mv );
+    
       }  
     }
     return 0;
@@ -402,6 +387,7 @@
     ModeBits = NoOpModeBits;
   }
 
+  /* modes coded in hilbert order; use superblock addressing */
   for ( SB=0 ; SB < cpi->super_n[0]; SB++ ){
     superblock_t *sp = &cpi->super[0][SB];
     for ( MB=0; MB<4; MB++ ) {
@@ -435,7 +421,8 @@
   }
 
   /* Pack and encode the motion vectors */
-  /* iterate through MB list */
+  /* MBs are iterated in Hilbert scan order, but the MVs within the MB are coded in raster order */
+
   for ( SB=0 ; SB < cpi->super_n[0]; SB++ ){
     superblock_t *sp = &cpi->super[0][SB];
     for ( MB=0; MB<4; MB++ ) {
@@ -589,9 +576,9 @@
     /* Check its four Macro-Blocks */
     for ( MB=0; MB<4; MB++ ) {
       macroblock_t *mbp = &cpi->macro[sp->m[MB]];      
-      int fi = mbp->y[0];
+      int fi = mbp->yuv[0][0];
 
-      for ( B=1; !cp[fi] && B<4; B++ ) fi = mbp->y[B];
+      for ( B=1; !cp[fi] && B<4; B++ ) fi = mbp->yuv[0][B];
       
       /* This one isn't coded go to the next one */
       if(!cp[fi]) continue;

Modified: branches/theora-thusnelda/lib/enc/frinit.c
===================================================================
--- branches/theora-thusnelda/lib/enc/frinit.c	2007-12-27 17:34:30 UTC (rev 14327)
+++ branches/theora-thusnelda/lib/enc/frinit.c	2007-12-27 18:11:33 UTC (rev 14328)
@@ -230,6 +230,7 @@
   }
 
   /* fill in macroblock fragment pointers; raster (MV coding) order */
+  /* 4:2:0 only for now */
   {
     int row,col,frag;
     int scanx[4] = {0,1,0,1};
@@ -246,20 +247,20 @@
 	  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] = fragindex;
+	    cpi->macro[macroindex].yuv[0][frag] = fragindex;
 	  }else
-	    cpi->macro[macroindex].y[frag] = cpi->frag_total;
+	    cpi->macro[macroindex].yuv[0][frag] = cpi->frag_total;
 	}
 	
 	if(row<cpi->frag_v[1] && col<cpi->frag_h[1])
-	  cpi->macro[macroindex].u = cpi->frag_n[0] + macroindex;
+	  cpi->macro[macroindex].yuv[1][0] = cpi->frag_n[0] + macroindex;
 	else
-	  cpi->macro[macroindex].u = cpi->frag_total;
+	  cpi->macro[macroindex].yuv[1][0] = cpi->frag_total;
 
 	if(row<cpi->frag_v[2] && col<cpi->frag_h[2])
-	  cpi->macro[macroindex].v = cpi->frag_n[0] + cpi->frag_n[1] + macroindex; 
+	  cpi->macro[macroindex].yuv[2][0] = cpi->frag_n[0] + cpi->frag_n[1] + macroindex; 
 	else
-	  cpi->macro[macroindex].v = cpi->frag_total;
+	  cpi->macro[macroindex].yuv[2][0] = cpi->frag_total;
 
       }
     }
@@ -267,12 +268,10 @@
 
   /* fill in 'invalid' macroblock */
   {
-    cpi->macro[cpi->macro_total].y[0] = cpi->frag_total;
-    cpi->macro[cpi->macro_total].y[1] = cpi->frag_total;
-    cpi->macro[cpi->macro_total].y[2] = cpi->frag_total;
-    cpi->macro[cpi->macro_total].y[3] = cpi->frag_total;
-    cpi->macro[cpi->macro_total].u = cpi->frag_total;
-    cpi->macro[cpi->macro_total].v = cpi->frag_total;
+    int p,f;
+    for(p=0;p<3;p++)
+      for(f=0;f<4;f++)
+	cpi->macro[cpi->macro_total].yuv[p][f] = cpi->frag_total;
   }
 
   /* allocate frames */

Modified: branches/theora-thusnelda/lib/enc/mcomp.c
===================================================================
--- branches/theora-thusnelda/lib/enc/mcomp.c	2007-12-27 17:34:30 UTC (rev 14327)
+++ branches/theora-thusnelda/lib/enc/mcomp.c	2007-12-27 18:11:33 UTC (rev 14328)
@@ -149,17 +149,18 @@
   dsp_save_fpu (cpi->dsp);
   unsigned char *cp = cpi->frag_coded;
   ogg_uint32_t *bp = cpi->frag_buffer_index;
-  
+  int *y = mp->yuv[0];
+
   /* Add together the intra errors for those blocks in the macro block
      that are coded (Y only) */
-  if ( cp[mp->y[0]] )
-    IntraError += dsp_intra8x8_err (cpi->dsp, &cpi->frame[bp[mp->y[0]]],cpi->stride[0]);
-  if ( cp[mp->y[1]] )
-    IntraError += dsp_intra8x8_err (cpi->dsp, &cpi->frame[bp[mp->y[1]]],cpi->stride[0]);
-  if ( cp[mp->y[2]] )
-    IntraError += dsp_intra8x8_err (cpi->dsp, &cpi->frame[bp[mp->y[2]]],cpi->stride[0]);
-  if ( cp[mp->y[3]] )
-    IntraError += dsp_intra8x8_err (cpi->dsp, &cpi->frame[bp[mp->y[3]]],cpi->stride[0]);
+  if ( cp[y[0]] )
+    IntraError += dsp_intra8x8_err (cpi->dsp, &cpi->frame[bp[y[0]]],cpi->stride[0]);
+  if ( cp[y[1]] )
+    IntraError += dsp_intra8x8_err (cpi->dsp, &cpi->frame[bp[y[1]]],cpi->stride[0]);
+  if ( cp[y[2]] )
+    IntraError += dsp_intra8x8_err (cpi->dsp, &cpi->frame[bp[y[2]]],cpi->stride[0]);
+  if ( cp[y[3]] )
+    IntraError += dsp_intra8x8_err (cpi->dsp, &cpi->frame[bp[y[3]]],cpi->stride[0]);
 
   dsp_restore_fpu (cpi->dsp);
   return IntraError;
@@ -181,6 +182,7 @@
   unsigned char * RefPtr1;
   unsigned char *cp = cpi->frag_coded;
   ogg_uint32_t *bp = cpi->frag_buffer_index;
+  int *y = mp->yuv[0];
 
   dsp_save_fpu (cpi->dsp);
   
@@ -200,28 +202,28 @@
 
   /* Add together the errors for those blocks in the macro block that
      are coded (Y only) */
-  if ( cp[mp->y[0]] ) {
-    SrcPtr1 = &SrcPtr[bp[mp->y[0]]];
-    RefPtr1 = &RefPtr[bp[mp->y[0]] + RefPixelOffset];
+  if ( cp[y[0]] ) {
+    SrcPtr1 = &SrcPtr[bp[y[0]]];
+    RefPtr1 = &RefPtr[bp[y[0]] + RefPixelOffset];
     InterError += GetInterErr(cpi, SrcPtr1, RefPtr1, &RefPtr1[RefPtr2Offset] );
   }
 
-  if ( cp[mp->y[1]] ) {
-    SrcPtr1 = &SrcPtr[bp[mp->y[1]]];
-    RefPtr1 = &RefPtr[bp[mp->y[1]] + RefPixelOffset];
+  if ( cp[y[1]] ) {
+    SrcPtr1 = &SrcPtr[bp[y[1]]];
+    RefPtr1 = &RefPtr[bp[y[1]] + RefPixelOffset];
     InterError += GetInterErr(cpi, SrcPtr1, RefPtr1, &RefPtr1[RefPtr2Offset] );
     
   }
   
-  if ( cp[mp->y[2]] ) {
-    SrcPtr1 = &SrcPtr[bp[mp->y[2]]];
-    RefPtr1 = &RefPtr[bp[mp->y[2]] + RefPixelOffset];
+  if ( cp[y[2]] ) {
+    SrcPtr1 = &SrcPtr[bp[y[2]]];
+    RefPtr1 = &RefPtr[bp[y[2]] + RefPixelOffset];
     InterError += GetInterErr(cpi, SrcPtr1, RefPtr1, &RefPtr1[RefPtr2Offset] );
   }
 
-  if ( cp[mp->y[3]] ) {
-    SrcPtr1 = &SrcPtr[bp[mp->y[3]]];
-    RefPtr1 = &RefPtr[bp[mp->y[3]] + RefPixelOffset];
+  if ( cp[y[3]] ) {
+    SrcPtr1 = &SrcPtr[bp[y[3]]];
+    RefPtr1 = &RefPtr[bp[y[3]] + RefPixelOffset];
     InterError += GetInterErr(cpi, SrcPtr1, RefPtr1, &RefPtr1[RefPtr2Offset] );
   }
   
@@ -258,37 +260,38 @@
   unsigned char * RefDataPtr2;
   unsigned char *cp = cpi->frag_coded;
   ogg_uint32_t *bp = cpi->frag_buffer_index;
+  int *yp = mp->yuv[0];
 
   dsp_save_fpu (cpi->dsp);
 
   /* Note which of the four blocks in the macro block are to be
      included in the search. */
-  disp[0] = cp[mp->y[0]];
-  disp[1] = cp[mp->y[1]];
-  disp[2] = cp[mp->y[2]];
-  disp[3] = cp[mp->y[3]];
+  disp[0] = cp[yp[0]];
+  disp[1] = cp[yp[1]];
+  disp[2] = cp[yp[2]];
+  disp[3] = cp[yp[3]];
 
   if(disp[0]){
-    SrcPtr[0] = &cpi->frame[bp[mp->y[0]]];
-    RefPtr[0] = &RefFramePtr[bp[mp->y[0]]];
+    SrcPtr[0] = &cpi->frame[bp[yp[0]]];
+    RefPtr[0] = &RefFramePtr[bp[yp[0]]];
     Error += dsp_sad8x8 (cpi->dsp, SrcPtr[0], RefPtr[0],
                          cpi->stride[0]);
   }
   if(disp[1]){
-    SrcPtr[1] = &cpi->frame[bp[mp->y[1]]];
-    RefPtr[1] = &RefFramePtr[bp[mp->y[1]]];
+    SrcPtr[1] = &cpi->frame[bp[yp[1]]];
+    RefPtr[1] = &RefFramePtr[bp[yp[1]]];
     Error += dsp_sad8x8 (cpi->dsp, SrcPtr[1], RefPtr[1],
                          cpi->stride[0]);
   }
   if(disp[2]){
-    SrcPtr[2] = &cpi->frame[bp[mp->y[2]]];
-    RefPtr[2] = &RefFramePtr[bp[mp->y[2]]];
+    SrcPtr[2] = &cpi->frame[bp[yp[2]]];
+    RefPtr[2] = &RefFramePtr[bp[yp[2]]];
     Error += dsp_sad8x8 (cpi->dsp, SrcPtr[2], RefPtr[2],
                          cpi->stride[0]);
   }
   if(disp[3]){
-    SrcPtr[3] = &cpi->frame[bp[mp->y[3]]];
-    RefPtr[3] = &RefFramePtr[bp[mp->y[3]]];
+    SrcPtr[3] = &cpi->frame[bp[yp[3]]];
+    RefPtr[3] = &RefFramePtr[bp[yp[3]]];
     Error += dsp_sad8x8 (cpi->dsp, SrcPtr[3], RefPtr[3],
                          cpi->stride[0]);
   }
@@ -436,31 +439,32 @@
   int off;
   unsigned char *cp = cpi->frag_coded;
   ogg_uint32_t *bp = cpi->frag_buffer_index;
+  int *yp = mp->yuv[0];
 
   dsp_save_fpu (cpi->dsp);
 
   /* Note which of the four blocks in the macro block are to be
      included in the search. */
-  disp[0] = cp[mp->y[0]];
-  disp[1] = cp[mp->y[1]];
-  disp[2] = cp[mp->y[2]];
-  disp[3] = cp[mp->y[3]];
+  disp[0] = cp[yp[0]];
+  disp[1] = cp[yp[1]];
+  disp[2] = cp[yp[2]];
+  disp[3] = cp[yp[3]];
 
   if(disp[0]){
-    SrcPtr[0] = &cpi->frame[bp[mp->y[0]]];
-    RefPtr[0] = &RefFramePtr[bp[mp->y[0]]];
+    SrcPtr[0] = &cpi->frame[bp[yp[0]]];
+    RefPtr[0] = &RefFramePtr[bp[yp[0]]];
   }
   if(disp[1]){
-    SrcPtr[1] = &cpi->frame[bp[mp->y[1]]];
-    RefPtr[1] = &RefFramePtr[bp[mp->y[1]]];
+    SrcPtr[1] = &cpi->frame[bp[yp[1]]];
+    RefPtr[1] = &RefFramePtr[bp[yp[1]]];
   }
   if(disp[2]){
-    SrcPtr[2] = &cpi->frame[bp[mp->y[2]]];
-    RefPtr[2] = &RefFramePtr[bp[mp->y[2]]];
+    SrcPtr[2] = &cpi->frame[bp[yp[2]]];
+    RefPtr[2] = &RefFramePtr[bp[yp[2]]];
   }
   if(disp[3]){
-    SrcPtr[3] = &cpi->frame[bp[mp->y[3]]];
-    RefPtr[3] = &RefFramePtr[bp[mp->y[3]]];
+    SrcPtr[3] = &cpi->frame[bp[yp[3]]];
+    RefPtr[3] = &RefFramePtr[bp[yp[3]]];
   }
 
   off = - ((MAX_MV_EXTENT/2) * cpi->stride[0]) - (MAX_MV_EXTENT/2);
@@ -658,29 +662,30 @@
                                         mv_t *MV ) {
   ogg_uint32_t  InterMVError;
   unsigned char *cp = cpi->frag_coded;
+  int *y = mp->yuv[0];
 
   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 ( cp[mp->y[0]] &&
-       cp[mp->y[1]] &&
-       cp[mp->y[2]] &&
-       cp[mp->y[3]] ) {
+  if ( cp[y[0]] &&
+       cp[y[1]] &&
+       cp[y[2]] &&
+       cp[y[3]] ) {
     
     /* Reset the error score. */
     InterMVError = 0;
     
     /* Get the error component from each coded block */
     InterMVError +=
-      GetBMVExhaustiveSearch(cpi, RefFramePtr, mp->y[0], &(MV[0]) );
+      GetBMVExhaustiveSearch(cpi, RefFramePtr, y[0], &(MV[0]) );
     InterMVError +=
-      GetBMVExhaustiveSearch(cpi, RefFramePtr, mp->y[1], &(MV[1]) );
+      GetBMVExhaustiveSearch(cpi, RefFramePtr, y[1], &(MV[1]) );
     InterMVError +=
-      GetBMVExhaustiveSearch(cpi, RefFramePtr, mp->y[2], &(MV[2]) );
+      GetBMVExhaustiveSearch(cpi, RefFramePtr, y[2], &(MV[2]) );
     InterMVError +=
-      GetBMVExhaustiveSearch(cpi, RefFramePtr, mp->y[3], &(MV[3]) );
+      GetBMVExhaustiveSearch(cpi, RefFramePtr, y[3], &(MV[3]) );
   }else{
     InterMVError = HUGE_ERROR;
   }



More information about the commits mailing list