Changeset 64506 in webkit


Ignore:
Timestamp:
Aug 2, 2010 4:51:56 PM (14 years ago)
Author:
Martin Robinson
Message:

2010-08-02 Martin Robinson <mrobinson@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@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.
Location:
trunk
Files:
3 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r64504 r64506  
     12010-08-02  Martin Robinson  <mrobinson@igalia.com>
     2
     3        Reviewed by Xan Lopez.
     4
     5        [GTK] Use GdkPixbuf for ImageBuffer::toDataURL
     6        https://bugs.webkit.org/show_bug.cgi?id=43088
     7
     8        * platform/gtk/Skipped: Generate results for a toDataURL test and unskip it.
     9
    1102010-08-02  Anders Carlsson  <andersca@apple.com>
    211
  • trunk/LayoutTests/platform/gtk/Skipped

    r64459 r64506  
    10821082fast/canvas/canvas-zoom.html
    10831083fast/canvas/pointInPath.html
    1084 fast/canvas/toDataURL-supportedTypes.html
    10851084fast/css/css1_forward_compatible_parsing.html
    10861085fast/css/invalid-percentage-property.html
  • trunk/WebCore/ChangeLog

    r64505 r64506  
     12010-08-02  Martin Robinson  <mrobinson@igalia.com>
     2
     3        Reviewed by Xan Lopez.
     4
     5        [GTK] Use GdkPixbuf for ImageBuffer::toDataURL
     6        https://bugs.webkit.org/show_bug.cgi?id=43088
     7
     8        Implement ImageBuffer::toDataURL with GdkPixbuf instead of Cairo. This
     9        allows the method to support a larger variety of image types.
     10
     11        * GNUmakefile.am: Add new files to the source list.
     12        * platform/MIMETypeRegistry.cpp:
     13        (WebCore::initializeSupportedImageMIMETypesForEncoding):
     14        Add the list of image types supported by GTK.
     15        * platform/graphics/cairo/ImageBufferCairo.cpp:
     16        * platform/graphics/gtk/CairoUtilities.cpp: Added.
     17        (getCairoSurfacePixel): Move this method from ImageGtk.cpp.
     18        (getGdkPixbufPixel): Move this method from ImageGtk.cpp.
     19        (cairoImageSurfaceToGdkPixbuf): Move this method from ImageGtk.cpp.
     20        * platform/graphics/gtk/CairoUtilities.h: Added.
     21        * platform/graphics/gtk/ImageBufferGtk.cpp: Added.
     22        (WebCore::ImageBuffer::toDataURL): Use GdkPixbuf to do the conversion to a data url.
     23        * platform/graphics/gtk/ImageGtk.cpp:
     24        (WebCore::BitmapImage::getGdkPixbuf): Use the new helper method in CairoUtilities.h.
     25
    1262010-08-02  Xan Lopez  <xlopez@igalia.com>
    227
  • trunk/WebCore/GNUmakefile.am

    r64471 r64506  
    24332433        WebCore/platform/graphics/cairo/TransformationMatrixCairo.cpp \
    24342434        WebCore/platform/graphics/gtk/ColorGtk.cpp \
     2435        WebCore/platform/graphics/gtk/CairoUtilities.cpp \
     2436        WebCore/platform/graphics/gtk/CairoUtilities.h \
    24352437        WebCore/platform/graphics/gtk/FontGtk.cpp \
    24362438        WebCore/platform/graphics/gtk/IconGtk.cpp \
     2439        WebCore/platform/graphics/gtk/ImageBufferGtk.cpp \
    24372440        WebCore/platform/graphics/gtk/ImageGtk.cpp \
    24382441        WebCore/platform/graphics/gtk/IntPointGtk.cpp \
  • trunk/WebCore/platform/MIMETypeRegistry.cpp

    r63239 r64506  
    157157
    158158    supportedImageMIMETypesForEncoding->remove("application/octet-stream");
     159#elif PLATFORM(GTK)
     160    supportedImageMIMETypesForEncoding->add("image/png");
     161    supportedImageMIMETypesForEncoding->add("image/jpeg");
     162    supportedImageMIMETypesForEncoding->add("image/tiff");
     163    supportedImageMIMETypesForEncoding->add("image/bmp");
     164    supportedImageMIMETypesForEncoding->add("image/ico");
    159165#elif PLATFORM(CAIRO)
    160166    supportedImageMIMETypesForEncoding->add("image/png");
  • trunk/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp

    r60675 r64506  
    278278}
    279279
     280#if !PLATFORM(GTK)
    280281static cairo_status_t writeFunction(void* closure, const unsigned char* data, unsigned int length)
    281282{
     
    304305    return "data:" + actualMimeType + ";base64," + String(out.data(), out.size());
    305306}
     307#endif
    306308
    307309} // namespace WebCore
  • trunk/WebCore/platform/graphics/gtk/ImageGtk.cpp

    r59868 r64506  
    2727
    2828#include "BitmapImage.h"
     29#include "CairoUtilities.h"
    2930#include "GOwnPtr.h"
    3031#include "SharedBuffer.h"
     
    173174}
    174175
    175 static inline unsigned char* getCairoSurfacePixel(unsigned char* data, unsigned x, unsigned y, unsigned rowStride)
    176 {
    177     return data + (y * rowStride) + x * 4;
    178 }
    179 
    180 static inline guchar* getGdkPixbufPixel(guchar* data, unsigned x, unsigned y, unsigned rowStride)
    181 {
    182     return data + (y * rowStride) + x * 4;
    183 }
    184 
    185176GdkPixbuf* BitmapImage::getGdkPixbuf()
    186177{
    187     int width = cairo_image_surface_get_width(frameAtIndex(currentFrame()));
    188     int height = cairo_image_surface_get_height(frameAtIndex(currentFrame()));
    189     unsigned char* surfaceData = cairo_image_surface_get_data(frameAtIndex(currentFrame()));
    190     int surfaceRowStride = cairo_image_surface_get_stride(frameAtIndex(currentFrame()));
    191 
    192     GdkPixbuf* dest = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
    193     if (!dest)
    194         return 0;
    195 
    196     guchar* pixbufData = gdk_pixbuf_get_pixels(dest);
    197     int pixbufRowStride = gdk_pixbuf_get_rowstride(dest);
    198 
    199     /* From: http://cairographics.org/manual/cairo-image-surface.html#cairo-format-t
    200      * "CAIRO_FORMAT_ARGB32: each pixel is a 32-bit quantity, with alpha in
    201      * the upper 8 bits, then red, then green, then blue. The 32-bit
    202      * quantities are stored native-endian. Pre-multiplied alpha is used.
    203      * (That is, 50% transparent red is 0x80800000, not 0x80ff0000.)"
    204      *
    205      * See http://developer.gimp.org/api/2.0/gdk-pixbuf/gdk-pixbuf-gdk-pixbuf.html#GdkPixbuf
    206      * for information on the structure of GdkPixbufs stored with GDK_COLORSPACE_RGB.
    207      *
    208      * RGB color channels in CAIRO_FORMAT_ARGB32 are stored based on the
    209      * endianness of the machine and are also multiplied by the alpha channel.
    210      * To properly transfer the data from the Cairo surface we must divide each
    211      * of the RGB channels by the alpha channel and then reorder all channels
    212      * if this machine is little-endian.
    213      */
    214     for (int y = 0; y < height; y++) {
    215         for (int x = 0; x < width; x++) {
    216             unsigned char* source = getCairoSurfacePixel(surfaceData, x, y, surfaceRowStride);
    217             guchar* dest = getGdkPixbufPixel(pixbufData, x, y, pixbufRowStride);
    218 
    219 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
    220             guchar alpha = source[3];
    221             dest[0] = alpha ? ((source[2] * 255) / alpha) : 0;
    222             dest[1] = alpha ? ((source[1] * 255) / alpha) : 0;
    223             dest[2] = alpha ? ((source[0] * 255) / alpha) : 0;
    224             dest[3] = alpha;
    225 #else
    226             guchar alpha = source[0];
    227             dest[0] = alpha ? ((source[1] * 255) / alpha) : 0;
    228             dest[1] = alpha ? ((source[2] * 255) / alpha) : 0;
    229             dest[2] = alpha ? ((source[3] * 255) / alpha) : 0;
    230             dest[3] = alpha;
    231 #endif
    232         }
    233     }
    234 
    235     return dest;
     178    return cairoImageSurfaceToGdkPixbuf(frameAtIndex(currentFrame()));
    236179}
    237180
Note: See TracChangeset for help on using the changeset viewer.