Skip to content

Commit fa9eb74

Browse files
authored
Fixed bug in PlanesOfBlocks.h and
added fix for subsampled chroma shift in MCompensate (for QTGMC and other MC denoise scripts).
1 parent 26105ad commit fa9eb74

2 files changed

Lines changed: 63 additions & 33 deletions

File tree

Sources/MVCompensate.cpp

Lines changed: 61 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -678,12 +678,14 @@ void MVCompensate::compensate_slice_normal(Slicer::TaskData &td)
678678
BLITLUMA(
679679
pDstCur[0] + xx, nDstPitches[0],
680680
pPlanes[0]->GetPointer(blx, bly), pPlanes[0]->GetPitch()
681-
);
681+
);
682682
for (int i = 1; i < planecount; i++) {
683683
if (pPlanes[i])
684-
{
684+
{
685+
int blx_uv = (nLogxRatioUVs[i] == 1) ? blx + 1 : blx; // add bias for integer division for 4:2:x formats
686+
int bly_uv = (nLogyRatioUVs[i] == 1) ? bly + 1 : bly; // add bias for integer division for 4:2:x formats
685687
BLITCHROMA(pDstCur[i] + (xx >> nLogxRatioUVs[i]), nDstPitches[i],
686-
pPlanes[i]->GetPointer(blx >> nLogxRatioUVs[i], bly >> nLogyRatioUVs[i]), pPlanes[i]->GetPitch()
688+
pPlanes[i]->GetPointer(blx_uv >> nLogxRatioUVs[i], bly_uv >> nLogyRatioUVs[i]), pPlanes[i]->GetPitch()
687689
);
688690
}
689691
}
@@ -698,11 +700,15 @@ void MVCompensate::compensate_slice_normal(Slicer::TaskData &td)
698700
pSrcPlanes[0]->GetPointer(blxsrc, blysrc), pSrcPlanes[0]->GetPitch()
699701
);
700702
for (int i = 1; i < planecount; i++) {
701-
if (pSrcPlanes[i])
703+
if (pSrcPlanes[i])
704+
{
705+
int blxsrc_uv = (nLogxRatioUVs[i] == 1) ? blxsrc + 1 : blxsrc; // add bias for integer division for 4:2:x formats
706+
int blysrc_uv = (nLogyRatioUVs[i] == 1) ? blysrc + 1 : blysrc; // add bias for integer division for 4:2:x formats
702707
BLITCHROMA(
703708
pDstCur[i] + (xx >> nLogxRatioUVs[i]), nDstPitches[i],
704-
pSrcPlanes[i]->GetPointer(blxsrc >> nLogxRatioUVs[i], blysrc >> nLogyRatioUVs[i]), pSrcPlanes[i]->GetPitch()
705-
);
709+
pSrcPlanes[i]->GetPointer(blxsrc_uv >> nLogxRatioUVs[i], blysrc_uv >> nLogyRatioUVs[i]), pSrcPlanes[i]->GetPitch()
710+
);
711+
}
706712
}
707713
}
708714

@@ -831,12 +837,16 @@ void MVCompensate::compensate_slice_overlap(int y_beg, int y_end)
831837
winOver, nBlkSizeX
832838
);
833839
for (int i = 1; i < planecount; i++) {
834-
if (pPlanes[i])
840+
if (pPlanes[i])
841+
{
842+
int blx_uv = (nLogxRatioUVs[i] == 1) ? blx + 1 : blx; // add bias for integer division for 4:2:x formats
843+
int bly_uv = (nLogyRatioUVs[i] == 1) ? bly + 1 : bly; // add bias for integer division for 4:2:x formats
835844
OVERSCHROMA(
836-
(uint16_t *)(pDstShorts[i] + (xx >> nLogxRatioUVs[i])), dstShortPitches[i],
837-
pPlanes[i]->GetPointer(blx >> nLogxRatioUVs[i], bly >> nLogyRatioUVs[i]), pPlanes[i]->GetPitch(),
845+
(uint16_t*)(pDstShorts[i] + (xx >> nLogxRatioUVs[i])), dstShortPitches[i],
846+
pPlanes[i]->GetPointer(blx_uv >> nLogxRatioUVs[i], bly_uv >> nLogyRatioUVs[i]), pPlanes[i]->GetPitch(),
838847
winOverUV, nBlkSizeX >> nLogxRatioUVs[i]
839-
);
848+
);
849+
}
840850
}
841851
}
842852
else if (pixelsize_super == 2) {
@@ -848,12 +858,16 @@ void MVCompensate::compensate_slice_overlap(int y_beg, int y_end)
848858
);
849859
// chroma uv
850860
for (int i = 1; i < planecount; i++) {
851-
if (pPlanes[i])
861+
if (pPlanes[i])
862+
{
863+
int blx_uv = (nLogxRatioUVs[i] == 1) ? blx + 1 : blx; // add bias for integer division for 4:2:x formats
864+
int bly_uv = (nLogyRatioUVs[i] == 1) ? bly + 1 : bly; // add bias for integer division for 4:2:x formats
852865
OVERSCHROMA16(
853-
(uint16_t *)(pDstShorts[i] + (xx >> nLogxRatioUVs[i])), dstShortPitches[i],
854-
pPlanes[i]->GetPointer(blx >> nLogxRatioUVs[i], bly >> nLogyRatioUVs[i]), pPlanes[i]->GetPitch(),
866+
(uint16_t*)(pDstShorts[i] + (xx >> nLogxRatioUVs[i])), dstShortPitches[i],
867+
pPlanes[i]->GetPointer(blx_uv >> nLogxRatioUVs[i], bly_uv >> nLogyRatioUVs[i]), pPlanes[i]->GetPitch(),
855868
winOverUV, nBlkSizeX >> nLogxRatioUVs[i]
856-
);
869+
);
870+
}
857871
}
858872
}
859873
else { // pixelsize_super == 4
@@ -865,12 +879,16 @@ void MVCompensate::compensate_slice_overlap(int y_beg, int y_end)
865879
);
866880
// chroma uv
867881
for (int i = 1; i < planecount; i++) {
868-
if (pPlanes[i])
882+
if (pPlanes[i])
883+
{
884+
int blx_uv = (nLogxRatioUVs[i] == 1) ? blx + 1 : blx; // add bias for integer division for 4:2:x formats
885+
int bly_uv = (nLogyRatioUVs[i] == 1) ? bly + 1 : bly; // add bias for integer division for 4:2:x formats
869886
OVERSCHROMA32(
870-
(uint16_t *)(pDstShorts[i] + (xx >> nLogxRatioUVs[i])), dstShortPitches[i],
871-
pPlanes[i]->GetPointer(blx >> nLogxRatioUVs[i], bly >> nLogyRatioUVs[i]), pPlanes[i]->GetPitch(),
887+
(uint16_t*)(pDstShorts[i] + (xx >> nLogxRatioUVs[i])), dstShortPitches[i],
888+
pPlanes[i]->GetPointer(blx_uv >> nLogxRatioUVs[i], bly_uv >> nLogyRatioUVs[i]), pPlanes[i]->GetPitch(),
872889
winOverUV, nBlkSizeX >> nLogxRatioUVs[i]
873-
);
890+
);
891+
}
874892
}
875893
}
876894
}
@@ -889,12 +907,16 @@ void MVCompensate::compensate_slice_overlap(int y_beg, int y_end)
889907
);
890908
// chroma uv
891909
for (int i = 1; i < planecount; i++) {
892-
if (pSrcPlanes[i])
910+
if (pSrcPlanes[i])
911+
{
912+
int blxsrc_uv = (nLogxRatioUVs[i] == 1) ? blxsrc + 1 : blxsrc; // add bias for integer division for 4:2:x formats
913+
int blysrc_uv = (nLogyRatioUVs[i] == 1) ? blysrc + 1 : blysrc; // add bias for integer division for 4:2:x formats
893914
OVERSCHROMA(
894-
(uint16_t *)(pDstShorts[i] + (xx >> nLogxRatioUVs[i])), dstShortPitches[i],
895-
pSrcPlanes[i]->GetPointer(blxsrc >> nLogxRatioUVs[i], blysrc >> nLogyRatioUVs[i]), pSrcPlanes[i]->GetPitch(),
915+
(uint16_t*)(pDstShorts[i] + (xx >> nLogxRatioUVs[i])), dstShortPitches[i],
916+
pSrcPlanes[i]->GetPointer(blxsrc_uv >> nLogxRatioUVs[i], blysrc_uv >> nLogyRatioUVs[i]), pSrcPlanes[i]->GetPitch(),
896917
winOverUV, nBlkSizeX >> nLogxRatioUVs[i]
897-
);
918+
);
919+
}
898920
}
899921
}
900922
else if (pixelsize_super == 2){
@@ -906,12 +928,16 @@ void MVCompensate::compensate_slice_overlap(int y_beg, int y_end)
906928
);
907929
// chroma uv
908930
for (int i = 1; i < planecount; i++) {
909-
if (pSrcPlanes[i])
931+
if (pSrcPlanes[i])
932+
{
933+
int blxsrc_uv = (nLogxRatioUVs[i] == 1) ? blxsrc + 1 : blxsrc; // add bias for integer division for 4:2:x formats
934+
int blysrc_uv = (nLogyRatioUVs[i] == 1) ? blysrc + 1 : blysrc; // add bias for integer division for 4:2:x formats
910935
OVERSCHROMA16(
911-
(uint16_t *)(pDstShorts[i] + (xx >> nLogxRatioUVs[i])), dstShortPitches[i],
912-
pSrcPlanes[i]->GetPointer(blxsrc >> nLogxRatioUVs[i], blysrc >> nLogyRatioUVs[i]), pSrcPlanes[i]->GetPitch(),
936+
(uint16_t*)(pDstShorts[i] + (xx >> nLogxRatioUVs[i])), dstShortPitches[i],
937+
pSrcPlanes[i]->GetPointer(blxsrc_uv >> nLogxRatioUVs[i], blysrc_uv >> nLogyRatioUVs[i]), pSrcPlanes[i]->GetPitch(),
913938
winOverUV, nBlkSizeX >> nLogxRatioUVs[i]
914-
);
939+
);
940+
}
915941
}
916942
}
917943
else { // if (pixelsize_super == 4)
@@ -922,12 +948,16 @@ void MVCompensate::compensate_slice_overlap(int y_beg, int y_end)
922948
);
923949
// chroma uv
924950
for (int i = 1; i < planecount; i++) {
925-
if (pSrcPlanes[i])
951+
if (pSrcPlanes[i])
952+
{
953+
int blxsrc_uv = (nLogxRatioUVs[i] == 1) ? blxsrc + 1 : blxsrc; // add bias for integer division for 4:2:x formats
954+
int blysrc_uv = (nLogyRatioUVs[i] == 1) ? blysrc + 1 : blysrc; // add bias for integer division for 4:2:x formats
926955
OVERSCHROMA32(
927-
(uint16_t *)(pDstShorts[i] + (xx >> nLogxRatioUVs[i])), dstShortPitches[i],
928-
pSrcPlanes[i]->GetPointer(blxsrc >> nLogxRatioUVs[i], blysrc >> nLogyRatioUVs[i]), pSrcPlanes[i]->GetPitch(),
929-
winOverUV, nBlkSizeX >> nLogxRatioUVs[i]
930-
);
956+
(uint16_t*)(pDstShorts[i] + (xx >> nLogxRatioUVs[i])), dstShortPitches[i],
957+
pSrcPlanes[i]->GetPointer(blxsrc_uv >> nLogxRatioUVs[i], blysrc_uv >> nLogyRatioUVs[i]), pSrcPlanes[i]->GetPitch(),
958+
winOverUV, nBlkSizeX >> nLogxRatioUVs[i]
959+
);
960+
}
931961
}
932962
}
933963
}

Sources/PlaneOfBlocks.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ class PlaneOfBlocks
410410
MV_FORCEINLINE const uint8_t* GetRefBlockU(WorkingArea& workarea, int nVx, int nVy)
411411
{
412412
int nVx1 = (nLogxRatioUV == 1) ? nVx + 1 : nVx;
413-
int nVy1 = (nLogxRatioUV == 1) ? nVy + 1 : nVy;
413+
int nVy1 = (nLogyRatioUV == 1) ? nVy + 1 : nVy;
414414
return
415415
(nPel == 2) ? pRefFrame->GetPlane(UPLANE)->GetAbsolutePointerPel <1>((workarea.x[1] << 1) + (nVx1 >> nLogxRatioUV), (workarea.y[1] << 1) + (nVy1 >> nLogyRatioUV)) :
416416
(nPel == 1) ? pRefFrame->GetPlane(UPLANE)->GetAbsolutePointerPel <0>((workarea.x[1]) + (nVx1 >> nLogxRatioUV), (workarea.y[1]) + (nVy1 >> nLogyRatioUV)) :
@@ -421,7 +421,7 @@ class PlaneOfBlocks
421421
MV_FORCEINLINE const uint8_t* GetRefBlockV(WorkingArea& workarea, int nVx, int nVy)
422422
{
423423
int nVx1 = (nLogxRatioUV == 1) ? nVx + 1 : nVx;
424-
int nVy1 = (nLogxRatioUV == 1) ? nVy + 1 : nVy;
424+
int nVy1 = (nLogyRatioUV == 1) ? nVy + 1 : nVy;
425425
return
426426
(nPel == 2) ? pRefFrame->GetPlane(VPLANE)->GetAbsolutePointerPel <1>((workarea.x[2] << 1) + (nVx1 >> nLogxRatioUV), (workarea.y[2] << 1) + (nVy1 >> nLogyRatioUV)) :
427427
(nPel == 1) ? pRefFrame->GetPlane(VPLANE)->GetAbsolutePointerPel <0>((workarea.x[2]) + (nVx1 >> nLogxRatioUV), (workarea.y[2]) + (nVy1 >> nLogyRatioUV)) :

0 commit comments

Comments
 (0)