|
| 1 | +// Copyright (c) Six Labors. |
| 2 | +// Licensed under the Six Labors Split License. |
| 3 | + |
| 4 | +using SixLabors.ImageSharp.Processing.Processors.Convolution; |
| 5 | + |
| 6 | +namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution; |
| 7 | + |
| 8 | +[Trait("Category", "Processors")] |
| 9 | +[GroupOutput("Convolution")] |
| 10 | +public class KernelSamplingMapTests |
| 11 | +{ |
| 12 | + public static readonly TheoryData<BorderWrappingMode, int, int> BoundsSmallerThanKernel = new() |
| 13 | + { |
| 14 | + { BorderWrappingMode.Repeat, 8, 5 }, |
| 15 | + { BorderWrappingMode.Mirror, 8, 5 }, |
| 16 | + { BorderWrappingMode.Bounce, 8, 5 }, |
| 17 | + { BorderWrappingMode.Wrap, 8, 5 }, |
| 18 | + { BorderWrappingMode.Repeat, 1, 1 }, |
| 19 | + { BorderWrappingMode.Mirror, 1, 1 }, |
| 20 | + { BorderWrappingMode.Bounce, 1, 1 }, |
| 21 | + { BorderWrappingMode.Wrap, 1, 1 }, |
| 22 | + { BorderWrappingMode.Repeat, 30, 30 }, |
| 23 | + { BorderWrappingMode.Mirror, 30, 30 }, |
| 24 | + { BorderWrappingMode.Bounce, 30, 30 }, |
| 25 | + { BorderWrappingMode.Wrap, 30, 30 }, |
| 26 | + }; |
| 27 | + |
| 28 | + [Theory] |
| 29 | + [MemberData(nameof(BoundsSmallerThanKernel))] |
| 30 | + public void BuildSamplingOffsetMap_BoundsSmallerThanKernelRadius_OffsetsStayInBounds(BorderWrappingMode mode, int width, int height) |
| 31 | + { |
| 32 | + // A 61-tap kernel has radius 30, so these bounds are covered entirely by the border |
| 33 | + // regions and offsets can overshoot the bounds by more than one sampling extent. |
| 34 | + const int kernelSize = 61; |
| 35 | + Rectangle bounds = new(100, 200, width, height); |
| 36 | + |
| 37 | + using KernelSamplingMap map = new(Configuration.Default.MemoryAllocator); |
| 38 | + map.BuildSamplingOffsetMap(kernelSize, kernelSize, bounds, mode, mode); |
| 39 | + |
| 40 | + foreach (int x in map.GetColumnOffsetSpan()) |
| 41 | + { |
| 42 | + Assert.InRange(x, bounds.Left, bounds.Right - 1); |
| 43 | + } |
| 44 | + |
| 45 | + foreach (int y in map.GetRowOffsetSpan()) |
| 46 | + { |
| 47 | + Assert.InRange(y, bounds.Top, bounds.Bottom - 1); |
| 48 | + } |
| 49 | + } |
| 50 | +} |
0 commit comments