Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
83 lines (76 loc) · 1.95 KB

File metadata and controls

83 lines (76 loc) · 1.95 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
function imageToArray(image) {
const canvas = document.createElement('canvas');
canvas.width = image.width;
canvas.height = image.height;
document.body.appendChild(canvas);
document.body.appendChild(image);
const ctx = canvas.getContext('2d');
ctx.drawImage(image, 0, 0);
const { data } = ctx.getImageData(0, 0, image.width, image.height);
document.body.removeChild(canvas);
document.body.removeChild(image);
let i = 0;
const result = [];
for (let y = 0; y < image.height; y++) {
const row = [];
result.unshift(row);
for (let x = 0; x < image.width; x++) {
const pixel = new Float32Array([
data[i++],
data[i++],
data[i++],
data[i++],
]);
row.push(pixel);
}
}
return result;
}
function loadImage(image) {
return new Promise((resolve) => {
if (typeof image === 'string') {
const src = image;
image = new Image();
image.src = src;
}
image.onload = () => {
resolve(image);
};
});
}
function loadImages(images) {
return Promise.all(images.map(image => loadImage(image)));
}
function check2DImage(result, expected, channel) {
const height = result.length;
const width = result[0].length;
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
if (result[y][x] !== expected[y][x][channel]) {
throw new Error(`result[${y}][${x}] value does not match expected value of ${expected[y][x][channel]}`);
}
}
}
return true;
}
function greenCanvas(mode, width, height) {
const gpu = new GPU({ mode });
const kernel = gpu.createKernel(function() {
this.color(0, 1, 0, 1);
}, { output: [width, height], graphical: true });
kernel();
const canvas = kernel.canvas;
gpu.destroy();
return canvas;
}
const _exports = {
greenCanvas,
imageToArray,
loadImage,
check2DImage,
};
if (typeof window !== 'undefined') {
window.browserTestUtils = _exports;
} else {
module.exports = _exports;
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.