?? uvlcreader.cpp
字號:
}
case LUMA_I16_AC:
{
pucScan = g_aucFrameScan;
uiPos=1;
DTRACE_T( "Luma:" );
DTRACE_V( cIdx );
DTRACE_N;
xPredictNonZeroCnt( rcMbDataAccess, cIdx, uiCoeffCnt, uiTrailingOnes );
xGetRunLevel( aiLevelRun, uiCoeffCnt, uiTrailingOnes, 15, uiTotalRun );
break;
}
case LUMA_SCAN:
{
pucScan = g_aucFrameScan;
DTRACE_T( "Luma:" );
DTRACE_V( cIdx );
DTRACE_N;
xPredictNonZeroCnt( rcMbDataAccess, cIdx, uiCoeffCnt, uiTrailingOnes );
xGetRunLevel( aiLevelRun, uiCoeffCnt, uiTrailingOnes, 16, uiTotalRun );
break;
}
default:
return Err::m_nERR;
}
uiPos += uiTotalRun + uiCoeffCnt - 1;
for ( Int i = (Int)uiCoeffCnt; i > 0; i-- )
{
piCoeff[ pucScan [uiPos--] ] = aiLevelRun[i-1];
for ( Int j = 0; j < aiLevelRun[i-1+0x10]; j++ )
{
piCoeff[ pucScan [uiPos--] ] = 0;
}
}
Bool bCoded = (uiCoeffCnt > 0);
if( ! bCoded )
{
ruiMbExtCbp &= ~(1 << cIdx.b4x4() );
}
return Err::m_nOK;
}
ErrVal UvlcReader::residualBlock( MbDataAccess& rcMbDataAccess,
ChromaIdx cIdx,
ResidualMode eResidualMode )
{
TCoeff* piCoeff = rcMbDataAccess.getMbTCoeffs().get( cIdx );
const UChar* pucScan;
UInt uiPos, uiMaxPos;
Int aiLevelRun[32];
UInt uiTrailingOnes = 0;
UInt uiTotalRun = 0;
UInt uiCoeffCnt = 0;
for ( uiPos = 0; uiPos < 32; uiPos++ )
{
aiLevelRun[uiPos] = 0;
}
uiPos = 0;
switch( eResidualMode )
{
case CHROMA_DC:
{
pucScan = g_aucIndexChromaDCScan;
uiPos=0; uiMaxPos= 4;
DTRACE_T( "CHROMA_DC:" );
DTRACE_V( cIdx );
DTRACE_N;
xGetTrailingOnes4( uiCoeffCnt, uiTrailingOnes );
xGetRunLevel( aiLevelRun, uiCoeffCnt, uiTrailingOnes, 4, uiTotalRun );
break;
}
case CHROMA_AC:
{
pucScan = g_aucFrameScan;
uiPos=1; uiMaxPos=16;
DTRACE_T( "CHROMA_AC:" );
DTRACE_V( cIdx );
DTRACE_N;
xPredictNonZeroCnt( rcMbDataAccess, cIdx, uiCoeffCnt, uiTrailingOnes );
xGetRunLevel( aiLevelRun, uiCoeffCnt, uiTrailingOnes, 15, uiTotalRun );
break;
}
default:
return Err::m_nERR;
}
uiPos += uiTotalRun + uiCoeffCnt - 1;
for ( Int i = (Int)uiCoeffCnt; i > 0; i-- )
{
piCoeff[ pucScan [uiPos--] ] = aiLevelRun[i-1];
for ( Int j = 0; j < aiLevelRun[i-1+0x10]; j++ )
{
piCoeff[ pucScan [uiPos--] ] = 0;
}
}
return Err::m_nOK;
}
ErrVal UvlcReader::transformSize8x8Flag( MbDataAccess& rcMbDataAccess )
{
DTRACE_T( "transformSize8x8Flag:" );
UInt uiCode;
RNOK( xGetFlag( uiCode) );
rcMbDataAccess.getMbData().setTransformSize8x8( uiCode?true:false );
DTRACE_V( uiCode );
DTRACE_N;
return Err::m_nOK;
}
ErrVal UvlcReader::xGetRefFrame( Bool bWriteBit, UInt& uiRefFrame )
{
DTRACE_T( "RefFrame" );
UInt uiCode;
if( bWriteBit )
{
RNOK( xGetFlag( uiCode ) );
uiRefFrame = 1-uiCode;
}
else
{
RNOK( xGetUvlcCode( uiRefFrame ) );
}
DTRACE_V( uiRefFrame+1 );
DTRACE_N;
return Err::m_nOK;
}
ErrVal UvlcReader::xGetMotionPredFlag( Bool& rbFlag )
{
DTRACE_T( "MotionPredFlag" );
UInt uiCode;
RNOK( xGetFlag( uiCode ) );
DTRACE_V( uiCode );
DTRACE_N;
rbFlag = (uiCode == 1);
return Err::m_nOK;
}
ErrVal UvlcReader::xGetMvd( Mv& cMv )
{
DTRACE_T( "Mvd: x" );
UInt uiTemp = 0;
RNOK( xGetUvlcCode( uiTemp ) );
Short sHor = ( uiTemp & 1) ? (Int)((uiTemp+1)>>1) : -(Int)(uiTemp>>1);
DTRACE_CODE( sHor );
DTRACE_TY("se(v)");
DTRACE_N;
DTRACE_T( "Mvd: y" );
RNOK( xGetUvlcCode( uiTemp ) );
Short sVer = ( uiTemp & 1) ? (Int)((uiTemp+1)>>1) : -(Int)(uiTemp>>1);
DTRACE_CODE( sVer );
DTRACE_TY("se(v)");
DTRACE_N;
cMv.setHor( sHor );
cMv.setVer( sVer );
return Err::m_nOK;
}
#if JMVM_ONLY // JVT-U052
ErrVal UvlcReader::Icpd( MbDataAccess& rcMbDataAccess )
{
UInt uiIcAct;
Icp cIcp;
RNOK( xGetFlag( uiIcAct) );
cIcp.setIcAct( uiIcAct );
if ( uiIcAct )
{
RNOK( xGetIcpd( cIcp ) );
}
rcMbDataAccess.getMbData().getMbIcp().setAllIcp(cIcp);
return Err::m_nOK;
}
ErrVal UvlcReader::xGetIcpd( Icp& cIcp )
{
UInt uiTemp;
DTRACE_T( "Icpd: offsetSym" );
RNOK( xGetUvlcCode( uiTemp ) );
Short sSymOffset = ( uiTemp & 1) ? (Int)((uiTemp+1)>>1) : -(Int)(uiTemp>>1);
DTRACE_CODE( sSymOffset );
DTRACE_TY("se(v)");
DTRACE_T( " offset " );
DTRACE_V( cIcp.getOffset() );
DTRACE_T( " pred " );
DTRACE_V( cIcp.getPredOffset() );
DTRACE_N;
return Err::m_nOK;
}
#endif
ErrVal UvlcReader::xPredictNonZeroCnt( MbDataAccess& rcMbDataAccess, LumaIdx cIdx, UInt& uiCoeffCount, UInt& uiTrailingOnes )
{
UInt uiCoeffCountCtx = rcMbDataAccess.getCtxCoeffCount( cIdx );
xGetTrailingOnes16( uiCoeffCountCtx, uiCoeffCount, uiTrailingOnes );
rcMbDataAccess.getMbTCoeffs().setCoeffCount( cIdx, uiCoeffCount );
return Err::m_nOK;
}
ErrVal UvlcReader::xPredictNonZeroCnt( MbDataAccess& rcMbDataAccess, ChromaIdx cIdx, UInt& uiCoeffCount, UInt& uiTrailingOnes )
{
UInt uiCoeffCountCtx = rcMbDataAccess.getCtxCoeffCount( cIdx );
xGetTrailingOnes16( uiCoeffCountCtx, uiCoeffCount, uiTrailingOnes );
rcMbDataAccess.getMbTCoeffs().setCoeffCount( cIdx, uiCoeffCount );
return Err::m_nOK;
}
ErrVal UvlcReader::xGetTrailingOnes16( UInt uiLastCoeffCount, UInt& uiCoeffCount, UInt& uiTrailingOnes )
{
DTRACE_POS;
if( 3 == uiLastCoeffCount )
{
UInt uiBits;
RNOK( m_pcBitReadBuffer->get( uiBits, 6 ) );
DTRACE_DO( m_uiBitCounter = 6 );
uiTrailingOnes = ( uiBits & 0x3 );
uiCoeffCount = ( uiBits >> 2 );
if ( !uiCoeffCount && uiTrailingOnes == 3 )
{
uiTrailingOnes = 0;
}
else
{
uiCoeffCount++;
}
}
else
{
assert (uiLastCoeffCount < 3);
RNOK( xCodeFromBitstream2D( &g_aucCodeTableTO16[uiLastCoeffCount][0][0], &g_aucLenTableTO16[uiLastCoeffCount][0][0], 17, 4, uiCoeffCount, uiTrailingOnes ) );
DTRACE_DO( m_uiBitCounter = g_aucLenTableTO16[uiLastCoeffCount][uiTrailingOnes][uiCoeffCount] );
}
DTRACE_T( " TrailingOnes16: Vlc: " );
DTRACE_V( uiLastCoeffCount );
DTRACE_T( " CoeffCnt: " );
DTRACE_V( uiCoeffCount );
DTRACE_T( " TraiOnes: " );
DTRACE_V( uiTrailingOnes );
DTRACE_N;
DTRACE_COUNT(m_uiBitCounter);
return Err::m_nOK;
}
ErrVal UvlcReader::xCodeFromBitstream2D( const UChar* aucCod, const UChar* aucLen, UInt uiWidth, UInt uiHeight, UInt& uiVal1, UInt& uiVal2 )
{
const UChar *paucLenTab;
const UChar *paucCodTab;
UChar uiLenRead = 0;
UChar uiCode = 0;
UChar uiMaxLen = 0;
// Find maximum number of bits to read before generating error
paucLenTab = aucLen;
paucCodTab = aucCod;
for (UInt j = 0; j < uiHeight; j++, paucLenTab += uiWidth, paucCodTab += uiWidth)
{
for ( UInt i = 0; i < uiWidth; i++ )
{
if ( paucLenTab[i] > uiMaxLen )
{
uiMaxLen = paucLenTab[i];
}
}
}
while ( uiLenRead < uiMaxLen )
{
// Read next bit
UInt uiBit;
RNOK( m_pcBitReadBuffer->get( uiBit, 1 ) );
uiCode = ( uiCode << 1 ) + uiBit;
uiLenRead++;
// Check for matches
paucLenTab = aucLen;
paucCodTab = aucCod;
for (UInt j = 0; j < uiHeight; j++, paucLenTab += uiWidth, paucCodTab += uiWidth)
{
for (UInt i = 0; i < uiWidth; i++)
{
if ( (paucLenTab[i] == uiLenRead) && (paucCodTab[i] == uiCode) )
{
uiVal1 = i;
uiVal2 = j;
return Err::m_nOK;
}
}
}
}
return Err::m_nERR;
}
ErrVal UvlcReader::xCodeFromBitstream2Di( const UInt* auiCod, const UInt* auiLen, UInt uiWidth, UInt uiHeight, UInt& uiVal1, UInt& uiVal2 )
{
const UInt *pauiLenTab;
const UInt *pauiCodTab;
UChar uiLenRead = 0;
UInt uiCode = 0;
UChar uiMaxLen = 0;
// Find maximum number of bits to read before generating error
pauiLenTab = auiLen;
pauiCodTab = auiCod;
for (UInt j = 0; j < uiHeight; j++, pauiLenTab += uiWidth, pauiCodTab += uiWidth)
{
for ( UInt i = 0; i < uiWidth; i++ )
{
if ( pauiLenTab[i] > uiMaxLen )
{
uiMaxLen = pauiLenTab[i];
}
}
}
while ( uiLenRead < uiMaxLen )
{
// Read next bit
UInt uiBit;
RNOK( m_pcBitReadBuffer->get( uiBit, 1 ) );
uiCode = ( uiCode << 1 ) + uiBit;
uiLenRead++;
// Check for matches
pauiLenTab = auiLen;
pauiCodTab = auiCod;
for (UInt j = 0; j < uiHeight; j++, pauiLenTab += uiWidth, pauiCodTab += uiWidth)
{
for (UInt i = 0; i < uiWidth; i++)
{
if ( (pauiLenTab[i] == uiLenRead) && (pauiCodTab[i] == uiCode) )
{
uiVal1 = i;
uiVal2 = j;
return Err::m_nOK;
}
}
}
}
return Err::m_nERR;
}
ErrVal UvlcReader::xGetRunLevel( Int* aiLevelRun, UInt uiCoeffCnt, UInt uiTrailingOnes, UInt uiMaxCoeffs, UInt& uiTotalRun )
{
ROTRS( 0 == uiCoeffCnt, Err::m_nOK );
if( uiTrailingOnes )
{
UInt uiBits;
RNOK( m_pcBitReadBuffer->get( uiBits, uiTrailingOnes ));
Int n = uiTrailingOnes-1;
for( UInt k = uiCoeffCnt; k > uiCoeffCnt-uiTrailingOnes; k--, n--)
{
aiLevelRun[k-1] = (uiBits & (1<<n)) ? -1 : 1;
}
DTRACE_POS;
DTRACE_T( " TrailingOnesSigns: " );
DTRACE_V( uiBits );
DTRACE_N;
DTRACE_COUNT(uiTrailingOnes);
}
UInt uiHighLevel = ( uiCoeffCnt > 3 && uiTrailingOnes == 3) ? 0 : 1;
UInt uiVlcTable = ( uiCoeffCnt > 10 && uiTrailingOnes < 3) ? 1 : 0;
for( Int k = uiCoeffCnt - 1 - uiTrailingOnes; k >= 0; k--)
{
Int iLevel;
if( uiVlcTable == 0 )
{
xGetLevelVLC0( iLevel );
}
else
{
xGetLevelVLCN( iLevel, uiVlcTable );
}
if( uiHighLevel )
{
iLevel += ( iLevel > 0 ) ? 1 : -1;
uiHighLevel = 0;
}
aiLevelRun[k] = iLevel;
UInt uiAbsLevel = (UInt)abs(iLevel);
// update VLC table
if( uiAbsLevel > g_auiIncVlc[ uiVlcTable ] )
{
uiVlcTable++;
}
if( k == Int(uiCoeffCnt - 1 - uiTrailingOnes) && uiAbsLevel > 3)
{
uiVlcTable = 2;
}
}
ROFRS( uiCoeffCnt < uiMaxCoeffs, Err::m_nOK );
uiVlcTable = uiCoeffCnt-1;
if( uiMaxCoeffs <= 4 )
{
xGetTotalRun4( uiVlcTable, uiTotalRun );
}
else
{
xGetTotalRun16( uiVlcTable, uiTotalRun );
}
// decode run before each coefficient
for ( UInt i = 0; i < uiCoeffCnt; i++ )
{
aiLevelRun[i + 0x10] = 0;
}
uiCoeffCnt--;
UInt uiRunCount = uiTotalRun;
if( uiRunCount > 0 && uiCoeffCnt > 0)
{
do
{
uiVlcTable = (( uiRunCount > RUNBEFORE_NUM) ? RUNBEFORE_NUM : uiRunCount) - 1;
UInt uiRun = 0;
xGetRun( uiVlcTable, uiRun );
aiLevelRun[uiCoeffCnt+0x10] = uiRun;
uiRunCount -= uiRun;
uiCoeffCnt--;
} while( uiRunCount != 0 && uiCoeffCnt != 0);
}
return Err::m_nOK;
}
ErrVal UvlcReader::xGetTrailingOnes4( UInt& uiCoeffCount, UInt& uiTrailingOnes )
{
RNOK( xCodeFromBitstream2D( &g_aucCodeTableTO4[0][0], &g_aucLenTableTO4[0][0], 5, 4, uiCoeffCount, uiTrailingOnes ) );
DTRACE_POS;
DTRACE_T( " TrailingOnes4: CoeffCnt: " );
DTRACE_V( uiCoeffCount );
DTRACE_T( " TraiOnes: " );
DTRACE_V( uiTrailingOnes );
DTRACE_N;
DTRACE_COUNT(g_aucLenTableTO4[uiTrailingOnes][uiCoeffCount]);
return Err::m_nOK;
}
ErrVal UvlcReader::xGetTotalRun4( UInt& uiVlcPos, UInt& uiTotalRun )
{
UInt uiTemp;
RNOK( xCodeFromBitstream2D( &g_aucCodeTableTZ4[uiVlcPos][0], &g_aucLenTableTZ4[uiVlcPos][0], 4, 1, uiTotalRun, uiTemp ) );
DTRACE_POS;
DTRACE_T( " TotalZeros4 vlc: " );
DTRACE_V( uiVlcPos );
DTRACE_T( " TotalRun: " );
DTRACE_V( uiTotalRun );
DTRACE_N;
DTRACE_COUNT(g_aucLenTableTZ4[uiVlcPos][uiTotalRun]);
return Err::m_nOK;
}
ErrVal UvlcReader::xGetTotalRun16( UInt uiVlcPos, UInt& uiTotalRun )
{
UInt uiTemp;
RNOK( xCodeFromBitstream2D( &g_aucCodeTableTZ16[uiVlcPos][0], &g_aucLenTableTZ16[uiVlcPos][0], 16, 1, uiTotalRun, uiTemp ) );
DTRACE_POS;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -