void Search:: checkIntraInInter ( Mode& intraMode, const CUGeom& cuGeom)
{
ProfileCUScope ( intraMode. cu, intraAnalysisElapsedTime, countIntraAnalysis) ;
CUData& cu = intraMode. cu;
uint32_t depth = cuGeom. depth;
cu. setPartSizeSubParts ( SIZE_2Nx2N) ;
cu. setPredModeSubParts ( MODE_INTRA) ;
const uint32_t initTuDepth = 0 ;
uint32_t log2TrSize = cuGeom. log2CUSize - initTuDepth;
uint32_t tuSize = 1 << log2TrSize;
const uint32_t absPartIdx = 0 ;
IntraNeighbors intraNeighbors;
initIntraNeighbors ( cu, absPartIdx, initTuDepth, true , & intraNeighbors) ;
initAdiPattern ( cu, cuGeom, absPartIdx, intraNeighbors, ALL_IDX) ;
const pixel* fenc = intraMode. fencYuv- > m_buf[ 0 ] ;
uint32_t stride = intraMode. fencYuv- > m_size;
int sad, bsad;
uint32_t bits, bbits, mode, bmode;
uint64_t cost, bcost;
int scaleTuSize = tuSize;
int scaleStride = stride;
int costShift = 0 ;
int sizeIdx = log2TrSize - 2 ;
if ( tuSize > 32 )
{
primitives. scale2D_64to32 ( m_fencScaled, fenc, stride) ;
fenc = m_fencScaled;
pixel nScale[ 129 ] ;
intraNeighbourBuf[ 1 ] [ 0 ] = intraNeighbourBuf[ 0 ] [ 0 ] ;
primitives. scale1D_128to64[ NONALIGNED] ( nScale + 1 , intraNeighbourBuf[ 0 ] + 1 ) ;
memcpy ( & intraNeighbourBuf[ 0 ] [ 1 ] , & nScale[ 1 ] , 2 * 64 * sizeof ( pixel) ) ;
memcpy ( & intraNeighbourBuf[ 1 ] [ 1 ] , & nScale[ 1 ] , 2 * 64 * sizeof ( pixel) ) ;
scaleTuSize = 32 ;
scaleStride = 32 ;
costShift = 2 ;
sizeIdx = 5 - 2 ;
}
pixelcmp_t sa8d = primitives. cu[ sizeIdx] . sa8d;
int predsize = scaleTuSize * scaleTuSize;
m_entropyCoder. loadIntraDirModeLuma ( m_rqt[ depth] . cur) ;
uint64_t mpms;
uint32_t mpmModes[ 3 ] ;
uint32_t rbits = getIntraRemModeBits ( cu, absPartIdx, mpmModes, mpms) ;
primitives. cu[ sizeIdx] . intra_pred[ DC_IDX] ( m_intraPredAngs, scaleStride, intraNeighbourBuf[ 0 ] , 0 , ( scaleTuSize <= 16 ) ) ;
bsad = sa8d ( fenc, scaleStride, m_intraPredAngs, scaleStride) << costShift;
bmode = mode = DC_IDX;
bbits = ( mpms & ( ( uint64_t ) 1 << mode) ) ? m_entropyCoder. bitsIntraModeMPM ( mpmModes, mode) : rbits;
bcost = m_rdCost. calcRdSADCost ( bsad, bbits) ;
pixel* planar = intraNeighbourBuf[ 0 ] ;
if ( tuSize & ( 8 | 16 | 32 ) )
planar = intraNeighbourBuf[ 1 ] ;
primitives. cu[ sizeIdx] . intra_pred[ PLANAR_IDX] ( m_intraPredAngs, scaleStride, planar, 0 , 0 ) ;
sad = sa8d ( fenc, scaleStride, m_intraPredAngs, scaleStride) << costShift;
mode = PLANAR_IDX;
bits = ( mpms & ( ( uint64_t ) 1 << mode) ) ? m_entropyCoder. bitsIntraModeMPM ( mpmModes, mode) : rbits;
cost = m_rdCost. calcRdSADCost ( sad, bits) ;
COPY4_IF_LT ( bcost, cost, bmode, mode, bsad, sad, bbits, bits) ;
bool allangs = true ;
if ( primitives. cu[ sizeIdx] . intra_pred_allangs)
{
primitives. cu[ sizeIdx] . transpose ( m_fencTransposed, fenc, scaleStride) ;
primitives. cu[ sizeIdx] . intra_pred_allangs ( m_intraPredAngs, intraNeighbourBuf[ 0 ] , intraNeighbourBuf[ 1 ] , ( scaleTuSize <= 16 ) ) ;
}
else
allangs = false ;
#define TRY_ANGLE(angle) \
if (allangs) { \
if (angle < 18) \
sad = sa8d(m_fencTransposed, scaleTuSize, &m_intraPredAngs[(angle - 2) * predsize], scaleTuSize) << costShift; \
else \
sad = sa8d(fenc, scaleStride, &m_intraPredAngs[(angle - 2) * predsize], scaleTuSize) << costShift; \
bits = (mpms & ((uint64_t)1 << angle)) ? m_entropyCoder.bitsIntraModeMPM(mpmModes, angle) : rbits; \
cost = m_rdCost.calcRdSADCost(sad, bits); \
} else { \
int filter = !!(g_intraFilterFlags[angle] & scaleTuSize); \
primitives.cu[sizeIdx].intra_pred[angle](m_intraPredAngs, scaleTuSize, intraNeighbourBuf[filter], angle, scaleTuSize <= 16); \
sad = sa8d(fenc, scaleStride, m_intraPredAngs, scaleTuSize) << costShift; \
bits = (mpms & ((uint64_t)1 << angle)) ? m_entropyCoder.bitsIntraModeMPM(mpmModes, angle) : rbits; \
cost = m_rdCost.calcRdSADCost(sad, bits); \
}
if ( m_param- > bEnableFastIntra)
{
int asad = 0 ;
uint32_t lowmode, highmode, amode = 5 , abits = 0 ;
uint64_t acost = MAX_INT64;
for ( mode = 5 ; mode < 35 ; mode + = 5 )
{
TRY_ANGLE ( mode) ;
COPY4_IF_LT ( acost, cost, amode, mode, asad, sad, abits, bits) ;
}
for ( uint32_t dist = 2 ; dist >= 1 ; dist-- )
{
lowmode = amode - dist;
highmode = amode + dist;
X265_CHECK ( lowmode >= 2 && lowmode <= 34 , "low intra mode out of range\n" ) ;
TRY_ANGLE ( lowmode) ;
COPY4_IF_LT ( acost, cost, amode, lowmode, asad, sad, abits, bits) ;
X265_CHECK ( highmode >= 2 && highmode <= 34 , "high intra mode out of range\n" ) ;
TRY_ANGLE ( highmode) ;
COPY4_IF_LT ( acost, cost, amode, highmode, asad, sad, abits, bits) ;
}
if ( amode == 33 )
{
TRY_ANGLE ( 34 ) ;
COPY4_IF_LT ( acost, cost, amode, 34 , asad, sad, abits, bits) ;
}
COPY4_IF_LT ( bcost, acost, bmode, amode, bsad, asad, bbits, abits) ;
}
else
{
for ( mode = 2 ; mode < 35 ; mode++ )
{
TRY_ANGLE ( mode) ;
COPY4_IF_LT ( bcost, cost, bmode, mode, bsad, sad, bbits, bits) ;
}
}
cu. setLumaIntraDirSubParts ( ( uint8_t ) bmode, absPartIdx, depth + initTuDepth) ;
intraMode. initCosts ( ) ;
intraMode. totalBits = bbits;
intraMode. distortion = bsad;
intraMode. sa8dCost = bcost;
intraMode. sa8dBits = bbits;
}