From 91a30f422e1e1be27bf85e076c2207cfc23c3e0b Mon Sep 17 00:00:00 2001 From: Carlos Garcia Campos Date: Sun, 10 Oct 2010 11:17:41 +0200 Subject: [PATCH] [libdocument] Use gdk_pixbuf_get_from_surface() instead of our own implementation --- libdocument/ev-document-misc.c | 66 +++------------------------------- 1 file changed, 4 insertions(+), 62 deletions(-) diff --git a/libdocument/ev-document-misc.c b/libdocument/ev-document-misc.c index d597127f..bfba1ec8 100644 --- a/libdocument/ev-document-misc.c +++ b/libdocument/ev-document-misc.c @@ -195,68 +195,10 @@ ev_document_misc_surface_from_pixbuf (GdkPixbuf *pixbuf) GdkPixbuf * ev_document_misc_pixbuf_from_surface (cairo_surface_t *surface) { - GdkPixbuf *pixbuf; - cairo_surface_t *image; - cairo_t *cr; - gboolean has_alpha; - gint width, height; - cairo_format_t surface_format; - gint pixbuf_n_channels; - gint pixbuf_rowstride; - guchar *pixbuf_pixels; - gint x, y; - - width = cairo_image_surface_get_width (surface); - height = cairo_image_surface_get_height (surface); - - surface_format = cairo_image_surface_get_format (surface); - has_alpha = (surface_format == CAIRO_FORMAT_ARGB32); - - pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, - TRUE, 8, - width, height); - pixbuf_n_channels = gdk_pixbuf_get_n_channels (pixbuf); - pixbuf_rowstride = gdk_pixbuf_get_rowstride (pixbuf); - pixbuf_pixels = gdk_pixbuf_get_pixels (pixbuf); - - image = cairo_image_surface_create_for_data (pixbuf_pixels, - surface_format, - width, height, - pixbuf_rowstride); - cr = cairo_create (image); - cairo_set_source_surface (cr, surface, 0, 0); - - if (has_alpha) - cairo_mask_surface (cr, surface, 0, 0); - else - cairo_paint (cr); - - cairo_destroy (cr); - cairo_surface_destroy (image); - - for (y = 0; y < height; y++) { - guchar *p = pixbuf_pixels + y * pixbuf_rowstride; - - for (x = 0; x < width; x++) { - guchar tmp; - -#if G_BYTE_ORDER == G_LITTLE_ENDIAN - tmp = p[0]; - p[0] = p[2]; - p[2] = tmp; - p[3] = (has_alpha) ? p[3] : 0xff; -#else - tmp = p[0]; - p[0] = p[1]; - p[1] = p[2]; - p[2] = p[3]; - p[3] = (has_alpha) ? tmp : 0xff; -#endif - p += pixbuf_n_channels; - } - } - - return pixbuf; + return gdk_pixbuf_get_from_surface (surface, + 0, 0, + cairo_image_surface_get_width (surface), + cairo_image_surface_get_height (surface)); } cairo_surface_t * -- 2.43.5