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

Add threshold to MagickImage #113

Merged
merged 2 commits into from
Oct 17, 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
11 changes: 11 additions & 0 deletions src/magick-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ export interface IMagickImage extends IDisposable {
statistics(): IStatistics;
statistics(channels: Channels): IStatistics;
strip(): void;
threshold(percentage: Percentage): void;
threshold(percentage: Percentage, channels: Channels): void;
toString(): string;
transparent(color: MagickColor): void;
trim(): void;
Expand Down Expand Up @@ -1386,6 +1388,15 @@ export class MagickImage extends NativeInstance implements IMagickImage {
});
}

threshold(percentage: Percentage): void
threshold(percentage: Percentage, channels: Channels): void
threshold(percentage: Percentage, channelsOrUndefined?: Channels): void {
const channels = this.valueOrDefault(channelsOrUndefined, Channels.Undefined);
Exception.usePointer(exception => {
ImageMagick._api._MagickImage_Threshold(this._instance, percentage.toQuantum(), channels, exception);
});
}

toString = (): string => `${this.format} ${this.width}x${this.height} ${this.depth}-bit ${ColorSpace[this.colorSpace]}`

transparent(color: MagickColor): void {
Expand Down
24 changes: 24 additions & 0 deletions tests/magick-image/threshold.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm.
// Licensed under the Apache License, Version 2.0.

import { Channels } from '../../src/channels'
import { ErrorMetric } from '../../src/error-metric'
import { Percentage } from '../../src/percentage'
import { TestImages } from '../test-images'

describe('MagickImage#threshold', () => {
it('should threshold the image with the correct default values', () => {
TestImages.Builtin.logo.use((image) => {
image.clone((other) => {
image.threshold(new Percentage(80))
other.threshold(new Percentage(80), Channels.Undefined)

const difference = other.compare(
with-heart marked this conversation as resolved.
Show resolved Hide resolved
image,
ErrorMetric.RootMeanSquared,
)
expect(difference).toBe(0)
with-heart marked this conversation as resolved.
Show resolved Hide resolved
})
})
})
})