Skip to content

Commit 0f76c7b

Browse files
Peeterushdlemstra
authored andcommitted
Added gammaCorrect to MagickImage.
1 parent 30bb9a8 commit 0f76c7b

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

src/magick-image.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,19 @@ export interface IMagickImage extends IDisposable {
961961
*/
962962
flop(): void;
963963

964+
/**
965+
* Gamma correct image.
966+
* @param gamma - The image gamma.
967+
*/
968+
gammaCorrect(gamma: number): void;
969+
970+
/**
971+
* Gamma correct image.
972+
* @param gamma - The image gamma for the channel.
973+
* @param channels - The channel(s) to gamma correct.
974+
*/
975+
gammaCorrect(gamma: number, channels: Channels): void;
976+
964977
/**
965978
* Gaussian blur image.
966979
* @param radius - The number of neighbor pixels to be included in the convolution.
@@ -2488,6 +2501,19 @@ export class MagickImage extends NativeInstance implements IMagickImage {
24882501
});
24892502
}
24902503

2504+
gammaCorrect(gamma: number): void;
2505+
gammaCorrect(gamma: number, channels: Channels): void;
2506+
gammaCorrect(gamma: number, channelsOrUndefined?: Channels): void {
2507+
const channels = this.valueOrDefault(
2508+
channelsOrUndefined,
2509+
Channels.Undefined
2510+
);
2511+
2512+
this.useExceptionPointer((exception) => {
2513+
ImageMagick._api._MagickImage_GammaCorrect(this._instance, gamma, channels, exception);
2514+
});
2515+
}
2516+
24912517
gaussianBlur(radius: number): void;
24922518
gaussianBlur(radius: number, sigma: number): void;
24932519
gaussianBlur(radius: number, sigma: number, channels: Channels): void;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm.
2+
// Licensed under the Apache License, Version 2.0.
3+
4+
import { Channels } from '@src/enums/channels';
5+
import { ErrorMetric } from '@src/enums/error-metric';
6+
import { TestImages } from '@test/test-images';
7+
8+
describe('MagickImage#gammaCorrect', () => {
9+
it('should gamma correct the image', () => {
10+
TestImages.Builtin.rose.use(image => {
11+
image.clone(other => {
12+
other.gammaCorrect(2);
13+
14+
const difference = image.compare(other, ErrorMetric.RootMeanSquared);
15+
expect(difference).toBeCloseTo(0.21576);
16+
});
17+
});
18+
});
19+
20+
it('should gamma correct the specified channels', () => {
21+
TestImages.Builtin.rose.use(image => {
22+
image.clone(other => {
23+
other.gammaCorrect(2, Channels.Red);
24+
25+
const difference = image.compare(other, ErrorMetric.RootMeanSquared);
26+
expect(difference).toBeCloseTo(0.10594);
27+
});
28+
});
29+
});
30+
});

0 commit comments

Comments
 (0)