Re: No more poppler_page_render_to_pixbuf() in Ubuntu 12.04

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I had the same problem but we still cannot move to GTK 3,
we're stuck with GTK 2. However, the following code is usable for me,
most of this code came from the put_pixels() code in the comments
of gdk-pixbuf-core.h. The only missing piece of the puzzle was
cairo_image_surface_create_for_data().

cairo_surface_t *cairo_image_surface_from_pixbuf(GdkPixbuf *pixbuf) {
        int     width;
        int     height;
        int     stride;
        int     n_channels;
        guchar  *data;

        n_channels = gdk_pixbuf_get_n_channels (pixbuf);
        g_assert (gdk_pixbuf_get_colorspace (pixbuf) == GDK_COLORSPACE_RGB);
        g_assert (gdk_pixbuf_get_bits_per_sample (pixbuf) == 8);
        g_assert (gdk_pixbuf_get_has_alpha (pixbuf));
        g_assert (n_channels == 4);

        width = gdk_pixbuf_get_width(pixbuf);
        height = gdk_pixbuf_get_height(pixbuf);
        stride = gdk_pixbuf_get_rowstride(pixbuf);
        data = gdk_pixbuf_get_pixels(pixbuf);

return cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32, width, height, stride);
}

Then cairo_create() on this surface and you can render directly on a GdkPixbuf.

GdkPixbuf is still needed to display e.g. PDFs with many pages rendered on a single
client-side image. When using GdkPixmap that large, I constantly get BadAlloc X error
in my GTK app.

2012-04-29 03:23 keltezéssel, Craig Bakalian írta:
Hi Tadej;

Yes, I finally came up with the following,

page = poppler_document_get_page(doc, page_num);
poppler_page_get_size(page, &width, &height);	
cairo_surface_t *s;
cairo_t *cr;
s = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
cr = cairo_create(s);
poppler_page_render(page, cr);
pixbuf = gdk_pixbuf_get_from_surface(s, 0, 0, width, height);
image = gtk_image_new_from_pixbuf(pixbuf);

with a build in GTK+-3.

I just don't understand why there was a depreciation of the older code.
Who makes these decisions?

Craig Bakalian





On Sun, 2012-04-29 at 01:36 +0200, Tadej Borovšak wrote:
Hello.

I used the code below to render a page of a pdf to a scrolled window in
a gtk application of mine. After downloading Ubuntu 12.04 I get that
there is no more support for poppler_page_render_to_pixbuf(). I do know
that we are supposed to use cairo.  But how?  How do I replace the code
below with cairo?  What are we supposed to use, total cairo or
gdk_cairo_create().
I can see 2 different ways of dealing with this API removal. To reuse
as much existing code as possible, you can create
cairo_image_surface_t, let poppler render your page there using
poppler_page_render() and write your own function that will convert
between cairo_image_surface_t and GdkPixbuf.

Another way would involve replacing GtkImage widget with
GtkDrawingArea and drawing your page directly from expose-event/draw
signal handler. Details will depend on whether you'll use GTK+-2 or
GTK+-3.

Cheers,
Tadej



_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
https://mail.gnome.org/mailman/listinfo/gtk-list



[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux