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 solarize to MagickImage #100

Merged
merged 6 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
10 changes: 10 additions & 0 deletions src/magick-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ export interface IMagickImage extends IDisposable {
sigmoidalContrast(contrast: number, midpoint: number): void;
sigmoidalContrast(contrast: number, midpoint: number, channels: Channels): void;
splice(geometry: MagickGeometry): void;
solarize(): void;
solarize(factor: Percentage | number): void;
Copy link
Owner

@dlemstra dlemstra Jun 26, 2023

Choose a reason for hiding this comment

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

In the interface I don't use | but write both overloads instead.

solarize(factor: number): void;
solarize(factor: Percentage): void;

statistics(): IStatistics;
statistics(channels: Channels): IStatistics;
strip(): void;
Expand Down Expand Up @@ -1328,6 +1330,14 @@ export class MagickImage extends NativeInstance implements IMagickImage {
this._sigmoidalContrast(true, contrast, midpointOrPercentage, channelsOrUndefined)
}

solarize(): void
solarize(factorOrNumber: Percentage | number = new Percentage(50)): 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 change factorOrNumber to numberOrPercentage? And I like the use of = new Percentage(50). Think I should have used that in some other spots also.

Exception.use(exception => {
const factor = typeof factorOrNumber === "number" ? new Percentage(factorOrNumber) : factorOrNumber;
ImageMagick._api._MagickImage_Solarize(this._instance, factor.toQuantum(), exception.ptr);
});
}

splice(geometry: MagickGeometry): void {
MagickRectangle.use(this, geometry, geometryPtr => {
Exception.use(exception => {
Expand Down
17 changes: 17 additions & 0 deletions tests/magick-image/solarize.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm.
// Licensed under the Apache License, Version 2.0.

import { MagickColor } from '../../src/magick-color';
import { MagickColors } from '../../src/magick-colors';
import { TestImages } from '../test-images';

describe('MagickImage#solarize', () => {
it('should solarize the image', () => {
TestImages.Builtin.logo.use(image => {
image.solarize();
expect(image).toHavePixelWithColor(125, 125, MagickColors.Black);
expect(image).toHavePixelWithColor(122, 143, new MagickColor('#007f7f'));
expect(image).toHavePixelWithColor(435, 240, new MagickColor('#2e6935'));
});
});
});