xTransformSkip函数主要是用于残差在TransformSkip模式下对残差的操作,VTM7.0中不再对残差进行伸缩和移位,并且将变换跳过模式用于亮度和色度模式下,最大尺寸限制为32x32。
xTransformSkip函数主要适用于TransformSkip模式下跳过变换直接对残差系数进行伸缩和移位;TransformSkip模式主要用于Luma变换块,且最大尺寸限制为32x32
基本流程如下:
初始化移位系数iTransformShift和伸缩系数iWHScale判断移位系数iTransformShift,若iTransformShift大于等于0则直接将残差系数进行伸缩和移位并赋值给psCoeff,否则执行3将iTransformShift取反,然后获取偏移值offset,对残差系数进行伸缩并加上偏移再进行移位,再将结果赋值给psCoeff
代码如下:
void TrQuant::xTransformSkip(const TransformUnit &tu, const ComponentID &compID, const CPelBuf &resi, TCoeff* psCoeff)
{
#if JVET_P1000_REMOVE_TRANFORMSHIFT_IN_TS_MODE
const CompArea &rect = tu.blocks[compID];
const uint32_t width = rect.width;
const uint32_t height = rect.height;
for (uint32_t y = 0, coefficientIndex = 0; y < height; y++)
{
for (uint32_t x = 0; x < width; x++, coefficientIndex++)
{
psCoeff[ coefficientIndex ] = TCoeff(resi.at(x, y));
}
}
#else
const SPS &sps = *tu.cs->sps;
const CompArea &rect = tu.blocks[compID];
const uint32_t width = rect.width;
const uint32_t height = rect.height;
const ChannelType chType = toChannelType(compID);
const int channelBitDepth = sps.getBitDepth(chType);
const int maxLog2TrDynamicRange = sps.getMaxLog2TrDynamicRange(chType);
int iTransformShift = getTransformShift(channelBitDepth, rect.size(), maxLog2TrDynamicRange);
if( sps.getSpsRangeExtension().getExtendedPrecisionProcessingFlag() )
{
iTransformShift = std::max<int>( 0, iTransformShift );
}
int iWHScale = 1;
const bool rotateResidual = TU::isNonTransformedResidualRotated( tu, compID );
const uint32_t uiSizeMinus1 = ( width * height ) - 1;
if( iTransformShift >= 0 )
{
for( uint32_t y = 0, coefficientIndex = 0; y < height; y++ )
{
for( uint32_t x = 0; x < width; x++, coefficientIndex++ )
{
psCoeff[rotateResidual ? uiSizeMinus1 - coefficientIndex : coefficientIndex] = ( TCoeff( resi.at( x, y ) ) * iWHScale ) << iTransformShift;
}
}
}
else //for very high bit depths
{
iTransformShift = -iTransformShift;
const TCoeff offset = 1 << ( iTransformShift - 1 );
for( uint32_t y = 0, coefficientIndex = 0; y < height; y++ )
{
for( uint32_t x = 0; x < width; x++, coefficientIndex++ )
{
psCoeff[rotateResidual ? uiSizeMinus1 - coefficientIndex : coefficientIndex] = ( TCoeff( resi.at( x, y ) ) * iWHScale + offset ) >> iTransformShift;
}
}
}
#endif
}