Skip to content

Commit

Permalink
Added gammaCorrect to MagickImage.
Browse files Browse the repository at this point in the history
  • Loading branch information
Peeterush authored and dlemstra committed Apr 19, 2024
1 parent 30bb9a8 commit 0f76c7b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/magick-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
30 changes: 30 additions & 0 deletions tests/magick-image/gamma-correct.spec.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
});

0 comments on commit 0f76c7b

Please sign in to comment.