Commit 91a30f42 authored by Carlos Garcia Campos's avatar Carlos Garcia Campos

[libdocument] Use gdk_pixbuf_get_from_surface() instead of our own implementation

parent 82415a85
......@@ -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 *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment