summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/resize-observer/create-pattern-data-url.js
blob: d3634dc424b96c619da5e9dfea865288ae4135fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const patternSize = 4;

export default function createPatternDataURL() {
  const ctx = document.createElement('canvas').getContext('2d');
  ctx.canvas.width = patternSize;
  ctx.canvas.height = patternSize;

  const b = [0, 0, 0, 255];
  const t = [0, 0, 0, 0];
  const r = [255, 0, 0, 255];
  const g = [0, 255, 0, 255];

  const imageData = new ImageData(patternSize, patternSize);
  imageData.data.set([
    b, t, t, r,
    t, b, g, t,
    t, r, b, t,
    g, t, t, b,
  ].flat());
  ctx.putImageData(imageData, 0, 0);
  return {patternSize, dataURL: ctx.canvas.toDataURL()};
}