OLD | NEW |
---|---|
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | 1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
2 <html> | 2 <title>Test that we can render a CMYK JPEG without color corruption.</title> |
3 <head> | 3 <script src="../../resources/testharness.js"></script> |
4 <script src="../../resources/js-test.js"></script> | 4 <script src="../../resources/testharnessreport.js"></script> |
5 </head> | 5 <script type="text/javascript"> |
6 <body> | 6 async_test(function(t) { |
7 <script src="script-tests/cmyk-jpeg-with-color-profile.js"></script> | 7 // The colors used for verifying the test results. |
8 </body> | 8 var red = 0, green = 0, blue = 0, alpha = 0; |
9 </html> | 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 // Create an image object and load a CMYK JPEG. | |
15 var image = new Image(); | |
16 image.onload = t.step_func_done(function() { | |
17 // Paste the loaded JPEG ('resources/cmyk-jpeg.jpg') to the canvas. | |
18 var context = canvas.getContext("2d"); | |
19 context.drawImage(image, 0, 0); | |
20 | |
21 // Read the pixels in the canvas and calculate their avarage values. | |
fs
2016/08/10 17:46:07
Nit: s/avarage/average/
sivag
2016/08/15 16:45:55
Done.
| |
22 // (DumpRenderTree always allows to read them.) | |
23 var data = context.getImageData(0, 0, canvas.width, canvas.height); | |
fs
2016/08/10 17:46:07
Optional: Maybe do getImageData(...).data directly
sivag
2016/08/15 16:45:54
I left it unchanged.
| |
24 var pixels = canvas.width * canvas.height; | |
25 for (var i = 0; i < pixels * 4; i += 4) { | |
26 red += data.data[i + 0]; | |
27 green += data.data[i + 1]; | |
28 blue += data.data[i + 2]; | |
29 alpha += data.data[i + 3]; | |
30 } | |
31 red /= pixels; | |
32 green /= pixels; | |
33 blue /= pixels; | |
34 alpha /= pixels; | |
35 | |
36 // Even though the output colors depend on color-profiles (i.e. they dep end | |
37 // on devices), green must be the most prominent color because the sourc e | |
38 // image only consists of green. So, we test it. | |
39 assert_greater_than(green, red); | |
40 assert_greater_than(green, blue); | |
41 | |
fs
2016/08/10 17:46:07
Nit: Drop blank line.
sivag
2016/08/15 16:45:54
Done.
| |
42 }); | |
43 image.src = "resources/cmyk-jpeg.jpg"; | |
44 }); | |
45 </script> | |
46 | |
fs
2016/08/10 17:46:07
Ditto.
sivag
2016/08/15 16:45:55
Done.
| |
OLD | NEW |