2 JPEG image RGB pixels should render without color corruption and in strict
<br>
3 order, regardless of the underlying machine pixel buffer endianess.
<br><br>
5 <img src=
"resources/rgb-jpeg-red.jpg" onload=
"test(this, [255,0,0,255])">
6 <img src=
"resources/rgb-jpeg-green.jpg" onload=
"test(this, [0,255,0,255])">
7 <img src=
"resources/rgb-jpeg-blue.jpg" onload=
"test(this, [0,0,255,255])">
9 <pre id=
"log">PASS
</pre>
12 if (window
.testRunner
) {
13 window
.testRunner
.waitUntilDone();
14 window
.testRunner
.dumpAsText();
19 document
.getElementById("log").textContent
+= '\n' + message
;
22 function averagePixelComponents(data
, size
)
24 var r
= 0, g
= 0, b
= 0, a
= 0;
25 for (var i
= 0, total
= size
* 4; i
< total
; i
+= 4) {
32 return [r
/ size
, g
/ size
, b
/ size
, a
/ size
];
35 function averagePixelShouldBe(pixel
, expect
, tolerance
)
38 pixel
.forEach(function(component
, i
) {
39 delta
= Math
.max(Math
.abs(pixel
[i
] - expect
[i
]), delta
);
42 if (delta
> tolerance
)
43 log('FAIL: [' + pixel
+ '] expected [' + expect
+ '] +/- ' + tolerance
);
46 function testImage(image
, expect
)
48 // Create a canvas, load the given image in it.
49 var canvas
= document
.createElement("canvas");
50 canvas
.width
= canvas
.height
= 64;
51 var context
= canvas
.getContext("2d");
52 context
.drawImage(image
, 0, 0);
54 // Compare the canvas pixel component averages.
55 var pixels
= context
.getImageData(0, 0, 64, 64).data
;
56 var result
= averagePixelComponents(pixels
, 64 * 64);
58 var pixelTolerance
= 3;
59 averagePixelShouldBe(result
, expect
, pixelTolerance
);
62 function test(image
, expect
)
65 loadedImages
= window
.loadedImages
|| 0;
66 testImage(image
, expect
);
67 if (++loadedImages
< 3)
70 log('FAIL: ' + e
.message
);
73 if (window
.testRunner
)
74 window
.testRunner
.notifyDone();