blob: 05c9338c306f5b2774d889f9eb62865e8f9d91e2 [file] [log] [blame]
<!DOCTYPE HTML>
<script src="../../../../../resources/testharness.js"></script>
<script src="../../../../../resources/testharnessreport.js"></script>
<script>
// The reference values are generated by calling SkImage::makeColorSpace()
// in a Skia fiddle. SkColorSpaceXform() may generate different results.
// Please see: https://fiddle.skia.org/c/94578944d9d52c2b4c2cadda88a4e204
var rec2020TransparentRed = [ 0.207764, 0.031372, 0.015686, 0.501953 ];
var rec2020TransparentGreen = [ 0.113708, 0.301758, 0.039215, 0.501953 ];
var rec2020TransparentBlue = [ 0.023529, 0.015686, 0.293945, 0.501953 ];
var rec2020TransparentBlack = [ 0.011765, 0.011765, 0.011765, 0.501953 ];
function testPixels(ctx, tests)
{
var actual, expected, tolerance = 0.005;
console.log(tests.length);
for (var i = 0; i < tests.length; i++) {
actual = ctx.getImageData(tests[i].x, tests[i].y, 1, 1).dataUnion;
expected = tests[i].color;
assert_true(actual.length === expected.length);
for (var j = 0; j < actual.length; j++)
assert_approx_equals(actual[j], expected[j], tolerance);
}
}
function drawSRGBImageOnRec2020Canvas(source)
{
var canvas = document.createElement('canvas');
canvas.width = 20;
canvas.height = 20;
var ctx = canvas.getContext('2d',
{colorSpace: 'rec2020', pixelFormat:'float16'});
ctx.drawImage(source, 0, 0);
var tests = [{x: 5, y: 5, color: rec2020TransparentRed},
{x: 15, y: 5, color: rec2020TransparentGreen},
{x: 5, y: 15, color: rec2020TransparentBlue},
{x: 15, y: 15, color: rec2020TransparentBlack}];
testPixels(ctx, tests);
}
promise_test(function() {
return new Promise((resolve, reject) => {
var image = new Image();
image.onload = function() {
resolve(image);
}
image.src = 'resources/pattern-semitransparent-srgb.png'
}).then(drawSRGBImageOnRec2020Canvas);
}, 'Draw SRGB image on a Rec2020 canvas and read back the Rec2020 pixels.');
// TODO(zakerinasab): crbug.com/713867
// Add at least two more tests to load pattern-semitransparent-p3d65.png and
// pattern-semitransparent-rec2020.png and draw them on a Rec2020 canvas.
</script>