Merge pull request #3152 from SixLabors/js/fix-convolution-small-bounds · SixLabors/ImageSharp@5a0a74f · GitHub
Skip to content

Commit 5a0a74f

Browse files
Merge pull request #3152 from SixLabors/js/fix-convolution-small-bounds
Fix convolution sampling for bounds smaller than the kernel radius
2 parents ed6c2dd + 0b685ab commit 5a0a74f

3 files changed

Lines changed: 143 additions & 1 deletion

File tree

‎src/ImageSharp/Processing/Processors/Convolution/KernelSamplingMap.cs‎

Lines changed: 63 additions & 1 deletion

‎tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
33

4+
using SixLabors.ImageSharp.PixelFormats;
45
using SixLabors.ImageSharp.Processing;
6+
using SixLabors.ImageSharp.Processing.Processors.Convolution;
57

68
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution;
79

@@ -13,4 +15,32 @@ public class GaussianBlurTest : Basic1ParameterConvolutionTests
1315

1416
protected override void Apply(IImageProcessingContext ctx, int value, Rectangle bounds) =>
1517
ctx.GaussianBlur(bounds, value);
18+
19+
[Theory]
20+
[InlineData(BorderWrappingMode.Repeat)]
21+
[InlineData(BorderWrappingMode.Mirror)]
22+
[InlineData(BorderWrappingMode.Bounce)]
23+
[InlineData(BorderWrappingMode.Wrap)]
24+
public void OnImageSmallerThanKernelRadius_LeavesSolidColorUnchanged(BorderWrappingMode mode)
25+
{
26+
// 8 rows against sigma 10 (61-tap kernel, radius 30). A normalized blur of a solid
27+
// image must remain that color no matter how the border sampling folds.
28+
Rgba32 red = new(255, 0, 0);
29+
using Image<Rgba32> image = new(130, 8, red);
30+
image.Mutate(x => x.GaussianBlur(image.Bounds, 10F, mode, mode));
31+
32+
image.ProcessPixelRows(accessor =>
33+
{
34+
for (int y = 0; y < accessor.Height; y++)
35+
{
36+
foreach (Rgba32 pixel in accessor.GetRowSpan(y))
37+
{
38+
Assert.InRange(pixel.R, 254, 255);
39+
Assert.InRange(pixel.G, 0, 1);
40+
Assert.InRange(pixel.B, 0, 1);
41+
Assert.Equal(255, pixel.A);
42+
}
43+
}
44+
});
45+
}
1646
}
Lines changed: 50 additions & 0 deletions

0 commit comments

Comments
 (0)