Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Combination of Gtk2 and Imlib2

by Schnuck (Novice)
on Apr 27, 2020 at 07:47 UTC ( #11116113=perlquestion: print w/replies, xml ) Need Help??

Schnuck has asked for the wisdom of the Perl Monks concerning the following question:

Hello Dear Monks,
I have used Gtk2 to show some images as thumbnails. But it's way too slow.
Since the c version of Imlib2 is very fast, I had the idea to combine the GUI interface of Gtk2 with the advanced image loading ability of Imlib2.
I found two modules which offer a way of using Imlib2, but I cannot think of a way to combine a canvas or a drawable with the other module.
I think I need an idea what to do. I have to admit that I'm still new to GTk2 and Imlib.
Greetings and thank you
#!/usr/bin/perl -w use Gtk2 -init; use Glib qw(TRUE FALSE); use Image::Base; use Image::Base::Imlib2; use Image::Base::Gtk2::Gdk::Image; use Image::Base::Gtk2::Gdk::Drawable; $win = Gtk2::Window->new; my $vbox = Gtk2::VBox->new; $win->add($vbox); my $canvas = Image::Base::Gtk2::Gdk::Drawable->new ( -window => $win, +-width => 800, -height => 700 ); $vbox->pack_start($canvas, FALSE, FALSE, 5 ); $filename = "01.Kudu.jpeg"; my $image = Image::Base::Imlib2->new (-file => $filename ); #$canvas = $image->clone; $win->show_all; Gtk2->main;

Replies are listed 'Best First'.
Re: Combination of Gtk2 and Imlib2
by Corion (Patriarch) on Apr 27, 2020 at 08:12 UTC

    Imlib2 does know anything of Gtk2, so you will have to make Imlib2 return something that Gtk2 (or Image::Base::Gtk2::Gdk::Drawable) understands.

    It seems that Image::Base::Gtk2::Gdk::Image only thinks about "drawing" on an image, pixel by pixel or line by line, and don't have a way to draw a bitmap or JPEG buffer. Its documentation says so.

    Image::Base::Gtk2::Gdk::Pixbuf can ->load from a file or ->load_string from a memory buffer. So I think the best approach would be to make Imlib2 return a JPEG buffer of the thumbnail and then use that with Image::Base::Gtk2::Gdk::Pixbuf.

    Is there a reason you are using Image::Base at all instead of talking to Gtk2 yourself?

      Thank you for your reply.
      There is a reason I'm trying to make Image::Base load the jpeg and not Gtk2.
      Displaying several thumbnails on a canvas is very slow with the image loading abilities of Gtk2.
      Image::Base has GTk2 parts and Imlib2 parts, so I thought they would offer some kind of connection between them.

      Perhaps it would be better to just use the Imlib2-module with the Gtk-module?
      I don't know. The Image::Base part may be unnecessary or even a bad idea.


        I thought about it for a while and realized it would be a good idea to find out where the time is lost during the display of the images as thumbnails.
        I used Time::HiRes to find out.

        I am actually loading jpeg data from a tar archive. I have to convert this to a Pixpuf, because Gtk2-Canvas needs a pixbuf to show the data.
        The conversion function into a pixbuf consumes the majority (~70%) of the time.

        This may be a hint that this won't be faster using Imlib2?

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11116113]
Approved by hippo
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2023-09-26 02:23 GMT
Find Nodes?
    Voting Booth?

    No recent polls found