Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Motion Blur #105

Merged
merged 2 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/magick-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ export interface IMagickImage extends IDisposable {
modulate(brightness: Percentage): void;
modulate(brightness: Percentage, saturation: Percentage): void;
modulate(brightness: Percentage, saturation: Percentage, hue: Percentage): void;
motionBlur():void;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please remove this overload? The user will always need to specify the values. In ImageMagick the last value is not mandatory but I don't want to create a specific overload for this. And this overload is also not available in the Magick.NET api and I am trying to keep this library as close as possible to the Magick.NET library.

motionBlur(radius?: number, sigma?: number, angle?: number): void;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these numbers should be mandatory in this overload.

negate(): void;
negate(channels: Channels): void;
negateGrayScale(): void;
Expand Down Expand Up @@ -1149,6 +1151,18 @@ export class MagickImage extends NativeInstance implements IMagickImage {
});
}

motionBlur():void;
motionBlur(radiusOrUndefined?: number, sigmaOrUndefined?: number, angleOrUndefined?: number): void {
const radius = this.valueOrDefault(radiusOrUndefined, 10);
const sigma = this.valueOrDefault(sigmaOrUndefined, 1);
const angle = this.valueOrDefault(angleOrUndefined, 0);

Exception.use(exception => {
const instance = ImageMagick._api._MagickImage_MotionBlur(this._instance, radius, sigma, angle, exception.ptr);
this._setInstance(instance, exception);
});
}

oilPaint(): void;
oilPaint(radius: number): void
oilPaint(radiusOrUndefined?: number): void {
Expand Down
23 changes: 23 additions & 0 deletions tests/magick-image/motion-blur.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm.
// Licensed under the Apache License, Version 2.0.

import { IMagickImage, MagickImage } from '../../src/magick-image';

let image: IMagickImage;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need this anymore. You can use TestImages.Builtin.logo.use((image) => { in the unit test instead.


beforeEach(() => {
image = MagickImage.create();
image.read('logo:');
});

afterEach(() => {
image.dispose();
});

describe('MagickImage#motionBlur', () => {
it('should change pixels of the image', () => {
image.motionBlur(100, 10, -90);

expect(image).toHavePixelWithColor(222, 60, '#ff0d0dff');
});
});