MCPcopy
hub / github.com/processing/p5.js / checkTint

Function checkTint

test/unit/image/loading.js:275–312  ·  view source on GitHub ↗
(tintColor)

Source from the content-addressed store, hash-verified

273 });
274
275 function checkTint(tintColor) {
276 myp5.loadPixels();
277 pImg.loadPixels();
278 for (var i = 0; i < myp5.pixels.length; i += 4) {
279 var x = (i / 4) % myp5.width;
280 var y = Math.floor(i / 4 / myp5.width);
281 for (var chan = 0; chan < tintColor.length; chan++) {
282 var inAlpha = 1;
283 var outAlpha = 1;
284 if (chan < 3) {
285 // The background of the canvas is black, so after applying the
286 // image's own alpha + the tint alpha to its color channels, we
287 // should arrive at the same color that we see on the canvas.
288 inAlpha = tintColor[3] / 255;
289 outAlpha = pImg.pixels[i + 3] / 255;
290
291 // Applying the tint involves un-multiplying the alpha of the source
292 // image, which causes a bit of loss of precision. I'm allowing a
293 // loss of 10 / 255 in this test.
294 assert.approximately(
295 myp5.pixels[i + chan],
296 pImg.pixels[i + chan] *
297 (tintColor[chan] / 255) *
298 outAlpha *
299 inAlpha,
300 10,
301 'Tint output for the ' +
302 chanNames[chan] +
303 ' channel of pixel (' +
304 x +
305 ', ' +
306 y +
307 ') should be equivalent to multiplying the image value by tint fraction'
308 );
309 }
310 }
311 }
312 }
313
314 test('tint() with color', function() {
315 assert.ok(pImg, 'image loaded');

Callers 1

loading.jsFile · 0.85

Calls 1

loadPixelsMethod · 0.45

Tested by

no test coverage detected