[xiph-commits] r14313 - branches/theora-thusnelda/lib/enc
xiphmont at svn.xiph.org
xiphmont at svn.xiph.org
Tue Dec 18 02:43:58 PST 2007
Author: xiphmont
Date: 2007-12-18 02:43:58 -0800 (Tue, 18 Dec 2007)
New Revision: 14313
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/encoder_toplevel.c
branches/theora-thusnelda/lib/enc/frinit.c
Log:
packing rearrangement finished, now to try to roll transform/tokenize...
Modified: branches/theora-thusnelda/lib/enc/codec_internal.h
===================================================================
--- branches/theora-thusnelda/lib/enc/codec_internal.h 2007-12-18 09:25:43 UTC (rev 14312)
+++ branches/theora-thusnelda/lib/enc/codec_internal.h 2007-12-18 10:43:58 UTC (rev 14313)
@@ -101,22 +101,15 @@
ogg_uint32_t Frequency;
} HUFF_ENTRY;
+typedef struct {
+ ogg_int16_t data[64];
+} dct_t;
+
typedef struct{
ogg_int32_t x;
ogg_int32_t y;
} mv_t;
-typedef struct fragment fragment_t;
-
-struct fragment {
- mv_t mv;
- ogg_int16_t pred_dc;
- ogg_int16_t dct[64];
- unsigned char nonzero;
-
- fragment_t *next;
-};
-
typedef struct macroblock {
int y[4]; // raster order
int u;
@@ -160,8 +153,11 @@
unsigned char *frag_coded;
coding_mode_t *frag_mode;
ogg_uint32_t *frag_buffer_index;
+ mv_t *frag_mv;
+ unsigned char *frag_nonzero;
+ ogg_int16_t *frag_dc;
+ dct_t *frag_dct;
- fragment_t *frag[3];
macroblock_t *macro;
superblock_t *super[3];
@@ -196,8 +192,8 @@
/*********************************************************************/
/* Token Buffers */
- fragment_t *coded_head;
- fragment_t *coded_tail;
+ int *coded_fi_list;
+ int coded_fi_count;
unsigned char *dct_token_storage;
ogg_uint16_t *dct_token_eb_storage;
Modified: branches/theora-thusnelda/lib/enc/dct_decode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/dct_decode.c 2007-12-18 09:25:43 UTC (rev 14312)
+++ branches/theora-thusnelda/lib/enc/dct_decode.c 2007-12-18 10:43:58 UTC (rev 14313)
@@ -36,18 +36,19 @@
}
static void ExpandBlock ( CP_INSTANCE *cpi, int fi){
- fragment_t *fp = &cpi->frag[0][fi];
int mode = cpi->frag_mode[fi];
int qi = cpi->BaseQ; // temporary
- int plane = (fp<cpi->frag[1] ? 0 : (fp<cpi->frag[2] ? 1 : 2));
+ int plane = (fi<cpi->frag_n[0] ? 0 : (fi-cpi->frag_n[0]<cpi->frag_n[1] ? 1 : 2));
int inter = (mode != CODE_INTRA);
ogg_int16_t reconstruct[64];
ogg_int16_t *quantizers = cpi->quant_tables[inter][plane][qi];
- ogg_int16_t *data = fp->dct;
+ ogg_int16_t *data = cpi->frag_dct[fi].data;
int bi = cpi->frag_buffer_index[fi];
+ data[0] = cpi->frag_dc[fi];
+
/* Invert quantisation and DCT to get pixel data. */
- switch(fp->nonzero){
+ switch(cpi->frag_nonzero[fi]){
case 0:case 1:
IDct1( data, quantizers, reconstruct );
break;
@@ -445,11 +446,11 @@
}
void ReconRefFrames (CP_INSTANCE *cpi){
- fragment_t *fp = cpi->coded_tail;
+ int *fip = cpi->coded_fi_list;
- while(fp){
- ExpandBlock( cpi, fp-cpi->frag[0] );
- fp = fp->next;
+ while(*fip>=0){
+ ExpandBlock( cpi, *fip );
+ fip++;
}
memcpy(cpi->lastrecon,cpi->recon,sizeof(*cpi->recon)*cpi->frame_size);
Modified: branches/theora-thusnelda/lib/enc/dct_encode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/dct_encode.c 2007-12-18 09:25:43 UTC (rev 14312)
+++ branches/theora-thusnelda/lib/enc/dct_encode.c 2007-12-18 10:43:58 UTC (rev 14313)
@@ -206,22 +206,23 @@
static void tokenize_groups(CP_INSTANCE *cpi,
int *eob_run, int *eob_plane, int *eob_ypre, int *eob_uvpre){
- fragment_t *fp = cpi->coded_tail;
+ int *fip = cpi->coded_fi_list;
- while(fp){
+ while(*fip>=0){
int coeff = 0;
- int plane = (fp >= cpi->frag[1]);
- fp->nonzero = 0;
-
+ int plane = (*fip >= cpi->frag_n[0]);
+ dct_t *dct = &cpi->frag_dct[*fip];
+ cpi->frag_nonzero[*fip] = 0;
+
while(coeff < BLOCK_SIZE){
- ogg_int16_t val = (coeff ? fp->dct[coeff] : fp->pred_dc);
+ ogg_int16_t val = dct->data[coeff];
int zero_run;
int i = coeff;
- fp->nonzero = coeff;
+ cpi->frag_nonzero[*fip] = coeff;
while( !val && (++i < BLOCK_SIZE) )
- val = fp->dct[i];
+ val = dct->data[i];
if ( i == BLOCK_SIZE ){
@@ -272,7 +273,7 @@
}
}
}
- fp=fp->next;
+ fip++;
}
}
@@ -416,12 +417,11 @@
static void BlockUpdateDifference (CP_INSTANCE * cpi,
unsigned char *FiltPtr,
ogg_int16_t *DctInputPtr,
- ogg_int32_t MvDevisor,
+ ogg_int32_t MvDivisor,
int fi,
ogg_uint32_t PixelsPerLine,
int mode) {
- fragment_t *fp = &cpi->frag[0][fi];
ogg_int32_t MvShift;
ogg_int32_t MvModMask;
ogg_int32_t AbsRefOffset;
@@ -432,12 +432,12 @@
half pixel MC */
unsigned char *ReconPtr1; /* DCT reconstructed image pointers */
unsigned char *ReconPtr2; /* Pointer used in half pixel MC */
- mv_t mv;
+ mv_t mv = cpi->frag_mv[fi];
int bi = cpi->frag_buffer_index[fi];
unsigned char *thisrecon = &cpi->recon[bi];
if ( ModeUsesMC[mode] ){
- switch(MvDevisor) {
+ switch(MvDivisor) {
case 2:
MvShift = 1;
MvModMask = 1;
@@ -450,18 +450,16 @@
break;
}
- mv = fp->mv;
-
/* Set up the baseline offset for the motion vector. */
- MVOffset = ((mv.y / MvDevisor) * PixelsPerLine) + (mv.x / MvDevisor);
+ MVOffset = ((mv.y / MvDivisor) * PixelsPerLine) + (mv.x / MvDivisor);
/* Work out the offset of the second reference position for 1/2
pixel interpolation. For the U and V planes the MV specifies 1/4
pixel accuracy. This is adjusted to 1/2 pixel as follows ( 0->0,
1/4->1/2, 1/2->1/2, 3/4->1/2 ). */
ReconPtr2Offset = 0;
- AbsXOffset = mv.x % MvDevisor;
- AbsYOffset = mv.y % MvDevisor;
+ AbsXOffset = mv.x % MvDivisor;
+ AbsYOffset = mv.y % MvDivisor;
if ( AbsXOffset ) {
if ( mv.x > 0 )
@@ -520,14 +518,14 @@
void TransformQuantizeBlock (CP_INSTANCE *cpi,
int fi){
- fragment_t *fp = &cpi->frag[0][fi];
coding_mode_t mode = cpi->frag_mode[fi];
unsigned char *cp = &cpi->frag_coded[fi];
unsigned char *FiltPtr = &cpi->frame[cpi->frag_buffer_index[fi]];
int qi = cpi->BaseQ; // temporary
int inter = (mode != CODE_INTRA);
- int plane = (fp < cpi->frag[1] ? 0 : (fp < cpi->frag[2] ? 1 : 2));
+ int plane = (fi < cpi->frag_n[0] ? 0 :
+ (fi-cpi->frag_n[0] < cpi->frag_n[1] ? 1 : 2));
ogg_int32_t *q = cpi->iquant_tables[inter][plane][qi];
ogg_int16_t DCTInput[64];
ogg_int16_t DCTOutput[64];
@@ -553,10 +551,11 @@
dsp_fdct_short(cpi->dsp, DCTInput, DCTOutput);
/* Quantize that transform data. */
- quantize (cpi, q, DCTOutput, fp->dct);
+ quantize (cpi, q, DCTOutput, cpi->frag_dct[fi].data);
+ cpi->frag_dc[fi] = cpi->frag_dct[fi].data[0];
if ( (mode == CODE_INTER_NO_MV) &&
- ( AllZeroDctData(fp->dct) ) ) {
+ ( AllZeroDctData(cpi->frag_dct[fi].data) ) ) {
*cp = 0;
}
Modified: branches/theora-thusnelda/lib/enc/encode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/encode.c 2007-12-18 09:25:43 UTC (rev 14312)
+++ branches/theora-thusnelda/lib/enc/encode.c 2007-12-18 10:43:58 UTC (rev 14313)
@@ -40,51 +40,43 @@
/* last used inter predictor (Raster Order) */
ogg_int16_t Last[3]; /* last value used for given frame */
- int WhichFrame;
- int WhichCase;
coding_mode_t *mp = cpi->frag_mode;
unsigned char *cp = cpi->frag_coded;
+ dct_t *dct = cpi->frag_dct;
+ ogg_int16_t *dc = cpi->frag_dc;
int fi = 0;
/* for y,u,v */
for ( plane = 0; plane < 3 ; plane++) {
- fragment_t *fp = cpi->frag[plane];
-
- /* initialize our array of last used DC Components */
for(k=0;k<3;k++)Last[k]=0;
-
fn[0]=1;
fn[1]=cpi->frag_h[plane]+1;
fn[2]=cpi->frag_h[plane];
fn[3]=cpi->frag_h[plane]-1;
-
/* do prediction on all of Y, U or V */
for ( m = 0 ; m < cpi->frag_v[plane] ; m++) {
- for ( n = 0 ; n < cpi->frag_h[plane] ; n++, fp++, fi++) {
- fp->pred_dc = fp->dct[0];
+ for ( n = 0 ; n < cpi->frag_h[plane] ; n++, fi++) {
/* only do 2 prediction if fragment coded and on non intra or
if all fragments are intra */
if(cp[fi]) {
- /* Type of Fragment */
- WhichFrame = Mode2Frame[mp[fi]];
+ int WhichFrame = Mode2Frame[mp[fi]];
/* Check Borderline Cases */
- WhichCase = (n==0) + ((m==0) << 1) + ((n+1 == cpi->frag_h[plane]) << 2);
+ int WhichCase = (n==0) + ((m==0) << 1) + ((n+1 == cpi->frag_h[plane]) << 2);
/* fragment valid for prediction use if coded and it comes
from same frame as the one we are predicting */
for(k=pcount=wpc=0; k<4; k++) {
int pflag = 1<<k;
if((bc_mask[WhichCase]&pflag)){
- fragment_t *fnp=fp - fn[k];
int fni = fi - fn[k];
if(cp[fni] &&
(Mode2Frame[mp[fni]] == WhichFrame)){
- v[pcount]=fnp->dct[0];
+ v[pcount]=dc[fni];
wpc|=pflag;
pcount++;
}
@@ -94,7 +86,7 @@
if(wpc==0) {
/* fall back to the last coded fragment */
- fp->pred_dc -= Last[WhichFrame];
+ dct[fi].data[0] = dc[fi] - Last[WhichFrame];
} else {
@@ -124,13 +116,13 @@
}
}
- fp->pred_dc -= DC;
+ dct[fi].data[0] = dc[fi] - DC;
}
/* Save the last fragment coded for whatever frame we are
predicting from */
- Last[WhichFrame] = fp->dct[0];
+ Last[WhichFrame] = dc[fi];
}
}
@@ -164,7 +156,6 @@
for ( B=0; B<4; B++, frag++ ) {
int fi = sp->f[frag];
- fragment_t *fp = &cpi->frag[0][fi];
if ( cp[fi] ) {
@@ -175,18 +166,9 @@
generated after DCT) If not then mark it and the
assosciated MB as coded. */
if ( cp[fi] ) {
-
- if(cpi->coded_head){
- cpi->coded_head->next = fp;
- cpi->coded_head = fp;
- }else{
- cpi->coded_head = cpi->coded_tail = fp;
- }
-
- /* MB is still coded */
+ cpi->coded_fi_list[cpi->coded_fi_count++]=fi;
coded = 1;
- mode = mp[fi];
-
+ mode = mp[fi];
}
}
}
@@ -411,6 +393,7 @@
ogg_uint32_t SB, MB, B;
coding_mode_t *mp = cpi->frag_mode;
unsigned char *cp = cpi->frag_coded;
+ mv_t *mv = cpi->frag_mv;
oggpack_buffer *opb=cpi->oggbuffer;
@@ -437,19 +420,16 @@
if(B==4) continue;
if(mp[fi]==CODE_INTER_PLUS_MV || mp[fi]==CODE_GOLDEN_MV){
- fragment_t *fp = &cpi->frag[0][fi];
-
/* One MV for the macroblock */
- oggpackB_write( opb, MvPatternPtr[fp->mv.x], MvBitsPtr[fp->mv.x] );
- oggpackB_write( opb, MvPatternPtr[fp->mv.y], MvBitsPtr[fp->mv.y] );
+ oggpackB_write( opb, MvPatternPtr[mv[fi].x], MvBitsPtr[mv[fi].x] );
+ oggpackB_write( opb, MvPatternPtr[mv[fi].y], MvBitsPtr[mv[fi].y] );
}else if (mp[fi] == CODE_INTER_FOURMV){
/* MV for each codedblock */
for(B=0; B<4; B++ ){
fi = mbp->y[B];
if(cp[fi]){
- fragment_t *fp = &cpi->frag[0][fi];
- oggpackB_write( opb, MvPatternPtr[fp->mv.x], MvBitsPtr[fp->mv.x] );
- oggpackB_write( opb, MvPatternPtr[fp->mv.y], MvBitsPtr[fp->mv.y] );
+ oggpackB_write( opb, MvPatternPtr[mv[fi].x], MvBitsPtr[mv[fi].x] );
+ oggpackB_write( opb, MvPatternPtr[mv[fi].y], MvBitsPtr[mv[fi].y] );
}
}
}
@@ -461,7 +441,7 @@
/* reset all coding metadata */
memset(cpi->ModeCount, 0, MAX_MODES*sizeof(*cpi->ModeCount));
- cpi->coded_head = cpi->coded_tail = NULL;
+ cpi->coded_fi_count = 0;
dsp_save_fpu (cpi->dsp);
@@ -470,8 +450,7 @@
CodePlane(cpi, 1);
CodePlane(cpi, 2);
- if(cpi->coded_head)
- cpi->coded_head->next = NULL; /* cap off the end of the coded block list */
+ cpi->coded_fi_list[cpi->coded_fi_count]=-1;
PredictDC(cpi);
DPCMTokenize(cpi);
@@ -514,9 +493,8 @@
int fi,
mv_t *mv,
int mode){
- fragment_t *fp = &cpi->frag[0][fi];
- fp->mv = *mv;
cpi->frag_mode[fi] = mode;
+ cpi->frag_mv[fi] = *mv;
}
static void SetMBMotionVectorsAndMode(CP_INSTANCE *cpi,
@@ -822,15 +800,12 @@
FourMVect[4].y = (FourMVect[4].y - 2) / 4;
FourMVect[5].y = FourMVect[4].y;
- {
- fragment_t *f0 = cpi->frag[0];
- SetFragMotionVectorAndMode(cpi,mbp->y[0], &FourMVect[0],CODE_INTER_FOURMV);
- SetFragMotionVectorAndMode(cpi,mbp->y[1], &FourMVect[1],CODE_INTER_FOURMV);
- SetFragMotionVectorAndMode(cpi,mbp->y[2], &FourMVect[2],CODE_INTER_FOURMV);
- SetFragMotionVectorAndMode(cpi,mbp->y[3], &FourMVect[3],CODE_INTER_FOURMV);
- SetFragMotionVectorAndMode(cpi,mbp->u, &FourMVect[4],CODE_INTER_FOURMV);
- SetFragMotionVectorAndMode(cpi,mbp->v, &FourMVect[5],CODE_INTER_FOURMV);
- }
+ SetFragMotionVectorAndMode(cpi,mbp->y[0], &FourMVect[0],CODE_INTER_FOURMV);
+ SetFragMotionVectorAndMode(cpi,mbp->y[1], &FourMVect[1],CODE_INTER_FOURMV);
+ SetFragMotionVectorAndMode(cpi,mbp->y[2], &FourMVect[2],CODE_INTER_FOURMV);
+ SetFragMotionVectorAndMode(cpi,mbp->y[3], &FourMVect[3],CODE_INTER_FOURMV);
+ SetFragMotionVectorAndMode(cpi,mbp->u, &FourMVect[4],CODE_INTER_FOURMV);
+ SetFragMotionVectorAndMode(cpi,mbp->v, &FourMVect[5],CODE_INTER_FOURMV);
/* 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-18 09:25:43 UTC (rev 14312)
+++ branches/theora-thusnelda/lib/enc/encoder_toplevel.c 2007-12-18 10:43:58 UTC (rev 14313)
@@ -75,15 +75,14 @@
ogg_uint32_t IntraError;
ogg_uint32_t i;
ogg_uint32_t KFIndicator = 0;
- fragment_t *fp = cpi->frag[0];
int fi = 0;
/* Clear down the macro block level mode and MV arrays. */
- for ( i = 0; i < cpi->frag_total; i++, fp++, fi++ ) {
+ for ( i = 0; i < cpi->frag_total; i++, fi++ ) {
cpi->frag_mode[fi] = CODE_INTER_NO_MV; /* Default coding mode */
cpi->frag_coded[fi] = 1; /* TEMPORARY */
- fp->mv.x=0;
- fp->mv.y=0;
+ cpi->frag_mv[fi].x=0;
+ cpi->frag_mv[fi].y=0;
}
/* Default to delta frames. */
Modified: branches/theora-thusnelda/lib/enc/frinit.c
===================================================================
--- branches/theora-thusnelda/lib/enc/frinit.c 2007-12-18 09:25:43 UTC (rev 14312)
+++ branches/theora-thusnelda/lib/enc/frinit.c 2007-12-18 10:43:58 UTC (rev 14313)
@@ -43,11 +43,6 @@
memset(cpi->dct_token,0,sizeof(cpi->dct_token));
memset(cpi->dct_token_eb,0,sizeof(cpi->dct_token_eb));
- if(cpi->frag[0]) _ogg_free(cpi->frag[0]);
- cpi->frag[0] = 0;
- cpi->frag[1] = 0;
- cpi->frag[2] = 0;
-
if(cpi->frag_coded) _ogg_free(cpi->frag_coded);
cpi->frag_coded = 0;
@@ -57,6 +52,21 @@
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;
+
+ if(cpi->frag_dct) _ogg_free(cpi->frag_dct);
+ cpi->frag_dct = 0;
+
+ if(cpi->frag_dc) _ogg_free(cpi->frag_dc);
+ cpi->frag_dc = 0;
+
+ if(cpi->coded_fi_list) _ogg_free(cpi->coded_fi_list);
+ cpi->coded_fi_list = 0;
+
if(cpi->macro) _ogg_free(cpi->macro);
cpi->macro = 0;
@@ -130,15 +140,18 @@
cpi->super_n[2] = cpi->super_h[2] * cpi->super_v[2];
cpi->super_total = cpi->super_n[0] + cpi->super_n[1] + cpi->super_n[2];
- cpi->frag[0] = calloc(cpi->frag_total+1, sizeof(**cpi->frag));
- cpi->frag[1] = cpi->frag[0] + cpi->frag_n[0];
- cpi->frag[2] = cpi->frag[1] + cpi->frag_n[1];
-
/* +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_mode = calloc(cpi->frag_total+1, sizeof(*cpi->frag_mode));
- cpi->frag_buffer_index = calloc(cpi->frag_total+1, sizeof(*cpi->frag_buffer_index));
+ cpi->frag_mode = calloc(cpi->frag_total, sizeof(*cpi->frag_mode));
+ 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));
+ /* possibly to be eliminated eventually when tokenize is rolled into transform */
+ cpi->coded_fi_list = calloc(cpi->frag_total, sizeof(*cpi->coded_fi_list));
+
/* +1; the last entry is the 'invalid' mb, which contains only 'invalid' frags */
cpi->macro = calloc(cpi->macro_total+1, sizeof(*cpi->macro));
More information about the commits
mailing list