5 canvas { padding:
3px; padding-bottom:
0px;}
11 if (window
.testRunner
) {
12 window
.testRunner
.dumpAsTextWithPixelResults();
13 window
.testRunner
.waitUntilDone();
17 function logMessage(message
)
19 document
.getElementById('log').textContent
+= '\n' + message
;
22 function logPixel(canvasContext
, x
, y
)
24 var p
= canvasContext
.getImageData(x
, y
, 1, 1).data
;
25 logMessage('rgba(' + [p
[0], p
[1], p
[2], p
[3]] + ')');
28 function appendNewCanvasElementTo(parentId
, canvasId
)
30 var canvas
= document
.createElement('canvas');
31 canvas
.width
= canvas
.height
= 64;
32 document
.getElementById(parentId
).appendChild(canvas
);
37 function canvasTest(item
, mimeType
)
39 var previousCanvas
= document
.getElementById('c' + (item
- 1));
41 var img
= new Image();
42 img
.onload = function() {
43 var canvas
= appendNewCanvasElementTo('list', 'c' + item
);
44 var context
= canvas
.getContext('2d');
45 context
.drawImage(this, 0, 0);
46 if (!window
.testRunner
)
47 logPixel(context
, 25, 25);
52 img
.src
= previousCanvas
.toDataURL(mimeType
);
57 var list
= document
.getElementById('list');
58 var log
= document
.getElementById('log');
59 list
.innerHTML
= log
.innerHTML
= '';
61 var select
= document
.getElementById('alpha');
62 var alpha
= Number(select
.value
).toFixed(3);
63 select
.onchange = function() { load(); };
65 var canvas
= appendNewCanvasElementTo('list', 'c0');
66 var context
= canvas
.getContext('2d');
67 context
.fillStyle
= 'rgba(0, 64, 0, ' + alpha
+ ')';
68 context
.fillRect(0, 0, 64, 64);
69 canvas
.style
.display
= 'none';
71 if (window
.testRunner
) {
72 document
.getElementById('instructions').style
.display
= 'none';
74 logMessage('alpha ' + alpha
);
84 if (autoTest
&& nextItem
> 70) {
85 if (window
.testRunner
)
86 window
.testRunner
.notifyDone();
90 canvasTest(nextItem
, 'image/png');
96 <body onload='load()'
>
98 Back-to-back canvas alpha image/png encode decode
<button onclick='test()'
>Test
</button> alpha
99 <input id='alpha' type='text' value='
0.5'
>