File tree Expand file tree Collapse file tree 3 files changed +29
-0
lines changed
Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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 ( ) {
You can’t perform that action at this time.
0 commit comments