Newer
Older
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( pu.cs->sps->getChromaFormatIdc() );
int refPicHeight = refPic->cs->pps->getPicHeightInLumaSamples() - ( inputConfWindow.getWindowTopOffset() + inputConfWindow.getWindowBottomOffset() ) * SPS::getWinUnitY( pu.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 = pu.cs->pps->getConformanceWindow();
int curPicHeight = pu.cs->pps->getPicHeightInLumaSamples() - ( curConfWindow.getWindowTopOffset() + curConfWindow.getWindowBottomOffset() ) * SPS::getWinUnitY( pu.cs->sps->getChromaFormatIdc() );
int curPicHeight = pu.cs->pps->getPicHeightInLumaSamples();
#endif
#endif
const int posShift = SCALE_RATIO_BITS - 4;
const ChromaFormat chFmt = pu.chromaFormat;
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 = ( ( pu.blocks[compID].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 = ( ( pu.blocks[compID].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 );
}
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 );
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
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, dstBuf.bufAt( 0, row ), dstBuf.stride, width, 1, yFrac, false, rndRes, chFmt, clpRng );
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 );
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
Position offset = Position( xInt, yInt );
refBuf = refPic->getRecoBuf( CompArea( compID, chFmt, offset, Size( 1, 1 ) ), wrapRef );
Pel* tempDstBuf = dstBuf.bufAt( col, row );
//--------------------------------copied from the "refPicWidth == curPicWidth" branch--------------------------------------------
if( yFrac == 0 )
{
m_if.filterHor( compID, (Pel*)refBuf.buf, refBuf.stride, /*dstBuf.buf*/tempDstBuf, dstBuf.stride, /*backupWidth*/1, /*backupHeight*/1, xFrac, rndRes, chFmt, clpRng );
}
else if( xFrac == 0 )
{
m_if.filterVer( compID, (Pel*)refBuf.buf, refBuf.stride, /*dstBuf.buf*/tempDstBuf, dstBuf.stride, /*backupWidth*/1, /*backupHeight*/1, yFrac, true, rndRes, chFmt, clpRng );
}
else
{
PelBuf tmpBuf = PelBuf( m_filteredBlockTmp[0][compID], pu.blocks[compID] );
tmpBuf.stride = dstBuf.stride;
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 );
}
JVET_J0090_SET_CACHE_ENABLE( false );
m_if.filterVer( compID, (Pel*)tmpBuf.buf + ( ( vFilterSize >> 1 ) - 1 ) * tmpBuf.stride, tmpBuf.stride, /*dstBuf.buf*/tempDstBuf, dstBuf.stride, /*backupWidth*/1, /*backupHeight*/1, yFrac, false, rndRes, chFmt, clpRng );
JVET_J0090_SET_CACHE_ENABLE( true );
}
//--------------------------------------------------------------------------------
}
}
#endif
}
return scaled;
}