Skip to content
This repository was archived by the owner on Jul 26, 2025. It is now read-only.

Commit 6a74b61

Browse files
committed
refactor: rename enhanceContrast to autoLevel
1 parent 86740f9 commit 6a74b61

File tree

5 files changed

+12
-13
lines changed

5 files changed

+12
-13
lines changed

src/filters/__tests__/enhanceContrast.test.ts renamed to src/filters/__tests__/autoLevel.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { enhanceContrast } from '../enhanceContrast';
1+
import { autoLevel } from '../autoLevel';
22

33
test('3x1 rgba image, custom output min and max', () => {
44
const image = testUtils.createRgbaImage([
@@ -7,7 +7,7 @@ test('3x1 rgba image, custom output min and max', () => {
77
[255, 200, 0, 50],
88
]);
99

10-
const result = enhanceContrast(image);
10+
const result = autoLevel(image);
1111

1212
expect(result).toMatchImageData([
1313
[0, 0, 0, 50],
@@ -18,15 +18,15 @@ test('3x1 rgba image, custom output min and max', () => {
1818

1919
test('1x3 grey image', () => {
2020
const image = testUtils.createGreyImage([[50, 100]]);
21-
expect(enhanceContrast(image)).toMatchImageData([[0, 255]]);
21+
expect(autoLevel(image)).toMatchImageData([[0, 255]]);
2222
});
2323

2424
test('alpha should not be modified', () => {
2525
const image = testUtils.createGreyaImage([
2626
[50, 100],
2727
[100, 50],
2828
]);
29-
expect(enhanceContrast(image)).toMatchImageData([
29+
expect(autoLevel(image)).toMatchImageData([
3030
[0, 100],
3131
[255, 50],
3232
]);
@@ -38,7 +38,7 @@ test('out option', () => {
3838
[30, 40],
3939
[60, 70],
4040
]);
41-
const result = enhanceContrast(image, { out: image });
41+
const result = autoLevel(image, { out: image });
4242
expect(result).toMatchImageData([
4343
[0, 10],
4444
[127, 40],
@@ -49,5 +49,5 @@ test('out option', () => {
4949

5050
test('bigger image', () => {
5151
const image = testUtils.load('featureMatching/id-crops/crop1.png');
52-
expect(enhanceContrast(image)).toMatchImageSnapshot();
52+
expect(autoLevel(image)).toMatchImageSnapshot();
5353
});

src/filters/enhanceContrast.ts renamed to src/filters/autoLevel.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import checkProcessable from '../utils/checkProcessable';
33
import { ImageColorModel } from '../utils/constants/colorModels';
44
import { getOutputImage } from '../utils/getOutputImage';
55

6-
export interface EnhanceContrastOptions {
6+
export interface AutoLevelOptions {
77
/**
88
* Image to which to output.
99
*/
@@ -17,10 +17,7 @@ export interface EnhanceContrastOptions {
1717
* @param options - Enhance contrast options.
1818
* @returns The enhanced image.
1919
*/
20-
export function enhanceContrast(
21-
image: Image,
22-
options: EnhanceContrastOptions = {},
23-
): Image {
20+
export function autoLevel(image: Image, options: AutoLevelOptions = {}): Image {
2421
checkProcessable(image, {
2522
bitDepth: [8, 16],
2623
});

src/filters/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export * from './and';
22
export * from './blur';
33
export * from './convolution';
44
export * from './derivativeFilter';
5-
export * from './enhanceContrast';
5+
export * from './autoLevel';
66
export * from './gaussianBlur';
77
export * from './gradientFilter';
88
export * from './hypotenuse';

src/filters/level.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ function getValueArray(
124124
if (value.length === imageChannels) {
125125
return value;
126126
} else {
127-
throw new Error('array length is not compatible with channel option');
127+
throw new RangeError(
128+
'array length is not compatible with channel option',
129+
);
128130
}
129131
} else {
130132
return new Array(imageChannels).fill(value);

0 commit comments

Comments
 (0)