Skip to content

Commit 26105ad

Browse files
authored
Fix for unbiased integer
division error
1 parent d8bdff7 commit 26105ad

3 files changed

Lines changed: 18 additions & 9 deletions

File tree

Sources/MDegrainN.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,8 +1948,10 @@ void MDegrainN::use_block_uv(
19481948
if (usable_flag)
19491949
{
19501950
const FakeBlockData &block = c_info._clip_sptr->GetBlock(0, i);
1951-
const int blx = block.GetX() * nPel + block.GetMV().x;
1952-
const int bly = block.GetY() * nPel + block.GetMV().y;
1951+
int blx = block.GetX() * nPel + block.GetMV().x;
1952+
int bly = block.GetY() * nPel + block.GetMV().y;
1953+
if (nLogxRatioUV_super == 1) blx++; // add bias for integer division for 4:2:x formats
1954+
if (nLogyRatioUV_super == 1) bly++; // add bias for integer division for 4:2:x formats
19531955
p = plane_ptr->GetPointer(blx >> nLogxRatioUV_super, bly >> nLogyRatioUV_super);
19541956
np = plane_ptr->GetPitch();
19551957
const sad_t block_sad = block.GetSAD(); // SAD of MV Block. Scaled to MVClip's bits_per_pixel;

Sources/MVDegrain3.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1544,7 +1544,9 @@ MV_FORCEINLINE void MVDegrainX::use_block_uv(const BYTE * &p, int &np, int &WRef
15441544
{
15451545
const FakeBlockData &block = mvclip.GetBlock(0, i);
15461546
int blx = block.GetX() * nPel + block.GetMV().x;
1547-
int bly = block.GetY() * nPel + block.GetMV().y;
1547+
int bly = block.GetY() * nPel + block.GetMV().y;
1548+
if (nLogxRatioUV_super == 1) blx++; // add bias for integer division for 4:2:x formats
1549+
if (nLogyRatioUV_super == 1) bly++; // add bias for integer division for 4:2:x formats
15481550
p = pPlane->GetPointer(blx >> nLogxRatioUV_super, bly >> nLogyRatioUV_super); // pixelsize - aware
15491551
np = pPlane->GetPitch();
15501552
sad_t blockSAD = block.GetSAD(); // SAD of MV Block. Scaled to MVClip's bits_per_pixel;

Sources/PlaneOfBlocks.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -409,18 +409,23 @@ class PlaneOfBlocks
409409

410410
MV_FORCEINLINE const uint8_t* GetRefBlockU(WorkingArea& workarea, int nVx, int nVy)
411411
{
412+
int nVx1 = (nLogxRatioUV == 1) ? nVx + 1 : nVx;
413+
int nVy1 = (nLogxRatioUV == 1) ? nVy + 1 : nVy;
412414
return
413-
(nPel == 2) ? pRefFrame->GetPlane(UPLANE)->GetAbsolutePointerPel <1>((workarea.x[1] << 1) + (nVx >> nLogxRatioUV), (workarea.y[1] << 1) + (nVy >> nLogyRatioUV)) :
414-
(nPel == 1) ? pRefFrame->GetPlane(UPLANE)->GetAbsolutePointerPel <0>((workarea.x[1]) + (nVx >> nLogxRatioUV), (workarea.y[1]) + (nVy >> nLogyRatioUV)) :
415-
pRefFrame->GetPlane(UPLANE)->GetAbsolutePointerPel <2>((workarea.x[1] << 2) + (nVx >> nLogxRatioUV), (workarea.y[1] << 2) + (nVy >> nLogyRatioUV));
415+
(nPel == 2) ? pRefFrame->GetPlane(UPLANE)->GetAbsolutePointerPel <1>((workarea.x[1] << 1) + (nVx1 >> nLogxRatioUV), (workarea.y[1] << 1) + (nVy1 >> nLogyRatioUV)) :
416+
(nPel == 1) ? pRefFrame->GetPlane(UPLANE)->GetAbsolutePointerPel <0>((workarea.x[1]) + (nVx1 >> nLogxRatioUV), (workarea.y[1]) + (nVy1 >> nLogyRatioUV)) :
417+
pRefFrame->GetPlane(UPLANE)->GetAbsolutePointerPel <2>((workarea.x[1] << 2) + (nVx1 >> nLogxRatioUV), (workarea.y[1] << 2) + (nVy1 >> nLogyRatioUV));
418+
416419
}
417420

418421
MV_FORCEINLINE const uint8_t* GetRefBlockV(WorkingArea& workarea, int nVx, int nVy)
419422
{
423+
int nVx1 = (nLogxRatioUV == 1) ? nVx + 1 : nVx;
424+
int nVy1 = (nLogxRatioUV == 1) ? nVy + 1 : nVy;
420425
return
421-
(nPel == 2) ? pRefFrame->GetPlane(VPLANE)->GetAbsolutePointerPel <1>((workarea.x[2] << 1) + (nVx >> nLogxRatioUV), (workarea.y[2] << 1) + (nVy >> nLogyRatioUV)) :
422-
(nPel == 1) ? pRefFrame->GetPlane(VPLANE)->GetAbsolutePointerPel <0>((workarea.x[2]) + (nVx >> nLogxRatioUV), (workarea.y[2]) + (nVy >> nLogyRatioUV)) :
423-
pRefFrame->GetPlane(VPLANE)->GetAbsolutePointerPel <2>((workarea.x[2] << 2) + (nVx >> nLogxRatioUV), (workarea.y[2] << 2) + (nVy >> nLogyRatioUV));
426+
(nPel == 2) ? pRefFrame->GetPlane(VPLANE)->GetAbsolutePointerPel <1>((workarea.x[2] << 1) + (nVx1 >> nLogxRatioUV), (workarea.y[2] << 1) + (nVy1 >> nLogyRatioUV)) :
427+
(nPel == 1) ? pRefFrame->GetPlane(VPLANE)->GetAbsolutePointerPel <0>((workarea.x[2]) + (nVx1 >> nLogxRatioUV), (workarea.y[2]) + (nVy1 >> nLogyRatioUV)) :
428+
pRefFrame->GetPlane(VPLANE)->GetAbsolutePointerPel <2>((workarea.x[2] << 2) + (nVx1 >> nLogxRatioUV), (workarea.y[2] << 2) + (nVy1 >> nLogyRatioUV));
424429
}
425430

426431
MV_FORCEINLINE const uint8_t* GetSrcBlock(int nX, int nY)

0 commit comments

Comments
 (0)