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

commit-queue at webkit.org commit-queue at webkit.org
Wed Dec 22 17:55:28 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit a902b3166bcc1f1ae7292d1603b552d40d86f54c
Author: commit-queue at webkit.org <commit-queue at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Thu Dec 2 19:42:52 2010 +0000

    2010-12-02  Noel Gordon  <noel.gordon at gmail.com>
    
            Reviewed by David Levin.
    
            [chromium] Add canvas.toDataURL("image/jpeg", quality) support
            https://bugs.webkit.org/show_bug.cgi?id=49365
    
            Chromium window/linux layout try results now match the default test result, so
            remove this platform-specific test exception file.
    
            * platform/chromium-win/fast/canvas/canvas-toDataURL-case-insensitive-mimetype-expected.txt: Removed.
    2010-12-02  Noel Gordon  <noel.gordon at gmail.com>
    
            Reviewed by David Levin.
    
            [chromium] Add canvas.toDataURL("image/jpeg", quality) support
            https://bugs.webkit.org/show_bug.cgi?id=49365
    
            Adds a libjpeg-based image encoder for Skia bitmaps.  Default encoding quality
            is 92 to match Mozilla, also Safari, though the actual value used by Safari is
            undocumented, and it appears to pre-blur images prior to compression.
    
            The preMultipliedBGRAtoRGB() routine restores the un-premultiplied RGB colors
            where there is non-zero alpha.  Again, this matches Firefox and Safari, but no
            browser conforms to the HTML5 canvas standard here, I believe, considering the
            result of canvas/philip/tests/toDataURL.jpeg.alpha.html; that test ignores the
            alpha channel when extracting an "image/jpeg".toDataURL().  The correct answer
            needs more investigation, bug http://webkit.org/b/40147.
    
            Canvas toDataURL is covered by existing tests canvas/philip/tests/toDataURL.*,
            and fast/canvas/*toDataURL* tests.
    
            * WebCore.gypi:
            * bindings/v8/custom/V8HTMLCanvasElementCustom.cpp:
            (WebCore::V8HTMLCanvasElement::toDataURLCallback): don't set encoding quality
            here, just pass the toDataURL parameters through to the canvas layer.
            * platform/chromium/MIMETypeRegistryChromium.cpp:
            (WebCore::MIMETypeRegistry::isSupportedImageMIMETypeForEncoding): implement
            the supported mimeTypes for encoding in-place.
            * platform/graphics/skia/ImageBufferSkia.cpp:
            (WebCore::ImageBuffer::toDataURL): add jpeg encoding and quality support.
            * platform/image-encoders/skia/JPEGImageEncoder.cpp: Added.
            (WebCore::prepareOutput):
            (WebCore::writeOutput):
            (WebCore::finishOutput):
            (WebCore::handleError):
            (WebCore::preMultipliedBGRAtoRGB): FIXME: bug 40147.
            (WebCore::JPEGImageEncoder::encode):
            * platform/image-encoders/skia/JPEGImageEncoder.h: Added.
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@73173 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 0e59355..60950c3 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,15 @@
+2010-12-02  Noel Gordon  <noel.gordon at gmail.com>
+
+        Reviewed by David Levin.
+
+        [chromium] Add canvas.toDataURL("image/jpeg", quality) support
+        https://bugs.webkit.org/show_bug.cgi?id=49365
+
+        Chromium window/linux layout try results now match the default test result, so
+        remove this platform-specific test exception file.
+
+        * platform/chromium-win/fast/canvas/canvas-toDataURL-case-insensitive-mimetype-expected.txt: Removed.
+
 2010-12-02  Sheriff Bot  <webkit.review.bot at gmail.com>
 
         Unreviewed, rolling out r73152.
diff --git a/LayoutTests/platform/chromium-win/fast/canvas/canvas-toDataURL-case-insensitive-mimetype-expected.txt b/LayoutTests/platform/chromium-win/fast/canvas/canvas-toDataURL-case-insensitive-mimetype-expected.txt
deleted file mode 100644
index 3d4ab79..0000000
--- a/LayoutTests/platform/chromium-win/fast/canvas/canvas-toDataURL-case-insensitive-mimetype-expected.txt
+++ /dev/null
@@ -1,11 +0,0 @@
-Test that toDataURL(mimeType) ignores the case of 'mimeType'.
-
-On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
-
-
-PASS tryMimeType('image/png') is 'image/png'
-PASS tryMimeType('iMAge/Png') is 'image/png'
-PASS tryMimeType('IMAGE/PNG') is 'image/png'
-PASS successfullyParsed is true
-
-TEST COMPLETE
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 48f4d92..9b91edd 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,42 @@
+2010-12-02  Noel Gordon  <noel.gordon at gmail.com>
+
+        Reviewed by David Levin.
+
+        [chromium] Add canvas.toDataURL("image/jpeg", quality) support
+        https://bugs.webkit.org/show_bug.cgi?id=49365
+
+        Adds a libjpeg-based image encoder for Skia bitmaps.  Default encoding quality
+        is 92 to match Mozilla, also Safari, though the actual value used by Safari is
+        undocumented, and it appears to pre-blur images prior to compression.
+
+        The preMultipliedBGRAtoRGB() routine restores the un-premultiplied RGB colors
+        where there is non-zero alpha.  Again, this matches Firefox and Safari, but no
+        browser conforms to the HTML5 canvas standard here, I believe, considering the
+        result of canvas/philip/tests/toDataURL.jpeg.alpha.html; that test ignores the
+        alpha channel when extracting an "image/jpeg".toDataURL().  The correct answer
+        needs more investigation, bug http://webkit.org/b/40147.
+
+        Canvas toDataURL is covered by existing tests canvas/philip/tests/toDataURL.*,
+        and fast/canvas/*toDataURL* tests.
+
+        * WebCore.gypi:
+        * bindings/v8/custom/V8HTMLCanvasElementCustom.cpp:
+        (WebCore::V8HTMLCanvasElement::toDataURLCallback): don't set encoding quality
+        here, just pass the toDataURL parameters through to the canvas layer.
+        * platform/chromium/MIMETypeRegistryChromium.cpp:
+        (WebCore::MIMETypeRegistry::isSupportedImageMIMETypeForEncoding): implement
+        the supported mimeTypes for encoding in-place.
+        * platform/graphics/skia/ImageBufferSkia.cpp:
+        (WebCore::ImageBuffer::toDataURL): add jpeg encoding and quality support.
+        * platform/image-encoders/skia/JPEGImageEncoder.cpp: Added.
+        (WebCore::prepareOutput):
+        (WebCore::writeOutput):
+        (WebCore::finishOutput):
+        (WebCore::handleError):
+        (WebCore::preMultipliedBGRAtoRGB): FIXME: bug 40147.
+        (WebCore::JPEGImageEncoder::encode):
+        * platform/image-encoders/skia/JPEGImageEncoder.h: Added.
+
 2010-12-02  Sheriff Bot  <webkit.review.bot at gmail.com>
 
         Unreviewed, rolling out r73152.
diff --git a/WebCore/WebCore.gypi b/WebCore/WebCore.gypi
index e48c56a..8773582 100644
--- a/WebCore/WebCore.gypi
+++ b/WebCore/WebCore.gypi
@@ -2937,6 +2937,8 @@
             'platform/image-decoders/zlib/zconf.h',
             'platform/image-decoders/zlib/zlib.h',
             'platform/image-decoders/zlib/zutil.h',
+            'platform/image-encoders/skia/JPEGImageEncoder.cpp',
+            'platform/image-encoders/skia/JPEGImageEncoder.h',
             'platform/image-encoders/skia/PNGImageEncoder.cpp',
             'platform/image-encoders/skia/PNGImageEncoder.h',
             'platform/mac/AutodrainedPool.mm',
diff --git a/WebCore/bindings/v8/custom/V8HTMLCanvasElementCustom.cpp b/WebCore/bindings/v8/custom/V8HTMLCanvasElementCustom.cpp
index d2f8c96..e154f7f 100644
--- a/WebCore/bindings/v8/custom/V8HTMLCanvasElementCustom.cpp
+++ b/WebCore/bindings/v8/custom/V8HTMLCanvasElementCustom.cpp
@@ -94,18 +94,19 @@ v8::Handle<v8::Value> V8HTMLCanvasElement::getContextCallback(const v8::Argument
 
 v8::Handle<v8::Value> V8HTMLCanvasElement::toDataURLCallback(const v8::Arguments& args)
 {
-    double quality = 1.0;
-    if (args.Length() > 1) {
-        if (args[1]->IsNumber())
-            quality = args[1]->NumberValue();
-        if (!(0.0 <= quality && quality <= 1.0))
-            quality = 1.0;
-    }
     v8::Handle<v8::Object> holder = args.Holder();
     HTMLCanvasElement* canvas = V8HTMLCanvasElement::toNative(holder);
-    String type = toWebCoreString(args[0]);
     ExceptionCode ec = 0;
-    String result = canvas->toDataURL(type, &quality, ec);
+
+    String type = toWebCoreString(args[0]);
+    double quality;
+    double* qualityPtr = 0;
+    if (args.Length() > 1 && args[1]->IsNumber()) {
+        quality = args[1]->NumberValue();
+        qualityPtr = &quality;
+    }
+
+    String result = canvas->toDataURL(type, qualityPtr, ec);
     V8Proxy::setDOMException(ec);
     return v8StringOrUndefined(result);
 }
diff --git a/WebCore/platform/chromium/MIMETypeRegistryChromium.cpp b/WebCore/platform/chromium/MIMETypeRegistryChromium.cpp
index 23f7926..9df8847 100644
--- a/WebCore/platform/chromium/MIMETypeRegistryChromium.cpp
+++ b/WebCore/platform/chromium/MIMETypeRegistryChromium.cpp
@@ -91,8 +91,7 @@ bool MIMETypeRegistry::isSupportedImageResourceMIMEType(const String& mimeType)
 
 bool MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(const String& mimeType)
 {
-    // FIXME: Fill this out. See: http://trac.webkit.org/changeset/30888
-    return isSupportedImageMIMEType(mimeType);
+    return mimeType == "image/jpeg" || mimeType == "image/png";
 }
 
 bool MIMETypeRegistry::isSupportedJavaScriptMIMEType(const String& mimeType)
diff --git a/WebCore/platform/graphics/skia/ImageBufferSkia.cpp b/WebCore/platform/graphics/skia/ImageBufferSkia.cpp
index adb732b..b714ef4 100644
--- a/WebCore/platform/graphics/skia/ImageBufferSkia.cpp
+++ b/WebCore/platform/graphics/skia/ImageBufferSkia.cpp
@@ -40,6 +40,8 @@
 #include "GLES2Canvas.h"
 #include "GraphicsContext.h"
 #include "ImageData.h"
+#include "JPEGImageEncoder.h"
+#include "MIMETypeRegistry.h"
 #include "PNGImageEncoder.h"
 #include "PlatformContextSkia.h"
 #include "SkColorPriv.h"
@@ -318,20 +320,28 @@ void ImageBuffer::putPremultipliedImageData(ImageData* source, const IntRect& so
     putImageData<Premultiplied>(source, sourceRect, destPoint, *context()->platformContext()->bitmap(), m_size);
 }
 
-String ImageBuffer::toDataURL(const String&, const double*) const
+String ImageBuffer::toDataURL(const String& mimeType, const double* quality) const
 {
-    // Encode the image into a vector.
-    Vector<unsigned char> pngEncodedData;
-    PNGImageEncoder::encode(*context()->platformContext()->bitmap(), &pngEncodedData);
-
-    // Convert it into base64.
-    Vector<char> base64EncodedData;
-    base64Encode(*reinterpret_cast<Vector<char>*>(&pngEncodedData), base64EncodedData);
-    // Append with a \0 so that it's a valid string.
-    base64EncodedData.append('\0');
-
-    // And the resulting string.
-    return makeString("data:image/png;base64,", base64EncodedData.data());
+    ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
+
+    Vector<unsigned char> encodedImage;
+    if (mimeType == "image/jpeg") {
+        int compressionQuality = JPEGImageEncoder::DefaultCompressionQuality;
+        if (quality && *quality >= 0.0 && *quality <= 1.0)
+            compressionQuality = static_cast<int>(*quality * 100 + 0.5);
+        if (!JPEGImageEncoder::encode(*context()->platformContext()->bitmap(), compressionQuality, &encodedImage))
+            return "data:,";
+    } else {
+        if (!PNGImageEncoder::encode(*context()->platformContext()->bitmap(), &encodedImage))
+            return "data:,";
+        ASSERT(mimeType == "image/png");
+    }
+
+    Vector<char> base64Data;
+    base64Encode(*reinterpret_cast<Vector<char>*>(&encodedImage), base64Data);
+    base64Data.append('\0');
+
+    return makeString("data:", mimeType, ";base64,", base64Data.data());
 }
 
 } // namespace WebCore
diff --git a/WebCore/platform/image-encoders/skia/JPEGImageEncoder.cpp b/WebCore/platform/image-encoders/skia/JPEGImageEncoder.cpp
new file mode 100644
index 0000000..c04019d
--- /dev/null
+++ b/WebCore/platform/image-encoders/skia/JPEGImageEncoder.cpp
@@ -0,0 +1,144 @@
+/*
+ * Copyright (c) 2010, Google Inc. All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "JPEGImageEncoder.h"
+
+#include "IntSize.h"
+#include "SkBitmap.h"
+#include "SkUnPreMultiply.h"
+extern "C" {
+#include <stdio.h> // jpeglib.h needs stdio.h FILE
+#include "jpeglib.h"
+#include <setjmp.h>
+}
+
+namespace WebCore {
+
+struct JPEGOutputBuffer : public jpeg_destination_mgr {
+    Vector<unsigned char>* output;
+    Vector<unsigned char> buffer;
+};
+
+static void prepareOutput(j_compress_ptr cinfo)
+{
+    JPEGOutputBuffer* out = static_cast<JPEGOutputBuffer*>(cinfo->dest);
+    const size_t internalBufferSize = 8192;
+    out->buffer.resize(internalBufferSize);
+    out->next_output_byte = out->buffer.data();
+    out->free_in_buffer = out->buffer.size();
+}
+
+static boolean writeOutput(j_compress_ptr cinfo)
+{
+    JPEGOutputBuffer* out = static_cast<JPEGOutputBuffer*>(cinfo->dest);
+    out->output->append(out->buffer.data(), out->buffer.size());
+    out->next_output_byte = out->buffer.data();
+    out->free_in_buffer = out->buffer.size();
+    return TRUE;
+}
+
+static void finishOutput(j_compress_ptr cinfo)
+{
+    JPEGOutputBuffer* out = static_cast<JPEGOutputBuffer*>(cinfo->dest);
+    const size_t size = out->buffer.size() - out->free_in_buffer;
+    out->output->append(out->buffer.data(), size);
+}
+
+static void handleError(j_common_ptr common)
+{
+    jmp_buf* jumpBufferPtr = static_cast<jmp_buf*>(common->client_data);
+    longjmp(*jumpBufferPtr, -1);
+}
+
+// FIXME: is alpha unpremultiplication correct, or should the alpha channel
+// be ignored? See bug http://webkit.org/b/40147.
+void preMultipliedBGRAtoRGB(const SkPMColor* input, unsigned int pixels, unsigned char* output)
+{
+    while (pixels-- > 0) {
+        SkColor unmultiplied = SkUnPreMultiply::PMColorToColor(*input++);
+        *output++ = SkColorGetR(unmultiplied);
+        *output++ = SkColorGetG(unmultiplied);
+        *output++ = SkColorGetB(unmultiplied);
+    }
+}
+
+bool JPEGImageEncoder::encode(const SkBitmap& bitmap, int quality, Vector<unsigned char>* output)
+{
+    if (bitmap.config() != SkBitmap::kARGB_8888_Config)
+        return false; // Only support ARGB 32 bpp skia bitmaps.
+
+    SkAutoLockPixels bitmapLock(bitmap);
+    IntSize imageSize(bitmap.width(), bitmap.height());
+    imageSize.clampNegativeToZero();
+    JPEGOutputBuffer destination;
+    destination.output = output;
+    Vector<JSAMPLE> row;
+
+    jpeg_compress_struct cinfo;
+    jpeg_error_mgr error;
+    cinfo.err = jpeg_std_error(&error);
+    error.error_exit = handleError;
+    jmp_buf jumpBuffer;
+    cinfo.client_data = &jumpBuffer;
+
+    if (setjmp(jumpBuffer)) {
+        jpeg_destroy_compress(&cinfo);
+        return false;
+    }
+
+    jpeg_create_compress(&cinfo);
+    cinfo.dest = &destination;
+    cinfo.dest->init_destination = prepareOutput;
+    cinfo.dest->empty_output_buffer = writeOutput;
+    cinfo.dest->term_destination = finishOutput;
+    cinfo.image_height = imageSize.height();
+    cinfo.image_width = imageSize.width();
+    cinfo.in_color_space = JCS_RGB;
+    cinfo.input_components = 3;
+
+    jpeg_set_defaults(&cinfo);
+    jpeg_set_quality(&cinfo, quality, TRUE);
+    jpeg_start_compress(&cinfo, TRUE);
+
+    const SkPMColor* pixels = static_cast<SkPMColor*>(bitmap.getPixels());
+    row.resize(cinfo.image_width * cinfo.input_components);
+    while (cinfo.next_scanline < cinfo.image_height) {
+        preMultipliedBGRAtoRGB(pixels, cinfo.image_width, row.data());
+        jpeg_write_scanlines(&cinfo, row.dataSlot(), 1);
+        pixels += cinfo.image_width;
+    }
+
+    jpeg_finish_compress(&cinfo);
+    jpeg_destroy_compress(&cinfo);
+    return true;
+}
+
+} // namespace WebCore
diff --git a/WebCore/platform/image-encoders/skia/JPEGImageEncoder.h b/WebCore/platform/image-encoders/skia/JPEGImageEncoder.h
new file mode 100644
index 0000000..f2ac52d
--- /dev/null
+++ b/WebCore/platform/image-encoders/skia/JPEGImageEncoder.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2010, Google Inc. All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef JPEGImageEncoder_h
+#define JPEGImageEncoder_h
+
+#include "Vector.h"
+
+class SkBitmap;
+
+namespace WebCore {
+
+class JPEGImageEncoder {
+public:
+    // Encode the input bitmap with a compression quality in [0-100].
+    static bool encode(const SkBitmap&, int quality, Vector<unsigned char>*);
+
+    // For callers: provide a reasonable compression quality default.
+    enum Quality { DefaultCompressionQuality = 92 };
+};
+
+} // namespace WebCore
+
+#endif

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list