[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

thakis at chromium.org thakis at chromium.org
Wed Dec 22 11:15:00 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 723e77e47fc9b1c60228767bcc0b7580d8552da1
Author: thakis at chromium.org <thakis at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Thu Jul 15 23:47:04 2010 +0000

    2010-07-15  Nico Weber  <thakis at chromium.org>
    
            Reviewed by Ojan Vafai.
    
            chromium/skia: Fix canvas.toDataURL in the presence of transparency
            https://bugs.webkit.org/show_bug.cgi?id=42214
    
            Test that toDataURL works with transparent images.
    
            * fast/canvas/toDataURL-alpha-expected.txt: Added.
            * fast/canvas/toDataURL-alpha.html: Added.
            * platform/chromium/test_expectations.txt:
            * platform/mac-leopard/fast/canvas/toDataURL-alpha-expected.checksum: Added.
            * platform/mac-leopard/fast/canvas/toDataURL-alpha-expected.png: Added.
    2010-07-15  Nico Weber  <thakis at chromium.org>
    
            Reviewed by Ojan Vafai.
    
            chromium/skia: Fix canvas.toDataURL in the presence of transparency
            https://bugs.webkit.org/show_bug.cgi?id=42214
    
            The problem was that SkBitmaps contain premultiplied data, but pnglib
            doesn't expect premultiplied data. Now, the encoder unpremultiplies
            data before sending it to pnglib.
    
            Patch partially by deanm.
    
            Covered by fast/canvas/toDataURL-alpha.html.
    
            * platform/image-encoders/skia/PNGImageEncoder.cpp:
            (WebCore::preMultipliedBGRAtoRGBA):
            (WebCore::encodeImpl):
            (WebCore::PNGImageEncoder::encode):
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@63494 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 9dd65c4..5aee44d 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,18 @@
+2010-07-15  Nico Weber  <thakis at chromium.org>
+
+        Reviewed by Ojan Vafai.
+
+        chromium/skia: Fix canvas.toDataURL in the presence of transparency
+        https://bugs.webkit.org/show_bug.cgi?id=42214
+
+        Test that toDataURL works with transparent images.
+
+        * fast/canvas/toDataURL-alpha-expected.txt: Added.
+        * fast/canvas/toDataURL-alpha.html: Added.
+        * platform/chromium/test_expectations.txt:
+        * platform/mac-leopard/fast/canvas/toDataURL-alpha-expected.checksum: Added.
+        * platform/mac-leopard/fast/canvas/toDataURL-alpha-expected.png: Added.
+
 2010-07-15  Ojan Vafai  <ojan at chromium.org>
 
         Unreviewed.
diff --git a/LayoutTests/fast/canvas/toDataURL-alpha-expected.txt b/LayoutTests/fast/canvas/toDataURL-alpha-expected.txt
new file mode 100644
index 0000000..5c4b0fa
--- /dev/null
+++ b/LayoutTests/fast/canvas/toDataURL-alpha-expected.txt
@@ -0,0 +1,12 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x262
+  RenderBlock {HTML} at (0,0) size 800x262
+    RenderBody {BODY} at (8,16) size 784x238
+      RenderBlock {P} at (0,0) size 784x18
+        RenderText {#text} at (0,0) size 356x18
+          text run at (0,0) width 356: "The test passes if both boxes below have the same color."
+      RenderBlock (anonymous) at (0,34) size 784x104
+        RenderHTMLCanvas {CANVAS} at (0,0) size 200x100
+        RenderText {#text} at (0,0) size 0x0
+      RenderBlock {DIV} at (0,138) size 200x100
diff --git a/LayoutTests/fast/canvas/toDataURL-alpha.html b/LayoutTests/fast/canvas/toDataURL-alpha.html
new file mode 100644
index 0000000..f44ce52
--- /dev/null
+++ b/LayoutTests/fast/canvas/toDataURL-alpha.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html> 
+<html xmlns="http://www.w3.org/1999/xhtml"> 
+<head> 
+<title>canvas toDataURL alpha png bug</title> 
+<script type="text/javascript"> 
+  function load() {
+      var context = document.getElementById("c").getContext("2d");
+      context.fillStyle = "rgba(200, 255, 200, 0.7)";
+      context.fillRect(0, 0, context.canvas.width, context.canvas.height);
+      document.getElementById("d").style.backgroundImage = ["url(", context.canvas.toDataURL("image/png"), ")"].join("");
+  }
+</script> 
+</head> 
+<body onload="load()"> 
+    <p>The test passes if both boxes below have the same color.</p>
+    <canvas id="c" width="200" height="100"></canvas>
+    <div id="d" style="width:200px;height:100px"></div>
+</body> 
+</html> 
diff --git a/LayoutTests/platform/chromium/test_expectations.txt b/LayoutTests/platform/chromium/test_expectations.txt
index 35d9ba9..eefca1e 100644
--- a/LayoutTests/platform/chromium/test_expectations.txt
+++ b/LayoutTests/platform/chromium/test_expectations.txt
@@ -2899,6 +2899,8 @@ BUG47826 MAC SKIP : fast/dom/HTMLMeterElement/meter-optimums.html = FAIL
 BUG47826 MAC SKIP : fast/dom/HTMLMeterElement/meter-styles.html = FAIL
 BUG47826 MAC SKIP : fast/dom/HTMLMeterElement/meter-styles-changing-pseudo.html = FAIL
 
+BUGWK42214 WIN LINUX : fast/canvas/toDataURL-alpha.html = IMAGE
+
 BUGWK41311 WIN LINUX : fast/borders/border-radius-circle.html = IMAGE
 BUGWK41311 WIN LINUX : fast/borders/border-radius-groove-01.html = IMAGE
 BUGWK41311 WIN LINUX : fast/borders/border-radius-groove-02.html = IMAGE
diff --git a/LayoutTests/platform/mac-leopard/fast/canvas/toDataURL-alpha-expected.checksum b/LayoutTests/platform/mac-leopard/fast/canvas/toDataURL-alpha-expected.checksum
new file mode 100644
index 0000000..257108e
--- /dev/null
+++ b/LayoutTests/platform/mac-leopard/fast/canvas/toDataURL-alpha-expected.checksum
@@ -0,0 +1 @@
+5779ea8a906d9388d43421c56773e801
\ No newline at end of file
diff --git a/LayoutTests/platform/mac-leopard/fast/canvas/toDataURL-alpha-expected.png b/LayoutTests/platform/mac-leopard/fast/canvas/toDataURL-alpha-expected.png
new file mode 100644
index 0000000..302767b
Binary files /dev/null and b/LayoutTests/platform/mac-leopard/fast/canvas/toDataURL-alpha-expected.png differ
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index b7f91fa..0c60b52 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,23 @@
+2010-07-15  Nico Weber  <thakis at chromium.org>
+
+        Reviewed by Ojan Vafai.
+
+        chromium/skia: Fix canvas.toDataURL in the presence of transparency
+        https://bugs.webkit.org/show_bug.cgi?id=42214
+
+        The problem was that SkBitmaps contain premultiplied data, but pnglib
+        doesn't expect premultiplied data. Now, the encoder unpremultiplies
+        data before sending it to pnglib.
+
+        Patch partially by deanm.
+
+        Covered by fast/canvas/toDataURL-alpha.html.
+
+        * platform/image-encoders/skia/PNGImageEncoder.cpp:
+        (WebCore::preMultipliedBGRAtoRGBA):
+        (WebCore::encodeImpl):
+        (WebCore::PNGImageEncoder::encode):
+
 2010-07-15  Alex Nicolaou  <anicolao at chromium.org>
 
         Reviewed by Eric Seidel.
diff --git a/WebCore/platform/image-encoders/skia/PNGImageEncoder.cpp b/WebCore/platform/image-encoders/skia/PNGImageEncoder.cpp
index 19363c8..a2e8760 100644
--- a/WebCore/platform/image-encoders/skia/PNGImageEncoder.cpp
+++ b/WebCore/platform/image-encoders/skia/PNGImageEncoder.cpp
@@ -36,6 +36,7 @@
 #include "Vector.h"
 
 #include "SkBitmap.h"
+#include "SkUnPreMultiply.h"
 
 extern "C" {
 #include "png.h"
@@ -57,6 +58,25 @@ static void convertBetweenBGRAandRGBA(const unsigned char* input, int numberOfPi
     }
 }
 
+// Converts BGRA->RGBA and RGBA->BGRA and undoes alpha premultiplication.
+static void preMultipliedBGRAtoRGBA(const unsigned char* input, int numberOfPixels,
+                                    unsigned char* output)
+{
+    SkBitmap inputBitmap;
+    inputBitmap.setConfig(SkBitmap::kARGB_8888_Config, numberOfPixels, 1);
+    inputBitmap.setPixels(const_cast<unsigned char*>(input));
+    for (int x = 0; x < numberOfPixels; x++) {
+        uint32_t srcPixel = *inputBitmap.getAddr32(x, 0);
+        SkColor unmultiplied = SkUnPreMultiply::PMColorToColor(srcPixel);
+        unsigned char* pixelOut = &output[x * 4];
+        pixelOut[0] = SkColorGetR(unmultiplied);
+        pixelOut[1] = SkColorGetG(unmultiplied);
+        pixelOut[2] = SkColorGetB(unmultiplied);
+        pixelOut[3] = SkColorGetA(unmultiplied);
+    }
+}
+
+
 // Encoder --------------------------------------------------------------------
 //
 // This section of the code is based on nsPNGEncoder.cpp in Mozilla
@@ -98,24 +118,12 @@ private:
     png_info** m_pngInfo;
 };
 
-// static
-bool PNGImageEncoder::encode(const SkBitmap& image, Vector<unsigned char>* output)
-{
-    if (image.config() != SkBitmap::kARGB_8888_Config)
-        return false;  // Only support ARGB at 8 bpp now.
-
-    image.lockPixels();
-    bool result = PNGImageEncoder::encode(static_cast<unsigned char*>(
-        image.getPixels()), IntSize(image.width(), image.height()),
-        image.rowBytes(), output);
-    image.unlockPixels();
-    return result;
-}
-
-// static
-bool PNGImageEncoder::encode(const unsigned char* input, const IntSize& size,
-                             int bytesPerRow,
-                             Vector<unsigned char>* output)
+static bool encodeImpl(const unsigned char* input,
+                       const IntSize& size,
+                       int bytesPerRow,
+                       Vector<unsigned char>* output,
+                       void (*conversionFunc)(const unsigned char*, int, unsigned char*)
+                       )
 {
     int inputColorComponents = 4;
     int outputColorComponents = 4;
@@ -158,7 +166,7 @@ bool PNGImageEncoder::encode(const unsigned char* input, const IntSize& size,
 
     OwnArrayPtr<unsigned char> rowPixels(new unsigned char[imageSize.width() * outputColorComponents]);
     for (int y = 0; y < imageSize.height(); y ++) {
-        convertBetweenBGRAandRGBA(&input[y * bytesPerRow], imageSize.width(), rowPixels.get());
+        conversionFunc(&input[y * bytesPerRow], imageSize.width(), rowPixels.get());
         png_write_row(pngPtr, rowPixels.get());
     }
 
@@ -166,4 +174,27 @@ bool PNGImageEncoder::encode(const unsigned char* input, const IntSize& size,
     return true;
 }
 
+
+// static
+bool PNGImageEncoder::encode(const SkBitmap& image, Vector<unsigned char>* output)
+{
+    if (image.config() != SkBitmap::kARGB_8888_Config)
+        return false; // Only support ARGB at 8 bpp now.
+
+    image.lockPixels();
+    bool result = encodeImpl(static_cast<unsigned char*>(
+        image.getPixels()), IntSize(image.width(), image.height()),
+        image.rowBytes(), output, preMultipliedBGRAtoRGBA);
+    image.unlockPixels();
+    return result;
+}
+
+// static
+bool PNGImageEncoder::encode(const unsigned char* input, const IntSize& size,
+                             int bytesPerRow,
+                             Vector<unsigned char>* output)
+{
+    return encodeImpl(input, size, bytesPerRow, output, convertBetweenBGRAandRGBA);
+}
+
 }  // namespace WebCore

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list