forked from gpujs/gpu.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread-image-data.js
More file actions
44 lines (36 loc) · 1.36 KB
/
read-image-data.js
File metadata and controls
44 lines (36 loc) · 1.36 KB
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
const { assert, skip, test, module: describe } = require('qunit');
const { GPU } = require('../../src');
describe('features: read from image data');
function readImageData(mode) {
const gpu = new GPU({ mode });
const dataArray = new Uint8ClampedArray([255, 255, 255, 255]);
const imageData = new ImageData(dataArray, 1, 1);
const kernel = gpu.createKernel(function(imageData) {
const pixel = imageData[this.thread.y][this.thread.x];
return pixel[0] + pixel[1] + pixel[2] + pixel[3];
}, {
output: [1]
});
const result = kernel(imageData);
assert.equal(result.length, 1);
assert.equal(result[0], 4);
gpu.destroy();
}
(typeof ImageData !== 'undefined' ? test : skip)('readImageData auto', () => {
readImageData(null);
});
(typeof ImageData !== 'undefined' ? test : skip)('readImageData gpu', () => {
readImageData('gpu');
});
(GPU.isWebGLSupported && typeof ImageData !== 'undefined' ? test : skip)('readImageData webgl', () => {
readImageData('webgl');
});
(GPU.isWebGL2Supported && typeof ImageData !== 'undefined' ? test : skip)('readImageData webgl2', () => {
readImageData('webgl2');
});
(GPU.isHeadlessGLSupported && typeof ImageData !== 'undefined' ? test : skip)('readImageData headlessgl', () => {
readImageData('headlessgl');
});
(typeof ImageData !== 'undefined' ? test : skip)('readImageData cpu', () => {
readImageData('cpu');
});