[chromium] Use WEBPImportPictureRGBX|BGRX to import picture data
authornoel.gordon@gmail.com <noel.gordon@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Jun 2012 02:57:27 +0000 (02:57 +0000)
committernoel.gordon@gmail.com <noel.gordon@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Jun 2012 02:57:27 +0000 (02:57 +0000)
https://bugs.webkit.org/show_bug.cgi?id=88218

Reviewed by Kent Tamura.

Source/WebCore:

Stop using the RGBA and RGBA variants of the picture import routines (since
these will import alpha channel data in a future libwebp). Use the RGBX and
BGRX variants to import picture data for encoding to make it clear that the
alpha channel is (and must be) ignored.

Test: fast/canvas/canvas-toDataURL-webp.html

* platform/image-encoders/skia/WEBPImageEncoder.cpp:
(WebCore::rgbPictureImport):
(WebCore::importPictureBGRX): Use WEBPImportPictureBGRX for picture imports
that must ignore the alpha channel. Change the template parameter to be the
premultiplied alpha state of the input image data.
(WebCore::importPictureRGBX): Use WEBPImportPictureRGBX, ditto.
(WebCore::encodePixels): Invert the sense of the template parameter to make
it now indicate the premultiplied alpha state of the input image data.

LayoutTests:

The test image (html5.png) has an alpha 255 background. The background should
be rendered black when a <canvas>.toDataURL('image/webp') is used as an <img>
element src attribute for example, since WEBP does not support alpha.

* fast/canvas/canvas-toDataURL-webp-expected.txt:
* fast/canvas/canvas-toDataURL-webp.html: Change the test to encode the added
html5.png test image as an image/webp data url.
* fast/canvas/resources/html5.png: Added.
* platform/chromium-mac-snowleopard/fast/canvas/canvas-toDataURL-webp-expected.png: Added.
* platform/chromium/TestExpectations: Requires WIN, LINUX rebaselines.

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

LayoutTests/ChangeLog
LayoutTests/fast/canvas/canvas-toDataURL-webp-expected.txt
LayoutTests/fast/canvas/canvas-toDataURL-webp.html
LayoutTests/fast/canvas/resources/html5.png [new file with mode: 0644]
LayoutTests/platform/chromium-mac-snowleopard/fast/canvas/canvas-toDataURL-webp-expected.png [new file with mode: 0644]
LayoutTests/platform/chromium/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/platform/image-encoders/skia/WEBPImageEncoder.cpp

index c9dc48072a8605e26fa6112561bb7e68e5920eef..508e78e2be875952ab41587dcb81a9e604bb61fb 100644 (file)
@@ -1,3 +1,21 @@
+2012-06-07  Noel Gordon  <noel.gordon@gmail.com>
+
+        [chromium] Use WEBPImportPictureRGBX|BGRX to import picture data
+        https://bugs.webkit.org/show_bug.cgi?id=88218
+
+        Reviewed by Kent Tamura.
+
+        The test image (html5.png) has an alpha 255 background. The background should
+        be rendered black when a <canvas>.toDataURL('image/webp') is used as an <img>
+        element src attribute for example, since WEBP does not support alpha.
+
+        * fast/canvas/canvas-toDataURL-webp-expected.txt:
+        * fast/canvas/canvas-toDataURL-webp.html: Change the test to encode the added
+        html5.png test image as an image/webp data url.
+        * fast/canvas/resources/html5.png: Added.
+        * platform/chromium-mac-snowleopard/fast/canvas/canvas-toDataURL-webp-expected.png: Added.
+        * platform/chromium/TestExpectations: Requires WIN, LINUX rebaselines.
+
 2012-06-07  Ojan Vafai  <ojan@chromium.org>
 
         Last set of chromium rebaselines after r119748.
index ce41bb383b372911747b8946ba1441babe2203fb..8b137891791fe96927ad78e64b0aad7bded08bdc 100644 (file)
@@ -1,2 +1 @@
-PASS: canvas.toDataURL('image/webp')
 
index 74e9e5d3f5722923b05c07a96b53e346b1020f03..260dccb6010bc5f95a1c0b43f2e3605bbefb934e 100644 (file)
@@ -1,65 +1,29 @@
-<!DOCTYPE html>
-
+<canvas id="canvas" width="64px" height="64px" style="display: none"></canvas>
 <pre id="log"></pre>
-<canvas id="canvas" width="100" height="60"></canvas>
-
+<img id="result">
 <script>
-if (window.layoutTestController)
-    window.layoutTestController.dumpAsText();
-
-function log(message)
-{
-    document.getElementById('log').textContent += message + '\n';
+if (window.layoutTestController) {
+    window.layoutTestController.dumpAsText(pixelTest = true);
+    window.layoutTestController.waitUntilDone();
 }
 
-function canvasPixelShouldBe(canvas, x, y, p, tolerance)
+function webpDataURLTest()
 {
-    try {
-        var pixelData = canvas.getContext('2d').getImageData(x, y, 1, 1);
-    } catch (e) {
-        return log('FAIL: can\'t access pixel at (' + x + ',' + y + ')');
-    }
-
-    var delta = 0, pixel = Array.prototype.slice.call(pixelData.data);
-    pixel.forEach(function(component, i) {
-        delta = Math.max(Math.abs(pixel[i] - p[i]), delta);
-    });
-
-    pixel = 'pixel [' + pixel + '] at (' + x + ',' + y + ')';
-    if (tolerance = tolerance || 0, delta > tolerance)
-        log('FAIL: ' + pixel + ', expected [' + p + '] +/-' + tolerance);
-}
-
-var canvas = document.getElementById('canvas');
-var context = canvas.getContext('2d');
+    var canvas = document.getElementById('canvas');
+    var context = canvas.getContext('2d');
+    context.drawImage(window.image, 0, 0, canvas.width, canvas.height);
 
-context.fillStyle = 'rgba(0, 128, 0, 0.0)';
-context.fillRect(0,  0, 100, 20);
-context.fillStyle = 'rgba(0, 128, 0, 0.5)';
-context.fillRect(0, 20, 100, 20);
-context.fillStyle = 'rgba(0, 128, 0, 1.0)';
-context.fillRect(0, 40, 100, 20);
+    var dataURL = canvas.toDataURL('image/webp', 0.8);
+    if (!dataURL.match(/^data:image\/webp[;,]/))
+        document.getElementById('log').textContent += "FAIL: canvas.toDataURL('image/webp') not supported";
+    else
+        document.getElementById('result').src = dataURL;
 
-function checkPixels()
-{
-    canvas.width = 100; // Reset (clear) the canvas element.
-    context.drawImage(image, 0, 0);
-    canvasPixelShouldBe(canvas, 0, 10, [0,   0, 0, 255], 8);
-    canvasPixelShouldBe(canvas, 0, 30, [0,  64, 0, 255], 8);
-    canvasPixelShouldBe(canvas, 0, 50, [0, 128, 0, 255], 8);
     if (window.layoutTestController)
         window.layoutTestController.notifyDone();
 }
 
-var dataURL = canvas.toDataURL('image/webp');
-
-if (!dataURL.match(/^data:image\/webp[;,]/)) {
-    log("FAIL: canvas.toDataURL('image/webp') not supported");
-} else {
-    log("PASS: canvas.toDataURL('image/webp')");
-    if (window.layoutTestController)
-        window.layoutTestController.waitUntilDone();
-    (image = new Image()).onload = checkPixels;
-    image.src = dataURL;
-}
+var image = new Image();
+image.onload = webpDataURLTest;
+image.src = 'resources/html5.png';
 </script>
diff --git a/LayoutTests/fast/canvas/resources/html5.png b/LayoutTests/fast/canvas/resources/html5.png
new file mode 100644 (file)
index 0000000..e344192
Binary files /dev/null and b/LayoutTests/fast/canvas/resources/html5.png differ
diff --git a/LayoutTests/platform/chromium-mac-snowleopard/fast/canvas/canvas-toDataURL-webp-expected.png b/LayoutTests/platform/chromium-mac-snowleopard/fast/canvas/canvas-toDataURL-webp-expected.png
new file mode 100644 (file)
index 0000000..8e557a8
Binary files /dev/null and b/LayoutTests/platform/chromium-mac-snowleopard/fast/canvas/canvas-toDataURL-webp-expected.png differ
index addefd59881d8cbf6f6e5810af6846ab34be22d1..313121508c764c22afeb2303718de94a62004d37 100644 (file)
@@ -3426,6 +3426,8 @@ BUGWK82122 LEOPARD SNOWLEOPARD : css3/selectors3/xml/css3-modsel-d2.xml = FAIL P
 BUGWK82122 LEOPARD SNOWLEOPARD : css3/selectors3/xml/css3-modsel-d3.xml = FAIL PASS
 BUGWK82122 LEOPARD SNOWLEOPARD : css3/selectors3/xml/css3-modsel-d4.xml = FAIL PASS
 
+BUGWK88218 LINUX WIN : fast/canvas/canvas-toDataURL-webp.html = MISSING
+
 // Needs a rebaseline after the bug.
 // The inner <input> should now grow to take the full cell's height.
 BUGWK80531 WIN : fast/table/colspanMinWidth-vertical.html = IMAGE+TEXT
index d90e693451487dbb33b6dec44502e61c20222ae7..e3774f0439ceb981a0140bc8a718bd8c5f25d01c 100644 (file)
@@ -1,3 +1,26 @@
+2012-06-07  Noel Gordon  <noel.gordon@gmail.com>
+
+        [chromium] Use WEBPImportPictureRGBX|BGRX to import picture data
+        https://bugs.webkit.org/show_bug.cgi?id=88218
+
+        Reviewed by Kent Tamura.
+
+        Stop using the RGBA and RGBA variants of the picture import routines (since
+        these will import alpha channel data in a future libwebp). Use the RGBX and
+        BGRX variants to import picture data for encoding to make it clear that the
+        alpha channel is (and must be) ignored.
+
+        Test: fast/canvas/canvas-toDataURL-webp.html
+
+        * platform/image-encoders/skia/WEBPImageEncoder.cpp:
+        (WebCore::rgbPictureImport):
+        (WebCore::importPictureBGRX): Use WEBPImportPictureBGRX for picture imports
+        that must ignore the alpha channel. Change the template parameter to be the
+        premultiplied alpha state of the input image data.
+        (WebCore::importPictureRGBX): Use WEBPImportPictureRGBX, ditto.
+        (WebCore::encodePixels): Invert the sense of the template parameter to make
+        it now indicate the premultiplied alpha state of the input image data.
+
 2012-06-07  Takashi Sakamoto  <tasak@google.com>
 
         Improve the performance of pushScope in StyleResolver
index ebc299d5f97519c360cac83c2cc76a69e8784afd..1e665181e44b4d334caa101b3ea88549d5d43790 100644 (file)
@@ -49,9 +49,9 @@ static int writeOutput(const uint8_t* data, size_t size, const WebPPicture* cons
     return 1;
 }
 
-static bool importPicture(const unsigned char* pixels, bool premultiply, WebPImporter importRGBX, WebPImporter importRGB, WebPPicture* picture)
+static bool rgbPictureImport(const unsigned char* pixels, bool premultiplied, WebPImporter importRGBX, WebPImporter importRGB, WebPPicture* picture)
 {
-    if (!premultiply)
+    if (premultiplied)
         return importRGBX(picture, pixels, picture->width * 4);
 
     // Write the RGB pixels to an rgb data buffer, alpha premultiplied, then import the rgb data.
@@ -76,14 +76,14 @@ static bool importPicture(const unsigned char* pixels, bool premultiply, WebPImp
     return importRGB(picture, rgb.data(), picture->width * 3);
 }
 
-template <bool Premultiply> inline bool importPictureBGRA(const unsigned char* pixels, WebPPicture* picture)
+template <bool Premultiplied> inline bool importPictureBGRX(const unsigned char* pixels, WebPPicture* picture)
 {
-    return importPicture(pixels, Premultiply, &WebPPictureImportBGRA, &WebPPictureImportBGR, picture);
+    return rgbPictureImport(pixels, Premultiplied, &WebPPictureImportBGRX, &WebPPictureImportBGR, picture);
 }
 
-template <bool Premultiply> inline bool importPictureRGBA(const unsigned char* pixels, WebPPicture* picture)
+template <bool Premultiplied> inline bool importPictureRGBX(const unsigned char* pixels, WebPPicture* picture)
 {
-    return importPicture(pixels, Premultiply, &WebPPictureImportRGBA, &WebPPictureImportRGB, picture);
+    return rgbPictureImport(pixels, Premultiplied, &WebPPictureImportRGBX, &WebPPictureImportRGB, picture);
 }
 
 static bool encodePixels(IntSize imageSize, const unsigned char* pixels, bool premultiplied, int quality, Vector<unsigned char>* output)
@@ -103,9 +103,9 @@ static bool encodePixels(IntSize imageSize, const unsigned char* pixels, bool pr
         return false;
     picture.height = imageSize.height();
 
-    if (premultiplied && !importPictureBGRA<false>(pixels, &picture))
+    if (premultiplied && !importPictureBGRX<true>(pixels, &picture))
         return false;
-    if (!premultiplied && !importPictureRGBA<true>(pixels, &picture))
+    if (!premultiplied && !importPictureRGBX<false>(pixels, &picture))
         return false;
 
     picture.custom_ptr = output;