OLD | NEW |
| (Empty) |
1 <!DOCTYPE html> | |
2 <body> | |
3 <script src="../../resources/testharness.js"></script> | |
4 <script src="../../resources/testharnessreport.js"></script> | |
5 <script> | |
6 test(drawThenGetImageData, 'verifies that getImageData works on rec-2020 canvase
s.'); | |
7 test(putThenGetImageData, 'verifies that putImageData works on rec-2020 canvases
.'); | |
8 | |
9 function drawThenGetImageData() { | |
10 var canvas = document.createElement('canvas'); | |
11 canvas.width = 10; | |
12 canvas.height = 10; | |
13 var ctx = canvas.getContext('2d', {colorSpace: 'rec-2020'}) | |
14 ctx.fillStyle = 'rgb(50, 100, 150)'; | |
15 ctx.fillRect(0, 0, 10, 10); | |
16 var pixel = ctx.getImageData(5, 5, 1, 1).data; | |
17 // Note: the color specified as as fillStyle is converted from srgb to linea
r | |
18 // when drawn and the the results of getImageData are re-converted to sRGB | |
19 assert_equals(pixel[0], 50, "Red component retrieved by getImageData is the
color that was drawn." ); | |
20 assert_equals(pixel[1], 100, "Green component retrieved by getImageData is t
he color that was drawn." ); | |
21 assert_equals(pixel[2], 150, "Blue component retrieved by getImageData is th
e color that was drawn." ); | |
22 assert_equals(pixel[3], 255, "Alpha component retrieved by getImageData is t
he color that was drawn." ); | |
23 } | |
24 | |
25 function putThenGetImageData() { | |
26 var canvas = document.createElement('canvas'); | |
27 canvas.width = 10; | |
28 canvas.height = 10; | |
29 var ctx = canvas.getContext('2d', {colorSpace: 'rec-2020'}) | |
30 var initialData = ctx.createImageData(1, 1); | |
31 initialData.data[0] = 50; | |
32 initialData.data[1] = 100; | |
33 initialData.data[2] = 150; | |
34 initialData.data[3] = 255; | |
35 ctx.putImageData(initialData, 5, 5); | |
36 var pixel = ctx.getImageData(5, 5, 1, 1).data; | |
37 assert_equals(pixel[0], 50, "Red component retrieved by getImageData is the
color that was put." ); | |
38 assert_equals(pixel[1], 100, "Green component retrieved by getImageData is t
he color that was put." ); | |
39 assert_equals(pixel[2], 150, "Blue component retrieved by getImageData is th
e color that was put." ); | |
40 assert_equals(pixel[3], 255, "Alpha component retrieved by getImageData is t
he color that was put." ); | |
41 } | |
42 </script> | |
43 </body> | |
OLD | NEW |