| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <body> | 2 <body> |
| 3 <script src="../../resources/testharness.js"></script> | 3 <script src="../../resources/testharness.js"></script> |
| 4 <script src="../../resources/testharnessreport.js"></script> | 4 <script src="../../resources/testharnessreport.js"></script> |
| 5 <script> | 5 <script> |
| 6 test(drawThenGetImageData, 'verifies that getImageData works on P3 canvases.'); | 6 test(drawThenGetImageData, 'verifies that getImageData works on P3 canvases.'); |
| 7 test(putThenGetImageData, 'verifies that putImageData works on P3 canvases.'); | 7 test(putThenGetImageData, 'verifies that putImageData works on P3 canvases.'); |
| 8 | 8 |
| 9 function drawThenGetImageData() { | 9 function drawThenGetImageData() { |
| 10 var canvas = document.createElement('canvas'); | 10 var canvas = document.createElement('canvas'); |
| 11 canvas.width = 10; | 11 canvas.width = 10; |
| 12 canvas.height = 10; | 12 canvas.height = 10; |
| 13 var ctx = canvas.getContext('2d', {colorSpace: 'p3'}) | 13 var ctx = canvas.getContext('2d', {colorSpace: 'p3'}) |
| 14 ctx.fillStyle = 'rgb(50, 100, 150)'; | 14 ctx.fillStyle = 'rgb(50, 100, 150)'; |
| 15 ctx.fillRect(0, 0, 10, 10); | 15 ctx.fillRect(0, 0, 10, 10); |
| 16 var pixel = ctx.getImageData(5, 5, 1, 1).data; | 16 var pixel = ctx.getImageData(5, 5, 1, 1).data; |
| 17 // Note: the color specified as as fillStyle is converted from srgb to linear | 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 | 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 co
lor that was drawn." ); | 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 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 the
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 the
color that was drawn." ); | 22 assert_equals(pixel[3], 255, "Alpha component retrieved by getImageData is t
he color that was drawn." ); |
| 23 } | 23 } |
| 24 | 24 |
| 25 function putThenGetImageData() { | 25 function putThenGetImageData() { |
| 26 var canvas = document.createElement('canvas'); | 26 var canvas = document.createElement('canvas'); |
| 27 canvas.width = 10; | 27 canvas.width = 10; |
| 28 canvas.height = 10; | 28 canvas.height = 10; |
| 29 var ctx = canvas.getContext('2d', {colorSpace: 'p3'}) | 29 var ctx = canvas.getContext('2d', {colorSpace: 'p3'}) |
| 30 var initialData = ctx.createImageData(1, 1); | 30 var initialData = ctx.createImageData(1, 1); |
| 31 initialData.data[0] = 50; | 31 initialData.data[0] = 50; |
| 32 initialData.data[1] = 100; | 32 initialData.data[1] = 100; |
| 33 initialData.data[2] = 150; | 33 initialData.data[2] = 150; |
| 34 initialData.data[3] = 255; | 34 initialData.data[3] = 255; |
| 35 ctx.putImageData(initialData, 5, 5); | 35 ctx.putImageData(initialData, 5, 5); |
| 36 var pixel = ctx.getImageData(5, 5, 1, 1).data; | 36 var pixel = ctx.getImageData(5, 5, 1, 1).data; |
| 37 assert_equals(pixel[0], 50, "Red component retrieved by getImageData is the co
lor that was put." ); | 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 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 the
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 the
color that was put." ); | 40 assert_equals(pixel[3], 255, "Alpha component retrieved by getImageData is t
he color that was put." ); |
| 41 } | 41 } |
| 42 | |
| 43 </script> | 42 </script> |
| 44 </body> | 43 </body> |
| OLD | NEW |