Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
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(
Copy link
Owner

Choose a reason for hiding this comment

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

I can change this but I prefer this to be on the same line.

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);
});
});
});
});