MCPcopy Create free account
hub / github.com/beefytech/Beef / ChamferedDistanceTransform

Function ChamferedDistanceTransform

BeefySysLib/img/ImgEffects.cpp:601–655  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

599}
600
601static void ChamferedDistanceTransform(uint32* out, int width, int height)
602{
603 AutoPerf gPerf("ImgEffects - ChamferedDistanceTransform");
604
605 if ((width < 4) || (height < 4))
606 {
607 ChamferedDistanceTransformSlow(out, width, height, 0, 0, width, height);
608 return;
609 }
610
611 // Do 2 pixel border (where we have to clamp)
612 ChamferedDistanceTransformSlow(out, width, height, 0, 0, width, 2);
613 ChamferedDistanceTransformSlow(out, width, height, 0, height-2, width, 2);
614 ChamferedDistanceTransformSlow(out, width, height, 0, 2, 2, height - 2);
615 ChamferedDistanceTransformSlow(out, width, height, width - 2, 2, 2, height - 2);
616
617 // Do inner region (no clamping)
618 int kernelCountFwd = sizeof(gKernelValsFwd) / sizeof(int);
619 int kernelCountRev = sizeof(gKernelValsRev) / sizeof(int);
620
621 int aStartX = 2;
622 int aStartY = 2;
623 int aEndX = width - 2;
624 int aEndY = height - 2;
625
626 for (int y = aStartY; y < aEndY; y++)
627 {
628 for (int x = aStartX; x < aEndX; x++)
629 {
630 for (int kernIdx = 0; kernIdx < kernelCountFwd; kernIdx++)
631 {
632 int cx = x + gKernelOfsFwd[kernIdx][0];
633 int cy = y + gKernelOfsFwd[kernIdx][1];
634 int aVal = out[cx+cy*width] + gKernelValsFwd[kernIdx];
635 if (aVal < (int) out[x+y*width])
636 out[x+y*width] = aVal;
637 }
638 }
639 }
640
641 for (int y = aEndY - 1; y >= aStartY; y--)
642 {
643 for (int x = aEndX - 1; x >= aStartX; x--)
644 {
645 for (int kernIdx = 0; kernIdx < kernelCountRev; kernIdx++)
646 {
647 int cx = x + gKernelOfsRev[kernIdx][0];
648 int cy = y + gKernelOfsRev[kernIdx][1];
649 int aVal = out[cx+cy*width] + gKernelValsRev[kernIdx];
650 if (aVal < (int) out[x+y*width])
651 out[x+y*width] = aVal;
652 }
653 }
654 }
655}
656
657#define IN_PIXEL(xval,yval) in[(xval) + (yval)*width]
658#define IN_PIXEL_YX(yval,xval) in[(xval) + (yval)*width]

Callers 2

ApplyMethod · 0.85
ChokedPixelTransformFunction · 0.85

Calls 1

Tested by

no test coverage detected