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

Commit 1225b4d

Browse files
feat: expose extendBorders (#465)
1 parent f81e45e commit 1225b4d

File tree

4 files changed

+53
-18
lines changed

4 files changed

+53
-18
lines changed

src/filters/convolution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import {
44
} from 'ml-convolution';
55

66
import { Image } from '../Image';
7+
import { extendBorders } from '../operations/extendBorders';
78
import { getClamp } from '../utils/clamp';
8-
import { extendBorders } from '../utils/extendBorders';
99
import { getIndex } from '../utils/getIndex';
1010
import { getOutputImage } from '../utils/getOutputImage';
1111
import { BorderType, getBorderInterpolation } from '../utils/interpolateBorder';

src/utils/__tests__/extendBorders.test.ts renamed to src/operations/__tests__/extendBorders.test.ts

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
import { extendBorders } from '../extendBorders';
22

3+
test('grey image with basic value', () => {
4+
const image = testUtils.createGreyImage(`
5+
1 2
6+
3 4
7+
5 6
8+
7 8
9+
`);
10+
11+
const newImage = extendBorders(image, {
12+
horizontal: 1,
13+
vertical: 1,
14+
borderType: 'constant',
15+
});
16+
expect(newImage).toMatchImageData(`
17+
0 0 0 0
18+
0 1 2 0
19+
0 3 4 0
20+
0 5 6 0
21+
0 7 8 0
22+
0 0 0 0
23+
`);
24+
});
25+
326
test('grey image with wrap', () => {
427
const image = testUtils.createGreyImage(`
528
1 2 3 4
@@ -8,26 +31,24 @@ test('grey image with wrap', () => {
831
4 5 6 7
932
5 6 7 8
1033
`);
11-
1234
const newImage = extendBorders(image, {
1335
horizontal: 2,
1436
vertical: 3,
1537
borderType: 'wrap',
1638
});
17-
1839
expect(newImage).toMatchImageData(`
19-
5 6 3 4 5 6 3 4
20-
6 7 4 5 6 7 4 5
21-
7 8 5 6 7 8 5 6
22-
3 4 1 2 3 4 1 2
23-
4 5 2 3 4 5 2 3
24-
5 6 3 4 5 6 3 4
25-
6 7 4 5 6 7 4 5
26-
7 8 5 6 7 8 5 6
27-
3 4 1 2 3 4 1 2
28-
4 5 2 3 4 5 2 3
29-
5 6 3 4 5 6 3 4
30-
`);
40+
5 6 3 4 5 6 3 4
41+
6 7 4 5 6 7 4 5
42+
7 8 5 6 7 8 5 6
43+
3 4 1 2 3 4 1 2
44+
4 5 2 3 4 5 2 3
45+
5 6 3 4 5 6 3 4
46+
6 7 4 5 6 7 4 5
47+
7 8 5 6 7 8 5 6
48+
3 4 1 2 3 4 1 2
49+
4 5 2 3 4 5 2 3
50+
5 6 3 4 5 6 3 4
51+
`);
3152
});
3253

3354
test('rgb image with default border type', () => {

src/utils/extendBorders.ts renamed to src/operations/extendBorders.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
import { Image } from '../Image';
2+
import { BorderType, getBorderInterpolation } from '../utils/interpolateBorder';
23

3-
import { BorderType, getBorderInterpolation } from './interpolateBorder';
4-
5-
interface ExtendBordersOptions {
4+
export interface ExtendBordersOptions {
5+
/**
6+
* Left and right border thickness.
7+
*/
68
horizontal: number;
9+
/**
10+
*Top and bottom border thickness.
11+
*/
712
vertical: number;
13+
/**
14+
* Specify how the borders should be handled.
15+
* @default `'reflect101'`
16+
*/
817
borderType?: BorderType;
18+
/**
19+
* Value of the border if BorderType is 'constant'.
20+
* @default `0`
21+
*/
922
borderValue?: number;
1023
}
1124

src/operations/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ export * from './operations.types';
1313
export * from './paintMaskOnImage';
1414
export * from './paintMaskOnMask';
1515
export * from './correctBackground';
16+
export * from './extendBorders';

0 commit comments

Comments
 (0)