From f69e514e2b8f23f756097b30f87919c1147aa66f Mon Sep 17 00:00:00 2001 From: Pepijn Peeters Date: Mon, 5 Feb 2024 15:52:48 +0100 Subject: [PATCH] Correct channel detection in MagickImage.blur --- src/magick-image.ts | 12 +++++++----- tests/magick-image/blur.spec.ts | 13 +++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/magick-image.ts b/src/magick-image.ts index 01bfd42..e69f65c 100644 --- a/src/magick-image.ts +++ b/src/magick-image.ts @@ -1935,15 +1935,17 @@ export class MagickImage extends NativeInstance implements IMagickImage { blur(channels: Channels): void; blur(radius: number, sigma: number): void; blur(radius: number, sigma: number, channels: Channels): void; - blur(radiusOrChannel?: number | Channels, sigmaOrUndefined?: number, channelsOrUndefined?: Channels): void { + blur(radiusOrChannels?: number | Channels, sigmaOrUndefined?: number, channelsOrUndefined?: Channels): void { let radius = 0; const sigma = this.valueOrDefault(sigmaOrUndefined, 1); let channels = this.valueOrDefault(channelsOrUndefined, Channels.Undefined); - if (typeof radiusOrChannel === 'number') - radius = radiusOrChannel; - else if (radiusOrChannel !== undefined) - channels = radiusOrChannel; + if (radiusOrChannels !== undefined) { + if (sigmaOrUndefined === undefined) + channels = radiusOrChannels; + else + radius = radiusOrChannels; + } this.useException(exception => { const instance = ImageMagick._api._MagickImage_Blur(this._instance, radius, sigma, channels, exception.ptr); diff --git a/tests/magick-image/blur.spec.ts b/tests/magick-image/blur.spec.ts index 2670634..c0ac8b0 100644 --- a/tests/magick-image/blur.spec.ts +++ b/tests/magick-image/blur.spec.ts @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. import { Channels } from '@src/enums/channels'; +import { ErrorMetric } from '@src/enums/error-metric'; import { TestImages } from '@test/test-images'; describe('MagickImage#blur', () => { @@ -12,6 +13,18 @@ describe('MagickImage#blur', () => { }); }); + it('should not confuse channels for radius', () => { + TestImages.Builtin.logo.use(imageA => { + imageA.clone(imageB => { + imageA.blur(Channels.Blue); + imageB.blur(4, 1); + + const difference = imageB.compare(imageA, ErrorMetric.RootMeanSquared); + expect(difference).not.toBe(0); + }) + }); + }); + it('should only blur the specified channel', () => { TestImages.Builtin.logo.use(image => { image.blur(5, 5, Channels.Green);