MCPcopy Index your code
hub / github.com/processing/p5.js / testImageRender

Function testImageRender

test/unit/image/loading.js:12–33  ·  view source on GitHub ↗
(file, sketch)

Source from the content-addressed store, hash-verified

10 * and checks that they are exactly the same. Sends result to the callback.
11 */
12var testImageRender = function(file, sketch) {
13 sketch.loadPixels();
14 var p = sketch.pixels;
15 var ctx = sketch;
16
17 sketch.clear();
18
19 return new Promise(function(resolve, reject) {
20 sketch.loadImage(file, resolve, reject);
21 }).then(function(img) {
22 ctx.image(img, 0, 0);
23
24 ctx.loadPixels();
25 var n = 0;
26 for (var i = 0; i < p.length; i++) {
27 var diff = Math.abs(p[i] - ctx.pixels[i]);
28 n += diff;
29 }
30 var same = n === 0 && ctx.pixels.length === p.length;
31 return same;
32 });
33};
34
35suite('loading images', function() {
36 const imagePath = '/test/unit/assets/cat.jpg';

Callers

nothing calls this directly

Calls 3

imageMethod · 0.80
loadPixelsMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected