Reading the POD, Tk::Animation is represented as array of Tk::Photo images, which, in turn, are stored "32 bits per pixel". Apparently, when going from possibly masked and/or partial frame, paletted <=8 bpp GIF to full-frame 32 bpp data, something horribly unoptimized happens inside Tk.

Here is a way of improving speed by 10 times (arguably, easier than examining Tk guts), for this 10 MB GIF, for which I only had to manually "collect" image data onto a "backdrop" accounting for mask of each frame (thankfully, no offsets etc. -- i.e. adjust as required for your images). I didn't try to optimize what I did with Imager, possibly it can be faster yet. + There are some glitches for couple of frames, I didn't investigate.

use strict; use warnings; use feature 'say'; use Time::HiRes 'time'; use Imager ':handy'; use Tk; use Tk::Animation; use Tk::Photo; use MIME::Base64; my $path = 'Animated_GIF_cheloVechek.gif'; die 'image not found' unless -e $path; my $size = -s $path; my $mw = MainWindow-> new; $mw-> configure( -title => $path ); my $top = $mw-> Frame-> pack; my $start = time; my $image_1 = $mw-> Animation( -format => 'gif', -file => $path ); print 'Tk::Animation took ', time - $start, " seconds for $size bytes \n"; $top-> Label( -image => $image_1 )-> pack; $image_1-> start_animation; $start = time; my $backdrop; my @frames = map { if ( $backdrop ) { # not 1st? my $mask = $_-> copy; my @mask_plt = map NC( 255, 255, 255 ), $mask-> getcolors; my $trans_idx = $mask-> tags( name => 'gif_trans_index' ); $mask_plt[ $trans_idx ] = NC( 0, 0, 0 ) if $trans_idx; $mask-> setcolors( colors => \@mask_plt ); $backdrop-> compose( src => $_, mask => $mask ); } else { $backdrop = $_ } $backdrop-> write( data => \my $data, type => 'bmp' ); $mw-> Photo( -data => encode_base64( $data )); } Imager-> read_multi( file => $path ); my $image_2 = $mw-> Animation; $image_2-> add_frame( @frames ); print 'Imager & Tk::Animation took ', time - $start, " seconds for $size bytes \n"; $top-> Label( -image => $image_2 )-> pack; $image_2-> start_animation; MainLoop; __END__ Tk::Animation took 10.3439958095551 seconds for 10740455 bytes Imager & Tk::Animation took 1.12088799476624 seconds for 10740455 byte +s

In reply to Re: Why is Tk::Animation so slow? by vr
in thread Why is Tk::Animation so slow? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.