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
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) {
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) {
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,
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]},
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);