cicp-chunk.html (1582B)
1 <!DOCTYPE html> 2 <title>PNG test: cICP chunk</title> 3 <link rel="help" href="https://w3c.github.io/PNG-spec/#cICP-chunk"> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="/html/canvas/resources/canvas-tests.js"></script> 7 <body> 8 9 <h1>cICP chunk</h1> 10 <p class="desc">test pixel values of a display-p3 PNG</p> 11 12 <p class="output">Actual output:</p> 13 <canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> 14 15 <ul id="d"></ul> 16 <script> 17 var t = async_test("test pixel values of a display-p3 PNG"); 18 const img = new Image(); 19 img.onload = () => { 20 _addTest(function(canvas, ctx) { 21 ctx.drawImage(img, 0, 0); 22 23 var pixel = ctx.getImageData(5, 5, 1, 1, {colorSpace: "srgb"}).data; 24 25 // The pixel values stored are (51 red, 102 green, 153 blue). 26 // These numbers are chosen because 0.2 * 255 = 51. 27 // The image has a cICP chunk indicating the Display P3 color space. 28 // This results in decoded pixel values of (27 red, 104 green, 157 blue). 29 const pixel_expected = [27, 104, 157, 255]; 30 const epsilon = 2; 31 32 _assertSame(pixel.length, pixel_expected.length, "pixel.length", "pixel_expected.length"); 33 assert_approx_equals(pixel[0], pixel_expected[0], epsilon); 34 assert_approx_equals(pixel[1], pixel_expected[1], epsilon); 35 assert_approx_equals(pixel[2], pixel_expected[2], epsilon); 36 assert_approx_equals(pixel[3], pixel_expected[3], epsilon); 37 }, {colorSpace: "display-p3"}); 38 }; 39 img.src = "support/cicp-display-p3.png"; 40 </script>