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

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Fri Mar 14 03:55:35 PDT 2008


Author: xiphmont
Date: 2008-03-14 03:55:34 -0700 (Fri, 14 Mar 2008)
New Revision: 14587

Modified:
   branches/theora-thusnelda/lib/enc/codec_internal.h
   branches/theora-thusnelda/lib/enc/dct_decode.c
   branches/theora-thusnelda/lib/enc/dct_encode.c
   branches/theora-thusnelda/lib/enc/encode.c
   branches/theora-thusnelda/lib/enc/frinit.c
   branches/theora-thusnelda/lib/enc/mcenc.c
   branches/theora-thusnelda/lib/enc/mode.c
Log:
Get some more of the per-mblock refactoring in SVN


Modified: branches/theora-thusnelda/lib/enc/codec_internal.h
===================================================================
--- branches/theora-thusnelda/lib/enc/codec_internal.h	2008-03-14 03:44:27 UTC (rev 14586)
+++ branches/theora-thusnelda/lib/enc/codec_internal.h	2008-03-14 10:55:34 UTC (rev 14587)
@@ -118,7 +118,8 @@
 
 typedef struct macroblock {
   /* the blocks comprising this macroblock */
-  int yuv[3][4]; /* [Y,U,V][raster order] */
+  int Ryuv[4]; /* [Y in raster order] */
+  int Hyuv[3][4]; /* [Y,U,V][hilbert order] */
 
   int cneighbors[4];      
   int ncneighbors;

Modified: branches/theora-thusnelda/lib/enc/dct_decode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/dct_decode.c	2008-03-14 03:44:27 UTC (rev 14586)
+++ branches/theora-thusnelda/lib/enc/dct_decode.c	2008-03-14 10:55:34 UTC (rev 14587)
@@ -451,22 +451,22 @@
 
   for (i=0; i<cpi->macro_total; i++, mp++ ) {
     coding_mode_t mode = mp->mode;
-    int fi = mp->yuv[0][0];
+    int fi = mp->Hyuv[0][0];
     if ( cp[fi] ) ExpandBlock( cpi, mode, fi );
 
-    fi = mp->yuv[0][1];
+    fi = mp->Hyuv[0][1];
     if ( cp[fi] ) ExpandBlock( cpi, mode, fi );
 
-    fi = mp->yuv[0][2];
+    fi = mp->Hyuv[0][2];
     if ( cp[fi] ) ExpandBlock( cpi, mode, fi );
 
-    fi = mp->yuv[0][3];
+    fi = mp->Hyuv[0][3];
     if ( cp[fi] ) ExpandBlock( cpi, mode, fi );
 
-    fi = mp->yuv[1][0];
+    fi = mp->Hyuv[1][0];
     if ( cp[fi] ) ExpandBlock( cpi, mode, fi );
 
-    fi = mp->yuv[2][0];
+    fi = mp->Hyuv[2][0];
     if ( cp[fi] ) ExpandBlock( cpi, mode, fi );
   }
 

Modified: branches/theora-thusnelda/lib/enc/dct_encode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/dct_encode.c	2008-03-14 03:44:27 UTC (rev 14586)
+++ branches/theora-thusnelda/lib/enc/dct_encode.c	2008-03-14 10:55:34 UTC (rev 14587)
@@ -209,83 +209,74 @@
   }
 }
 
-static void tokenize_groups(CP_INSTANCE *cpi, int plane,
-			    int *eob_run, int *eob_plane, 
-			    int *eob_pre){
-  int SB,B;
+static void tokenize_block(CP_INSTANCE *cpi, int fi, int plane,
+			   int *eob_run, int *eob_plane, 
+			   int *eob_pre){
   unsigned char *cp=cpi->frag_coded;
-
-  for ( SB=0; SB<cpi->super_n[plane]; SB++ ){
-    superblock_t *sp = &cpi->super[plane][SB];
-    for ( B=0; B<16; B++ ) {
-      int fi = sp->f[B];
-      if ( cp[fi] ) {
-
-	int coeff = 0;
-	dct_t *dct = &cpi->frag_dct[fi];
-	cpi->frag_nonzero[fi] = 0;
+  if ( cp[fi] ) {
+    int coeff = 0;
+    dct_t *dct = &cpi->frag_dct[fi];
+    cpi->frag_nonzero[fi] = 0;
+    
+    while(coeff < BLOCK_SIZE){
+      ogg_int16_t val = dct->data[coeff];
+      int zero_run;
+      int i = coeff;
+      
+      cpi->frag_nonzero[fi] = coeff;
+      
+      while( !val && (++i < BLOCK_SIZE) )
+	val = dct->data[i];
+	  
+      if ( i == BLOCK_SIZE ){
 	
-	while(coeff < BLOCK_SIZE){
-	  ogg_int16_t val = dct->data[coeff];
-	  int zero_run;
-	  int i = coeff;
+	/* if there are no other tokens in this group yet, set up to be
+	   prepended later.  Group 0/Plane 0 is the exception (can't be
+	   prepended) */
+	if(cpi->dct_token_count[plane][coeff] == 0 && (coeff||plane)){
+	  eob_pre[coeff]++;
+#ifdef COLLECT_METRICS
+	  cpi->dct_eob_fi_stack[plane][coeff][cpi->dct_eob_fi_count[plane][coeff]++]=fi;
+#endif
+	}else{
+	  if(eob_run[coeff] == 4095){
+	    emit_eob_run(cpi,eob_plane[coeff],coeff,4095);
+	    eob_run[coeff] = 0;
+	  }
 	  
-	  cpi->frag_nonzero[fi] = coeff;
+	  if(eob_run[coeff]==0)
+	    eob_plane[coeff]=plane;
 	  
-	  while( !val && (++i < BLOCK_SIZE) )
-	    val = dct->data[i];
-	  
-	  if ( i == BLOCK_SIZE ){
-	    
-	    /* if there are no other tokens in this group yet, set up to be
-	       prepended later.  Group 0/Plane 0 is the exception (can't be
-	       prepended) */
-	    if(cpi->dct_token_count[plane][coeff] == 0 && (coeff||plane)){
-	      eob_pre[coeff]++;
+	  eob_run[coeff]++;
 #ifdef COLLECT_METRICS
-	      cpi->dct_eob_fi_stack[plane][coeff][cpi->dct_eob_fi_count[plane][coeff]++]=fi;
+	  cpi->dct_eob_fi_stack[plane][coeff][cpi->dct_eob_fi_count[plane][coeff]++]=fi;
 #endif
-	    }else{
-	      if(eob_run[coeff] == 4095){
-		emit_eob_run(cpi,eob_plane[coeff],coeff,4095);
-		eob_run[coeff] = 0;
-	      }
-	      
-	      if(eob_run[coeff]==0)
-		eob_plane[coeff]=plane;
-	      
-	      eob_run[coeff]++;
-#ifdef COLLECT_METRICS
-	      cpi->dct_eob_fi_stack[plane][coeff][cpi->dct_eob_fi_count[plane][coeff]++]=fi;
-#endif
-	    }
-	    coeff = BLOCK_SIZE;
+	}
+	coeff = BLOCK_SIZE;
+      }else{
+	
+	if(eob_run[coeff]){
+	  emit_eob_run(cpi,eob_plane[coeff],coeff,eob_run[coeff]);
+	  eob_run[coeff]=0;
+	}
+	
+	zero_run = i-coeff;
+	if (zero_run){
+	  ogg_uint32_t absval = abs(val);
+	  if ( ((absval == 1) && (zero_run <= 17)) ||
+	       ((absval <= 3) && (zero_run <= 3)) ) {
+	    TokenizeDctRunValue( cpi, plane, coeff, zero_run, val, fi);
+	    coeff = i+1;
 	  }else{
-	    
-	    if(eob_run[coeff]){
-	      emit_eob_run(cpi,eob_plane[coeff],coeff,eob_run[coeff]);
-	      eob_run[coeff]=0;
-	    }
-	    
-	    zero_run = i-coeff;
-	    if (zero_run){
-	      ogg_uint32_t absval = abs(val);
-	      if ( ((absval == 1) && (zero_run <= 17)) ||
-		   ((absval <= 3) && (zero_run <= 3)) ) {
-		TokenizeDctRunValue( cpi, plane, coeff, zero_run, val, fi);
-		coeff = i+1;
-	      }else{
-		if ( zero_run <= 8 )
-		  add_token(cpi, plane, coeff, DCT_SHORT_ZRL_TOKEN, zero_run - 1, fi);
-		else
-		  add_token(cpi, plane, coeff, DCT_ZRL_TOKEN, zero_run - 1, fi);
-		coeff = i;
-	      }
-	    }else{
-	      TokenizeDctValue(cpi, plane, coeff, val, fi);
-	      coeff = i+1;
-	    }
+	    if ( zero_run <= 8 )
+	      add_token(cpi, plane, coeff, DCT_SHORT_ZRL_TOKEN, zero_run - 1, fi);
+	    else
+	      add_token(cpi, plane, coeff, DCT_ZRL_TOKEN, zero_run - 1, fi);
+	    coeff = i;
 	  }
+	}else{
+	  TokenizeDctValue(cpi, plane, coeff, val, fi);
+	  coeff = i+1;
 	}
       }
     }
@@ -298,7 +289,7 @@
 
   int eob_pre[3][64];
   
-  int i,j;
+  int i,j,sbi,mbi;
 
   memset(eob_run, 0, sizeof(eob_run));
   memset(eob_pre, 0, sizeof(eob_pre));
@@ -328,10 +319,36 @@
 #endif
   }
 
-  /* Tokenize the dct data. */
-  for(i=0;i<3;i++)
-    tokenize_groups (cpi, i, eob_run[i], eob_plane[i], eob_pre[i]);
   
+  for (sbi=0; sbi < cpi->super_n[0]; sbi++ ){
+    superblock_t *sp = &cpi->super[0][sbi];
+    for (mbi=0; mbi < 4; mbi++ ){
+      int bi;
+      macroblock_t *mb = &cpi->macro[sp->m[mbi]];
+      for (bi=0; bi<4; bi++ ) {
+	int fi = mb->Hyuv[0][bi];
+	tokenize_block(cpi, fi, 0, eob_run[0], eob_plane[0], eob_pre[0]);
+      }
+    }
+  }
+  for (sbi=0; sbi < cpi->super_n[1]; sbi++ ){
+    superblock_t *sb = &cpi->super[1][sbi];
+    int bi;
+    for (bi=0; bi<16; bi++ ) {
+      int fi = sb->f[bi];
+      tokenize_block(cpi, fi, 1, eob_run[1], eob_plane[1], eob_pre[1]);
+    }
+  }
+
+  for (sbi=0; sbi < cpi->super_n[2]; sbi++ ){
+    superblock_t *sb = &cpi->super[2][sbi];
+    int bi;
+    for (bi=0; bi<16; bi++ ) {
+      int fi = sb->f[bi];
+      tokenize_block(cpi, fi, 2, eob_run[2], eob_plane[2], eob_pre[2]);
+    }
+  }
+
   /* tie together eob runs at the beginnings/ends of coeff groups */
   {
     int coeff = 0;

Modified: branches/theora-thusnelda/lib/enc/encode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/encode.c	2008-03-14 03:44:27 UTC (rev 14586)
+++ branches/theora-thusnelda/lib/enc/encode.c	2008-03-14 10:55:34 UTC (rev 14587)
@@ -163,10 +163,9 @@
   switch(subsample){
   case 1:
     for ( ; mp<mp_end; mp++ ) {
-      int *yuv = mp->yuv[plane];
 
       for ( B=0; B<4; B++) {
-	fi = yuv[B];
+	fi = mp->Ryuv[B];
 	if ( cp[fi] ) 
 	  TransformQuantizeBlock( cpi, mp->mode, fi, mp->mv[B] );
       }
@@ -177,7 +176,7 @@
     return 1;
   case 4:
     for ( ; mp<mp_end; mp++ ) {
-      int fi = mp->yuv[plane][0];
+      int fi = mp->Hyuv[plane][0];
       if ( cp[fi] ) {
 	
 	if(mp->mode == CODE_INTER_FOURMV){

Modified: branches/theora-thusnelda/lib/enc/frinit.c
===================================================================
--- branches/theora-thusnelda/lib/enc/frinit.c	2008-03-14 03:44:27 UTC (rev 14586)
+++ branches/theora-thusnelda/lib/enc/frinit.c	2008-03-14 10:55:34 UTC (rev 14587)
@@ -220,19 +220,20 @@
   /* 4:2:0 only for now */
   {
     int row,col,frag;
-    int scanx[4] = {0,1,0,1};
-    int scany[4] = {0,0,1,1};
+    int scanx[4][4] = { {0,1,1,0}, {1,0,0,1}, {0,0,1,1}, {0,0,1,1} };
+    int scany[4][4] = { {0,0,1,1}, {1,1,0,0}, {0,1,1,0}, {0,1,1,0} };
 
     for(row=0;row<cpi->macro_v;row++){
       int baserow = row*2;
       for(col=0;col<cpi->macro_h;col++){
 	int basecol = col*2;
 	int macroindex = row*cpi->macro_h + col;
+	int hpos = (col&1) + (row&1)*2;
 	int fragindex;
 	for(frag=0;frag<4;frag++){
 	  /* translate to fragment index */
-	  int frow = baserow + scany[frag];
-	  int fcol = basecol + scanx[frag];
+	  int frow = baserow + scany[hpos][frag];
+	  int fcol = basecol + scanx[hpos][frag];
 	  if(frow<cpi->frag_v[0] && fcol<cpi->frag_h[0]){
 	    fragindex = frow*cpi->frag_h[0] + fcol;	    
 #ifdef COLLECT_METRICS
@@ -240,7 +241,8 @@
 #endif
 	  }else
 	    fragindex = cpi->frag_total;
-	  cpi->macro[macroindex].yuv[0][frag] = fragindex;
+	  cpi->macro[macroindex].Ryuv[frag] = (baserow+((frag&2)>>1))*cpi->frag_h[0]+basecol+(frag&1);
+	  cpi->macro[macroindex].Hyuv[0][frag] = fragindex;
 	}
 	
 	if(row<cpi->frag_v[1] && col<cpi->frag_h[1]){
@@ -250,7 +252,7 @@
 #endif
 	}else
 	  fragindex = cpi->frag_total;
-	cpi->macro[macroindex].yuv[1][0] = fragindex;
+	cpi->macro[macroindex].Hyuv[1][0] = fragindex;
 	
 	if(row<cpi->frag_v[2] && col<cpi->frag_h[2]){
 	  fragindex = cpi->frag_n[0] + cpi->frag_n[1] + macroindex; 
@@ -259,7 +261,7 @@
 #endif
 	}else
 	  fragindex = cpi->frag_total;
-	cpi->macro[macroindex].yuv[2][0] = fragindex;
+	cpi->macro[macroindex].Hyuv[2][0] = fragindex;
 	
       }
     }
@@ -304,8 +306,10 @@
   {
     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;
+      for(f=0;f<4;f++){
+	cpi->macro[cpi->macro_total].Ryuv[f] = cpi->frag_total;
+	cpi->macro[cpi->macro_total].Hyuv[p][f] = cpi->frag_total;
+      }
     cpi->macro[cpi->macro_total].ncneighbors=0;
     cpi->macro[cpi->macro_total].npneighbors=0;
 #ifdef COLLECT_METRICS

Modified: branches/theora-thusnelda/lib/enc/mcenc.c
===================================================================
--- branches/theora-thusnelda/lib/enc/mcenc.c	2008-03-14 03:44:27 UTC (rev 14586)
+++ branches/theora-thusnelda/lib/enc/mcenc.c	2008-03-14 10:55:34 UTC (rev 14587)
@@ -201,7 +201,7 @@
   int i;
   err=0;
   for(i=0;i<4;i++){
-    int fi = mb->yuv[0][i];
+    int fi = mb->Ryuv[i];
     ogg_uint32_t base_offset = cpi->frag_buffer_index[fi];
     const unsigned char *cur = cpi->frame + base_offset;
     const unsigned char *ref = (_goldenp ? cpi->golden : cpi->recon) + base_offset;
@@ -229,7 +229,7 @@
   mvoffset=_delta.x+_delta.y*stride;
   err=0;
   for(bi=0;bi<4;bi++){
-    int fi = mb->yuv[0][bi];
+    int fi = mb->Ryuv[bi];
     if(fi < cpi->frag_total){ /* last fragment is the 'invalid fragment' */
       ogg_uint32_t base_offset = cpi->frag_buffer_index[fi];
       const unsigned char *cur = cpi->frame + base_offset;
@@ -311,7 +311,7 @@
   int best_site;
   int sitei;
   int err;
-  int fi = mb->yuv[0][_bi];
+  int fi = mb->Ryuv[_bi];
 
   if(fi == cpi->frag_total) return _best_err;
 
@@ -618,12 +618,12 @@
     /* basic 1MV search always done for all macroblocks, coded or not, keyframe or not */
     oc_mcenc_search(cpi, &mcenc, mbi, 0, mb->mv);
 
-    /* replace the block MVs for not-coded blocks with (0,0).*/    
+    /* replace the block MVs for not-coded blocks with (0,0).*/   
     mb->coded = 0;
     for ( bi=0; bi<4; bi++ ){
-      int fi = mb->yuv[0][bi];
+      int fi = mb->Ryuv[bi];
       if(!cp[fi]) 
-	mb->mv[fi]=(mv_t){0,0};
+	mb->mv[bi]=(mv_t){0,0};
       else
 	mb->coded |= (1<<bi);
     }

Modified: branches/theora-thusnelda/lib/enc/mode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/mode.c	2008-03-14 03:44:27 UTC (rev 14586)
+++ branches/theora-thusnelda/lib/enc/mode.c	2008-03-14 10:55:34 UTC (rev 14587)
@@ -257,23 +257,23 @@
   int fi;
   /* all frags in a macroblock are valid so long as the macroblock itself is valid */
   if(mbi < cpi->macro_total){ 
-    fi = mb->yuv[0][0];
+    fi = mb->Hyuv[0][0];
     if(all || cp[fi])
       cost += BINMAP(mode_rate[qi][0][1],BIntraSAD(cpi,fi,0));
-    fi = mb->yuv[0][1];
+    fi = mb->Hyuv[0][1];
     if(all || cp[fi])
       cost += BINMAP(mode_rate[qi][0][1],BIntraSAD(cpi,fi,0));
-    fi = mb->yuv[0][2];
+    fi = mb->Hyuv[0][2];
     if(all || cp[fi])
       cost += BINMAP(mode_rate[qi][0][1],BIntraSAD(cpi,fi,0));
-    fi = mb->yuv[0][3];
+    fi = mb->Hyuv[0][3];
     if(all || cp[fi])
       cost += BINMAP(mode_rate[qi][0][1],BIntraSAD(cpi,fi,0));
 
-    fi = mb->yuv[1][0];
+    fi = mb->Hyuv[1][0];
     if(all || cp[fi])
       cost += BINMAP(mode_rate[qi][1][1],BIntraSAD(cpi,fi,1));
-    fi = mb->yuv[2][0];
+    fi = mb->Hyuv[2][0];
     if(all || cp[fi])
       cost += BINMAP(mode_rate[qi][2][1],BIntraSAD(cpi,fi,2));
    
@@ -363,23 +363,23 @@
   int cost = 0;
   int fi;
 
-  fi=mb->yuv[0][0];
+  fi=mb->Hyuv[0][0];
   if(cp[fi])
     cost += BINMAP(mode_rate[qi][0][0],BInterSAD(cpi,fi,0,goldenp,mv,0));
-  fi=mb->yuv[0][1];
+  fi=mb->Hyuv[0][1];
   if(cp[fi])
     cost += BINMAP(mode_rate[qi][0][0],BInterSAD(cpi,fi,0,goldenp,mv,0));
-  fi=mb->yuv[0][2];
+  fi=mb->Hyuv[0][2];
   if(cp[fi])
     cost += BINMAP(mode_rate[qi][0][0],BInterSAD(cpi,fi,0,goldenp,mv,0));
-  fi=mb->yuv[0][3];
+  fi=mb->Hyuv[0][3];
   if(cp[fi])
     cost += BINMAP(mode_rate[qi][0][0],BInterSAD(cpi,fi,0,goldenp,mv,0));
 
-  fi=mb->yuv[1][0];
+  fi=mb->Hyuv[1][0];
   if(cp[fi])
     cost += BINMAP(mode_rate[qi][1][0],BInterSAD(cpi,fi,1,goldenp,mv,1));
-  fi=mb->yuv[2][0];
+  fi=mb->Hyuv[2][0];
   if(cp[fi])
     cost += BINMAP(mode_rate[qi][2][0],BInterSAD(cpi,fi,2,goldenp,mv,1));
 
@@ -394,16 +394,16 @@
   mv_t ch;
   int fi;
 
-  fi=mb->yuv[0][0];
+  fi=mb->Hyuv[0][0];
   if(cp[fi])
     cost += BINMAP(mode_rate[qi][0][0],BInterSAD(cpi,fi,0,goldenp,mv[0],0));
-  fi=mb->yuv[0][1];
+  fi=mb->Hyuv[0][1];
   if(cp[fi])
     cost += BINMAP(mode_rate[qi][0][0],BInterSAD(cpi,fi,0,goldenp,mv[1],0));
-  fi=mb->yuv[0][2];
+  fi=mb->Hyuv[0][2];
   if(cp[fi])
     cost += BINMAP(mode_rate[qi][0][0],BInterSAD(cpi,fi,0,goldenp,mv[2],0));
-  fi=mb->yuv[0][3];
+  fi=mb->Hyuv[0][3];
   if(cp[fi])
     cost += BINMAP(mode_rate[qi][0][0],BInterSAD(cpi,fi,0,goldenp,mv[3],0));
 
@@ -415,10 +415,10 @@
   ch.x = ( ch.x >= 0 ? (ch.x + 2) / 4 : (ch.x - 2) / 4);
   ch.y = ( ch.y >= 0 ? (ch.y + 2) / 4 : (ch.y - 2) / 4);
   
-  fi=mb->yuv[1][0];
+  fi=mb->Hyuv[1][0];
   if(cp[fi])
     cost += BINMAP(mode_rate[qi][1][0],BInterSAD(cpi,fi,1,goldenp,ch,1));
-  fi=mb->yuv[2][0];
+  fi=mb->Hyuv[2][0];
   if(cp[fi])
     cost += BINMAP(mode_rate[qi][2][0],BInterSAD(cpi,fi,2,goldenp,ch,1));
 



More information about the commits mailing list