Skip to content

Commit 9b9e134

Browse files
authored
Merge pull request #1332 from SixLabors/sp/bokeh-blur-init-tweaks
Bokeh blur constructor tweaks (input validation, tiny speedup)
2 parents 801961d + 38311ed commit 9b9e134

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ public sealed class BokehBlurProcessor : IImageProcessor
2929
/// Initializes a new instance of the <see cref="BokehBlurProcessor"/> class.
3030
/// </summary>
3131
public BokehBlurProcessor()
32-
: this(DefaultRadius, DefaultComponents, DefaultGamma)
3332
{
33+
this.Radius = DefaultRadius;
34+
this.Components = DefaultComponents;
35+
this.Gamma = DefaultGamma;
3436
}
3537

3638
/// <summary>
@@ -47,6 +49,8 @@ public BokehBlurProcessor()
4749
/// </param>
4850
public BokehBlurProcessor(int radius, int components, float gamma)
4951
{
52+
Guard.MustBeGreaterThan(radius, 0, nameof(radius));
53+
Guard.MustBeBetweenOrEqualTo(components, 1, 6, nameof(components));
5054
Guard.MustBeGreaterThanOrEqualTo(gamma, 1, nameof(gamma));
5155

5256
this.Radius = radius;

tests/ImageSharp.Tests/Processing/Processors/Convolution/BokehBlurTest.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ [[ 0.00451261+0.0165137j 0.02161237-0.00299122j 0.00387479-0.02682816j
3535
0.02565295+0.01611732j 0.0153483+0.01605112j 0.00698622+0.01370844j
3636
0.00135338+0.00998296j -0.00152245+0.00604545j -0.00227282+0.002851j ]]";
3737

38+
[Theory]
39+
[InlineData(-10, 2, 3f)]
40+
[InlineData(-1, 2, 3f)]
41+
[InlineData(0, 2, 3f)]
42+
[InlineData(20, -1, 3f)]
43+
[InlineData(20, -0, 3f)]
44+
[InlineData(20, 4, -10f)]
45+
[InlineData(20, 4, 0f)]
46+
public void VerifyBokehBlurProcessorArguments_Fail(int radius, int components, float gamma)
47+
{
48+
Assert.Throws<ArgumentOutOfRangeException>(() => new BokehBlurProcessor(radius, components, gamma));
49+
}
50+
3851
[Fact]
3952
public void VerifyComplexComponents()
4053
{

0 commit comments

Comments
 (0)