Skip to content

Commit

Permalink
Added adaptiveBlur to MagickImage.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemstra committed Mar 15, 2024
1 parent da54d8e commit 8263de8
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/magick-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,24 @@ export interface IMagickImage extends IDisposable {
*/
width: number;

/**
* Adaptive-blur image with the default blur factor (0x1).
*/
adaptiveBlur(): void;

/**
* Adaptive-blur image with the default blur factor (0x1).
* @param radius - The radius of the Gaussian, in pixels, not counting the center pixel.
*/
adaptiveBlur(radius: number): void;

/**
* Adaptive-blur image with specified blur factor.
* @param radius - The radius of the Gaussian, in pixels, not counting the center pixel.
* @param sigma - The standard deviation of the Laplacian, in pixels.
*/
adaptiveBlur(radius: number, sigma: number): void;

/**
* Applies the specified alpha option.
* @param value - The option to use.
Expand Down Expand Up @@ -1956,6 +1974,18 @@ export class MagickImage extends NativeInstance implements IMagickImage {

get width(): number { return ImageMagick._api._MagickImage_Width_Get(this._instance); }

adaptiveBlur(): void;
adaptiveBlur(radius: number): void;
adaptiveBlur(radius: number, sigma: number): void;
adaptiveBlur(radiusOrUndefined?: number, sigmaOrUndefined?: number): void {
const radius = this.valueOrDefault(radiusOrUndefined, 0);
const sigma = this.valueOrDefault(sigmaOrUndefined, 1);
this.useException(exception => {
const instance = ImageMagick._api._MagickImage_AdaptiveBlur(this._instance, radius, sigma, exception.ptr);
this._setInstance(instance, exception);
});
}

alpha(value: AlphaOption): void {
this.useExceptionPointer(exception => {
ImageMagick._api._MagickImage_SetAlpha(this._instance, value, exception);
Expand Down
38 changes: 38 additions & 0 deletions tests/magick-image/adaptive-blur.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm.
// Licensed under the Apache License, Version 2.0.

import { ErrorMetric } from '@src/enums/error-metric';
import { TestImages } from '@test/test-images';

describe('MagickImage#blur', () => {
it('should change pixels of the image', () => {
TestImages.fujiFilmFinePixS1ProJpg.use(image => {
image.adaptiveBlur(4, 2);
expect(image).toHavePixelWithColor(56, 68, '#3e719cff');
});
});

it('should use the correct default value for sigma', () => {
TestImages.Builtin.logo.use(image => {
image.clone(other => {
image.adaptiveBlur(3);
other.adaptiveBlur(3, 1);

const difference = other.compare(image, ErrorMetric.RootMeanSquared);
expect(difference).toBe(0);
})
});
});

it('should use the correct default value for radius and sigma', () => {
TestImages.Builtin.logo.use(image => {
image.clone(other => {
image.adaptiveBlur();
other.adaptiveBlur(0, 1);

const difference = other.compare(image, ErrorMetric.RootMeanSquared);
expect(difference).toBe(0);
})
});
});
});

0 comments on commit 8263de8

Please sign in to comment.