blob: 0d9ed532b3c364c800ed9556dd3ef36184ef721f [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 p3TransparentRed = [0.270508, 0.019608, 0.015686, 0.501953];
var p3TransparentGreen = [0.066650, 0.317627, 0.035278, 0.501953];
var p3TransparentBlue = [0.011765, 0.011765, 0.297852, 0.501953];
var p3TransparentBlack = [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 drawSRGBImageOnP3Canvas(source)
{
var canvas = document.createElement('canvas');
canvas.width = 20;
canvas.height = 20;
var ctx = canvas.getContext('2d',
{colorSpace: 'p3', pixelFormat:'float16'});
ctx.drawImage(source, 0, 0);
var tests = [{x: 5, y: 5, color: p3TransparentRed},
{x: 15, y: 5, color: p3TransparentGreen},
{x: 5, y: 15, color: p3TransparentBlue},
{x: 15, y: 15, color: p3TransparentBlack}];
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(drawSRGBImageOnP3Canvas);
}, 'Draw SRGB image on a P3 canvas and read back the P3 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 P3 canvas.
</script>