[xiph-commits] r14643 - branches/theora-thusnelda/lib/enc
xiphmont at svn.xiph.org
xiphmont at svn.xiph.org
Fri Mar 28 08:41:25 PDT 2008
Author: xiphmont
Date: 2008-03-28 08:41:24 -0700 (Fri, 28 Mar 2008)
New Revision: 14643
Modified:
branches/theora-thusnelda/lib/enc/codec_internal.h
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:
Expand the Ryuv ordering array in MB to include U/V; useful for 4:4:4 and 4:2:2
Correct a Ryuv vs. Hyuv ordering bug in 4MV SAD computation (4MV vectors are coded in raster order even thought he blocks are coded in Hilbert order)
Modified: branches/theora-thusnelda/lib/enc/codec_internal.h
===================================================================
--- branches/theora-thusnelda/lib/enc/codec_internal.h 2008-03-27 15:21:54 UTC (rev 14642)
+++ branches/theora-thusnelda/lib/enc/codec_internal.h 2008-03-28 15:41:24 UTC (rev 14643)
@@ -118,7 +118,7 @@
typedef struct macroblock {
/* the blocks comprising this macroblock */
- int Ryuv[4]; /* [Y in raster order] */
+ int Ryuv[3][4]; /* [Y,U,V][raster order] */
int Hyuv[3][4]; /* [Y,U,V][hilbert order] */
int cneighbors[4];
Modified: branches/theora-thusnelda/lib/enc/encode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/encode.c 2008-03-27 15:21:54 UTC (rev 14642)
+++ branches/theora-thusnelda/lib/enc/encode.c 2008-03-28 15:41:24 UTC (rev 14643)
@@ -165,7 +165,7 @@
for ( ; mp<mp_end; mp++ ) {
for ( B=0; B<4; B++) {
- fi = mp->Ryuv[B];
+ fi = mp->Ryuv[plane][B];
if ( cp[fi] )
TransformQuantizeBlock( cpi, mp->mode, fi, mp->mv[B] );
}
Modified: branches/theora-thusnelda/lib/enc/frinit.c
===================================================================
--- branches/theora-thusnelda/lib/enc/frinit.c 2008-03-27 15:21:54 UTC (rev 14642)
+++ branches/theora-thusnelda/lib/enc/frinit.c 2008-03-28 15:41:24 UTC (rev 14643)
@@ -220,8 +220,8 @@
/* 4:2:0 only for now */
{
int row,col,frag;
- 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} };
+ int Hscanx[4][4] = { {0,1,1,0}, {1,0,0,1}, {0,0,1,1}, {0,0,1,1} };
+ int Hscany[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;
@@ -229,40 +229,59 @@
int basecol = col*2;
int macroindex = row*cpi->macro_h + col;
int hpos = (col&1) + (row&1)*2;
- int fragindex;
+
+ /* Y */
for(frag=0;frag<4;frag++){
- /* translate to fragment index */
- 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;
+ int Hrow = baserow + Hscany[hpos][frag];
+ int Hcol = basecol + Hscanx[hpos][frag];
+ int Rrow = baserow + ((frag>>1)&1);
+ int Rcol = basecol + (frag&1);
+
+ cpi->macro[macroindex].Hyuv[0][frag] = cpi->frag_total; // default
+ cpi->macro[macroindex].Ryuv[0][frag] = cpi->frag_total; //default
+ if(Hrow<cpi->frag_v[0] && Hcol<cpi->frag_h[0]){
+ cpi->macro[macroindex].Hyuv[0][frag] = Hrow*cpi->frag_h[0] + Hcol;
#ifdef COLLECT_METRICS
cpi->frag_mbi[fragindex] = macroindex;
#endif
- }else
- fragindex = cpi->frag_total;
- cpi->macro[macroindex].Ryuv[frag] = (baserow+((frag&2)>>1))*cpi->frag_h[0]+basecol+(frag&1);
- cpi->macro[macroindex].Hyuv[0][frag] = fragindex;
+ }
+ if(Rrow<cpi->frag_v[0] && Rcol<cpi->frag_h[0])
+ cpi->macro[macroindex].Ryuv[0][frag] = Rrow*cpi->frag_h[0] + Rcol;
}
-
+
+ /* U */
+ cpi->macro[macroindex].Ryuv[1][0] = cpi->frag_total;
+ cpi->macro[macroindex].Ryuv[1][1] = cpi->frag_total;
+ cpi->macro[macroindex].Ryuv[1][2] = cpi->frag_total;
+ cpi->macro[macroindex].Ryuv[1][3] = cpi->frag_total;
+ cpi->macro[macroindex].Hyuv[1][0] = cpi->frag_total;
+ cpi->macro[macroindex].Hyuv[1][1] = cpi->frag_total;
+ cpi->macro[macroindex].Hyuv[1][2] = cpi->frag_total;
+ cpi->macro[macroindex].Hyuv[1][3] = cpi->frag_total;
if(row<cpi->frag_v[1] && col<cpi->frag_h[1]){
- fragindex = cpi->frag_n[0] + macroindex;
+ cpi->macro[macroindex].Hyuv[1][0] = cpi->frag_n[0] + macroindex;
+ cpi->macro[macroindex].Ryuv[1][0] = cpi->frag_n[0] + macroindex;
#ifdef COLLECT_METRICS
cpi->frag_mbi[fragindex] = macroindex;
#endif
- }else
- fragindex = cpi->frag_total;
- cpi->macro[macroindex].Hyuv[1][0] = fragindex;
+ }
+ /* V */
+ cpi->macro[macroindex].Ryuv[2][0] = cpi->frag_total;
+ cpi->macro[macroindex].Ryuv[2][1] = cpi->frag_total;
+ cpi->macro[macroindex].Ryuv[2][2] = cpi->frag_total;
+ cpi->macro[macroindex].Ryuv[2][3] = cpi->frag_total;
+ cpi->macro[macroindex].Hyuv[2][0] = cpi->frag_total;
+ cpi->macro[macroindex].Hyuv[2][1] = cpi->frag_total;
+ cpi->macro[macroindex].Hyuv[2][2] = cpi->frag_total;
+ cpi->macro[macroindex].Hyuv[2][3] = cpi->frag_total;
if(row<cpi->frag_v[2] && col<cpi->frag_h[2]){
- fragindex = cpi->frag_n[0] + cpi->frag_n[1] + macroindex;
+ cpi->macro[macroindex].Hyuv[2][0] = cpi->frag_n[0] + cpi->frag_n[1] + macroindex;
+ cpi->macro[macroindex].Ryuv[2][0] = cpi->frag_n[0] + cpi->frag_n[1] + macroindex;
#ifdef COLLECT_METRICS
cpi->frag_mbi[fragindex] = macroindex;
#endif
- }else
- fragindex = cpi->frag_total;
- cpi->macro[macroindex].Hyuv[2][0] = fragindex;
-
+ }
}
}
}
@@ -307,7 +326,7 @@
int p,f;
for(p=0;p<3;p++)
for(f=0;f<4;f++){
- cpi->macro[cpi->macro_total].Ryuv[f] = cpi->frag_total;
+ cpi->macro[cpi->macro_total].Ryuv[p][f] = cpi->frag_total;
cpi->macro[cpi->macro_total].Hyuv[p][f] = cpi->frag_total;
}
cpi->macro[cpi->macro_total].ncneighbors=0;
Modified: branches/theora-thusnelda/lib/enc/mcenc.c
===================================================================
--- branches/theora-thusnelda/lib/enc/mcenc.c 2008-03-27 15:21:54 UTC (rev 14642)
+++ branches/theora-thusnelda/lib/enc/mcenc.c 2008-03-28 15:41:24 UTC (rev 14643)
@@ -201,7 +201,7 @@
int i;
err=0;
for(i=0;i<4;i++){
- int fi = mb->Ryuv[i];
+ int fi = mb->Ryuv[0][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->lastrecon) + base_offset;
@@ -230,7 +230,7 @@
mvoffset=_delta.x+_delta.y*stride;
err=0;
for(bi=0;bi<4;bi++){
- int fi = mb->Ryuv[bi];
+ int fi = mb->Ryuv[0][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;
@@ -314,7 +314,7 @@
int best_site;
int sitei;
int err;
- int fi = mb->Ryuv[_bi];
+ int fi = mb->Ryuv[0][_bi];
if(fi == cpi->frag_total) return _best_err;
@@ -625,7 +625,7 @@
/* replace the block MVs for not-coded blocks with (0,0).*/
mb->coded = 0;
for ( bi=0; bi<4; bi++ ){
- int fi = mb->Ryuv[bi];
+ int fi = mb->Ryuv[0][bi];
if(!cp[fi])
mb->mv[bi]=(mv_t){0,0};
else
Modified: branches/theora-thusnelda/lib/enc/mode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/mode.c 2008-03-27 15:21:54 UTC (rev 14642)
+++ branches/theora-thusnelda/lib/enc/mode.c 2008-03-28 15:41:24 UTC (rev 14643)
@@ -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->Hyuv[0][0];
+ fi = mb->Ryuv[0][0];
if(all || cp[fi])
cost += BINMAP(mode_rate[qi][0][1],BIntraSAD(cpi,fi,0));
- fi = mb->Hyuv[0][1];
+ fi = mb->Ryuv[0][1];
if(all || cp[fi])
cost += BINMAP(mode_rate[qi][0][1],BIntraSAD(cpi,fi,0));
- fi = mb->Hyuv[0][2];
+ fi = mb->Ryuv[0][2];
if(all || cp[fi])
cost += BINMAP(mode_rate[qi][0][1],BIntraSAD(cpi,fi,0));
- fi = mb->Hyuv[0][3];
+ fi = mb->Ryuv[0][3];
if(all || cp[fi])
cost += BINMAP(mode_rate[qi][0][1],BIntraSAD(cpi,fi,0));
- fi = mb->Hyuv[1][0];
+ fi = mb->Ryuv[1][0];
if(all || cp[fi])
cost += BINMAP(mode_rate[qi][1][1],BIntraSAD(cpi,fi,1));
- fi = mb->Hyuv[2][0];
+ fi = mb->Ryuv[2][0];
if(all || cp[fi])
cost += BINMAP(mode_rate[qi][2][1],BIntraSAD(cpi,fi,2));
@@ -336,23 +336,23 @@
int cost = 0;
int fi;
- fi=mb->Hyuv[0][0];
+ fi=mb->Ryuv[0][0];
if(cp[fi])
cost += BINMAP(mode_rate[qi][0][0],BInterSAD(cpi,fi,0,goldenp,mv,0));
- fi=mb->Hyuv[0][1];
+ fi=mb->Ryuv[0][1];
if(cp[fi])
cost += BINMAP(mode_rate[qi][0][0],BInterSAD(cpi,fi,0,goldenp,mv,0));
- fi=mb->Hyuv[0][2];
+ fi=mb->Ryuv[0][2];
if(cp[fi])
cost += BINMAP(mode_rate[qi][0][0],BInterSAD(cpi,fi,0,goldenp,mv,0));
- fi=mb->Hyuv[0][3];
+ fi=mb->Ryuv[0][3];
if(cp[fi])
cost += BINMAP(mode_rate[qi][0][0],BInterSAD(cpi,fi,0,goldenp,mv,0));
- fi=mb->Hyuv[1][0];
+ fi=mb->Ryuv[1][0];
if(cp[fi])
cost += BINMAP(mode_rate[qi][1][0],BInterSAD(cpi,fi,1,goldenp,mv,1));
- fi=mb->Hyuv[2][0];
+ fi=mb->Ryuv[2][0];
if(cp[fi])
cost += BINMAP(mode_rate[qi][2][0],BInterSAD(cpi,fi,2,goldenp,mv,1));
@@ -367,16 +367,16 @@
mv_t ch;
int fi;
- fi=mb->Hyuv[0][0];
+ fi=mb->Ryuv[0][0];
if(cp[fi])
cost += BINMAP(mode_rate[qi][0][0],BInterSAD(cpi,fi,0,goldenp,mv[0],0));
- fi=mb->Hyuv[0][1];
+ fi=mb->Ryuv[0][1];
if(cp[fi])
cost += BINMAP(mode_rate[qi][0][0],BInterSAD(cpi,fi,0,goldenp,mv[1],0));
- fi=mb->Hyuv[0][2];
+ fi=mb->Ryuv[0][2];
if(cp[fi])
cost += BINMAP(mode_rate[qi][0][0],BInterSAD(cpi,fi,0,goldenp,mv[2],0));
- fi=mb->Hyuv[0][3];
+ fi=mb->Ryuv[0][3];
if(cp[fi])
cost += BINMAP(mode_rate[qi][0][0],BInterSAD(cpi,fi,0,goldenp,mv[3],0));
@@ -388,10 +388,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->Hyuv[1][0];
+ fi=mb->Ryuv[1][0];
if(cp[fi])
cost += BINMAP(mode_rate[qi][1][0],BInterSAD(cpi,fi,1,goldenp,ch,1));
- fi=mb->Hyuv[2][0];
+ fi=mb->Ryuv[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