OLD | NEW |
| (Empty) |
1 description("Test that we can render a CMYK JPEG without color corruption."); | |
2 | |
3 // This is an async test because it has to wait for WebKit to load an image. | |
4 jsTestIsAsync = true; | |
5 | |
6 // The colors used for verifying the test results. | |
7 var red = 0, green = 0, blue = 0, alpha = 0; | |
8 | |
9 // Create a canvas element. This element is used for pasting a CMYK JPEG and | |
10 // reading its pixels. | |
11 var canvas = document.createElement("canvas"); | |
12 canvas.width = 64; | |
13 canvas.height = 64; | |
14 | |
15 // Create an image object and load a CMYK JPEG. | |
16 var image = new Image(); | |
17 image.onload = function() { | |
18 // Paste the loaded JPEG ('resources/cmyk-jpeg.jpg') to the canvas. | |
19 var context = canvas.getContext("2d"); | |
20 context.drawImage(image, 0, 0); | |
21 | |
22 // Read the pixels in the canvas and calculate their avarage values. | |
23 // (DumpRenderTree always allows to read them.) | |
24 var data = context.getImageData(0, 0, canvas.width, canvas.height); | |
25 var pixels = canvas.width * canvas.height; | |
26 for (var i = 0; i < pixels * 4; i += 4) { | |
27 red += data.data[i + 0]; | |
28 green += data.data[i + 1]; | |
29 blue += data.data[i + 2]; | |
30 alpha += data.data[i + 3]; | |
31 } | |
32 red /= pixels; | |
33 green /= pixels; | |
34 blue /= pixels; | |
35 alpha /= pixels; | |
36 | |
37 // Even though the output colors depend on color-profiles (i.e. they depend | |
38 // on devices), green must be the most prominent color because the source | |
39 // image only consists of green. So, we test it. | |
40 shouldBeTrue("green > red"); | |
41 shouldBeTrue("green > blue"); | |
42 | |
43 // Notify this test has been finished. | |
44 finishJSTest(); | |
45 } | |
46 image.src = "resources/cmyk-jpeg.jpg"; | |
OLD | NEW |