Newer
Older
const ComponentID compID = blk.compID;
const bool rndRes = !bi;
int shiftHor = MV_FRACTIONAL_BITS_INTERNAL + ::getComponentScaleX( compID, chFmt );
int shiftVer = MV_FRACTIONAL_BITS_INTERNAL + ::getComponentScaleY( compID, chFmt );
int width = blk.width;
int height = blk.height;
CPelBuf refBuf;
const bool scaled = scalingRatio != SCALE_1X;
if( scaled )
{
int row, col;
#if RPR_CONF_WINDOW
const Window& inputConfWindow = refPic->cs->pps->getConformanceWindow();
int refPicWidth = refPic->cs->pps->getPicWidthInLumaSamples() - ( inputConfWindow.getWindowLeftOffset() + inputConfWindow.getWindowRightOffset() ) * SPS::getWinUnitX( refPic->cs->sps->getChromaFormatIdc() );
int refPicHeight = refPic->cs->pps->getPicHeightInLumaSamples() - ( inputConfWindow.getWindowTopOffset() + inputConfWindow.getWindowBottomOffset() ) * SPS::getWinUnitY( refPic->cs->sps->getChromaFormatIdc() );
int refPicWidth = refPic->cs->pps->getPicWidthInLumaSamples();
int refPicHeight = refPic->cs->pps->getPicHeightInLumaSamples();
#endif
#if RPR_BUFFER
#if RPR_CONF_WINDOW
const Window& curConfWindow = pps.getConformanceWindow();
int curPicHeight = pps.getPicHeightInLumaSamples() - ( curConfWindow.getWindowTopOffset() + curConfWindow.getWindowBottomOffset() ) * SPS::getWinUnitY( refPic->cs->sps->getChromaFormatIdc() );
int curPicHeight = pps.getPicHeightInLumaSamples();
#endif
#endif
const int posShift = SCALE_RATIO_BITS - 4;
int stepX = ( scalingRatio.first + 8 ) >> 4;
int stepY = ( scalingRatio.second + 8 ) >> 4;
int64_t x0Int;
int64_t y0Int;
int offX = 1 << ( posShift - shiftHor - 1 );
int offY = 1 << ( posShift - shiftVer - 1 );
x0Int = ( ( blk.pos().x << ( 4 + ::getComponentScaleX( compID, chFmt ) ) ) + mv.getHor() )* scalingRatio.first;
x0Int = SIGN( x0Int ) * ( ( llabs( x0Int ) + ( (long long)1 << ( 7 + ::getComponentScaleX( compID, chFmt ) ) ) ) >> ( 8 + ::getComponentScaleX( compID, chFmt ) ) );
y0Int = ( ( blk.pos().y << ( 4 + ::getComponentScaleY( compID, chFmt ) ) ) + mv.getVer() )* scalingRatio.second;
y0Int = SIGN( y0Int ) * ( ( llabs( y0Int ) + ( (long long)1 << ( 7 + ::getComponentScaleY( compID, chFmt ) ) ) ) >> ( 8 + ::getComponentScaleY( compID, chFmt ) ) );
#if RPR_BUFFER
const int extSize = isLuma( compID ) ? 1 : 2;
int vFilterSize = isLuma( compID ) ? NTAPS_LUMA : NTAPS_CHROMA;
int refHeight = ( height * refPicHeight ) / curPicHeight;
refHeight = std::max<int>( 1, refHeight );
CHECK( MAX_CU_SIZE * MAX_SCALING_RATIO < refHeight + vFilterSize - 1 + extSize, "Buffer size is not enough, increase MAX_SCALING_RATIO" );
Pel buffer[( MAX_CU_SIZE + 16 ) * ( MAX_CU_SIZE * MAX_SCALING_RATIO + 16 )];
int tmpStride = width;
int yInt0 = ( (int32_t)y0Int + offY ) >> posShift;
yInt0 = std::min( std::max( 0, yInt0 ), ( refPicHeight >> ::getComponentScaleY( compID, chFmt ) ) );
int xInt0 = ( (int32_t)x0Int + offX ) >> posShift;
xInt0 = std::min( std::max( 0, xInt0 ), ( refPicWidth >> ::getComponentScaleX( compID, chFmt ) ) );
int xInt = 0, yInt = 0;
for( col = 0; col < width; col++ )
{
int posX = (int32_t)x0Int + col * stepX;
xInt = ( posX + offX ) >> posShift;
xInt = std::min( std::max( 0, xInt ), ( refPicWidth >> ::getComponentScaleX( compID, chFmt ) ) );
int xFrac = ( ( posX + offX ) >> ( posShift - shiftHor ) ) & ( ( 1 << shiftHor ) - 1 );
CHECK( xInt0 > xInt, "Wrong horizontal starting point" );
Position offset = Position( xInt, yInt0 );
refBuf = refPic->getRecoBuf( CompArea( compID, chFmt, offset, Size( 1, refHeight ) ), wrapRef );
Pel* tempBuf = buffer + col;
m_if.filterHor( compID, (Pel*)refBuf.buf - ( ( vFilterSize >> 1 ) - 1 ) * refBuf.stride, refBuf.stride, tempBuf, tmpStride, 1, refHeight + vFilterSize - 1 + extSize, xFrac, false, chFmt, clpRng, filterIndex, false, useAltHpelIf );
}
for( row = 0; row < height; row++ )
{
int posY = (int32_t)y0Int + row * stepY;
yInt = ( posY + offY ) >> posShift;
yInt = std::min( std::max( 0, yInt ), ( refPicHeight >> ::getComponentScaleY( compID, chFmt ) ) );
int yFrac = ( ( posY + offY ) >> ( posShift - shiftVer ) ) & ( ( 1 << shiftVer ) - 1 );
CHECK( yInt0 > yInt, "Wrong vertical starting point" );
Pel* tempBuf = buffer + ( yInt - yInt0 ) * tmpStride;
JVET_J0090_SET_CACHE_ENABLE( false );
m_if.filterVer( compID, tempBuf + ( ( vFilterSize >> 1 ) - 1 ) * tmpStride, tmpStride, dst + row * dstStride, dstStride, width, 1, yFrac, false, rndRes, chFmt, clpRng, filterIndex, false, useAltHpelIf );
JVET_J0090_SET_CACHE_ENABLE( true );
}
Position offset = Position( xInt, yInt );
refBuf = refPic->getRecoBuf( CompArea( compID, chFmt, offset, Size( 1, 1 ) ), wrapRef );
#else
for( row = 0; row < height; row++ )
{
for( col = 0; col < width; col++ )
{
// pixel position in the current picture
int posX = (int32_t)x0Int + col * stepX;
int posY = (int32_t)y0Int + row * stepY;
// integer reference position in the reference frame
int xInt = ( posX + offX ) >> posShift;
int yInt = ( posY + offY ) >> posShift;
xInt = std::min( std::max( 0, xInt ), ( refPicWidth >> ::getComponentScaleX( compID, chFmt ) ) );
yInt = std::min( std::max( 0, yInt ), ( refPicHeight >> ::getComponentScaleY( compID, chFmt ) ) );
// fractional position in the reference frame
int xFrac = ( ( posX + offX ) >> ( posShift - shiftHor ) ) & ( ( 1 << shiftHor ) - 1 );
int yFrac = ( ( posY + offY ) >> ( posShift - shiftVer ) ) & ( ( 1 << shiftVer ) - 1 );
Position offset = Position( xInt, yInt );
refBuf = refPic->getRecoBuf( CompArea( compID, chFmt, offset, Size( 1, 1 ) ), wrapRef );
Pel* tempDstBuf = dst + col + row * dstStride;
//--------------------------------copied from the "refPicWidth == curPicWidth" branch--------------------------------------------
if( yFrac == 0 )
{
m_if.filterHor( compID, (Pel*)refBuf.buf, refBuf.stride, /*dstBuf.buf*/tempDstBuf, dstStride, /*backupWidth*/1, /*backupHeight*/1, xFrac, rndRes, chFmt, clpRng, filterIndex, false, useAltHpelIf );
}
else if( xFrac == 0 )
{
m_if.filterVer( compID, (Pel*)refBuf.buf, refBuf.stride, /*dstBuf.buf*/tempDstBuf, dstStride, /*backupWidth*/1, /*backupHeight*/1, yFrac, true, rndRes, chFmt, clpRng, filterIndex, false, useAltHpelIf );
}
else
{
PelBuf tmpBuf = PelBuf( m_filteredBlockTmp[0][compID], blk );
tmpBuf.stride = dstStride;
int vFilterSize = isLuma( compID ) ? NTAPS_LUMA : NTAPS_CHROMA;
//for(int y = 0; y < vFilterSize; y++)
{
m_if.filterHor( compID, (Pel*)refBuf.buf - ( ( vFilterSize >> 1 ) - 1 ) * refBuf.stride, refBuf.stride, tmpBuf.buf, tmpBuf.stride, /*backupWidth*/1, /*backupHeight*/1 + vFilterSize - 1, xFrac, false, chFmt, clpRng, filterIndex, false, useAltHpelIf );
}
JVET_J0090_SET_CACHE_ENABLE( false );
m_if.filterVer( compID, (Pel*)tmpBuf.buf + ( ( vFilterSize >> 1 ) - 1 ) * tmpBuf.stride, tmpBuf.stride, /*dstBuf.buf*/tempDstBuf, dstStride, /*backupWidth*/1, /*backupHeight*/1, yFrac, false, rndRes, chFmt, clpRng, filterIndex, false, useAltHpelIf );
JVET_J0090_SET_CACHE_ENABLE( true );
}
//--------------------------------------------------------------------------------
}
}
#endif
}
return scaled;
}