Skip to content

Commit

Permalink
libdocument: Use gdk_pixbuf_get_from_surface()
Browse files Browse the repository at this point in the history
....instead of our own implementation

origin commit:
https://git.gnome.org/browse/evince/commit/?h=gnome-3-0&id=91a30f4
  • Loading branch information
Carlos Garcia Campos authored and raveit65 committed Apr 8, 2018
1 parent 62ca1c0 commit 73ca242
Showing 1 changed file with 4 additions and 62 deletions.
66 changes: 4 additions & 62 deletions libdocument/ev-document-misc.c
Expand Up @@ -229,68 +229,10 @@ ev_document_misc_pixbuf_from_surface (cairo_surface_t *surface)
{
g_return_val_if_fail (surface, NULL);

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 *
Expand Down

0 comments on commit 73ca242

Please sign in to comment.