Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / images / rgb-jpeg-endian-pixels.html
bloba56a5b3eb269f751d38dc93251710762d50976ee
1 <!DOCTYPE html>
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>
11 <script>
12 if (window.testRunner) {
13 window.testRunner.waitUntilDone();
14 window.testRunner.dumpAsText();
17 function log(message)
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) {
26 r += data[i + 0];
27 g += data[i + 1];
28 b += data[i + 2];
29 a += data[i + 3];
32 return [r / size, g / size, b / size, a / size];
35 function averagePixelShouldBe(pixel, expect, tolerance)
37 var delta = 0;
38 pixel.forEach(function(component, i) {
39 delta = Math.max(Math.abs(pixel[i] - expect[i]), delta);
40 });
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)
64 try {
65 loadedImages = window.loadedImages || 0;
66 testImage(image, expect);
67 if (++loadedImages < 3)
68 return;
69 } catch (e) {
70 log('FAIL: ' + e.message);
73 if (window.testRunner)
74 window.testRunner.notifyDone();
76 </script>