Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /html/canvas/element/color-type/2d.color.type.u8srgb.to.f16p3.to.u8srgb.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<meta charset="UTF-8">
<title>Canvas test: 2d.color.type.u8srgb.to.f16p3.to.u8srgb</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/html/canvas/resources/canvas-tests.js"></script>
<link rel="stylesheet" href="/html/canvas/resources/canvas-tests.css">
<body class="show_output">
<h1>2d.color.type.u8srgb.to.f16p3.to.u8srgb</h1>
<p class="desc">test display-p3 float16 canvas storing 8-bit srgb data accurately</p>
<p class="output">Actual output:</p>
<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
<ul id="d"></ul>
<script>
var t = async_test("test display-p3 float16 canvas storing 8-bit srgb data accurately");
_addTest(function(canvas, ctx) {
// Consider the color in sRGB:
// (5,250,128)/255
// In Display P3 this is:
// (0.450400386839, 0.9659537931, 0.55239459823)
// Quantized to float16, that should evaluate to:
// (0x3735, 0x3BBA, 0x386B)
// (0.450439453125, 0.9658203125, 0.55224609375)
// Converted back to sRGB this is:
// (5.342920953809, 249.965067892273, 127.959124250169)/255
// Quantized to 8-bit, this is:
// (5, 250, 128)
var input = new ImageData(new Uint8ClampedArray([5, 250, 128, 255]),
1, 1, {colorSpace: "srgb"});
ctx.putImageData(input, 0, 0);
var readback = ctx.getImageData(0, 0, 1, 1, {colorSpace:"srgb"});
const kEpsilon = 2;
assert_approx_equals(readback.data[0], 5, kEpsilon);
assert_approx_equals(readback.data[1], 250, kEpsilon);
assert_approx_equals(readback.data[2], 128, kEpsilon);
}, {colorType: "float16", colorSpace: "display-p3"});
</script>