Skip to content

Commit

Permalink
No longer throw an argument exception for a negative bias value in Ad…
Browse files Browse the repository at this point in the history
…aptiveThreshold (#1717)
  • Loading branch information
dlemstra committed Sep 19, 2024
1 parent 51320b7 commit 32996b4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
6 changes: 1 addition & 5 deletions src/Magick.NET/MagickImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1030,11 +1030,7 @@ public void AdaptiveThreshold(uint width, uint height, double bias)
/// <param name="channels">The channel(s) that should be thresholded.</param>
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
public void AdaptiveThreshold(uint width, uint height, double bias, Channels channels)
{
Throw.IfNegative(nameof(bias), bias);

_nativeInstance.AdaptiveThreshold(width, height, bias, channels);
}
=> _nativeInstance.AdaptiveThreshold(width, height, bias, channels);

/// <summary>
/// Local adaptive threshold image.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,29 @@ public partial class MagickImageTests
{
public class TheAdaptiveThresholdMethod
{
#if !Q16HDRI
[Fact]
public void ShouldThrowExceptionWhenBiasIsNegative()
public void ShouldThrowExceptionWhenBiasPercentagetIsNegative()
{
using var image = new MagickImage(Files.MagickNETIconPNG);
Assert.Throws<ArgumentException>("bias", () => image.AdaptiveThreshold(10, 10, -1, Channels.Red));
Assert.Throws<ArgumentException>("biasPercentage", () => image.AdaptiveThreshold(10, 10, new Percentage(-1), Channels.Red));
}

#if !Q16HDRI
#else
[Fact]
public void ShouldThrowExceptionWhenBiasPercentagetIsNegative()
public void ShouldNotThrowExceptionWhenBiasPercentagetIsNegative()
{
using var image = new MagickImage(Files.MagickNETIconPNG);
Assert.Throws<ArgumentException>("biasPercentage", () => image.AdaptiveThreshold(10, 10, new Percentage(-1), Channels.Red));
image.AdaptiveThreshold(10, 10, new Percentage(-1), Channels.Red);
}
#endif

[Fact]
public void ShouldAllowNegativeBiasValue()
{
using var image = new MagickImage(Files.MagickNETIconPNG);
image.AdaptiveThreshold(10, 10, -1, Channels.Red);
}

[Fact]
public void ShouldThresholdTheImage()
{
Expand Down

0 comments on commit 32996b4

Please sign in to comment.