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

Commit fedba43

Browse files
opatinytargos
andauthored
feat: implement channelLabels (#294)
* feat: implement channelLabels Closes: #256 * Update src/utils/constants/channelLabels.ts Co-authored-by: Michaël Zasso <[email protected]> * fix: type error --------- Co-authored-by: Michaël Zasso <[email protected]>
1 parent 70d251c commit fedba43

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Image } from '../../../Image';
2+
import { channelLabels } from '../channelLabels';
3+
import { ImageColorModel } from '../colorModels';
4+
5+
test.each([
6+
{
7+
message: 'grey',
8+
colorModel: ImageColorModel.GREY,
9+
expected: ['Grey'],
10+
},
11+
{
12+
message: 'greya',
13+
colorModel: ImageColorModel.GREYA,
14+
expected: ['Grey', 'Alpha'],
15+
},
16+
{
17+
message: 'rgb',
18+
colorModel: ImageColorModel.RGB,
19+
expected: ['Red', 'Green', 'Blue'],
20+
},
21+
{
22+
message: 'rgba',
23+
colorModel: ImageColorModel.RGBA,
24+
expected: ['Red', 'Green', 'Blue', 'Alpha'],
25+
},
26+
{
27+
message: 'binary',
28+
colorModel: ImageColorModel.BINARY,
29+
expected: ['Mask'],
30+
},
31+
])('channelLabels for $message image', (data) => {
32+
expect(channelLabels[data.colorModel]).toStrictEqual(data.expected);
33+
});
34+
35+
test('channelLabels through image colorModel', () => {
36+
const image = new Image(2, 2);
37+
expect(channelLabels[image.colorModel]).toStrictEqual([
38+
'Red',
39+
'Green',
40+
'Blue',
41+
]);
42+
});

src/utils/constants/channelLabels.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { ImageColorModel } from './colorModels';
2+
3+
export const channelLabels = {
4+
GREY: ['Grey'],
5+
GREYA: ['Grey', 'Alpha'],
6+
RGB: ['Red', 'Green', 'Blue'],
7+
RGBA: ['Red', 'Green', 'Blue', 'Alpha'],
8+
BINARY: ['Mask'],
9+
} as const satisfies Record<ImageColorModel, readonly string[]>;

0 commit comments

Comments
 (0)