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

Commit 21a6296

Browse files
committed
test: add tests to setBlendedVisiblePixel
1 parent 8a82333 commit 21a6296

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { setBlendedVisiblePixel } from '../setBlendedVisiblePixel';
2+
3+
test('GREYA image, default options', () => {
4+
const image = testUtils.createGreyaImage([
5+
[50, 255],
6+
[20, 30],
7+
]);
8+
setBlendedVisiblePixel(image, 0, 1);
9+
expect(image).toMatchImageData([
10+
[50, 255],
11+
[0, 255],
12+
]);
13+
});
14+
15+
test('GREYA image: set pixel out of bounds', () => {
16+
const image = testUtils.createGreyaImage([
17+
[50, 255, 1, 2, 3, 4],
18+
[20, 30, 5, 6, 7, 8],
19+
[1, 2, 3, 4, 5, 6],
20+
]);
21+
setBlendedVisiblePixel(image, 0, 5, { color: [40, 40] });
22+
expect(image).toMatchImageData([
23+
[50, 255, 1, 2, 3, 4],
24+
[20, 30, 5, 6, 7, 8],
25+
[1, 2, 3, 4, 5, 6],
26+
]);
27+
});
28+
29+
test('RGBA image: set pixel out of bounds', () => {
30+
const image = testUtils.createGreyaImage([
31+
[50, 255, 1, 200, 2, 3, 4, 200],
32+
[20, 30, 5, 200, 6, 7, 8, 200],
33+
[1, 2, 3, 200, 4, 5, 6, 200],
34+
]);
35+
setBlendedVisiblePixel(image, 0, 5, { color: [40, 40, 40, 40] });
36+
expect(image).toMatchImageData([
37+
[50, 255, 1, 200, 2, 3, 4, 200],
38+
[20, 30, 5, 200, 6, 7, 8, 200],
39+
[1, 2, 3, 200, 4, 5, 6, 200],
40+
]);
41+
});
42+
43+
test('GREYA image: alpha different from 255', () => {
44+
const image = testUtils.createGreyaImage([[50, 64]]);
45+
setBlendedVisiblePixel(image, 0, 0, { color: [100, 128] });
46+
const alpha = 128 + 64 * (1 - 128 / 255);
47+
const component = (100 * 128 + 50 * 64 * (1 - 128 / 255)) / alpha;
48+
expect(image).toMatchImageData([[component, alpha]]);
49+
});
50+
51+
test('asymetrical test', () => {
52+
const image = testUtils.createGreyaImage([
53+
[50, 255, 1, 2, 3, 4],
54+
[20, 30, 5, 6, 7, 8],
55+
[1, 2, 3, 4, 5, 6],
56+
]);
57+
setBlendedVisiblePixel(image, 2, 0, { color: [0, 125] });
58+
expect(image).toMatchImageData([
59+
[50, 255, 1, 2, 0, 127],
60+
[20, 30, 5, 6, 7, 8],
61+
[1, 2, 3, 4, 5, 6],
62+
]);
63+
});

0 commit comments

Comments
 (0)