Bug 1826805 [wpt PR 39409] - Fix quote style in generated WPT filter tests., a=testonly
[gecko.git] / testing / web-platform / tests / html / canvas / offscreen / filters / 2d.filter.canvasFilterObject.componentTransfer.gamma.tentative.worker.js
bloba36fa19a5efad6948108a3cfd7c337daca1f5f76
1 // DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py.
2 // OffscreenCanvas test in a worker:2d.filter.canvasFilterObject.componentTransfer.gamma.tentative
3 // Description:Test pixels on CanvasFilter() componentTransfer with gamma type
4 // Note:
6 importScripts("/resources/testharness.js");
7 importScripts("/html/canvas/resources/canvas-tests.js");
9 var t = async_test("Test pixels on CanvasFilter() componentTransfer with gamma type");
10 var t_pass = t.done.bind(t);
11 var t_fail = t.step_func(function(reason) {
12     throw reason;
13 });
14 t.step(function() {
16 var canvas = new OffscreenCanvas(100, 50);
17 var ctx = canvas.getContext('2d');
19 // From https://www.w3.org/TR/SVG11/filters.html#feComponentTransferElement
20 function getColor(inputColor, amplitude, exponent, offset) {
21     return [
22         Math.max(0, Math.min(1, Math.pow(inputColor[0]/255, exponent[0]) * amplitude[0] + offset[0])) * 255,
23         Math.max(0, Math.min(1, Math.pow(inputColor[1]/255, exponent[1]) * amplitude[1] + offset[1])) * 255,
24         Math.max(0, Math.min(1, Math.pow(inputColor[2]/255, exponent[2]) * amplitude[2] + offset[2])) * 255,
25     ];
28 const amplitudes = [2, 1.1, 0.5];
29 const exponents = [5, 3, 1];
30 const offsets = [0.25, 0, 0.5];
31 ctx.filter = new CanvasFilter({filter: 'componentTransfer',
32     funcR: {type: 'gamma', amplitude: amplitudes[0], exponent: exponents[0], offset: offsets[0]},
33     funcG: {type: 'gamma', amplitude: amplitudes[1], exponent: exponents[1], offset: offsets[1]},
34     funcB: {type: 'gamma', amplitude: amplitudes[2], exponent: exponents[2], offset: offsets[2]},
35 });
37 const inputColors = [
38     [255, 255, 255],
39     [0, 0, 0],
40     [127, 0, 34],
41     [252, 186, 3],
42     [50, 68, 87],
45 for (const color of inputColors) {
46     let outputColor = getColor(color, amplitudes, exponents, offsets);
47     ctx.fillStyle = `rgb(${color[0]}, ${color[1]}, ${color[2]})`;
48     ctx.fillRect(0, 0, 10, 10);
49     _assertPixelApprox(canvas, 5, 5, outputColor[0],outputColor[1],outputColor[2],255, 2);
51 t.done();
53 });
54 done();