2 <!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
3 <title>OffscreenCanvas test:
2d.filter.canvasFilterObject.componentTransfer.gamma.tentative
</title>
4 <script src=
"/resources/testharness.js"></script>
5 <script src=
"/resources/testharnessreport.js"></script>
6 <script src=
"/html/canvas/resources/canvas-tests.js"></script>
8 <h1>2d.filter.canvasFilterObject.componentTransfer.gamma.tentative
</h1>
9 <p class=
"desc">Test pixels on CanvasFilter() componentTransfer with gamma type
</p>
13 var t
= async_test("Test pixels on CanvasFilter() componentTransfer with gamma type");
14 var t_pass
= t
.done
.bind(t
);
15 var t_fail
= t
.step_func(function(reason
) {
18 t
.step(async
function() {
20 var canvas
= new OffscreenCanvas(100, 50);
21 var ctx
= canvas
.getContext('2d');
23 await (function(canvas
, ctx
) {
24 // From https://www.w3.org/TR/SVG11/filters.html#feComponentTransferElement
25 function getColor(inputColor
, amplitude
, exponent
, offset
) {
27 Math
.max(0, Math
.min(1, Math
.pow(inputColor
[0]/255, exponent
[0]) * amplitude
[0] + offset
[0])) * 255,
28 Math
.max(0, Math
.min(1, Math
.pow(inputColor
[1]/255, exponent
[1]) * amplitude
[1] + offset
[1])) * 255,
29 Math
.max(0, Math
.min(1, Math
.pow(inputColor
[2]/255, exponent
[2]) * amplitude
[2] + offset
[2])) * 255,
33 const amplitudes
= [2, 1.1, 0.5];
34 const exponents
= [5, 3, 1];
35 const offsets
= [0.25, 0, 0.5];
36 ctx
.filter
= new CanvasFilter({filter
: 'componentTransfer',
37 funcR
: {type
: 'gamma', amplitude
: amplitudes
[0], exponent
: exponents
[0], offset
: offsets
[0]},
38 funcG
: {type
: 'gamma', amplitude
: amplitudes
[1], exponent
: exponents
[1], offset
: offsets
[1]},
39 funcB
: {type
: 'gamma', amplitude
: amplitudes
[2], exponent
: exponents
[2], offset
: offsets
[2]},
50 for (const color
of inputColors
) {
51 let outputColor
= getColor(color
, amplitudes
, exponents
, offsets
);
52 ctx
.fillStyle
= `rgb(${color[0]}, ${color[1]}, ${color[2]})`;
53 ctx
.fillRect(0, 0, 10, 10);
54 _assertPixelApprox(canvas
, 5, 5, outputColor
[0],outputColor
[1],outputColor
[2],255, 2);