Newer
Older
const int filterLength = downsampling ? 12 : (useLumaFilter ? NTAPS_LUMA : NTAPS_CHROMA);
#endif
#if RPR_ENABLE && IF_12TAP
const int log2Norm = downsampling ? 14 : 16;
#else
const int log2Norm = downsampling ? 14 : 12;
int *buf = new int[orgHeight * scaledWidth];
int maxVal = ( 1 << bitDepth ) - 1;
CHECK( bitDepth > 17, "Overflow may happen!" );
for( int i = 0; i < scaledWidth; i++ )
{
const Pel* org = orgSrc;
int refPos = ( ( ( i << compScale.first ) - afterScaleLeftOffset ) * scalingRatio.first + addX ) >> posShiftX;
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
int integer = refPos >> numFracShift;
int frac = refPos & numFracPositions;
int* tmp = buf + i;
for( int j = 0; j < orgHeight; j++ )
{
int sum = 0;
const TFilterCoeff* f = filterHor + frac * filterLength;
for( int k = 0; k < filterLength; k++ )
{
int xInt = std::min<int>( std::max( 0, integer + k - filterLength / 2 + 1 ), orgWidth - 1 );
sum += f[k] * org[xInt]; // postpone horizontal filtering gain removal after vertical filtering
}
*tmp = sum;
tmp += scaledWidth;
org += orgStride;
}
}
Pel* dst = scaledSrc;
for( int j = 0; j < scaledHeight; j++ )
{
int refPos = ( ( ( j << compScale.second ) - afterScaleTopOffset ) * scalingRatio.second + addY ) >> posShiftY;
int integer = refPos >> numFracShift;
int frac = refPos & numFracPositions;
for( int i = 0; i < scaledWidth; i++ )
{
#if RPR_ENABLE && IF_12TAP
uint64_t sum = 0;
#else
int sum = 0;
int* tmp = buf + i;
const TFilterCoeff* f = filterVer + frac * filterLength;
for( int k = 0; k < filterLength; k++ )
{
int yInt = std::min<int>( std::max( 0, integer + k - filterLength / 2 + 1 ), orgHeight - 1 );
sum += f[k] * tmp[yInt*scaledWidth];
}
#if RPR_ENABLE && IF_12TAP
const uint64_t one = 1;
int sumS = (int)((sum + (one << (log2Norm - 1))) >> log2Norm);
dst[i] = std::min<int>(std::max(0, sumS), maxVal);
#else
dst[i] = std::min<int>( std::max( 0, ( sum + ( 1 << ( log2Norm - 1 ) ) ) >> log2Norm ), maxVal );
}
dst += scaledStride;
}
delete[] buf;
}
void Picture::rescalePicture( const std::pair<int, int> scalingRatio,
const CPelUnitBuf& beforeScaling, const Window& scalingWindowBefore,
const PelUnitBuf& afterScaling, const Window& scalingWindowAfter,
const ChromaFormat chromaFormatIDC, const BitDepths& bitDepths, const bool useLumaFilter, const bool downsampling,
Kenneth Andersson
committed
const bool horCollocatedChromaFlag, const bool verCollocatedChromaFlag
#if JVET_AB0082
, bool rescaleForDisplay, int upscaleFilterForDisplay
#endif
)
{
for( int comp = 0; comp < ::getNumberValidComponents( chromaFormatIDC ); comp++ )
{
ComponentID compID = ComponentID( comp );
const CPelBuf& beforeScale = beforeScaling.get( compID );
const PelBuf& afterScale = afterScaling.get( compID );
sampleRateConv( scalingRatio, std::pair<int, int>( ::getComponentScaleX( compID, chromaFormatIDC ), ::getComponentScaleY( compID, chromaFormatIDC ) ),
beforeScale, scalingWindowBefore.getWindowLeftOffset() * SPS::getWinUnitX( chromaFormatIDC ), scalingWindowBefore.getWindowTopOffset() * SPS::getWinUnitY( chromaFormatIDC ),
afterScale, scalingWindowAfter.getWindowLeftOffset() * SPS::getWinUnitX( chromaFormatIDC ), scalingWindowAfter.getWindowTopOffset() * SPS::getWinUnitY( chromaFormatIDC ),
bitDepths.recon[toChannelType(compID)], downsampling || useLumaFilter ? true : isLuma( compID ), downsampling,
Kenneth Andersson
committed
isLuma( compID ) ? 1 : horCollocatedChromaFlag, isLuma( compID ) ? 1 : verCollocatedChromaFlag
#if JVET_AB0082
, rescaleForDisplay, upscaleFilterForDisplay
#endif
);
}
}
void Picture::saveSubPicBorder(int POC, int subPicX0, int subPicY0, int subPicWidth, int subPicHeight)
{
// 1.1 set up margin for back up memory allocation
int xMargin = margin >> getComponentScaleX(COMPONENT_Y, cs->area.chromaFormat);
int yMargin = margin >> getComponentScaleY(COMPONENT_Y, cs->area.chromaFormat);
// 1.2 measure the size of back up memory
Area areaAboveBelow(0, 0, subPicWidth + 2 * xMargin, yMargin);
Area areaLeftRight(0, 0, xMargin, subPicHeight);
UnitArea unitAreaAboveBelow(cs->area.chromaFormat, areaAboveBelow);
UnitArea unitAreaLeftRight(cs->area.chromaFormat, areaLeftRight);
// 1.3 create back up memory
m_bufSubPicAbove.create(unitAreaAboveBelow);
m_bufSubPicBelow.create(unitAreaAboveBelow);
m_bufSubPicLeft.create(unitAreaLeftRight);
m_bufSubPicRight.create(unitAreaLeftRight);
m_bufWrapSubPicAbove.create(unitAreaAboveBelow);
m_bufWrapSubPicBelow.create(unitAreaAboveBelow);
for (int comp = 0; comp < getNumberValidComponents(cs->area.chromaFormat); comp++)
{
ComponentID compID = ComponentID(comp);
// 2.1 measure the margin for each component
int xmargin = margin >> getComponentScaleX(compID, cs->area.chromaFormat);
int ymargin = margin >> getComponentScaleY(compID, cs->area.chromaFormat);
// 2.2 calculate the origin of the subpicture
Biao Wang
committed
int left = subPicX0 >> getComponentScaleX(compID, cs->area.chromaFormat);
int top = subPicY0 >> getComponentScaleY(compID, cs->area.chromaFormat);
// 2.3 calculate the width/height of the subPic
Biao Wang
committed
int width = subPicWidth >> getComponentScaleX(compID, cs->area.chromaFormat);
int height = subPicHeight >> getComponentScaleY(compID, cs->area.chromaFormat);
// 3.1.1 set reconstructed picture
PelBuf s = M_BUFS(0, PIC_RECONSTRUCTION).get(compID);
Biao Wang
committed
Pel *src = s.bufAt(left, top);
// 3.2.1 set back up buffer for left
PelBuf dBufLeft = m_bufSubPicLeft.getBuf(compID);
Pel *dstLeft = dBufLeft.bufAt(0, 0);
// 3.2.2 set back up buffer for right
PelBuf dBufRight = m_bufSubPicRight.getBuf(compID);
Pel *dstRight = dBufRight.bufAt(0, 0);
// 3.2.3 copy to recon picture to back up buffer
Pel *srcLeft = src - xmargin;
Pel *srcRight = src + width;
for (int y = 0; y < height; y++)
{
::memcpy(dstLeft + y * dBufLeft.stride, srcLeft + y * s.stride, sizeof(Pel) * xmargin);
::memcpy(dstRight + y * dBufRight.stride, srcRight + y * s.stride, sizeof(Pel) * xmargin);
}
// 3.3.1 set back up buffer for above
Biao Wang
committed
PelBuf dBufTop = m_bufSubPicAbove.getBuf(compID);
Pel *dstTop = dBufTop.bufAt(0, 0);
// 3.3.2 set back up buffer for below
Biao Wang
committed
PelBuf dBufBottom = m_bufSubPicBelow.getBuf(compID);
Pel *dstBottom = dBufBottom.bufAt(0, 0);
// 3.3.3 copy to recon picture to back up buffer
Biao Wang
committed
Pel *srcTop = src - xmargin - ymargin * s.stride;
Pel *srcBottom = src - xmargin + height * s.stride;
for (int y = 0; y < ymargin; y++)
{
Biao Wang
committed
::memcpy(dstTop + y * dBufTop.stride, srcTop + y * s.stride, sizeof(Pel) * (2 * xmargin + width));
::memcpy(dstBottom + y * dBufBottom.stride, srcBottom + y * s.stride, sizeof(Pel) * (2 * xmargin + width));
}
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
// back up recon wrap buffer
if (cs->sps->getWrapAroundEnabledFlag())
{
PelBuf sWrap = M_BUFS(0, PIC_RECON_WRAP).get(compID);
Pel *srcWrap = sWrap.bufAt(left, top);
// 3.4.1 set back up buffer for above
PelBuf dBufTopWrap = m_bufWrapSubPicAbove.getBuf(compID);
Pel *dstTopWrap = dBufTopWrap.bufAt(0, 0);
// 3.4.2 set back up buffer for below
PelBuf dBufBottomWrap = m_bufWrapSubPicBelow.getBuf(compID);
Pel *dstBottomWrap = dBufBottomWrap.bufAt(0, 0);
// 3.4.3 copy recon wrap picture to back up buffer
Pel *srcTopWrap = srcWrap - xmargin - ymargin * sWrap.stride;
Pel *srcBottomWrap = srcWrap - xmargin + height * sWrap.stride;
for (int y = 0; y < ymargin; y++)
{
::memcpy(dstTopWrap + y * dBufTopWrap.stride, srcTopWrap + y * sWrap.stride, sizeof(Pel) * (2 * xmargin + width));
::memcpy(dstBottomWrap + y * dBufBottomWrap.stride, srcBottomWrap + y * sWrap.stride, sizeof(Pel) * (2 * xmargin + width));
}
}
}
}
void Picture::extendSubPicBorder(int POC, int subPicX0, int subPicY0, int subPicWidth, int subPicHeight)
{
for (int comp = 0; comp < getNumberValidComponents(cs->area.chromaFormat); comp++)
{
ComponentID compID = ComponentID(comp);
// 2.1 measure the margin for each component
int xmargin = margin >> getComponentScaleX(compID, cs->area.chromaFormat);
int ymargin = margin >> getComponentScaleY(compID, cs->area.chromaFormat);
// 2.2 calculate the origin of the Subpicture
Biao Wang
committed
int left = subPicX0 >> getComponentScaleX(compID, cs->area.chromaFormat);
int top = subPicY0 >> getComponentScaleY(compID, cs->area.chromaFormat);
// 2.3 calculate the width/height of the Subpicture
Biao Wang
committed
int width = subPicWidth >> getComponentScaleX(compID, cs->area.chromaFormat);
int height = subPicHeight >> getComponentScaleY(compID, cs->area.chromaFormat);
int numPt = (cs->isGdrEnabled()) ? 2 : 1;
for (int i = 0; i < numPt; i++)
{
PelBuf s = M_BUFS(0, PIC_RECONSTRUCTION+i).get(compID);
Pel *src = s.bufAt(left, top);
#else
// 3.1 set reconstructed picture
PelBuf s = M_BUFS(0, PIC_RECONSTRUCTION).get(compID);
Pel *src = s.bufAt(left, top);
#endif
// 4.1 apply padding for left and right
Biao Wang
committed
Pel *dstLeft = src - xmargin;
Pel *dstRight = src + width;
Pel *srcLeft = src + 0;
Pel *srcRight = src + width - 1;
for (int y = 0; y < height; y++)
{
for (int x = 0; x < xmargin; x++)
{
Biao Wang
committed
dstLeft[x] = *srcLeft;
dstRight[x] = *srcRight;
}
Biao Wang
committed
dstLeft += s.stride;
dstRight += s.stride;
srcLeft += s.stride;
srcRight += s.stride;
// 4.2 apply padding on bottom
Pel *srcBottom = src + s.stride * (height - 1) - xmargin;
Pel *dstBottom = srcBottom + s.stride;
for (int y = 0; y < ymargin; y++)
{
::memcpy(dstBottom, srcBottom, sizeof(Pel)*(2 * xmargin + width));
dstBottom += s.stride;
}
// 4.3 apply padding for top
// si is still (-marginX, SubpictureHeight-1)
Pel *srcTop = src - xmargin;
Pel *dstTop = srcTop - s.stride;
// si is now (-marginX, 0)
for (int y = 0; y < ymargin; y++)
{
::memcpy(dstTop, srcTop, sizeof(Pel)*(2 * xmargin + width));
dstTop -= s.stride;
}
#if JVET_Z0118_GDR
} // for loop
#endif
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
// Appy padding for recon wrap buffer
if (cs->sps->getWrapAroundEnabledFlag())
{
// set recon wrap picture
PelBuf sWrap = M_BUFS(0, PIC_RECON_WRAP).get(compID);
Pel *srcWrap = sWrap.bufAt(left, top);
// apply padding on bottom
Pel *srcBottomWrap = srcWrap + sWrap.stride * (height - 1) - xmargin;
Pel *dstBottomWrap = srcBottomWrap + sWrap.stride;
for (int y = 0; y < ymargin; y++)
{
::memcpy(dstBottomWrap, srcBottomWrap, sizeof(Pel)*(2 * xmargin + width));
dstBottomWrap += sWrap.stride;
}
// apply padding for top
// si is still (-marginX, SubpictureHeight-1)
Pel *srcTopWrap = srcWrap - xmargin;
Pel *dstTopWrap = srcTopWrap - sWrap.stride;
// si is now (-marginX, 0)
for (int y = 0; y < ymargin; y++)
{
::memcpy(dstTopWrap, srcTopWrap, sizeof(Pel)*(2 * xmargin + width));
dstTopWrap -= sWrap.stride;
}
}
}
void Picture::restoreSubPicBorder(int POC, int subPicX0, int subPicY0, int subPicWidth, int subPicHeight)
{
for (int comp = 0; comp < getNumberValidComponents(cs->area.chromaFormat); comp++)
{
ComponentID compID = ComponentID(comp);
// 2.1 measure the margin for each component
int xmargin = margin >> getComponentScaleX(compID, cs->area.chromaFormat);
int ymargin = margin >> getComponentScaleY(compID, cs->area.chromaFormat);
// 2.2 calculate the origin of the subpicture
Biao Wang
committed
int left = subPicX0 >> getComponentScaleX(compID, cs->area.chromaFormat);
int top = subPicY0 >> getComponentScaleY(compID, cs->area.chromaFormat);
// 2.3 calculate the width/height of the subpicture
Biao Wang
committed
int width = subPicWidth >> getComponentScaleX(compID, cs->area.chromaFormat);
int height = subPicHeight >> getComponentScaleY(compID, cs->area.chromaFormat);
// 3.1 set reconstructed picture
PelBuf s = M_BUFS(0, PIC_RECONSTRUCTION).get(compID);
Biao Wang
committed
Pel *src = s.bufAt(left, top);
// 4.2.1 copy from back up buffer to recon picture
PelBuf dBufLeft = m_bufSubPicLeft.getBuf(compID);
Pel *dstLeft = dBufLeft.bufAt(0, 0);
// 4.2.2 set back up buffer for right
PelBuf dBufRight = m_bufSubPicRight.getBuf(compID);
Pel *dstRight = dBufRight.bufAt(0, 0);
// 4.2.3 copy to recon picture to back up buffer
Pel *srcLeft = src - xmargin;
Pel *srcRight = src + width;
for (int y = 0; y < height; y++)
{
// the destination and source position is reversed on purpose
::memcpy(srcLeft + y * s.stride, dstLeft + y * dBufLeft.stride, sizeof(Pel) * xmargin);
::memcpy(srcRight + y * s.stride, dstRight + y * dBufRight.stride, sizeof(Pel) * xmargin);
}
Biao Wang
committed
// 4.3.1 set back up buffer for above
PelBuf dBufTop = m_bufSubPicAbove.getBuf(compID);
Pel *dstTop = dBufTop.bufAt(0, 0);
// 4.3.2 set back up buffer for below
Biao Wang
committed
PelBuf dBufBottom = m_bufSubPicBelow.getBuf(compID);
Pel *dstBottom = dBufBottom.bufAt(0, 0);
// 4.3.3 copy to recon picture to back up buffer
Biao Wang
committed
Pel *srcTop = src - xmargin - ymargin * s.stride;
Pel *srcBottom = src - xmargin + height * s.stride;
for (int y = 0; y < ymargin; y++)
{
Biao Wang
committed
::memcpy(srcTop + y * s.stride, dstTop + y * dBufTop.stride, sizeof(Pel) * (2 * xmargin + width));
::memcpy(srcBottom + y * s.stride, dstBottom + y * dBufBottom.stride, sizeof(Pel) * (2 * xmargin + width));
}
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
// restore recon wrap buffer
if (cs->sps->getWrapAroundEnabledFlag())
{
// set recon wrap picture
PelBuf sWrap = M_BUFS(0, PIC_RECON_WRAP).get(compID);
Pel *srcWrap = sWrap.bufAt(left, top);
// set back up buffer for above
PelBuf dBufTopWrap = m_bufWrapSubPicAbove.getBuf(compID);
Pel *dstTopWrap = dBufTopWrap.bufAt(0, 0);
// set back up buffer for below
PelBuf dBufBottomWrap = m_bufWrapSubPicBelow.getBuf(compID);
Pel *dstBottomWrap = dBufBottomWrap.bufAt(0, 0);
// copy to recon wrap picture from back up buffer
Pel *srcTopWrap = srcWrap - xmargin - ymargin * sWrap.stride;
Pel *srcBottomWrap = srcWrap - xmargin + height * sWrap.stride;
for (int y = 0; y < ymargin; y++)
{
::memcpy(srcTopWrap + y * sWrap.stride, dstTopWrap + y * dBufTopWrap.stride, sizeof(Pel) * (2 * xmargin + width));
::memcpy(srcBottomWrap + y * sWrap.stride, dstBottomWrap + y * dBufBottomWrap.stride, sizeof(Pel) * (2 * xmargin + width));
}
}
}
// 5.0 destroy the back up memory
m_bufSubPicAbove.destroy();
m_bufSubPicBelow.destroy();
m_bufSubPicLeft.destroy();
m_bufSubPicRight.destroy();
m_bufWrapSubPicAbove.destroy();
m_bufWrapSubPicBelow.destroy();
}
void Picture::extendPicBorder( const PPS *pps )

Karsten Suehring
committed
{
if ( m_bIsBorderExtended )
{
if( isWrapAroundEnabled( pps ) && ( !m_wrapAroundValid || m_wrapAroundOffset != pps->getWrapAroundOffset() ) )
{
extendWrapBorder( pps );
}

Karsten Suehring
committed
return;
}
int numPt = (cs->isGdrEnabled()) ? PIC_RECONSTRUCTION_1 : PIC_RECONSTRUCTION_0;
Seungwook Hong
committed
for (int pt = (int) PIC_RECONSTRUCTION_0; pt <= (int) numPt; pt++)
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
{
for (int comp = 0; comp < getNumberValidComponents(cs->area.chromaFormat); comp++)
{
ComponentID compID = ComponentID(comp);
PelBuf p = M_BUFS(0, (PictureType) pt).get(compID);
Pel *piTxt = p.bufAt(0, 0);
int xmargin = margin >> getComponentScaleX(compID, cs->area.chromaFormat);
int ymargin = margin >> getComponentScaleY(compID, cs->area.chromaFormat);
Pel* pi = piTxt;
// do left and right margins
for (int y = 0; y < p.height; y++)
{
for (int x = 0; x < xmargin; x++)
{
pi[-xmargin + x] = pi[0];
pi[p.width + x] = pi[p.width - 1];
}
pi += p.stride;
}
// pi is now the (0,height) (bottom left of image within bigger picture
pi -= (p.stride + xmargin);
// pi is now the (-marginX, height-1)
for (int y = 0; y < ymargin; y++)
{
::memcpy(pi + (y + 1)*p.stride, pi, sizeof(Pel)*(p.width + (xmargin << 1)));
}
// pi is still (-marginX, height-1)
pi -= ((p.height - 1) * p.stride);
// pi is now (-marginX, 0)
for (int y = 0; y < ymargin; y++)
{
::memcpy(pi - (y + 1)*p.stride, pi, sizeof(Pel)*(p.width + (xmargin << 1)));
}
// reference picture with horizontal wrapped boundary
if (isWrapAroundEnabled(pps))
{
extendWrapBorder(pps);
}
else
{
m_wrapAroundValid = false;
m_wrapAroundOffset = 0;
}
}
}
#else

Karsten Suehring
committed
for(int comp=0; comp<getNumberValidComponents( cs->area.chromaFormat ); comp++)
{
ComponentID compID = ComponentID( comp );
PelBuf p = M_BUFS( 0, PIC_RECONSTRUCTION ).get( compID );
Pel *piTxt = p.bufAt(0,0);
int xmargin = margin >> getComponentScaleX( compID, cs->area.chromaFormat );
int ymargin = margin >> getComponentScaleY( compID, cs->area.chromaFormat );
Pel* pi = piTxt;
// do left and right margins
for (int y = 0; y < p.height; y++)
{
for (int x = 0; x < xmargin; x++)
pi[-xmargin + x] = pi[0];
pi[p.width + x] = pi[p.width - 1];

Karsten Suehring
committed
// pi is now the (0,height) (bottom left of image within bigger picture
pi -= (p.stride + xmargin);
// pi is now the (-marginX, height-1)
for (int y = 0; y < ymargin; y++ )
{
::memcpy( pi + (y+1)*p.stride, pi, sizeof(Pel)*(p.width + (xmargin << 1)));
}
// pi is still (-marginX, height-1)
pi -= ((p.height-1) * p.stride);
// pi is now (-marginX, 0)
for (int y = 0; y < ymargin; y++ )
{
::memcpy( pi - (y+1)*p.stride, pi, sizeof(Pel)*(p.width + (xmargin<<1)) );
}
// reference picture with horizontal wrapped boundary
if ( isWrapAroundEnabled( pps ) )
{
extendWrapBorder( pps );
}
else
{
m_wrapAroundValid = false;
m_wrapAroundOffset = 0;
}

Karsten Suehring
committed
}

Karsten Suehring
committed
m_bIsBorderExtended = true;
}
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
void Picture::extendWrapBorder( const PPS *pps )
{
for(int comp=0; comp<getNumberValidComponents( cs->area.chromaFormat ); comp++)
{
ComponentID compID = ComponentID( comp );
PelBuf p = M_BUFS( 0, PIC_RECON_WRAP ).get( compID );
p.copyFrom(M_BUFS( 0, PIC_RECONSTRUCTION ).get( compID ));
Pel *piTxt = p.bufAt(0,0);
int xmargin = margin >> getComponentScaleX( compID, cs->area.chromaFormat );
int ymargin = margin >> getComponentScaleY( compID, cs->area.chromaFormat );
Pel* pi = piTxt;
int xoffset = pps->getWrapAroundOffset() >> getComponentScaleX( compID, cs->area.chromaFormat );
for (int y = 0; y < p.height; y++)
{
for (int x = 0; x < xmargin; x++ )
{
if( x < xoffset )
{
pi[ -x - 1 ] = pi[ -x - 1 + xoffset ];
pi[ p.width + x ] = pi[ p.width + x - xoffset ];
}
else
{
pi[ -x - 1 ] = pi[ 0 ];
pi[ p.width + x ] = pi[ p.width - 1 ];
}
}
pi += p.stride;
}
pi -= (p.stride + xmargin);
for (int y = 0; y < ymargin; y++ )
{
::memcpy( pi + (y+1)*p.stride, pi, sizeof(Pel)*(p.width + (xmargin << 1)));
}
pi -= ((p.height-1) * p.stride);
for (int y = 0; y < ymargin; y++ )
{
::memcpy( pi - (y+1)*p.stride, pi, sizeof(Pel)*(p.width + (xmargin<<1)) );
}
}
m_wrapAroundValid = true;
m_wrapAroundOffset = pps->getWrapAroundOffset();
}

Karsten Suehring
committed
PelBuf Picture::getBuf( const ComponentID compID, const PictureType &type )
{
if (type == PIC_RECONSTRUCTION_0 || type == PIC_RECONSTRUCTION_1)
{
return M_BUFS(scheduler.getSplitPicId(), type).getBuf(compID);
}
#endif
return M_BUFS( ( type == PIC_ORIGINAL || type == PIC_TRUE_ORIGINAL || type == PIC_FILTERED_ORIGINAL || type == PIC_ORIGINAL_INPUT || type == PIC_TRUE_ORIGINAL_INPUT || type == PIC_FILTERED_ORIGINAL_INPUT ) ? 0 : scheduler.getSplitPicId(), type ).getBuf( compID );

Karsten Suehring
committed
}
const CPelBuf Picture::getBuf( const ComponentID compID, const PictureType &type ) const
{
if (type == PIC_RECONSTRUCTION_0 || type == PIC_RECONSTRUCTION_1)
{
return M_BUFS(scheduler.getSplitPicId(), type).getBuf(compID);
}
#endif
return M_BUFS( ( type == PIC_ORIGINAL || type == PIC_TRUE_ORIGINAL || type == PIC_FILTERED_ORIGINAL || type == PIC_ORIGINAL_INPUT || type == PIC_TRUE_ORIGINAL_INPUT || type == PIC_FILTERED_ORIGINAL_INPUT ) ? 0 : scheduler.getSplitPicId(), type ).getBuf( compID );

Karsten Suehring
committed
}
PelBuf Picture::getBuf( const CompArea &blk, const PictureType &type )
{
if( !blk.valid() )
{
return PelBuf();
}
#if ENABLE_SPLIT_PARALLELISM
const int jId = ( type == PIC_ORIGINAL || type == PIC_TRUE_ORIGINAL || type == PIC_ORIGINAL_INPUT || type == PIC_TRUE_ORIGINAL_INPUT ) ? 0 : scheduler.getSplitPicId();

Karsten Suehring
committed
#endif
#if !KEEP_PRED_AND_RESI_SIGNALS
#if JVET_AC0162_ALF_RESIDUAL_SAMPLES_INPUT
if (type == PIC_PREDICTION)
#else

Karsten Suehring
committed
if( type == PIC_RESIDUAL || type == PIC_PREDICTION )

Karsten Suehring
committed
{
CompArea localBlk = blk;
localBlk.x &= ( cs->pcv->maxCUWidthMask >> getComponentScaleX( blk.compID, blk.chromaFormat ) );
localBlk.y &= ( cs->pcv->maxCUHeightMask >> getComponentScaleY( blk.compID, blk.chromaFormat ) );
return M_BUFS( jId, type ).getBuf( localBlk );
}
#endif
return M_BUFS( jId, type ).getBuf( blk );
}
const CPelBuf Picture::getBuf( const CompArea &blk, const PictureType &type ) const
{
if( !blk.valid() )
{
return PelBuf();
}
#if ENABLE_SPLIT_PARALLELISM
const int jId = ( type == PIC_ORIGINAL || type == PIC_TRUE_ORIGINAL ) ? 0 : scheduler.getSplitPicId();

Karsten Suehring
committed
#endif
#if !KEEP_PRED_AND_RESI_SIGNALS
#if JVET_AC0162_ALF_RESIDUAL_SAMPLES_INPUT
if (type == PIC_PREDICTION)
#else

Karsten Suehring
committed
if( type == PIC_RESIDUAL || type == PIC_PREDICTION )

Karsten Suehring
committed
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
{
CompArea localBlk = blk;
localBlk.x &= ( cs->pcv->maxCUWidthMask >> getComponentScaleX( blk.compID, blk.chromaFormat ) );
localBlk.y &= ( cs->pcv->maxCUHeightMask >> getComponentScaleY( blk.compID, blk.chromaFormat ) );
return M_BUFS( jId, type ).getBuf( localBlk );
}
#endif
return M_BUFS( jId, type ).getBuf( blk );
}
PelUnitBuf Picture::getBuf( const UnitArea &unit, const PictureType &type )
{
if( chromaFormat == CHROMA_400 )
{
return PelUnitBuf( chromaFormat, getBuf( unit.Y(), type ) );
}
else
{
return PelUnitBuf( chromaFormat, getBuf( unit.Y(), type ), getBuf( unit.Cb(), type ), getBuf( unit.Cr(), type ) );
}
}
const CPelUnitBuf Picture::getBuf( const UnitArea &unit, const PictureType &type ) const
{
if( chromaFormat == CHROMA_400 )
{
return CPelUnitBuf( chromaFormat, getBuf( unit.Y(), type ) );
}
else
{
return CPelUnitBuf( chromaFormat, getBuf( unit.Y(), type ), getBuf( unit.Cb(), type ), getBuf( unit.Cr(), type ) );
}
}
Pel* Picture::getOrigin( const PictureType &type, const ComponentID compID ) const
{
#if ENABLE_SPLIT_PARALLELISM
const int jId = ( type == PIC_ORIGINAL || type == PIC_TRUE_ORIGINAL ) ? 0 : scheduler.getSplitPicId();

Karsten Suehring
committed
#endif
return M_BUFS( jId, type ).getOrigin( compID );
}
void Picture::createSpliceIdx(int nums)
{
m_ctuNums = nums;
m_spliceIdx = new int[m_ctuNums];
memset(m_spliceIdx, 0, m_ctuNums * sizeof(int));
}
bool Picture::getSpliceFull()
{
int count = 0;
for (int i = 0; i < m_ctuNums; i++)
{
if (m_spliceIdx[i] != 0)
count++;
}
if (count < m_ctuNums * 0.25)
return false;
return true;
}
void Picture::addPictureToHashMapForInter()
{
int picWidth = slices[0]->getPPS()->getPicWidthInLumaSamples();
int picHeight = slices[0]->getPPS()->getPicHeightInLumaSamples();
bool* bIsBlockSame[2][3];
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
blockHashValues[i][j] = new uint32_t[picWidth*picHeight];
}
for (int j = 0; j < 3; j++)
{
bIsBlockSame[i][j] = new bool[picWidth*picHeight];
}
}
m_hashMap.create(picWidth, picHeight);
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
m_hashMap.generateBlock2x2HashValue(getOrigBuf(), picWidth, picHeight, slices[0]->getSPS()->getBitDepths(), blockHashValues[0], bIsBlockSame[0]);//2x2
m_hashMap.generateBlockHashValue(picWidth, picHeight, 4, 4, blockHashValues[0], blockHashValues[1], bIsBlockSame[0], bIsBlockSame[1]);//4x4
m_hashMap.addToHashMapByRowWithPrecalData(blockHashValues[1], bIsBlockSame[1][2], picWidth, picHeight, 4, 4);
m_hashMap.generateBlockHashValue(picWidth, picHeight, 8, 8, blockHashValues[1], blockHashValues[0], bIsBlockSame[1], bIsBlockSame[0]);//8x8
m_hashMap.addToHashMapByRowWithPrecalData(blockHashValues[0], bIsBlockSame[0][2], picWidth, picHeight, 8, 8);
m_hashMap.generateBlockHashValue(picWidth, picHeight, 16, 16, blockHashValues[0], blockHashValues[1], bIsBlockSame[0], bIsBlockSame[1]);//16x16
m_hashMap.addToHashMapByRowWithPrecalData(blockHashValues[1], bIsBlockSame[1][2], picWidth, picHeight, 16, 16);
m_hashMap.generateBlockHashValue(picWidth, picHeight, 32, 32, blockHashValues[1], blockHashValues[0], bIsBlockSame[1], bIsBlockSame[0]);//32x32
m_hashMap.addToHashMapByRowWithPrecalData(blockHashValues[0], bIsBlockSame[0][2], picWidth, picHeight, 32, 32);
m_hashMap.generateBlockHashValue(picWidth, picHeight, 64, 64, blockHashValues[0], blockHashValues[1], bIsBlockSame[0], bIsBlockSame[1]);//64x64
m_hashMap.addToHashMapByRowWithPrecalData(blockHashValues[1], bIsBlockSame[1][2], picWidth, picHeight, 64, 64);
m_hashMap.setInitial();
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
delete[] blockHashValues[i][j];
}
for (int j = 0; j < 3; j++)
{
delete[] bIsBlockSame[i][j];
}
}
}
#if JVET_Z0118_GDR
void Picture::initCleanCurPicture()
{
if (!cs->isGdrEnabled())
{
return;
}
const int picWidth = getPicWidthInLumaSamples();
const int picHight = getPicHeightInLumaSamples();
const int bitDepth = slices[0]->getSPS()->getBitDepth(CHANNEL_TYPE_LUMA);
const Pel dirtyPelVal = 1 << (bitDepth - 1);
UnitArea wholePictureArea = UnitArea(chromaFormat, Area(Position(0, 0), Size(picWidth, picHight)));
getBuf(wholePictureArea, PIC_RECONSTRUCTION_0).fill(dirtyPelVal);
getBuf(wholePictureArea, PIC_RECONSTRUCTION_1).fill(dirtyPelVal);
cs->getMotionBuf(wholePictureArea, PIC_RECONSTRUCTION_0).fill(0);
cs->getMotionBuf(wholePictureArea, PIC_RECONSTRUCTION_1).fill(0);
#if JVET_W0123_TIMD_FUSION
cs->getIpmBuf(wholePictureArea, PIC_RECONSTRUCTION_0).fill(0);
cs->getIpmBuf(wholePictureArea, PIC_RECONSTRUCTION_1).fill(0);
#endif
}
void Picture::copyCleanCurPicture()
{
if (!cs->isGdrEnabled())
{
return;
}
{
ChromaFormat chromaFormat = cs->sps->getChromaFormatIdc();
int gdrEndX = cs->picHeader->getGdrEndX();
int gdrEndY = cs->pps->getPicHeightInLumaSamples();
UnitArea cleanArea = UnitArea(chromaFormat, Area(Position(0, 0), Size(gdrEndX, gdrEndY)));
PelUnitBuf picBuf0 = getBuf(cleanArea, PIC_RECONSTRUCTION_0);
PelUnitBuf picBuf1 = getBuf(cleanArea, PIC_RECONSTRUCTION_1);
picBuf1.copyFrom(picBuf0);
}
}
#endif
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
#if JVET_AG0145_ADAPTIVE_CLIPPING
void Picture::calcLumaClpParams()
{
int pelMax = getLumaClpRng().max;
int pelMin = getLumaClpRng().min;
#if JVET_AI0096_ADAPTIVE_CLIPPING_BIT_DEPTH_FIX
int targetMin = 16 * (1 << (cs->sps->getBitDepth(toChannelType(COMPONENT_Y)) - 8));
int targetMax = 235 * (1 << (cs->sps->getBitDepth(toChannelType(COMPONENT_Y)) - 8));
#else
int targetMin = 64, targetMax = 940;
#endif
if (cs->slice->getSliceType() != I_SLICE)
{
const Picture *const pColPic = cs->slice->getRefPic(RefPicList(1 - cs->slice->getColFromL0Flag()), cs->slice->getColRefIdx())->unscaledPic;
ClpRng colLumaClpRng = pColPic->getLumaClpRng();
targetMin = colLumaClpRng.min;
targetMax = colLumaClpRng.max;
}
int clipDeltaShift = 0;
if (cs->slice->getSliceType() != I_SLICE && cs->slice->getCheckLDC())
{
clipDeltaShift = ADAPTIVE_CLIP_SHIFT_DELTA_VALUE_1;
cs->slice->setAdaptiveClipQuant(true);
}
else
{
clipDeltaShift = ADAPTIVE_CLIP_SHIFT_DELTA_VALUE_0;
cs->slice->setAdaptiveClipQuant(false);
}
#if JVET_AJ0237_INTERNAL_12BIT
clipDeltaShift += std::max(0, cs->sps->getBitDepth(toChannelType(COMPONENT_Y)) - 10);
#endif
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
int pelMaxOF = 0;
int pelMinOF = (1 << cs->sps->getBitDepth(toChannelType(COMPONENT_Y))) - 1;
const int orgPelMin = pelMin;
{
int deltaMinToSignal = (pelMin - targetMin);
if (deltaMinToSignal < 0)
{
int absDelta = ((targetMin - pelMin) >> clipDeltaShift) << clipDeltaShift;
pelMin = targetMin - absDelta;
while (pelMin > orgPelMin)
{
pelMin -= (1 << clipDeltaShift);
}
while (pelMin < 0)
{
pelMinOF = pelMin;
pelMin = 0;
}
CHECK(pelMin < 0, "this is not possible");
}
else if (deltaMinToSignal > 0)
{
int absDelta = (deltaMinToSignal >> clipDeltaShift) << clipDeltaShift;
pelMin = targetMin + absDelta;
CHECK(pelMin > orgPelMin, "this is not possible");
CHECK(pelMin < 0, "this is not possible");
}
else
{
CHECK(pelMin != targetMin, "this is not possible");
}
}
const int orgPelMax = pelMax;
{
int deltaMaxToSignal = (pelMax - targetMax);
if (deltaMaxToSignal < 0)
{
int absDelta = ((targetMax - pelMax) >> clipDeltaShift) << clipDeltaShift;
pelMax = targetMax - absDelta;
CHECK(pelMax < orgPelMax, "this is not possible");
CHECK(pelMax > (1 << cs->sps->getBitDepth(toChannelType(COMPONENT_Y))) - 1, "this is not possible");
}
else if (deltaMaxToSignal > 0)
{
int absDelta = (deltaMaxToSignal >> clipDeltaShift) << clipDeltaShift;
pelMax = targetMax + absDelta;
while (pelMax < orgPelMax)
{
pelMax += (1 << clipDeltaShift);
}
while (pelMax >= (1 << cs->sps->getBitDepth(toChannelType(COMPONENT_Y))))
{
pelMaxOF = pelMax;
pelMax = (1 << cs->sps->getBitDepth(toChannelType(COMPONENT_Y))) - 1;
}
CHECK(pelMax > (1 << cs->sps->getBitDepth(toChannelType(COMPONENT_Y))) - 1, "this is not possible");
}
else
{
CHECK(pelMax != targetMax, "this is not possible");
}
}
cs->slice->setLumaPelMax(pelMax);
cs->slice->setLumaPelMin(pelMin);
lumaClpRng.min = pelMin;
lumaClpRng.max = pelMax;
lumaClpRngforQuant.min = std::min(pelMin, pelMinOF);
lumaClpRngforQuant.max = std::max(pelMax, pelMaxOF);
}
#endif