[xiph-commits] r14233 - in branches/theora-thusnelda/lib: dec/x86
enc
xiphmont at svn.xiph.org
xiphmont at svn.xiph.org
Mon Nov 26 09:06:57 PST 2007
Author: xiphmont
Date: 2007-11-26 09:06:55 -0800 (Mon, 26 Nov 2007)
New Revision: 14233
Modified:
branches/theora-thusnelda/lib/dec/x86/mmxstate.c
branches/theora-thusnelda/lib/dec/x86/x86int.h
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_quant.c
branches/theora-thusnelda/lib/enc/encoder_toplevel.c
branches/theora-thusnelda/lib/enc/frinit.c
branches/theora-thusnelda/lib/enc/quant_lookup.h
Log:
Kill off more of the absurd overenginnering in the quantization code.
Modified: branches/theora-thusnelda/lib/dec/x86/mmxstate.c
===================================================================
--- branches/theora-thusnelda/lib/dec/x86/mmxstate.c 2007-11-26 00:13:48 UTC (rev 14232)
+++ branches/theora-thusnelda/lib/dec/x86/mmxstate.c 2007-11-26 17:06:55 UTC (rev 14233)
@@ -40,9 +40,9 @@
-void oc_state_frag_recon_mmx(oc_theora_state *_state,const oc_fragment *_frag,
- int _pli,ogg_int16_t _dct_coeffs[128],int _last_zzi,int _ncoefs,
- ogg_uint16_t _dc_iquant,const ogg_uint16_t _ac_iquant[64]){
+void oc_state_frag_recon_mmx(oc_theora_state *_state, oc_fragment *_frag,
+ int _pli,ogg_int16_t _dct_coeffs[128],int _last_zzi,int _ncoefs,
+ ogg_uint16_t _dc_iquant,const ogg_uint16_t _ac_iquant[64]){
ogg_int16_t __attribute__((aligned(8))) res_buf[64];
int dst_framei;
int dst_ystride;
Modified: branches/theora-thusnelda/lib/dec/x86/x86int.h
===================================================================
--- branches/theora-thusnelda/lib/dec/x86/x86int.h 2007-11-26 00:13:48 UTC (rev 14232)
+++ branches/theora-thusnelda/lib/dec/x86/x86int.h 2007-11-26 17:06:55 UTC (rev 14233)
@@ -30,7 +30,7 @@
int _src2_ystride,const ogg_int16_t *_residue);
void oc_state_frag_copy_mmx(const oc_theora_state *_state,const int *_fragis,
int _nfragis,int _dst_frame,int _src_frame,int _pli);
-void oc_state_frag_recon_mmx(oc_theora_state *_state,const oc_fragment *_frag,
+void oc_state_frag_recon_mmx(oc_theora_state *_state,oc_fragment *_frag,
int _pli,ogg_int16_t _dct_coeffs[128],int _last_zzi,int _ncoefs,
ogg_uint16_t _dc_iquant,const ogg_uint16_t _ac_iquant[64]);
void oc_restore_fpu_mmx(void);
Modified: branches/theora-thusnelda/lib/enc/codec_internal.h
===================================================================
--- branches/theora-thusnelda/lib/enc/codec_internal.h 2007-11-26 00:13:48 UTC (rev 14232)
+++ branches/theora-thusnelda/lib/enc/codec_internal.h 2007-11-26 17:06:55 UTC (rev 14233)
@@ -77,18 +77,11 @@
#define MAX_MV_EXTENT 31 /* Max search distance in half pixel increments */
-typedef struct coeffNode{
- int i;
- struct coeffNode *next;
-} COEFFNODE;
-
typedef struct{
ogg_int32_t x;
ogg_int32_t y;
} MOTION_VECTOR;
-typedef MOTION_VECTOR COORDINATE;
-
/** block coding modes */
typedef enum{
CODE_INTER_NO_MV = 0x0, /* INTER prediction, (0,0) motion
@@ -111,31 +104,46 @@
struct HUFF_ENTRY *Next;
ogg_int32_t Value;
ogg_uint32_t Frequency;
-
} HUFF_ENTRY;
+typedef struct{
+ ogg_int32_t x;
+ ogg_int32_t y;
+} mv_t;
+
+typedef struct fragment {
+ int coded;
+ mv_t mv;
+ ogg_int16_t dc;
+ ogg_int16_t dct[64];
+
+ ogg_uint32_t raw_index;
+ ogg_uint32_t recon_index;
+} fragment_t;
+
+typedef struct macroblock {
+ int mode;
+ fragment_t *f[4]; // hilbert order
+} macroblock_t;
+
+#define SB_MB_ULFRAG(sb,mbnum) (sb->f[ ((mbnum)<2? ((mbnum)==0?3:5) : ((mbnum)==2?9:13)) ])
+typedef struct superblock {
+ fragment_t *f[16]; // hilbert order
+} superblock_t;
+
+typedef ogg_int16_t quant_table[64];
+typedef quant_table quant_tables[64];
+
+typedef ogg_int32_t iquant_table[64];
+typedef iquant_table iquant_tables[64];
+
/** Decoder (Playback) instance -- installed in a theora_state */
typedef struct PB_INSTANCE {
- theora_info info;
-
- /* flag to indicate if the headers already have been written */
- int HeadersWritten;
-
- /* how far do we shift the granulepos to seperate out P frame counts? */
- int keyframe_granule_shift;
/***********************************************************************/
/* Frame Info */
- CODING_MODE CodingMode;
unsigned char FrameType;
- ogg_uint32_t QualitySetting;
- ogg_uint32_t FrameQIndex; /* Quality specified as a
- table index */
- ogg_uint32_t ThisFrameQualityValue; /* Quality value for this frame */
- ogg_int32_t CodedBlockIndex; /* Number of Coded Blocks */
- ogg_uint32_t CodedBlocksThisFrame; /* Index into coded blocks */
- ogg_uint32_t FrameSize; /* The number of bytes in the frame. */
/**********************************************************************/
/* Frame Size & Index Information */
@@ -190,6 +198,7 @@
pixel in recon buffer */
unsigned char *display_fragments; /* Fragment update map */
+ int CodedBlockIndex;
ogg_int32_t *CodedBlockList; /* A list of fragment indices for
coded blocks. */
MOTION_VECTOR *FragMVect; /* Frag motion vectors */
@@ -230,57 +239,15 @@
/* Loop filter bounding values */
ogg_int16_t FiltBoundingValue[256];
- /* Naming convention for all quant matrices and related data structures:
- * Fields containing "Inter" in their name are for Inter frames, the
- * rest is Intra. */
-
- /* Dequantiser and rounding tables */
- ogg_uint16_t *QThreshTable;
- ogg_int16_t dequant_Y_coeffs[64];
- ogg_int16_t dequant_U_coeffs[64];
- ogg_int16_t dequant_V_coeffs[64];
- ogg_int16_t dequant_InterY_coeffs[64];
- ogg_int16_t dequant_InterU_coeffs[64];
- ogg_int16_t dequant_InterV_coeffs[64];
-
- unsigned int zigzag_index[64];
-
HUFF_ENTRY *HuffRoot_VP3x[NUM_HUFF_TABLES];
ogg_uint32_t *HuffCodeArray_VP3x[NUM_HUFF_TABLES];
unsigned char *HuffCodeLengthArray_VP3x[NUM_HUFF_TABLES];
const unsigned char *ExtraBitLengths_VP3x;
- th_quant_info quant_info;
- oc_quant_tables quant_tables[2][3];
+ th_quant_info quant_info;
+ quant_tables quant_tables[2][3];
+ iquant_tables iquant_tables[2][3];
- /* Quantiser and rounding tables */
- /* this is scheduled to be replaced a new mechanism
- that will simply reuse the dequantizer information. */
- ogg_int32_t fp_quant_Y_coeffs[64]; /* used in reiniting quantizers */
- ogg_int32_t fp_quant_U_coeffs[64];
- ogg_int32_t fp_quant_V_coeffs[64];
- ogg_int32_t fp_quant_Inter_Y_coeffs[64];
- ogg_int32_t fp_quant_Inter_U_coeffs[64];
- ogg_int32_t fp_quant_Inter_V_coeffs[64];
-
- ogg_int32_t fp_quant_Y_round[64];
- ogg_int32_t fp_quant_U_round[64];
- ogg_int32_t fp_quant_V_round[64];
- ogg_int32_t fp_quant_Inter_Y_round[64];
- ogg_int32_t fp_quant_Inter_U_round[64];
- ogg_int32_t fp_quant_Inter_V_round[64];
-
- ogg_int32_t fp_ZeroBinSize_Y[64];
- ogg_int32_t fp_ZeroBinSize_U[64];
- ogg_int32_t fp_ZeroBinSize_V[64];
- ogg_int32_t fp_ZeroBinSize_Inter_Y[64];
- ogg_int32_t fp_ZeroBinSize_Inter_U[64];
- ogg_int32_t fp_ZeroBinSize_Inter_V[64];
-
- ogg_int32_t *fquant_coeffs;
- ogg_int32_t *fquant_round;
- ogg_int32_t *fquant_ZbSize;
-
/* Predictor used in choosing entropy table for decoding block patterns. */
unsigned char BlockPatternPredictor;
@@ -304,8 +271,16 @@
is the only assumption that library makes about our internal format.*/
oc_state_dispatch_vtbl dispatch_vtbl;
+ theora_info info;
unsigned char *yuvptr;
+
+ /* flag to indicate if the headers already have been written */
+ int HeadersWritten;
+ /* how far do we shift the granulepos to seperate out P frame counts? */
+ int keyframe_granule_shift;
+
+
/* Compressor Configuration */
int BaseQ;
int GoldenFrameEnabled;
@@ -436,26 +411,21 @@
ogg_int16_t * ChangePtr,
ogg_uint32_t LineStep ) ;
-extern void SetupLoopFilter(PB_INSTANCE *pbi);
-extern void LoopFilter(PB_INSTANCE *pbi);
-extern void ReconRefFrames (PB_INSTANCE *pbi);
+extern void ReconRefFrames (CP_INSTANCE *cpi);
extern void ExpandToken( ogg_int16_t * ExpandedBlock,
unsigned char * CoeffIndex, ogg_uint32_t Token,
ogg_int32_t ExtraBits );
-extern void select_quantiser (PB_INSTANCE *pbi, int type);
-
extern void quantize( PB_INSTANCE *pbi,
+ ogg_int32_t *iquant_table,
ogg_int16_t * DCT_block,
ogg_int16_t * quantized_list);
-extern void UpdateQ( PB_INSTANCE *pbi, int NewQIndex );
-extern void UpdateQC( CP_INSTANCE *cpi, ogg_uint32_t NewQ );
extern void fdct_short ( ogg_int16_t * InputData, ogg_int16_t * OutputData );
extern ogg_uint32_t DPCMTokenizeBlock (CP_INSTANCE *cpi,
ogg_int32_t FragIndex);
extern void TransformQuantizeBlock (CP_INSTANCE *cpi, ogg_int32_t FragIndex,
ogg_uint32_t PixelsPerLine ) ;
-extern void InitFrameDetails(PB_INSTANCE *pbi);
+extern void InitFrameDetails(CP_INSTANCE *cpi);
extern void WriteQTables(PB_INSTANCE *pbi,oggpack_buffer *opb);
extern void InitQTables( PB_INSTANCE *pbi );
extern void InitHuffmanSet( PB_INSTANCE *pbi );
@@ -507,7 +477,4 @@
ogg_uint32_t UVSuperBlocks,
ogg_uint32_t HFrags, ogg_uint32_t VFrags );
-extern void UpdateUMVBorder( PB_INSTANCE *pbi,
- unsigned char * DestReconPtr );
-
#endif /* ENCODER_INTERNAL_H */
Modified: branches/theora-thusnelda/lib/enc/dct_decode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/dct_decode.c 2007-11-26 00:13:48 UTC (rev 14232)
+++ branches/theora-thusnelda/lib/enc/dct_decode.c 2007-11-26 17:06:55 UTC (rev 14233)
@@ -36,43 +36,38 @@
}
}
-void SetupLoopFilter(PB_INSTANCE *pbi){
- ogg_int32_t FLimit;
-
- FLimit = pbi->quant_info.loop_filter_limits[pbi->FrameQIndex];
- SetupBoundingValueArray_Generic(pbi, FLimit);
-}
-
-static void ExpandBlock ( PB_INSTANCE *pbi, ogg_int32_t FragmentNumber){
+static void ExpandBlock ( CP_INSTANCE *cpi, ogg_int32_t FragmentNumber){
+ PB_INSTANCE *pbi = &cpi->pb;
ogg_uint32_t ReconPixelsPerLine; /* Pixels per line */
ogg_int32_t ReconPixelIndex; /* Offset for block into a
reconstruction buffer */
ogg_int16_t reconstruct[64];
- ogg_int16_t *quantizers;
- ogg_int16_t *data = &pbi->QFragData[FragmentNumber][0];
+ ogg_int16_t *quantizers;
+ ogg_int16_t *data = &pbi->QFragData[FragmentNumber][0];
int mode = pbi->FragCodingMethod[FragmentNumber];
+ int qi = cpi->BaseQ; // temporary
/* Select the appropriate inverse Q matrix and line stride */
if ( FragmentNumber<pbi->YPlaneFragments ) {
ReconPixelsPerLine = pbi->YStride;
if ( mode == CODE_INTRA )
- quantizers = pbi->dequant_Y_coeffs;
+ quantizers = pbi->quant_tables[0][0][qi];
else
- quantizers = pbi->dequant_InterY_coeffs;
+ quantizers = pbi->quant_tables[1][0][qi];
}else{
ReconPixelsPerLine = pbi->UVStride;
if ( mode == CODE_INTRA )
if ( FragmentNumber < pbi->YPlaneFragments + pbi->UVPlaneFragments )
- quantizers = pbi->dequant_U_coeffs;
+ quantizers = pbi->quant_tables[0][1][qi];
else
- quantizers = pbi->dequant_V_coeffs;
+ quantizers = pbi->quant_tables[0][2][qi];
else
if ( FragmentNumber < pbi->YPlaneFragments + pbi->UVPlaneFragments )
- quantizers = pbi->dequant_InterU_coeffs;
+ quantizers = pbi->quant_tables[1][1][qi];
else
- quantizers = pbi->dequant_InterV_coeffs;
+ quantizers = pbi->quant_tables[1][2][qi];
}
#ifdef _TH_DEBUG_
@@ -172,15 +167,16 @@
}
}
-static void UpdateUMV_VBorders( PB_INSTANCE *pbi,
+static void UpdateUMV_VBorders( CP_INSTANCE *cpi,
unsigned char * DestReconPtr,
ogg_uint32_t PlaneFragOffset ){
- ogg_uint32_t i;
- ogg_uint32_t PixelIndex;
+ PB_INSTANCE *pbi = &cpi->pb;
+ ogg_uint32_t i;
+ ogg_uint32_t PixelIndex;
- ogg_uint32_t PlaneStride;
- ogg_uint32_t LineFragments;
- ogg_uint32_t PlaneBorderWidth;
+ ogg_uint32_t PlaneStride;
+ ogg_uint32_t LineFragments;
+ ogg_uint32_t PlaneBorderWidth;
ogg_uint32_t PlaneHeight;
unsigned char *SrcPtr1;
@@ -194,13 +190,13 @@
PlaneStride = pbi->YStride;
PlaneBorderWidth = UMV_BORDER;
LineFragments = pbi->HFragments;
- PlaneHeight = pbi->info.height;
+ PlaneHeight = cpi->info.height;
}else{
/* U or V plane. */
PlaneStride = pbi->UVStride;
PlaneBorderWidth = UMV_BORDER / 2;
LineFragments = pbi->HFragments / 2;
- PlaneHeight = pbi->info.height / 2;
+ PlaneHeight = cpi->info.height / 2;
}
/* Setup the source data values and destination pointers for the
@@ -227,22 +223,23 @@
}
}
-void UpdateUMVBorder( PB_INSTANCE *pbi,
+void UpdateUMVBorder( CP_INSTANCE *cpi,
unsigned char * DestReconPtr ) {
ogg_uint32_t PlaneFragOffset;
+ PB_INSTANCE *pbi = &cpi->pb;
/* Y plane */
PlaneFragOffset = 0;
- UpdateUMV_VBorders( pbi, DestReconPtr, PlaneFragOffset );
+ UpdateUMV_VBorders( cpi, DestReconPtr, PlaneFragOffset );
UpdateUMV_HBorders( pbi, DestReconPtr, PlaneFragOffset );
/* Then the U and V Planes */
PlaneFragOffset = pbi->YPlaneFragments;
- UpdateUMV_VBorders( pbi, DestReconPtr, PlaneFragOffset );
+ UpdateUMV_VBorders( cpi, DestReconPtr, PlaneFragOffset );
UpdateUMV_HBorders( pbi, DestReconPtr, PlaneFragOffset );
PlaneFragOffset = pbi->YPlaneFragments + pbi->UVPlaneFragments;
- UpdateUMV_VBorders( pbi, DestReconPtr, PlaneFragOffset );
+ UpdateUMV_VBorders( cpi, DestReconPtr, PlaneFragOffset );
UpdateUMV_HBorders( pbi, DestReconPtr, PlaneFragOffset );
}
@@ -367,7 +364,8 @@
}
}
-void LoopFilter(PB_INSTANCE *pbi){
+static void LoopFilter(CP_INSTANCE *cpi){
+ PB_INSTANCE *pbi = &cpi->pb;
ogg_int32_t i;
ogg_int16_t * BoundingValuePtr=pbi->FiltBoundingValue+127;
@@ -377,20 +375,9 @@
ogg_int32_t LineFragments;
ogg_int32_t LineLength;
ogg_int32_t FLimit;
- int QIndex;
int j,m,n;
- /* Set the limit value for the loop filter based upon the current
- quantizer. */
- QIndex = Q_TABLE_SIZE - 1;
- while ( QIndex >= 0 ) {
- if ( (QIndex == 0) ||
- ( pbi->quant_info.ac_scale[QIndex] >= pbi->ThisFrameQualityValue) )
- break;
- QIndex --;
- }
-
- FLimit = pbi->quant_info.loop_filter_limits[QIndex];
+ FLimit = cpi->pb.quant_info.loop_filter_limits[cpi->BaseQ]; // temp
if ( FLimit == 0 ) return;
SetupBoundingValueArray_Generic(pbi, FLimit);
@@ -645,15 +632,14 @@
}
}
-void ReconRefFrames (PB_INSTANCE *pbi){
+void ReconRefFrames (CP_INSTANCE *cpi){
+ PB_INSTANCE *pbi = &cpi->pb;
ogg_int32_t i;
unsigned char *SwapReconBuffersTemp;
- SetupLoopFilter(pbi);
-
/* Inverse DCT and reconstitute buffer in thisframe */
for(i=0;i<pbi->UnitFragments;i++)
- ExpandBlock( pbi, i );
+ ExpandBlock( cpi, i );
/* Copy the current reconstruction back to the last frame recon buffer. */
if(pbi->CodedBlockIndex > (ogg_int32_t) (pbi->UnitFragments >> 1)){
@@ -666,105 +652,105 @@
}
/* Apply a loop filter to edge pixels of updated blocks */
- LoopFilter(pbi);
+ LoopFilter(cpi);
#ifdef _TH_DEBUG_
- {
- int x,y,i,j,k,xn,yn,stride;
- int plane;
- int buf;
-
- /* dump fragment DCT components */
- for(plane=0;plane<3;plane++){
- char *plstr;
- int offset;
- switch(plane){
- case 0:
- plstr="Y";
- xn = pbi->HFragments;
- yn = pbi->VFragments;
- offset = 0;
- stride = pbi->YStride;
- break;
- case 1:
- plstr="U";
- xn = pbi->HFragments>>1;
- yn = pbi->VFragments>>1;
- offset = pbi->VFragments * pbi->HFragments;
- stride = pbi->UVStride;
- break;
- case 2:
- plstr="V";
- xn = pbi->HFragments>>1;
- yn = pbi->VFragments>>1;
- offset = pbi->VFragments * pbi->HFragments +
- ((pbi->VFragments * pbi->HFragments) >> 2);
- stride = pbi->UVStride;
- break;
- }
- for(y=0;y<yn;y++){
- for(x=0;x<xn;x++,i++){
+ {
+ int x,y,i,j,k,xn,yn,stride;
+ int plane;
+ int buf;
+
+ /* dump fragment DCT components */
+ for(plane=0;plane<3;plane++){
+ char *plstr;
+ int offset;
+ switch(plane){
+ case 0:
+ plstr="Y";
+ xn = pbi->HFragments;
+ yn = pbi->VFragments;
+ offset = 0;
+ stride = pbi->YStride;
+ break;
+ case 1:
+ plstr="U";
+ xn = pbi->HFragments>>1;
+ yn = pbi->VFragments>>1;
+ offset = pbi->VFragments * pbi->HFragments;
+ stride = pbi->UVStride;
+ break;
+ case 2:
+ plstr="V";
+ xn = pbi->HFragments>>1;
+ yn = pbi->VFragments>>1;
+ offset = pbi->VFragments * pbi->HFragments +
+ ((pbi->VFragments * pbi->HFragments) >> 2);
+ stride = pbi->UVStride;
+ break;
+ }
+ for(y=0;y<yn;y++){
+ for(x=0;x<xn;x++,i++){
+
+ for(buf=0;buf<3;buf++){
+ Q_LIST_ENTRY (*ptr)[64];
+ char *bufn;
- for(buf=0;buf<3;buf++){
- Q_LIST_ENTRY (*ptr)[64];
- char *bufn;
-
- switch(buf){
- case 0:
- bufn = "coded";
- ptr = pbi->QFragQUAN;
- break;
- case 1:
- bufn = "coeff";
- ptr = pbi->QFragFREQ;
- break;
- case 2:
- bufn = "idct";
- ptr = pbi->QFragTIME;
- break;
- }
-
- i = offset + y*xn + x;
-
- TH_DEBUG("%s %s [%d][%d] = {",bufn,plstr,x,y);
- if ( !pbi->display_fragments[i] )
- TH_DEBUG(" not coded }\n");
- else{
- int l=0;
- for(j=0;j<8;j++){
- TH_DEBUG("\n ");
- for(k=0;k<8;k++,l++){
- TH_DEBUG("%d ",ptr[i][l]);
- }
+ switch(buf){
+ case 0:
+ bufn = "coded";
+ ptr = pbi->QFragQUAN;
+ break;
+ case 1:
+ bufn = "coeff";
+ ptr = pbi->QFragFREQ;
+ break;
+ case 2:
+ bufn = "idct";
+ ptr = pbi->QFragTIME;
+ break;
+ }
+
+ i = offset + y*xn + x;
+
+ TH_DEBUG("%s %s [%d][%d] = {",bufn,plstr,x,y);
+ if ( !pbi->display_fragments[i] )
+ TH_DEBUG(" not coded }\n");
+ else{
+ int l=0;
+ for(j=0;j<8;j++){
+ TH_DEBUG("\n ");
+ for(k=0;k<8;k++,l++){
+ TH_DEBUG("%d ",ptr[i][l]);
}
- TH_DEBUG(" }\n");
}
+ TH_DEBUG(" }\n");
}
-
- /* and the loop filter output, which is a flat struct */
- TH_DEBUG("recon %s [%d][%d] = {",plstr,x,y);
- for(j=0;j<8;j++){
- int l = pbi->recon_pixel_index_table[i] + j*stride;
- TH_DEBUG("\n ");
- for(k=0;k<8;k++,l++)
- TH_DEBUG("%d ", pbi->LastFrameRecon[l]);
- }
- TH_DEBUG(" }\n\n");
}
+
+ /* and the loop filter output, which is a flat struct */
+ TH_DEBUG("recon %s [%d][%d] = {",plstr,x,y);
+ for(j=0;j<8;j++){
+ int l = pbi->recon_pixel_index_table[i] + j*stride;
+ TH_DEBUG("\n ");
+ for(k=0;k<8;k++,l++)
+ TH_DEBUG("%d ", pbi->LastFrameRecon[l]);
+ }
+ TH_DEBUG(" }\n\n");
}
}
}
+ }
#endif
-
+
/* We may need to update the UMV border */
- UpdateUMVBorder(pbi, pbi->LastFrameRecon);
-
+ UpdateUMVBorder(cpi, pbi->LastFrameRecon);
+
/* Reconstruct the golden frame if necessary.
For VFW codec only on key frames */
if ( pbi->FrameType == KEY_FRAME ){
CopyRecon( pbi, pbi->GoldenFrame, pbi->LastFrameRecon );
/* We may need to update the UMV border */
- UpdateUMVBorder(pbi, pbi->GoldenFrame);
+ UpdateUMVBorder(cpi, pbi->GoldenFrame);
}
}
Modified: branches/theora-thusnelda/lib/enc/dct_encode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/dct_encode.c 2007-11-26 00:13:48 UTC (rev 14232)
+++ branches/theora-thusnelda/lib/enc/dct_encode.c 2007-11-26 17:06:55 UTC (rev 14233)
@@ -228,16 +228,8 @@
ogg_uint32_t DPCMTokenizeBlock (CP_INSTANCE *cpi,
ogg_int32_t FragIndex){
- ogg_uint32_t token_count;
+ int token_count;
- if ( cpi->pb.FrameType == KEY_FRAME ){
- /* Key frame so code block in INTRA mode. */
- cpi->pb.CodingMode = CODE_INTRA;
- }else{
- /* Get Motion vector and mode for this block. */
- cpi->pb.CodingMode = cpi->pb.FragCodingMethod[FragIndex];
- }
-
/* Tokenise the dct data. */
token_count = TokenizeDctBlock( cpi->PredictedDC[FragIndex],
cpi->pb.QFragData[FragIndex],
@@ -267,7 +259,8 @@
ogg_int32_t MvDevisor,
ogg_uint32_t FragIndex,
ogg_uint32_t PixelsPerLine,
- ogg_uint32_t ReconPixelsPerLine) {
+ ogg_uint32_t ReconPixelsPerLine,
+ int mode) {
ogg_int32_t MvShift;
ogg_int32_t MvModMask;
@@ -280,7 +273,7 @@
unsigned char *ReconPtr1; /* DCT reconstructed image pointers */
unsigned char *ReconPtr2; /* Pointer used in half pixel MC */
- if ( ModeUsesMC[cpi->pb.CodingMode] ){
+ if ( ModeUsesMC[mode] ){
switch(MvDevisor) {
case 2:
MvShift = 1;
@@ -323,7 +316,7 @@
ReconPtr2Offset -= ReconPixelsPerLine;
}
- if ( cpi->pb.CodingMode==CODE_GOLDEN_MV ) {
+ if ( mode==CODE_GOLDEN_MV ) {
ReconPtr1 = &cpi->
pb.GoldenFrame[cpi->pb.recon_pixel_index_table[FragIndex]];
} else {
@@ -350,9 +343,9 @@
}
} else {
- if ( (cpi->pb.CodingMode==CODE_INTER_NO_MV ) ||
- ( cpi->pb.CodingMode==CODE_USING_GOLDEN ) ) {
- if ( cpi->pb.CodingMode==CODE_INTER_NO_MV ) {
+ if ( ( mode==CODE_INTER_NO_MV ) ||
+ ( mode==CODE_USING_GOLDEN ) ) {
+ if ( mode==CODE_INTER_NO_MV ) {
ReconPtr1 = &cpi->
pb.LastFrameRecon[cpi->pb.recon_pixel_index_table[FragIndex]];
} else {
@@ -363,14 +356,15 @@
dsp_sub8x8(cpi->dsp, FiltPtr, ReconPtr1, DctInputPtr,
PixelsPerLine, ReconPixelsPerLine);
dsp_copy8x8 (cpi->dsp, ReconPtr1, thisrecon, ReconPixelsPerLine);
- } else if ( cpi->pb.CodingMode==CODE_INTRA ) {
+ } else if ( mode==CODE_INTRA ) {
dsp_sub8x8_128(cpi->dsp, FiltPtr, DctInputPtr, PixelsPerLine);
dsp_set8x8(cpi->dsp, 128, thisrecon, ReconPixelsPerLine);
}
}
}
-void TransformQuantizeBlock (CP_INSTANCE *cpi, ogg_int32_t FragIndex,
+void TransformQuantizeBlock (CP_INSTANCE *cpi,
+ ogg_int32_t FragIndex,
ogg_uint32_t PixelsPerLine) {
unsigned char *FiltPtr; /* Pointers to srf filtered pixels */
ogg_int16_t *DctInputPtr; /* Pointer into buffer containing input to DCT */
@@ -380,6 +374,9 @@
unsigned char *ReconPtr1; /* DCT reconstructed image pointers */
ogg_int32_t MvDivisor; /* Defines MV resolution (2 = 1/2
pixel for Y or 4 = 1/4 for UV) */
+ int qi = cpi->BaseQ;
+ ogg_int32_t *q;
+ int mode;
DctInputPtr = cpi->DCTDataBuffer;
@@ -399,10 +396,10 @@
if ( cpi->pb.FrameType == KEY_FRAME ) {
/* Key frame so code block in INTRA mode. */
- cpi->pb.CodingMode = CODE_INTRA;
+ mode = CODE_INTRA;
}else{
/* Get Motion vector and mode for this block. */
- cpi->pb.CodingMode = cpi->pb.FragCodingMethod[FragIndex];
+ mode = cpi->pb.FragCodingMethod[FragIndex];
}
/* Selection of Quantiser matrix and set other plane related values. */
@@ -410,25 +407,25 @@
LeftEdge = !(FragIndex%cpi->pb.HFragments);
/* Select the appropriate Y quantiser matrix */
- if ( cpi->pb.CodingMode == CODE_INTRA )
- select_quantiser(&cpi->pb, BLOCK_Y);
+ if ( mode == CODE_INTRA )
+ q=cpi->pb.iquant_tables[0][0][qi];
else
- select_quantiser(&cpi->pb, BLOCK_INTER_Y);
+ q=cpi->pb.iquant_tables[1][0][qi];
} else {
LeftEdge = !((FragIndex-cpi->pb.YPlaneFragments)%(cpi->pb.HFragments>>1));
if(FragIndex < (ogg_int32_t)cpi->pb.YPlaneFragments + (ogg_int32_t)cpi->pb.UVPlaneFragments) {
/* U plane */
- if ( cpi->pb.CodingMode == CODE_INTRA )
- select_quantiser(&cpi->pb, BLOCK_U);
+ if ( mode == CODE_INTRA )
+ q=cpi->pb.iquant_tables[0][1][qi];
else
- select_quantiser(&cpi->pb, BLOCK_INTER_U);
+ q=cpi->pb.iquant_tables[1][1][qi];
} else {
/* V plane */
- if ( cpi->pb.CodingMode == CODE_INTRA )
- select_quantiser(&cpi->pb, BLOCK_V);
+ if ( mode == CODE_INTRA )
+ q=cpi->pb.iquant_tables[0][2][qi];
else
- select_quantiser(&cpi->pb, BLOCK_INTER_V);
+ q=cpi->pb.iquant_tables[1][2][qi];
}
}
@@ -437,7 +434,7 @@
forward DCT */
BlockUpdateDifference(cpi, FiltPtr, DctInputPtr, ReconPtr1,
MvDivisor, FragIndex, PixelsPerLine,
- ReconPixelsPerLine);
+ ReconPixelsPerLine, mode);
/* Proceed to encode the data into the encode buffer if the encoder
is enabled. */
@@ -445,9 +442,9 @@
dsp_fdct_short(cpi->dsp, cpi->DCTDataBuffer, cpi->DCT_codes );
/* Quantize that transform data. */
- quantize ( &cpi->pb, cpi->DCT_codes, cpi->pb.QFragData[FragIndex] );
+ quantize ( &cpi->pb, q, cpi->DCT_codes, cpi->pb.QFragData[FragIndex] );
- if ( (cpi->pb.CodingMode == CODE_INTER_NO_MV) &&
+ if ( (mode == CODE_INTER_NO_MV) &&
( AllZeroDctData(cpi->pb.QFragData[FragIndex]) ) ) {
cpi->pb.display_fragments[FragIndex] = 0;
}
Modified: branches/theora-thusnelda/lib/enc/encode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/encode.c 2007-11-26 00:13:48 UTC (rev 14232)
+++ branches/theora-thusnelda/lib/enc/encode.c 2007-11-26 17:06:55 UTC (rev 14233)
@@ -836,15 +836,15 @@
/* Encode and tokenise the Y, U and V components */
coded_pixels = QuadCodeComponent(cpi, 0, cpi->pb.YSBRows, cpi->pb.YSBCols,
- cpi->pb.info.width );
+ cpi->info.width );
coded_pixels += QuadCodeComponent(cpi, cpi->pb.YSuperBlocks,
cpi->pb.UVSBRows,
cpi->pb.UVSBCols,
- cpi->pb.info.width>>1 );
+ cpi->info.width>>1 );
coded_pixels += QuadCodeComponent(cpi,
cpi->pb.YSuperBlocks+cpi->pb.UVSuperBlocks,
cpi->pb.UVSBRows, cpi->pb.UVSBCols,
- cpi->pb.info.width>>1 );
+ cpi->info.width>>1 );
PredictDC(cpi, cpi->PredictedDC);
@@ -867,7 +867,7 @@
PackCodedVideo(cpi);
/* Reconstruct the reference frames */
- ReconRefFrames(&cpi->pb);
+ ReconRefFrames(cpi);
dsp_restore_fpu (cpi->dsp);
@@ -1008,7 +1008,7 @@
ogg_uint32_t UVFragOffset;
int MBCodedFlag;
- unsigned char QIndex;
+ unsigned char QIndex = cpi->BaseQ; // temporary
/* initialize error scores */
*InterError = 0;
@@ -1042,16 +1042,13 @@
ZeroVect.x = 0;
ZeroVect.y = 0;
- QIndex = (unsigned char)cpi->pb.FrameQIndex;
-
-
/* change the quatization matrix to the one at best Q to compute the
new error score */
cpi->MinImprovementForNewMV = (MvThreshTable[QIndex] << 12);
cpi->InterTripOutThresh = (5000<<12);
cpi->MVChangeFactor = MVChangeFactorTable[QIndex]; /* 0.9 */
- if ( cpi->pb.info.quick_p ) {
+ if ( cpi->info.quick_p ) {
cpi->ExhaustiveSearchThresh = (1000<<12);
cpi->FourMVThreshold = (2500<<12);
} else {
@@ -1159,7 +1156,7 @@
if ( BestError > cpi->MinImprovementForNewMV && cpi->MotionCompensation) {
/* Use a mix of heirachical and exhaustive searches for
quick mode. */
- if ( cpi->pb.info.quick_p ) {
+ if ( cpi->info.quick_p ) {
MBInterMVError = GetMBMVInterError( cpi, cpi->pb.LastFrameRecon,
YFragIndex, PixelsPerLine,
cpi->MVPixelOffsetY,
@@ -1389,7 +1386,6 @@
}
void WriteFrameHeader( CP_INSTANCE *cpi) {
- ogg_uint32_t i;
oggpack_buffer *opb=cpi->oggbuffer;
TH_DEBUG("\n>>>> beginning frame %ld\n\n",dframe);
@@ -1399,20 +1395,8 @@
TH_DEBUG("frame type = video, %s\n",cpi->pb.FrameType?"predicted":"key");
/* Write out details of the current value of Q... variable resolution. */
- for ( i = 0; i < Q_TABLE_SIZE; i++ ) {
- if ( cpi->pb.ThisFrameQualityValue == cpi->pb.QThreshTable[i] ) {
- TH_DEBUG("frame quality = { %d }\n",i);
- oggpackB_write( opb, i, 6 );
- break;
- }
- }
+ oggpackB_write( opb, cpi->BaseQ, 6 ); // temporary
- if ( i == Q_TABLE_SIZE ) {
- /* An invalid DCT value was specified. */
- /*IssueWarning( "Invalid Q Multiplier" );*/
- oggpackB_write( opb, 31, 6 );
- }
-
/* we only support one Q index per frame */
oggpackB_write( opb, 0, 1 );
Modified: branches/theora-thusnelda/lib/enc/encoder_quant.c
===================================================================
--- branches/theora-thusnelda/lib/enc/encoder_quant.c 2007-11-26 00:13:48 UTC (rev 14232)
+++ branches/theora-thusnelda/lib/enc/encoder_quant.c 2007-11-26 17:06:55 UTC (rev 14233)
@@ -142,8 +142,6 @@
int pli; /* Y U V */
th_quant_info *qinfo = &pbi->quant_info;
- pbi->QThreshTable = pbi->quant_info.ac_scale;
-
for(qti=0;qti<2;qti++){
for(pli=0;pli<3;pli++){
int qi; /* quality index */
@@ -172,12 +170,14 @@
q=((ogg_uint32_t)qinfo->dc_scale[qi]*base[0]/100)<<2;
q=OC_CLAMPI(OC_DC_QUANT_MIN[qti],q,OC_QUANT_MAX);
pbi->quant_tables[qti][pli][qi][0]=(ogg_uint16_t)q;
-
+ pbi->iquant_tables[qti][pli][qi][0]=(ogg_int32_t)(0.5 + (double)SHIFT16/q);
+
/*Now scale AC coefficients from the proper table.*/
for(ci=1;ci<64;ci++){
q=((ogg_uint32_t)qinfo->ac_scale[qi]*base[ci]/100)<<2;
q=OC_CLAMPI(OC_AC_QUANT_MIN[qti],q,OC_QUANT_MAX);
- pbi->quant_tables[qti][pli][qi][ci]=(ogg_uint16_t)q;
+ pbi->quant_tables[qti][pli][qi][zigzag_index[ci]]=(ogg_uint16_t)q;
+ pbi->iquant_tables[qti][pli][qi][ci]=(ogg_int32_t)(0.5 + (double)SHIFT16/q);
}
if(++qi>=qi_end)break;
@@ -272,361 +272,20 @@
}
-static void BuildZigZagIndex(PB_INSTANCE *pbi){
- ogg_int32_t i,j;
-
- /* invert the row to zigzag coeffient order lookup table */
- for ( i = 0; i < BLOCK_SIZE; i++ ){
- j = dezigzag_index[i];
- pbi->zigzag_index[j] = i;
- }
-}
-
-static void init_quantizer ( CP_INSTANCE *cpi,
- unsigned char QIndex ){
+void quantize( PB_INSTANCE *pbi,
+ ogg_int32_t *q,
+ ogg_int16_t *in,
+ ogg_int16_t *out){
int i;
- double ZBinFactor;
- double RoundingFactor;
-
- double temp_fp_quant_coeffs;
- double temp_fp_quant_round;
- double temp_fp_ZeroBinSize;
- PB_INSTANCE *pbi = &cpi->pb;
-
-
- const ogg_uint16_t * temp_Y_coeffs;
- const ogg_uint16_t * temp_U_coeffs;
- const ogg_uint16_t * temp_V_coeffs;
- const ogg_uint16_t * temp_Inter_Y_coeffs;
- const ogg_uint16_t * temp_Inter_U_coeffs;
- const ogg_uint16_t * temp_Inter_V_coeffs;
- ogg_uint16_t scale_factor = cpi->pb.quant_info.ac_scale[QIndex];
-
- /* Notes on setup of quantisers. The initial multiplication by
- the scale factor is done in the ogg_int32_t domain to insure that the
- precision in the quantiser is the same as in the inverse
- quantiser where all calculations are integer. The "<< 2" is a
- normalisation factor for the forward DCT transform. */
-
- temp_Y_coeffs = pbi->quant_tables[0][0][QIndex];
- temp_U_coeffs = pbi->quant_tables[0][1][QIndex];
- temp_V_coeffs = pbi->quant_tables[0][2][QIndex];
- temp_Inter_Y_coeffs = pbi->quant_tables[1][0][QIndex];
- temp_Inter_U_coeffs = pbi->quant_tables[1][1][QIndex];
- temp_Inter_V_coeffs = pbi->quant_tables[1][2][QIndex];
-
- ZBinFactor = 0.9;
-
- switch(cpi->pb.info.sharpness){
- case 0:
- ZBinFactor = 0.65;
- if ( scale_factor <= 50 )
- RoundingFactor = 0.499;
- else
- RoundingFactor = 0.46;
- break;
- case 1:
- ZBinFactor = 0.75;
- if ( scale_factor <= 50 )
- RoundingFactor = 0.476;
- else
- RoundingFactor = 0.400;
- break;
- default:
- ZBinFactor = 0.9;
- if ( scale_factor <= 50 )
- RoundingFactor = 0.476;
- else
- RoundingFactor = 0.333;
- break;
- }
-
- /* Use fixed multiplier for intra Y DC */
- temp_fp_quant_coeffs = temp_Y_coeffs[0];
- temp_fp_quant_round = temp_fp_quant_coeffs * RoundingFactor;
- pbi->fp_quant_Y_round[0] = (ogg_int32_t) (0.5 + temp_fp_quant_round);
- temp_fp_ZeroBinSize = temp_fp_quant_coeffs * ZBinFactor;
- pbi->fp_ZeroBinSize_Y[0] = (ogg_int32_t) (0.5 + temp_fp_ZeroBinSize);
- temp_fp_quant_coeffs = 1.0 / temp_fp_quant_coeffs;
- pbi->fp_quant_Y_coeffs[0] = (0.5 + SHIFT16 * temp_fp_quant_coeffs);
-
- /* Intra U */
- temp_fp_quant_coeffs = temp_U_coeffs[0];
- temp_fp_quant_round = temp_fp_quant_coeffs * RoundingFactor;
- pbi->fp_quant_U_round[0] = (0.5 + temp_fp_quant_round);
- temp_fp_ZeroBinSize = temp_fp_quant_coeffs * ZBinFactor;
- pbi->fp_ZeroBinSize_U[0] = (0.5 + temp_fp_ZeroBinSize);
- temp_fp_quant_coeffs = 1.0 / temp_fp_quant_coeffs;
- pbi->fp_quant_U_coeffs[0]= (0.5 + SHIFT16 * temp_fp_quant_coeffs);
-
- /* Intra V */
- temp_fp_quant_coeffs = temp_V_coeffs[0];
- temp_fp_quant_round = temp_fp_quant_coeffs * RoundingFactor;
- pbi->fp_quant_V_round[0] = (0.5 + temp_fp_quant_round);
- temp_fp_ZeroBinSize = temp_fp_quant_coeffs * ZBinFactor;
- pbi->fp_ZeroBinSize_V[0] = (0.5 + temp_fp_ZeroBinSize);
- temp_fp_quant_coeffs = 1.0 / temp_fp_quant_coeffs;
- pbi->fp_quant_V_coeffs[0]= (0.5 + SHIFT16 * temp_fp_quant_coeffs);
-
-
- /* Inter Y */
- temp_fp_quant_coeffs = temp_Inter_Y_coeffs[0];
- temp_fp_quant_round = temp_fp_quant_coeffs * RoundingFactor;
- pbi->fp_quant_Inter_Y_round[0]= (0.5 + temp_fp_quant_round);
- temp_fp_ZeroBinSize = temp_fp_quant_coeffs * ZBinFactor;
- pbi->fp_ZeroBinSize_Inter_Y[0]= (0.5 + temp_fp_ZeroBinSize);
- temp_fp_quant_coeffs= 1.0 / temp_fp_quant_coeffs;
- pbi->fp_quant_Inter_Y_coeffs[0]= (0.5 + SHIFT16 * temp_fp_quant_coeffs);
-
- /* Inter U */
- temp_fp_quant_coeffs = temp_Inter_U_coeffs[0];
- temp_fp_quant_round = temp_fp_quant_coeffs * RoundingFactor;
- pbi->fp_quant_Inter_U_round[0]= (0.5 + temp_fp_quant_round);
- temp_fp_ZeroBinSize = temp_fp_quant_coeffs * ZBinFactor;
- pbi->fp_ZeroBinSize_Inter_U[0]= (0.5 + temp_fp_ZeroBinSize);
- temp_fp_quant_coeffs= 1.0 / temp_fp_quant_coeffs;
- pbi->fp_quant_Inter_U_coeffs[0]= (0.5 + SHIFT16 * temp_fp_quant_coeffs);
-
- /* Inter V */
- temp_fp_quant_coeffs = temp_Inter_V_coeffs[0];
- temp_fp_quant_round = temp_fp_quant_coeffs * RoundingFactor;
- pbi->fp_quant_Inter_V_round[0]= (0.5 + temp_fp_quant_round);
- temp_fp_ZeroBinSize = temp_fp_quant_coeffs * ZBinFactor;
- pbi->fp_ZeroBinSize_Inter_V[0]= (0.5 + temp_fp_ZeroBinSize);
- temp_fp_quant_coeffs= 1.0 / temp_fp_quant_coeffs;
- pbi->fp_quant_Inter_V_coeffs[0]= (0.5 + SHIFT16 * temp_fp_quant_coeffs);
-
-
- for ( i = 1; i < 64; i++ ){
- /* Intra Y */
- temp_fp_quant_coeffs = temp_Y_coeffs[i];
- temp_fp_quant_round = temp_fp_quant_coeffs * RoundingFactor;
- pbi->fp_quant_Y_round[i] = (0.5 + temp_fp_quant_round);
- temp_fp_ZeroBinSize = temp_fp_quant_coeffs * ZBinFactor;
- pbi->fp_ZeroBinSize_Y[i] = (0.5 + temp_fp_ZeroBinSize);
- temp_fp_quant_coeffs = 1.0 / temp_fp_quant_coeffs;
- pbi->fp_quant_Y_coeffs[i] = (0.5 + SHIFT16 * temp_fp_quant_coeffs);
-
- /* Intra U */
- temp_fp_quant_coeffs = temp_U_coeffs[i];
- temp_fp_quant_round = temp_fp_quant_coeffs * RoundingFactor;
- pbi->fp_quant_U_round[i] = (0.5 + temp_fp_quant_round);
- temp_fp_ZeroBinSize = temp_fp_quant_coeffs * ZBinFactor;
- pbi->fp_ZeroBinSize_U[i] = (0.5 + temp_fp_ZeroBinSize);
- temp_fp_quant_coeffs = 1.0 / temp_fp_quant_coeffs;
- pbi->fp_quant_U_coeffs[i]= (0.5 + SHIFT16 * temp_fp_quant_coeffs);
-
- /* Intra V */
- temp_fp_quant_coeffs = temp_V_coeffs[i];
- temp_fp_quant_round = temp_fp_quant_coeffs * RoundingFactor;
- pbi->fp_quant_V_round[i] = (0.5 + temp_fp_quant_round);
- temp_fp_ZeroBinSize = temp_fp_quant_coeffs * ZBinFactor;
- pbi->fp_ZeroBinSize_V[i] = (0.5 + temp_fp_ZeroBinSize);
- temp_fp_quant_coeffs = 1.0 / temp_fp_quant_coeffs;
- pbi->fp_quant_V_coeffs[i]= (0.5 + SHIFT16 * temp_fp_quant_coeffs);
-
- /* Inter Y */
- temp_fp_quant_coeffs = temp_Inter_Y_coeffs[i];
- temp_fp_quant_round = temp_fp_quant_coeffs * RoundingFactor;
- pbi->fp_quant_Inter_Y_round[i]= (0.5 + temp_fp_quant_round);
- temp_fp_ZeroBinSize = temp_fp_quant_coeffs * ZBinFactor;
- pbi->fp_ZeroBinSize_Inter_Y[i]= (0.5 + temp_fp_ZeroBinSize);
- temp_fp_quant_coeffs = 1.0 / temp_fp_quant_coeffs;
- pbi->fp_quant_Inter_Y_coeffs[i]= (0.5 + SHIFT16 * temp_fp_quant_coeffs);
-
- /* Inter U */
- temp_fp_quant_coeffs = temp_Inter_U_coeffs[i];
- temp_fp_quant_round = temp_fp_quant_coeffs * RoundingFactor;
- pbi->fp_quant_Inter_U_round[i]= (0.5 + temp_fp_quant_round);
- temp_fp_ZeroBinSize = temp_fp_quant_coeffs * ZBinFactor;
- pbi->fp_ZeroBinSize_Inter_U[i]= (0.5 + temp_fp_ZeroBinSize);
- temp_fp_quant_coeffs = 1.0 / temp_fp_quant_coeffs;
- pbi->fp_quant_Inter_U_coeffs[i]= (0.5 + SHIFT16 * temp_fp_quant_coeffs);
-
- /* Inter V */
- temp_fp_quant_coeffs = temp_Inter_V_coeffs[i];
- temp_fp_quant_round = temp_fp_quant_coeffs * RoundingFactor;
- pbi->fp_quant_Inter_V_round[i]= (0.5 + temp_fp_quant_round);
- temp_fp_ZeroBinSize = temp_fp_quant_coeffs * ZBinFactor;
- pbi->fp_ZeroBinSize_Inter_V[i]= (0.5 + temp_fp_ZeroBinSize);
- temp_fp_quant_coeffs = 1.0 / temp_fp_quant_coeffs;
- pbi->fp_quant_Inter_V_coeffs[i]= (0.5 + SHIFT16 * temp_fp_quant_coeffs);
-
-
- }
-
- pbi->fquant_coeffs = pbi->fp_quant_Y_coeffs;
-
-}
-
-void select_quantiser(PB_INSTANCE *pbi, int type) {
- /* select a quantiser according to what plane has to be coded in what
- * mode. Could be extended to a more sophisticated scheme. */
-
- switch(type) {
- case BLOCK_Y:
- pbi->fquant_coeffs = pbi->fp_quant_Y_coeffs;
- pbi->fquant_round = pbi->fp_quant_Y_round;
- pbi->fquant_ZbSize = pbi->fp_ZeroBinSize_Y;
- break;
- case BLOCK_U:
- pbi->fquant_coeffs = pbi->fp_quant_U_coeffs;
- pbi->fquant_round = pbi->fp_quant_U_round;
- pbi->fquant_ZbSize = pbi->fp_ZeroBinSize_U;
- break;
- case BLOCK_V:
- pbi->fquant_coeffs = pbi->fp_quant_V_coeffs;
- pbi->fquant_round = pbi->fp_quant_V_round;
- pbi->fquant_ZbSize = pbi->fp_ZeroBinSize_V;
- break;
- case BLOCK_INTER_Y:
- pbi->fquant_coeffs = pbi->fp_quant_Inter_Y_coeffs;
- pbi->fquant_round = pbi->fp_quant_Inter_Y_round;
- pbi->fquant_ZbSize = pbi->fp_ZeroBinSize_Inter_Y;
- break;
- case BLOCK_INTER_U:
- pbi->fquant_coeffs = pbi->fp_quant_Inter_U_coeffs;
- pbi->fquant_round = pbi->fp_quant_Inter_U_round;
- pbi->fquant_ZbSize = pbi->fp_ZeroBinSize_Inter_U;
- break;
- case BLOCK_INTER_V:
- pbi->fquant_coeffs = pbi->fp_quant_Inter_V_coeffs;
- pbi->fquant_round = pbi->fp_quant_Inter_V_round;
- pbi->fquant_ZbSize = pbi->fp_ZeroBinSize_Inter_V;
- break;
- }
-}
-
-
-void quantize( PB_INSTANCE *pbi,
- ogg_int16_t * DCT_block,
- ogg_int16_t * quantized_list){
- ogg_uint32_t i; /* Row index */
- ogg_int16_t val; /* Quantised value. */
-
- ogg_int32_t * FquantRoundPtr = pbi->fquant_round;
- ogg_int32_t * FquantCoeffsPtr = pbi->fquant_coeffs;
- ogg_int32_t * FquantZBinSizePtr = pbi->fquant_ZbSize;
- ogg_int16_t * DCT_blockPtr = DCT_block;
- ogg_uint32_t * ZigZagPtr = (ogg_uint32_t *)pbi->zigzag_index;
- ogg_int32_t temp;
-
/* Set the quantized_list to default to 0 */
- memset( quantized_list, 0, 64 * sizeof(*quantized_list) );
-
- /* Note that we add half divisor to effect rounding on positive number */
- for( i = 0; i < VFRAGPIXELS; i++) {
+ memset(out, 0, 64 * sizeof(*out) );
- int col;
- /* Iterate through columns */
- for( col = 0; col < 8; col++) {
- if ( DCT_blockPtr[col] >= FquantZBinSizePtr[col] ) {
- temp = FquantCoeffsPtr[col] * ( DCT_blockPtr[col] + FquantRoundPtr[col] ) ;
- val = (temp>>16);
- quantized_list[ZigZagPtr[col]] = ( val > 511 ) ? 511 : val;
- } else if ( DCT_blockPtr[col] <= -FquantZBinSizePtr[col] ) {
- temp = FquantCoeffsPtr[col] *
- ( DCT_blockPtr[col] - FquantRoundPtr[col] ) + MIN16;
- val = (temp>>16);
- quantized_list[ZigZagPtr[col]] = ( val < -511 ) ? -511 : val;
- }
- }
-
- FquantRoundPtr += 8;
- FquantCoeffsPtr += 8;
- FquantZBinSizePtr += 8;
- DCT_blockPtr += 8;
- ZigZagPtr += 8;
+ /* Note that we add half divisor to effect rounding on positive number */
+ for( i = 0; i < 64; i++) {
+ int val = ( (q[i] * in[i] + (1<<15)) >> 16 );
+ if(val>511)val=511;
+ if(val<-511)val=-511;
+ out[zigzag_index[i]] = val;
}
}
-
-static void init_dequantizer ( PB_INSTANCE *pbi,
- unsigned char QIndex ){
- int i, j;
-
- ogg_uint16_t * InterY_coeffs;
- ogg_uint16_t * InterU_coeffs;
- ogg_uint16_t * InterV_coeffs;
- ogg_uint16_t * Y_coeffs;
- ogg_uint16_t * U_coeffs;
- ogg_uint16_t * V_coeffs;
-
- Y_coeffs = pbi->quant_tables[0][0][QIndex];
- U_coeffs = pbi->quant_tables[0][1][QIndex];
- V_coeffs = pbi->quant_tables[0][2][QIndex];
- InterY_coeffs = pbi->quant_tables[1][0][QIndex];
- InterU_coeffs = pbi->quant_tables[1][1][QIndex];
- InterV_coeffs = pbi->quant_tables[1][2][QIndex];
-
- /* invert the dequant index into the quant index
- the dxer has a different order than the cxer. */
- BuildZigZagIndex(pbi);
-
- /* Reorder dequantisation coefficients into dct zigzag order. */
- for ( i = 0; i < BLOCK_SIZE; i++ ) {
- j = pbi->zigzag_index[i];
- pbi->dequant_Y_coeffs[j] = Y_coeffs[i];
- }
- for ( i = 0; i < BLOCK_SIZE; i++ ) {
- j = pbi->zigzag_index[i];
- pbi->dequant_U_coeffs[j] = U_coeffs[i];
- }
- for ( i = 0; i < BLOCK_SIZE; i++ ) {
- j = pbi->zigzag_index[i];
- pbi->dequant_V_coeffs[j] = V_coeffs[i];
- }
- for ( i = 0; i < BLOCK_SIZE; i++ ){
- j = pbi->zigzag_index[i];
- pbi->dequant_InterY_coeffs[j] = InterY_coeffs[i];
- }
- for ( i = 0; i < BLOCK_SIZE; i++ ){
- j = pbi->zigzag_index[i];
- pbi->dequant_InterU_coeffs[j] = InterU_coeffs[i];
- }
- for ( i = 0; i < BLOCK_SIZE; i++ ){
- j = pbi->zigzag_index[i];
- pbi->dequant_InterV_coeffs[j] = InterV_coeffs[i];
- }
-}
-
-void UpdateQ( PB_INSTANCE *pbi, int NewQIndex ){
- ogg_uint32_t qscale;
-
- /* clamp to legal bounds */
- if (NewQIndex >= Q_TABLE_SIZE) NewQIndex = Q_TABLE_SIZE - 1;
- else if (NewQIndex < 0) NewQIndex = 0;
-
- pbi->FrameQIndex = NewQIndex;
-
- qscale = pbi->quant_info.ac_scale[NewQIndex];
- pbi->ThisFrameQualityValue = qscale;
-
- /* Re-initialise the Q tables for forward and reverse transforms. */
- init_dequantizer ( pbi, (unsigned char) pbi->FrameQIndex );
-}
-
-void UpdateQC( CP_INSTANCE *cpi, ogg_uint32_t NewQ ){
- ogg_uint32_t qscale;
- PB_INSTANCE *pbi = &cpi->pb;
-
- /* Do bounds checking and convert to a float. */
- qscale = NewQ;
- if ( qscale < pbi->quant_info.ac_scale[Q_TABLE_SIZE-1] )
- qscale = pbi->quant_info.ac_scale[Q_TABLE_SIZE-1];
- else if ( qscale > pbi->quant_info.ac_scale[0] )
- qscale = pbi->quant_info.ac_scale[0];
-
- /* Set the inter/intra descision control variables. */
- pbi->FrameQIndex = Q_TABLE_SIZE - 1;
- while ((ogg_int32_t) pbi->FrameQIndex >= 0 ) {
- if ( (pbi->FrameQIndex == 0) ||
- ( pbi->quant_info.ac_scale[pbi->FrameQIndex] >= NewQ) )
- break;
- pbi->FrameQIndex --;
- }
-
- /* Re-initialise the Q tables for forward and reverse transforms. */
- init_quantizer ( cpi, pbi->FrameQIndex );
- init_dequantizer ( pbi, pbi->FrameQIndex );
-}
Modified: branches/theora-thusnelda/lib/enc/encoder_toplevel.c
===================================================================
--- branches/theora-thusnelda/lib/enc/encoder_toplevel.c 2007-11-26 00:13:48 UTC (rev 14232)
+++ branches/theora-thusnelda/lib/enc/encoder_toplevel.c 2007-11-26 17:06:55 UTC (rev 14233)
@@ -231,12 +231,6 @@
SetupKeyFrame(cpi);
- cpi->pb.ThisFrameQualityValue =
- cpi->pb.quant_info.ac_scale[cpi->BaseQ];
-
- /* Initialise quantizer. */
- UpdateQC(cpi, cpi->pb.ThisFrameQualityValue );
-
/* Compress and output the frist frame. */
PickIntra( cpi, cpi->pb.YSBRows, cpi->pb.YSBCols);
UpdateFrame(cpi);
@@ -250,9 +244,6 @@
SetupKeyFrame(cpi);
- /* Initialise DCT tables. */
- UpdateQC(cpi, cpi->pb.ThisFrameQualityValue );
-
/* Compress and output the frist frame. */
PickIntra( cpi, cpi->pb.YSBRows, cpi->pb.YSBCols);
UpdateFrame(cpi);
@@ -288,16 +279,16 @@
/* Select modes and motion vectors for each of the blocks : return
an error score for inter and intra */
PickModes( cpi, cpi->pb.YSBRows, cpi->pb.YSBCols,
- cpi->pb.info.width,
+ cpi->info.width,
&InterError, &IntraError );
/* decide whether we really should have made this frame a key frame */
/* forcing out a keyframe if the max interval is up is done at a higher level */
- if( cpi->pb.info.keyframe_auto_p){
+ if( cpi->info.keyframe_auto_p){
if( ( 2* IntraError < 5 * InterError )
&& ( KFIndicator >= (ogg_uint32_t)
- cpi->pb.info.keyframe_auto_threshold)
- && ( cpi->LastKeyFrame > cpi->pb.info.keyframe_mindistance)
+ cpi->info.keyframe_auto_threshold)
+ && ( cpi->LastKeyFrame > cpi->info.keyframe_mindistance)
){
CompressKeyFrame(cpi); /* Code a key frame */
return 0;
@@ -383,15 +374,15 @@
if(c->keyframe_mindistance>32768)c->keyframe_mindistance=32768;
if(c->keyframe_mindistance>c->keyframe_frequency_force)
c->keyframe_mindistance=c->keyframe_frequency_force;
- cpi->pb.keyframe_granule_shift=_ilog(c->keyframe_frequency_force-1);
+ cpi->keyframe_granule_shift=_ilog(c->keyframe_frequency_force-1);
/* clamp the target_bitrate to a maximum of 24 bits so we get a
more meaningful value when we write this out in the header. */
if(c->target_bitrate>(1<<24)-1)c->target_bitrate=(1<<24)-1;
/* copy in config */
- memcpy(&cpi->pb.info,c,sizeof(*c));
- th->i=&cpi->pb.info;
+ memcpy(&cpi->info,c,sizeof(*c));
+ th->i=&cpi->info;
th->granulepos=-1;
/* Set up an encode buffer */
@@ -404,7 +395,7 @@
oggpackB_writeinit(cpi->oggbuffer, cpi->oggbufferstate);
#endif
- InitFrameDetails(&cpi->pb);
+ InitFrameDetails(cpi);
EInitFragmentInfo(cpi);
EInitFrameInfo(cpi);
@@ -426,7 +417,7 @@
cpi->ThisIsFirstFrame = 1;
cpi->readyflag = 1;
- cpi->pb.HeadersWritten = 0;
+ cpi->HeadersWritten = 0;
return 0;
}
@@ -443,8 +434,8 @@
if(cpi->doneflag)return OC_EINVAL;
/* If frame size has changed, abort out for now */
- if (yuv->y_height != (int)cpi->pb.info.height ||
- yuv->y_width != (int)cpi->pb.info.width )
+ if (yuv->y_height != (int)cpi->info.height ||
+ yuv->y_width != (int)cpi->info.width )
return(-1);
/* Copy over input YUV to internal YUV buffers. */
@@ -489,7 +480,7 @@
/* don't allow generating invalid files that overflow the p-frame
shift, even if keyframe_auto_p is turned off */
if(cpi->LastKeyFrame >= (ogg_uint32_t)
- cpi->pb.info.keyframe_frequency_force)
+ cpi->info.keyframe_frequency_force)
cpi->ThisIsKeyFrame = 1;
if ( cpi->ThisIsKeyFrame ) {
@@ -507,7 +498,7 @@
cpi->packetflag=1;
t->granulepos=
- ((cpi->CurrentFrame - cpi->LastKeyFrame)<<cpi->pb.keyframe_granule_shift)+
+ ((cpi->CurrentFrame - cpi->LastKeyFrame)<<cpi->keyframe_granule_shift)+
cpi->LastKeyFrame - 1;
#ifdef _TH_DEBUG_
@@ -576,30 +567,30 @@
oggpackB_write(cpi->oggbuffer,TH_VERSION_MINOR,8);
oggpackB_write(cpi->oggbuffer,TH_VERSION_SUB,8);
- oggpackB_write(cpi->oggbuffer,cpi->pb.info.width>>4,16);
- oggpackB_write(cpi->oggbuffer,cpi->pb.info.height>>4,16);
- oggpackB_write(cpi->oggbuffer,cpi->pb.info.frame_width,24);
- oggpackB_write(cpi->oggbuffer,cpi->pb.info.frame_height,24);
- oggpackB_write(cpi->oggbuffer,cpi->pb.info.offset_x,8);
+ oggpackB_write(cpi->oggbuffer,cpi->info.width>>4,16);
+ oggpackB_write(cpi->oggbuffer,cpi->info.height>>4,16);
+ oggpackB_write(cpi->oggbuffer,cpi->info.frame_width,24);
+ oggpackB_write(cpi->oggbuffer,cpi->info.frame_height,24);
+ oggpackB_write(cpi->oggbuffer,cpi->info.offset_x,8);
/* Applications use offset_y to mean offset from the top of the image; the
* meaning in the bitstream is the opposite (from the bottom). Transform.
*/
- offset_y = cpi->pb.info.height - cpi->pb.info.frame_height -
- cpi->pb.info.offset_y;
+ offset_y = cpi->info.height - cpi->info.frame_height -
+ cpi->info.offset_y;
oggpackB_write(cpi->oggbuffer,offset_y,8);
- oggpackB_write(cpi->oggbuffer,cpi->pb.info.fps_numerator,32);
- oggpackB_write(cpi->oggbuffer,cpi->pb.info.fps_denominator,32);
- oggpackB_write(cpi->oggbuffer,cpi->pb.info.aspect_numerator,24);
- oggpackB_write(cpi->oggbuffer,cpi->pb.info.aspect_denominator,24);
+ oggpackB_write(cpi->oggbuffer,cpi->info.fps_numerator,32);
+ oggpackB_write(cpi->oggbuffer,cpi->info.fps_denominator,32);
+ oggpackB_write(cpi->oggbuffer,cpi->info.aspect_numerator,24);
+ oggpackB_write(cpi->oggbuffer,cpi->info.aspect_denominator,24);
- oggpackB_write(cpi->oggbuffer,cpi->pb.info.colorspace,8);
- oggpackB_write(cpi->oggbuffer,cpi->pb.info.target_bitrate,24);
- oggpackB_write(cpi->oggbuffer,cpi->pb.info.quality,6);
+ oggpackB_write(cpi->oggbuffer,cpi->info.colorspace,8);
+ oggpackB_write(cpi->oggbuffer,cpi->info.target_bitrate,24);
+ oggpackB_write(cpi->oggbuffer,cpi->info.quality,6);
- oggpackB_write(cpi->oggbuffer,cpi->pb.keyframe_granule_shift,5);
+ oggpackB_write(cpi->oggbuffer,cpi->keyframe_granule_shift,5);
- oggpackB_write(cpi->oggbuffer,cpi->pb.info.pixelformat,2);
+ oggpackB_write(cpi->oggbuffer,cpi->info.pixelformat,2);
oggpackB_write(cpi->oggbuffer,0,3); /* spare config bits */
@@ -708,7 +699,7 @@
op->granulepos=0;
cpi->packetflag=0;
- cpi->pb.HeadersWritten = 1;
+ cpi->HeadersWritten = 1;
return(0);
}
@@ -747,11 +738,11 @@
if(cpi)pbi=&cpi->pb;
if(granulepos>=0){
- ogg_int64_t iframe=granulepos>>pbi->keyframe_granule_shift;
- ogg_int64_t pframe=granulepos-(iframe<<pbi->keyframe_granule_shift);
+ ogg_int64_t iframe=granulepos>>cpi->keyframe_granule_shift;
+ ogg_int64_t pframe=granulepos-(iframe<<cpi->keyframe_granule_shift);
return (iframe+pframe)*
- ((double)pbi->info.fps_denominator/pbi->info.fps_numerator);
+ ((double)cpi->info.fps_denominator/cpi->info.fps_numerator);
}
#endif
@@ -768,8 +759,8 @@
if(cpi)pbi=&cpi->pb;
if(granulepos>=0){
- ogg_int64_t iframe=granulepos>>pbi->keyframe_granule_shift;
- ogg_int64_t pframe=granulepos-(iframe<<pbi->keyframe_granule_shift);
+ ogg_int64_t iframe=granulepos>>cpi->keyframe_granule_shift;
+ ogg_int64_t pframe=granulepos-(iframe<<cpi->keyframe_granule_shift);
return (iframe+pframe);
}
@@ -794,7 +785,7 @@
case TH_ENCCTL_SET_QUANT_PARAMS:
if( ( buf==NULL&&buf_sz!=0 )
|| ( buf!=NULL&&buf_sz!=sizeof(th_quant_info) )
- || cpi->pb.HeadersWritten ){
+ || cpi->HeadersWritten ){
return TH_EINVAL;
}
@@ -803,7 +794,7 @@
return 0;
case TH_ENCCTL_SET_VP3_COMPATIBLE:
- if(cpi->pb.HeadersWritten)
+ if(cpi->HeadersWritten)
return TH_EINVAL;
memcpy(&pbi->quant_info, &TH_VP31_QUANT_INFO, sizeof(th_quant_info));
@@ -819,17 +810,17 @@
switch(value) {
case 0:
cpi->MotionCompensation = 1;
- pbi->info.quick_p = 0;
+ cpi->info.quick_p = 0;
break;
case 1:
cpi->MotionCompensation = 1;
- pbi->info.quick_p = 1;
+ cpi->info.quick_p = 1;
break;
case 2:
cpi->MotionCompensation = 0;
- pbi->info.quick_p = 1;
+ cpi->info.quick_p = 1;
break;
default:
Modified: branches/theora-thusnelda/lib/enc/frinit.c
===================================================================
--- branches/theora-thusnelda/lib/enc/frinit.c 2007-11-26 00:13:48 UTC (rev 14232)
+++ branches/theora-thusnelda/lib/enc/frinit.c 2007-11-26 17:06:55 UTC (rev 14233)
@@ -19,7 +19,8 @@
#include "codec_internal.h"
-static void CalcPixelIndexTable( PB_INSTANCE *pbi){
+static void CalcPixelIndexTable( CP_INSTANCE *cpi){
+ PB_INSTANCE *pbi = &cpi->pb;
ogg_uint32_t i;
ogg_uint32_t * PixelIndexTablePtr;
@@ -28,7 +29,7 @@
for ( i = 0; i < pbi->YPlaneFragments; i++ ) {
PixelIndexTablePtr[ i ] =
((i / pbi->HFragments) * VFRAGPIXELS *
- pbi->info.width);
+ cpi->info.width);
PixelIndexTablePtr[ i ] +=
((i % pbi->HFragments) * HFRAGPIXELS);
}
@@ -38,7 +39,7 @@
PixelIndexTablePtr[ i ] =
((i / (pbi->HFragments / 2) ) *
(VFRAGPIXELS *
- (pbi->info.width / 2)) );
+ (cpi->info.width / 2)) );
PixelIndexTablePtr[ i ] +=
((i % (pbi->HFragments / 2) ) *
HFRAGPIXELS) + pbi->YPlaneSize;
@@ -244,24 +245,25 @@
}
-void InitFrameDetails(PB_INSTANCE *pbi){
+void InitFrameDetails(CP_INSTANCE *cpi){
int FrameSize;
+ PB_INSTANCE *pbi = &cpi->pb;
/* Set the frame size etc. */
- pbi->YPlaneSize = pbi->info.width *
- pbi->info.height;
+ pbi->YPlaneSize = cpi->info.width *
+ cpi->info.height;
pbi->UVPlaneSize = pbi->YPlaneSize / 4;
- pbi->HFragments = pbi->info.width / HFRAGPIXELS;
- pbi->VFragments = pbi->info.height / VFRAGPIXELS;
+ pbi->HFragments = cpi->info.width / HFRAGPIXELS;
+ pbi->VFragments = cpi->info.height / VFRAGPIXELS;
pbi->UnitFragments = ((pbi->VFragments * pbi->HFragments)*3)/2;
pbi->YPlaneFragments = pbi->HFragments * pbi->VFragments;
pbi->UVPlaneFragments = pbi->YPlaneFragments / 4;
- pbi->YStride = (pbi->info.width + STRIDE_EXTRA);
+ pbi->YStride = (cpi->info.width + STRIDE_EXTRA);
pbi->UVStride = pbi->YStride / 2;
pbi->ReconYPlaneSize = pbi->YStride *
- (pbi->info.height + STRIDE_EXTRA);
+ (cpi->info.height + STRIDE_EXTRA);
pbi->ReconUVPlaneSize = pbi->ReconYPlaneSize / 4;
FrameSize = pbi->ReconYPlaneSize + 2 * pbi->ReconUVPlaneSize;
@@ -276,14 +278,14 @@
(pbi->UVStride * (UMV_BORDER/2)) + (UMV_BORDER/2);
/* Image dimensions in Super-Blocks */
- pbi->YSBRows = (pbi->info.height/32) +
- ( pbi->info.height%32 ? 1 : 0 );
- pbi->YSBCols = (pbi->info.width/32) +
- ( pbi->info.width%32 ? 1 : 0 );
- pbi->UVSBRows = ((pbi->info.height/2)/32) +
- ( (pbi->info.height/2)%32 ? 1 : 0 );
- pbi->UVSBCols = ((pbi->info.width/2)/32) +
- ( (pbi->info.width/2)%32 ? 1 : 0 );
+ pbi->YSBRows = (cpi->info.height/32) +
+ ( cpi->info.height%32 ? 1 : 0 );
+ pbi->YSBCols = (cpi->info.width/32) +
+ ( cpi->info.width%32 ? 1 : 0 );
+ pbi->UVSBRows = ((cpi->info.height/2)/32) +
+ ( (cpi->info.height/2)%32 ? 1 : 0 );
+ pbi->UVSBCols = ((cpi->info.width/2)/32) +
+ ( (cpi->info.width/2)%32 ? 1 : 0 );
/* Super-Blocks per component */
pbi->YSuperBlocks = pbi->YSBRows * pbi->YSBCols;
@@ -302,7 +304,7 @@
/* Re-initialise the pixel index table. */
- CalcPixelIndexTable( pbi );
+ CalcPixelIndexTable( cpi );
}
Modified: branches/theora-thusnelda/lib/enc/quant_lookup.h
===================================================================
--- branches/theora-thusnelda/lib/enc/quant_lookup.h 2007-11-26 00:13:48 UTC (rev 14232)
+++ branches/theora-thusnelda/lib/enc/quant_lookup.h 2007-11-26 17:06:55 UTC (rev 14233)
@@ -30,6 +30,17 @@
* lookup table for DCT coefficient zig-zag ordering
* ****************************/
+static const ogg_uint32_t zigzag_index[64] = {
+ 0, 1, 5, 6, 14, 15, 27, 28,
+ 2, 4, 7, 13, 16, 26, 29, 42,
+ 3, 8, 12, 17, 25, 30, 41, 43,
+ 9, 11, 18, 24, 31, 40, 44, 53,
+ 10, 19, 23, 32, 39, 45, 52, 54,
+ 20, 22, 33, 38, 46, 51, 55, 60,
+ 21, 34, 37, 47, 50, 56, 59, 61,
+ 35, 36, 48, 49, 57, 58, 62, 63
+};
+
static const ogg_uint32_t dezigzag_index[64] = {
0, 1, 8, 16, 9, 2, 3, 10,
17, 24, 32, 25, 18, 11, 4, 5,
More information about the commits
mailing list