Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

how to speed up image file loading with gtk2 iconview?

by renegadex (Beadle)
on Sep 30, 2008 at 15:27 UTC ( #714578=perlquestion: print w/ replies, xml ) Need Help??
renegadex has asked for the wisdom of the Perl Monks concerning the following question:

i made a code that creates thumbnails of pictures using the iconview widget. problem is, when opening many (20++) pictures (2000++px x 2000++px) it turns out to be slow. is there a way to open a folder even if the pictures are still loading? would progressive loading help?
my @selection_list = (); my $liststore = Gtk2::ListStore->new("Glib::String","Glib::String","Gt +k2::Gdk::Pixbuf","Glib::Int","Glib::Int","Gtk2::Gdk::Pixbuf"); my $iconview = Gtk2::IconView->new_with_model($liststore); sub browse_files { # SEARCH FOR FOLDERS # $iconview->set('visible',0); my $path = $_[0]; my $new_path = $path; print $path , "\n"; use Encode; opendir my $dh, $path or warn "Error: $!"; my @files = grep !/^\.\.?$/, readdir $dh; closedir $dh; @files = map { decode( 'utf8', "$path/".$_ ) } sort @files; my @files_t=(); foreach my $file (@files) { $file =~ s|//|/|g; (my $text = $file ) =~ s|^.*/||g; if (-d $file) { my $folder_pixbuf_t = Gtk2::Gdk::Pixbuf->new_from_file("ic +ons/folder_green.png"); my $rowiter = $liststore->append; $liststore->set_value($rowiter,0,substr($file,length($path +)+1,length($file) - length($path))); $liststore->set_value($rowiter,1,$file); $liststore->set_value($rowiter,2,$folder_pixbuf_t); $liststore->set_value($rowiter,3,1); $liststore->set_value($rowiter,4,0); push @files_t, $file; } } foreach my $file (@files) { $file =~ s|//|/|g; (my $text = $file ) =~ s|^.*/||g; if( uc($file) =~ /.*\.(PNG|JPG|GIF|JPEG)$/ ){ my $isselected = 0; foreach my $x_t (@selection_list){ if($file eq $x_t){ $isselected=1; } } my $folder_pixbuf_t = Gtk2::Gdk::Pixbuf->new_from_file_at_ +scale($file,100,100,1); my $backup_pixbuf_t = $folder_pixbuf_t->copy; my $rowiter = $liststore->append; if($isselected==1){ my $bookmark_t = Gtk2::Gdk::Pixbuf->new_from_file("ico +ns/bookmarks2.png"); $bookmark_t->composite($folder_pixbuf_t,0,0,22,22,0,0, +1,1,'nearest',255); } $liststore->set_value($rowiter,0,substr($file,length($path +)+1,length($file) - length($path))); $liststore->set_value($rowiter,1,$file); $liststore->set_value($rowiter,2,$folder_pixbuf_t); $liststore->set_value($rowiter,3,0); if($isselected==1){ $liststore->set_value($rowiter,4,1); }else{ $liststore->set_value($rowiter,4,0); } $liststore->set_value($rowiter,5,$backup_pixbuf_t); push @files_t, $file; } } $iconview->set('visible',1); return @files_t; }

Comment on how to speed up image file loading with gtk2 iconview?
Download Code
Re: how to speed up image file loading with gtk2 iconview?
by zentara (Archbishop) on Sep 30, 2008 at 16:54 UTC
    About the only thing I can think of is to have a thread reading the images ahead of time and stuffing the pixbufs into a hash. Of course, with alot of images, that hash can get huge. Using it with iconview seems to be the hassle.

    If the images are relatively constant, why not use a separate script that reads all the images, puts them into pixbufs, stashes them into a hash, then saves it as a Storable db. You can even store the thumbnail for the image too. Then when you run your program, it will just slurp in all the pixbufs from the Storable db.

    If you want speed, I think displaying alot of images in a Liststore is not the right way to go. I faced the same problem in Gtk2-thumbnail-previewer. If I wsan't so lazy ( or was getting paid :-)) I would work out a way to preload with Storable, or if the images changed alot, use a thread to be making the pixbufs, and after it made the first subdir, continue on with others. But there is one catch, what if the user clicks on a subdir that hasn't been processed yet, you may need 2 threads...one for background work, and one for an unexpected click.

    All in all, I think preloading them with Storable, will be the fastest. That way you only read the files once from disk, and combine them all into one big Storable db. The Storable db will load very fast, as it is only a single file.


    I'm not really a human, but I play one on earth Remember How Lucky You Are
Re: how to speed up image file loading with gtk2 iconview?
by zentara (Archbishop) on Sep 30, 2008 at 18:59 UTC
    I was dic*ing around today with the idea, and came up with this, which may be of interest to you. It loads fast, and you may be able to process the first 100 files first, display, then finish processing the other files. Gtk2 ListStore Thumbnail/Image Viewer

    I'm not really a human, but I play one on earth Remember How Lucky You Are

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://714578]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (8)
As of 2014-07-14 02:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (254 votes), past polls