Skip to content

Commit

Permalink
Added solarize to MagickImage (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenscordeirobr authored Jun 26, 2023
1 parent bcb3113 commit a249a3a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/magick-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ 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: number): void;
solarize(factor: Percentage): void;
statistics(): IStatistics;
statistics(channels: Channels): IStatistics;
strip(): void;
Expand Down Expand Up @@ -1328,6 +1331,14 @@ export class MagickImage extends NativeInstance implements IMagickImage {
this._sigmoidalContrast(true, contrast, midpointOrPercentage, channelsOrUndefined)
}

solarize(): void
solarize(numberOrPercentage: Percentage | number = new Percentage(50)): void {
Exception.use(exception => {
const factor = typeof numberOrPercentage === "number" ? new Percentage(numberOrPercentage) : numberOrPercentage;
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'));
});
});
});

0 comments on commit a249a3a

Please sign in to comment.