MCPcopy Index your code
hub / github.com/gpujs/gpu.js / testHTMLImage

Function testHTMLImage

test/features/dynamic-arguments.js:6–43  ·  view source on GitHub ↗
(done, mode)

Source from the content-addressed store, hash-verified

4describe('features: dynamic arguments');
5
6function testHTMLImage(done, mode) {
7 const image1 = new Image();
8 const image2 = new Image();
9 image1.src = 'jellyfish.jpeg';
10 image2.src = 'jellyfish-1.jpeg';
11 let loadedCount = 0;
12 image1.onload = image2.onload = () => {
13 loadedCount++;
14 if (loadedCount === 2) loaded();
15 };
16
17 function loaded() {
18 const gpu = new GPU({ mode });
19 const kernel = gpu.createKernel(function(image) {
20 const pixel = image[this.thread.y][this.thread.x];
21 return (pixel[0] + pixel[1] + pixel[2]) / 3;
22 })
23 .setDynamicArguments(true)
24 .setDynamicOutput(true)
25 .setOutput([276, 183]);
26
27 const pixels1 = kernel(image1);
28 kernel.setOutput([138, 91]);
29 const pixels2 = kernel(image2);
30
31 assert.ok(pixels1[0][0] > .43);
32 assert.ok(pixels1[0][0] < .45);
33 assert.equal(pixels1.length, image1.height);
34 assert.equal(pixels1[0].length, image1.width);
35 assert.ok(pixels2[0][0] > .82);
36 assert.ok(pixels2[0][0] < .83);
37 assert.equal(pixels2.length, image2.height);
38 assert.equal(pixels2[0].length, image2.width);
39
40 gpu.destroy();
41 done();
42 }
43}
44
45(typeof Image !== 'undefined' ? test : skip)('HTML Image auto', t => {
46 testHTMLImage(t.async());

Callers 1

Calls 1

loadedFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…