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

mrobinson at webkit.org mrobinson at webkit.org
Wed Dec 22 11:39:26 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit f8c90dee980983b805f4146abfa2a0d904b1d65c
Author: mrobinson at webkit.org <mrobinson at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Mon Aug 2 23:51:56 2010 +0000

    2010-08-02  Martin Robinson  <mrobinson at igalia.com>
    
            Reviewed by Xan Lopez.
    
            [GTK] Use GdkPixbuf for ImageBuffer::toDataURL
            https://bugs.webkit.org/show_bug.cgi?id=43088
    
            * platform/gtk/Skipped: Generate results for a toDataURL test and unskip it.
    2010-08-02  Martin Robinson  <mrobinson at igalia.com>
    
            Reviewed by Xan Lopez.
    
            [GTK] Use GdkPixbuf for ImageBuffer::toDataURL
            https://bugs.webkit.org/show_bug.cgi?id=43088
    
            Implement ImageBuffer::toDataURL with GdkPixbuf instead of Cairo. This
            allows the method to support a larger variety of image types.
    
            * GNUmakefile.am: Add new files to the source list.
            * platform/MIMETypeRegistry.cpp:
            (WebCore::initializeSupportedImageMIMETypesForEncoding):
            Add the list of image types supported by GTK.
            * platform/graphics/cairo/ImageBufferCairo.cpp:
            * platform/graphics/gtk/CairoUtilities.cpp: Added.
            (getCairoSurfacePixel): Move this method from ImageGtk.cpp.
            (getGdkPixbufPixel): Move this method from ImageGtk.cpp.
            (cairoImageSurfaceToGdkPixbuf): Move this method from ImageGtk.cpp.
            * platform/graphics/gtk/CairoUtilities.h: Added.
            * platform/graphics/gtk/ImageBufferGtk.cpp: Added.
            (WebCore::ImageBuffer::toDataURL): Use GdkPixbuf to do the conversion to a data url.
            * platform/graphics/gtk/ImageGtk.cpp:
            (WebCore::BitmapImage::getGdkPixbuf): Use the new helper method in CairoUtilities.h.
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@64506 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 946cd2b..7ee480f 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,12 @@
+2010-08-02  Martin Robinson  <mrobinson at igalia.com>
+
+        Reviewed by Xan Lopez.
+
+        [GTK] Use GdkPixbuf for ImageBuffer::toDataURL
+        https://bugs.webkit.org/show_bug.cgi?id=43088
+
+        * platform/gtk/Skipped: Generate results for a toDataURL test and unskip it.
+
 2010-08-02  Anders Carlsson  <andersca at apple.com>
 
         Reviewed by Sam Weinig.
diff --git a/LayoutTests/platform/gtk/Skipped b/LayoutTests/platform/gtk/Skipped
index 0f5f79c..1b8998f 100644
--- a/LayoutTests/platform/gtk/Skipped
+++ b/LayoutTests/platform/gtk/Skipped
@@ -1081,7 +1081,6 @@ fast/canvas/canvas-transform-non-invertible.html
 fast/canvas/canvas-transform-skewed.html
 fast/canvas/canvas-zoom.html
 fast/canvas/pointInPath.html
-fast/canvas/toDataURL-supportedTypes.html
 fast/css/css1_forward_compatible_parsing.html
 fast/css/invalid-percentage-property.html
 fast/css/text-align.html
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 1275d8b..a2a4f6c 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,28 @@
+2010-08-02  Martin Robinson  <mrobinson at igalia.com>
+
+        Reviewed by Xan Lopez.
+
+        [GTK] Use GdkPixbuf for ImageBuffer::toDataURL
+        https://bugs.webkit.org/show_bug.cgi?id=43088
+
+        Implement ImageBuffer::toDataURL with GdkPixbuf instead of Cairo. This
+        allows the method to support a larger variety of image types.
+
+        * GNUmakefile.am: Add new files to the source list.
+        * platform/MIMETypeRegistry.cpp: 
+        (WebCore::initializeSupportedImageMIMETypesForEncoding):
+        Add the list of image types supported by GTK.
+        * platform/graphics/cairo/ImageBufferCairo.cpp:
+        * platform/graphics/gtk/CairoUtilities.cpp: Added.
+        (getCairoSurfacePixel): Move this method from ImageGtk.cpp.
+        (getGdkPixbufPixel): Move this method from ImageGtk.cpp.
+        (cairoImageSurfaceToGdkPixbuf): Move this method from ImageGtk.cpp.
+        * platform/graphics/gtk/CairoUtilities.h: Added.
+        * platform/graphics/gtk/ImageBufferGtk.cpp: Added.
+        (WebCore::ImageBuffer::toDataURL): Use GdkPixbuf to do the conversion to a data url.
+        * platform/graphics/gtk/ImageGtk.cpp:
+        (WebCore::BitmapImage::getGdkPixbuf): Use the new helper method in CairoUtilities.h.
+
 2010-08-02  Xan Lopez  <xlopez at igalia.com>
 
         Reviewed by Gustavo Noronha.
diff --git a/WebCore/GNUmakefile.am b/WebCore/GNUmakefile.am
index 4f7ca6c..70034c9 100644
--- a/WebCore/GNUmakefile.am
+++ b/WebCore/GNUmakefile.am
@@ -2432,8 +2432,11 @@ webcoregtk_sources += \
 	WebCore/platform/graphics/cairo/PatternCairo.cpp \
 	WebCore/platform/graphics/cairo/TransformationMatrixCairo.cpp \
 	WebCore/platform/graphics/gtk/ColorGtk.cpp \
+	WebCore/platform/graphics/gtk/CairoUtilities.cpp \
+	WebCore/platform/graphics/gtk/CairoUtilities.h \
 	WebCore/platform/graphics/gtk/FontGtk.cpp \
 	WebCore/platform/graphics/gtk/IconGtk.cpp \
+	WebCore/platform/graphics/gtk/ImageBufferGtk.cpp \
 	WebCore/platform/graphics/gtk/ImageGtk.cpp \
 	WebCore/platform/graphics/gtk/IntPointGtk.cpp \
 	WebCore/platform/graphics/gtk/IntRectGtk.cpp \
diff --git a/WebCore/platform/MIMETypeRegistry.cpp b/WebCore/platform/MIMETypeRegistry.cpp
index 3740144..b4cc2fa 100644
--- a/WebCore/platform/MIMETypeRegistry.cpp
+++ b/WebCore/platform/MIMETypeRegistry.cpp
@@ -156,6 +156,12 @@ static void initializeSupportedImageMIMETypesForEncoding()
     }
 
     supportedImageMIMETypesForEncoding->remove("application/octet-stream");
+#elif PLATFORM(GTK)
+    supportedImageMIMETypesForEncoding->add("image/png");
+    supportedImageMIMETypesForEncoding->add("image/jpeg");
+    supportedImageMIMETypesForEncoding->add("image/tiff");
+    supportedImageMIMETypesForEncoding->add("image/bmp");
+    supportedImageMIMETypesForEncoding->add("image/ico");
 #elif PLATFORM(CAIRO)
     supportedImageMIMETypesForEncoding->add("image/png");
 #endif
diff --git a/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp b/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp
index c298e18..1a43e54 100644
--- a/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp
+++ b/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp
@@ -277,6 +277,7 @@ void ImageBuffer::putPremultipliedImageData(ImageData* source, const IntRect& so
     putImageData<Premultiplied>(source, sourceRect, destPoint, m_data, m_size);
 }
 
+#if !PLATFORM(GTK)
 static cairo_status_t writeFunction(void* closure, const unsigned char* data, unsigned int length)
 {
     Vector<char>* in = reinterpret_cast<Vector<char>*>(closure);
@@ -303,5 +304,6 @@ String ImageBuffer::toDataURL(const String& mimeType, const double*) const
 
     return "data:" + actualMimeType + ";base64," + String(out.data(), out.size());
 }
+#endif
 
 } // namespace WebCore
diff --git a/WebCore/platform/graphics/gtk/CairoUtilities.cpp b/WebCore/platform/graphics/gtk/CairoUtilities.cpp
new file mode 100644
index 0000000..81e00f0
--- /dev/null
+++ b/WebCore/platform/graphics/gtk/CairoUtilities.cpp
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2010 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 "CairoUtilities.h"
+
+#include <cairo.h>
+#include <gtk/gtk.h>
+
+static inline unsigned char* getCairoSurfacePixel(unsigned char* data, unsigned x, unsigned y, unsigned rowStride)
+{
+    return data + (y * rowStride) + x * 4;
+}
+
+static inline guchar* getGdkPixbufPixel(guchar* data, unsigned x, unsigned y, unsigned rowStride)
+{
+    return data + (y * rowStride) + x * 4;
+}
+
+GdkPixbuf* cairoImageSurfaceToGdkPixbuf(cairo_surface_t* surface)
+{
+    int width = cairo_image_surface_get_width(surface);
+    int height = cairo_image_surface_get_height(surface);
+    unsigned char* surfaceData = cairo_image_surface_get_data(surface);
+    int surfaceRowStride = cairo_image_surface_get_stride(surface);
+
+    GdkPixbuf* dest = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
+    if (!dest)
+        return 0;
+
+    guchar* pixbufData = gdk_pixbuf_get_pixels(dest);
+    int pixbufRowStride = gdk_pixbuf_get_rowstride(dest);
+
+    /* From: http://cairographics.org/manual/cairo-image-surface.html#cairo-format-t
+     * "CAIRO_FORMAT_ARGB32: each pixel is a 32-bit quantity, with alpha in
+     * the upper 8 bits, then red, then green, then blue. The 32-bit
+     * quantities are stored native-endian. Pre-multiplied alpha is used.
+     * (That is, 50% transparent red is 0x80800000, not 0x80ff0000.)"
+     *
+     * See http://developer.gimp.org/api/2.0/gdk-pixbuf/gdk-pixbuf-gdk-pixbuf.html#GdkPixbuf
+     * for information on the structure of GdkPixbufs stored with GDK_COLORSPACE_RGB.
+     *
+     * RGB color channels in CAIRO_FORMAT_ARGB32 are stored based on the
+     * endianness of the machine and are also multiplied by the alpha channel.
+     * To properly transfer the data from the Cairo surface we must divide each
+     * of the RGB channels by the alpha channel and then reorder all channels
+     * if this machine is little-endian.
+     */
+    for (int y = 0; y < height; y++) {
+        for (int x = 0; x < width; x++) {
+            unsigned char* source = getCairoSurfacePixel(surfaceData, x, y, surfaceRowStride);
+            guchar* dest = getGdkPixbufPixel(pixbufData, x, y, pixbufRowStride);
+
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+            guchar alpha = source[3];
+            dest[0] = alpha ? ((source[2] * 255) / alpha) : 0;
+            dest[1] = alpha ? ((source[1] * 255) / alpha) : 0;
+            dest[2] = alpha ? ((source[0] * 255) / alpha) : 0;
+            dest[3] = alpha;
+#else
+            guchar alpha = source[0];
+            dest[0] = alpha ? ((source[1] * 255) / alpha) : 0;
+            dest[1] = alpha ? ((source[2] * 255) / alpha) : 0;
+            dest[2] = alpha ? ((source[3] * 255) / alpha) : 0;
+            dest[3] = alpha;
+#endif
+        }
+    }
+
+    return dest;
+}
+
diff --git a/WebCore/platform/graphics/gtk/CairoUtilities.h b/WebCore/platform/graphics/gtk/CairoUtilities.h
new file mode 100644
index 0000000..89eb458
--- /dev/null
+++ b/WebCore/platform/graphics/gtk/CairoUtilities.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2010 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 CairoUtilities_h
+#define CairoUtilities_h
+
+typedef struct _cairo_surface cairo_surface_t;
+typedef struct _GdkPixbuf GdkPixbuf;
+GdkPixbuf* cairoImageSurfaceToGdkPixbuf(cairo_surface_t* surface);
+
+#endif // CairoUtilities_h
diff --git a/WebCore/platform/graphics/gtk/ImageBufferGtk.cpp b/WebCore/platform/graphics/gtk/ImageBufferGtk.cpp
new file mode 100644
index 0000000..d0b0274
--- /dev/null
+++ b/WebCore/platform/graphics/gtk/ImageBufferGtk.cpp
@@ -0,0 +1,73 @@
+/*
+ *  Copyright (C) 2010 Igalia S.L.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+
+#include "config.h"
+#include "ImageBuffer.h"
+
+#include "Base64.h"
+#include "CairoUtilities.h"
+#include "GOwnPtr.h"
+#include "GRefPtrGtk.h"
+#include "MIMETypeRegistry.h"
+#include <cairo.h>
+#include <gtk/gtk.h>
+#include <wtf/text/CString.h>
+
+namespace WebCore {
+
+String ImageBuffer::toDataURL(const String& mimeType, const double* quality) const
+{
+    ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
+
+    if (!mimeType.startsWith("image/"))
+        return "data:,";
+
+    // List of supported image types comes from the GdkPixbuf documentation.
+    // http://library.gnome.org/devel/gdk-pixbuf/stable/gdk-pixbuf-file-saving.html#gdk-pixbuf-save-to-bufferv
+    String type = mimeType.substring(sizeof "image");
+    if (type != "jpeg" && type != "png" && type != "tiff" && type != "ico" && type != "bmp")
+        return "data:,";
+
+    GRefPtr<GdkPixbuf> pixbuf = cairoImageSurfaceToGdkPixbuf(m_data.m_surface);
+    if (!pixbuf)
+        return "data:,";
+
+    GOwnPtr<gchar> buffer(0);
+    gsize bufferSize;
+    GError* error = 0;
+    gboolean success = FALSE;
+    if (type == "jpeg" && quality && *quality >= 0.0 && *quality <= 1.0) {
+        String qualityString = String::format("%f", *quality);
+        success = gdk_pixbuf_save_to_buffer(pixbuf.get(), &buffer.outPtr(), &bufferSize,
+            type.utf8().data(), &error, "quality", qualityString.utf8().data(), NULL);
+    } else {
+        success = gdk_pixbuf_save_to_buffer(pixbuf.get(), &buffer.outPtr(), &bufferSize, type.utf8().data(), &error, NULL);
+    }
+
+    if (!success)
+        return "data:,";
+
+    Vector<char> out;
+    base64Encode(reinterpret_cast<const char*>(buffer.get()), bufferSize, out);
+    out.append('\0');
+
+    return String::format("data:%s;base64,%s", mimeType.utf8().data(), out.data());
+}
+
+}
diff --git a/WebCore/platform/graphics/gtk/ImageGtk.cpp b/WebCore/platform/graphics/gtk/ImageGtk.cpp
index 3de8495..30db6d7 100644
--- a/WebCore/platform/graphics/gtk/ImageGtk.cpp
+++ b/WebCore/platform/graphics/gtk/ImageGtk.cpp
@@ -26,6 +26,7 @@
 #include "config.h"
 
 #include "BitmapImage.h"
+#include "CairoUtilities.h"
 #include "GOwnPtr.h"
 #include "SharedBuffer.h"
 #include <wtf/text/CString.h>
@@ -172,67 +173,9 @@ PassRefPtr<Image> Image::loadPlatformThemeIcon(const char* name, int size)
     return loadImageFromFile(getThemeIconFileName(name, size));
 }
 
-static inline unsigned char* getCairoSurfacePixel(unsigned char* data, unsigned x, unsigned y, unsigned rowStride)
-{
-    return data + (y * rowStride) + x * 4;
-}
-
-static inline guchar* getGdkPixbufPixel(guchar* data, unsigned x, unsigned y, unsigned rowStride)
-{
-    return data + (y * rowStride) + x * 4;
-}
-
 GdkPixbuf* BitmapImage::getGdkPixbuf()
 {
-    int width = cairo_image_surface_get_width(frameAtIndex(currentFrame()));
-    int height = cairo_image_surface_get_height(frameAtIndex(currentFrame()));
-    unsigned char* surfaceData = cairo_image_surface_get_data(frameAtIndex(currentFrame()));
-    int surfaceRowStride = cairo_image_surface_get_stride(frameAtIndex(currentFrame()));
-
-    GdkPixbuf* dest = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
-    if (!dest)
-        return 0;
-
-    guchar* pixbufData = gdk_pixbuf_get_pixels(dest);
-    int pixbufRowStride = gdk_pixbuf_get_rowstride(dest);
-
-    /* From: http://cairographics.org/manual/cairo-image-surface.html#cairo-format-t
-     * "CAIRO_FORMAT_ARGB32: each pixel is a 32-bit quantity, with alpha in
-     * the upper 8 bits, then red, then green, then blue. The 32-bit
-     * quantities are stored native-endian. Pre-multiplied alpha is used.
-     * (That is, 50% transparent red is 0x80800000, not 0x80ff0000.)"
-     *
-     * See http://developer.gimp.org/api/2.0/gdk-pixbuf/gdk-pixbuf-gdk-pixbuf.html#GdkPixbuf
-     * for information on the structure of GdkPixbufs stored with GDK_COLORSPACE_RGB.
-     *
-     * RGB color channels in CAIRO_FORMAT_ARGB32 are stored based on the
-     * endianness of the machine and are also multiplied by the alpha channel.
-     * To properly transfer the data from the Cairo surface we must divide each
-     * of the RGB channels by the alpha channel and then reorder all channels
-     * if this machine is little-endian.
-     */
-    for (int y = 0; y < height; y++) {
-        for (int x = 0; x < width; x++) {
-            unsigned char* source = getCairoSurfacePixel(surfaceData, x, y, surfaceRowStride);
-            guchar* dest = getGdkPixbufPixel(pixbufData, x, y, pixbufRowStride);
-
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN
-            guchar alpha = source[3];
-            dest[0] = alpha ? ((source[2] * 255) / alpha) : 0;
-            dest[1] = alpha ? ((source[1] * 255) / alpha) : 0;
-            dest[2] = alpha ? ((source[0] * 255) / alpha) : 0;
-            dest[3] = alpha;
-#else
-            guchar alpha = source[0];
-            dest[0] = alpha ? ((source[1] * 255) / alpha) : 0;
-            dest[1] = alpha ? ((source[2] * 255) / alpha) : 0;
-            dest[2] = alpha ? ((source[3] * 255) / alpha) : 0;
-            dest[3] = alpha;
-#endif
-        }
-    }
-
-    return dest;
+    return cairoImageSurfaceToGdkPixbuf(frameAtIndex(currentFrame()));
 }
 
 }

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list