1 From 69f69eed816b89be9a01a48a1f0643d1fd496118 Mon Sep 17 00:00:00 2001
2 From: Nils Philippsen <nils@redhat.com>
3 Date: Fri, 6 May 2011 11:58:44 +0200
4 Subject: [PATCH] patch: poppler-0.17
6 Squashed commit of the following:
8 commit 529d940222dfc352d41fbf72de29134421aa4002
9 Author: Nils Philippsen <nils@redhat.com>
10 Date: Fri May 6 11:50:30 2011 +0200
12 use code based on pixbufs instead of cairo surfaces
14 this is done to avoid adding to libgimp, thanks to Mukund Sivaraman for
17 commit f8671d8767d4cdab830dc06310e96c63a88ec0fd
18 Author: Mukund Sivaraman <muks@banu.com>
19 Date: Thu Apr 21 13:57:13 2011 +0530
21 file-pdf-load: Update attribution, removing bogus copyright
22 (cherry picked from commit e999122e0b20b6ccd6bde3ce039bb64068fc0019)
24 commit 89a78f2590d298dac2f42e6d9a3016fc5d672c70
25 Author: Nils Philippsen <nils@redhat.com>
26 Date: Thu Apr 21 13:52:18 2011 +0200
28 file-pdf-load: Use better API + cleanups
30 * fixes issues with poppler 0.17 completely
31 * uses new libgimp API to pass surfaces instead of pixbufs
32 * uses GTK+ 3 API to convert surfaces to pixbufs where available
33 (backported from commit 7bdadd80ba479d6ff904e276d805e16f6b940ee2)
35 commit 4e92302c4a14a961f112587a0ad86696c88da2f8
36 Author: Nils Philippsen <nils@redhat.com>
37 Date: Thu Apr 21 13:38:08 2011 +0200
39 file-pdf-load: Don't use deprecated API (bug #646947)
41 (cherry picked from commit 9b3e1c91fd2eac69da6947ec9c7fbf10096ba237)
45 plug-ins/common/file-pdf.c
47 plug-ins/common/file-pdf.c | 323 ++++++++++++++++++++++++++++++++++++++------
48 1 files changed, 283 insertions(+), 40 deletions(-)
50 diff --git a/plug-ins/common/file-pdf.c b/plug-ins/common/file-pdf.c
51 index a43b459..43c2b7d 100644
52 --- a/plug-ins/common/file-pdf.c
53 +++ b/plug-ins/common/file-pdf.c
56 * Copyright (C) 2005 Nathan Summers
58 + * Some code in render_page_to_surface() borrowed from
59 + * poppler.git/glib/poppler-page.cc.
61 * This program is free software; you can redistribute it and/or modify
62 * it under the terms of the GNU General Public License as published by
63 * the Free Software Foundation; either version 2 of the License, or
64 @@ -80,16 +83,20 @@ static gboolean load_dialog (PopplerDocument *doc,
65 static PopplerDocument * open_document (const gchar *filename,
68 -static GdkPixbuf * get_thumbnail (PopplerDocument *doc,
69 +static cairo_surface_t * get_thumb_surface (PopplerDocument *doc,
71 + gint preferred_size);
73 +static GdkPixbuf * get_thumb_pixbuf (PopplerDocument *doc,
77 static gint32 layer_from_pixbuf (gint32 image,
78 - const gchar *layer_name,
81 - gdouble progress_start,
82 - gdouble progress_scale);
83 + const gchar *layer_name,
86 + gdouble progress_start,
87 + gdouble progress_scale);
90 ** the following was formerly part of
91 @@ -433,11 +440,12 @@ run (const gchar *name,
99 - GdkPixbuf *pixbuf = NULL;
101 + gdouble height = 0;
104 + gint num_pages = 0;
105 + GdkPixbuf *pixbuf = NULL;
107 /* Possibly retrieve last settings */
108 gimp_get_data (LOAD_PROC, &loadvals);
109 @@ -455,7 +463,10 @@ run (const gchar *name,
110 g_object_unref (page);
113 - pixbuf = get_thumbnail (doc, 0, param[1].data.d_int32);
114 + num_pages = poppler_document_get_n_pages (doc);
116 + pixbuf = get_thumb_pixbuf (doc, 0, param[1].data.d_int32);
118 g_object_unref (doc);
121 @@ -548,6 +559,187 @@ open_document (const gchar *filename,
125 +/* FIXME: Remove this someday when we depend fully on GTK+ >= 3 */
127 +#if (!GTK_CHECK_VERSION (3, 0, 0))
129 +static cairo_format_t
130 +gdk_cairo_format_for_content (cairo_content_t content)
134 + case CAIRO_CONTENT_COLOR:
135 + return CAIRO_FORMAT_RGB24;
136 + case CAIRO_CONTENT_ALPHA:
137 + return CAIRO_FORMAT_A8;
138 + case CAIRO_CONTENT_COLOR_ALPHA:
140 + return CAIRO_FORMAT_ARGB32;
144 +static cairo_surface_t *
145 +gdk_cairo_surface_coerce_to_image (cairo_surface_t *surface,
146 + cairo_content_t content,
152 + cairo_surface_t *copy;
155 + copy = cairo_image_surface_create (gdk_cairo_format_for_content (content),
159 + cr = cairo_create (copy);
160 + cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
161 + cairo_set_source_surface (cr, surface, -src_x, -src_y);
163 + cairo_destroy (cr);
169 +convert_alpha (guchar *dest_data,
180 + src_data += src_stride * src_y + src_x * 4;
182 + for (y = 0; y < height; y++) {
183 + guint32 *src = (guint32 *) src_data;
185 + for (x = 0; x < width; x++) {
186 + guint alpha = src[x] >> 24;
190 + dest_data[x * 4 + 0] = 0;
191 + dest_data[x * 4 + 1] = 0;
192 + dest_data[x * 4 + 2] = 0;
196 + dest_data[x * 4 + 0] = (((src[x] & 0xff0000) >> 16) * 255 + alpha / 2) / alpha;
197 + dest_data[x * 4 + 1] = (((src[x] & 0x00ff00) >> 8) * 255 + alpha / 2) / alpha;
198 + dest_data[x * 4 + 2] = (((src[x] & 0x0000ff) >> 0) * 255 + alpha / 2) / alpha;
200 + dest_data[x * 4 + 3] = alpha;
203 + src_data += src_stride;
204 + dest_data += dest_stride;
209 +convert_no_alpha (guchar *dest_data,
220 + src_data += src_stride * src_y + src_x * 4;
222 + for (y = 0; y < height; y++) {
223 + guint32 *src = (guint32 *) src_data;
225 + for (x = 0; x < width; x++) {
226 + dest_data[x * 3 + 0] = src[x] >> 16;
227 + dest_data[x * 3 + 1] = src[x] >> 8;
228 + dest_data[x * 3 + 2] = src[x];
231 + src_data += src_stride;
232 + dest_data += dest_stride;
237 + * gdk_pixbuf_get_from_surface:
238 + * @surface: surface to copy from
239 + * @src_x: Source X coordinate within @surface
240 + * @src_y: Source Y coordinate within @surface
241 + * @width: Width in pixels of region to get
242 + * @height: Height in pixels of region to get
244 + * Transfers image data from a #cairo_surface_t and converts it to an RGB(A)
245 + * representation inside a #GdkPixbuf. This allows you to efficiently read
246 + * individual pixels from cairo surfaces. For #GdkWindows, use
247 + * gdk_pixbuf_get_from_window() instead.
249 + * This function will create an RGB pixbuf with 8 bits per channel.
250 + * The pixbuf will contain an alpha channel if the @surface contains one.
252 + * Return value: (transfer full): A newly-created pixbuf with a reference
253 + * count of 1, or %NULL on error
256 +gdk_pixbuf_get_from_surface (cairo_surface_t *surface,
262 + cairo_content_t content;
265 + /* General sanity checks */
266 + g_return_val_if_fail (surface != NULL, NULL);
267 + g_return_val_if_fail (width > 0 && height > 0, NULL);
269 + content = cairo_surface_get_content (surface) | CAIRO_CONTENT_COLOR;
270 + dest = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
271 + !!(content & CAIRO_CONTENT_ALPHA),
275 + surface = gdk_cairo_surface_coerce_to_image (surface, content,
278 + cairo_surface_flush (surface);
279 + if (cairo_surface_status (surface) || dest == NULL)
281 + cairo_surface_destroy (surface);
285 + if (gdk_pixbuf_get_has_alpha (dest))
286 + convert_alpha (gdk_pixbuf_get_pixels (dest),
287 + gdk_pixbuf_get_rowstride (dest),
288 + cairo_image_surface_get_data (surface),
289 + cairo_image_surface_get_stride (surface),
293 + convert_no_alpha (gdk_pixbuf_get_pixels (dest),
294 + gdk_pixbuf_get_rowstride (dest),
295 + cairo_image_surface_get_data (surface),
296 + cairo_image_surface_get_stride (surface),
300 + cairo_surface_destroy (surface);
307 layer_from_pixbuf (gint32 image,
308 const gchar *layer_name,
309 @@ -566,6 +758,54 @@ layer_from_pixbuf (gint32 image,
313 +static cairo_surface_t *
314 +render_page_to_surface (PopplerPage *page,
319 + cairo_surface_t *surface;
322 + surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
323 + cr = cairo_create (surface);
326 + cairo_translate (cr, 0.0, 0.0);
329 + cairo_scale (cr, scale, scale);
331 + poppler_page_render (page, cr);
332 + cairo_restore (cr);
334 + cairo_set_operator (cr, CAIRO_OPERATOR_DEST_OVER);
335 + cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
338 + cairo_destroy (cr);
344 +render_page_to_pixbuf (PopplerPage *page,
350 + cairo_surface_t *surface;
352 + surface = render_page_to_surface (page, width, height, scale);
353 + pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0,
354 + cairo_image_surface_get_width (surface),
355 + cairo_image_surface_get_height (surface));
356 + cairo_surface_destroy (surface);
362 load_image (PopplerDocument *doc,
363 const gchar *filename,
364 @@ -597,7 +837,7 @@ load_image (PopplerDocument *doc,
373 @@ -627,15 +867,13 @@ load_image (PopplerDocument *doc,
374 gimp_image_set_resolution (image_ID, resolution, resolution);
377 - buf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, width, height);
379 - poppler_page_render_to_pixbuf (page, 0, 0, width, height, scale, 0, buf);
380 + pixbuf = render_page_to_pixbuf (page, width, height, scale);
382 - layer_from_pixbuf (image_ID, page_label, i, buf,
383 + layer_from_pixbuf (image_ID, page_label, i, pixbuf,
384 doc_progress, 1.0 / pages->n_pages);
387 - g_object_unref (buf);
388 + g_object_unref(pixbuf);
390 doc_progress = (double) (i + 1) / pages->n_pages;
391 gimp_progress_update (doc_progress);
392 @@ -676,30 +914,22 @@ load_image (PopplerDocument *doc,
397 -get_thumbnail (PopplerDocument *doc,
399 - gint preferred_size)
400 +static cairo_surface_t *
401 +get_thumb_surface (PopplerDocument *doc,
403 + gint preferred_size)
407 + cairo_surface_t *surface;
409 page = poppler_document_get_page (doc, page_num);
414 - /* XXX: Remove conditional when we depend on poppler 0.8.0, but also
415 - * add configure check to make sure POPPLER_WITH_GDK is enabled!
417 -#ifdef POPPLER_WITH_GDK
418 - pixbuf = poppler_page_get_thumbnail_pixbuf (page);
420 - pixbuf = poppler_page_get_thumbnail (page);
423 + surface = poppler_page_get_thumbnail (page);
430 @@ -712,15 +942,28 @@ get_thumbnail (PopplerDocument *doc,
434 - pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8,
437 - poppler_page_render_to_pixbuf (page,
438 - 0, 0, width, height, scale, 0, pixbuf);
439 + surface = render_page_to_surface (page, width, height, scale);
442 g_object_unref (page);
448 +get_thumb_pixbuf (PopplerDocument *doc,
450 + gint preferred_size)
452 + cairo_surface_t *surface;
455 + surface = get_thumb_surface (doc, page_num, preferred_size);
456 + pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0,
457 + cairo_image_surface_get_width (surface),
458 + cairo_image_surface_get_height (surface));
459 + cairo_surface_destroy (surface);
464 @@ -769,8 +1012,8 @@ thumbnail_thread (gpointer data)
465 idle_data->page_no = i;
467 /* FIXME get preferred size from somewhere? */
468 - idle_data->pixbuf = get_thumbnail (thread_data->document, i,
470 + idle_data->pixbuf = get_thumb_pixbuf (thread_data->document, i,
473 g_idle_add (idle_set_thumbnail, idle_data);