[Cairo] Canvas putImageData is not working as expected
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Aug 2013 06:48:42 +0000 (06:48 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Aug 2013 06:48:42 +0000 (06:48 +0000)
https://bugs.webkit.org/show_bug.cgi?id=119992

Patch by Hurnjoo Lee <hurnjoo.lee@samsung.com> on 2013-08-19
Reviewed by Darin Adler.

Source/WebCore:

ImageBufferCairo::putImageArray didn't perform pre-multiply in case of zero alpha value.
If the alpha value is not 255, image data should always be pre-multiplied.

Test: fast/canvas/canvas-putImageData-zero-alpha.html

* platform/graphics/cairo/ImageBufferCairo.cpp:
(WebCore::ImageBuffer::putByteArray):

LayoutTests:

Add a ref test that ensures that putImageData of canvas with zero alpha work correctly.

* fast/canvas/canvas-putImageData-zero-alpha-expected.html: Added.
* fast/canvas/canvas-putImageData-zero-alpha.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/canvas/canvas-putImageData-zero-alpha-expected.html [new file with mode: 0644]
LayoutTests/fast/canvas/canvas-putImageData-zero-alpha.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp

index 6084731..91ef245 100644 (file)
@@ -1,3 +1,15 @@
+2013-08-19  Hurnjoo Lee  <hurnjoo.lee@samsung.com>
+
+        [Cairo] Canvas putImageData is not working as expected
+        https://bugs.webkit.org/show_bug.cgi?id=119992
+
+        Reviewed by Darin Adler.
+
+        Add a ref test that ensures that putImageData of canvas with zero alpha work correctly.
+
+        * fast/canvas/canvas-putImageData-zero-alpha-expected.html: Added.
+        * fast/canvas/canvas-putImageData-zero-alpha.html: Added.
+
 2013-08-19  James Craig  <james@cookiecrook.com>
 
         <https://webkit.org/b/118754> AX: aria-required.html needs to test @required vs @aria-required mismatch reconciliation
diff --git a/LayoutTests/fast/canvas/canvas-putImageData-zero-alpha-expected.html b/LayoutTests/fast/canvas/canvas-putImageData-zero-alpha-expected.html
new file mode 100644 (file)
index 0000000..c8fd42c
--- /dev/null
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <style>
+  body {
+    background-color:blue;
+  }
+
+  #box {
+    width:100px;
+    height:100px;
+    border:1px solid;
+  }
+  </style>
+</head>
+<body>
+  <canvas id="box" width="100" height="100">
+  </canvas>
+</body>
+</html>
diff --git a/LayoutTests/fast/canvas/canvas-putImageData-zero-alpha.html b/LayoutTests/fast/canvas/canvas-putImageData-zero-alpha.html
new file mode 100644 (file)
index 0000000..33e9b79
--- /dev/null
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <style>
+  body {
+    background-color:blue;
+  }
+
+  #box {
+    width:100px;
+    height:100px;
+    border:1px solid;
+  }
+  </style>
+  <script>
+    if (window.testRunner) {
+      testRunner.dumpAsText(true);
+      testRunner.waitUntilDone();
+    }
+    function doTest()
+    {
+      var c = document.getElementById("box");
+      var ctx = c.getContext("2d");
+
+      var imgData = ctx.createImageData(100, 100);
+      for (var i = 0; i < imgData.data.length ; i += 4) {
+        imgData.data[i + 0] = 255;
+        imgData.data[i + 1] = 0;
+        imgData.data[i + 2] = 0;
+        imgData.data[i + 3] = 0;
+      }
+      ctx.putImageData(imgData, 0, 0);
+      if (window.testRunner)
+        testRunner.notifyDone();
+    }
+    window.addEventListener('load', doTest, false);
+  </script>
+</head>
+<body>
+  <canvas id="box" width="100" height="100">
+  </canvas>
+</body>
+</html>
index ba21586..e559b78 100644 (file)
@@ -1,3 +1,18 @@
+2013-08-19  Hurnjoo Lee  <hurnjoo.lee@samsung.com>
+
+        [Cairo] Canvas putImageData is not working as expected
+        https://bugs.webkit.org/show_bug.cgi?id=119992
+
+        Reviewed by Darin Adler.
+
+        ImageBufferCairo::putImageArray didn't perform pre-multiply in case of zero alpha value.
+        If the alpha value is not 255, image data should always be pre-multiplied.
+
+        Test: fast/canvas/canvas-putImageData-zero-alpha.html
+
+        * platform/graphics/cairo/ImageBufferCairo.cpp:
+        (WebCore::ImageBuffer::putByteArray):
+
 2013-08-19  Santosh Mahto  <santosh.ma@samsung.com>
 
         <https://webkit.org/b/119991> change usage of calculateUTCOffset()/calculateDSTOffset  to calculateLocalTimeOffset
index a21d4a0..4cf7166 100644 (file)
@@ -335,7 +335,7 @@ void ImageBuffer::putByteArray(Multiply multiplied, Uint8ClampedArray* source, c
             unsigned alpha = srcRows[basex + 3];
 
             if (multiplied == Unmultiplied) {
-                if (alpha && alpha != 255) {
+                if (alpha != 255) {
                     red = (red * alpha + 254) / 255;
                     green = (green * alpha + 254) / 255;
                     blue = (blue * alpha + 254) / 255;