diff --git a/src/Magick.NET.Core/IMagickImage.cs b/src/Magick.NET.Core/IMagickImage.cs
index 1038219362..a09be9362b 100644
--- a/src/Magick.NET.Core/IMagickImage.cs
+++ b/src/Magick.NET.Core/IMagickImage.cs
@@ -559,7 +559,8 @@ Interlace Interlace
/// Applies a non-linear, edge-preserving, and noise-reducing smoothing filter.
///
/// The width of the neighborhood in pixels.
- /// The height of the neighborhood in pixels.\
+ /// The height of the neighborhood in pixels.
+ /// Thrown when an error is raised by ImageMagick.
void BilateralBlur(int width, int height);
///
@@ -569,6 +570,7 @@ Interlace Interlace
/// The height of the neighborhood in pixels.
/// The sigma in the intensity space.
/// The sigma in the coordinate space.
+ /// Thrown when an error is raised by ImageMagick.
void BilateralBlur(int width, int height, double intensitySigma, double spatialSigma);
///
diff --git a/src/Magick.NET/MagickImage.cs b/src/Magick.NET/MagickImage.cs
index 8d00101a86..7d81463bdb 100644
--- a/src/Magick.NET/MagickImage.cs
+++ b/src/Magick.NET/MagickImage.cs
@@ -1314,8 +1314,12 @@ public void AutoThreshold(AutoThresholdMethod method)
///
/// The width of the neighborhood in pixels.
/// The height of the neighborhood in pixels.
+ /// Thrown when an error is raised by ImageMagick.
public void BilateralBlur(int width, int height)
{
+ Throw.IfNegative(nameof(width), width);
+ Throw.IfNegative(nameof(height), height);
+
var intensitySigma = Math.Sqrt((width * width) + (height * height));
BilateralBlur(width, height, intensitySigma, intensitySigma * 0.25);
}
@@ -1327,8 +1331,14 @@ public void BilateralBlur(int width, int height)
/// The height of the neighborhood in pixels.
/// The sigma in the intensity space.
/// The sigma in the coordinate space.
+ /// Thrown when an error is raised by ImageMagick.
public void BilateralBlur(int width, int height, double intensitySigma, double spatialSigma)
- => _nativeInstance.BilateralBlur(width, height, intensitySigma, spatialSigma);
+ {
+ Throw.IfNegative(nameof(width), width);
+ Throw.IfNegative(nameof(height), height);
+
+ _nativeInstance.BilateralBlur(width, height, intensitySigma, spatialSigma);
+ }
///
/// Forces all pixels below the threshold into black while leaving all pixels at or above
diff --git a/tests/Magick.NET.Tests/MagickImageTests/TheBilateralBlurMethod.cs b/tests/Magick.NET.Tests/MagickImageTests/TheBilateralBlurMethod.cs
index b1a257c258..15d278687f 100644
--- a/tests/Magick.NET.Tests/MagickImageTests/TheBilateralBlurMethod.cs
+++ b/tests/Magick.NET.Tests/MagickImageTests/TheBilateralBlurMethod.cs
@@ -1,6 +1,7 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
// Licensed under the Apache License, Version 2.0.
+using System;
using ImageMagick;
using Xunit;
@@ -10,6 +11,34 @@ public partial class MagickImageTests
{
public class TheBilateralBlurMethod
{
+ [Fact]
+ public void ShouldThrowExceptionWhenWidthIsNegative()
+ {
+ using var image = new MagickImage(Files.NoisePNG);
+ Assert.Throws("width", () => image.BilateralBlur(-1, 2));
+ }
+
+ [Fact]
+ public void ShouldThrowExceptionWhenWidthIsNegativeThanOneWithLowAndHigh()
+ {
+ using var image = new MagickImage(Files.NoisePNG);
+ Assert.Throws("width", () => image.BilateralBlur(-1, 2, 0.1, 0.1));
+ }
+
+ [Fact]
+ public void ShouldThrowExceptionWhenHeightIsNegative()
+ {
+ using var image = new MagickImage(Files.NoisePNG);
+ Assert.Throws("height", () => image.BilateralBlur(2, -1));
+ }
+
+ [Fact]
+ public void ShouldThrowExceptionWhenHeightIsNegativeWithLowAndHigh()
+ {
+ using var image = new MagickImage(Files.NoisePNG);
+ Assert.Throws("height", () => image.BilateralBlur(2, -1, 0.1, 0.1));
+ }
+
[Fact]
public void ShouldApplyTheFilter()
{