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