2 <title>putImageData(getImageData) pair test
</title>
3 <body class=
"show_output">
4 <h3>Test that putImageData(getImageData) pair leaves canvas ImageData the same.
</h3>
5 <canvas id=
"c" class=
"output" width=
"64" height=
"64"><p class=
"fallback">FAIL (fallback content)
</p></canvas>
7 Result:
<a id=
"result"></a>
10 testRunner
.dumpAsText();
12 var canvas
= document
.getElementById("c");
13 var ctx
= canvas
.getContext("2d");
14 var passed
= getPutImageData(50, ctx
, 0, 0, 0, 0.0);
15 passed
|= getPutImageData(50, ctx
, 0, 0, 0, 0.5);
16 passed
|= getPutImageData(50, ctx
, 0, 0, 0, 1.0);
17 passed
|= getPutImageData(50, ctx
, 127, 128, 129, 0.49);
18 passed
|= getPutImageData(50, ctx
, 127, 128, 129, 0.51);
19 passed
|= getPutImageData(50, ctx
, 127, 128, 129, 0.5);
20 passed
|= getPutImageData(50, ctx
, 128, 128, 128, 0.0);
21 passed
|= getPutImageData(50, ctx
, 128, 128, 128, 0.5);
22 passed
|= getPutImageData(50, ctx
, 128, 128, 128, 1.0);
24 var result_a
= document
.getElementById("result");
26 result_a
.innerHTML
= "FAIL";
28 result_a
.innerHTML
= "PASS";
30 function getPutImageData(numIters
, ctx
, r
, g
, b
, a
) {
31 var x
= 0, y
= 0, w
= ctx
.canvas
.width
, h
= ctx
.canvas
.height
;
33 // Paint the canvas green to start
34 ctx
.fillStyle
= color
;
35 ctx
.fillRect(x
,y
,w
,h
);
37 // Now paint the canvas a random hue of gray
38 var color
= 'rgba(' + r
+ ',' + g
+ ',' + b
+ ',' + a
+ ')';
39 ctx
.fillStyle
= color
;
40 ctx
.fillRect(x
,y
,w
,h
);
42 // Get the current "original" image data
43 var origImageData
= ctx
.getImageData(x
, y
, w
, h
);
44 ctx
.putImageData(origImageData
, x
, y
);
46 // Get and put the image data 'numIters' times
47 for(var i
= 0; i
< numIters
; i
++)
48 ctx
.putImageData(ctx
.getImageData(x
,y
,w
,h
), x
,y
);
50 // Grab new current image data
51 var currImageData
= ctx
.getImageData(x
, y
, w
, h
);
53 // Verify that original and new current image datas are equal
54 for(var i
= 0; i
< currImageData
.data
.length
; i
++) {
55 var origSubpixel
= origImageData
.data
[i
];
56 var currSubpixel
= currImageData
.data
[i
];
58 // If even 1 subpixel is off, return failure
59 if (origSubpixel
!= currSubpixel
)