Gentoo Archives: gentoo-commits

From: "Sebastian Pipping (sping)" <sping@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in media-gfx/gimp/files: gimp-2.6.11-poppler-0.17.patch
Date: Thu, 29 Sep 2011 16:13:47
Message-Id: 20110929161330.A4BDD2004C@flycatcher.gentoo.org
1 sping 11/09/29 16:13:30
2
3 Added: gimp-2.6.11-poppler-0.17.patch
4 Log:
5 media-gfx/gimp: Fix compilation against recent poppler (bug #384903)
6
7 (Portage version: 2.1.10.19/cvs/Linux x86_64)
8
9 Revision Changes Path
10 1.1 media-gfx/gimp/files/gimp-2.6.11-poppler-0.17.patch
11
12 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/media-gfx/gimp/files/gimp-2.6.11-poppler-0.17.patch?rev=1.1&view=markup
13 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/media-gfx/gimp/files/gimp-2.6.11-poppler-0.17.patch?rev=1.1&content-type=text/plain
14
15 Index: gimp-2.6.11-poppler-0.17.patch
16 ===================================================================
17 From 69f69eed816b89be9a01a48a1f0643d1fd496118 Mon Sep 17 00:00:00 2001
18 From: Nils Philippsen <nils@××××××.com>
19 Date: Fri, 6 May 2011 11:58:44 +0200
20 Subject: [PATCH] patch: poppler-0.17
21
22 Squashed commit of the following:
23
24 commit 529d940222dfc352d41fbf72de29134421aa4002
25 Author: Nils Philippsen <nils@××××××.com>
26 Date: Fri May 6 11:50:30 2011 +0200
27
28 use code based on pixbufs instead of cairo surfaces
29
30 this is done to avoid adding to libgimp, thanks to Mukund Sivaraman for
31 hints how to do this
32
33 commit f8671d8767d4cdab830dc06310e96c63a88ec0fd
34 Author: Mukund Sivaraman <muks@××××.com>
35 Date: Thu Apr 21 13:57:13 2011 +0530
36
37 file-pdf-load: Update attribution, removing bogus copyright
38 (cherry picked from commit e999122e0b20b6ccd6bde3ce039bb64068fc0019)
39
40 commit 89a78f2590d298dac2f42e6d9a3016fc5d672c70
41 Author: Nils Philippsen <nils@××××××.com>
42 Date: Thu Apr 21 13:52:18 2011 +0200
43
44 file-pdf-load: Use better API + cleanups
45
46 * fixes issues with poppler 0.17 completely
47 * uses new libgimp API to pass surfaces instead of pixbufs
48 * uses GTK+ 3 API to convert surfaces to pixbufs where available
49 (backported from commit 7bdadd80ba479d6ff904e276d805e16f6b940ee2)
50
51 commit 4e92302c4a14a961f112587a0ad86696c88da2f8
52 Author: Nils Philippsen <nils@××××××.com>
53 Date: Thu Apr 21 13:38:08 2011 +0200
54
55 file-pdf-load: Don't use deprecated API (bug #646947)
56
57 (cherry picked from commit 9b3e1c91fd2eac69da6947ec9c7fbf10096ba237)
58
59 Conflicts:
60
61 plug-ins/common/file-pdf.c
62 ---
63 plug-ins/common/file-pdf.c | 323 ++++++++++++++++++++++++++++++++++++++------
64 1 files changed, 283 insertions(+), 40 deletions(-)
65
66 diff --git a/plug-ins/common/file-pdf.c b/plug-ins/common/file-pdf.c
67 index a43b459..43c2b7d 100644
68 --- a/plug-ins/common/file-pdf.c
69 +++ b/plug-ins/common/file-pdf.c
70 @@ -4,6 +4,9 @@
71 *
72 * Copyright (C) 2005 Nathan Summers
73 *
74 + * Some code in render_page_to_surface() borrowed from
75 + * poppler.git/glib/poppler-page.cc.
76 + *
77 * This program is free software; you can redistribute it and/or modify
78 * it under the terms of the GNU General Public License as published by
79 * the Free Software Foundation; either version 2 of the License, or
80 @@ -80,16 +83,20 @@ static gboolean load_dialog (PopplerDocument *doc,
81 static PopplerDocument * open_document (const gchar *filename,
82 GError **error);
83
84 -static GdkPixbuf * get_thumbnail (PopplerDocument *doc,
85 +static cairo_surface_t * get_thumb_surface (PopplerDocument *doc,
86 + gint page,
87 + gint preferred_size);
88 +
89 +static GdkPixbuf * get_thumb_pixbuf (PopplerDocument *doc,
90 gint page,
91 gint preferred_size);
92
93 static gint32 layer_from_pixbuf (gint32 image,
94 - const gchar *layer_name,
95 - gint position,
96 - GdkPixbuf *buf,
97 - gdouble progress_start,
98 - gdouble progress_scale);
99 + const gchar *layer_name,
100 + gint position,
101 + GdkPixbuf *pixbuf,
102 + gdouble progress_start,
103 + gdouble progress_scale);
104
105 /**
106 ** the following was formerly part of
107 @@ -433,11 +440,12 @@ run (const gchar *name,
108 }
109 else
110 {
111 - gdouble width = 0;
112 - gdouble height = 0;
113 - gdouble scale;
114 - gint32 image = -1;
115 - GdkPixbuf *pixbuf = NULL;
116 + gdouble width = 0;
117 + gdouble height = 0;
118 + gdouble scale;
119 + gint32 image = -1;
120 + gint num_pages = 0;
121 + GdkPixbuf *pixbuf = NULL;
122
123 /* Possibly retrieve last settings */
124 gimp_get_data (LOAD_PROC, &loadvals);
125 @@ -455,7 +463,10 @@ run (const gchar *name,
126 g_object_unref (page);
127 }
128
129 - pixbuf = get_thumbnail (doc, 0, param[1].data.d_int32);
130 + num_pages = poppler_document_get_n_pages (doc);
131 +
132 + pixbuf = get_thumb_pixbuf (doc, 0, param[1].data.d_int32);
133 +
134 g_object_unref (doc);
135 }
136
137 @@ -548,6 +559,187 @@ open_document (const gchar *filename,
138 return doc;
139 }
140
141 +/* FIXME: Remove this someday when we depend fully on GTK+ >= 3 */
142 +
143 +#if (!GTK_CHECK_VERSION (3, 0, 0))
144 +
145 +static cairo_format_t
146 +gdk_cairo_format_for_content (cairo_content_t content)
147 +{
148 + switch (content)
149 + {
150 + case CAIRO_CONTENT_COLOR:
151 + return CAIRO_FORMAT_RGB24;
152 + case CAIRO_CONTENT_ALPHA:
153 + return CAIRO_FORMAT_A8;
154 + case CAIRO_CONTENT_COLOR_ALPHA:
155 + default:
156 + return CAIRO_FORMAT_ARGB32;
157 + }
158 +}
159 +
160 +static cairo_surface_t *
161 +gdk_cairo_surface_coerce_to_image (cairo_surface_t *surface,
162 + cairo_content_t content,
163 + int src_x,
164 + int src_y,
165 + int width,
166 + int height)
167 +{
168 + cairo_surface_t *copy;
169 + cairo_t *cr;
170 +
171 + copy = cairo_image_surface_create (gdk_cairo_format_for_content (content),
172 + width,
173 + height);
174 +
175 + cr = cairo_create (copy);
176 + cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
177 + cairo_set_source_surface (cr, surface, -src_x, -src_y);
178 + cairo_paint (cr);
179 + cairo_destroy (cr);
180 +
181 + return copy;
182 +}
183 +
184 +static void
185 +convert_alpha (guchar *dest_data,
186 + int dest_stride,
187 + guchar *src_data,
188 + int src_stride,
189 + int src_x,
190 + int src_y,
191 + int width,
192 + int height)
193 +{
194 + int x, y;
195 +
196 + src_data += src_stride * src_y + src_x * 4;
197 +
198 + for (y = 0; y < height; y++) {
199 + guint32 *src = (guint32 *) src_data;
200 +
201 + for (x = 0; x < width; x++) {
202 + guint alpha = src[x] >> 24;
203 +
204 + if (alpha == 0)
205 + {
206 + dest_data[x * 4 + 0] = 0;
207 + dest_data[x * 4 + 1] = 0;
208 + dest_data[x * 4 + 2] = 0;
209 + }
210 + else
211 + {
212 + dest_data[x * 4 + 0] = (((src[x] & 0xff0000) >> 16) * 255 + alpha / 2) / alpha;
213 + dest_data[x * 4 + 1] = (((src[x] & 0x00ff00) >> 8) * 255 + alpha / 2) / alpha;
214 + dest_data[x * 4 + 2] = (((src[x] & 0x0000ff) >> 0) * 255 + alpha / 2) / alpha;
215 + }
216 + dest_data[x * 4 + 3] = alpha;
217 + }
218 +
219 + src_data += src_stride;
220 + dest_data += dest_stride;
221 + }
222 +}
223 +
224 +static void
225 +convert_no_alpha (guchar *dest_data,
226 + int dest_stride,
227 + guchar *src_data,
228 + int src_stride,
229 + int src_x,
230 + int src_y,
231 + int width,
232 + int height)
233 +{
234 + int x, y;
235 +
236 + src_data += src_stride * src_y + src_x * 4;
237 +
238 + for (y = 0; y < height; y++) {
239 + guint32 *src = (guint32 *) src_data;
240 +
241 + for (x = 0; x < width; x++) {
242 + dest_data[x * 3 + 0] = src[x] >> 16;
243 + dest_data[x * 3 + 1] = src[x] >> 8;
244 + dest_data[x * 3 + 2] = src[x];
245 + }
246 +
247 + src_data += src_stride;
248 + dest_data += dest_stride;
249 + }
250 +}
251 +
252 +/**
253 + * gdk_pixbuf_get_from_surface:
254 + * @surface: surface to copy from
255 + * @src_x: Source X coordinate within @surface
256 + * @src_y: Source Y coordinate within @surface
257 + * @width: Width in pixels of region to get
258 + * @height: Height in pixels of region to get
259 + *
260 + * Transfers image data from a #cairo_surface_t and converts it to an RGB(A)
261 + * representation inside a #GdkPixbuf. This allows you to efficiently read
262 + * individual pixels from cairo surfaces. For #GdkWindows, use
263 + * gdk_pixbuf_get_from_window() instead.
264 + *
265 + * This function will create an RGB pixbuf with 8 bits per channel.
266 + * The pixbuf will contain an alpha channel if the @surface contains one.
267 + *
268 + * Return value: (transfer full): A newly-created pixbuf with a reference
269 + * count of 1, or %NULL on error
270 + */
271 +static GdkPixbuf *
272 +gdk_pixbuf_get_from_surface (cairo_surface_t *surface,
273 + gint src_x,
274 + gint src_y,
275 + gint width,
276 + gint height)
277 +{
278 + cairo_content_t content;
279 + GdkPixbuf *dest;
280 +
281 + /* General sanity checks */
282 + g_return_val_if_fail (surface != NULL, NULL);
283 + g_return_val_if_fail (width > 0 && height > 0, NULL);
284 +
285 + content = cairo_surface_get_content (surface) | CAIRO_CONTENT_COLOR;
286 + dest = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
287 + !!(content & CAIRO_CONTENT_ALPHA),
288 + 8,
289 + width, height);
290 +
291 + surface = gdk_cairo_surface_coerce_to_image (surface, content,
292 + src_x, src_y,
293 + width, height);
294 + cairo_surface_flush (surface);
295 + if (cairo_surface_status (surface) || dest == NULL)
296 + {
297 + cairo_surface_destroy (surface);
298 + return NULL;
299 + }
300 +
301 + if (gdk_pixbuf_get_has_alpha (dest))
302 + convert_alpha (gdk_pixbuf_get_pixels (dest),
303 + gdk_pixbuf_get_rowstride (dest),
304 + cairo_image_surface_get_data (surface),
305 + cairo_image_surface_get_stride (surface),
306 + 0, 0,
307 + width, height);
308 + else
309 + convert_no_alpha (gdk_pixbuf_get_pixels (dest),
310 + gdk_pixbuf_get_rowstride (dest),
311 + cairo_image_surface_get_data (surface),
312 + cairo_image_surface_get_stride (surface),
313 + 0, 0,
314 + width, height);
315 +
316 + cairo_surface_destroy (surface);
317 + return dest;
318 +}
319 +
320 +#endif
321 +
322 static gint32
323 layer_from_pixbuf (gint32 image,
324 const gchar *layer_name,
325 @@ -566,6 +758,54 @@ layer_from_pixbuf (gint32 image,
326 return layer;
327 }
328
329 +static cairo_surface_t *
330 +render_page_to_surface (PopplerPage *page,
331 + int width,
332 + int height,
333 + double scale)
334 +{
335 + cairo_surface_t *surface;
336 + cairo_t *cr;
337 +
338 + surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
339 + cr = cairo_create (surface);
340 +
341 + cairo_save (cr);
342 + cairo_translate (cr, 0.0, 0.0);
343 +
344 + if (scale != 1.0)
345 + cairo_scale (cr, scale, scale);
346 +
347 + poppler_page_render (page, cr);
348 + cairo_restore (cr);
349 +
350 + cairo_set_operator (cr, CAIRO_OPERATOR_DEST_OVER);
351 + cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
352 + cairo_paint (cr);
353 +
354 + cairo_destroy (cr);
355 +
356 + return surface;
357 +}
358 +
359 +static GdkPixbuf *
360 +render_page_to_pixbuf (PopplerPage *page,
361 + int width,
362 + int height,
363 + double scale)
364 +{
365 + GdkPixbuf *pixbuf;
366 + cairo_surface_t *surface;
367 +
368 + surface = render_page_to_surface (page, width, height, scale);
369 + pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0,
370 + cairo_image_surface_get_width (surface),
371 + cairo_image_surface_get_height (surface));
372 + cairo_surface_destroy (surface);
373 +
374 + return pixbuf;
375 +}
376 +
377 static gint32
378 load_image (PopplerDocument *doc,
379 const gchar *filename,
380 @@ -597,7 +837,7 @@ load_image (PopplerDocument *doc,
381 gdouble page_width;
382 gdouble page_height;
383
384 - GdkPixbuf *buf;
385 + GdkPixbuf *pixbuf;
386 gint width;
387 gint height;
388
389 @@ -627,15 +867,13 @@ load_image (PopplerDocument *doc,
390 gimp_image_set_resolution (image_ID, resolution, resolution);
391 }
392
393 - buf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, width, height);
394 -
395 - poppler_page_render_to_pixbuf (page, 0, 0, width, height, scale, 0, buf);
396 + pixbuf = render_page_to_pixbuf (page, width, height, scale);
397
398 - layer_from_pixbuf (image_ID, page_label, i, buf,
399 + layer_from_pixbuf (image_ID, page_label, i, pixbuf,
400 doc_progress, 1.0 / pages->n_pages);
401
402 g_free (page_label);
403 - g_object_unref (buf);
404 + g_object_unref(pixbuf);
405
406 doc_progress = (double) (i + 1) / pages->n_pages;
407 gimp_progress_update (doc_progress);
408 @@ -676,30 +914,22 @@ load_image (PopplerDocument *doc,
409 return image_ID;
410 }
411
412 -static GdkPixbuf *
413 -get_thumbnail (PopplerDocument *doc,
414 - gint page_num,
415 - gint preferred_size)
416 +static cairo_surface_t *
417 +get_thumb_surface (PopplerDocument *doc,
418 + gint page_num,
419 + gint preferred_size)
420 {
421 PopplerPage *page;
422 - GdkPixbuf *pixbuf;
423 + cairo_surface_t *surface;
424
425 page = poppler_document_get_page (doc, page_num);
426
427 if (! page)
428 return NULL;
429
430 - /* XXX: Remove conditional when we depend on poppler 0.8.0, but also
431 - * add configure check to make sure POPPLER_WITH_GDK is enabled!
432 - */
433 -#ifdef POPPLER_WITH_GDK
434 - pixbuf = poppler_page_get_thumbnail_pixbuf (page);
435 -#else
436 - pixbuf = poppler_page_get_thumbnail (page);
437 -#endif
438 -
439 + surface = poppler_page_get_thumbnail (page);
440
441 - if (! pixbuf)
442 + if (! surface)
443 {
444 gdouble width;
445 gdouble height;
446 @@ -712,15 +942,28 @@ get_thumbnail (PopplerDocument *doc,
447 width *= scale;
448 height *= scale;
449
450 - pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8,
451 - width, height);
452 -
453 - poppler_page_render_to_pixbuf (page,
454 - 0, 0, width, height, scale, 0, pixbuf);
455 + surface = render_page_to_surface (page, width, height, scale);
456 }
457
458 g_object_unref (page);
459
460 + return surface;
461 +}
462 +
463 +static GdkPixbuf *
464 +get_thumb_pixbuf (PopplerDocument *doc,
465 + gint page_num,
466 + gint preferred_size)
467 +{
468 + cairo_surface_t *surface;
469 + GdkPixbuf *pixbuf;
470 +
471 + surface = get_thumb_surface (doc, page_num, preferred_size);
472 + pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0,
473 + cairo_image_surface_get_width (surface),
474 + cairo_image_surface_get_height (surface));
475 + cairo_surface_destroy (surface);
476 +
477 return pixbuf;
478 }
479
480 @@ -769,8 +1012,8 @@ thumbnail_thread (gpointer data)
481 idle_data->page_no = i;
482
483 /* FIXME get preferred size from somewhere? */
484 - idle_data->pixbuf = get_thumbnail (thread_data->document, i,
485 - THUMBNAIL_SIZE);
486 + idle_data->pixbuf = get_thumb_pixbuf (thread_data->document, i,
487 + THUMBNAIL_SIZE);
488
489 g_idle_add (idle_set_thumbnail, idle_data);
490
491 --
492 1.7.5