We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1531ce2 commit 58002beCopy full SHA for 58002be
index.js
@@ -6,6 +6,9 @@ function pixelmatch(img1, img2, output, width, height, options) {
6
7
if (img1.length !== img2.length) throw new Error('Image sizes do not match.');
8
9
+ if (!ArrayBuffer.isView(img1) || !ArrayBuffer.isView(img2) || (output && !ArrayBuffer.isView(output)))
10
+ throw new Error('Image data: Uint8Array, Uint8ClampedArray or Buffer expected.');
11
+
12
const len = width * height;
13
const a32 = new Uint32Array(img1.buffer, img1.byteOffset, len);
14
const b32 = new Uint32Array(img2.buffer, img2.byteOffset, len);
test/test.js
@@ -15,9 +15,17 @@ diffTest('6a', '6b', '6diff', 0.05, false, 51);
15
diffTest('6a', '6a', '6empty', 0, false, 0);
16
17
test('throws error if image sizes do not match', (t) => {
18
- t.throws(() => {
19
- match([1, 2, 3], [1, 2, 3, 4], null, 2, 1);
20
- }, /Image sizes do not match/);
+ t.throws(() => match([1, 2, 3], [1, 2, 3, 4], null, 2, 1), /Image sizes do not match/);
+ t.end();
+});
21
22
+test('throws error if provided wrong image data format', (t) => {
23
+ const re = /Image data: Uint8Array, Uint8ClampedArray or Buffer expected/;
24
+ const arr = new Uint8Array(4 * 20 * 20);
25
+ const bad = new Array(arr.length).fill(0);
26
+ t.throws(() => match(bad, arr, null, 20, 20), re);
27
+ t.throws(() => match(arr, bad, null, 20, 20), re);
28
+ t.throws(() => match(arr, arr, bad, 20, 20), re);
29
t.end();
30
});
31
0 commit comments