| OLD | NEW |
| 1 <html> | 1 <html> |
| 2 <head> | 2 <head> |
| 3 <title>drawing <video> to <canvas></title> | 3 <title>drawing <video> to <canvas></title> |
| 4 <!-- TODO(philipj): Convert test to testharness.js. crbug.com/588956 |
| 5 (Please avoid writing new tests using video-test.js) --> |
| 4 <script src=../http/tests/media/video-test.js></script> | 6 <script src=../http/tests/media/video-test.js></script> |
| 5 | 7 |
| 6 <script> | 8 <script> |
| 7 var ctx; | 9 var ctx; |
| 8 var results = { | 10 var results = { |
| 9 current: 0, | 11 current: 0, |
| 10 values: [ | 12 values: [ |
| 11 { time:0, r:255, g:255, b:0 }, | 13 { time:0, r:255, g:255, b:0 }, |
| 12 { time:2, r:8, g:0, b:226 }, | 14 { time:2, r:8, g:0, b:226 }, |
| 13 { time:4, r:0, g:24, b:197 }, | 15 { time:4, r:0, g:24, b:197 }, |
| 14 { time:6, r:0, g:46, b:166 }, | 16 { time:6, r:0, g:46, b:166 }, |
| 15 { time:8, r:0, g:66, b:136 }, | 17 { time:8, r:0, g:66, b:136 }, |
| 16 { time:10, r:0, g:85, b:112 }, | 18 { time:10, r:0, g:85, b:112 }, |
| 17 ] | 19 ] |
| 18 }; | 20 }; |
| 19 | 21 |
| 20 var width; | 22 var width; |
| 21 var height; | 23 var height; |
| 22 | 24 |
| 23 function testPixel() | 25 function testPixel() |
| 24 { | 26 { |
| 25 var expected = results.values[results.current]; | 27 var expected = results.values[results.current]; |
| 26 if (expected.time) | 28 if (expected.time) |
| 27 ctx.drawImage(video, 0, 0, width, height); | 29 ctx.drawImage(video, 0, 0, width, height); |
| 28 | 30 |
| 29 var frame = ctx.getImageData(0, 0, width, height); | 31 var frame = ctx.getImageData(0, 0, width, height); |
| 30 r = frame.data[4 * 2 * width + 16 + 0]; | 32 r = frame.data[4 * 2 * width + 16 + 0]; |
| 31 g = frame.data[4 * 2 * width + 16 + 1]; | 33 g = frame.data[4 * 2 * width + 16 + 1]; |
| 32 b = frame.data[4 * 2 * width + 16 + 2]; | 34 b = frame.data[4 * 2 * width + 16 + 2]; |
| 33 | 35 |
| 34 testExpected("r", expected.r); | 36 testExpected("r", expected.r); |
| 35 testExpected("g", expected.g); | 37 testExpected("g", expected.g); |
| 36 testExpected("b", expected.b); | 38 testExpected("b", expected.b); |
| 37 | 39 |
| 38 if (++results.current >= results.values.length) | 40 if (++results.current >= results.values.length) |
| 39 endTest(); | 41 endTest(); |
| 40 else | 42 else |
| 41 setTimeout(testFrame, 0); | 43 setTimeout(testFrame, 0); |
| 42 } | 44 } |
| 43 | 45 |
| 44 function testFrame() | 46 function testFrame() |
| 45 { | 47 { |
| 46 video.pause(); | 48 video.pause(); |
| 47 consoleWrite(""); | 49 consoleWrite(""); |
| 48 var expected = results.values[results.current]; | 50 var expected = results.values[results.current]; |
| 49 if (expected.time) | 51 if (expected.time) |
| 50 run("video.currentTime = " + expected.time); | 52 run("video.currentTime = " + expected.time); |
| 51 setTimeout(testPixel, 100); | 53 setTimeout(testPixel, 100); |
| 52 } | 54 } |
| 53 | 55 |
| 54 function loadedmetadata() | 56 function loadedmetadata() |
| 55 { | 57 { |
| 56 width = video.videoWidth / 2; | 58 width = video.videoWidth / 2; |
| 57 height = video.videoHeight / 2; | 59 height = video.videoHeight / 2; |
| 58 | 60 |
| 59 ctx = canvas.getContext("2d"); | 61 ctx = canvas.getContext("2d"); |
| 60 ctx.fillStyle = 'yellow'; | 62 ctx.fillStyle = 'yellow'; |
| 61 ctx.fillRect(0, 0, width, height); | 63 ctx.fillRect(0, 0, width, height); |
| 62 testFrame(); | 64 testFrame(); |
| 63 } | 65 } |
| 64 | 66 |
| 65 function start() | 67 function start() |
| 66 { | 68 { |
| 67 findMediaElement(); | 69 findMediaElement(); |
| 68 canvas = document.getElementsByTagName('canvas')[0]; | 70 canvas = document.getElementsByTagName('canvas')[0]; |
| 69 waitForEvent('loadedmetadata', loadedmetadata); | 71 waitForEvent('loadedmetadata', loadedmetadata); |
| 70 run("video.src = 'content/counting.mp4'"); | 72 run("video.src = 'content/counting.mp4'"); |
| 71 } | 73 } |
| 72 </script> | 74 </script> |
| 73 </head> | 75 </head> |
| 74 | 76 |
| 75 <body onload="start()" > | 77 <body onload="start()" > |
| 76 | 78 |
| 77 <div> | 79 <div> |
| 78 <video controls></video> | 80 <video controls></video> |
| 79 <canvas width="160" height="120" ></canvas> | 81 <canvas width="160" height="120" ></canvas> |
| 80 </div> | 82 </div> |
| 81 | 83 |
| 82 <p>Test <video> as a source for <canvas>.</p> | 84 <p>Test <video> as a source for <canvas>.</p> |
| 83 | 85 |
| 84 </body> | 86 </body> |
| 85 </html> | 87 </html> |
| OLD | NEW |