<!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. Original colors are picked using gimp.
// Please see: https://fiddle.skia.org/c/7e2176335d016e42a84e44a9624ae0ac
var e_sRGB_TransparentRed = [0.886230, 0.121521, 0.121521, 0.501953];
var e_sRGB_TransparentGreen = [0.121521, 0.886230, 0.121521, 0.501953];
var e_sRGB_TransparentBlue = [0.121521, 0.121521, 0.886230, 0.501953];
var e_sRGB_TransparentBlack = [0.121521, 0.121521, 0.121521, 0.501953];
function testPixels(ctx, tests, imageSetting)
{
var actual, expected, tolerance = 0.01;
for (var i = 0; i < tests.length; i++) {
actual = ctx.getImageData(tests[i].x, tests[i].y, 1, 1, imageSetting).data;
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 drawSRGBImageOnLinearRGBCanvas(source)
{
var canvas = document.createElement('canvas');
canvas.width = 20;
canvas.height = 20;
var ctx = canvas.getContext('2d',
{colorSpace: 'srgb', pixelFormat:'float16'});
var imageSetting = {colorSpace: 'srgb', storageFormat:'float32'}
ctx.drawImage(source, 0, 0);
var tests = [{x: 5, y: 5, color: e_sRGB_TransparentRed},
{x: 15, y: 5, color: e_sRGB_TransparentGreen},
{x: 5, y: 15, color: e_sRGB_TransparentBlue},
{x: 15, y: 15, color: e_sRGB_TransparentBlack}];
testPixels(ctx, tests, imageSetting);
}
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(drawSRGBImageOnLinearRGBCanvas);
}, 'Draw SRGB image on an e-sRGB canvas and read back the e-sRGB pixels.');
</script>