diff --git a/src/magick-image.ts b/src/magick-image.ts index 31810756..51b8e868 100644 --- a/src/magick-image.ts +++ b/src/magick-image.ts @@ -961,6 +961,19 @@ export interface IMagickImage extends IDisposable { */ flop(): void; + /** + * Gamma correct image. + * @param gamma - The image gamma. + */ + gammaCorrect(gamma: number): void; + + /** + * Gamma correct image. + * @param gamma - The image gamma for the channel. + * @param channels - The channel(s) to gamma correct. + */ + gammaCorrect(gamma: number, channels: Channels): void; + /** * Gaussian blur image. * @param radius - The number of neighbor pixels to be included in the convolution. @@ -2488,6 +2501,19 @@ export class MagickImage extends NativeInstance implements IMagickImage { }); } + gammaCorrect(gamma: number): void; + gammaCorrect(gamma: number, channels: Channels): void; + gammaCorrect(gamma: number, channelsOrUndefined?: Channels): void { + const channels = this.valueOrDefault( + channelsOrUndefined, + Channels.Undefined + ); + + this.useExceptionPointer((exception) => { + ImageMagick._api._MagickImage_GammaCorrect(this._instance, gamma, channels, exception); + }); + } + gaussianBlur(radius: number): void; gaussianBlur(radius: number, sigma: number): void; gaussianBlur(radius: number, sigma: number, channels: Channels): void; diff --git a/tests/magick-image/gamma-correct.spec.ts b/tests/magick-image/gamma-correct.spec.ts new file mode 100644 index 00000000..2d7ba629 --- /dev/null +++ b/tests/magick-image/gamma-correct.spec.ts @@ -0,0 +1,30 @@ +// Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. +// Licensed under the Apache License, Version 2.0. + +import { Channels } from '@src/enums/channels'; +import { ErrorMetric } from '@src/enums/error-metric'; +import { TestImages } from '@test/test-images'; + +describe('MagickImage#gammaCorrect', () => { + it('should gamma correct the image', () => { + TestImages.Builtin.rose.use(image => { + image.clone(other => { + other.gammaCorrect(2); + + const difference = image.compare(other, ErrorMetric.RootMeanSquared); + expect(difference).toBeCloseTo(0.21576); + }); + }); + }); + + it('should gamma correct the specified channels', () => { + TestImages.Builtin.rose.use(image => { + image.clone(other => { + other.gammaCorrect(2, Channels.Red); + + const difference = image.compare(other, ErrorMetric.RootMeanSquared); + expect(difference).toBeCloseTo(0.10594); + }); + }); + }); +});