2011-02-04 Hironori Bono <hbono@chromium.org>
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 5 Feb 2011 03:05:47 +0000 (03:05 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 5 Feb 2011 03:05:47 +0000 (03:05 +0000)
        Reviewed by Adam Barth.

        [chromium] JPEG corruption
        https://bugs.webkit.org/show_bug.cgi?id=53250

        This change adds a new script test that we can render a CMYK JPEG with a
        color profile correctly, i.e. we can render it without color corruption.

        * fast/images/cmyk-jpeg-with-color-profile-expected.txt: Added.
        * fast/images/cmyk-jpeg-with-color-profile.html: Added.
        * fast/images/resources/cmyk-jpeg.jpg: Added.
        * fast/images/script-tests/cmyk-jpeg-with-color-profile.js: Added.
        (image.onload):
2011-02-04  Hironori Bono  <hbono@chromium.org>

        Reviewed by Adam Barth.

        [chromium] JPEG corruption
        https://bugs.webkit.org/show_bug.cgi?id=53250

        Same as gray-scale JPEGs, we convert the colors of CMYK JPEGs with color
        profiles from CMYK to RGB twice and it causes color corruption. This
        change suppresses the color profiles for CMYK JPEGs same as gray-scale
        ones.

        Test: fast/images/cmyk-jpeg-with-color-profile.html

        * platform/image-decoders/jpeg/JPEGImageDecoder.cpp:
        (WebCore::JPEGImageReader::decode):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@77724 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/images/cmyk-jpeg-with-color-profile-expected.txt [new file with mode: 0644]
LayoutTests/fast/images/cmyk-jpeg-with-color-profile.html [new file with mode: 0644]
LayoutTests/fast/images/resources/cmyk-jpeg.jpg [new file with mode: 0755]
LayoutTests/fast/images/script-tests/cmyk-jpeg-with-color-profile.js [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.cpp

index 3e2b632365df1553f42d838f3b6686f60f685afc..fd6223c3600c7bfdda3a508a788c508981d77d57 100644 (file)
@@ -1,3 +1,19 @@
+2011-02-04  Hironori Bono  <hbono@chromium.org>
+
+        Reviewed by Adam Barth.
+
+        [chromium] JPEG corruption
+        https://bugs.webkit.org/show_bug.cgi?id=53250
+
+        This change adds a new script test that we can render a CMYK JPEG with a
+        color profile correctly, i.e. we can render it without color corruption.
+
+        * fast/images/cmyk-jpeg-with-color-profile-expected.txt: Added.
+        * fast/images/cmyk-jpeg-with-color-profile.html: Added.
+        * fast/images/resources/cmyk-jpeg.jpg: Added.
+        * fast/images/script-tests/cmyk-jpeg-with-color-profile.js: Added.
+        (image.onload):
+
 2011-02-04  Martin Robinson  <mrobinson@igalia.com>
 
         Update pixel results for the fast/forms directory in preparation for landing
diff --git a/LayoutTests/fast/images/cmyk-jpeg-with-color-profile-expected.txt b/LayoutTests/fast/images/cmyk-jpeg-with-color-profile-expected.txt
new file mode 100644 (file)
index 0000000..d1b63e5
--- /dev/null
@@ -0,0 +1,11 @@
+Test that we can render a CMYK JPEG without color corruption.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS green > red is true
+PASS green > blue is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/images/cmyk-jpeg-with-color-profile.html b/LayoutTests/fast/images/cmyk-jpeg-with-color-profile.html
new file mode 100644 (file)
index 0000000..c2c7044
--- /dev/null
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../js/resources/js-test-style.css">
+<script src="../js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="script-tests/cmyk-jpeg-with-color-profile.js"></script>
+<script src="../js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/images/resources/cmyk-jpeg.jpg b/LayoutTests/fast/images/resources/cmyk-jpeg.jpg
new file mode 100755 (executable)
index 0000000..430f5c5
Binary files /dev/null and b/LayoutTests/fast/images/resources/cmyk-jpeg.jpg differ
diff --git a/LayoutTests/fast/images/script-tests/cmyk-jpeg-with-color-profile.js b/LayoutTests/fast/images/script-tests/cmyk-jpeg-with-color-profile.js
new file mode 100644 (file)
index 0000000..75117d8
--- /dev/null
@@ -0,0 +1,48 @@
+description("Test that we can render a CMYK JPEG without color corruption.");
+
+// This is an async test because it has to wait for WebKit to load an image.
+jsTestIsAsync = true;
+
+// The colors used for verifying the test results.
+var red = 0, green = 0, blue = 0, alpha = 0;
+
+// Create a canvas element. This element is used for pasting a CMYK JPEG and
+// reading its pixels.
+var canvas = document.createElement("canvas");
+canvas.width = 64;
+canvas.height = 64;
+
+// Create an image object and load a CMYK JPEG.
+var image = new Image();
+image.onload = function() {
+    // Paste the loaded JPEG ('resources/cmyk-jpeg.jpg') to the canvas.
+    var context = canvas.getContext("2d");
+    context.drawImage(image, 0, 0);
+
+    // Read the pixels in the canvas and calculate their avarage values.
+    // (DumpRenderTree always allows to read them.)
+    var data = context.getImageData(0, 0, canvas.width, canvas.height);
+    var pixels = canvas.width * canvas.height;
+    for (var i = 0; i < pixels * 4; i += 4) {
+        red += data.data[i + 0];
+        green += data.data[i + 1];
+        blue += data.data[i + 2];
+        alpha += data.data[i + 3];
+    }
+    red   /= pixels;
+    green /= pixels;
+    blue  /= pixels;
+    alpha /= pixels;
+
+    // Even though the output colors depend on color-profiles (i.e. they depend
+    // on devices), green must be the most prominent color because the source
+    // image only consists of green. So, we test it.
+    shouldBeTrue("green > red");
+    shouldBeTrue("green > blue");
+
+    // Notify this test has been finished.
+    finishJSTest();
+}
+image.src = "resources/cmyk-jpeg.jpg";
+
+var successfullyParsed = true;
index 4ab54d012f1c560e2bf4709ef19466b738039a9b..fac585bf178908b3e8d54e12b1be43323cb7d9f6 100644 (file)
@@ -1,3 +1,20 @@
+2011-02-04  Hironori Bono  <hbono@chromium.org>
+
+        Reviewed by Adam Barth.
+
+        [chromium] JPEG corruption
+        https://bugs.webkit.org/show_bug.cgi?id=53250
+
+        Same as gray-scale JPEGs, we convert the colors of CMYK JPEGs with color
+        profiles from CMYK to RGB twice and it causes color corruption. This
+        change suppresses the color profiles for CMYK JPEGs same as gray-scale
+        ones.
+
+        Test: fast/images/cmyk-jpeg-with-color-profile.html
+
+        * platform/image-decoders/jpeg/JPEGImageDecoder.cpp:
+        (WebCore::JPEGImageReader::decode):
+
 2011-02-04  Xiyuan Xia  <xiyuan@chromium.org>
 
         Reviewed by Tony Chang.
index e88ff1d2193b56a1999d16bf3f502f1cd140c3c6..1434c65d2ab2785ecf4bbbf6e5e4789bece8a9b1 100644 (file)
@@ -222,6 +222,12 @@ public:
                 // jpeglib cannot convert these to rgb, but it can convert ycck
                 // to cmyk.
                 m_info.out_color_space = JCS_CMYK;
+
+                // Same as with grayscale images, we convert CMYK images to RGBA
+                // ones. When we keep the color profiles of these CMYK images,
+                // CoreGraphics will convert their colors again. So, we discard
+                // their color profiles to prevent color corruption.
+                m_decoder->setIgnoreGammaAndColorProfile(true);
                 break;
             default:
                 return m_decoder->setFailed();