summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/canvas/element/wide-gamut-canvas/2d.color.space.p3.toBlob.p3.canvas.html
blob: 1a44af20a6381a9dd9270323323a8e0774a2fa2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<title>Canvas test: 2d.color.space.p3.toBlob.p3.canvas</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.space.p3.toBlob.p3.canvas</h1>
<p class="desc">test if toblob returns p3 data from p3 color space canvas</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 if toblob returns p3 data from p3 color space canvas");
_addTest(function(canvas, ctx) {

  ctx.fillStyle = "rgba(155, 27, 27, 1)";
  ctx.fillRect(0, 0, 1, 1);
  ctx.fillStyle = "rgba(27, 155, 27, 0)";
  ctx.fillRect(1, 0, 1, 1);
  ctx.fillStyle = "rgba(27, 27, 155, 0.5)";
  ctx.fillRect(0, 1, 1, 1);
  ctx.fillStyle = "rgba(27, 27, 27, 0.5)";
  ctx.fillRect(1, 1, 1, 1);
  expectedPixels = ctx.getImageData(0, 0, 2, 2, {colorSpace: "display-p3"}).data;

  var image = new Image();
  image.onload = t.step_func_done(function() {
      var dstCanvas = document.createElement("canvas");
      dstCanvas.width = 2;
      dstCanvas.height = 2;
      var ctx = dstCanvas.getContext('2d', {colorSpace: "display-p3"});
      ctx.drawImage(image, 0, 0);
      var actualPixels = ctx.getImageData(0, 0, 2, 2, {colorSpace: "display-p3"}).data;
      assert_array_approx_equals(actualPixels, expectedPixels, 2);
  });

  canvas.toBlob(function(blob) {
      var urlCreator = window.URL || window.webkitURL;
      image.src = urlCreator.createObjectURL(blob);
  }, 'image/png', 1);

}, {colorSpace: "display-p3"});
</script>