📄 simpleintrapredictionprocess.cpp
字号:
/* Open H.264
*
* #include <standard_disclaimer>
*
* Authors: aitorgaray@yifan.net
* _
*/
#define __SIMPLE_INTRA_PREDICTION_PROCESS_CC
#include "SimpleIntraPredictionProcess.h"
#include "../TemporalLumaMacroblock.h"
#include "../TemporalBlock.h"
SimpleIntraPredictionProcess::SimpleIntraPredictionProcess( IntraPredictor& intraPredictor, Transform& transform, SADCalculator& sadCalculator, Quantize& quantize)
:IntraPredictionProcess( intraPredictor, transform, sadCalculator, quantize) {
}
// *toDO* refactor this into at least two methods
int SimpleIntraPredictionProcess::predictLumaMacroBlock( /* in out */ LumaMacroblock& macroblock,
/* out */ int* macroblockMode, int blockModes[ 4][ 4],
/* in*/ int qp) {
int mode; // *toDO* is painful to put for-scope variables here because of VisualC++ incompatibility issues
// find the best macro block mode
TemporalLumaMacroblock predictedMacroblock[ LUMA_16x16_PREDICTION_COUNT];
bool validMacroblock[ LUMA_16x16_PREDICTION_COUNT];
uint best16x16Mode = (uint )-1,
best16x16Cost = (uint )-1; // *noTE* huge cost
// *toDO* replace the 'true, true, true' with valid dynamic values
_intraPredictor.predictLuma16x16( macroblock, true, true, true, predictedMacroblock, validMacroblock);
for( mode = 0; mode < LUMA_16x16_PREDICTION_COUNT; mode++) {
if( validMacroblock[ mode]) {
uint cost;
_transform.do16x16HadamarTransform( predictedMacroblock[ mode]);
// see how much resembles to the original one
cost = _sadCalculator.calculate( macroblock, predictedMacroblock[ mode]);
if( cost < best16x16Cost) {
best16x16Cost = cost;
best16x16Mode = mode;
}
}
}
// be sure that at least we have checked one mode
ASSERT( best16x16Mode != (uint )-1);
*macroblockMode = best16x16Mode;
// find the best block mode
// we need this temporal macroblock because blocks must be predicted
// from previously predicted, encoded and decoded blocks, i.e., blocks
// from the deconding loop-back.
// *toDO* the same must be done outside this class in macro-block level
TemporalLumaMacroblock temporalMacroblock;
TemporalBlock predictedBlock[ LUMA_4x4_PREDICTION_COUNT];
bool validBlock[ LUMA_4x4_PREDICTION_COUNT];
uint best4x4Mode = (uint )-1,
best4x4Cost = (uint )-1; // *noTE* huge cost
// *toDO* think how to do it in a 'virtual' way for performance optimizations
//temporalMacroBlock.copyFrom( macroBlock);
// by = block y, bx = block x
for( int by = 0; by < 4; by++) {
for( int bx = 0; bx < 4; bx++) {
Block temporalBlock( temporalMacroblock.getBaseAddresForSubBlock( by, bx), temporalMacroblock._stride),
originalBlock( macroblock.getBaseAddresForSubBlock( by, bx), macroblock._stride);
// *toDO* replace the 'true, true, true' with valid dynamic values
_intraPredictor.predictLuma4x4( temporalBlock, true, true,true, predictedBlock, validBlock);
for( mode = 0; mode < LUMA_4x4_PREDICTION_COUNT; mode++) {
if( validBlock[ mode]) {
uint cost;
_transform.do4x4DCLumaForwardTransform( predictedBlock[ mode]);
// see how much resembles to the original one
cost = _sadCalculator.calculate( originalBlock, predictedBlock[ mode]);
if( cost < best4x4Cost) {
best4x4Cost = cost;
best4x4Mode = mode;
}
}
} // for( mode
ASSERT( best4x4Mode != (uint )-1);
blockModes[ by][ bx] = best4x4Mode;
// send best mode back to further block prediction
// *toDO*
//doCodificationAndDecodification( predictedBlock[ best4x4Mode], qp);
//temporalMacroBlock.copyFrom( predictedBlock[ best4x4Mode], by, bx);
} // for( by
} // for( bx
if( best16x16Cost < best4x4Cost) {
return 16;
} else {
return 4;
}
}
/* $Log:$
*
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -