Skip to content

Commit b9c3bce

Browse files
authored
Merge pull request #5871 from davepagurek/fix/mediaelement-tint
Fix tint() for p5.MediaElement
2 parents 503d31e + c7133d4 commit b9c3bce

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/core/p5.Renderer2D.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ p5.Renderer2D.prototype.image = function(
161161
}
162162

163163
try {
164+
if (p5.MediaElement && img instanceof p5.MediaElement) {
165+
img._ensureCanvas();
166+
}
164167
if (this._tint && img.canvas) {
165168
cnv = this._getTintedImageCanvas(img);
166169
}

test/unit/assets/cat.webm

12 KB
Binary file not shown.

test/unit/dom/dom.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,32 @@ suite('DOM', function() {
12961296
};
12971297
}
12981298
);
1299+
1300+
test('should work with tint()', function(done) {
1301+
const imgElt = myp5.createImg('/test/unit/assets/cat.jpg', '');
1302+
testElement = myp5.createVideo('/test/unit/assets/cat.webm', () => {
1303+
// Workaround for headless tests, where the video data isn't loading
1304+
// correctly: mock the video element using an image for this test
1305+
const prevElt = testElement.elt;
1306+
testElement.elt = imgElt.elt;
1307+
1308+
myp5.background(255);
1309+
myp5.tint(255, 0, 0);
1310+
myp5.image(testElement, 0, 0);
1311+
1312+
testElement.elt = prevElt;
1313+
imgElt.remove();
1314+
1315+
myp5.loadPixels();
1316+
testElement.loadPixels();
1317+
console.log(testElement.pixels.slice(0, 3));
1318+
console.log(myp5.pixels.slice(0, 3));
1319+
assert.equal(myp5.pixels[0], testElement.pixels[0]);
1320+
assert.equal(myp5.pixels[1], 0);
1321+
assert.equal(myp5.pixels[2], 0);
1322+
done();
1323+
});
1324+
});
12991325
});
13001326

13011327
suite('p5.prototype.createAudio', function() {

0 commit comments

Comments
 (0)