[xiph-commits] r14199 - in branches/theora-thusnelda/lib: . enc
xiphmont at svn.xiph.org
xiphmont at svn.xiph.org
Tue Nov 20 06:33:27 PST 2007
Author: xiphmont
Date: 2007-11-20 06:33:26 -0800 (Tue, 20 Nov 2007)
New Revision: 14199
Removed:
branches/theora-thusnelda/lib/enc/misc_common.c
branches/theora-thusnelda/lib/enc/pp.c
branches/theora-thusnelda/lib/enc/pp.h
branches/theora-thusnelda/lib/enc/scan.c
Modified:
branches/theora-thusnelda/lib/Makefile.am
branches/theora-thusnelda/lib/enc/codec_internal.h
branches/theora-thusnelda/lib/enc/dct_encode.c
branches/theora-thusnelda/lib/enc/encode.c
branches/theora-thusnelda/lib/enc/encoder_huffman.c
branches/theora-thusnelda/lib/enc/encoder_idct.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/mcomp.c
branches/theora-thusnelda/lib/enc/pb.c
Log:
Continue the process of tearing out dead, misguided and
soon-to-be-replaced code.
Modified: branches/theora-thusnelda/lib/Makefile.am
===================================================================
--- branches/theora-thusnelda/lib/Makefile.am 2007-11-20 02:45:44 UTC (rev 14198)
+++ branches/theora-thusnelda/lib/Makefile.am 2007-11-20 14:33:26 UTC (rev 14199)
@@ -40,11 +40,8 @@
enc/frarray.c \
enc/frinit.c \
enc/mcomp.c \
- enc/misc_common.c \
enc/pb.c \
- enc/pp.c \
enc/reconstruct.c \
- enc/scan.c \
enc/dsp.c
if CPU_x86_64
@@ -108,7 +105,6 @@
enc/encoder_lookup.h \
enc/encoder_huffman.h \
enc/hufftables.h \
- enc/pp.h \
enc/quant_lookup.h \
enc/toplevel_lookup.h \
enc/dsp.h \
Modified: branches/theora-thusnelda/lib/enc/codec_internal.h
===================================================================
--- branches/theora-thusnelda/lib/enc/codec_internal.h 2007-11-20 02:45:44 UTC (rev 14198)
+++ branches/theora-thusnelda/lib/enc/codec_internal.h 2007-11-20 14:33:26 UTC (rev 14199)
@@ -59,8 +59,8 @@
#define Q_TABLE_SIZE 64
-#define KEY_FRAME 0
-#define DELTA_FRAME 1
+#define KEY_FRAME 0
+#define DELTA_FRAME 1
#define MAX_MODES 8
#define MODE_BITS 3
@@ -72,22 +72,14 @@
#define KEY_FRAME_CONTEXT 5
-/* Preprocessor defines */
-#define MAX_PREV_FRAMES 16
-
/* Number of search sites for a 4-step search (at pixel accuracy) */
#define MAX_SEARCH_SITES 33
-#define VERY_BEST_Q 10
-#define MIN_BPB_FACTOR 0.3
-#define MAX_BPB_FACTOR 3.0
-
#define MAX_MV_EXTENT 31 /* Max search distance in half pixel increments */
typedef struct CONFIG_TYPE2{
double OutputFrameRate;
ogg_uint32_t TargetBandwidth;
- ogg_uint32_t KeyFrameDataTarget ; /* Data rate target for key frames */
ogg_uint32_t FirstFrameQ;
ogg_uint32_t BaseQ;
@@ -102,145 +94,12 @@
} COEFFNODE;
typedef struct{
- unsigned char * Yuv0ptr;
- unsigned char * Yuv1ptr;
- unsigned char * disp_fragments;
-
- ogg_uint32_t * RegionIndex; /* Gives pixel index for top left of
- each block */
- ogg_uint32_t VideoFrameHeight;
- ogg_uint32_t VideoFrameWidth;
-
-} SCAN_CONFIG_DATA;
-
-typedef unsigned char YUV_BUFFER_ENTRY;
-
-typedef struct{
ogg_int32_t x;
ogg_int32_t y;
} MOTION_VECTOR;
typedef MOTION_VECTOR COORDINATE;
-/** Quantizer matrix entry */
-typedef ogg_int16_t Q_LIST_ENTRY;
-
-/** Decode Post-Processor instance */
-typedef struct PP_INSTANCE {
- ogg_uint32_t PrevFrameLimit;
-
- ogg_uint32_t *ScanPixelIndexTable;
- signed char *ScanDisplayFragments;
-
- signed char *PrevFragments[MAX_PREV_FRAMES];
-
- ogg_uint32_t *FragScores; /* The individual frame difference ratings. */
- signed char *SameGreyDirPixels;
- signed char *BarBlockMap;
-
- /* Number of pixels changed by diff threshold in row of a fragment. */
- unsigned char *FragDiffPixels;
-
- unsigned char *PixelScores;
- unsigned char *PixelChangedMap;
- unsigned char *ChLocals;
- ogg_int16_t *yuv_differences;
- ogg_int32_t *RowChangedPixels;
- signed char *TmpCodedMap;
-
- /* Plane pointers and dimension variables */
- unsigned char * YPlanePtr0;
- unsigned char * YPlanePtr1;
- unsigned char * UPlanePtr0;
- unsigned char * UPlanePtr1;
- unsigned char * VPlanePtr0;
- unsigned char * VPlanePtr1;
-
- ogg_uint32_t VideoYPlaneWidth;
- ogg_uint32_t VideoYPlaneHeight;
- ogg_uint32_t VideoUVPlaneWidth;
- ogg_uint32_t VideoUVPlaneHeight;
-
- ogg_uint32_t VideoYPlaneStride;
- ogg_uint32_t VideoUPlaneStride;
- ogg_uint32_t VideoVPlaneStride;
-
- /* Scan control variables. */
- unsigned char HFragPixels;
- unsigned char VFragPixels;
-
- ogg_uint32_t ScanFrameFragments;
- ogg_uint32_t ScanYPlaneFragments;
- ogg_uint32_t ScanUVPlaneFragments;
- ogg_uint32_t ScanHFragments;
- ogg_uint32_t ScanVFragments;
-
- ogg_uint32_t YFramePixels;
- ogg_uint32_t UVFramePixels;
-
- ogg_uint32_t SgcThresh;
-
- ogg_uint32_t OutputBlocksUpdated;
- ogg_uint32_t KFIndicator;
-
- /* The pre-processor scan configuration. */
- SCAN_CONFIG_DATA ScanConfig;
-
- ogg_int32_t SRFGreyThresh;
- ogg_int32_t SRFColThresh;
- ogg_int32_t SgcLevelThresh;
- ogg_int32_t SuvcLevelThresh;
-
- ogg_uint32_t NoiseSupLevel;
-
- /* Block Thresholds. */
- ogg_uint32_t PrimaryBlockThreshold;
- unsigned char LineSearchTripTresh;
-
- int PAKEnabled;
-
- int LevelThresh;
- int NegLevelThresh;
- int SrfThresh;
- int NegSrfThresh;
- int HighChange;
- int NegHighChange;
-
- /* Threshold lookup tables */
- unsigned char SrfPakThreshTable[512];
- unsigned char SrfThreshTable[512];
- unsigned char SgcThreshTable[512];
-
- /* Variables controlling S.A.D. break outs. */
- ogg_uint32_t GrpLowSadThresh;
- ogg_uint32_t GrpHighSadThresh;
- ogg_uint32_t ModifiedGrpLowSadThresh;
- ogg_uint32_t ModifiedGrpHighSadThresh;
-
- ogg_int32_t PlaneHFragments;
- ogg_int32_t PlaneVFragments;
- ogg_int32_t PlaneHeight;
- ogg_int32_t PlaneWidth;
- ogg_int32_t PlaneStride;
-
- ogg_uint32_t BlockThreshold;
- ogg_uint32_t BlockSgcThresh;
- double UVBlockThreshCorrection;
- double UVSgcCorrection;
-
- double YUVPlaneCorrectionFactor;
- double AbsDiff_ScoreMultiplierTable[256];
- unsigned char NoiseScoreBoostTable[256];
- unsigned char MaxLineSearchLen;
-
- ogg_int32_t YuvDiffsCircularBufferSize;
- ogg_int32_t ChLocalsCircularBufferSize;
- ogg_int32_t PixelMapCircularBufferSize;
-
- DspFunctions dsp; /* Selected functions for this platform */
-
-} PP_INSTANCE;
-
/** block coding modes */
typedef enum{
CODE_INTER_NO_MV = 0x0, /* INTER prediction, (0,0) motion
@@ -268,16 +127,16 @@
typedef struct qmat_range_table {
int startq, startqi; /* index where this range starts */
- Q_LIST_ENTRY *qmat; /* qmat at this range boundary */
+ ogg_int16_t *qmat; /* qmat at this range boundary */
} qmat_range_table;
/** codec setup data, maps to the third bitstream header */
typedef struct codec_setup_info {
ogg_uint32_t QThreshTable[Q_TABLE_SIZE];
- Q_LIST_ENTRY DcScaleFactorTable[Q_TABLE_SIZE];
+ ogg_int16_t DcScaleFactorTable[Q_TABLE_SIZE];
int MaxQMatrixIndex;
- Q_LIST_ENTRY *qmats;
+ ogg_int16_t *qmats;
qmat_range_table *range_table[6];
HUFF_ENTRY *HuffRoot[NUM_HUFF_TABLES];
@@ -291,30 +150,20 @@
theora_info info;
/* flag to indicate if the headers already have been written */
- int HeadersWritten;
+ int HeadersWritten;
/* how far do we shift the granulepos to seperate out P frame counts? */
int keyframe_granule_shift;
/***********************************************************************/
- /* Decoder and Frame Type Information */
-
- int DecoderErrorCode;
- int FramesHaveBeenSkipped;
-
- int PostProcessEnabled;
- ogg_uint32_t PostProcessingLevel; /* Perform post processing */
-
/* Frame Info */
CODING_MODE CodingMode;
unsigned char FrameType;
- unsigned char KeyFrameType;
ogg_uint32_t QualitySetting;
ogg_uint32_t FrameQIndex; /* Quality specified as a
table index */
ogg_uint32_t ThisFrameQualityValue; /* Quality value for this frame */
- ogg_uint32_t LastFrameQualityValue; /* Last Frame's Quality */
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. */
@@ -359,10 +208,9 @@
/**********************************************************************/
/* Frames */
- YUV_BUFFER_ENTRY *ThisFrameRecon;
- YUV_BUFFER_ENTRY *GoldenFrame;
- YUV_BUFFER_ENTRY *LastFrameRecon;
- YUV_BUFFER_ENTRY *PostProcessBuffer;
+ unsigned char *ThisFrameRecon;
+ unsigned char *GoldenFrame;
+ unsigned char *LastFrameRecon;
/**********************************************************************/
/* Fragment Information */
@@ -373,9 +221,6 @@
pixel in recon buffer */
unsigned char *display_fragments; /* Fragment update map */
- unsigned char *skipped_display_fragments;/* whether fragment YUV
- Conversion and update is to be
- skipped */
ogg_int32_t *CodedBlockList; /* A list of fragment indices for
coded blocks. */
MOTION_VECTOR *FragMVect; /* Frag motion vectors */
@@ -383,32 +228,16 @@
ogg_uint32_t *FragTokenCounts; /* Number of tokens per fragment */
ogg_uint32_t (*TokenList)[128]; /* Fragment Token Pointers */
- ogg_int32_t *FragmentVariances;
- ogg_uint32_t *FragQIndex; /* Fragment Quality used in
- PostProcess */
- Q_LIST_ENTRY (*PPCoefBuffer)[64]; /* PostProcess Buffer for
- coefficients data */
-
unsigned char *FragCoeffs; /* # of coeffs decoded so far for
fragment */
unsigned char *FragCoefEOB; /* Position of last non 0 coef
within QFragData */
- Q_LIST_ENTRY (*QFragData)[64]; /* Fragment Coefficients
+ ogg_int16_t (*QFragData)[64]; /* Fragment Coefficients
Array Pointers */
CODING_MODE *FragCodingMethod; /* coding method for the
fragment */
/***********************************************************************/
- /* pointers to addresses used for allocation and deallocation the
- others are rounded up to the nearest 32 bytes */
-
- COEFFNODE *_Nodes;
- ogg_uint32_t *transIndex; /* ptr to table of
- transposed indexes */
-
- /***********************************************************************/
- ogg_int32_t bumpLast;
-
/* Macro Block and SuperBlock Information */
ogg_int32_t (*BlockMap)[4][4]; /* super block + sub macro
block + sub frag ->
@@ -423,38 +252,15 @@
/**********************************************************************/
ogg_uint32_t EOB_Run;
- COORDINATE *FragCoordinates;
MOTION_VECTOR MVector;
ogg_int32_t ReconPtr2Offset; /* Offset for second reconstruction
in half pixel MC */
- Q_LIST_ENTRY *quantized_list;
+ ogg_int16_t *quantized_list;
ogg_int16_t *ReconDataBuffer;
- Q_LIST_ENTRY InvLastIntraDC;
- Q_LIST_ENTRY InvLastInterDC;
- Q_LIST_ENTRY LastIntraDC;
- Q_LIST_ENTRY LastInterDC;
- ogg_uint32_t BlocksToDecode; /* Blocks to be decoded this frame */
ogg_uint32_t DcHuffChoice; /* Huffman table selection variables */
unsigned char ACHuffChoice;
- ogg_uint32_t QuadMBListIndex;
- ogg_int32_t ByteCount;
-
- ogg_uint32_t bit_pattern;
- unsigned char bits_so_far;
- unsigned char NextBit;
- ogg_int32_t BitsLeft;
-
- ogg_int16_t *DequantBuffer;
-
- ogg_int32_t fp_quant_InterUV_coeffs[64];
- ogg_int32_t fp_quant_InterUV_round[64];
- ogg_int32_t fp_ZeroBinSize_InterUV[64];
-
- ogg_int16_t *TmpReconBuffer;
- ogg_int16_t *TmpDataBuffer;
-
/* Loop filter bounding values */
ogg_int16_t FiltBoundingValue[256];
@@ -463,15 +269,15 @@
* rest is Intra. */
/* Dequantiser and rounding tables */
- ogg_uint16_t *QThreshTable;
- Q_LIST_ENTRY dequant_Y_coeffs[64];
- Q_LIST_ENTRY dequant_U_coeffs[64];
- Q_LIST_ENTRY dequant_V_coeffs[64];
- Q_LIST_ENTRY dequant_InterY_coeffs[64];
- Q_LIST_ENTRY dequant_InterU_coeffs[64];
- Q_LIST_ENTRY dequant_InterV_coeffs[64];
+ 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];
- Q_LIST_ENTRY *dequant_coeffs; /* currently active quantizer */
+ ogg_int16_t *dequant_coeffs; /* currently active quantizer */
unsigned int zigzag_index[64];
HUFF_ENTRY *HuffRoot_VP3x[NUM_HUFF_TABLES];
@@ -513,19 +319,14 @@
/* Predictor used in choosing entropy table for decoding block patterns. */
unsigned char BlockPatternPredictor;
- short Modifier[4][512];
- short *ModifierPointer[4];
-
- unsigned char *DataOutputInPtr;
-
DspFunctions dsp; /* Selected functions for this platform */
#ifdef _TH_DEBUG_
- Q_LIST_ENTRY (*QFragQUAN)[64]; /* Fragment Coefficients
+ ogg_int16_t (*QFragQUAN)[64]; /* Fragment Coefficients
Array Pointers */
- Q_LIST_ENTRY (*QFragFREQ)[64]; /* Fragment Coefficients
+ ogg_int16_t (*QFragFREQ)[64]; /* Fragment Coefficients
Array Pointers */
- Q_LIST_ENTRY (*QFragTIME)[64]; /* Fragment Coefficients
+ ogg_int16_t (*QFragTIME)[64]; /* Fragment Coefficients
Array Pointers */
#endif
@@ -539,61 +340,24 @@
oc_state_dispatch_vtbl dispatch_vtbl;
/* Compressor Configuration */
- SCAN_CONFIG_DATA ScanConfig;
CONFIG_TYPE2 Configuration;
int GoldenFrameEnabled;
int InterPrediction;
int MotionCompensation;
ogg_uint32_t LastKeyFrame ;
- ogg_int32_t DropCount ;
- ogg_int32_t MaxConsDroppedFrames ;
- ogg_int32_t DropFrameTriggerBytes;
- int DropFrameCandidate;
/* Compressor Statistics */
- double TotErrScore;
ogg_int64_t KeyFrameCount; /* Count of key frames. */
ogg_int64_t TotKeyFrameBytes;
- ogg_uint32_t LastKeyFrameSize;
- ogg_uint32_t PriorKeyFrameSize[KEY_FRAME_CONTEXT];
- ogg_uint32_t PriorKeyFrameDistance[KEY_FRAME_CONTEXT];
- ogg_int32_t FrameQuality[6];
- int DecoderErrorCode; /* Decoder error flag. */
- ogg_int32_t ThreshMapThreshold;
- ogg_int32_t TotalMotionScore;
- ogg_int64_t TotalByteCount;
- ogg_int32_t FixedQ;
/* Frame Statistics */
signed char InterCodeCount;
ogg_int64_t CurrentFrame;
- ogg_int64_t CarryOver ;
- ogg_uint32_t LastFrameSize;
ogg_uint32_t FrameBitCount;
int ThisIsFirstFrame;
int ThisIsKeyFrame;
- ogg_int32_t MotionScore;
- ogg_uint32_t RegulationBlocks;
- ogg_int32_t RecoveryMotionScore;
- int RecoveryBlocksAdded ;
- double ProportionRecBlocks;
- double MaxRecFactor ;
-
- /* Rate Targeting variables. */
- ogg_uint32_t ThisFrameTargetBytes;
- double BpbCorrectionFactor;
-
- /* Up regulation variables */
- ogg_uint32_t FinalPassLastPos; /* Used to regulate a final
- unrestricted high quality
- pass. */
- ogg_uint32_t LastEndSB; /* Where we were in the loop
- last time. */
- ogg_uint32_t ResidueLastEndSB; /* Where we were in the residue
- update loop last time. */
-
/* Controlling Block Selection */
ogg_uint32_t MVChangeFactor;
ogg_uint32_t FourMvChangeFactor;
@@ -602,17 +366,9 @@
ogg_uint32_t MinImprovementForFourMV;
ogg_uint32_t FourMVThreshold;
- /* Module shared data structures. */
- ogg_int32_t frame_target_rate;
- ogg_int32_t BaseLineFrameTargetRate;
- ogg_int32_t min_blocks_per_frame;
- ogg_uint32_t tot_bytes_old;
-
+ /*********************************************************************/
+ unsigned char *yuvptr;
/*********************************************************************/
- /* Frames Used in the selecetive convolution filtering of the Y plane. */
- YUV_BUFFER_ENTRY *yuv0ptr;
- YUV_BUFFER_ENTRY *yuv1ptr;
- /*********************************************************************/
/*********************************************************************/
/* Token Buffers */
@@ -635,7 +391,6 @@
ogg_int32_t TokensToBeCoded;
ogg_int32_t TokensCoded;
/********************************************************************/
-
/* SuperBlock, MacroBLock and Fragment Information */
/* Coded flag arrays and counters for them */
unsigned char *PartiallyCodedFlags;
@@ -665,11 +420,8 @@
/*********************************************************************/
ogg_uint32_t RunLength;
- double BitRateCapFactor; /* Factor relating delta frame target
- to cut off target. */
+ unsigned char MBCodingMode;
- unsigned char MBCodingMode; /* Coding mode flags */
-
ogg_int32_t MVPixelOffsetY[MAX_SEARCH_SITES];
ogg_uint32_t InterTripOutThresh;
unsigned char MVEnabled;
@@ -683,26 +435,12 @@
signed char HalfPixelXOffset[9]; /* Half pixel MV offsets for X */
signed char HalfPixelYOffset[9]; /* Half pixel MV offsets for Y */
- ogg_uint32_t bit_pattern ;
- unsigned char bits_so_far ;
- ogg_uint32_t lastval ;
- ogg_uint32_t lastrun ;
-
- Q_LIST_ENTRY *quantized_list;
-
MOTION_VECTOR MVector;
- ogg_uint32_t TempBitCount;
ogg_int16_t *DCT_codes; /* Buffer that stores the result of
Forward DCT */
ogg_int16_t *DCTDataBuffer; /* Input data buffer for Forward DCT */
- /* Motion compensation related variables */
- ogg_uint32_t MvMaxExtent;
-
- double QTargetModifier[Q_TABLE_SIZE];
-
/* instances (used for reconstructing buffers and to hold tokens etc.) */
- PP_INSTANCE pp; /* preprocessor */
PB_INSTANCE pb; /* playback */
/* ogg bitpacker for use in packet coding, other API state */
@@ -720,16 +458,10 @@
#define clamp255(x) ((unsigned char)((((x)<0)-1) & ((x) | -((x)>255))))
-extern void ConfigurePP( PP_INSTANCE *ppi, int Level ) ;
-extern ogg_uint32_t YUVAnalyseFrame( PP_INSTANCE *ppi,
- ogg_uint32_t * KFIndicator );
-
-extern void ClearPPInstance(PP_INSTANCE *ppi);
-extern void InitPPInstance(PP_INSTANCE *ppi, DspFunctions *funcs);
extern void InitPBInstance(PB_INSTANCE *pbi);
extern void ClearPBInstance(PB_INSTANCE *pbi);
-extern void IDct1( Q_LIST_ENTRY * InputData,
+extern void IDct1( ogg_int16_t * InputData,
ogg_int16_t *QuantMatrix,
ogg_int16_t * OutputData );
@@ -752,16 +484,15 @@
unsigned int srcstride);
extern void LoopFilter(PB_INSTANCE *pbi);
extern void ReconRefFrames (PB_INSTANCE *pbi);
-extern void ExpandToken( Q_LIST_ENTRY * ExpandedBlock,
+extern void ExpandToken( ogg_int16_t * ExpandedBlock,
unsigned char * CoeffIndex, ogg_uint32_t Token,
ogg_int32_t ExtraBits );
-extern void ClearDownQFragData(PB_INSTANCE *pbi);
extern void select_quantiser (PB_INSTANCE *pbi, int type);
extern void quantize( PB_INSTANCE *pbi,
ogg_int16_t * DCT_block,
- Q_LIST_ENTRY * quantized_list);
+ 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 );
@@ -833,18 +564,11 @@
ogg_uint32_t YSuperBlocks,
ogg_uint32_t UVSuperBlocks,
ogg_uint32_t HFrags, ogg_uint32_t VFrags );
-extern void UpRegulateDataStream (CP_INSTANCE *cpi, ogg_uint32_t RegulationQ,
- ogg_int32_t RecoveryBlocks ) ;
-extern void RegulateQ( CP_INSTANCE *cpi, ogg_int32_t UpdateScore );
extern void UpdateUMVBorder( PB_INSTANCE *pbi,
unsigned char * DestReconPtr );
-extern void PInitFrameInfo(PP_INSTANCE * ppi);
-extern double GetEstimatedBpb( CP_INSTANCE *cpi, ogg_uint32_t TargetQ );
extern void ClearTmpBuffers(PB_INSTANCE * pbi);
extern void InitTmpBuffers(PB_INSTANCE * pbi);
-extern void ScanYUVInit( PP_INSTANCE * ppi,
- SCAN_CONFIG_DATA * ScanConfigPtr);
#endif /* ENCODER_INTERNAL_H */
Modified: branches/theora-thusnelda/lib/enc/dct_encode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/dct_encode.c 2007-11-20 02:45:44 UTC (rev 14198)
+++ branches/theora-thusnelda/lib/enc/dct_encode.c 2007-11-20 14:33:26 UTC (rev 14199)
@@ -25,95 +25,72 @@
static unsigned char TokenizeDctValue (ogg_int16_t DataValue,
ogg_uint32_t * TokenListPtr ){
- unsigned char tokens_added = 0;
- ogg_uint32_t AbsDataVal = abs( (ogg_int32_t)DataValue );
-
+ int AbsDataVal = abs(DataValue);
+ int neg = (DataValue<0);
/* Values are tokenised as category value and a number of additional
bits that define the position within the category. */
- if ( DataValue == 0 ) return 0;
+ if ( AbsDataVal == 0 ) return 0;
if ( AbsDataVal == 1 ){
- if ( DataValue == 1 )
- TokenListPtr[0] = ONE_TOKEN;
- else
- TokenListPtr[0] = MINUS_ONE_TOKEN;
- tokens_added = 1;
+
+ TokenListPtr[0] = (neg ? MINUS_ONE_TOKEN : ONE_TOKEN);
+ return 1;
+
} else if ( AbsDataVal == 2 ) {
- if ( DataValue == 2 )
- TokenListPtr[0] = TWO_TOKEN;
- else
- TokenListPtr[0] = MINUS_TWO_TOKEN;
- tokens_added = 1;
+
+ TokenListPtr[0] = (neg ? MINUS_TWO_TOKEN : TWO_TOKEN);
+ return 1;
+
} else if ( AbsDataVal <= MAX_SINGLE_TOKEN_VALUE ) {
+
TokenListPtr[0] = LOW_VAL_TOKENS + (AbsDataVal - DCT_VAL_CAT2_MIN);
- if ( DataValue > 0 )
- TokenListPtr[1] = 0;
- else
- TokenListPtr[1] = 1;
- tokens_added = 2;
+ TokenListPtr[1] = neg;
+ return 2;
+
} else if ( AbsDataVal <= 8 ) {
+
/* Bit 1 determines sign, Bit 0 the value */
TokenListPtr[0] = DCT_VAL_CATEGORY3;
- if ( DataValue > 0 )
- TokenListPtr[1] = (AbsDataVal - DCT_VAL_CAT3_MIN);
- else
- TokenListPtr[1] = (0x02) + (AbsDataVal - DCT_VAL_CAT3_MIN);
- tokens_added = 2;
+ TokenListPtr[1] = (AbsDataVal - DCT_VAL_CAT3_MIN) + (neg << 1);
+ return 2;
+
} else if ( AbsDataVal <= 12 ) {
+
/* Bit 2 determines sign, Bit 0-2 the value */
TokenListPtr[0] = DCT_VAL_CATEGORY4;
- if ( DataValue > 0 )
- TokenListPtr[1] = (AbsDataVal - DCT_VAL_CAT4_MIN);
- else
- TokenListPtr[1] = (0x04) + (AbsDataVal - DCT_VAL_CAT4_MIN);
- tokens_added = 2;
+ TokenListPtr[1] = (AbsDataVal - DCT_VAL_CAT4_MIN) + (neg << 2);
+ return 2;
+
} else if ( AbsDataVal <= 20 ) {
+
/* Bit 3 determines sign, Bit 0-2 the value */
TokenListPtr[0] = DCT_VAL_CATEGORY5;
- if ( DataValue > 0 )
- TokenListPtr[1] = (AbsDataVal - DCT_VAL_CAT5_MIN);
- else
- TokenListPtr[1] = (0x08) + (AbsDataVal - DCT_VAL_CAT5_MIN);
- tokens_added = 2;
+ TokenListPtr[1] = (AbsDataVal - DCT_VAL_CAT5_MIN) + (neg << 3);
+ return 2;
+
} else if ( AbsDataVal <= 36 ) {
+
/* Bit 4 determines sign, Bit 0-3 the value */
TokenListPtr[0] = DCT_VAL_CATEGORY6;
- if ( DataValue > 0 )
- TokenListPtr[1] = (AbsDataVal - DCT_VAL_CAT6_MIN);
- else
- TokenListPtr[1] = (0x010) + (AbsDataVal - DCT_VAL_CAT6_MIN);
- tokens_added = 2;
+ TokenListPtr[1] = (AbsDataVal - DCT_VAL_CAT6_MIN) + (neg << 4);
+ return 2;
+
} else if ( AbsDataVal <= 68 ) {
+
/* Bit 5 determines sign, Bit 0-4 the value */
TokenListPtr[0] = DCT_VAL_CATEGORY7;
- if ( DataValue > 0 )
- TokenListPtr[1] = (AbsDataVal - DCT_VAL_CAT7_MIN);
- else
- TokenListPtr[1] = (0x20) + (AbsDataVal - DCT_VAL_CAT7_MIN);
- tokens_added = 2;
- } else if ( AbsDataVal <= 511 ) {
+ TokenListPtr[1] = (AbsDataVal - DCT_VAL_CAT7_MIN) + (neg << 5);
+ return 2;
+
+ } else {
+
/* Bit 9 determines sign, Bit 0-8 the value */
TokenListPtr[0] = DCT_VAL_CATEGORY8;
- if ( DataValue > 0 )
- TokenListPtr[1] = (AbsDataVal - DCT_VAL_CAT8_MIN);
- else
- TokenListPtr[1] = (0x200) + (AbsDataVal - DCT_VAL_CAT8_MIN);
- tokens_added = 2;
- } else {
- TokenListPtr[0] = DCT_VAL_CATEGORY8;
- if ( DataValue > 0 ){
- TokenListPtr[1] = (511 - DCT_VAL_CAT8_MIN);
- fprintf(stderr,"OVERFLOW \n");
- }else{
- TokenListPtr[1] = (0x200) + (511 - DCT_VAL_CAT8_MIN);
- fprintf(stderr,"OVERFLOW \n");
- }
- tokens_added = 2;
- }
+ TokenListPtr[1] = (AbsDataVal - DCT_VAL_CAT8_MIN) + (neg <<9 );
+ return 2;
- /* Return the total number of tokens added */
- return tokens_added;
+ }
}
static unsigned char TokenizeDctRunValue (unsigned char RunLength,
@@ -273,7 +250,7 @@
return BLOCK_SIZE;
}
-static int AllZeroDctData( Q_LIST_ENTRY * QuantList ){
+static int AllZeroDctData( ogg_int16_t * QuantList ){
ogg_uint32_t i;
for ( i = 0; i < 64; i ++ )
@@ -418,7 +395,7 @@
}
/* adjusted / filtered pointers */
- FiltPtr = &cpi->yuv1ptr[cpi->pb.pixel_index_table[FragIndex]];
+ FiltPtr = &cpi->yuvptr[cpi->pb.pixel_index_table[FragIndex]];
if ( cpi->pb.FrameType == KEY_FRAME ) {
/* Key frame so code block in INTRA mode. */
Modified: branches/theora-thusnelda/lib/enc/encode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/encode.c 2007-11-20 02:45:44 UTC (rev 14198)
+++ branches/theora-thusnelda/lib/enc/encode.c 2007-11-20 14:33:26 UTC (rev 14199)
@@ -758,7 +758,6 @@
int FragsAcross=cpi->pb.HFragments;
int FragsDown = cpi->pb.VFragments;
int FromFragment,ToFragment;
- ogg_int32_t FragIndex;
int WhichFrame;
int WhichCase;
@@ -934,8 +933,6 @@
/* Reconstruct the reference frames */
ReconRefFrames(&cpi->pb);
- UpdateFragQIndex(&cpi->pb);
-
/* Return total number of coded pixels */
return coded_pixels;
}
@@ -1208,19 +1205,19 @@
BestError = (BestError > MBIntraError) ? MBIntraError : BestError;
/* Get the golden frame error */
- MBGFError = GetMBInterError( cpi, cpi->yuv1ptr,
+ MBGFError = GetMBInterError( cpi, cpi->yuvptr,
cpi->pb.GoldenFrame, YFragIndex,
0, 0, PixelsPerLine );
BestError = (BestError > MBGFError) ? MBGFError : BestError;
/* Calculate the 0,0 case. */
- MBInterError = GetMBInterError( cpi, cpi->yuv1ptr,
+ MBInterError = GetMBInterError( cpi, cpi->yuvptr,
cpi->pb.LastFrameRecon,
YFragIndex, 0, 0, PixelsPerLine );
BestError = (BestError > MBInterError) ? MBInterError : BestError;
/* Measure error for last MV */
- MBLastInterError = GetMBInterError( cpi, cpi->yuv1ptr,
+ MBLastInterError = GetMBInterError( cpi, cpi->yuvptr,
cpi->pb.LastFrameRecon,
YFragIndex, LastInterMVect.x,
LastInterMVect.y, PixelsPerLine );
@@ -1228,7 +1225,7 @@
MBLastInterError : BestError;
/* Measure error for prior last MV */
- MBPriorLastInterError = GetMBInterError( cpi, cpi->yuv1ptr,
+ MBPriorLastInterError = GetMBInterError( cpi, cpi->yuvptr,
cpi->pb.LastFrameRecon,
YFragIndex,
PriorLastInterMVect.x,
@@ -1300,7 +1297,7 @@
cpi->MVPixelOffsetY, &GFMVect );
/* Measure error for last GFMV */
- LastMBGF_MVError = GetMBInterError( cpi, cpi->yuv1ptr,
+ LastMBGF_MVError = GetMBInterError( cpi, cpi->yuvptr,
cpi->pb.GoldenFrame,
YFragIndex, LastGFMVect.x,
LastGFMVect.y, PixelsPerLine );
Modified: branches/theora-thusnelda/lib/enc/encoder_huffman.c
===================================================================
--- branches/theora-thusnelda/lib/enc/encoder_huffman.c 2007-11-20 02:45:44 UTC (rev 14198)
+++ branches/theora-thusnelda/lib/enc/encoder_huffman.c 2007-11-20 14:33:26 UTC (rev 14199)
@@ -223,43 +223,6 @@
}
}
-static int ReadHuffTree(HUFF_ENTRY * HuffRoot, int depth,
- oggpack_buffer *opb) {
- long bit;
- long ret;
- theora_read(opb,1,&bit);
- if(bit < 0) return OC_BADHEADER;
- else if(!bit) {
- int ret;
- if (++depth > 32) return OC_BADHEADER;
- HuffRoot->ZeroChild = (HUFF_ENTRY *)_ogg_calloc(1, sizeof(HUFF_ENTRY));
- ret = ReadHuffTree(HuffRoot->ZeroChild, depth, opb);
- if (ret < 0) return ret;
- HuffRoot->OneChild = (HUFF_ENTRY *)_ogg_calloc(1, sizeof(HUFF_ENTRY));
- ret = ReadHuffTree(HuffRoot->OneChild, depth, opb);
- if (ret < 0) return ret;
- HuffRoot->Value = -1;
- } else {
- HuffRoot->ZeroChild = NULL;
- HuffRoot->OneChild = NULL;
- theora_read(opb,5,&ret);
- HuffRoot->Value=ret;;
- if (HuffRoot->Value < 0) return OC_BADHEADER;
- }
- return 0;
-}
-
-int ReadHuffmanTrees(codec_setup_info *ci, oggpack_buffer *opb) {
- int i;
- for (i=0; i<NUM_HUFF_TABLES; i++) {
- int ret;
- ci->HuffRoot[i] = (HUFF_ENTRY *)_ogg_calloc(1, sizeof(HUFF_ENTRY));
- ret = ReadHuffTree(ci->HuffRoot[i], 0, opb);
- if (ret) return ret;
- }
- return 0;
-}
-
static void WriteHuffTree(HUFF_ENTRY *HuffRoot, oggpack_buffer *opb) {
if (HuffRoot->Value >= 0) {
oggpackB_write(opb, 1, 1);
Modified: branches/theora-thusnelda/lib/enc/encoder_idct.c
===================================================================
--- branches/theora-thusnelda/lib/enc/encoder_idct.c 2007-11-20 02:45:44 UTC (rev 14198)
+++ branches/theora-thusnelda/lib/enc/encoder_idct.c 2007-11-20 14:33:26 UTC (rev 14199)
@@ -121,7 +121,7 @@
-void IDctSlow__c( Q_LIST_ENTRY * InputData,
+void IDctSlow__c( ogg_int16_t * InputData,
ogg_int16_t *QuantMatrix,
ogg_int16_t * OutputData ) {
ogg_int32_t IntermediateData[64];
@@ -350,7 +350,7 @@
}
-void IDct10__c( Q_LIST_ENTRY * InputData,
+void IDct10__c( ogg_int16_t * InputData,
ogg_int16_t *QuantMatrix,
ogg_int16_t * OutputData ){
ogg_int32_t IntermediateData[64];
@@ -542,7 +542,7 @@
0 0 0 0 0 0 0 0
**************************/
-void IDct1( Q_LIST_ENTRY * InputData,
+void IDct1( ogg_int16_t * InputData,
ogg_int16_t *QuantMatrix,
ogg_int16_t * OutputData ){
int loop;
Modified: branches/theora-thusnelda/lib/enc/encoder_quant.c
===================================================================
--- branches/theora-thusnelda/lib/enc/encoder_quant.c 2007-11-20 02:45:44 UTC (rev 14198)
+++ branches/theora-thusnelda/lib/enc/encoder_quant.c 2007-11-20 14:33:26 UTC (rev 14199)
@@ -501,9 +501,9 @@
void quantize( PB_INSTANCE *pbi,
ogg_int16_t * DCT_block,
- Q_LIST_ENTRY * quantized_list){
+ ogg_int16_t * quantized_list){
ogg_uint32_t i; /* Row index */
- Q_LIST_ENTRY val; /* Quantised value. */
+ ogg_int16_t val; /* Quantised value. */
ogg_int32_t * FquantRoundPtr = pbi->fquant_round;
ogg_int32_t * FquantCoeffsPtr = pbi->fquant_coeffs;
@@ -513,7 +513,7 @@
ogg_int32_t temp;
/* Set the quantized_list to default to 0 */
- memset( quantized_list, 0, 64 * sizeof(Q_LIST_ENTRY) );
+ 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++) {
@@ -523,12 +523,12 @@
for( col = 0; col < 8; col++) {
if ( DCT_blockPtr[col] >= FquantZBinSizePtr[col] ) {
temp = FquantCoeffsPtr[col] * ( DCT_blockPtr[col] + FquantRoundPtr[col] ) ;
- val = (Q_LIST_ENTRY) (temp>>16);
+ 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 = (Q_LIST_ENTRY) (temp>>16);
+ val = (temp>>16);
quantized_list[ZigZagPtr[col]] = ( val < -511 ) ? -511 : val;
}
}
Modified: branches/theora-thusnelda/lib/enc/encoder_toplevel.c
===================================================================
--- branches/theora-thusnelda/lib/enc/encoder_toplevel.c 2007-11-20 02:45:44 UTC (rev 14198)
+++ branches/theora-thusnelda/lib/enc/encoder_toplevel.c 2007-11-20 14:33:26 UTC (rev 14199)
@@ -31,13 +31,6 @@
long dframe=0;
#endif
-#define A_TABLE_SIZE 29
-#define DF_CANDIDATE_WINDOW 5
-
-/*
- * th_quant_info for VP3
- */
-
/*The default quantization parameters used by VP3.1.*/
static const int OC_VP31_RANGE_SIZES[1]={63};
static const th_quant_base OC_VP31_BASES_INTRA_Y[2]={
@@ -154,8 +147,6 @@
static void EClearFragmentInfo(CP_INSTANCE * cpi){
- if(cpi->FragmentLastQ)
- _ogg_free(cpi->FragmentLastQ);
if(cpi->FragTokens)
_ogg_free(cpi->FragTokens);
if(cpi->FragTokenCounts)
@@ -170,8 +161,6 @@
_ogg_free( cpi->DCT_codes );
if(cpi->DCTDataBuffer )
_ogg_free( cpi->DCTDataBuffer);
- if(cpi->quantized_list)
- _ogg_free( cpi->quantized_list);
if(cpi->PredictedDC)
_ogg_free( cpi->PredictedDC);
if(cpi->PartiallyCodedFlags)
@@ -184,7 +173,6 @@
if(cpi->BlockCodedFlags)
_ogg_free(cpi->BlockCodedFlags);
- cpi->FragmentLastQ = 0;
cpi->FragTokens = 0;
cpi->FragTokenCounts = 0;
cpi->RunHuffIndices = 0;
@@ -192,7 +180,6 @@
cpi->MVList = 0;
cpi->DCT_codes = 0;
cpi->DCTDataBuffer = 0;
- cpi->quantized_list = 0;
cpi->PredictedDC = 0;
cpi->BlockCodedFlags = 0;
}
@@ -223,9 +210,6 @@
SEGV handler, there's no reason to to check malloc return; it is
a waste of code. */
- cpi->FragmentLastQ =
- _ogg_malloc(cpi->pb.UnitFragments*
- sizeof(*cpi->FragmentLastQ));
cpi->FragTokens =
_ogg_malloc(cpi->pb.UnitFragments*
sizeof(*cpi->FragTokens));
@@ -253,9 +237,6 @@
cpi->DCTDataBuffer =
_ogg_malloc(64*
sizeof(*cpi->DCTDataBuffer));
- cpi->quantized_list =
- _ogg_malloc(64*
- sizeof(*cpi->quantized_list));
cpi->PartiallyCodedFlags =
_ogg_malloc(cpi->pb.MacroBlocks*
sizeof(*cpi->PartiallyCodedFlags));
@@ -270,14 +251,10 @@
static void EClearFrameInfo(CP_INSTANCE * cpi) {
- if(cpi->yuv0ptr)
- _ogg_free(cpi->yuv0ptr);
- cpi->yuv0ptr = 0;
+ if(cpi->yuvptr)
+ _ogg_free(cpi->yuvptr);
+ cpi->yuvptr = 0;
- if(cpi->yuv1ptr)
- _ogg_free(cpi->yuv1ptr);
- cpi->yuv1ptr = 0;
-
if(cpi->OptimisedTokenListEb )
_ogg_free(cpi->OptimisedTokenListEb);
cpi->OptimisedTokenListEb = 0;
@@ -303,12 +280,9 @@
EClearFrameInfo(cpi);
/* allocate frames */
- cpi->yuv0ptr =
+ cpi->yuvptr =
_ogg_malloc(FrameSize*
- sizeof(*cpi->yuv0ptr));
- cpi->yuv1ptr =
- _ogg_malloc(FrameSize*
- sizeof(*cpi->yuv1ptr));
+ sizeof(*cpi->yuvptr));
cpi->OptimisedTokenListEb =
_ogg_malloc(FrameSize*
sizeof(*cpi->OptimisedTokenListEb));
@@ -324,11 +298,6 @@
}
static void SetupKeyFrame(CP_INSTANCE *cpi) {
- /* Make sure the "last frame" buffer contains the first frame data
- as well. */
- memcpy ( cpi->yuv0ptr, cpi->yuv1ptr,
- cpi->pb.ReconYPlaneSize + 2 * cpi->pb.ReconUVPlaneSize );
-
/* Initialise the cpi->pb.display_fragments and other fragment
structures for the first frame. */
memset( cpi->pb.display_fragments, 1, cpi->pb.UnitFragments );
@@ -338,79 +307,15 @@
}
static void AdjustKeyFrameContext(CP_INSTANCE *cpi) {
- ogg_uint32_t i;
- ogg_uint32_t AvKeyFrameFrequency =
- (ogg_uint32_t) (cpi->CurrentFrame / cpi->KeyFrameCount);
- ogg_uint32_t AvKeyFrameBytes =
- (ogg_uint32_t) (cpi->TotKeyFrameBytes / cpi->KeyFrameCount);
- ogg_uint32_t TotalWeight=0;
- ogg_int32_t AvKeyFramesPerSecond;
- ogg_int32_t MinFrameTargetRate;
/* Update the frame carry over. */
cpi->TotKeyFrameBytes += oggpackB_bytes(cpi->oggbuffer);
- /* reset keyframe context and calculate weighted average of last
- KEY_FRAME_CONTEXT keyframes */
- for( i = 0 ; i < KEY_FRAME_CONTEXT ; i ++ ) {
- if ( i < KEY_FRAME_CONTEXT -1) {
- cpi->PriorKeyFrameSize[i] = cpi->PriorKeyFrameSize[i+1];
- cpi->PriorKeyFrameDistance[i] = cpi->PriorKeyFrameDistance[i+1];
- } else {
- cpi->PriorKeyFrameSize[KEY_FRAME_CONTEXT - 1] =
- oggpackB_bytes(cpi->oggbuffer);
- cpi->PriorKeyFrameDistance[KEY_FRAME_CONTEXT - 1] =
- cpi->LastKeyFrame;
- }
-
- AvKeyFrameBytes += PriorKeyFrameWeight[i] *
- cpi->PriorKeyFrameSize[i];
- AvKeyFrameFrequency += PriorKeyFrameWeight[i] *
- cpi->PriorKeyFrameDistance[i];
- TotalWeight += PriorKeyFrameWeight[i];
- }
- AvKeyFrameBytes /= TotalWeight;
- AvKeyFrameFrequency /= TotalWeight;
- AvKeyFramesPerSecond = 100 * cpi->Configuration.OutputFrameRate /
- AvKeyFrameFrequency ;
-
- /* Calculate a new target rate per frame allowing for average key
- frame frequency over newest frames . */
- if ( 100 * cpi->Configuration.TargetBandwidth >
- AvKeyFrameBytes * AvKeyFramesPerSecond &&
- (100 * cpi->Configuration.OutputFrameRate - AvKeyFramesPerSecond )){
- cpi->frame_target_rate =
- (ogg_int32_t)(100* cpi->Configuration.TargetBandwidth -
- AvKeyFrameBytes * AvKeyFramesPerSecond ) /
- ( (100 * cpi->Configuration.OutputFrameRate - AvKeyFramesPerSecond ) );
- } else {
- /* don't let this number get too small!!! */
- cpi->frame_target_rate = 1;
- }
-
- /* minimum allowable frame_target_rate */
- MinFrameTargetRate = (cpi->Configuration.TargetBandwidth /
- cpi->Configuration.OutputFrameRate) / 3;
-
- if(cpi->frame_target_rate < MinFrameTargetRate ) {
- cpi->frame_target_rate = MinFrameTargetRate;
- }
-
cpi->LastKeyFrame = 1;
- cpi->LastKeyFrameSize=oggpackB_bytes(cpi->oggbuffer);
-
}
static void UpdateFrame(CP_INSTANCE *cpi){
- double CorrectionFactor;
-
- /* Reset the DC predictors. */
- cpi->pb.LastIntraDC = 0;
- cpi->pb.InvLastIntraDC = 0;
- cpi->pb.LastInterDC = 0;
- cpi->pb.InvLastInterDC = 0;
-
/* Initialise bit packing mechanism. */
#ifndef LIBOGG2
oggpackB_reset(cpi->oggbuffer);
@@ -423,206 +328,46 @@
/* Write out the frame header information including size. */
WriteFrameHeader(cpi);
- /* Copy back any extra frags that are to be updated by the codec
- as part of the background cleanup task */
- //CopyBackExtraFrags(cpi);
-
/* Encode the data. */
EncodeData(cpi);
- /* Adjust drop frame trigger. */
- if ( cpi->pb.FrameType != KEY_FRAME ) {
- /* Apply decay factor then add in the last frame size. */
- cpi->DropFrameTriggerBytes =
- ((cpi->DropFrameTriggerBytes * (DF_CANDIDATE_WINDOW-1)) /
- DF_CANDIDATE_WINDOW) + oggpackB_bytes(cpi->oggbuffer);
- }else{
- /* Increase cpi->DropFrameTriggerBytes a little. Just after a key
- frame may actually be a good time to drop a frame. */
- cpi->DropFrameTriggerBytes =
- (cpi->DropFrameTriggerBytes * DF_CANDIDATE_WINDOW) /
- (DF_CANDIDATE_WINDOW-1);
- }
-
- /* Test for overshoot which may require a dropped frame next time
- around. If we are already in a drop frame condition but the
- previous frame was not dropped then the threshold for continuing
- to allow dropped frames is reduced. */
- if ( cpi->DropFrameCandidate ) {
- if ( cpi->DropFrameTriggerBytes >
- (cpi->frame_target_rate * (DF_CANDIDATE_WINDOW+1)) )
- cpi->DropFrameCandidate = 1;
- else
- cpi->DropFrameCandidate = 0;
- } else {
- if ( cpi->DropFrameTriggerBytes >
- (cpi->frame_target_rate * ((DF_CANDIDATE_WINDOW*2)-2)) )
- cpi->DropFrameCandidate = 1;
- else
- cpi->DropFrameCandidate = 0;
- }
-
- /* Update the BpbCorrectionFactor variable according to whether or
- not we were close enough with our selection of DCT quantiser. */
- if ( cpi->pb.FrameType != KEY_FRAME ) {
- /* Work out a size correction factor. */
- CorrectionFactor = (double)oggpackB_bytes(cpi->oggbuffer) /
- (double)cpi->ThisFrameTargetBytes;
-
- if ( (CorrectionFactor > 1.05) &&
- (cpi->pb.ThisFrameQualityValue <
- cpi->pb.QThreshTable[cpi->Configuration.ActiveMaxQ]) ) {
- CorrectionFactor = 1.0 + ((CorrectionFactor - 1.0)/2);
- if ( CorrectionFactor > 1.5 )
- cpi->BpbCorrectionFactor *= 1.5;
- else
- cpi->BpbCorrectionFactor *= CorrectionFactor;
-
- /* Keep BpbCorrectionFactor within limits */
- if ( cpi->BpbCorrectionFactor > MAX_BPB_FACTOR )
- cpi->BpbCorrectionFactor = MAX_BPB_FACTOR;
- } else if ( (CorrectionFactor < 0.95) &&
- (cpi->pb.ThisFrameQualityValue > VERY_BEST_Q) ){
- CorrectionFactor = 1.0 - ((1.0 - CorrectionFactor)/2);
- if ( CorrectionFactor < 0.75 )
- cpi->BpbCorrectionFactor *= 0.75;
- else
- cpi->BpbCorrectionFactor *= CorrectionFactor;
-
- /* Keep BpbCorrectionFactor within limits */
- if ( cpi->BpbCorrectionFactor < MIN_BPB_FACTOR )
- cpi->BpbCorrectionFactor = MIN_BPB_FACTOR;
- }
- }
-
- /* Adjust carry over and or key frame context. */
- if ( cpi->pb.FrameType == KEY_FRAME ) {
- /* Adjust the key frame context unless the key frame was very small */
+ if ( cpi->pb.FrameType == KEY_FRAME )
AdjustKeyFrameContext(cpi);
- } else {
- /* Update the frame carry over */
- cpi->CarryOver += ((ogg_int32_t)cpi->frame_target_rate -
- (ogg_int32_t)oggpackB_bytes(cpi->oggbuffer));
- }
- cpi->TotalByteCount += oggpackB_bytes(cpi->oggbuffer);
+
}
static void CompressFirstFrame(CP_INSTANCE *cpi) {
- ogg_uint32_t i;
- /* set up context of key frame sizes and distances for more local
- datarate control */
- for( i = 0 ; i < KEY_FRAME_CONTEXT ; i ++ ) {
- cpi->PriorKeyFrameSize[i] = cpi->Configuration.KeyFrameDataTarget;
- cpi->PriorKeyFrameDistance[i] = cpi->pb.info.keyframe_frequency_force;
- }
-
/* Keep track of the total number of Key Frames Coded. */
cpi->KeyFrameCount = 1;
cpi->LastKeyFrame = 1;
cpi->TotKeyFrameBytes = 0;
- /* A key frame is not a dropped frame there for reset the count of
- consequative dropped frames. */
- cpi->DropCount = 0;
-
SetupKeyFrame(cpi);
- /* Calculate a new target rate per frame allowing for average key
- frame frequency and size thus far. */
- if ( cpi->Configuration.TargetBandwidth >
- ((cpi->Configuration.KeyFrameDataTarget *
- cpi->Configuration.OutputFrameRate)/
- cpi->pb.info.keyframe_frequency) ) {
+ cpi->pb.ThisFrameQualityValue =
+ cpi->pb.quant_info.ac_scale[cpi->Configuration.BaseQ];
- cpi->frame_target_rate =
- (ogg_int32_t)((cpi->Configuration.TargetBandwidth -
- ((cpi->Configuration.KeyFrameDataTarget *
- cpi->Configuration.OutputFrameRate)/
- cpi->pb.info.keyframe_frequency)) /
- cpi->Configuration.OutputFrameRate);
- }else
- cpi->frame_target_rate = 1;
-
- /* Set baseline frame target rate. */
- cpi->BaseLineFrameTargetRate = cpi->frame_target_rate;
-
- /* A key frame is not a dropped frame there for reset the count of
- consequative dropped frames. */
- cpi->DropCount = 0;
-
- /* Initialise drop frame trigger to 5 frames worth of data. */
- cpi->DropFrameTriggerBytes = cpi->frame_target_rate * DF_CANDIDATE_WINDOW;
-
- /* Set a target size for this key frame based upon the baseline
- target and frequency */
- cpi->ThisFrameTargetBytes = cpi->Configuration.KeyFrameDataTarget;
-
- /* Get a DCT quantizer level for the key frame. */
- cpi->MotionScore = cpi->pb.UnitFragments;
-
- RegulateQ(cpi, cpi->pb.UnitFragments);
-
- cpi->pb.LastFrameQualityValue = cpi->pb.ThisFrameQualityValue;
-
/* Initialise quantizer. */
UpdateQC(cpi, cpi->pb.ThisFrameQualityValue );
- /* Initialise the cpi->pb.display_fragments and other fragment
- structures for the first frame. */
- for ( i = 0; i < cpi->pb.UnitFragments; i ++ )
- cpi->FragmentLastQ[i] = cpi->pb.ThisFrameQualityValue;
-
/* Compress and output the frist frame. */
PickIntra( cpi,
cpi->pb.YSBRows, cpi->pb.YSBCols);
UpdateFrame(cpi);
- /* Initialise the carry over rate targeting variables. */
- cpi->CarryOver = 0;
-
}
static void CompressKeyFrame(CP_INSTANCE *cpi){
- ogg_uint32_t i;
- /* Before we compress reset the carry over to the actual frame carry over */
- cpi->CarryOver = cpi->Configuration.TargetBandwidth * cpi->CurrentFrame /
- cpi->Configuration.OutputFrameRate - cpi->TotalByteCount;
-
/* Keep track of the total number of Key Frames Coded */
cpi->KeyFrameCount += 1;
- /* A key frame is not a dropped frame there for reset the count of
- consequative dropped frames. */
- cpi->DropCount = 0;
-
SetupKeyFrame(cpi);
- /* set a target size for this frame */
- cpi->ThisFrameTargetBytes = (ogg_int32_t) cpi->frame_target_rate +
- ( (cpi->Configuration.KeyFrameDataTarget - cpi->frame_target_rate) *
- cpi->LastKeyFrame / cpi->pb.info.keyframe_frequency_force );
-
- if ( cpi->ThisFrameTargetBytes > cpi->Configuration.KeyFrameDataTarget )
- cpi->ThisFrameTargetBytes = cpi->Configuration.KeyFrameDataTarget;
-
- /* Get a DCT quantizer level for the key frame. */
- cpi->MotionScore = cpi->pb.UnitFragments;
-
- RegulateQ(cpi, cpi->pb.UnitFragments);
-
- cpi->pb.LastFrameQualityValue = cpi->pb.ThisFrameQualityValue;
-
/* Initialise DCT tables. */
UpdateQC(cpi, cpi->pb.ThisFrameQualityValue );
- /* Initialise the cpi->pb.display_fragments and other fragment
- structures for the first frame. */
- for ( i = 0; i < cpi->pb.UnitFragments; i ++ )
- cpi->FragmentLastQ[i] = cpi->pb.ThisFrameQualityValue;
-
-
/* Compress and output the frist frame. */
PickIntra( cpi,
cpi->pb.YSBRows, cpi->pb.YSBCols);
@@ -631,14 +376,9 @@
}
static int CompressFrame( CP_INSTANCE *cpi) {
- ogg_int32_t min_blocks_per_frame;
ogg_uint32_t i;
- int DropFrame = 0;
ogg_uint32_t KFIndicator = 0;
- double QModStep;
- double QModifier = 1.0;
-
/* Clear down the macro block level mode and MV arrays. */
for ( i = 0; i < cpi->pb.UnitFragments; i++ ) {
cpi->pb.FragCodingMethod[i] = CODE_INTER_NO_MV; /* Default coding mode */
@@ -652,150 +392,16 @@
/* Clear down the difference arrays for the current frame. */
memset( cpi->pb.display_fragments, 0, cpi->pb.UnitFragments );
- /* Calculate the target bytes for this frame. */
- cpi->ThisFrameTargetBytes = cpi->frame_target_rate;
-
- /* Correct target to try and compensate for any overall rate error
- that is developing */
-
- /* Set the max allowed Q for this frame based upon carry over
- history. First set baseline worst Q for this frame */
- cpi->Configuration.ActiveMaxQ = cpi->Configuration.MaxQ + 10;
- if ( cpi->Configuration.ActiveMaxQ >= Q_TABLE_SIZE )
- cpi->Configuration.ActiveMaxQ = Q_TABLE_SIZE - 1;
-
- /* Make a further adjustment based upon the carry over and recent
- history.. cpi->Configuration.ActiveMaxQ reduced by 1 for each 1/2
- seconds worth of -ve carry over up to a limit of 6. Also
- cpi->Configuration.ActiveMaxQ reduced if frame is a
- "DropFrameCandidate". Remember that if we are behind the bit
- target carry over is -ve. */
- if ( cpi->CarryOver < 0 ) {
- if ( cpi->DropFrameCandidate ) {
- cpi->Configuration.ActiveMaxQ -= 4;
- }
-
- if ( cpi->CarryOver <
- -((ogg_int32_t)cpi->Configuration.TargetBandwidth*3) )
- cpi->Configuration.ActiveMaxQ -= 6;
- else
- cpi->Configuration.ActiveMaxQ +=
- (ogg_int32_t) ((cpi->CarryOver*2) /
- (ogg_int32_t)cpi->Configuration.TargetBandwidth);
-
- /* Check that we have not dropped quality too far */
- if ( cpi->Configuration.ActiveMaxQ < cpi->Configuration.MaxQ )
- cpi->Configuration.ActiveMaxQ = cpi->Configuration.MaxQ;
- }
-
- /* Calculate the Q Modifier step size required to cause a step down
- from full target bandwidth to 40% of target between max Q and
- best Q */
- QModStep = 0.5 / (double)((Q_TABLE_SIZE - 1) -
- cpi->Configuration.ActiveMaxQ);
-
- /* Set up the cpi->QTargetModifier[] table. */
- for ( i = 0; i < cpi->Configuration.ActiveMaxQ; i++ ) {
- cpi->QTargetModifier[i] = QModifier;
- }
- for ( i = cpi->Configuration.ActiveMaxQ; i < Q_TABLE_SIZE; i++ ) {
- cpi->QTargetModifier[i] = QModifier;
- QModifier -= QModStep;
- }
-
- /* if we are allowed to drop frames and are falling behind (eg more
- than x frames worth of bandwidth) */
- if ( cpi->pb.info.dropframes_p &&
- ( cpi->DropCount < cpi->MaxConsDroppedFrames) &&
- ( cpi->CarryOver <
- -((ogg_int32_t)cpi->Configuration.TargetBandwidth)) &&
- ( cpi->DropFrameCandidate) ) {
- /* (we didn't do this frame so we should have some left over for
- the next frame) */
- cpi->CarryOver += cpi->frame_target_rate;
- DropFrame = 1;
- cpi->DropCount ++;
-
- /* Adjust DropFrameTriggerBytes to account for the saving achieved. */
- cpi->DropFrameTriggerBytes =
- (cpi->DropFrameTriggerBytes *
- (DF_CANDIDATE_WINDOW-1))/DF_CANDIDATE_WINDOW;
-
- /* Even if we drop a frame we should account for it when
- considering key frame seperation. */
- cpi->LastKeyFrame++;
- } else if ( cpi->CarryOver <
- -((ogg_int32_t)cpi->Configuration.TargetBandwidth * 2) ) {
- /* Reduce frame bit target by 1.75% for each 1/10th of a seconds
- worth of -ve carry over down to a minimum of 65% of its
- un-modified value. */
-
- cpi->ThisFrameTargetBytes =
- (ogg_uint32_t)(cpi->ThisFrameTargetBytes * 0.65);
- } else if ( cpi->CarryOver < 0 ) {
- /* Note that cpi->CarryOver is a -ve here hence 1.0 "+" ... */
- cpi->ThisFrameTargetBytes =
- (ogg_uint32_t)(cpi->ThisFrameTargetBytes *
- (1.0 + ( ((cpi->CarryOver * 10)/
- ((ogg_int32_t)cpi->
- Configuration.TargetBandwidth)) * 0.0175) ));
- }
-
- if ( !DropFrame ) {
+ {
/* pick all the macroblock modes and motion vectors */
ogg_uint32_t InterError;
ogg_uint32_t IntraError;
+
+ /* for now, mark all blocks to be coded... */
+ for(i=0;i<cpi->pb.UnitFragments;i++)
+ cpi->pb.display_fragments[i]=1;
- /* Set Baseline filter level. */
- ConfigurePP( &cpi->pp, cpi->pb.info.noise_sensitivity);
-
- /* Score / analyses the fragments. */
- cpi->MotionScore = YUVAnalyseFrame(&cpi->pp, &KFIndicator );
-
- /* Get the baseline Q value */
- RegulateQ( cpi, cpi->MotionScore );
-
- /* Estimate the min number of blocks at best Q */
- min_blocks_per_frame =
- (ogg_int32_t)(cpi->ThisFrameTargetBytes /
- GetEstimatedBpb( cpi, VERY_BEST_Q ));
- if ( min_blocks_per_frame == 0 )
- min_blocks_per_frame = 1;
-
- /* If we have less than this number then consider adding in some
- extra blocks */
- if ( cpi->MotionScore < min_blocks_per_frame ) {
- min_blocks_per_frame =
- cpi->MotionScore +
- (ogg_int32_t)(((min_blocks_per_frame - cpi->MotionScore) * 4) / 3 );
- UpRegulateDataStream( cpi, VERY_BEST_Q, min_blocks_per_frame );
- }else{
- /* Reset control variable for best quality final pass. */
- cpi->FinalPassLastPos = 0;
- }
-
- /* Get the modified Q prediction taking into account extra blocks added. */
- RegulateQ( cpi, cpi->MotionScore );
-
- /* Unless we are already well ahead (4 seconds of data) of the
- projected bitrate */
- if ( cpi->CarryOver <
- (ogg_int32_t)(cpi->Configuration.TargetBandwidth * 4) ){
- /* Look at the predicted Q (pbi->FrameQIndex). Adjust the
- target bits for this frame based upon projected Q and
- re-calculate. The idea is that if the Q is better than a
- given (good enough) level then we will try and save some bits
- for use in more difficult segments. */
- cpi->ThisFrameTargetBytes =
- (ogg_int32_t) (cpi->ThisFrameTargetBytes *
- cpi->QTargetModifier[cpi->pb.FrameQIndex]);
-
- /* Recalculate Q again */
- RegulateQ( cpi, cpi->MotionScore );
- }
-
-
/* 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,
@@ -821,25 +427,10 @@
/* Proceed with the frame update. */
UpdateFrame(cpi);
- cpi->DropCount = 0;
- if ( cpi->MotionScore > 0 ){
- /* Note the Quantizer used for each block coded. */
- for ( i = 0; i < cpi->pb.UnitFragments; i++ ){
- if ( cpi->pb.display_fragments[i] ){
- cpi->FragmentLastQ[i] = cpi->pb.ThisFrameQualityValue;
- }
- }
-
- }
- }else{
- /* even if we 'drop' a frame, a placeholder must be written as we
- currently assume fixed frame rate timebase as Ogg mapping
- invariant */
- UpdateFrame(cpi);
}
- return DropFrame;
+ return 0;
}
/********************** The toplevel: encode ***********************/
@@ -856,8 +447,6 @@
static void theora_encode_dispatch_init(CP_INSTANCE *cpi);
int theora_encode_init(theora_state *th, theora_info *c){
- int i;
-
CP_INSTANCE *cpi;
#ifdef _TH_DEBUG_
@@ -878,7 +467,6 @@
c->version_subminor=TH_VERSION_SUB;
InitTmpBuffers(&cpi->pb);
- InitPPInstance(&cpi->pp, &cpi->dsp);
/* Initialise Configuration structure to legal values */
if(c->quality>63)c->quality=63;
@@ -897,16 +485,12 @@
cpi->ExhaustiveSearchThresh = 2500;
cpi->MinImprovementForFourMV = 100;
cpi->FourMVThreshold = 10000;
- cpi->BitRateCapFactor = 1.5;
cpi->InterTripOutThresh = 5000;
cpi->MVEnabled = 1;
cpi->InterCodeCount = 127;
- cpi->BpbCorrectionFactor = 1.0;
cpi->GoldenFrameEnabled = 1;
cpi->InterPrediction = 1;
cpi->MotionCompensation = 1;
- cpi->ThreshMapThreshold = 5;
- cpi->MaxConsDroppedFrames = 1;
/* Set encoder flags. */
/* if not AutoKeyframing cpi->ForceKeyFrameEvery = is frequency */
@@ -936,10 +520,6 @@
th->i=&cpi->pb.info;
th->granulepos=-1;
- /* Set up default values for QTargetModifier[Q_TABLE_SIZE] table */
- for ( i = 0; i < Q_TABLE_SIZE; i++ )
- cpi->QTargetModifier[i] = 1.0;
-
/* Set up an encode buffer */
#ifndef LIBOGG2
cpi->oggbuffer = _ogg_malloc(sizeof(oggpack_buffer));
@@ -957,31 +537,10 @@
(double)( c->fps_numerator /
c->fps_denominator );
- cpi->frame_target_rate = cpi->Configuration.TargetBandwidth /
- cpi->Configuration.OutputFrameRate;
-
- /* Set key frame data rate target; this is nominal keyframe size */
- cpi->Configuration.KeyFrameDataTarget = (c->keyframe_data_target_bitrate *
- c->fps_denominator /
- c->fps_numerator ) / 8;
-
- /* Note the height and width in the pre-processor control structure. */
- cpi->ScanConfig.VideoFrameHeight = cpi->pb.info.height;
- cpi->ScanConfig.VideoFrameWidth = cpi->pb.info.width;
-
InitFrameDetails(&cpi->pb);
EInitFragmentInfo(cpi);
EInitFrameInfo(cpi);
- /* Set up pre-processor config pointers. */
- cpi->ScanConfig.Yuv0ptr = cpi->yuv0ptr;
- cpi->ScanConfig.Yuv1ptr = cpi->yuv1ptr;
- cpi->ScanConfig.disp_fragments = cpi->pb.display_fragments;
- cpi->ScanConfig.RegionIndex = cpi->pb.pixel_index_table;
-
- /* Initialise the pre-processor module. */
- ScanYUVInit(&cpi->pp, &(cpi->ScanConfig));
-
/* Initialise Motion compensation */
InitMotionCompensation(cpi);
@@ -989,18 +548,6 @@
/* We always start at frame 1 */
cpi->CurrentFrame = 1;
- /* Reset the rate targeting correction factor. */
- cpi->BpbCorrectionFactor = 1.0;
-
- cpi->TotalByteCount = 0;
- cpi->TotalMotionScore = 0;
-
- /* Up regulation variables. */
- cpi->FinalPassLastPos = 0; /* Used to regulate a final unrestricted pass. */
- cpi->LastEndSB = 0; /* Where we were in the loop last time. */
- cpi->ResidueLastEndSB = 0; /* Where we were in the residue update
- loop last time. */
-
InitHuffmanSet(&cpi->pb);
/* This makes sure encoder version specific tables are initialised */
@@ -1037,7 +584,7 @@
/* Copy over input YUV to internal YUV buffers. */
/* we invert the image for backward compatibility with VP3 */
/* First copy over the Y data */
- LocalDataPtr = cpi->yuv1ptr + yuv->y_width*(yuv->y_height - 1);
+ LocalDataPtr = cpi->yuvptr + yuv->y_width*(yuv->y_height - 1);
InputDataPtr = yuv->y;
for ( i = 0; i < yuv->y_height; i++ ){
memcpy( LocalDataPtr, InputDataPtr, yuv->y_width );
@@ -1046,7 +593,7 @@
}
/* Now copy over the U data */
- LocalDataPtr = &cpi->yuv1ptr[(yuv->y_height * yuv->y_width)];
+ LocalDataPtr = &cpi->yuvptr[(yuv->y_height * yuv->y_width)];
LocalDataPtr += yuv->uv_width*(yuv->uv_height - 1);
InputDataPtr = yuv->u;
for ( i = 0; i < yuv->uv_height; i++ ){
@@ -1057,7 +604,7 @@
/* Now copy over the V data */
LocalDataPtr =
- &cpi->yuv1ptr[((yuv->y_height*yuv->y_width)*5)/4];
+ &cpi->yuvptr[((yuv->y_height*yuv->y_width)*5)/4];
LocalDataPtr += yuv->uv_width*(yuv->uv_height - 1);
InputDataPtr = yuv->v;
for ( i = 0; i < yuv->uv_height; i++ ){
@@ -1090,7 +637,6 @@
}
/* Update stats variables. */
- cpi->LastFrameSize = oggpackB_bytes(cpi->oggbuffer);
cpi->CurrentFrame++;
cpi->packetflag=1;
@@ -1098,17 +644,6 @@
((cpi->CurrentFrame - cpi->LastKeyFrame)<<cpi->pb.keyframe_granule_shift)+
cpi->LastKeyFrame - 1;
- if(!dropped){
- unsigned char *tmp = cpi->yuv0ptr;
- cpi->yuv0ptr = cpi->yuv1ptr;
- cpi->yuv1ptr = tmp;
-
- cpi->ScanConfig.Yuv0ptr = cpi->yuv0ptr;
- cpi->ScanConfig.Yuv1ptr = cpi->yuv1ptr;
- cpi->pp.ScanConfig.Yuv0ptr = cpi->yuv0ptr;
- cpi->pp.ScanConfig.Yuv1ptr = cpi->yuv1ptr;
- }
-
#ifdef _TH_DEBUG_
dframe++;
#endif
@@ -1323,7 +858,6 @@
EClearFragmentInfo(cpi);
EClearFrameInfo(cpi);
ClearTmpBuffers(&cpi->pb);
- ClearPPInstance(&cpi->pp);
oggpackB_writeclear(cpi->oggbuffer);
_ogg_free(cpi->oggbuffer);
Modified: branches/theora-thusnelda/lib/enc/frinit.c
===================================================================
--- branches/theora-thusnelda/lib/enc/frinit.c 2007-11-20 02:45:44 UTC (rev 14198)
+++ branches/theora-thusnelda/lib/enc/frinit.c 2007-11-20 14:33:26 UTC (rev 14199)
@@ -19,52 +19,6 @@
#include "codec_internal.h"
-void InitializeFragCoordinates(PB_INSTANCE *pbi){
-
- ogg_uint32_t i, j;
-
- ogg_uint32_t HorizFrags = pbi->HFragments;
- ogg_uint32_t VertFrags = pbi->VFragments;
- ogg_uint32_t StartFrag = 0;
-
- /* Y */
-
- for(i = 0; i< VertFrags; i++){
- for(j = 0; j< HorizFrags; j++){
-
- ogg_uint32_t ThisFrag = i * HorizFrags + j;
- pbi->FragCoordinates[ ThisFrag ].x=j * BLOCK_HEIGHT_WIDTH;
- pbi->FragCoordinates[ ThisFrag ].y=i * BLOCK_HEIGHT_WIDTH;
-
- }
- }
-
- /* U */
- HorizFrags >>= 1;
- VertFrags >>= 1;
- StartFrag = pbi->YPlaneFragments;
-
- for(i = 0; i< VertFrags; i++) {
- for(j = 0; j< HorizFrags; j++) {
- ogg_uint32_t ThisFrag = StartFrag + i * HorizFrags + j;
- pbi->FragCoordinates[ ThisFrag ].x=j * BLOCK_HEIGHT_WIDTH;
- pbi->FragCoordinates[ ThisFrag ].y=i * BLOCK_HEIGHT_WIDTH;
-
- }
- }
-
- /* V */
- StartFrag = pbi->YPlaneFragments + pbi->UVPlaneFragments;
- for(i = 0; i< VertFrags; i++) {
- for(j = 0; j< HorizFrags; j++) {
- ogg_uint32_t ThisFrag = StartFrag + i * HorizFrags + j;
- pbi->FragCoordinates[ ThisFrag ].x=j * BLOCK_HEIGHT_WIDTH;
- pbi->FragCoordinates[ ThisFrag ].y=i * BLOCK_HEIGHT_WIDTH;
-
- }
- }
-}
-
static void CalcPixelIndexTable( PB_INSTANCE *pbi){
ogg_uint32_t i;
ogg_uint32_t * PixelIndexTablePtr;
@@ -139,7 +93,6 @@
if(pbi->FragMVect) _ogg_free(pbi->FragMVect);
if(pbi->FragCoeffs) _ogg_free(pbi->FragCoeffs);
if(pbi->FragCoefEOB) _ogg_free(pbi->FragCoefEOB);
- if(pbi->skipped_display_fragments) _ogg_free(pbi->skipped_display_fragments);
if(pbi->QFragData) _ogg_free(pbi->QFragData);
#ifdef _TH_DEBUG_
if(pbi->QFragTIME) _ogg_free(pbi->QFragTIME);
@@ -151,12 +104,7 @@
#endif
if(pbi->TokenList) _ogg_free(pbi->TokenList);
if(pbi->FragCodingMethod) _ogg_free(pbi->FragCodingMethod);
- if(pbi->FragCoordinates) _ogg_free(pbi->FragCoordinates);
- if(pbi->FragQIndex) _ogg_free(pbi->FragQIndex);
- if(pbi->PPCoefBuffer) _ogg_free(pbi->PPCoefBuffer);
- if(pbi->FragmentVariances) _ogg_free(pbi->FragmentVariances);
-
if(pbi->BlockMap) _ogg_free(pbi->BlockMap);
if(pbi->SBCodedFlags) _ogg_free(pbi->SBCodedFlags);
@@ -164,12 +112,8 @@
if(pbi->MBFullyFlags) _ogg_free(pbi->MBFullyFlags);
if(pbi->MBCodedFlags) _ogg_free(pbi->MBCodedFlags);
- if(pbi->_Nodes) _ogg_free(pbi->_Nodes);
- pbi->_Nodes = 0;
-
pbi->QFragData = 0;
pbi->TokenList = 0;
- pbi->skipped_display_fragments = 0;
pbi->FragCoeffs = 0;
pbi->FragCoefEOB = 0;
pbi->display_fragments = 0;
@@ -187,7 +131,6 @@
pbi->SBFullyFlags = 0;
pbi->QFragData = 0;
pbi->TokenList = 0;
- pbi->skipped_display_fragments = 0;
pbi->FragCoeffs = 0;
pbi->FragCoefEOB = 0;
pbi->display_fragments = 0;
@@ -196,15 +139,7 @@
pbi->FragTokenCounts = 0;
pbi->CodedBlockList = 0;
pbi->FragCodingMethod = 0;
- pbi->FragCoordinates = 0;
pbi->FragMVect = 0;
-
- pbi->PPCoefBuffer=0;
- pbi->PPCoefBuffer=0;
- pbi->FragQIndex = 0;
- pbi->FragQIndex = 0;
- pbi->FragmentVariances= 0;
- pbi->FragmentVariances = 0 ;
}
void InitFragmentInfo(PB_INSTANCE * pbi){
@@ -237,9 +172,6 @@
pbi->FragCoefEOB =
_ogg_malloc(pbi->UnitFragments * sizeof(*pbi->FragCoefEOB));
- pbi->skipped_display_fragments =
- _ogg_malloc(pbi->UnitFragments * sizeof(*pbi->skipped_display_fragments));
-
pbi->QFragData =
_ogg_malloc(pbi->UnitFragments * sizeof(*pbi->QFragData));
@@ -262,21 +194,6 @@
pbi->FragCodingMethod =
_ogg_malloc(pbi->UnitFragments * sizeof(*pbi->FragCodingMethod));
- pbi->FragCoordinates =
- _ogg_malloc(pbi->UnitFragments * sizeof(*pbi->FragCoordinates));
-
- pbi->FragQIndex =
- _ogg_malloc(pbi->UnitFragments * sizeof(*pbi->FragQIndex));
-
- pbi->PPCoefBuffer =
- _ogg_malloc(pbi->UnitFragments * sizeof(*pbi->PPCoefBuffer));
-
- pbi->FragmentVariances =
- _ogg_malloc(pbi->UnitFragments * sizeof(*pbi->FragmentVariances));
-
- pbi->_Nodes =
- _ogg_malloc(pbi->UnitFragments * sizeof(*pbi->_Nodes));
-
/* Super Block Initialization */
pbi->SBCodedFlags =
_ogg_malloc(pbi->SuperBlocks * sizeof(*pbi->SBCodedFlags));
@@ -303,21 +220,10 @@
_ogg_free(pbi->GoldenFrame);
if(pbi->LastFrameRecon)
_ogg_free(pbi->LastFrameRecon);
- if(pbi->PostProcessBuffer)
- _ogg_free(pbi->PostProcessBuffer);
-
pbi->ThisFrameRecon = 0;
pbi->GoldenFrame = 0;
pbi->LastFrameRecon = 0;
- pbi->PostProcessBuffer = 0;
-
-
- pbi->ThisFrameRecon = 0;
- pbi->GoldenFrame = 0;
- pbi->LastFrameRecon = 0;
- pbi->PostProcessBuffer = 0;
-
}
void InitFrameInfo(PB_INSTANCE * pbi, unsigned int FrameSize){
@@ -335,22 +241,11 @@
pbi->LastFrameRecon =
_ogg_malloc(FrameSize*sizeof(*pbi->LastFrameRecon));
- pbi->PostProcessBuffer =
- _ogg_malloc(FrameSize*sizeof(*pbi->PostProcessBuffer));
-
}
void InitFrameDetails(PB_INSTANCE *pbi){
int FrameSize;
- /*pbi->PostProcessingLevel = 0;
- pbi->PostProcessingLevel = 4;
- pbi->PostProcessingLevel = 5;
- pbi->PostProcessingLevel = 6;*/
-
- pbi->PostProcessingLevel = 0;
-
-
/* Set the frame size etc. */
pbi->YPlaneSize = pbi->info.width *
@@ -399,7 +294,6 @@
InitFragmentInfo(pbi);
InitFrameInfo(pbi, FrameSize);
- InitializeFragCoordinates(pbi);
/* Configure mapping between quad-tree and fragments */
CreateBlockMapping ( pbi->BlockMap, pbi->YSuperBlocks,
Modified: branches/theora-thusnelda/lib/enc/mcomp.c
===================================================================
--- branches/theora-thusnelda/lib/enc/mcomp.c 2007-11-20 02:45:44 UTC (rev 14198)
+++ branches/theora-thusnelda/lib/enc/mcomp.c 2007-11-20 14:33:26 UTC (rev 14199)
@@ -156,28 +156,28 @@
if ( cpi->pb.display_fragments[LocalFragIndex] )
IntraError +=
dsp_intra8x8_err (cpi->dsp, &cpi->
- yuv1ptr[cpi->pb.pixel_index_table[LocalFragIndex]],
+ yuvptr[cpi->pb.pixel_index_table[LocalFragIndex]],
PixelsPerLine);
LocalFragIndex++;
if ( cpi->pb.display_fragments[LocalFragIndex] )
IntraError +=
dsp_intra8x8_err (cpi->dsp, &cpi->
- yuv1ptr[cpi->pb.pixel_index_table[LocalFragIndex]],
+ yuvptr[cpi->pb.pixel_index_table[LocalFragIndex]],
PixelsPerLine);
LocalFragIndex = FragIndex + cpi->pb.HFragments;
if ( cpi->pb.display_fragments[LocalFragIndex] )
IntraError +=
dsp_intra8x8_err (cpi->dsp, &cpi->
- yuv1ptr[cpi->pb.pixel_index_table[LocalFragIndex]],
+ yuvptr[cpi->pb.pixel_index_table[LocalFragIndex]],
PixelsPerLine);
LocalFragIndex++;
if ( cpi->pb.display_fragments[LocalFragIndex] )
IntraError +=
dsp_intra8x8_err (cpi->dsp, &cpi->
- yuv1ptr[cpi->pb.pixel_index_table[LocalFragIndex]],
+ yuvptr[cpi->pb.pixel_index_table[LocalFragIndex]],
PixelsPerLine);
dsp_restore_fpu (cpi->dsp);
@@ -319,7 +319,7 @@
cpi->pb.display_fragments[FragIndex + cpi->pb.HFragments + 1];
/* Set up the source pointers for the four source blocks. */
- SrcPtr[0] = &cpi->yuv1ptr[cpi->pb.pixel_index_table[FragIndex]];
+ SrcPtr[0] = &cpi->yuvptr[cpi->pb.pixel_index_table[FragIndex]];
SrcPtr[1] = SrcPtr[0] + 8;
SrcPtr[2] = SrcPtr[0] + (PixelsPerLine * 8);
SrcPtr[3] = SrcPtr[2] + 8;
@@ -459,7 +459,7 @@
MV->y += cpi->HalfPixelYOffset[BestHalfOffset];
/* Get the error score for the chosen 1/2 pixel offset as a variance. */
- InterMVError = GetMBInterError( cpi, cpi->yuv1ptr, RefFramePtr,
+ InterMVError = GetMBInterError( cpi, cpi->yuvptr, RefFramePtr,
FragIndex, MV->x, MV->y, PixelsPerLine );
dsp_restore_fpu (cpi->dsp);
@@ -511,7 +511,7 @@
/* Set up the source pointers for the four source blocks. */
SrcPtr[0] = &cpi->
- yuv1ptr[cpi->pb.pixel_index_table[FragIndex]];
+ yuvptr[cpi->pb.pixel_index_table[FragIndex]];
SrcPtr[1] = SrcPtr[0] + 8;
SrcPtr[2] = SrcPtr[0] + (PixelsPerLine * 8);
SrcPtr[3] = SrcPtr[2] + 8;
@@ -619,7 +619,7 @@
MV->y += cpi->HalfPixelYOffset[BestHalfOffset];
/* Get the error score for the chosen 1/2 pixel offset as a variance. */
- InterMVError = GetMBInterError( cpi, cpi->yuv1ptr, RefFramePtr,
+ InterMVError = GetMBInterError( cpi, cpi->yuvptr, RefFramePtr,
FragIndex, MV->x, MV->y, PixelsPerLine );
dsp_restore_fpu (cpi->dsp);
@@ -653,7 +653,7 @@
/* Set up the source pointer for the block. */
SrcPtr = &cpi->
- yuv1ptr[cpi->pb.pixel_index_table[FragIndex]];
+ yuvptr[cpi->pb.pixel_index_table[FragIndex]];
RefPtr = &RefFramePtr[cpi->pb.recon_pixel_index_table[FragIndex]];
RefPtr = RefPtr - ((MAX_MV_EXTENT/2) *
Deleted: branches/theora-thusnelda/lib/enc/misc_common.c
===================================================================
--- branches/theora-thusnelda/lib/enc/misc_common.c 2007-11-20 02:45:44 UTC (rev 14198)
+++ branches/theora-thusnelda/lib/enc/misc_common.c 2007-11-20 14:33:26 UTC (rev 14199)
@@ -1,288 +0,0 @@
-/********************************************************************
- * *
- * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
- * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
- * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
- * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
- * *
- * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2007 *
- * by the Xiph.Org Foundation http://www.xiph.org/ *
- * *
- ********************************************************************
-
- function:
- last mod: $Id$
-
- ********************************************************************/
-
-#include <string.h>
-#include "codec_internal.h"
-#include "block_inline.h"
-
-#define FIXED_Q 150
-#define MAX_UP_REG_LOOPS 2
-
-/* Gives the initial bytes per block estimate for each Q value */
-double BpbTable[Q_TABLE_SIZE] = {
- 0.42, 0.45, 0.46, 0.49, 0.51, 0.53, 0.56, 0.58,
- 0.61, 0.64, 0.68, 0.71, 0.74, 0.77, 0.80, 0.84,
- 0.89, 0.92, 0.98, 1.01, 1.04, 1.13, 1.17, 1.23,
- 1.28, 1.34, 1.41, 1.45, 1.51, 1.59, 1.69, 1.80,
- 1.84, 1.94, 2.02, 2.15, 2.23, 2.34, 2.44, 2.50,
- 2.69, 2.80, 2.87, 3.04, 3.16, 3.29, 3.59, 3.66,
- 3.86, 3.94, 4.22, 4.50, 4.64, 4.70, 5.24, 5.34,
- 5.61, 5.87, 6.11, 6.41, 6.71, 6.99, 7.36, 7.69
-};
-
-double KfBpbTable[Q_TABLE_SIZE] = {
- 0.74, 0.81, 0.88, 0.94, 1.00, 1.06, 1.14, 1.19,
- 1.27, 1.34, 1.42, 1.49, 1.54, 1.59, 1.66, 1.73,
- 1.80, 1.87, 1.97, 2.01, 2.08, 2.21, 2.25, 2.36,
- 2.39, 2.50, 2.55, 2.65, 2.71, 2.82, 2.95, 3.01,
- 3.11, 3.19, 3.31, 3.42, 3.58, 3.66, 3.78, 3.89,
- 4.11, 4.26, 4.36, 4.39, 4.63, 4.76, 4.85, 5.04,
- 5.26, 5.29, 5.47, 5.64, 5.76, 6.05, 6.35, 6.67,
- 6.91, 7.17, 7.40, 7.56, 8.02, 8.45, 8.86, 9.38
-};
-
-double GetEstimatedBpb( CP_INSTANCE *cpi, ogg_uint32_t TargetQ ){
- ogg_uint32_t i;
- ogg_int32_t ThreshTableIndex = Q_TABLE_SIZE - 1;
- double BytesPerBlock;
-
- /* Search for the Q table index that matches the given Q. */
- for ( i = 0; i < Q_TABLE_SIZE; i++ ) {
- if ( TargetQ >= cpi->pb.QThreshTable[i] ) {
- ThreshTableIndex = i;
- break;
- }
- }
-
- /* Adjust according to Q shift and type of frame */
- if ( cpi->pb.FrameType == KEY_FRAME ) {
- /* Get primary prediction */
- BytesPerBlock = KfBpbTable[ThreshTableIndex];
- } else {
- /* Get primary prediction */
- BytesPerBlock = BpbTable[ThreshTableIndex];
- BytesPerBlock = BytesPerBlock * cpi->BpbCorrectionFactor;
- }
-
- return BytesPerBlock;
-}
-
-static void UpRegulateMB( CP_INSTANCE *cpi, ogg_uint32_t RegulationQ,
- ogg_uint32_t SB, ogg_uint32_t MB, int NoCheck ) {
- ogg_int32_t FragIndex;
- ogg_uint32_t B;
-
- /* Variables used in calculating corresponding row,col and index in
- UV planes */
- ogg_uint32_t UVRow;
- ogg_uint32_t UVColumn;
- ogg_uint32_t UVFragOffset;
-
- /* There may be MB's lying out of frame which must be ignored. For
- these MB's Top left block will have a negative Fragment Index. */
- if ( QuadMapToMBTopLeft(cpi->pb.BlockMap, SB, MB ) >= 0 ) {
- /* Up regulate the component blocks Y then UV. */
- for ( B=0; B<4; B++ ){
- FragIndex = QuadMapToIndex1( cpi->pb.BlockMap, SB, MB, B );
-
- if ( ( !cpi->pb.display_fragments[FragIndex] ) &&
- ( (NoCheck) || (cpi->FragmentLastQ[FragIndex] > RegulationQ) ) ){
- cpi->pb.display_fragments[FragIndex] = 1;
- cpi->FragmentLastQ[FragIndex] = RegulationQ;
- cpi->MotionScore++;
- }
- }
-
- /* Check the two UV blocks */
- FragIndex = QuadMapToMBTopLeft(cpi->pb.BlockMap, SB, MB );
-
- UVRow = (FragIndex / (cpi->pb.HFragments * 2));
- UVColumn = (FragIndex % cpi->pb.HFragments) / 2;
- UVFragOffset = (UVRow * (cpi->pb.HFragments / 2)) + UVColumn;
-
- FragIndex = cpi->pb.YPlaneFragments + UVFragOffset;
- if ( ( !cpi->pb.display_fragments[FragIndex] ) &&
- ( (NoCheck) || (cpi->FragmentLastQ[FragIndex] > RegulationQ) ) ) {
- cpi->pb.display_fragments[FragIndex] = 1;
- cpi->FragmentLastQ[FragIndex] = RegulationQ;
- cpi->MotionScore++;
- }
-
- FragIndex += cpi->pb.UVPlaneFragments;
- if ( ( !cpi->pb.display_fragments[FragIndex] ) &&
- ( (NoCheck) || (cpi->FragmentLastQ[FragIndex] > RegulationQ) ) ) {
- cpi->pb.display_fragments[FragIndex] = 1;
- cpi->FragmentLastQ[FragIndex] = RegulationQ;
- cpi->MotionScore++;
- }
- }
-}
-
-static void UpRegulateBlocks (CP_INSTANCE *cpi, ogg_uint32_t RegulationQ,
- ogg_int32_t RecoveryBlocks,
- ogg_uint32_t * LastSB, ogg_uint32_t * LastMB ) {
-
- ogg_uint32_t LoopTimesRound = 0;
- ogg_uint32_t MaxSB = cpi->pb.YSBRows *
- cpi->pb.YSBCols; /* Tot super blocks in image */
- ogg_uint32_t SB, MB; /* Super-Block and macro block indices. */
-
- /* First scan for blocks for which a residue update is outstanding. */
- while ( (cpi->MotionScore < RecoveryBlocks) &&
- (LoopTimesRound < MAX_UP_REG_LOOPS) ) {
- LoopTimesRound++;
-
- for ( SB = (*LastSB); SB < MaxSB; SB++ ) {
- /* Check its four Macro-Blocks */
- for ( MB=(*LastMB); MB<4; MB++ ) {
- /* Mark relevant blocks for update */
- UpRegulateMB( cpi, RegulationQ, SB, MB, 0 );
-
- /* Keep track of the last refresh MB. */
- (*LastMB) += 1;
- if ( (*LastMB) == 4 )
- (*LastMB) = 0;
-
- /* Termination clause */
- if (cpi->MotionScore >= RecoveryBlocks) {
- /* Make sure we don't stall at SB level */
- if ( *LastMB == 0 )
- SB++;
- break;
- }
- }
-
- /* Termination clause */
- if (cpi->MotionScore >= RecoveryBlocks)
- break;
- }
-
- /* Update super block start index */
- if ( SB >= MaxSB){
- (*LastSB) = 0;
- }else{
- (*LastSB) = SB;
- }
- }
-}
-
-void UpRegulateDataStream (CP_INSTANCE *cpi, ogg_uint32_t RegulationQ,
- ogg_int32_t RecoveryBlocks ) {
- ogg_uint32_t LastPassMBPos = 0;
- ogg_uint32_t StdLastMBPos = 0;
-
- ogg_uint32_t MaxSB = cpi->pb.YSBRows *
- cpi->pb.YSBCols; /* Tot super blocks in image */
-
- ogg_uint32_t SB=0; /* Super-Block index */
- ogg_uint32_t MB; /* Macro-Block index */
-
- /* Decduct the number of blocks in an MB / 2 from the recover block count.
- This will compensate for the fact that once we start checking an MB
- we test every block in that macro block */
- if ( RecoveryBlocks > 3 )
- RecoveryBlocks -= 3;
-
- /* Up regulate blocks last coded at higher Q */
- UpRegulateBlocks( cpi, RegulationQ, RecoveryBlocks,
- &cpi->LastEndSB, &StdLastMBPos );
-
- /* If we have still not used up the minimum number of blocks and are
- at the minimum Q then run through a final pass of the data to
- insure that each block gets a final refresh. */
- if ( (RegulationQ == VERY_BEST_Q) &&
- (cpi->MotionScore < RecoveryBlocks) ) {
- if ( cpi->FinalPassLastPos < MaxSB ) {
- for ( SB = cpi->FinalPassLastPos; SB < MaxSB; SB++ ) {
- /* Check its four Macro-Blocks */
- for ( MB=LastPassMBPos; MB<4; MB++ ) {
- /* Mark relevant blocks for update */
- UpRegulateMB( cpi, RegulationQ, SB, MB, 1 );
-
- /* Keep track of the last refresh MB. */
- LastPassMBPos += 1;
- if ( LastPassMBPos == 4 ) {
- LastPassMBPos = 0;
-
- /* Increment SB index */
- cpi->FinalPassLastPos += 1;
- }
-
- /* Termination clause */
- if (cpi->MotionScore >= RecoveryBlocks)
- break;
- }
-
- /* Termination clause */
- if (cpi->MotionScore >= RecoveryBlocks)
- break;
-
- }
- }
- }
-}
-
-void RegulateQ( CP_INSTANCE *cpi, ogg_int32_t UpdateScore ) {
- double PredUnitScoreBytes;
- ogg_uint32_t QIndex = Q_TABLE_SIZE - 1;
- ogg_uint32_t i;
-
- if ( UpdateScore > 0 ) {
- double TargetUnitScoreBytes = (double)cpi->ThisFrameTargetBytes /
- (double)UpdateScore;
- double LastBitError = 10000.0; /* Silly high number */
- /* Search for the best Q for the target bitrate. */
- for ( i = 0; i < Q_TABLE_SIZE; i++ ) {
- PredUnitScoreBytes = GetEstimatedBpb( cpi, cpi->pb.QThreshTable[i] );
- if ( PredUnitScoreBytes > TargetUnitScoreBytes ) {
- if ( (PredUnitScoreBytes - TargetUnitScoreBytes) <= LastBitError ) {
- QIndex = i;
- } else {
- QIndex = i - 1;
- }
- break;
- } else {
- LastBitError = TargetUnitScoreBytes - PredUnitScoreBytes;
- }
- }
- }
-
- /* QIndex should now indicate the optimal Q. */
- cpi->pb.ThisFrameQualityValue = cpi->pb.QThreshTable[QIndex];
-
- /* Apply range restrictions for key frames. */
- if ( cpi->pb.FrameType == KEY_FRAME ) {
- if ( cpi->pb.ThisFrameQualityValue > cpi->pb.QThreshTable[20] )
- cpi->pb.ThisFrameQualityValue = cpi->pb.QThreshTable[20];
- else if ( cpi->pb.ThisFrameQualityValue < cpi->pb.QThreshTable[50] )
- cpi->pb.ThisFrameQualityValue = cpi->pb.QThreshTable[50];
- }
-
- /* Limit the Q value to the maximum available value */
- if (cpi->pb.ThisFrameQualityValue >
- cpi->pb.QThreshTable[cpi->Configuration.ActiveMaxQ]) {
- cpi->pb.ThisFrameQualityValue =
- (ogg_uint32_t)cpi->pb.QThreshTable[cpi->Configuration.ActiveMaxQ];
- }
-
- if(cpi->FixedQ) {
- if ( cpi->pb.FrameType == KEY_FRAME ) {
- cpi->pb.ThisFrameQualityValue = cpi->pb.QThreshTable[43];
- cpi->pb.ThisFrameQualityValue = cpi->FixedQ;
- } else {
- cpi->pb.ThisFrameQualityValue = cpi->FixedQ;
- }
- }
-
- /* If the quantizer value has changed then re-initialise it */
- if ( cpi->pb.ThisFrameQualityValue != cpi->pb.LastFrameQualityValue ) {
- /* Initialise quality tables. */
- UpdateQC( cpi, cpi->pb.ThisFrameQualityValue );
- cpi->pb.LastFrameQualityValue = cpi->pb.ThisFrameQualityValue;
- }
-}
-
Modified: branches/theora-thusnelda/lib/enc/pb.c
===================================================================
--- branches/theora-thusnelda/lib/enc/pb.c 2007-11-20 02:45:44 UTC (rev 14198)
+++ branches/theora-thusnelda/lib/enc/pb.c 2007-11-20 14:33:26 UTC (rev 14199)
@@ -23,19 +23,8 @@
if(pbi->ReconDataBuffer)
_ogg_free(pbi->ReconDataBuffer);
- if(pbi->DequantBuffer)
- _ogg_free(pbi->DequantBuffer);
- if(pbi->TmpDataBuffer)
- _ogg_free(pbi->TmpDataBuffer);
- if(pbi->TmpReconBuffer)
- _ogg_free(pbi->TmpReconBuffer);
-
pbi->ReconDataBuffer=0;
- pbi->DequantBuffer = 0;
- pbi->TmpDataBuffer = 0;
- pbi->TmpReconBuffer = 0;
-
}
void InitTmpBuffers(PB_INSTANCE * pbi){
@@ -46,16 +35,6 @@
/* Adjust the position of all of our temporary */
pbi->ReconDataBuffer =
_ogg_malloc(64*sizeof(*pbi->ReconDataBuffer));
-
- pbi->DequantBuffer =
- _ogg_malloc(64 * sizeof(*pbi->DequantBuffer));
-
- pbi->TmpDataBuffer =
- _ogg_malloc(64 * sizeof(*pbi->TmpDataBuffer));
-
- pbi->TmpReconBuffer =
- _ogg_malloc(64 * sizeof(*pbi->TmpReconBuffer));
-
}
void ClearPBInstance(PB_INSTANCE *pbi){
@@ -79,15 +58,4 @@
#else
pbi->opb = _ogg_malloc(oggpack_buffersize());
#endif
-
- /* variables needing initialization (not being set to 0) */
-
- pbi->ModifierPointer[0] = &pbi->Modifier[0][255];
- pbi->ModifierPointer[1] = &pbi->Modifier[1][255];
- pbi->ModifierPointer[2] = &pbi->Modifier[2][255];
- pbi->ModifierPointer[3] = &pbi->Modifier[3][255];
-
- pbi->DecoderErrorCode = 0;
- pbi->KeyFrameType = DCT_KEY_FRAME;
- pbi->FramesHaveBeenSkipped = 0;
}
Deleted: branches/theora-thusnelda/lib/enc/pp.c
===================================================================
--- branches/theora-thusnelda/lib/enc/pp.c 2007-11-20 02:45:44 UTC (rev 14198)
+++ branches/theora-thusnelda/lib/enc/pp.c 2007-11-20 14:33:26 UTC (rev 14199)
@@ -1,954 +0,0 @@
-/********************************************************************
- * *
- * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
- * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
- * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
- * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
- * *
- * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2007 *
- * by the Xiph.Org Foundation http://www.xiph.org/ *
- * *
- ********************************************************************
-
- function:
- last mod: $Id$
-
- ********************************************************************/
-
-#include <stdlib.h>
-#include <string.h>
-#include "codec_internal.h"
-#include "pp.h"
-#include "dsp.h"
-
-#define MAX(a, b) ((a>b)?a:b)
-#define MIN(a, b) ((a<b)?a:b)
-#define PP_QUALITY_THRESH 49
-
-static const ogg_int32_t SharpenModifier[ Q_TABLE_SIZE ] =
-{ -12, -11, -10, -10, -9, -9, -9, -9,
- -6, -6, -6, -6, -6, -6, -6, -6,
- -4, -4, -4, -4, -4, -4, -4, -4,
- -2, -2, -2, -2, -2, -2, -2, -2,
- -2, -2, -2, -2, -2, -2, -2, -2,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0
-};
-
-static const ogg_uint32_t DcQuantScaleV1[ Q_TABLE_SIZE ] = {
- 22, 20, 19, 18, 17, 17, 16, 16,
- 15, 15, 14, 14, 13, 13, 12, 12,
- 11, 11, 10, 10, 9, 9, 9, 8,
- 8, 8, 7, 7, 7, 6, 6, 6,
- 6, 5, 5, 5, 5, 4, 4, 4,
- 4, 4, 3, 3, 3, 3, 3, 3,
- 3, 2, 2, 2, 2, 2, 2, 2,
- 2, 1, 1, 1, 1, 1, 1, 1
-};
-
-static const ogg_uint32_t * const DeringModifierV1=DcQuantScaleV1;
-
-static void PClearFrameInfo(PP_INSTANCE * ppi){
- int i;
-
- if(ppi->ScanPixelIndexTable) _ogg_free(ppi->ScanPixelIndexTable);
- ppi->ScanPixelIndexTable=0;
-
- if(ppi->ScanDisplayFragments) _ogg_free(ppi->ScanDisplayFragments);
- ppi->ScanDisplayFragments=0;
-
- for(i = 0 ; i < MAX_PREV_FRAMES ; i ++)
- if(ppi->PrevFragments[i]){
- _ogg_free(ppi->PrevFragments[i]);
- ppi->PrevFragments[i]=0;
- }
-
- if(ppi->FragScores) _ogg_free(ppi->FragScores);
- ppi->FragScores=0;
-
- if(ppi->SameGreyDirPixels) _ogg_free(ppi->SameGreyDirPixels);
- ppi->SameGreyDirPixels=0;
-
- if(ppi->FragDiffPixels) _ogg_free(ppi->FragDiffPixels);
- ppi->FragDiffPixels=0;
-
- if(ppi->BarBlockMap) _ogg_free(ppi->BarBlockMap);
- ppi->BarBlockMap=0;
-
- if(ppi->TmpCodedMap) _ogg_free(ppi->TmpCodedMap);
- ppi->TmpCodedMap=0;
-
- if(ppi->RowChangedPixels) _ogg_free(ppi->RowChangedPixels);
- ppi->RowChangedPixels=0;
-
- if(ppi->PixelScores) _ogg_free(ppi->PixelScores);
- ppi->PixelScores=0;
-
- if(ppi->PixelChangedMap) _ogg_free(ppi->PixelChangedMap);
- ppi->PixelChangedMap=0;
-
- if(ppi->ChLocals) _ogg_free(ppi->ChLocals);
- ppi->ChLocals=0;
-
- if(ppi->yuv_differences) _ogg_free(ppi->yuv_differences);
- ppi->yuv_differences=0;
-
-}
-
-void PInitFrameInfo(PP_INSTANCE * ppi){
- int i;
- PClearFrameInfo(ppi);
-
- ppi->ScanPixelIndexTable =
- _ogg_malloc(ppi->ScanFrameFragments*sizeof(*ppi->ScanPixelIndexTable));
-
- ppi->ScanDisplayFragments =
- _ogg_malloc(ppi->ScanFrameFragments*sizeof(*ppi->ScanDisplayFragments));
-
- for(i = 0 ; i < MAX_PREV_FRAMES ; i ++)
- ppi->PrevFragments[i] =
- _ogg_malloc(ppi->ScanFrameFragments*sizeof(*ppi->PrevFragments));
-
- ppi->FragScores =
- _ogg_malloc(ppi->ScanFrameFragments*sizeof(*ppi->FragScores));
-
- ppi->SameGreyDirPixels =
- _ogg_malloc(ppi->ScanFrameFragments*sizeof(*ppi->SameGreyDirPixels));
-
- ppi->FragDiffPixels =
- _ogg_malloc(ppi->ScanFrameFragments*sizeof(*ppi->FragScores));
-
- ppi->BarBlockMap=
- _ogg_malloc(3 * ppi->ScanHFragments*sizeof(*ppi->BarBlockMap));
-
- ppi->TmpCodedMap =
- _ogg_malloc(ppi->ScanHFragments*sizeof(*ppi->TmpCodedMap));
-
- ppi->RowChangedPixels =
- _ogg_malloc(3 * ppi->ScanConfig.VideoFrameHeight*
- sizeof(*ppi->RowChangedPixels));
-
- ppi->PixelScores =
- _ogg_malloc(ppi->ScanConfig.VideoFrameWidth*
- sizeof(*ppi->PixelScores) * PSCORE_CB_ROWS);
-
- ppi->PixelChangedMap =
- _ogg_malloc(ppi->ScanConfig.VideoFrameWidth*
- sizeof(*ppi->PixelChangedMap) * PMAP_CB_ROWS);
-
- ppi->ChLocals =
- _ogg_malloc(ppi->ScanConfig.VideoFrameWidth*
- sizeof(*ppi->ChLocals) * CHLOCALS_CB_ROWS);
-
- ppi->yuv_differences =
- _ogg_malloc(ppi->ScanConfig.VideoFrameWidth*
- sizeof(*ppi->yuv_differences) * YDIFF_CB_ROWS);
-}
-
-void ClearPPInstance(PP_INSTANCE *ppi){
- PClearFrameInfo(ppi);
-}
-
-
-void InitPPInstance(PP_INSTANCE *ppi, DspFunctions *funcs){
-
- memset(ppi,0,sizeof(*ppi));
-
- memcpy(&ppi->dsp, funcs, sizeof(DspFunctions));
-
- /* Initializations */
- ppi->PrevFrameLimit = 3; /* Must not exceed MAX_PREV_FRAMES (Note
- that this number includes the current
- frame so "1 = no effect") */
-
- /* Scan control variables. */
- ppi->HFragPixels = 8;
- ppi->VFragPixels = 8;
-
- ppi->SRFGreyThresh = 4;
- ppi->SRFColThresh = 5;
- ppi->NoiseSupLevel = 3;
- ppi->SgcLevelThresh = 3;
- ppi->SuvcLevelThresh = 4;
-
- /* Variables controlling S.A.D. breakouts. */
- ppi->GrpLowSadThresh = 10;
- ppi->GrpHighSadThresh = 64;
- ppi->PrimaryBlockThreshold = 5;
- ppi->SgcThresh = 16; /* (Default values for 8x8 blocks). */
-
- ppi->UVBlockThreshCorrection = 1.25;
- ppi->UVSgcCorrection = 1.5;
-
- ppi->MaxLineSearchLen = MAX_SEARCH_LINE_LEN;
-}
-
-static void DeringBlockStrong(unsigned char *SrcPtr,
- unsigned char *DstPtr,
- ogg_int32_t Pitch,
- ogg_uint32_t FragQIndex,
- const ogg_uint32_t *QuantScale){
-
- ogg_int16_t UDMod[72];
- ogg_int16_t LRMod[72];
- unsigned int j,k,l;
- const unsigned char * Src;
- unsigned int QValue = QuantScale[FragQIndex];
-
- unsigned char p;
- unsigned char pl;
- unsigned char pr;
- unsigned char pu;
- unsigned char pd;
-
- int al;
- int ar;
- int au;
- int ad;
-
- int atot;
- int B;
- int newVal;
-
- const unsigned char *curRow = SrcPtr - 1; /* avoid negative array indexes */
- unsigned char *dstRow = DstPtr;
- const unsigned char *lastRow = SrcPtr-Pitch;
- const unsigned char *nextRow = SrcPtr+Pitch;
-
- unsigned int rowOffset = 0;
- unsigned int round = (1<<6);
-
- int High;
- int Low;
- int TmpMod;
-
- int Sharpen = SharpenModifier[FragQIndex];
- High = 3 * QValue;
- if(High>32)High=32;
- Low = 0;
-
-
- /* Initialize the Mod Data */
- Src = SrcPtr-Pitch;
- for(k=0;k<9;k++){
- for(j=0;j<8;j++){
-
- TmpMod = 32 + QValue - (abs(Src[j+Pitch]-Src[j]));
-
- if(TmpMod< -64)
- TmpMod = Sharpen;
-
- else if(TmpMod<Low)
- TmpMod = Low;
-
- else if(TmpMod>High)
- TmpMod = High;
-
- UDMod[k*8+j] = (ogg_int16_t)TmpMod;
- }
- Src +=Pitch;
- }
-
- Src = SrcPtr-1;
-
- for(k=0;k<8;k++){
- for(j=0;j<9;j++){
- TmpMod = 32 + QValue - (abs(Src[j+1]-Src[j]));
-
- if(TmpMod< -64 )
- TmpMod = Sharpen;
-
- else if(TmpMod<0)
- TmpMod = Low;
-
- else if(TmpMod>High)
- TmpMod = High;
-
- LRMod[k*9+j] = (ogg_int16_t)TmpMod;
- }
- Src+=Pitch;
- }
-
- for(k=0;k<8;k++){
- /* In the case that this function called with same buffer for
- source and destination, To keep the c and the mmx version to have
- consistant results, intermediate buffer is used to store the
- eight pixel value before writing them to destination
- (i.e. Overwriting souce for the speical case) */
- for(l=0;l<8;l++){
-
- atot = 128;
- B = round;
- p = curRow[ rowOffset +l +1];
-
- pl = curRow[ rowOffset +l];
- al = LRMod[k*9+l];
- atot -= al;
- B += al * pl;
-
- pu = lastRow[ rowOffset +l];
- au = UDMod[k*8+l];
- atot -= au;
- B += au * pu;
-
- pd = nextRow[ rowOffset +l];
- ad = UDMod[(k+1)*8+l];
- atot -= ad;
- B += ad * pd;
-
- pr = curRow[ rowOffset +l+2];
- ar = LRMod[k*9+l+1];
- atot -= ar;
- B += ar * pr;
-
- newVal = ( atot * p + B) >> 7;
-
- dstRow[ rowOffset +l]= clamp255( newVal );
- }
- rowOffset += Pitch;
- }
-}
-
-static void DeringBlockWeak(unsigned char *SrcPtr,
- unsigned char *DstPtr,
- ogg_int32_t Pitch,
- ogg_uint32_t FragQIndex,
- const ogg_uint32_t *QuantScale){
-
- ogg_int16_t UDMod[72];
- ogg_int16_t LRMod[72];
- unsigned int j,k;
- const unsigned char * Src;
- unsigned int QValue = QuantScale[FragQIndex];
-
- unsigned char p;
- unsigned char pl;
- unsigned char pr;
- unsigned char pu;
- unsigned char pd;
-
- int al;
- int ar;
- int au;
- int ad;
-
- int atot;
- int B;
- int newVal;
-
- const unsigned char *curRow = SrcPtr-1;
- unsigned char *dstRow = DstPtr;
- const unsigned char *lastRow = SrcPtr-Pitch;
- const unsigned char *nextRow = SrcPtr+Pitch;
-
- unsigned int rowOffset = 0;
- unsigned int round = (1<<6);
-
- int High;
- int Low;
- int TmpMod;
- int Sharpen = SharpenModifier[FragQIndex];
-
- High = 3 * QValue;
- if(High>24)
- High=24;
- Low = 0 ;
-
- /* Initialize the Mod Data */
- Src=SrcPtr-Pitch;
- for(k=0;k<9;k++) {
- for(j=0;j<8;j++) {
-
- TmpMod = 32 + QValue - 2*(abs(Src[j+Pitch]-Src[j]));
-
- if(TmpMod< -64)
- TmpMod = Sharpen;
-
- else if(TmpMod<Low)
- TmpMod = Low;
-
- else if(TmpMod>High)
- TmpMod = High;
-
- UDMod[k*8+j] = (ogg_int16_t)TmpMod;
- }
- Src +=Pitch;
- }
-
- Src = SrcPtr-1;
-
- for(k=0;k<8;k++){
- for(j=0;j<9;j++){
- TmpMod = 32 + QValue - 2*(abs(Src[j+1]-Src[j]));
-
- if(TmpMod< -64 )
- TmpMod = Sharpen;
-
- else if(TmpMod<Low)
- TmpMod = Low;
-
- else if(TmpMod>High)
- TmpMod = High;
-
- LRMod[k*9+j] = (ogg_int16_t)TmpMod;
- }
- Src+=Pitch;
- }
-
- for(k=0;k<8;k++) {
- for(j=0;j<8;j++){
- atot = 128;
- B = round;
- p = curRow[ rowOffset +j+1];
-
- pl = curRow[ rowOffset +j];
- al = LRMod[k*9+j];
- atot -= al;
- B += al * pl;
-
- pu = lastRow[ rowOffset +j];
- au = UDMod[k*8+j];
- atot -= au;
- B += au * pu;
-
- pd = nextRow[ rowOffset +j];
- ad = UDMod[(k+1)*8+j];
- atot -= ad;
- B += ad * pd;
-
- pr = curRow[ rowOffset +j+2];
- ar = LRMod[k*9+j+1];
- atot -= ar;
- B += ar * pr;
-
- newVal = ( atot * p + B) >> 7;
-
- dstRow[ rowOffset +j] = clamp255( newVal );
- }
-
- rowOffset += Pitch;
- }
-}
-
-static void DeringFrame(PB_INSTANCE *pbi,
- unsigned char *Src, unsigned char *Dst){
- ogg_uint32_t col,row;
- unsigned char *SrcPtr;
- unsigned char *DestPtr;
- ogg_uint32_t BlocksAcross,BlocksDown;
- const ogg_uint32_t *QuantScale;
- ogg_uint32_t Block;
- ogg_uint32_t LineLength;
-
- ogg_int32_t Thresh1,Thresh2,Thresh3,Thresh4;
-
- Thresh1 = 384;
- Thresh2 = 4 * Thresh1;
- Thresh3 = 5 * Thresh2/4;
- Thresh4 = 5 * Thresh2/2;
-
- QuantScale = DeringModifierV1;
-
- BlocksAcross = pbi->HFragments;
- BlocksDown = pbi->VFragments;
-
- SrcPtr = Src + pbi->ReconYDataOffset;
- DestPtr = Dst + pbi->ReconYDataOffset;
- LineLength = pbi->YStride;
-
- Block = 0;
-
- for ( row = 0 ; row < BlocksDown; row ++){
- for (col = 0; col < BlocksAcross; col ++){
- ogg_uint32_t Quality = pbi->FragQIndex[Block];
- ogg_int32_t Variance = pbi->FragmentVariances[Block];
-
- if( pbi->PostProcessingLevel >5 && Variance > Thresh3 ){
- DeringBlockStrong(SrcPtr + 8 * col, DestPtr + 8 * col,
- LineLength,Quality,QuantScale);
-
- if( (col > 0 &&
- pbi->FragmentVariances[Block-1] > Thresh4 ) ||
- (col + 1 < BlocksAcross &&
- pbi->FragmentVariances[Block+1] > Thresh4 ) ||
- (row + 1 < BlocksDown &&
- pbi->FragmentVariances[Block+BlocksAcross] > Thresh4) ||
- (row > 0 &&
- pbi->FragmentVariances[Block-BlocksAcross] > Thresh4) ){
-
- DeringBlockStrong(SrcPtr + 8 * col, DestPtr + 8 * col,
- LineLength,Quality,QuantScale);
- DeringBlockStrong(SrcPtr + 8 * col, DestPtr + 8 * col,
- LineLength,Quality,QuantScale);
- }
- } else if(Variance > Thresh2 ) {
-
- DeringBlockStrong(SrcPtr + 8 * col, DestPtr + 8 * col,
- LineLength,Quality,QuantScale);
- } else if(Variance > Thresh1 ) {
-
- DeringBlockWeak(SrcPtr + 8 * col, DestPtr + 8 * col,
- LineLength,Quality,QuantScale);
-
- } else {
-
- dsp_copy8x8(pbi->dsp, SrcPtr + 8 * col, DestPtr + 8 * col, LineLength);
-
- }
-
- ++Block;
-
- }
- SrcPtr += 8 * LineLength;
- DestPtr += 8 * LineLength;
- }
-
- /* Then U */
-
- BlocksAcross /= 2;
- BlocksDown /= 2;
- LineLength /= 2;
-
- SrcPtr = Src + pbi->ReconUDataOffset;
- DestPtr = Dst + pbi->ReconUDataOffset;
- for ( row = 0 ; row < BlocksDown; row ++) {
- for (col = 0; col < BlocksAcross; col ++) {
- ogg_uint32_t Quality = pbi->FragQIndex[Block];
- ogg_int32_t Variance = pbi->FragmentVariances[Block];
-
- if( pbi->PostProcessingLevel >5 && Variance > Thresh4 ) {
- DeringBlockStrong(SrcPtr + 8 * col, DestPtr + 8 * col,
- LineLength,Quality,QuantScale);
- DeringBlockStrong(SrcPtr + 8 * col, DestPtr + 8 * col,
- LineLength,Quality,QuantScale);
- DeringBlockStrong(SrcPtr + 8 * col, DestPtr + 8 * col,
- LineLength,Quality,QuantScale);
-
- }else if(Variance > Thresh2 ){
- DeringBlockStrong(SrcPtr + 8 * col, DestPtr + 8 * col,
- LineLength,Quality,QuantScale);
- }else if(Variance > Thresh1 ){
- DeringBlockWeak(SrcPtr + 8 * col, DestPtr + 8 * col,
- LineLength,Quality,QuantScale);
- }else{
- dsp_copy8x8(pbi->dsp, SrcPtr + 8 * col, DestPtr + 8 * col, LineLength);
- }
-
- ++Block;
-
- }
- SrcPtr += 8 * LineLength;
- DestPtr += 8 * LineLength;
- }
-
- /* Then V */
- SrcPtr = Src + pbi->ReconVDataOffset;
- DestPtr = Dst + pbi->ReconVDataOffset;
-
- for ( row = 0 ; row < BlocksDown; row ++){
- for (col = 0; col < BlocksAcross; col ++){
-
- ogg_uint32_t Quality = pbi->FragQIndex[Block];
- ogg_int32_t Variance = pbi->FragmentVariances[Block];
-
-
- if( pbi->PostProcessingLevel >5 && Variance > Thresh4 ) {
- DeringBlockStrong(SrcPtr + 8 * col, DestPtr + 8 * col,
- LineLength,Quality,QuantScale);
- DeringBlockStrong(SrcPtr + 8 * col, DestPtr + 8 * col,
- LineLength,Quality,QuantScale);
- DeringBlockStrong(SrcPtr + 8 * col, DestPtr + 8 * col,
- LineLength,Quality,QuantScale);
-
- }else if(Variance > Thresh2 ){
- DeringBlockStrong(SrcPtr + 8 * col, DestPtr + 8 * col,
- LineLength,Quality,QuantScale);
- }else if(Variance > Thresh1 ){
- DeringBlockWeak(SrcPtr + 8 * col, DestPtr + 8 * col,
- LineLength,Quality,QuantScale);
- }else{
- dsp_copy8x8(pbi->dsp, SrcPtr + 8 * col, DestPtr + 8 * col, LineLength);
- }
-
- ++Block;
-
- }
- SrcPtr += 8 * LineLength;
- DestPtr += 8 * LineLength;
-
- }
-
-}
-
-void UpdateFragQIndex(PB_INSTANCE *pbi){
-
- ogg_uint32_t ThisFrameQIndex;
- ogg_uint32_t i;
-
- /* Check this frame quality index */
- ThisFrameQIndex = pbi->FrameQIndex;
-
-
- /* It is not a key frame, so only reset those are coded */
- for( i = 0; i < pbi->UnitFragments; i++ )
- if( pbi->display_fragments[i])
- pbi->FragQIndex[i] = ThisFrameQIndex;
-
-}
-
-static void DeblockLoopFilteredBand(PB_INSTANCE *pbi,
- unsigned char *SrcPtr,
- unsigned char *DesPtr,
- ogg_uint32_t PlaneLineStep,
- ogg_uint32_t FragsAcross,
- ogg_uint32_t StartFrag,
- const ogg_uint32_t *QuantScale){
- ogg_uint32_t j,k;
- ogg_uint32_t CurrentFrag=StartFrag;
- ogg_int32_t QStep;
- ogg_int32_t FLimit;
- unsigned char *Src, *Des;
- ogg_int32_t x[10];
- ogg_int32_t Sum1, Sum2;
-
- while(CurrentFrag < StartFrag + FragsAcross){
-
- Src=SrcPtr+8*(CurrentFrag-StartFrag)-PlaneLineStep*5;
- Des=DesPtr+8*(CurrentFrag-StartFrag)-PlaneLineStep*4;
-
- QStep = QuantScale[pbi->FragQIndex[CurrentFrag+FragsAcross]];
- FLimit = ( QStep * 3 ) >> 2;
-
- for( j=0; j<8 ; j++){
- x[0] = Src[0];
- x[1] = Src[PlaneLineStep];
- x[2] = Src[PlaneLineStep*2];
- x[3] = Src[PlaneLineStep*3];
- x[4] = Src[PlaneLineStep*4];
- x[5] = Src[PlaneLineStep*5];
- x[6] = Src[PlaneLineStep*6];
- x[7] = Src[PlaneLineStep*7];
- x[8] = Src[PlaneLineStep*8];
- x[9] = Src[PlaneLineStep*9];
-
- Sum1=Sum2=0;
-
- for(k=1;k<=4;k++){
- Sum1 += abs(x[k]-x[k-1]);
- Sum2 += abs(x[k+4]-x[k+5]);
- }
-
- pbi->FragmentVariances[CurrentFrag] +=((Sum1>255)?255:Sum1);
- pbi->FragmentVariances[CurrentFrag + FragsAcross] += ((Sum2>255)?255:Sum2);
-
- if( Sum1 < FLimit &&
- Sum2 < FLimit &&
- (x[5] - x[4]) < QStep &&
- (x[4] - x[5]) < QStep ){
-
- /* low pass filtering (LPF7: 1 1 1 2 1 1 1) */
- Des[0 ] = (x[0] + x[0] +x[0] + x[1] * 2 +
- x[2] + x[3] +x[4] + 4) >> 3;
- Des[PlaneLineStep ] = (x[0] + x[0] +x[1] + x[2] * 2 +
- x[3] + x[4] +x[5] + 4) >> 3;
- Des[PlaneLineStep*2] = (x[0] + x[1] +x[2] + x[3] * 2 +
- x[4] + x[5] +x[6] + 4) >> 3;
- Des[PlaneLineStep*3] = (x[1] + x[2] +x[3] + x[4] * 2 +
- x[5] + x[6] +x[7] + 4) >> 3;
- Des[PlaneLineStep*4] = (x[2] + x[3] +x[4] + x[5] * 2 +
- x[6] + x[7] +x[8] + 4) >> 3;
- Des[PlaneLineStep*5] = (x[3] + x[4] +x[5] + x[6] * 2 +
- x[7] + x[8] +x[9] + 4) >> 3;
- Des[PlaneLineStep*6] = (x[4] + x[5] +x[6] + x[7] * 2 +
- x[8] + x[9] +x[9] + 4) >> 3;
- Des[PlaneLineStep*7] = (x[5] + x[6] +x[7] + x[8] * 2 +
- x[9] + x[9] +x[9] + 4) >> 3;
-
- }else {
- /* copy the pixels to destination */
- Des[0 ]= (unsigned char)x[1];
- Des[PlaneLineStep ]= (unsigned char)x[2];
- Des[PlaneLineStep*2]= (unsigned char)x[3];
- Des[PlaneLineStep*3]= (unsigned char)x[4];
- Des[PlaneLineStep*4]= (unsigned char)x[5];
- Des[PlaneLineStep*5]= (unsigned char)x[6];
- Des[PlaneLineStep*6]= (unsigned char)x[7];
- Des[PlaneLineStep*7]= (unsigned char)x[8];
- }
- Src ++;
- Des ++;
- }
-
-
- /* done with filtering the horizontal edge, now let's do the
- vertical one */
- /* skip the first one */
- if(CurrentFrag==StartFrag)
- CurrentFrag++;
- else{
- Des=DesPtr-8*PlaneLineStep+8*(CurrentFrag-StartFrag);
- Src=Des-5;
- Des-=4;
-
- QStep = QuantScale[pbi->FragQIndex[CurrentFrag]];
- FLimit = ( QStep * 3 ) >> 2;
-
- for( j=0; j<8 ; j++){
- x[0] = Src[0];
- x[1] = Src[1];
- x[2] = Src[2];
- x[3] = Src[3];
- x[4] = Src[4];
- x[5] = Src[5];
- x[6] = Src[6];
- x[7] = Src[7];
- x[8] = Src[8];
- x[9] = Src[9];
-
- Sum1=Sum2=0;
-
- for(k=1;k<=4;k++){
- Sum1 += abs(x[k]-x[k-1]);
- Sum2 += abs(x[k+4]-x[k+5]);
- }
-
- pbi->FragmentVariances[CurrentFrag-1] += ((Sum1>255)?255:Sum1);
- pbi->FragmentVariances[CurrentFrag] += ((Sum2>255)?255:Sum2);
-
- if( Sum1 < FLimit &&
- Sum2 < FLimit &&
- (x[5] - x[4]) < QStep &&
- (x[4] - x[5]) < QStep ){
-
- /* low pass filtering (LPF7: 1 1 1 2 1 1 1) */
- Des[0] = (x[0] + x[0] +x[0] + x[1] * 2 + x[2] + x[3] +x[4] + 4) >> 3;
- Des[1] = (x[0] + x[0] +x[1] + x[2] * 2 + x[3] + x[4] +x[5] + 4) >> 3;
- Des[2] = (x[0] + x[1] +x[2] + x[3] * 2 + x[4] + x[5] +x[6] + 4) >> 3;
- Des[3] = (x[1] + x[2] +x[3] + x[4] * 2 + x[5] + x[6] +x[7] + 4) >> 3;
- Des[4] = (x[2] + x[3] +x[4] + x[5] * 2 + x[6] + x[7] +x[8] + 4) >> 3;
- Des[5] = (x[3] + x[4] +x[5] + x[6] * 2 + x[7] + x[8] +x[9] + 4) >> 3;
- Des[6] = (x[4] + x[5] +x[6] + x[7] * 2 + x[8] + x[9] +x[9] + 4) >> 3;
- Des[7] = (x[5] + x[6] +x[7] + x[8] * 2 + x[9] + x[9] +x[9] + 4) >> 3;
- }
-
- Src += PlaneLineStep;
- Des += PlaneLineStep;
- }
- CurrentFrag ++;
- }
- }
-}
-
-static void DeblockVerticalEdgesInLoopFilteredBand(PB_INSTANCE *pbi,
- unsigned char *SrcPtr,
- unsigned char *DesPtr,
- ogg_uint32_t PlaneLineStep,
- ogg_uint32_t FragsAcross,
- ogg_uint32_t StartFrag,
- const ogg_uint32_t *QuantScale){
- ogg_uint32_t j,k;
- ogg_uint32_t CurrentFrag=StartFrag;
- ogg_int32_t QStep;
- ogg_int32_t FLimit;
- unsigned char *Src, *Des;
- ogg_int32_t x[10];
- ogg_int32_t Sum1, Sum2;
-
- while(CurrentFrag < StartFrag + FragsAcross-1) {
-
- Src=SrcPtr+8*(CurrentFrag-StartFrag+1)-5;
- Des=DesPtr+8*(CurrentFrag-StartFrag+1)-4;
-
- QStep = QuantScale[pbi->FragQIndex[CurrentFrag+1]];
- FLimit = ( QStep * 3)>>2 ;
-
- for( j=0; j<8 ; j++){
- x[0] = Src[0];
- x[1] = Src[1];
- x[2] = Src[2];
- x[3] = Src[3];
- x[4] = Src[4];
- x[5] = Src[5];
- x[6] = Src[6];
- x[7] = Src[7];
- x[8] = Src[8];
- x[9] = Src[9];
-
- Sum1=Sum2=0;
-
- for(k=1;k<=4;k++){
- Sum1 += abs(x[k]-x[k-1]);
- Sum2 += abs(x[k+4]-x[k+5]);
- }
-
- pbi->FragmentVariances[CurrentFrag] += ((Sum1>255)?255:Sum1);
- pbi->FragmentVariances[CurrentFrag+1] += ((Sum2>255)?255:Sum2);
-
-
- if( Sum1 < FLimit &&
- Sum2 < FLimit &&
- (x[5] - x[4]) < QStep &&
- (x[4] - x[5]) < QStep ){
-
- /* low pass filtering (LPF7: 1 1 1 2 1 1 1) */
- Des[0] = (x[0] + x[0] +x[0] + x[1] * 2 + x[2] + x[3] +x[4] + 4) >> 3;
- Des[1] = (x[0] + x[0] +x[1] + x[2] * 2 + x[3] + x[4] +x[5] + 4) >> 3;
- Des[2] = (x[0] + x[1] +x[2] + x[3] * 2 + x[4] + x[5] +x[6] + 4) >> 3;
- Des[3] = (x[1] + x[2] +x[3] + x[4] * 2 + x[5] + x[6] +x[7] + 4) >> 3;
- Des[4] = (x[2] + x[3] +x[4] + x[5] * 2 + x[6] + x[7] +x[8] + 4) >> 3;
- Des[5] = (x[3] + x[4] +x[5] + x[6] * 2 + x[7] + x[8] +x[9] + 4) >> 3;
- Des[6] = (x[4] + x[5] +x[6] + x[7] * 2 + x[8] + x[9] +x[9] + 4) >> 3;
- Des[7] = (x[5] + x[6] +x[7] + x[8] * 2 + x[9] + x[9] +x[9] + 4) >> 3;
- }
- Src +=PlaneLineStep;
- Des +=PlaneLineStep;
-
- }
- CurrentFrag ++;
- }
-}
-
-static void DeblockPlane(PB_INSTANCE *pbi,
- unsigned char *SourceBuffer,
- unsigned char *DestinationBuffer,
- ogg_uint32_t Channel ){
-
- ogg_uint32_t i,k;
- ogg_uint32_t PlaneLineStep=0;
- ogg_uint32_t StartFrag =0;
- ogg_uint32_t PixelIndex=0;
- unsigned char * SrcPtr=0, * DesPtr=0;
- ogg_uint32_t FragsAcross=0;
- ogg_uint32_t FragsDown=0;
- const ogg_uint32_t *QuantScale=0;
-
- switch( Channel ){
- case 0:
- /* Get the parameters */
- PlaneLineStep = pbi->YStride;
- FragsAcross = pbi->HFragments;
- FragsDown = pbi->VFragments;
- StartFrag = 0;
- PixelIndex = pbi->ReconYDataOffset;
- SrcPtr = & SourceBuffer[PixelIndex];
- DesPtr = & DestinationBuffer[PixelIndex];
- break;
-
- case 1:
- /* Get the parameters */
- PlaneLineStep = pbi->UVStride;
- FragsAcross = pbi->HFragments / 2;
- FragsDown = pbi->VFragments / 2;
- StartFrag = pbi->YPlaneFragments;
-
- PixelIndex = pbi->ReconUDataOffset;
- SrcPtr = & SourceBuffer[PixelIndex];
- DesPtr = & DestinationBuffer[PixelIndex];
- break;
-
- default:
- /* Get the parameters */
- PlaneLineStep = pbi->UVStride;
- FragsAcross = pbi->HFragments / 2;
- FragsDown = pbi->VFragments / 2;
- StartFrag = pbi->YPlaneFragments + pbi->UVPlaneFragments;
-
- PixelIndex = pbi->ReconVDataOffset;
- SrcPtr = & SourceBuffer[PixelIndex];
- DesPtr = & DestinationBuffer[PixelIndex];
- break;
- }
-
- QuantScale = DcQuantScaleV1;
-
- for(i=0;i<4;i++)
- memcpy(DesPtr+i*PlaneLineStep, SrcPtr+i*PlaneLineStep, PlaneLineStep);
-
- k = 1;
-
- while( k < FragsDown ){
-
- SrcPtr += 8*PlaneLineStep;
- DesPtr += 8*PlaneLineStep;
-
- /* Filter both the horizontal and vertical block edges inside the band */
- DeblockLoopFilteredBand(pbi, SrcPtr, DesPtr, PlaneLineStep,
- FragsAcross, StartFrag, QuantScale);
-
- /* Move Pointers */
- StartFrag += FragsAcross;
-
- k ++;
- }
-
- /* The Last band */
- for(i=0;i<4;i++)
- memcpy(DesPtr+(i+4)*PlaneLineStep,
- SrcPtr+(i+4)*PlaneLineStep,
- PlaneLineStep);
-
- DeblockVerticalEdgesInLoopFilteredBand(pbi,SrcPtr,DesPtr,PlaneLineStep,
- FragsAcross,StartFrag,QuantScale);
-
-}
-
-static void DeblockFrame(PB_INSTANCE *pbi, unsigned char *SourceBuffer,
- unsigned char *DestinationBuffer){
-
- memset(pbi->FragmentVariances, 0 , sizeof(ogg_int32_t) * pbi->UnitFragments);
-
-
- UpdateFragQIndex(pbi);
-
-
- SetupLoopFilter(pbi);
-
- /* Y */
- DeblockPlane( pbi, SourceBuffer, DestinationBuffer, 0);
-
- /* U */
- DeblockPlane( pbi, SourceBuffer, DestinationBuffer, 1);
-
- /* V */
- DeblockPlane( pbi, SourceBuffer, DestinationBuffer, 2);
-
-}
-
-void PostProcess(PB_INSTANCE *pbi){
-
- switch (pbi->PostProcessingLevel){
- case 8:
- /* on a slow machine, use a simpler and faster deblocking filter */
- DeblockFrame(pbi, pbi->LastFrameRecon,pbi->PostProcessBuffer);
- break;
-
- case 6:
- DeblockFrame(pbi, pbi->LastFrameRecon,pbi->PostProcessBuffer);
- UpdateUMVBorder(pbi, pbi->PostProcessBuffer );
- DeringFrame(pbi, pbi->PostProcessBuffer, pbi->PostProcessBuffer);
- break;
-
- case 5:
- DeblockFrame(pbi, pbi->LastFrameRecon,pbi->PostProcessBuffer);
- UpdateUMVBorder(pbi, pbi->PostProcessBuffer );
- DeringFrame(pbi, pbi->PostProcessBuffer, pbi->PostProcessBuffer);
- break;
- case 4:
- DeblockFrame(pbi, pbi->LastFrameRecon, pbi->PostProcessBuffer);
- break;
- case 1:
- UpdateFragQIndex(pbi);
- break;
-
- case 0:
- break;
-
- default:
- DeblockFrame(pbi, pbi->LastFrameRecon, pbi->PostProcessBuffer);
- UpdateUMVBorder(pbi, pbi->PostProcessBuffer );
- DeringFrame(pbi, pbi->PostProcessBuffer, pbi->PostProcessBuffer);
- break;
- }
-}
-
Deleted: branches/theora-thusnelda/lib/enc/pp.h
===================================================================
--- branches/theora-thusnelda/lib/enc/pp.h 2007-11-20 02:45:44 UTC (rev 14198)
+++ branches/theora-thusnelda/lib/enc/pp.h 2007-11-20 14:33:26 UTC (rev 14199)
@@ -1,48 +0,0 @@
-/********************************************************************
- * *
- * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
- * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
- * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
- * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
- * *
- * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2007 *
- * by the Xiph.Org Foundation http://www.xiph.org/ *
- * *
- ********************************************************************
-
- function:
- last mod: $Id$
-
- ********************************************************************/
-
-/* Constants. */
-#define INTERNAL_BLOCK_HEIGHT 8
-#define INTERNAL_BLOCK_WIDTH 8
-
-
-/* NEW Line search values. */
-#define UP 0
-#define DOWN 1
-#define LEFT 2
-#define RIGHT 3
-
-#define FIRST_ROW 0
-#define NOT_EDGE_ROW 1
-#define LAST_ROW 2
-
-#define YDIFF_CB_ROWS (INTERNAL_BLOCK_HEIGHT * 3)
-#define CHLOCALS_CB_ROWS (INTERNAL_BLOCK_HEIGHT * 3)
-#define PMAP_CB_ROWS (INTERNAL_BLOCK_HEIGHT * 3)
-#define PSCORE_CB_ROWS (INTERNAL_BLOCK_HEIGHT * 4)
-
-/* Status values in block coding map */
-#define CANDIDATE_BLOCK_LOW -2
-#define CANDIDATE_BLOCK -1
-#define BLOCK_NOT_CODED 0
-#define BLOCK_CODED_BAR 3
-#define BLOCK_CODED_SGC 4
-#define BLOCK_CODED_LOW 4
-#define BLOCK_CODED 5
-
-#define MAX_PREV_FRAMES 16
-#define MAX_SEARCH_LINE_LEN 7
Deleted: branches/theora-thusnelda/lib/enc/scan.c
===================================================================
--- branches/theora-thusnelda/lib/enc/scan.c 2007-11-20 02:45:44 UTC (rev 14198)
+++ branches/theora-thusnelda/lib/enc/scan.c 2007-11-20 14:33:26 UTC (rev 14199)
@@ -1,2259 +0,0 @@
-/********************************************************************
- * *
- * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
- * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
- * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
- * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
- * *
- * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2007 *
- * by the Xiph.Org Foundation http://www.xiph.org/ *
- * *
- ********************************************************************
-
- function:
- last mod: $Id$
-
- ********************************************************************/
-
-#include <stdlib.h>
-#include <math.h>
-#include <string.h>
-#include "codec_internal.h"
-#include "dsp.h"
-
-#define MAX_SEARCH_LINE_LEN 7
-
-#define SET8_0(ptr) \
- ((ogg_uint32_t *)ptr)[0] = 0x00000000; \
- ((ogg_uint32_t *)ptr)[1] = 0x00000000;
-#define SET8_1(ptr) \
- ((ogg_uint32_t *)ptr)[0] = 0x01010101; \
- ((ogg_uint32_t *)ptr)[1] = 0x01010101;
-#define SET8_8(ptr) \
- ((ogg_uint32_t *)ptr)[0] = 0x08080808; \
- ((ogg_uint32_t *)ptr)[1] = 0x08080808;
-
-static ogg_uint32_t LineLengthScores[ MAX_SEARCH_LINE_LEN + 1 ] = {
- 0, 0, 0, 0, 2, 4, 12, 24
-};
-
-static ogg_uint32_t BodyNeighbourScore = 8;
-static double DiffDevisor = 0.0625;
-#define HISTORY_BLOCK_FACTOR 2
-#define MIN_STEP_THRESH 6
-#define SCORE_MULT_LOW 0.5
-#define SCORE_MULT_HIGH 4
-
-#define UP 0
-#define DOWN 1
-#define LEFT 2
-#define RIGHT 3
-
-#define INTERNAL_BLOCK_HEIGHT 8
-#define INTERNAL_BLOCK_WIDTH 8
-
-#define BLOCK_NOT_CODED 0
-#define BLOCK_CODED_BAR 3
-#define BLOCK_CODED_SGC 4
-#define BLOCK_CODED_LOW 4
-#define BLOCK_CODED 5
-
-#define CANDIDATE_BLOCK_LOW -2
-#define CANDIDATE_BLOCK -1
-
-#define FIRST_ROW 0
-#define NOT_EDGE_ROW 1
-#define LAST_ROW 2
-
-#define YDIFF_CB_ROWS (INTERNAL_BLOCK_HEIGHT * 3)
-#define CHLOCALS_CB_ROWS (INTERNAL_BLOCK_HEIGHT * 3)
-#define PMAP_CB_ROWS (INTERNAL_BLOCK_HEIGHT * 3)
-
-void ConfigurePP( PP_INSTANCE *ppi, int Level ) {
- switch ( Level ){
- case 0:
- ppi->SRFGreyThresh = 1;
- ppi->SRFColThresh = 1;
- ppi->NoiseSupLevel = 2;
- ppi->SgcLevelThresh = 1;
- ppi->SuvcLevelThresh = 1;
- ppi->GrpLowSadThresh = 6;
- ppi->GrpHighSadThresh = 24;
- ppi->PrimaryBlockThreshold = 2;
- ppi->SgcThresh = 10;
-
- ppi->PAKEnabled = 0;
- break;
-
- case 1:
- ppi->SRFGreyThresh = 2;
- ppi->SRFColThresh = 2;
- ppi->NoiseSupLevel = 2;
- ppi->SgcLevelThresh = 2;
- ppi->SuvcLevelThresh = 2;
- ppi->GrpLowSadThresh = 8;
- ppi->GrpHighSadThresh = 32;
- ppi->PrimaryBlockThreshold = 5;
- ppi->SgcThresh = 12;
-
- ppi->PAKEnabled = 1;
- break;
-
- case 2: /* Default VP3 settings */
- ppi->SRFGreyThresh = 3;
- ppi->SRFColThresh = 3;
- ppi->NoiseSupLevel = 2;
- ppi->SgcLevelThresh = 2;
- ppi->SuvcLevelThresh = 2;
- ppi->GrpLowSadThresh = 8;
- ppi->GrpHighSadThresh = 32;
- ppi->PrimaryBlockThreshold = 5;
- ppi->SgcThresh = 16;
-
- ppi->PAKEnabled = 1;
- break;
-
- case 3:
- ppi->SRFGreyThresh = 4;
- ppi->SRFColThresh = 4;
- ppi->NoiseSupLevel = 3;
- ppi->SgcLevelThresh = 3;
- ppi->SuvcLevelThresh = 3;
- ppi->GrpLowSadThresh = 10;
- ppi->GrpHighSadThresh = 48;
- ppi->PrimaryBlockThreshold = 5;
- ppi->SgcThresh = 18;
-
- ppi->PAKEnabled = 1;
- break;
-
- case 4:
- ppi->SRFGreyThresh = 5;
- ppi->SRFColThresh = 5;
- ppi->NoiseSupLevel = 3;
- ppi->SgcLevelThresh = 4;
- ppi->SuvcLevelThresh = 4;
- ppi->GrpLowSadThresh = 12;
- ppi->GrpHighSadThresh = 48;
- ppi->PrimaryBlockThreshold = 5;
- ppi->SgcThresh = 20;
-
- ppi->PAKEnabled = 1;
- break;
-
- case 5:
- ppi->SRFGreyThresh = 6;
- ppi->SRFColThresh = 6;
- ppi->NoiseSupLevel = 3;
- ppi->SgcLevelThresh = 4;
- ppi->SuvcLevelThresh = 4;
- ppi->GrpLowSadThresh = 12;
- ppi->GrpHighSadThresh = 64;
- ppi->PrimaryBlockThreshold = 10;
- ppi->SgcThresh = 24;
-
- ppi->PAKEnabled = 1;
- break;
-
- case 6:
- ppi->SRFGreyThresh = 6;
- ppi->SRFColThresh = 7;
- ppi->NoiseSupLevel = 3;
- ppi->SgcLevelThresh = 4;
- ppi->SuvcLevelThresh = 4;
- ppi->GrpLowSadThresh = 12;
- ppi->GrpHighSadThresh = 64;
- ppi->PrimaryBlockThreshold = 10;
- ppi->SgcThresh = 24;
-
- ppi->PAKEnabled = 1;
- break;
-
- default:
- ppi->SRFGreyThresh = 3;
- ppi->SRFColThresh = 3;
- ppi->NoiseSupLevel = 2;
- ppi->SgcLevelThresh = 2;
- ppi->SuvcLevelThresh = 2;
- ppi->GrpLowSadThresh = 10;
- ppi->GrpHighSadThresh = 32;
- ppi->PrimaryBlockThreshold = 5;
- ppi->SgcThresh = 16;
- ppi->PAKEnabled = 1;
- break;
- }
-}
-
-static void ScanCalcPixelIndexTable(PP_INSTANCE *ppi){
- ogg_uint32_t i;
- ogg_uint32_t * PixelIndexTablePtr = ppi->ScanPixelIndexTable;
-
- /* If appropriate add on extra inices for U and V planes. */
- for ( i = 0; i < (ppi->ScanYPlaneFragments); i++ ) {
- PixelIndexTablePtr[ i ] =
- ((i / ppi->ScanHFragments) *
- VFRAGPIXELS * ppi->ScanConfig.VideoFrameWidth);
- PixelIndexTablePtr[ i ] +=
- ((i % ppi->ScanHFragments) * HFRAGPIXELS);
- }
-
- PixelIndexTablePtr = &ppi->ScanPixelIndexTable[ppi->ScanYPlaneFragments];
-
- for ( i = 0; i < (ppi->ScanUVPlaneFragments * 2); i++ ){
- PixelIndexTablePtr[ i ] =
- ((i / (ppi->ScanHFragments >> 1) ) *
- (VFRAGPIXELS * (ppi->ScanConfig.VideoFrameWidth >> 1)) );
- PixelIndexTablePtr[ i ] +=
- ((i % (ppi->ScanHFragments >> 1) ) *
- HFRAGPIXELS) + ppi->YFramePixels;
- }
-}
-
-static void InitScanMapArrays(PP_INSTANCE *ppi){
- int i;
- unsigned char StepThresh;
-
- /* Clear down the fragment level map arrays for the current frame. */
- memset( ppi->FragScores, 0,
- ppi->ScanFrameFragments * sizeof(*ppi->FragScores) );
- memset( ppi->SameGreyDirPixels, 0,
- ppi->ScanFrameFragments );
- memset( ppi->FragDiffPixels, 0,
- ppi->ScanFrameFragments );
- memset( ppi->RowChangedPixels, 0,
- 3* ppi->ScanConfig.VideoFrameHeight*sizeof(*ppi->RowChangedPixels));
-
- memset( ppi->ScanDisplayFragments, BLOCK_NOT_CODED, ppi->ScanFrameFragments);
-
- /* Threshold used in setting up ppi->NoiseScoreBoostTable[] */
- StepThresh = (unsigned int)(ppi->SRFGreyThresh >> 1);
- if ( StepThresh < MIN_STEP_THRESH )
- StepThresh = MIN_STEP_THRESH;
- ppi->SrfThresh = (int)ppi->SRFGreyThresh;
-
- /* Set up various tables used to tweak pixel score values and
- scoring rules based upon absolute value of a pixel change */
- for ( i = 0; i < 256; i++ ){
- /* Score multiplier table indexed by absolute difference. */
- ppi->AbsDiff_ScoreMultiplierTable[i] = (double)i * DiffDevisor;
- if ( ppi->AbsDiff_ScoreMultiplierTable[i] < SCORE_MULT_LOW )
- ppi->AbsDiff_ScoreMultiplierTable[i] = SCORE_MULT_LOW;
- else if ( ppi->AbsDiff_ScoreMultiplierTable[i] > SCORE_MULT_HIGH)
- ppi->AbsDiff_ScoreMultiplierTable[i] = SCORE_MULT_HIGH;
-
- /* Table that facilitates a relaxation of the changed locals rules
- in NoiseScoreRow() for pixels that have changed by a large
- amount. */
- if ( i < (ppi->SrfThresh + StepThresh) )
- ppi->NoiseScoreBoostTable[i] = 0;
- else if ( i < (ppi->SrfThresh + (StepThresh * 4)) )
- ppi->NoiseScoreBoostTable[i] = 1;
- else if ( i < (ppi->SrfThresh + (StepThresh * 6)) )
- ppi->NoiseScoreBoostTable[i] = 2;
- else
- ppi->NoiseScoreBoostTable[i] = 3;
-
- }
-
- /* Set various other threshold parameters. */
-
- /* Set variables that control access to the line search algorithms. */
- ppi->LineSearchTripTresh = 16;
- if ( ppi->LineSearchTripTresh > ppi->PrimaryBlockThreshold )
- ppi->LineSearchTripTresh = (unsigned int)(ppi->PrimaryBlockThreshold + 1);
-
- /* Adjust line search length if block threshold low */
- ppi->MaxLineSearchLen = MAX_SEARCH_LINE_LEN;
- while ( (ppi->MaxLineSearchLen > 0) &&
- (LineLengthScores[ppi->MaxLineSearchLen-1] >
- ppi->PrimaryBlockThreshold) )
- ppi->MaxLineSearchLen -= 1;
-
-}
-
-void ScanYUVInit( PP_INSTANCE * ppi, SCAN_CONFIG_DATA * ScanConfigPtr){
- int i;
-
- /* Set up the various imported data structure pointers. */
- ppi->ScanConfig.Yuv0ptr = ScanConfigPtr->Yuv0ptr;
- ppi->ScanConfig.Yuv1ptr = ScanConfigPtr->Yuv1ptr;
- ppi->ScanConfig.disp_fragments = ScanConfigPtr->disp_fragments;
-
- ppi->ScanConfig.RegionIndex = ScanConfigPtr->RegionIndex;
-
- ppi->ScanConfig.VideoFrameWidth = ScanConfigPtr->VideoFrameWidth;
- ppi->ScanConfig.VideoFrameHeight = ScanConfigPtr->VideoFrameHeight;
-
- /* UV plane sizes. */
- ppi->VideoUVPlaneWidth = ScanConfigPtr->VideoFrameWidth / 2;
- ppi->VideoUVPlaneHeight = ScanConfigPtr->VideoFrameHeight / 2;
-
- /* Note the size of each plane in pixels. */
- ppi->YFramePixels = ppi->ScanConfig.VideoFrameWidth *
- ppi->ScanConfig.VideoFrameHeight;
- ppi->UVFramePixels = ppi->VideoUVPlaneWidth * ppi->VideoUVPlaneHeight;
-
- /* Work out various fragment related values. */
- ppi->ScanYPlaneFragments = ppi->YFramePixels /
- (HFRAGPIXELS * VFRAGPIXELS);
- ppi->ScanUVPlaneFragments = ppi->UVFramePixels /
- (HFRAGPIXELS * VFRAGPIXELS);;
- ppi->ScanHFragments = ppi->ScanConfig.VideoFrameWidth / HFRAGPIXELS;
- ppi->ScanVFragments = ppi->ScanConfig.VideoFrameHeight / VFRAGPIXELS;
- ppi->ScanFrameFragments = ppi->ScanYPlaneFragments +
- (2 * ppi->ScanUVPlaneFragments);
-
- PInitFrameInfo(ppi);
-
- /* Set up the scan pixel index table. */
- ScanCalcPixelIndexTable(ppi);
-
- /* Initialise the previous frame block history lists */
- for ( i = 0; i < MAX_PREV_FRAMES; i++ )
- memset( ppi->PrevFragments[i], BLOCK_NOT_CODED, ppi->ScanFrameFragments);
-
- /* YUVAnalyseFrame() is not called for the first frame in a sequence
- (a key frame obviously). This memset insures that for the second
- frame all blocks are marked for coding in line with the behaviour
- for other key frames. */
- memset( ppi->PrevFragments[ppi->PrevFrameLimit-1],
- BLOCK_CODED, ppi->ScanFrameFragments );
-
- /* Initialise scan arrays */
- InitScanMapArrays(ppi);
-}
-
-static void SetFromPrevious(PP_INSTANCE *ppi) {
- unsigned int i,j;
-
- /* We buld up the list of previously updated blocks in the zero
- index list of PrevFragments[] so we must start by reseting its
- contents */
- memset( ppi->PrevFragments[0], BLOCK_NOT_CODED, ppi->ScanFrameFragments );
-
- if ( ppi->PrevFrameLimit > 1 ){
- /* Now build up PrevFragments[0] from PrevFragments[1 to PrevFrameLimit] */
- for ( i = 0; i < ppi->ScanFrameFragments; i++ ){
- for ( j = 1; j < ppi->PrevFrameLimit; j++ ){
- if ( ppi->PrevFragments[j][i] > BLOCK_CODED_BAR ){
- ppi->PrevFragments[0][i] = BLOCK_CODED;
- break;
- }
- }
- }
- }
-}
-
-static void UpdatePreviousBlockLists(PP_INSTANCE *ppi) {
- int i;
-
- /* Shift previous frame block lists along. */
- for ( i = ppi->PrevFrameLimit; i > 1; i-- ){
- memcpy( ppi->PrevFragments[i], ppi->PrevFragments[i-1],
- ppi->ScanFrameFragments );
- }
-
- /* Now copy in this frames block list */
- memcpy( ppi->PrevFragments[1], ppi->ScanDisplayFragments,
- ppi->ScanFrameFragments );
-}
-
-static void CreateOutputDisplayMap( PP_INSTANCE *ppi,
- signed char *InternalFragmentsPtr,
- signed char *RecentHistoryPtr,
- unsigned char *ExternalFragmentsPtr ) {
- ogg_uint32_t i;
- ogg_uint32_t HistoryBlocksAdded = 0;
- ogg_uint32_t YBand = (ppi->ScanYPlaneFragments/8); /* 1/8th of Y image. */
-
- ppi->OutputBlocksUpdated = 0;
- for ( i = 0; i < ppi->ScanFrameFragments; i++ ) {
- if ( InternalFragmentsPtr[i] > BLOCK_NOT_CODED ) {
- ppi->OutputBlocksUpdated ++;
- ExternalFragmentsPtr[i] = 1;
- }else if ( RecentHistoryPtr[i] == BLOCK_CODED ){
- HistoryBlocksAdded ++;
- ExternalFragmentsPtr[i] = 1;
- }else{
- ExternalFragmentsPtr[i] = 0;
- }
- }
-
- /* Add in a weighting for the history blocks that have been added */
- ppi->OutputBlocksUpdated += (HistoryBlocksAdded / HISTORY_BLOCK_FACTOR);
-
- /* Now calculate a key frame candidate indicator. This is based
- upon Y data only and ignores the top and bottom 1/8 of the
- image. Also ignore history blocks and BAR blocks. */
- ppi->KFIndicator = 0;
- for ( i = YBand; i < (ppi->ScanYPlaneFragments - YBand); i++ )
- if ( InternalFragmentsPtr[i] > BLOCK_CODED_BAR )
- ppi->KFIndicator ++;
-
- /* Convert the KF score to a range 0-100 */
- ppi->KFIndicator = ((ppi->KFIndicator*100)/((ppi->ScanYPlaneFragments*3)/4));
-}
-
-static int RowSadScan( PP_INSTANCE *ppi,
- unsigned char * YuvPtr1,
- unsigned char * YuvPtr2,
- signed char * DispFragPtr){
- ogg_int32_t i, j;
- ogg_uint32_t GrpSad;
- ogg_uint32_t LocalGrpLowSadThresh = ppi->ModifiedGrpLowSadThresh;
- ogg_uint32_t LocalGrpHighSadThresh = ppi->ModifiedGrpHighSadThresh;
- signed char *LocalDispFragPtr;
- unsigned char *LocalYuvPtr1;
- unsigned char *LocalYuvPtr2;
-
- int InterestingBlocksInRow = 0;
-
- /* For each row of pixels in the row of blocks */
- for ( j = 0; j < VFRAGPIXELS; j++ ){
- /* Set local block map pointer. */
- LocalDispFragPtr = DispFragPtr;
-
- /* Set the local pixel data pointers for this row.*/
- LocalYuvPtr1 = YuvPtr1;
- LocalYuvPtr2 = YuvPtr2;
-
- /* Scan along the row of pixels If the block to which a group of
- pixels belongs is already marked for update then do nothing. */
- for ( i = 0; i < ppi->PlaneHFragments; i ++ ){
- if ( *LocalDispFragPtr <= BLOCK_NOT_CODED ){
- /* Calculate the SAD score for the block row */
- GrpSad = dsp_row_sad8(ppi->dsp, LocalYuvPtr1,LocalYuvPtr2);
-
- /* Now test the group SAD score */
- if ( GrpSad > LocalGrpLowSadThresh ){
- /* If SAD very high we must update else we have candidate block */
- if ( GrpSad > LocalGrpHighSadThresh ){
- /* Force update */
- *LocalDispFragPtr = BLOCK_CODED;
- }else{
- /* Possible Update required */
- *LocalDispFragPtr = CANDIDATE_BLOCK;
- }
- InterestingBlocksInRow = 1;
- }
- }
- LocalDispFragPtr++;
-
- LocalYuvPtr1 += 8;
- LocalYuvPtr2 += 8;
- }
-
- /* Increment the base data pointers to the start of the next line. */
- YuvPtr1 += ppi->PlaneStride;
- YuvPtr2 += ppi->PlaneStride;
- }
-
- return InterestingBlocksInRow;
-
-}
-
-static int ColSadScan( PP_INSTANCE *ppi,
- unsigned char * YuvPtr1,
- unsigned char * YuvPtr2,
- signed char * DispFragPtr ){
- ogg_int32_t i;
- ogg_uint32_t MaxSad;
- ogg_uint32_t LocalGrpLowSadThresh = ppi->ModifiedGrpLowSadThresh;
- ogg_uint32_t LocalGrpHighSadThresh = ppi->ModifiedGrpHighSadThresh;
- signed char * LocalDispFragPtr;
-
- unsigned char * LocalYuvPtr1;
- unsigned char * LocalYuvPtr2;
-
- int InterestingBlocksInRow = 0;
-
- /* Set the local pixel data pointers for this row. */
- LocalYuvPtr1 = YuvPtr1;
- LocalYuvPtr2 = YuvPtr2;
-
- /* Set local block map pointer. */
- LocalDispFragPtr = DispFragPtr;
-
- /* Scan along the row of blocks */
- for ( i = 0; i < ppi->PlaneHFragments; i ++ ){
- /* Skip if block already marked to be coded. */
- if ( *LocalDispFragPtr <= BLOCK_NOT_CODED ){
- /* Calculate the SAD score for the block column */
- MaxSad = dsp_col_sad8x8(ppi->dsp, LocalYuvPtr1, LocalYuvPtr2, ppi->PlaneStride );
-
- /* Now test the group SAD score */
- if ( MaxSad > LocalGrpLowSadThresh ){
- /* If SAD very high we must update else we have candidate block */
- if ( MaxSad > LocalGrpHighSadThresh ){
- /* Force update */
- *LocalDispFragPtr = BLOCK_CODED;
- }else{
- /* Possible Update required */
- *LocalDispFragPtr = CANDIDATE_BLOCK;
- }
- InterestingBlocksInRow = 1;
- }
- }
-
- /* Increment the block map pointer. */
- LocalDispFragPtr++;
-
- /* Step data pointers on ready for next block */
- LocalYuvPtr1 += HFRAGPIXELS;
- LocalYuvPtr2 += HFRAGPIXELS;
- }
-
- return InterestingBlocksInRow;
-}
-
-static void SadPass2( PP_INSTANCE *ppi,
- ogg_int32_t RowNumber,
- signed char * DispFragPtr ){
- ogg_int32_t i;
-
- /* First row */
- if ( RowNumber == 0 ) {
- /* First block in row. */
- if ( DispFragPtr[0] == CANDIDATE_BLOCK ){
- if ( (DispFragPtr[1] == BLOCK_CODED) ||
- (DispFragPtr[ppi->PlaneHFragments] == BLOCK_CODED) ||
- (DispFragPtr[ppi->PlaneHFragments+1] == BLOCK_CODED) ){
- ppi->TmpCodedMap[0] = BLOCK_CODED_LOW;
- }else{
- ppi->TmpCodedMap[0] = DispFragPtr[0];
- }
- }else{
- ppi->TmpCodedMap[0] = DispFragPtr[0];
- }
-
- /* All but first and last in row */
- for ( i = 1; (i < ppi->PlaneHFragments-1); i++ ){
- if ( DispFragPtr[i] == CANDIDATE_BLOCK ){
- if ( (DispFragPtr[i-1] == BLOCK_CODED) ||
- (DispFragPtr[i+1] == BLOCK_CODED) ||
- (DispFragPtr[i+ppi->PlaneHFragments] == BLOCK_CODED) ||
- (DispFragPtr[i+ppi->PlaneHFragments-1] == BLOCK_CODED) ||
- (DispFragPtr[i+ppi->PlaneHFragments+1] == BLOCK_CODED) ){
- ppi->TmpCodedMap[i] = BLOCK_CODED_LOW;
- }else{
- ppi->TmpCodedMap[i] = DispFragPtr[i];
- }
- }else{
- ppi->TmpCodedMap[i] = DispFragPtr[i];
- }
- }
-
- /* Last block in row. */
- i = ppi->PlaneHFragments-1;
- if ( DispFragPtr[i] == CANDIDATE_BLOCK ){
- if ( (DispFragPtr[i-1] == BLOCK_CODED) ||
- (DispFragPtr[i+ppi->PlaneHFragments] == BLOCK_CODED) ||
- (DispFragPtr[i+ppi->PlaneHFragments-1] == BLOCK_CODED) ){
- ppi->TmpCodedMap[i] = BLOCK_CODED_LOW;
- }else{
- ppi->TmpCodedMap[i] = DispFragPtr[i];
- }
- }else{
- ppi->TmpCodedMap[i] = DispFragPtr[i];
- }
- }else if ( RowNumber < (ppi->PlaneVFragments - 1) ){
- /* General case */
- /* First block in row. */
- if ( DispFragPtr[0] == CANDIDATE_BLOCK ){
- if ( (DispFragPtr[1] == BLOCK_CODED) ||
- (DispFragPtr[(-ppi->PlaneHFragments)] == BLOCK_CODED) ||
- (DispFragPtr[(-ppi->PlaneHFragments)+1] == BLOCK_CODED) ||
- (DispFragPtr[ppi->PlaneHFragments] == BLOCK_CODED) ||
- (DispFragPtr[ppi->PlaneHFragments+1] == BLOCK_CODED) ){
- ppi->TmpCodedMap[0] = BLOCK_CODED_LOW;
- }else{
- ppi->TmpCodedMap[0] = DispFragPtr[0];
- }
- }else{
- ppi->TmpCodedMap[0] = DispFragPtr[0];
- }
-
- /* All but first and last in row */
- for ( i = 1; (i < ppi->PlaneHFragments-1); i++ ){
- if ( DispFragPtr[i] == CANDIDATE_BLOCK ){
- if ( (DispFragPtr[i-1] == BLOCK_CODED) ||
- (DispFragPtr[i+1] == BLOCK_CODED) ||
- (DispFragPtr[i-ppi->PlaneHFragments] == BLOCK_CODED) ||
- (DispFragPtr[i-ppi->PlaneHFragments-1] == BLOCK_CODED) ||
- (DispFragPtr[i-ppi->PlaneHFragments+1] == BLOCK_CODED) ||
- (DispFragPtr[i+ppi->PlaneHFragments] == BLOCK_CODED) ||
- (DispFragPtr[i+ppi->PlaneHFragments-1] == BLOCK_CODED) ||
- (DispFragPtr[i+ppi->PlaneHFragments+1] == BLOCK_CODED) ){
- ppi->TmpCodedMap[i] = BLOCK_CODED_LOW;
- }else{
- ppi->TmpCodedMap[i] = DispFragPtr[i];
- }
- }else{
- ppi->TmpCodedMap[i] = DispFragPtr[i];
- }
- }
-
- /* Last block in row. */
- i = ppi->PlaneHFragments-1;
- if ( DispFragPtr[i] == CANDIDATE_BLOCK ){
- if ( (DispFragPtr[i-1] == BLOCK_CODED) ||
- (DispFragPtr[i-ppi->PlaneHFragments] == BLOCK_CODED) ||
- (DispFragPtr[i-ppi->PlaneHFragments-1] == BLOCK_CODED) ||
- (DispFragPtr[i+ppi->PlaneHFragments] == BLOCK_CODED) ||
- (DispFragPtr[i+ppi->PlaneHFragments-1] == BLOCK_CODED) ){
- ppi->TmpCodedMap[i] = BLOCK_CODED_LOW;
- }else{
- ppi->TmpCodedMap[i] = DispFragPtr[i];
- }
- }else{
- ppi->TmpCodedMap[i] = DispFragPtr[i];
- }
- }else{
- /* Last row */
- /* First block in row. */
- if ( DispFragPtr[0] == CANDIDATE_BLOCK ){
- if ( (DispFragPtr[1] == BLOCK_CODED) ||
- (DispFragPtr[(-ppi->PlaneHFragments)] == BLOCK_CODED) ||
- (DispFragPtr[(-ppi->PlaneHFragments)+1] == BLOCK_CODED)){
- ppi->TmpCodedMap[0] = BLOCK_CODED_LOW;
- }else{
- ppi->TmpCodedMap[0] = DispFragPtr[0];
- }
- }else{
- ppi->TmpCodedMap[0] = DispFragPtr[0];
- }
-
- /* All but first and last in row */
- for ( i = 1; (i < ppi->PlaneHFragments-1); i++ ){
- if ( DispFragPtr[i] == CANDIDATE_BLOCK ){
- if ( (DispFragPtr[i-1] == BLOCK_CODED) ||
- (DispFragPtr[i+1] == BLOCK_CODED) ||
- (DispFragPtr[i-ppi->PlaneHFragments] == BLOCK_CODED) ||
- (DispFragPtr[i-ppi->PlaneHFragments-1] == BLOCK_CODED) ||
- (DispFragPtr[i-ppi->PlaneHFragments+1] == BLOCK_CODED) ){
- ppi->TmpCodedMap[i] = BLOCK_CODED_LOW;
- }else{
- ppi->TmpCodedMap[i] = DispFragPtr[i];
- }
- }else{
- ppi->TmpCodedMap[i] = DispFragPtr[i];
- }
- }
-
- /* Last block in row. */
- i = ppi->PlaneHFragments-1;
- if ( DispFragPtr[i] == CANDIDATE_BLOCK ){
- if ( (DispFragPtr[i-1] == BLOCK_CODED) ||
- (DispFragPtr[i-ppi->PlaneHFragments] == BLOCK_CODED) ||
- (DispFragPtr[i-ppi->PlaneHFragments-1] == BLOCK_CODED) ){
- ppi->TmpCodedMap[i] = BLOCK_CODED_LOW;
- }else{
- ppi->TmpCodedMap[i] = DispFragPtr[i];
- }
- }else{
- ppi->TmpCodedMap[i] = DispFragPtr[i];
- }
- }
-
- /* Now copy back the modified Fragment data */
- memcpy( &DispFragPtr[0], &ppi->TmpCodedMap[0], (ppi->PlaneHFragments) );
-}
-
-static unsigned char ApplyPakLowPass( PP_INSTANCE *ppi,
- unsigned char * SrcPtr ){
- unsigned char * SrcPtr1 = SrcPtr - 1;
- unsigned char * SrcPtr0 = SrcPtr1 - ppi->PlaneStride; /* Note the
- use of
- stride not
- width. */
- unsigned char * SrcPtr2 = SrcPtr1 + ppi->PlaneStride;
-
- return (unsigned char)( ( (ogg_uint32_t)SrcPtr0[0] +
- (ogg_uint32_t)SrcPtr0[1] +
- (ogg_uint32_t)SrcPtr0[2] +
- (ogg_uint32_t)SrcPtr1[0] +
- (ogg_uint32_t)SrcPtr1[2] +
- (ogg_uint32_t)SrcPtr2[0] +
- (ogg_uint32_t)SrcPtr2[1] +
- (ogg_uint32_t)SrcPtr2[2] ) >> 3 );
-
-}
-
-static void RowDiffScan( PP_INSTANCE *ppi,
- unsigned char * YuvPtr1,
- unsigned char * YuvPtr2,
- ogg_int16_t * YUVDiffsPtr,
- unsigned char * bits_map_ptr,
- signed char * SgcPtr,
- signed char * DispFragPtr,
- unsigned char * FDiffPixels,
- ogg_int32_t * RowDiffsPtr,
- unsigned char * ChLocalsPtr, int EdgeRow ){
-
- ogg_int32_t i,j;
- ogg_int32_t FragChangedPixels;
-
- ogg_int16_t Diff; /* Temp local workspace. */
-
- /* Cannot use kernel if at edge or if PAK disabled */
- if ( (!ppi->PAKEnabled) || EdgeRow ){
- for ( i = 0; i < ppi->PlaneWidth; i += HFRAGPIXELS ){
- /* Reset count of pixels changed for the current fragment. */
- FragChangedPixels = 0;
-
- /* Test for break out conditions to save time. */
- if (*DispFragPtr == CANDIDATE_BLOCK){
-
- /* Clear down entries in changed locals array */
- SET8_0(ChLocalsPtr);
-
- for ( j = 0; j < HFRAGPIXELS; j++ ){
- /* Take a local copy of the measured difference. */
- Diff = (int)YuvPtr1[j] - (int)YuvPtr2[j];
-
- /* Store the actual difference value */
- YUVDiffsPtr[j] = Diff;
-
- /* Test against the Level thresholds and record the results */
- SgcPtr[0] += ppi->SgcThreshTable[Diff+255];
-
- /* Test against the SRF thresholds */
- bits_map_ptr[j] = ppi->SrfThreshTable[Diff+255];
- FragChangedPixels += ppi->SrfThreshTable[Diff+255];
- }
- }else{
- /* If we are breaking out here mark all pixels as changed. */
- if ( *DispFragPtr > BLOCK_NOT_CODED ){
- SET8_1(bits_map_ptr);
- SET8_8(ChLocalsPtr);
- }else{
- SET8_0(ChLocalsPtr);
- }
- }
-
- *RowDiffsPtr += FragChangedPixels;
- *FDiffPixels += (unsigned char)FragChangedPixels;
-
- YuvPtr1 += HFRAGPIXELS;
- YuvPtr2 += HFRAGPIXELS;
- bits_map_ptr += HFRAGPIXELS;
- ChLocalsPtr += HFRAGPIXELS;
- YUVDiffsPtr += HFRAGPIXELS;
- SgcPtr ++;
- FDiffPixels ++;
-
- /* If we have a lot of changed pixels for this fragment on this
- row then the fragment is almost sure to be picked (e.g. through
- the line search) so we can mark it as selected and then ignore
- it. */
- if (FragChangedPixels >= 7){
- *DispFragPtr = BLOCK_CODED_LOW;
- }
- DispFragPtr++;
- }
- }else{
-
- /*************************************************************/
- /* First fragment of row !! */
-
- i = 0;
- /* Reset count of pixels changed for the current fragment. */
- FragChangedPixels = 0;
-
- /* Test for break out conditions to save time. */
- if (*DispFragPtr == CANDIDATE_BLOCK){
- /* Clear down entries in changed locals array */
- SET8_0(ChLocalsPtr);
-
- for ( j = 0; j < HFRAGPIXELS; j++ ){
- /* Take a local copy of the measured difference. */
- Diff = (int)YuvPtr1[j] - (int)YuvPtr2[j];
-
- /* Store the actual difference value */
- YUVDiffsPtr[j] = Diff;
-
- /* Test against the Level thresholds and record the results */
- SgcPtr[0] += ppi->SgcThreshTable[Diff+255];
-
- if (j>0 && ppi->SrfPakThreshTable[Diff+255] )
- Diff = (int)ApplyPakLowPass( ppi, &YuvPtr1[j] ) -
- (int)ApplyPakLowPass( ppi, &YuvPtr2[j] );
-
- /* Test against the SRF thresholds */
- bits_map_ptr[j] = ppi->SrfThreshTable[Diff+255];
- FragChangedPixels += ppi->SrfThreshTable[Diff+255];
- }
- }else{
- /* If we are breaking out here mark all pixels as changed. */
- if ( *DispFragPtr > BLOCK_NOT_CODED ){
- SET8_1(bits_map_ptr);
- SET8_8(ChLocalsPtr);
- }else{
- SET8_0(ChLocalsPtr);
- }
- }
-
- *RowDiffsPtr += FragChangedPixels;
- *FDiffPixels += (unsigned char)FragChangedPixels;
-
- YuvPtr1 += HFRAGPIXELS;
- YuvPtr2 += HFRAGPIXELS;
- bits_map_ptr += HFRAGPIXELS;
- ChLocalsPtr += HFRAGPIXELS;
- YUVDiffsPtr += HFRAGPIXELS;
- SgcPtr ++;
- FDiffPixels ++;
-
- /* If we have a lot of changed pixels for this fragment on this
- row then the fragment is almost sure to be picked
- (e.g. through the line search) so we can mark it as selected
- and then ignore it. */
- if (FragChangedPixels >= 7){
- *DispFragPtr = BLOCK_CODED_LOW;
- }
- DispFragPtr++;
- /*************************************************************/
- /* Fragment in between!! */
-
- for ( i = HFRAGPIXELS ; i < ppi->PlaneWidth-HFRAGPIXELS;
- i += HFRAGPIXELS ){
- /* Reset count of pixels changed for the current fragment. */
- FragChangedPixels = 0;
-
- /* Test for break out conditions to save time. */
- if (*DispFragPtr == CANDIDATE_BLOCK){
- /* Clear down entries in changed locals array */
- SET8_0(ChLocalsPtr);
- for ( j = 0; j < HFRAGPIXELS; j++ ){
- /* Take a local copy of the measured difference. */
- Diff = (int)YuvPtr1[j] - (int)YuvPtr2[j];
-
- /* Store the actual difference value */
- YUVDiffsPtr[j] = Diff;
-
- /* Test against the Level thresholds and record the results */
- SgcPtr[0] += ppi->SgcThreshTable[Diff+255];
-
- if (ppi->SrfPakThreshTable[Diff+255] )
- Diff = (int)ApplyPakLowPass( ppi, &YuvPtr1[j] ) -
- (int)ApplyPakLowPass( ppi, &YuvPtr2[j] );
-
-
- /* Test against the SRF thresholds */
- bits_map_ptr[j] = ppi->SrfThreshTable[Diff+255];
- FragChangedPixels += ppi->SrfThreshTable[Diff+255];
- }
- }else{
- /* If we are breaking out here mark all pixels as changed. */
- if ( *DispFragPtr > BLOCK_NOT_CODED ){
- SET8_1(bits_map_ptr);
- SET8_8(ChLocalsPtr);
- }else{
- SET8_0(ChLocalsPtr);
- }
- }
-
- *RowDiffsPtr += FragChangedPixels;
- *FDiffPixels += (unsigned char)FragChangedPixels;
-
- YuvPtr1 += HFRAGPIXELS;
- YuvPtr2 += HFRAGPIXELS;
- bits_map_ptr += HFRAGPIXELS;
- ChLocalsPtr += HFRAGPIXELS;
- YUVDiffsPtr += HFRAGPIXELS;
- SgcPtr ++;
- FDiffPixels ++;
-
- /* If we have a lot of changed pixels for this fragment on this
- row then the fragment is almost sure to be picked
- (e.g. through the line search) so we can mark it as selected
- and then ignore it. */
- if (FragChangedPixels >= 7){
- *DispFragPtr = BLOCK_CODED_LOW;
- }
- DispFragPtr++;
- }
- /*************************************************************/
- /* Last fragment of row !! */
-
- /* Reset count of pixels changed for the current fragment. */
- FragChangedPixels = 0;
-
- /* Test for break out conditions to save time. */
- if (*DispFragPtr == CANDIDATE_BLOCK){
- /* Clear down entries in changed locals array */
- SET8_0(ChLocalsPtr);
-
- for ( j = 0; j < HFRAGPIXELS; j++ ){
- /* Take a local copy of the measured difference. */
- Diff = (int)YuvPtr1[j] - (int)YuvPtr2[j];
-
- /* Store the actual difference value */
- YUVDiffsPtr[j] = Diff;
-
- /* Test against the Level thresholds and record the results */
- SgcPtr[0] += ppi->SgcThreshTable[Diff+255];
-
- if (j<7 && ppi->SrfPakThreshTable[Diff+255] )
- Diff = (int)ApplyPakLowPass( ppi, &YuvPtr1[j] ) -
- (int)ApplyPakLowPass( ppi, &YuvPtr2[j] );
-
-
- /* Test against the SRF thresholds */
- bits_map_ptr[j] = ppi->SrfThreshTable[Diff+255];
- FragChangedPixels += ppi->SrfThreshTable[Diff+255];
- }
- }else{
- /* If we are breaking out here mark all pixels as changed.*/
- if ( *DispFragPtr > BLOCK_NOT_CODED ) {
- SET8_1(bits_map_ptr);
- SET8_8(ChLocalsPtr);
- }else{
- SET8_0(ChLocalsPtr);
- }
- }
- /* If we have a lot of changed pixels for this fragment on this
- row then the fragment is almost sure to be picked (e.g. through
- the line search) so we can mark it as selected and then ignore
- it. */
- *RowDiffsPtr += FragChangedPixels;
- *FDiffPixels += (unsigned char)FragChangedPixels;
-
- /* If we have a lot of changed pixels for this fragment on this
- row then the fragment is almost sure to be picked (e.g. through
- the line search) so we can mark it as selected and then ignore
- it. */
- if (FragChangedPixels >= 7){
- *DispFragPtr = BLOCK_CODED_LOW;
- }
- DispFragPtr++;
-
- }
-}
-
-static void ConsolidateDiffScanResults( PP_INSTANCE *ppi,
- unsigned char * FDiffPixels,
- signed char * SgcScoresPtr,
- signed char * DispFragPtr ){
- ogg_int32_t i;
-
- for ( i = 0; i < ppi->PlaneHFragments; i ++ ){
- /* Consider only those blocks that were candidates in the
- difference scan. Ignore definite YES and NO cases. */
- if ( DispFragPtr[i] == CANDIDATE_BLOCK ){
- if ( ((ogg_uint32_t)abs(SgcScoresPtr[i]) > ppi->BlockSgcThresh) ){
- /* Block marked for update due to Sgc change */
- DispFragPtr[i] = BLOCK_CODED_SGC;
- }else if ( FDiffPixels[i] == 0 ){
- /* Block is no longer a candidate for the main tests but will
- still be considered a candidate in RowBarEnhBlockMap() */
- DispFragPtr[i] = CANDIDATE_BLOCK_LOW;
- }
- }
- }
-}
-
-static void RowChangedLocalsScan( PP_INSTANCE *ppi,
- unsigned char * PixelMapPtr,
- unsigned char * ChLocalsPtr,
- signed char * DispFragPtr,
- unsigned char RowType ){
-
- unsigned char changed_locals = 0;
- unsigned char * PixelsChangedPtr0;
- unsigned char * PixelsChangedPtr1;
- unsigned char * PixelsChangedPtr2;
- ogg_int32_t i, j;
- ogg_int32_t LastRowIndex = ppi->PlaneWidth - 1;
-
- /* Set up the line based pointers into the bits changed map. */
- PixelsChangedPtr0 = PixelMapPtr - ppi->PlaneWidth;
- if ( PixelsChangedPtr0 < ppi->PixelChangedMap )
- PixelsChangedPtr0 += ppi->PixelMapCircularBufferSize;
- PixelsChangedPtr0 -= 1;
-
- PixelsChangedPtr1 = PixelMapPtr - 1;
-
- PixelsChangedPtr2 = PixelMapPtr + ppi->PlaneWidth;
- if ( PixelsChangedPtr2 >=
- (ppi->PixelChangedMap + ppi->PixelMapCircularBufferSize) )
- PixelsChangedPtr2 -= ppi->PixelMapCircularBufferSize;
- PixelsChangedPtr2 -= 1;
-
- if ( RowType == NOT_EDGE_ROW ){
- /* Scan through the row of pixels and calculate changed locals. */
- for ( i = 0; i < ppi->PlaneWidth; i += HFRAGPIXELS ){
- /* Skip a group of 8 pixels if the assosciated fragment has no
- pixels of interest. */
- if ( *DispFragPtr == CANDIDATE_BLOCK ){
- for ( j = 0; j < HFRAGPIXELS; j++ ){
- changed_locals = 0;
-
- /* If the pixel itself has changed */
- if ( PixelsChangedPtr1[1] ){
- if ( (i > 0) || (j > 0) ){
- changed_locals += PixelsChangedPtr0[0];
- changed_locals += PixelsChangedPtr1[0];
- changed_locals += PixelsChangedPtr2[0];
- }
-
- changed_locals += PixelsChangedPtr0[1];
- changed_locals += PixelsChangedPtr2[1];
-
- if ( (i + j) < LastRowIndex ){
- changed_locals += PixelsChangedPtr0[2];
- changed_locals += PixelsChangedPtr1[2];
- changed_locals += PixelsChangedPtr2[2];
- }
-
- /* Store the number of changed locals */
- *ChLocalsPtr |= changed_locals;
- }
-
- /* Increment to next pixel in the row */
- ChLocalsPtr++;
- PixelsChangedPtr0++;
- PixelsChangedPtr1++;
- PixelsChangedPtr2++;
- }
- }else{
- if ( *DispFragPtr > BLOCK_NOT_CODED )
- SET8_0(ChLocalsPtr);
-
- /* Step pointers */
- ChLocalsPtr += HFRAGPIXELS;
- PixelsChangedPtr0 += HFRAGPIXELS;
- PixelsChangedPtr1 += HFRAGPIXELS;
- PixelsChangedPtr2 += HFRAGPIXELS;
- }
-
- /* Move on to next fragment. */
- DispFragPtr++;
-
- }
- }else{
- /* Scan through the row of pixels and calculate changed locals. */
- for ( i = 0; i < ppi->PlaneWidth; i += HFRAGPIXELS ){
- /* Skip a group of 8 pixels if the assosciated fragment has no
- pixels of interest */
- if ( *DispFragPtr == CANDIDATE_BLOCK ){
- for ( j = 0; j < HFRAGPIXELS; j++ ){
- changed_locals = 0;
-
- /* If the pixel itself has changed */
- if ( PixelsChangedPtr1[1] ){
- if ( RowType == FIRST_ROW ){
- if ( (i > 0) || (j > 0) ){
- changed_locals += PixelsChangedPtr1[0];
- changed_locals += PixelsChangedPtr2[0];
- }
-
- changed_locals += PixelsChangedPtr2[1];
-
- if ( (i + j) < LastRowIndex ){
- changed_locals += PixelsChangedPtr1[2];
- changed_locals += PixelsChangedPtr2[2];
- }
- }else{
- if ( (i > 0) || (j > 0 ) ){
- changed_locals += PixelsChangedPtr0[0];
- changed_locals += PixelsChangedPtr1[0];
- }
-
- changed_locals += PixelsChangedPtr0[1];
-
- if ( (i + j) < LastRowIndex ){
- changed_locals += PixelsChangedPtr0[2];
- changed_locals += PixelsChangedPtr1[2];
- }
- }
-
- /* Store the number of changed locals */
- *ChLocalsPtr |= changed_locals;
- }
-
- /* Increment to next pixel in the row */
- ChLocalsPtr++;
- PixelsChangedPtr0++;
- PixelsChangedPtr1++;
- PixelsChangedPtr2++;
- }
- }else{
- if ( *DispFragPtr > BLOCK_NOT_CODED )
- SET8_0(ChLocalsPtr);
-
- /* Step pointers */
- ChLocalsPtr += HFRAGPIXELS;
- PixelsChangedPtr0 += HFRAGPIXELS;
- PixelsChangedPtr1 += HFRAGPIXELS;
- PixelsChangedPtr2 += HFRAGPIXELS;
- }
-
- /* Move on to next fragment. */
- DispFragPtr++;
- }
- }
-}
-
-static void NoiseScoreRow( PP_INSTANCE *ppi,
- unsigned char * PixelMapPtr,
- unsigned char * ChLocalsPtr,
- ogg_int16_t * YUVDiffsPtr,
- unsigned char * PixelNoiseScorePtr,
- ogg_uint32_t * FragScorePtr,
- signed char * DispFragPtr,
- ogg_int32_t * RowDiffsPtr ){
- ogg_int32_t i,j;
- unsigned char changed_locals = 0;
- ogg_int32_t Score;
- ogg_uint32_t FragScore;
- ogg_int32_t AbsDiff;
-
- /* For each pixel in the row */
- for ( i = 0; i < ppi->PlaneWidth; i += HFRAGPIXELS ){
- /* Skip a group of 8 pixels if the assosciated fragment has no
- pixels of interest. */
- if ( *DispFragPtr == CANDIDATE_BLOCK ){
- /* Reset the cumulative fragment score. */
- FragScore = 0;
-
- /* Pixels grouped along the row into fragments */
- for ( j = 0; j < HFRAGPIXELS; j++ ){
- if ( PixelMapPtr[j] ){
- AbsDiff = (ogg_int32_t)( abs(YUVDiffsPtr[j]) );
- changed_locals = ChLocalsPtr[j];
-
- /* Give this pixel a score based on changed locals and level
- of its own change. */
- Score = (1 + ((ogg_int32_t)(changed_locals +
- ppi->NoiseScoreBoostTable[AbsDiff]) -
- ppi->NoiseSupLevel));
-
- /* For no zero scores adjust by a level based score multiplier. */
- if ( Score > 0 ){
- Score = ((double)Score *
- ppi->AbsDiff_ScoreMultiplierTable[AbsDiff] );
- if ( Score < 1 )
- Score = 1;
- }else{
- /* Set -ve values to 0 */
- Score = 0;
-
- /* If there are no changed locals then clear the pixel
- changed flag and decrement the pixels changed in
- fragment count to speed later stages. */
- if ( changed_locals == 0 ){
- PixelMapPtr[j] = 0;
- *RowDiffsPtr -= 1;
- }
- }
-
- /* Update the pixel scores etc. */
- PixelNoiseScorePtr[j] = (unsigned char)Score;
- FragScore += (ogg_uint32_t)Score;
- }
- }
-
- /* Add fragment score (with plane correction factor) into main
- data structure */
- *FragScorePtr += (ogg_int32_t)(FragScore *
- ppi->YUVPlaneCorrectionFactor);
-
- /* If score is greater than trip threshold then mark blcok for update. */
- if ( *FragScorePtr > ppi->BlockThreshold ){
- *DispFragPtr = BLOCK_CODED_LOW;
- }
- }
-
- /* Increment the various pointers */
- FragScorePtr++;
- DispFragPtr++;
- PixelNoiseScorePtr += HFRAGPIXELS;
- PixelMapPtr += HFRAGPIXELS;
- ChLocalsPtr += HFRAGPIXELS;
- YUVDiffsPtr += HFRAGPIXELS;
- }
-}
-
-static void PrimaryEdgeScoreRow( PP_INSTANCE *ppi,
- unsigned char * ChangedLocalsPtr,
- ogg_int16_t * YUVDiffsPtr,
- unsigned char * PixelNoiseScorePtr,
- ogg_uint32_t * FragScorePtr,
- signed char * DispFragPtr,
- unsigned char RowType ){
- ogg_uint32_t BodyNeighbours;
- ogg_uint32_t AbsDiff;
- unsigned char changed_locals = 0;
- ogg_int32_t Score;
- ogg_uint32_t FragScore;
- unsigned char * CHLocalsPtr0;
- unsigned char * CHLocalsPtr1;
- unsigned char * CHLocalsPtr2;
- ogg_int32_t i,j;
- ogg_int32_t LastRowIndex = ppi->PlaneWidth - 1;
-
- /* Set up pointers into the current previous and next row of the
- changed locals data structure. */
- CHLocalsPtr0 = ChangedLocalsPtr - ppi->PlaneWidth;
- if ( CHLocalsPtr0 < ppi->ChLocals )
- CHLocalsPtr0 += ppi->ChLocalsCircularBufferSize;
- CHLocalsPtr0 -= 1;
-
- CHLocalsPtr1 = ChangedLocalsPtr - 1;
-
- CHLocalsPtr2 = ChangedLocalsPtr + ppi->PlaneWidth;
- if ( CHLocalsPtr2 >= (ppi->ChLocals + ppi->ChLocalsCircularBufferSize) )
- CHLocalsPtr2 -= ppi->ChLocalsCircularBufferSize;
- CHLocalsPtr2 -= 1;
-
-
- /* The defining rule used here is as follows. */
- /* An edge pixels has 3-5 changed locals. */
- /* And one or more of these changed locals has itself got 7-8
- changed locals. */
-
- if ( RowType == NOT_EDGE_ROW ){
- /* Loop for all pixels in the row. */
- for ( i = 0; i < ppi->PlaneWidth; i += HFRAGPIXELS ){
- /* Does the fragment contain anything interesting to work with. */
- if ( *DispFragPtr == CANDIDATE_BLOCK ){
- /* Reset the cumulative fragment score. */
- FragScore = 0;
-
- /* Pixels grouped along the row into fragments */
- for ( j = 0; j < HFRAGPIXELS; j++ ){
- /* How many changed locals has the current pixel got. */
- changed_locals = ChangedLocalsPtr[j];
-
- /* Is the pixel a suitable candidate */
- if ( (changed_locals > 2) && (changed_locals < 6) ){
- /* The pixel may qualify... have a closer look. */
- BodyNeighbours = 0;
-
- /* Count the number of "BodyNeighbours" .. Pixels that
- have 7 or more changed neighbours. */
- if ( (i > 0) || (j > 0 ) ){
- if ( CHLocalsPtr0[0] >= 7 )
- BodyNeighbours++;
- if ( CHLocalsPtr1[0] >= 7 )
- BodyNeighbours++;
- if ( CHLocalsPtr2[0] >= 7 )
- BodyNeighbours++;
- }
-
- if ( CHLocalsPtr0[1] >= 7 )
- BodyNeighbours++;
- if ( CHLocalsPtr2[1] >= 7 )
- BodyNeighbours++;
-
- if ( (i + j) < LastRowIndex ){
- if ( CHLocalsPtr0[2] >= 7 )
- BodyNeighbours++;
- if ( CHLocalsPtr1[2] >= 7 )
- BodyNeighbours++;
- if ( CHLocalsPtr2[2] >= 7 )
- BodyNeighbours++;
- }
-
- if ( BodyNeighbours > 0 ){
- AbsDiff = abs( YUVDiffsPtr[j] );
- Score = (ogg_int32_t)
- ( (double)(BodyNeighbours *
- BodyNeighbourScore) *
- ppi->AbsDiff_ScoreMultiplierTable[AbsDiff] );
- if ( Score < 1 )
- Score = 1;
-
- /* Increment the score by a value determined by the
- number of body neighbours. */
- PixelNoiseScorePtr[j] += (unsigned char)Score;
- FragScore += (ogg_uint32_t)Score;
- }
- }
-
- /* Increment pointers into changed locals buffer */
- CHLocalsPtr0 ++;
- CHLocalsPtr1 ++;
- CHLocalsPtr2 ++;
- }
-
- /* Add fragment score (with plane correction factor) into main
- data structure */
- *FragScorePtr += (ogg_int32_t)(FragScore *
- ppi->YUVPlaneCorrectionFactor);
-
- /* If score is greater than trip threshold then mark blcok for
- update. */
- if ( *FragScorePtr > ppi->BlockThreshold ){
- *DispFragPtr = BLOCK_CODED_LOW;
- }
-
- }else{
- /* Nothing to do for this fragment group */
- /* Advance pointers into changed locals buffer */
- CHLocalsPtr0 += HFRAGPIXELS;
- CHLocalsPtr1 += HFRAGPIXELS;
- CHLocalsPtr2 += HFRAGPIXELS;
- }
-
- /* Increment the various pointers */
- FragScorePtr++;
- DispFragPtr++;
- PixelNoiseScorePtr += HFRAGPIXELS;
- ChangedLocalsPtr += HFRAGPIXELS;
- YUVDiffsPtr += HFRAGPIXELS;
- }
- }else{
- /* This is either the top or bottom row of pixels in a plane. */
- /* Loop for all pixels in the row. */
- for ( i = 0; i < ppi->PlaneWidth; i += HFRAGPIXELS ){
- /* Does the fragment contain anything interesting to work with. */
- if ( *DispFragPtr == CANDIDATE_BLOCK ){
- /* Reset the cumulative fragment score. */
- FragScore = 0;
-
- /* Pixels grouped along the row into fragments */
- for ( j = 0; j < HFRAGPIXELS; j++ ){
- /* How many changed locals has the current pixel got. */
- changed_locals = ChangedLocalsPtr[j];
-
- /* Is the pixel a suitable candidate */
- if ( (changed_locals > 2) && (changed_locals < 6) ){
- /* The pixel may qualify... have a closer look. */
- BodyNeighbours = 0;
-
- /* Count the number of "BodyNeighbours" .. Pixels
- that have 7 or more changed neighbours. */
- if ( RowType == LAST_ROW ){
- /* Test for cases where it could be the first pixel on
- the line */
- if ( (i > 0) || (j > 0) ){
- if ( CHLocalsPtr0[0] >= 7 )
- BodyNeighbours++;
- if ( CHLocalsPtr1[0] >= 7 )
- BodyNeighbours++;
- }
-
- if ( CHLocalsPtr0[1] >= 7 )
- BodyNeighbours++;
-
- /* Test for the end of line case */
- if ( (i + j) < LastRowIndex ){
- if ( CHLocalsPtr0[2] >= 7 )
- BodyNeighbours++;
-
- if ( CHLocalsPtr1[2] >= 7 )
- BodyNeighbours++;
- }
- }else{
- /* First Row */
- /* Test for cases where it could be the first pixel on
- the line */
- if ( (i > 0) || (j > 0) ){
- if ( CHLocalsPtr1[0] >= 7 )
- BodyNeighbours++;
- if ( CHLocalsPtr2[0] >= 7 )
- BodyNeighbours++;
- }
-
- /* Test for the end of line case */
- if ( CHLocalsPtr2[1] >= 7 )
- BodyNeighbours++;
-
- if ( (i + j) < LastRowIndex ){
- if ( CHLocalsPtr1[2] >= 7 )
- BodyNeighbours++;
- if ( CHLocalsPtr2[2] >= 7 )
- BodyNeighbours++;
- }
- }
-
- /* Allocate a score according to the number of Body neighbours. */
- if ( BodyNeighbours > 0 ){
- AbsDiff = abs( YUVDiffsPtr[j] );
- Score = (ogg_int32_t)
- ( (double)(BodyNeighbours * BodyNeighbourScore) *
- ppi->AbsDiff_ScoreMultiplierTable[AbsDiff] );
- if ( Score < 1 )
- Score = 1;
-
- PixelNoiseScorePtr[j] += (unsigned char)Score;
- FragScore += (ogg_uint32_t)Score;
- }
- }
-
- /* Increment pointers into changed locals buffer */
- CHLocalsPtr0 ++;
- CHLocalsPtr1 ++;
- CHLocalsPtr2 ++;
- }
-
- /* Add fragment score (with plane correction factor) into main
- data structure */
- *FragScorePtr +=
- (ogg_int32_t)(FragScore * ppi->YUVPlaneCorrectionFactor);
-
- /* If score is greater than trip threshold then mark blcok for
- update. */
- if ( *FragScorePtr > ppi->BlockThreshold ){
- *DispFragPtr = BLOCK_CODED_LOW;
- }
-
- }else{
- /* Nothing to do for this fragment group */
- /* Advance pointers into changed locals buffer */
- CHLocalsPtr0 += HFRAGPIXELS;
- CHLocalsPtr1 += HFRAGPIXELS;
- CHLocalsPtr2 += HFRAGPIXELS;
- }
-
- /* Increment the various pointers */
- FragScorePtr++;
- DispFragPtr++;
- PixelNoiseScorePtr += HFRAGPIXELS;
- ChangedLocalsPtr += HFRAGPIXELS;
- YUVDiffsPtr += HFRAGPIXELS;
- }
- }
-}
-
-static void PixelLineSearch( PP_INSTANCE *ppi,
- unsigned char * ChangedLocalsPtr,
- ogg_int32_t RowNumber,
- ogg_int32_t ColNumber,
- unsigned char direction,
- ogg_uint32_t * line_length ){
- /* Exit if the pixel does not qualify or we have fallen off the edge
- of either the image plane or the row. */
- if ( (RowNumber < 0) ||
- (RowNumber >= ppi->PlaneHeight) ||
- (ColNumber < 0) ||
- (ColNumber >= ppi->PlaneWidth) ||
- ((*ChangedLocalsPtr) <= 1) ||
- ((*ChangedLocalsPtr) >= 6) ){
- /* If not then it isn't part of any line. */
- return;
- }
-
- if (*line_length < ppi->MaxLineSearchLen){
- ogg_uint32_t TmpLineLength;
- ogg_uint32_t BestLineLength;
- unsigned char * search_ptr;
-
- /* Increment the line length to include this pixel. */
- *line_length += 1;
- BestLineLength = *line_length;
-
- /* Continue search */
- /* up */
- if ( direction == UP ){
- TmpLineLength = *line_length;
-
- search_ptr = ChangedLocalsPtr - ppi->PlaneWidth;
- if ( search_ptr < ppi->ChLocals )
- search_ptr += ppi->ChLocalsCircularBufferSize;
-
- PixelLineSearch( ppi, search_ptr, RowNumber - 1, ColNumber,
- direction, &TmpLineLength );
-
- if ( TmpLineLength > BestLineLength )
- BestLineLength = TmpLineLength;
- }
-
- /* up and left */
- if ( (BestLineLength < ppi->MaxLineSearchLen) &&
- ((direction == UP) || (direction == LEFT)) ){
- TmpLineLength = *line_length;
-
- search_ptr = ChangedLocalsPtr - ppi->PlaneWidth;
- if ( search_ptr < ppi->ChLocals )
- search_ptr += ppi->ChLocalsCircularBufferSize;
- search_ptr -= 1;
-
- PixelLineSearch( ppi, search_ptr, RowNumber - 1, ColNumber - 1,
- direction, &TmpLineLength );
-
- if ( TmpLineLength > BestLineLength )
- BestLineLength = TmpLineLength;
- }
-
- /* up and right */
- if ( (BestLineLength < ppi->MaxLineSearchLen) &&
- ((direction == UP) || (direction == RIGHT)) ){
- TmpLineLength = *line_length;
-
- search_ptr = ChangedLocalsPtr - ppi->PlaneWidth;
- if ( search_ptr < ppi->ChLocals )
- search_ptr += ppi->ChLocalsCircularBufferSize;
- search_ptr += 1;
-
- PixelLineSearch( ppi, search_ptr, RowNumber - 1, ColNumber + 1,
- direction, &TmpLineLength );
-
- if ( TmpLineLength > BestLineLength )
- BestLineLength = TmpLineLength;
- }
-
- /* left */
- if ( (BestLineLength < ppi->MaxLineSearchLen) && ( direction == LEFT ) ){
- TmpLineLength = *line_length;
- PixelLineSearch( ppi, ChangedLocalsPtr - 1, RowNumber, ColNumber - 1,
- direction, &TmpLineLength );
-
- if ( TmpLineLength > BestLineLength )
- BestLineLength = TmpLineLength;
- }
-
- /* right */
- if ( (BestLineLength < ppi->MaxLineSearchLen) && ( direction == RIGHT ) ){
- TmpLineLength = *line_length;
- PixelLineSearch( ppi, ChangedLocalsPtr + 1, RowNumber, ColNumber + 1,
- direction, &TmpLineLength );
-
- if ( TmpLineLength > BestLineLength )
- BestLineLength = TmpLineLength;
- }
-
- /* Down */
- if ( BestLineLength < ppi->MaxLineSearchLen ){
- TmpLineLength = *line_length;
- if ( direction == DOWN ){
- search_ptr = ChangedLocalsPtr + ppi->PlaneWidth;
- if ( search_ptr >= (ppi->ChLocals + ppi->ChLocalsCircularBufferSize) )
- search_ptr -= ppi->ChLocalsCircularBufferSize;
-
- PixelLineSearch( ppi, search_ptr, RowNumber + 1, ColNumber, direction,
- &TmpLineLength );
-
- if ( TmpLineLength > BestLineLength )
- BestLineLength = TmpLineLength;
- }
-
-
- /* down and left */
- if ( (BestLineLength < ppi->MaxLineSearchLen) &&
- ((direction == DOWN) || (direction == LEFT)) ){
- TmpLineLength = *line_length;
-
- search_ptr = ChangedLocalsPtr + ppi->PlaneWidth;
- if ( search_ptr >= (ppi->ChLocals + ppi->ChLocalsCircularBufferSize) )
- search_ptr -= ppi->ChLocalsCircularBufferSize;
- search_ptr -= 1;
-
- PixelLineSearch( ppi, search_ptr, RowNumber + 1, ColNumber - 1,
- direction, &TmpLineLength );
-
- if ( TmpLineLength > BestLineLength )
- BestLineLength = TmpLineLength;
- }
-
- /* down and right */
- if ( (BestLineLength < ppi->MaxLineSearchLen) &&
- ((direction == DOWN) || (direction == RIGHT)) ){
- TmpLineLength = *line_length;
-
- search_ptr = ChangedLocalsPtr + ppi->PlaneWidth;
- if ( search_ptr >= (ppi->ChLocals + ppi->ChLocalsCircularBufferSize) )
- search_ptr -= ppi->ChLocalsCircularBufferSize;
- search_ptr += 1;
-
- PixelLineSearch( ppi, search_ptr, RowNumber + 1, ColNumber + 1,
- direction, &TmpLineLength );
-
- if ( TmpLineLength > BestLineLength )
- BestLineLength = TmpLineLength;
- }
- }
-
- /* Note the search value for this pixel. */
- *line_length = BestLineLength;
- }
-}
-
-static unsigned char LineSearchScorePixel( PP_INSTANCE *ppi,
- unsigned char * ChangedLocalsPtr,
- ogg_int32_t RowNumber,
- ogg_int32_t ColNumber ){
- ogg_uint32_t line_length = 0;
- ogg_uint32_t line_length2 = 0;
- ogg_uint32_t line_length_score = 0;
- ogg_uint32_t tmp_line_length = 0;
- ogg_uint32_t tmp_line_length2 = 0;
-
- /* Look UP and Down */
- PixelLineSearch( ppi, ChangedLocalsPtr, RowNumber,
- ColNumber, UP, &tmp_line_length );
-
- if (tmp_line_length < ppi->MaxLineSearchLen) {
- /* Look DOWN */
- PixelLineSearch( ppi, ChangedLocalsPtr, RowNumber,
- ColNumber, DOWN, &tmp_line_length2 );
- line_length = tmp_line_length + tmp_line_length2 - 1;
-
- if ( line_length > ppi->MaxLineSearchLen )
- line_length = ppi->MaxLineSearchLen;
- }else
- line_length = tmp_line_length;
-
- /* If no max length line found then look left and right */
- if ( line_length < ppi->MaxLineSearchLen ){
- tmp_line_length = 0;
- tmp_line_length2 = 0;
-
- PixelLineSearch( ppi, ChangedLocalsPtr, RowNumber,
- ColNumber, LEFT, &tmp_line_length );
- if (tmp_line_length < ppi->MaxLineSearchLen){
- PixelLineSearch( ppi, ChangedLocalsPtr, RowNumber,
- ColNumber, RIGHT, &tmp_line_length2 );
- line_length2 = tmp_line_length + tmp_line_length2 - 1;
-
- if ( line_length2 > ppi->MaxLineSearchLen )
- line_length2 = ppi->MaxLineSearchLen;
- }else
- line_length2 = tmp_line_length;
-
- }
-
- /* Take the largest line length */
- if ( line_length2 > line_length )
- line_length = line_length2;
-
- /* Create line length score */
- line_length_score = LineLengthScores[line_length];
-
- return (unsigned char)line_length_score;
-}
-
-static void LineSearchScoreRow( PP_INSTANCE *ppi,
- unsigned char * ChangedLocalsPtr,
- ogg_int16_t * YUVDiffsPtr,
- unsigned char * PixelNoiseScorePtr,
- ogg_uint32_t * FragScorePtr,
- signed char * DispFragPtr,
- ogg_int32_t RowNumber ){
- ogg_uint32_t AbsDiff;
- unsigned char changed_locals = 0;
- ogg_int32_t Score;
- ogg_uint32_t FragScore;
- ogg_int32_t i,j;
-
- /* The defining rule used here is as follows. */
- /* An edge pixels has 2-5 changed locals. */
- /* And one or more of these changed locals has itself got 7-8
- changed locals. */
-
- /* Loop for all pixels in the row. */
- for ( i = 0; i < ppi->PlaneWidth; i += HFRAGPIXELS ){
- /* Does the fragment contain anything interesting to work with. */
- if ( *DispFragPtr == CANDIDATE_BLOCK ){
- /* Reset the cumulative fragment score. */
- FragScore = 0;
-
- /* Pixels grouped along the row into fragments */
- for ( j = 0; j < HFRAGPIXELS; j++ ){
- /* How many changed locals has the current pixel got. */
- changed_locals = ChangedLocalsPtr[j];
-
- /* Is the pixel a suitable candidate for edge enhancement */
- if ( (changed_locals > 1) && (changed_locals < 6) &&
- (PixelNoiseScorePtr[j] < ppi->LineSearchTripTresh) ) {
- Score = (ogg_int32_t)
- LineSearchScorePixel( ppi, &ChangedLocalsPtr[j], RowNumber, i+j );
-
- if ( Score ){
- AbsDiff = abs( YUVDiffsPtr[j] );
- Score = (ogg_int32_t)
- ( (double)Score * ppi->AbsDiff_ScoreMultiplierTable[AbsDiff] );
- if ( Score < 1 )
- Score = 1;
-
- PixelNoiseScorePtr[j] += (unsigned char)Score;
- FragScore += (ogg_uint32_t)Score;
- }
- }
- }
-
- /* Add fragment score (with plane correction factor) into main
- data structure */
- *FragScorePtr +=
- (ogg_int32_t)(FragScore * ppi->YUVPlaneCorrectionFactor);
-
- /* If score is greater than trip threshold then mark blcok for update. */
- if ( *FragScorePtr > ppi->BlockThreshold ){
- *DispFragPtr = BLOCK_CODED_LOW;
- }
- }
-
- /* Increment the various pointers */
- FragScorePtr++;
- DispFragPtr++;
- PixelNoiseScorePtr += HFRAGPIXELS;
- ChangedLocalsPtr += HFRAGPIXELS;
- YUVDiffsPtr += HFRAGPIXELS;
-
- }
-}
-
-static void RowBarEnhBlockMap( PP_INSTANCE *ppi,
- signed char * UpdatedBlockMapPtr,
- signed char * BarBlockMapPtr,
- ogg_uint32_t RowNumber ){
- int i;
-
- /* Start by blanking the row in the bar block map structure. */
- memset( BarBlockMapPtr, BLOCK_NOT_CODED, ppi->PlaneHFragments );
-
- /* First row */
- if ( RowNumber == 0 ){
-
- /* For each fragment in the row. */
- for ( i = 0; i < ppi->PlaneHFragments; i ++ ){
- /* Test for CANDIDATE_BLOCK or CANDIDATE_BLOCK_LOW. Uncoded or
- coded blocks will be ignored. */
- if ( UpdatedBlockMapPtr[i] <= CANDIDATE_BLOCK ){
- /* Is one of the immediate neighbours updated in the main map. */
- /* Note special cases for blocks at the start and end of rows. */
- if ( i == 0 ){
-
- if ((UpdatedBlockMapPtr[i+1] > BLOCK_NOT_CODED ) ||
- (UpdatedBlockMapPtr[i+ppi->PlaneHFragments]>BLOCK_NOT_CODED ) ||
- (UpdatedBlockMapPtr[i+ppi->PlaneHFragments+1]>BLOCK_NOT_CODED ) )
- BarBlockMapPtr[i] = BLOCK_CODED_BAR;
-
-
- }else if ( i == (ppi->PlaneHFragments - 1) ){
-
- if ((UpdatedBlockMapPtr[i-1] > BLOCK_NOT_CODED ) ||
- (UpdatedBlockMapPtr[i+ppi->PlaneHFragments-1]>BLOCK_NOT_CODED) ||
- (UpdatedBlockMapPtr[i+ppi->PlaneHFragments]>BLOCK_NOT_CODED) )
- BarBlockMapPtr[i] = BLOCK_CODED_BAR;
-
- }else{
- if((UpdatedBlockMapPtr[i-1] > BLOCK_NOT_CODED ) ||
- (UpdatedBlockMapPtr[i+1] > BLOCK_NOT_CODED ) ||
- (UpdatedBlockMapPtr[i+ppi->PlaneHFragments-1] > BLOCK_NOT_CODED)||
- (UpdatedBlockMapPtr[i+ppi->PlaneHFragments] > BLOCK_NOT_CODED ) ||
- (UpdatedBlockMapPtr[i+ppi->PlaneHFragments+1] > BLOCK_NOT_CODED) )
- BarBlockMapPtr[i] = BLOCK_CODED_BAR;
- }
- }
- }
-
- } else if ( RowNumber == (ogg_uint32_t)(ppi->PlaneVFragments-1)) {
-
- /* Last row */
- /* Used to read PlaneHFragments */
-
- /* For each fragment in the row. */
- for ( i = 0; i < ppi->PlaneHFragments; i ++ ){
- /* Test for CANDIDATE_BLOCK or CANDIDATE_BLOCK_LOW
- Uncoded or coded blocks will be ignored. */
- if ( UpdatedBlockMapPtr[i] <= CANDIDATE_BLOCK ){
- /* Is one of the immediate neighbours updated in the main map. */
- /* Note special cases for blocks at the start and end of rows. */
- if ( i == 0 ){
- if((UpdatedBlockMapPtr[i+1] > BLOCK_NOT_CODED ) ||
- (UpdatedBlockMapPtr[i-ppi->PlaneHFragments] > BLOCK_NOT_CODED ) ||
- (UpdatedBlockMapPtr[i-ppi->PlaneHFragments+1] > BLOCK_NOT_CODED ))
- BarBlockMapPtr[i] = BLOCK_CODED_BAR;
-
- }else if ( i == (ppi->PlaneHFragments - 1) ){
- if((UpdatedBlockMapPtr[i-1] > BLOCK_NOT_CODED ) ||
- (UpdatedBlockMapPtr[i-ppi->PlaneHFragments-1] > BLOCK_NOT_CODED)||
- (UpdatedBlockMapPtr[i-ppi->PlaneHFragments] > BLOCK_NOT_CODED ) )
- BarBlockMapPtr[i] = BLOCK_CODED_BAR;
- }else{
- if((UpdatedBlockMapPtr[i-1] > BLOCK_NOT_CODED ) ||
- (UpdatedBlockMapPtr[i+1] > BLOCK_NOT_CODED ) ||
- (UpdatedBlockMapPtr[i-ppi->PlaneHFragments-1] > BLOCK_NOT_CODED)||
- (UpdatedBlockMapPtr[i-ppi->PlaneHFragments] > BLOCK_NOT_CODED ) ||
- (UpdatedBlockMapPtr[i-ppi->PlaneHFragments+1] > BLOCK_NOT_CODED) )
- BarBlockMapPtr[i] = BLOCK_CODED_BAR;
- }
- }
- }
-
- }else{
- /* All other rows */
- /* For each fragment in the row. */
- for ( i = 0; i < ppi->PlaneHFragments; i ++ ){
- /* Test for CANDIDATE_BLOCK or CANDIDATE_BLOCK_LOW */
- /* Uncoded or coded blocks will be ignored. */
- if ( UpdatedBlockMapPtr[i] <= CANDIDATE_BLOCK ){
- /* Is one of the immediate neighbours updated in the main map. */
- /* Note special cases for blocks at the start and end of rows. */
- if ( i == 0 ){
-
- if((UpdatedBlockMapPtr[i+1] > BLOCK_NOT_CODED ) ||
- (UpdatedBlockMapPtr[i-ppi->PlaneHFragments] > BLOCK_NOT_CODED ) ||
- (UpdatedBlockMapPtr[i-ppi->PlaneHFragments+1] > BLOCK_NOT_CODED)||
- (UpdatedBlockMapPtr[i+ppi->PlaneHFragments] > BLOCK_NOT_CODED ) ||
- (UpdatedBlockMapPtr[i+ppi->PlaneHFragments+1] > BLOCK_NOT_CODED) )
- BarBlockMapPtr[i] = BLOCK_CODED_BAR;
-
- }else if ( i == (ppi->PlaneHFragments - 1) ){
-
- if((UpdatedBlockMapPtr[i-1] > BLOCK_NOT_CODED ) ||
- (UpdatedBlockMapPtr[i-ppi->PlaneHFragments-1] > BLOCK_NOT_CODED)||
- (UpdatedBlockMapPtr[i-ppi->PlaneHFragments] > BLOCK_NOT_CODED ) ||
- (UpdatedBlockMapPtr[i+ppi->PlaneHFragments-1] > BLOCK_NOT_CODED)||
- (UpdatedBlockMapPtr[i+ppi->PlaneHFragments] > BLOCK_NOT_CODED ) )
- BarBlockMapPtr[i] = BLOCK_CODED_BAR;
-
- }else{
- if((UpdatedBlockMapPtr[i-1] > BLOCK_NOT_CODED ) ||
- (UpdatedBlockMapPtr[i+1] > BLOCK_NOT_CODED ) ||
- (UpdatedBlockMapPtr[i-ppi->PlaneHFragments-1] > BLOCK_NOT_CODED)||
- (UpdatedBlockMapPtr[i-ppi->PlaneHFragments] > BLOCK_NOT_CODED ) ||
- (UpdatedBlockMapPtr[i-ppi->PlaneHFragments+1] > BLOCK_NOT_CODED)||
- (UpdatedBlockMapPtr[i+ppi->PlaneHFragments-1] > BLOCK_NOT_CODED)||
- (UpdatedBlockMapPtr[i+ppi->PlaneHFragments] > BLOCK_NOT_CODED ) ||
- (UpdatedBlockMapPtr[i+ppi->PlaneHFragments+1] > BLOCK_NOT_CODED ))
- BarBlockMapPtr[i] = BLOCK_CODED_BAR;
- }
- }
- }
- }
-}
-
-static void BarCopyBack( PP_INSTANCE *ppi,
- signed char * UpdatedBlockMapPtr,
- signed char * BarBlockMapPtr ){
- ogg_int32_t i;
-
- /* For each fragment in the row. */
- for ( i = 0; i < ppi->PlaneHFragments; i ++ ){
- if ( BarBlockMapPtr[i] > BLOCK_NOT_CODED ){
- UpdatedBlockMapPtr[i] = BarBlockMapPtr[i];
- }
- }
-}
-
-static void AnalysePlane( PP_INSTANCE *ppi,
- unsigned char * PlanePtr0,
- unsigned char * PlanePtr1,
- ogg_uint32_t FragArrayOffset,
- ogg_uint32_t PWidth,
- ogg_uint32_t PHeight,
- ogg_uint32_t PStride ) {
- unsigned char * RawPlanePtr0;
- unsigned char * RawPlanePtr1;
-
- ogg_int16_t * YUVDiffsPtr;
- ogg_int16_t * YUVDiffsPtr1;
- ogg_int16_t * YUVDiffsPtr2;
-
- ogg_uint32_t FragIndex;
- ogg_uint32_t ScoreFragIndex1;
- ogg_uint32_t ScoreFragIndex2;
- ogg_uint32_t ScoreFragIndex3;
- ogg_uint32_t ScoreFragIndex4;
-
- int UpdatedOrCandidateBlocks = 0;
-
- unsigned char * ChLocalsPtr0;
- unsigned char * ChLocalsPtr1;
- unsigned char * ChLocalsPtr2;
-
- unsigned char * PixelsChangedPtr0;
- unsigned char * PixelsChangedPtr1;
-
- unsigned char * PixelScoresPtr1;
- unsigned char * PixelScoresPtr2;
-
- signed char * DispFragPtr0;
- signed char * DispFragPtr1;
- signed char * DispFragPtr2;
-
- ogg_uint32_t * FragScoresPtr1;
- ogg_uint32_t * FragScoresPtr2;
-
- ogg_int32_t * RowDiffsPtr;
- ogg_int32_t * RowDiffsPtr1;
- ogg_int32_t * RowDiffsPtr2;
-
- ogg_int32_t i,j;
-
- ogg_int32_t RowNumber1;
- ogg_int32_t RowNumber2;
- ogg_int32_t RowNumber3;
- ogg_int32_t RowNumber4;
-
- int EdgeRow;
- ogg_int32_t LineSearchRowNumber = 0;
-
- /* Variables used as temporary stores for frequently used values. */
- ogg_int32_t Row0Mod3;
- ogg_int32_t Row1Mod3;
- ogg_int32_t Row2Mod3;
- ogg_int32_t BlockRowPixels;
-
- /* Set pixel difference threshold */
- if ( FragArrayOffset == 0 ){
- /* Luminance */
- ppi->LevelThresh = (int)ppi->SgcLevelThresh;
- ppi->NegLevelThresh = -ppi->LevelThresh;
-
- ppi->SrfThresh = (int)ppi->SRFGreyThresh;
- ppi->NegSrfThresh = -ppi->SrfThresh;
-
- /* Scores correction for Y pixels. */
- ppi->YUVPlaneCorrectionFactor = 1.0;
-
- ppi->BlockThreshold = ppi->PrimaryBlockThreshold;
- ppi->BlockSgcThresh = ppi->SgcThresh;
- }else{
- /* Chrominance */
- ppi->LevelThresh = (int)ppi->SuvcLevelThresh;
- ppi->NegLevelThresh = -ppi->LevelThresh;
-
- ppi->SrfThresh = (int)ppi->SRFColThresh;
- ppi->NegSrfThresh = -ppi->SrfThresh;
-
- /* Scores correction for UV pixels. */
- ppi->YUVPlaneCorrectionFactor = 1.5;
-
- /* Block threholds different for subsampled U and V blocks */
- ppi->BlockThreshold =
- (ppi->PrimaryBlockThreshold / ppi->UVBlockThreshCorrection);
- ppi->BlockSgcThresh =
- (ppi->SgcThresh / ppi->UVSgcCorrection);
- }
-
- /* Initialise the SRF thresh table and pointer. */
- memset( ppi->SrfThreshTable, 1, 512 );
- for ( i = ppi->NegSrfThresh; i <= ppi->SrfThresh; i++ )
- ppi->SrfThreshTable[i+255] = 0;
-
- /* Initialise the PAK thresh table. */
- for ( i = -255; i <= 255; i++ )
- if ( ppi->SrfThreshTable[i+255] &&
- (i <= ppi->HighChange) &&
- (i >= ppi->NegHighChange) )
- ppi->SrfPakThreshTable[i+255] = 1;
- else
- ppi->SrfPakThreshTable[i+255] = 0;
-
- /* Initialise the SGc lookup table */
- for ( i = -255; i <= 255; i++ ){
- if ( i <= ppi->NegLevelThresh )
- ppi->SgcThreshTable[i+255] = (unsigned char) -1;
- else if ( i >= ppi->LevelThresh )
- ppi->SgcThreshTable[i+255] = 1;
- else
- ppi->SgcThreshTable[i+255] = 0;
- }
-
- /* Set up plane dimension variables */
- ppi->PlaneHFragments = PWidth / HFRAGPIXELS;
- ppi->PlaneVFragments = PHeight / VFRAGPIXELS;
- ppi->PlaneWidth = PWidth;
- ppi->PlaneHeight = PHeight;
- ppi->PlaneStride = PStride;
-
- /* Set up local pointers into the raw image data. */
- RawPlanePtr0 = PlanePtr0;
- RawPlanePtr1 = PlanePtr1;
-
- /* Note size and endo points for circular buffers. */
- ppi->YuvDiffsCircularBufferSize = YDIFF_CB_ROWS * ppi->PlaneWidth;
- ppi->ChLocalsCircularBufferSize = CHLOCALS_CB_ROWS * ppi->PlaneWidth;
- ppi->PixelMapCircularBufferSize = PMAP_CB_ROWS * ppi->PlaneWidth;
-
- /* Set high change thresh where PAK not needed */
- ppi->HighChange = ppi->SrfThresh * 4;
- ppi->NegHighChange = -ppi->HighChange;
-
- /* Set up row difference pointers. */
- RowDiffsPtr = ppi->RowChangedPixels;
- RowDiffsPtr1 = ppi->RowChangedPixels;
- RowDiffsPtr2 = ppi->RowChangedPixels;
-
- BlockRowPixels = ppi->PlaneWidth * VFRAGPIXELS;
-
- for ( i = 0; i < (ppi->PlaneVFragments + 4); i++ ){
- RowNumber1 = (i - 1);
- RowNumber2 = (i - 2);
- RowNumber3 = (i - 3);
- RowNumber4 = (i - 4);
-
- /* Pre calculate some frequently used values */
- Row0Mod3 = i % 3;
- Row1Mod3 = RowNumber1 % 3;
- Row2Mod3 = RowNumber2 % 3;
-
- /* For row diff scan last two iterations are invalid */
- if ( i < ppi->PlaneVFragments ){
- FragIndex = (i * ppi->PlaneHFragments) + FragArrayOffset;
- YUVDiffsPtr = &ppi->yuv_differences[Row0Mod3 * BlockRowPixels];
-
- PixelsChangedPtr0 = (&ppi->PixelChangedMap[Row0Mod3 * BlockRowPixels]);
- DispFragPtr0 = &ppi->ScanDisplayFragments[FragIndex];
-
- ChLocalsPtr0 = (&ppi->ChLocals[Row0Mod3 * BlockRowPixels]);
-
- }
-
- /* Set up the changed locals pointer to trail behind by one row of
- fragments. */
- if ( i > 0 ){
- /* For last iteration the ch locals and noise scans are invalid */
- if ( RowNumber1 < ppi->PlaneVFragments ){
- ScoreFragIndex1 = (RowNumber1 * ppi->PlaneHFragments) +
- FragArrayOffset;
-
- ChLocalsPtr1 = &ppi->ChLocals[Row1Mod3 * BlockRowPixels];
- PixelsChangedPtr1 =
- &ppi->PixelChangedMap[(Row1Mod3) * BlockRowPixels];
-
- PixelScoresPtr1 = &ppi->PixelScores[(RowNumber1 % 4) * BlockRowPixels];
-
- YUVDiffsPtr1 = &ppi->yuv_differences[Row1Mod3 * BlockRowPixels];
- FragScoresPtr1 = &ppi->FragScores[ScoreFragIndex1];
- DispFragPtr1 = &ppi->ScanDisplayFragments[ScoreFragIndex1];
-
- }
-
- if ( RowNumber2 >= 0 ){
- ScoreFragIndex2 = (RowNumber2 * ppi->PlaneHFragments) +
- FragArrayOffset;
- ChLocalsPtr2 = (&ppi->ChLocals[Row2Mod3 * BlockRowPixels]);
- YUVDiffsPtr2 = &ppi->yuv_differences[Row2Mod3 * BlockRowPixels];
-
- PixelScoresPtr2 = &ppi->PixelScores[(RowNumber2 % 4) * BlockRowPixels];
-
- FragScoresPtr2 = &ppi->FragScores[ScoreFragIndex2];
- DispFragPtr2 = &ppi->ScanDisplayFragments[ScoreFragIndex2];
- }else{
- ChLocalsPtr2 = NULL;
- }
- }else{
- ChLocalsPtr1 = NULL;
- ChLocalsPtr2 = NULL;
- }
-
- /* Fast break out test for obvious yes and no cases in this row of
- blocks */
- if ( i < ppi->PlaneVFragments ){
- dsp_save_fpu (ppi->dsp);
- UpdatedOrCandidateBlocks =
- RowSadScan( ppi, RawPlanePtr0, RawPlanePtr1, DispFragPtr0 );
- UpdatedOrCandidateBlocks |=
- ColSadScan( ppi, RawPlanePtr0, RawPlanePtr1, DispFragPtr0 );
- dsp_restore_fpu (ppi->dsp);
- }else{
- /* Make sure we still call other functions if RowSadScan() disabled */
- UpdatedOrCandidateBlocks = 1;
- }
-
- /* Consolidation and fast break ot tests at Row 1 level */
- if ( (i > 0) && (RowNumber1 < ppi->PlaneVFragments) ){
- /* Mark as coded any candidate block that lies adjacent to a
- coded block. */
- SadPass2( ppi, RowNumber1, DispFragPtr1 );
-
- /* Check results of diff scan in last set of blocks. */
- /* Eliminate NO cases and add in +SGC cases */
- ConsolidateDiffScanResults( ppi, &ppi->FragDiffPixels[ScoreFragIndex1],
- &ppi->SameGreyDirPixels[ScoreFragIndex1],
- DispFragPtr1
- );
- }
-
- for ( j = 0; j < VFRAGPIXELS; j++ ){
- /* Last two iterations do not apply */
- if ( i < ppi->PlaneVFragments ){
- /* Is the current fragment at an edge. */
- EdgeRow = ( ( (i == 0) && (j == 0) ) ||
- ( (i == (ppi->PlaneVFragments - 1)) &&
- (j == (VFRAGPIXELS - 1)) ) );
-
- /* Clear the arrays that will be used for the changed pixels maps */
- memset( PixelsChangedPtr0, 0, ppi->PlaneWidth );
-
- /* Difference scan and map each row */
- if ( UpdatedOrCandidateBlocks ){
- /* Scan the row for interesting differences */
- /* Also clear the array that will be used for changed locals map */
- RowDiffScan( ppi, RawPlanePtr0, RawPlanePtr1,
- YUVDiffsPtr, PixelsChangedPtr0,
- &ppi->SameGreyDirPixels[FragIndex],
- DispFragPtr0, &ppi->FragDiffPixels[FragIndex],
- RowDiffsPtr, ChLocalsPtr0, EdgeRow);
- }else{
- /* Clear the array that will be used for changed locals map */
- memset( ChLocalsPtr0, 0, ppi->PlaneWidth );
- }
-
- /* The actual image plane pointers must be incremented by
- stride as this may be different (more) than the plane
- width. Our own internal buffers use ppi->PlaneWidth. */
- RawPlanePtr0 += ppi->PlaneStride;
- RawPlanePtr1 += ppi->PlaneStride;
- PixelsChangedPtr0 += ppi->PlaneWidth;
- ChLocalsPtr0 += ppi->PlaneWidth;
- YUVDiffsPtr += ppi->PlaneWidth;
- RowDiffsPtr++;
- }
-
- /* Run behind calculating the changed locals data and noise scores. */
- if ( ChLocalsPtr1 != NULL ){
- /* Last few iterations do not apply */
- if ( RowNumber1 < ppi->PlaneVFragments ){
- /* Blank the next row in the pixel scores data structure. */
- memset( PixelScoresPtr1, 0, ppi->PlaneWidth );
-
- /* Don't bother doing anything if there are no changed
- pixels in this row */
- if ( *RowDiffsPtr1 ){
- /* Last valid row is a special case */
- if ( i < ppi->PlaneVFragments )
- RowChangedLocalsScan( ppi, PixelsChangedPtr1, ChLocalsPtr1,
- DispFragPtr1,
- ( (((i-1)==0) && (j==0)) ?
- FIRST_ROW : NOT_EDGE_ROW) );
- else
- RowChangedLocalsScan( ppi, PixelsChangedPtr1, ChLocalsPtr1,
- DispFragPtr1,
- ((j==(VFRAGPIXELS-1)) ?
- LAST_ROW : NOT_EDGE_ROW) );
-
- NoiseScoreRow( ppi, PixelsChangedPtr1, ChLocalsPtr1, YUVDiffsPtr1,
- PixelScoresPtr1, FragScoresPtr1, DispFragPtr1,
- RowDiffsPtr1 );
- }
-
- ChLocalsPtr1 += ppi->PlaneWidth;
- PixelsChangedPtr1 += ppi->PlaneWidth;
- YUVDiffsPtr1 += ppi->PlaneWidth;
- PixelScoresPtr1 += ppi->PlaneWidth;
- RowDiffsPtr1 ++;
- }
-
- /* Run edge enhancement algorithms */
- if ( RowNumber2 < ppi->PlaneVFragments ){
- if ( ChLocalsPtr2 != NULL ){
- /* Don't bother doing anything if there are no changed
- pixels in this row */
- if ( *RowDiffsPtr2 ){
- if ( RowNumber1 < ppi->PlaneVFragments ){
- PrimaryEdgeScoreRow( ppi, ChLocalsPtr2, YUVDiffsPtr2,
- PixelScoresPtr2, FragScoresPtr2,
- DispFragPtr2,
- ( (((i-2)==0) && (j==0)) ?
- FIRST_ROW : NOT_EDGE_ROW) );
- }else{
- /* Edge enhancement */
- PrimaryEdgeScoreRow( ppi, ChLocalsPtr2, YUVDiffsPtr2,
- PixelScoresPtr2, FragScoresPtr2,
- DispFragPtr2,
- ((j==(VFRAGPIXELS-1)) ?
- LAST_ROW : NOT_EDGE_ROW) );
- }
-
- /* Recursive line search */
- LineSearchScoreRow( ppi, ChLocalsPtr2, YUVDiffsPtr2,
- PixelScoresPtr2, FragScoresPtr2,
- DispFragPtr2,
- LineSearchRowNumber );
- }
-
- ChLocalsPtr2 += ppi->PlaneWidth;
- YUVDiffsPtr2 += ppi->PlaneWidth;
- PixelScoresPtr2 += ppi->PlaneWidth;
- LineSearchRowNumber += 1;
- RowDiffsPtr2 ++;
- }
- }
- }
- }
-
- /* BAR algorithm */
- if ( (RowNumber3 >= 0) && (RowNumber3 < ppi->PlaneVFragments) ){
- ScoreFragIndex3 = (RowNumber3 * ppi->PlaneHFragments) + FragArrayOffset;
- RowBarEnhBlockMap(ppi,
- &ppi->ScanDisplayFragments[ScoreFragIndex3],
- &ppi->BarBlockMap[(RowNumber3 % 3) *
- ppi->PlaneHFragments],
- RowNumber3 );
- }
-
- /* BAR copy back and "ppi->SRF filtering" or "pixel copy back" */
- if ( (RowNumber4 >= 0) && (RowNumber4 < ppi->PlaneVFragments) ){
- /* BAR copy back stage must lag by one more row to avoid BAR blocks
- being used in BAR descisions. */
- ScoreFragIndex4 = (RowNumber4 * ppi->PlaneHFragments) + FragArrayOffset;
-
- BarCopyBack(ppi, &ppi->ScanDisplayFragments[ScoreFragIndex4],
- &ppi->BarBlockMap[(RowNumber4 % 3) * ppi->PlaneHFragments]);
- }
- }
-}
-
-ogg_uint32_t YUVAnalyseFrame( PP_INSTANCE *ppi, ogg_uint32_t * KFIndicator ){
-
- /* Initialise the map arrays. */
- InitScanMapArrays(ppi);
-
- /* If the motion level in the previous frame was high then adjust
- the high and low SAD thresholds to speed things up. */
- ppi->ModifiedGrpLowSadThresh = ppi->GrpLowSadThresh;
- ppi->ModifiedGrpHighSadThresh = ppi->GrpHighSadThresh;
-
-
- /* Set up the internal plane height and width variables. */
- ppi->VideoYPlaneWidth = ppi->ScanConfig.VideoFrameWidth;
- ppi->VideoYPlaneHeight = ppi->ScanConfig.VideoFrameHeight;
- ppi->VideoUVPlaneWidth = ppi->ScanConfig.VideoFrameWidth / 2;
- ppi->VideoUVPlaneHeight = ppi->ScanConfig.VideoFrameHeight / 2;
-
- /* To start with the strides will be set from the widths */
- ppi->VideoYPlaneStride = ppi->VideoYPlaneWidth;
- ppi->VideoUPlaneStride = ppi->VideoUVPlaneWidth;
- ppi->VideoVPlaneStride = ppi->VideoUVPlaneWidth;
-
- /* Set up the plane pointers */
- ppi->YPlanePtr0 = ppi->ScanConfig.Yuv0ptr;
- ppi->YPlanePtr1 = ppi->ScanConfig.Yuv1ptr;
- ppi->UPlanePtr0 = (ppi->ScanConfig.Yuv0ptr + ppi->YFramePixels);
- ppi->UPlanePtr1 = (ppi->ScanConfig.Yuv1ptr + ppi->YFramePixels);
- ppi->VPlanePtr0 = (ppi->ScanConfig.Yuv0ptr + ppi->YFramePixels +
- ppi->UVFramePixels);
- ppi->VPlanePtr1 = (ppi->ScanConfig.Yuv1ptr + ppi->YFramePixels +
- ppi->UVFramePixels);
-
- /* Check previous frame lists and if necessary mark extra blocks for
- update. */
- SetFromPrevious(ppi);
-
- /* Ananlyse the U and V palnes. */
- AnalysePlane( ppi, ppi->UPlanePtr0, ppi->UPlanePtr1,
- ppi->ScanYPlaneFragments, ppi->VideoUVPlaneWidth,
- ppi->VideoUVPlaneHeight, ppi->VideoUPlaneStride );
- AnalysePlane( ppi, ppi->VPlanePtr0, ppi->VPlanePtr1,
- (ppi->ScanYPlaneFragments + ppi->ScanUVPlaneFragments),
- ppi->VideoUVPlaneWidth, ppi->VideoUVPlaneHeight,
- ppi->VideoVPlaneStride );
-
- /* Now analyse the Y plane. */
- AnalysePlane( ppi, ppi->YPlanePtr0, ppi->YPlanePtr1, 0,
- ppi->VideoYPlaneWidth, ppi->VideoYPlaneHeight,
- ppi->VideoYPlaneStride );
-
- /* Update the list of previous frame block updates. */
- UpdatePreviousBlockLists(ppi);
-
- /* Create an output block map for the calling process. */
- CreateOutputDisplayMap( ppi, ppi->ScanDisplayFragments,
- ppi->PrevFragments[0],
- ppi->ScanConfig.disp_fragments );
-
- /* Set the candidate key frame indicator (0-100) */
- *KFIndicator = ppi->KFIndicator;
-
- /* Return the normalised block count (this is actually a motion
- level weighting not a true block count). */
- return ppi->OutputBlocksUpdated;
-}
-
More information about the commits
mailing list