summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/eom-print-preview.c96
1 files changed, 3 insertions, 93 deletions
diff --git a/src/eom-print-preview.c b/src/eom-print-preview.c
index 383b633..02f4927 100644
--- a/src/eom-print-preview.c
+++ b/src/eom-print-preview.c
@@ -683,98 +683,6 @@ create_preview_buffer (EomPrintPreview *preview)
return pixbuf;
}
-/*
- Function inspired from gdk_cairo_set_source_pixbuf (). The main reason is
- that I want to save the cairo_surface_t created from the scaled buffer to
- improve performance.
-*/
-static cairo_surface_t *
-create_surface_from_pixbuf (GdkPixbuf *pixbuf)
-{
- gint width = gdk_pixbuf_get_width (pixbuf);
- gint height = gdk_pixbuf_get_height (pixbuf);
- guchar *gdk_pixels = gdk_pixbuf_get_pixels (pixbuf);
- int gdk_rowstride = gdk_pixbuf_get_rowstride (pixbuf);
- int n_channels = gdk_pixbuf_get_n_channels (pixbuf);
- int cairo_stride;
- guchar *cairo_pixels;
- cairo_format_t format;
- cairo_surface_t *surface;
- static const cairo_user_data_key_t key;
- int j;
-
- if (n_channels == 3)
- format = CAIRO_FORMAT_RGB24;
- else
- format = CAIRO_FORMAT_ARGB32;
-
- cairo_stride = cairo_format_stride_for_width (format, width);
- cairo_pixels = g_malloc_n (height, cairo_stride);
- surface = cairo_image_surface_create_for_data ((unsigned char *)cairo_pixels,
- format,
- width, height, cairo_stride);
- cairo_surface_set_user_data (surface, &key,
- cairo_pixels, (cairo_destroy_func_t)g_free);
-
- for (j = height; j; j--)
- {
- guchar *p = gdk_pixels;
- guchar *q = cairo_pixels;
-
- if (n_channels == 3)
- {
- guchar *end = p + 3 * width;
-
- while (p < end)
- {
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN
- q[0] = p[2];
- q[1] = p[1];
- q[2] = p[0];
-#else
- q[1] = p[0];
- q[2] = p[1];
- q[3] = p[2];
-#endif
- p += 3;
- q += 4;
- }
- }
- else
- {
- guchar *end = p + 4 * width;
- guint t1,t2,t3;
-
-#define MULT(d,c,a,t) G_STMT_START { t = c * a + 0x7f; d = ((t >> 8) + t) >> 8; } G_STMT_END
-
- while (p < end)
- {
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN
- MULT(q[0], p[2], p[3], t1);
- MULT(q[1], p[1], p[3], t2);
- MULT(q[2], p[0], p[3], t3);
- q[3] = p[3];
-#else
- q[0] = p[3];
- MULT(q[1], p[0], p[3], t1);
- MULT(q[2], p[1], p[3], t2);
- MULT(q[3], p[2], p[3], t3);
-#endif
-
- p += 4;
- q += 4;
- }
-
-#undef MULT
- }
-
- gdk_pixels += gdk_rowstride;
- cairo_pixels += cairo_stride;
- }
-
- return surface;
-}
-
static void
create_surface (EomPrintPreview *preview)
{
@@ -788,7 +696,9 @@ create_surface (EomPrintPreview *preview)
pixbuf = create_preview_buffer (preview);
if (pixbuf) {
- priv->surface = create_surface_from_pixbuf (pixbuf);
+ priv->surface =
+ gdk_cairo_surface_create_from_pixbuf (pixbuf, 0,
+ gtk_widget_get_window (GTK_WIDGET (preview)));
g_object_unref (pixbuf);
}
priv->flag_create_surface = FALSE;