diff options
Diffstat (limited to 'WebCore/platform/graphics/gtk/GdkCairoUtilities.cpp')
-rw-r--r-- | WebCore/platform/graphics/gtk/GdkCairoUtilities.cpp | 63 |
1 files changed, 4 insertions, 59 deletions
diff --git a/WebCore/platform/graphics/gtk/GdkCairoUtilities.cpp b/WebCore/platform/graphics/gtk/GdkCairoUtilities.cpp index d768ce2..d8018a3 100644 --- a/WebCore/platform/graphics/gtk/GdkCairoUtilities.cpp +++ b/WebCore/platform/graphics/gtk/GdkCairoUtilities.cpp @@ -25,70 +25,15 @@ #include "config.h" #include "GdkCairoUtilities.h" +#include "GtkVersioning.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; + return gdk_pixbuf_get_from_surface(surface, 0, 0, + cairo_image_surface_get_width(surface), + cairo_image_surface_get_height(surface)); } |