From a249a3a9eb067d0bf8f7deb076a547abaef5db04 Mon Sep 17 00:00:00 2001 From: Rubens Cordeiro Date: Mon, 26 Jun 2023 18:54:47 -0300 Subject: [PATCH] Added solarize to MagickImage (#100) --- src/magick-image.ts | 11 +++++++++++ tests/magick-image/solarize.spec.ts | 17 +++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 tests/magick-image/solarize.spec.ts diff --git a/src/magick-image.ts b/src/magick-image.ts index 6d92da62..0a64ceca 100644 --- a/src/magick-image.ts +++ b/src/magick-image.ts @@ -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; @@ -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 => { diff --git a/tests/magick-image/solarize.spec.ts b/tests/magick-image/solarize.spec.ts new file mode 100644 index 00000000..c913e684 --- /dev/null +++ b/tests/magick-image/solarize.spec.ts @@ -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')); + }); + }); +});