From: Brian M. <bmi...@hu...> - 2006-09-26 02:22:30
|
As I revisited this, I remembered that my problem with ImageMagick was = with threads, not Win32::GUI (ImageMagick doesn't seem to work at all with threads). I've been playing with this, and ImageMagick can read animated gif's. I haven't figured out how to get individual frames from the animation. = All I can get is the first frame... I've never played with PAR, so I can't help there... Brian Millham This message traveled at least 44,000 miles to reach you! Creator of the DW6000 Monitor http://www.millham.net/dw6000 bmi...@hu... -----Original Message----- From: Glenn Linderman [mailto:perl@NevCal.com]=20 Sent: Monday, September 25, 2006 10:03 PM To: Brian Millham; per...@li... Subject: Re: [perl-win32-gui-users] [win32-gui] DIBitmap and Animated = GIFs? Hi Brian, I have several application successfully using ImageMagick and Win32::GUI = -- but I'm not using animated .gif files, or attempting to display them, = so I won't be much help in that regard. On the other hand, my problem=20 with ImageMagick these days is that even the bribes version, which used=20 to be easily usable with PAR, no longer is. But I'm pretty sure that is = a PAR problem, not ImageMagick or Win32::GUI. On approximately 9/25/2006 4:59 PM, came the following characters from=20 the keyboard of Brian Millham: > A note on ImageMagick, I've had problems getting it to work properly = with > Win32::GUI. There appears to be a namespace problem, but I haven't = really > looked into it much. I am currently working on a project that I may = need > ImageMagick, so if I find anything out about the problem, I'll post it here > (I'll also check if it supports animated GIFs) > > Brian Millham > This message traveled at least 44,000 miles to reach you! > Creator of the DW6000 Monitor > http://www.millham.net/dw6000 > bmi...@hu... > > -----Original Message----- > From: per...@li... > [mailto:per...@li...] On Behalf = Of > Robert May > Sent: Monday, September 25, 2006 6:27 PM > To: Steve Loughran > Cc: per...@li... > Subject: Re: [perl-win32-gui-users] [win32-gui] DIBitmap and Animated GIFs? > > Steve Loughran wrote: > =20 >> Well, my attempts at loading in animated/multi-page GIFs has come to = a >> =20 > stop. > =20 >> Image:ParseGIF seems to create "invalid gifs" (but its last update = was=20 >> 1999 apparently!), DIBitmap doesnt handle them at all (due to it = using=20 >> an earlier version of FreeImage), Imager::Files only supports native = M$=20 >> file formats on win32 (and the extra libraries it requires to support = >> GIFs are a right pain to get running on win32... if it will work at=20 >> all), and GD can create animated GIFs but has no mention anywhere of = how=20 >> to load them. >> >> So I am stuck. Does anyone have any pointers to any perl code/modules = >> that will help me load animated/multi-page GIFs and extract the=20 >> individual images? >> =20 > > > It's many years since I played with ImageMagick, but it may do what = you=20 > need. Find info about the Perl wrapper at > http://www.imagemagick.org/script/perl-magick.php > > I can see version 6.2.8 of Image::Magick in ActiveState's ppm = repository. > > I can't immediately see anything that says it reads animated GIFs, but = > would be surprised if it doesn't. > > Rob. > =20 --=20 Glenn -- http://nevcal.com/ =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D A protocol is complete when there is nothing left to remove. -- Stuart Cheshire, Apple Computer, regarding Zero Configuration = Networking --- avast! Antivirus: Outbound message clean. Virus Database (VPS): 0639-1, 09/25/2006 Tested on: 9/25/2006 10:21:46 PM avast! is copyright (c) 2000-2006 ALWIL Software. http://www.avast.com |
From: Brian M. <bmi...@hu...> - 2006-09-26 03:47:10
|
Now you've got me going... I really didn't care that much about animated GIFs, I was just trying to help... But I was getting annoyed that I couldn't figure out how to get the individual frames, or even a frame = count. So now I'm working on this. I can now get individual frames from an animated gif. $image =3D Image::Magick->new(); $image->Read('ani.gif'); $framecount =3D $#$image; $frame0 =3D $image->[0]; $frame1 =3D $image->[1]; Note the difference from your example. Not $image[0] but $image->[0]. Now I need to display the images in a Win32::GUI window, and figure out = the timing. Brian Millham This message traveled at least 44,000 miles to reach you! Creator of the DW6000 Monitor http://www.millham.net/dw6000 bmi...@hu... -----Original Message----- From: per...@li... [mailto:per...@li...] On Behalf Of Glenn Linderman Sent: Monday, September 25, 2006 10:57 PM To: Brian Millham Cc: per...@li... Subject: Re: [perl-win32-gui-users] [win32-gui] DIBitmap and Animated = GIFs? On approximately 9/25/2006 7:21 PM, came the following characters from=20 the keyboard of Brian Millham: > As I revisited this, I remembered that my problem with ImageMagick was with > threads, not Win32::GUI (ImageMagick doesn't seem to work at all with > threads). >=20 > I've been playing with this, and ImageMagick can read animated gif's. = I > haven't figured out how to get individual frames from the animation. = All I > can get is the first frame... Try using subscripts. Maybe something like this would work... You can=20 also get help on the imagemagick mailing list. $image =3D Image::Magick->new(); $image->Read('ani.gif'); $framecount =3D $#$image; $frame0 =3D $image[ 0 ]; $frame1 =3D $image[ 1 ]; etc. You get to add the bounds checking and error checking. Animated GIF=20 files, IIRC, are not always full-frame, but deltas? That's all I think=20 I know about them, but I could be wrong. So I'm not sure if you display = the frames individually that they will be what you expect, but if you=20 are into animated GIFs, maybe they will be what you expect. --=20 Glenn -- http://nevcal.com/ =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D A protocol is complete when there is nothing left to remove. -- Stuart Cheshire, Apple Computer, regarding Zero Configuration = Networking -------------------------------------------------------------------------= Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share = your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=3Djoin.php&p=3Dsourceforge&CID=3D= DEVDEV _______________________________________________ Perl-Win32-GUI-Users mailing list Per...@li... https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users http://perl-win32-gui.sourceforge.net/ --- avast! Antivirus: Inbound message clean. Virus Database (VPS): 0639-1, 09/25/2006 Tested on: 9/25/2006 11:28:33 PM avast! is copyright (c) 2000-2006 ALWIL Software. http://www.avast.com --- avast! Antivirus: Outbound message clean. Virus Database (VPS): 0639-1, 09/25/2006 Tested on: 9/25/2006 11:45:09 PM avast! is copyright (c) 2000-2006 ALWIL Software. http://www.avast.com |
From: Steve L. <ste...@sc...> - 2006-09-26 20:26:33
|
Frame timing: $delay = $image->[$frame_count]->Get('delay'); (I think!). Still having some issue with anims (I think its PerlMagick thats causing the problems), but its most certainly getting there :) Steve > So now I'm working on this. I can now get individual frames from an > animated gif. > > $image = Image::Magick->new(); > $image->Read('ani.gif'); > $framecount = $#$image; > $frame0 = $image->[0]; > $frame1 = $image->[1]; > > Note the difference from your example. Not $image[0] but $image->[0]. > > Now I need to display the images in a Win32::GUI window, and figure out the > timing. > > Brian Millham > This message traveled at least 44,000 miles to reach you! > Creator of the DW6000 Monitor > http://www.millham.net/dw6000 > bmi...@hu... > > -----Original Message----- > From: per...@li... > [mailto:per...@li...] On Behalf Of > Glenn Linderman > Sent: Monday, September 25, 2006 10:57 PM > To: Brian Millham > Cc: per...@li... > Subject: Re: [perl-win32-gui-users] [win32-gui] DIBitmap and Animated GIFs? > > On approximately 9/25/2006 7:21 PM, came the following characters from > the keyboard of Brian Millham: >> As I revisited this, I remembered that my problem with ImageMagick was > with >> threads, not Win32::GUI (ImageMagick doesn't seem to work at all with >> threads). >> >> I've been playing with this, and ImageMagick can read animated gif's. I >> haven't figured out how to get individual frames from the animation. All > I >> can get is the first frame... > > Try using subscripts. Maybe something like this would work... You can > also get help on the imagemagick mailing list. > > $image = Image::Magick->new(); > $image->Read('ani.gif'); > $framecount = $#$image; > $frame0 = $image[ 0 ]; > $frame1 = $image[ 1 ]; > > etc. > > You get to add the bounds checking and error checking. Animated GIF > files, IIRC, are not always full-frame, but deltas? That's all I think > I know about them, but I could be wrong. So I'm not sure if you display > the frames individually that they will be what you expect, but if you > are into animated GIFs, maybe they will be what you expect. > |
From: Brian M. <bmi...@hu...> - 2006-09-27 01:47:07
Attachments:
animatedgif.pl
|
I've got a simple script that can display an animated gif. I think that it could be improved. It's a bit slow loading the gif, and = it doesn't handle the missing information from some frames (changes from I-frames [in MPEG speak]) and it doesn't handle transparent backgrounds. Oh, and there's no error checking. I tried to add enough comments so everyone can understand what I did. If you make any improvements, please share them with the list (or at = least with me) Would this be a good script to add as an example script with the = Win32::GUI distribution? Enjoy! I hope this helps someone! Brian Millham This message traveled at least 44,000 miles to reach you! Creator of the DW6000 Monitor http://www.millham.net/dw6000 bmi...@hu... -----Original Message----- From: per...@li... [mailto:per...@li...] On Behalf Of Steve Loughran Sent: Tuesday, September 26, 2006 4:26 PM To: per...@li... Subject: Re: [perl-win32-gui-users] [win32-gui] DIBitmap and Animated = GIFs? Frame timing: $delay =3D $image->[$frame_count]->Get('delay'); (I think!). Still having some issue with anims (I think its PerlMagick thats causing = the problems), but its most certainly getting there :) Steve > So now I'm working on this. I can now get individual frames from an > animated gif. >=20 > $image =3D Image::Magick->new(); > $image->Read('ani.gif'); > $framecount =3D $#$image; > $frame0 =3D $image->[0]; > $frame1 =3D $image->[1]; >=20 > Note the difference from your example. Not $image[0] but $image->[0]. >=20 > Now I need to display the images in a Win32::GUI window, and figure = out the > timing. >=20 > Brian Millham > This message traveled at least 44,000 miles to reach you! > Creator of the DW6000 Monitor > http://www.millham.net/dw6000 > bmi...@hu... >=20 > -----Original Message----- > From: per...@li... > [mailto:per...@li...] On Behalf = Of > Glenn Linderman > Sent: Monday, September 25, 2006 10:57 PM > To: Brian Millham > Cc: per...@li... > Subject: Re: [perl-win32-gui-users] [win32-gui] DIBitmap and Animated GIFs? >=20 > On approximately 9/25/2006 7:21 PM, came the following characters from = > the keyboard of Brian Millham: >> As I revisited this, I remembered that my problem with ImageMagick = was > with >> threads, not Win32::GUI (ImageMagick doesn't seem to work at all with >> threads). >> >> I've been playing with this, and ImageMagick can read animated gif's. = I >> haven't figured out how to get individual frames from the animation. = All > I >> can get is the first frame... >=20 > Try using subscripts. Maybe something like this would work... You can = > also get help on the imagemagick mailing list. >=20 > $image =3D Image::Magick->new(); > $image->Read('ani.gif'); > $framecount =3D $#$image; > $frame0 =3D $image[ 0 ]; > $frame1 =3D $image[ 1 ]; >=20 > etc. >=20 > You get to add the bounds checking and error checking. Animated GIF=20 > files, IIRC, are not always full-frame, but deltas? That's all I = think=20 > I know about them, but I could be wrong. So I'm not sure if you = display=20 > the frames individually that they will be what you expect, but if you=20 > are into animated GIFs, maybe they will be what you expect. >=20 -------------------------------------------------------------------------= Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share = your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=3Djoin.php&p=3Dsourceforge&CID=3D= DEVDEV _______________________________________________ Perl-Win32-GUI-Users mailing list Per...@li... https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users http://perl-win32-gui.sourceforge.net/ --- avast! Antivirus: Inbound message clean. Virus Database (VPS): 0639-2, 09/26/2006 Tested on: 9/26/2006 5:05:55 PM avast! is copyright (c) 2000-2006 ALWIL Software. http://www.avast.com --- avast! Antivirus: Outbound message clean. Virus Database (VPS): 0639-2, 09/26/2006 Tested on: 9/26/2006 9:45:47 PM avast! is copyright (c) 2000-2006 ALWIL Software. http://www.avast.com =20 |
From: Steve L. <ste...@sc...> - 2006-09-27 10:32:25
|
I found the answer to the "delta" frames (and all the other problems that I was having: #==== $multi_image=Image::Magick->new; $multi_image->Read("gif_anim.gif"); $count = $#$multi_image; #coalesce the image $coalesce = $multi_image->Coalesce(); $temp = 0; while (temp <= $count) { #save the *coalesced* image $coalesce->[$temp]->Write(filename => "out-$temp.gif"); $temp++; } #==== works a treat :) I do apologize for stirring up this whole animated GIF issue... I know its not strictly win32-gui related. Sorry! Steve Brian Millham wrote: > I've got a simple script that can display an animated gif. > > I think that it could be improved. It's a bit slow loading the gif, and it > doesn't handle the missing information from some frames (changes from > I-frames [in MPEG speak]) and it doesn't handle transparent backgrounds. > Oh, and there's no error checking. > > I tried to add enough comments so everyone can understand what I did. > > If you make any improvements, please share them with the list (or at least > with me) > > Would this be a good script to add as an example script with the Win32::GUI > distribution? > > Enjoy! I hope this helps someone! > > Brian Millham > This message traveled at least 44,000 miles to reach you! > Creator of the DW6000 Monitor > http://www.millham.net/dw6000 > bmi...@hu... > > -----Original Message----- > From: per...@li... > [mailto:per...@li...] On Behalf Of > Steve Loughran > Sent: Tuesday, September 26, 2006 4:26 PM > To: per...@li... > Subject: Re: [perl-win32-gui-users] [win32-gui] DIBitmap and Animated GIFs? > > Frame timing: > > $delay = $image->[$frame_count]->Get('delay'); > > (I think!). > > Still having some issue with anims (I think its PerlMagick thats causing the problems), but its most certainly getting there :) > > Steve > >> So now I'm working on this. I can now get individual frames from an >> animated gif. >> >> $image = Image::Magick->new(); >> $image->Read('ani.gif'); >> $framecount = $#$image; >> $frame0 = $image->[0]; >> $frame1 = $image->[1]; >> >> Note the difference from your example. Not $image[0] but $image->[0]. >> >> Now I need to display the images in a Win32::GUI window, and figure out > the >> timing. >> >> Brian Millham >> This message traveled at least 44,000 miles to reach you! >> Creator of the DW6000 Monitor >> http://www.millham.net/dw6000 >> bmi...@hu... >> >> -----Original Message----- >> From: per...@li... >> [mailto:per...@li...] On Behalf Of >> Glenn Linderman >> Sent: Monday, September 25, 2006 10:57 PM >> To: Brian Millham >> Cc: per...@li... >> Subject: Re: [perl-win32-gui-users] [win32-gui] DIBitmap and Animated > GIFs? >> On approximately 9/25/2006 7:21 PM, came the following characters from the keyboard of Brian Millham: >>> As I revisited this, I remembered that my problem with ImageMagick was >> with >>> threads, not Win32::GUI (ImageMagick doesn't seem to work at all with >>> threads). >>> >>> I've been playing with this, and ImageMagick can read animated gif's. I >>> haven't figured out how to get individual frames from the animation. All >> I >>> can get is the first frame... >> Try using subscripts. Maybe something like this would work... You can also get help on the imagemagick mailing list. >> >> $image = Image::Magick->new(); >> $image->Read('ani.gif'); >> $framecount = $#$image; >> $frame0 = $image[ 0 ]; >> $frame1 = $image[ 1 ]; >> >> etc. >> >> You get to add the bounds checking and error checking. Animated GIF files, IIRC, are not always full-frame, but deltas? That's all I think I know about them, but I could be wrong. So I'm not sure if you display the frames individually that they will be what you expect, but if you are into animated GIFs, maybe they will be what you expect. >> > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys -- and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Perl-Win32-GUI-Users mailing list > Per...@li... > https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users > http://perl-win32-gui.sourceforge.net/ > --- > avast! Antivirus: Inbound message clean. > Virus Database (VPS): 0639-2, 09/26/2006 > Tested on: 9/26/2006 5:05:55 PM > avast! is copyright (c) 2000-2006 ALWIL Software. > http://www.avast.com > > > > --- > avast! Antivirus: Outbound message clean. > Virus Database (VPS): 0639-2, 09/26/2006 > Tested on: 9/26/2006 9:45:47 PM > avast! is copyright (c) 2000-2006 ALWIL Software. > http://www.avast.com > > > > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys -- and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > > > ------------------------------------------------------------------------ > > _______________________________________________ > Perl-Win32-GUI-Users mailing list > Per...@li... > https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users > http://perl-win32-gui.sourceforge.net/ |
From: Steve L. <ste...@sc...> - 2006-09-27 10:38:25
|
*cough* while ($temp <= $count) > $temp = 0; > while (temp <= $count) > { > #save the *coalesced* image > $coalesce->[$temp]->Write(filename => "out-$temp.gif"); > $temp++; > } |
From: Robert M. <rm...@po...> - 2006-09-27 18:41:50
|
Brian Millham wrote: > I've got a simple script that can display an animated gif. [snip] > I think that it could be improved. It's a bit slow loading the gif, and it > doesn't handle the missing information from some frames (changes from > I-frames [in MPEG speak]) and it doesn't handle transparent backgrounds. > Oh, and there's no error checking. > > I tried to add enough comments so everyone can understand what I did. > > If you make any improvements, please share them with the list (or at least > with me) > > Would this be a good script to add as an example script with the Win32::GUI > distribution? Very nice. There's plenty of alternatives for displaying the image (e.g. drawing it directly into the DC), but this shows all the important steps. I have a policy (open for discussion, of course) of not distributing samples that require modules not distributed with ActiveState Perl or Win32::GUI itself, as I think the samples we distribute should run 'out of the box'. This is, however, exactly the sort of sample that I'd like to see on the Wiki - http://perl-win32-gui.sourceforge.net/wiki/ Regards, Rob. |
From: Robert M. <rm...@po...> - 2006-09-27 22:20:14
|
Glenn Linderman wrote: > On approximately 9/27/2006 11:41 AM, came the following characters from > the keyboard of Robert May: >> Brian Millham wrote: >> >> [various snips] >> >>> Would this be a good script to add as an example script with the Win32::GUI >>> distribution? >>> >> I have a policy (open for discussion, of course) of not >> distributing samples that require modules not distributed with >> ActiveState Perl or Win32::GUI itself, as I think the samples we >> distribute should run 'out of the box'. >> >> This is, however, exactly the sort of sample that I'd like to see on the >> Wiki - http://perl-win32-gui.sourceforge.net/wiki/ >> > That seems like a nice dichotomy of example scripts: distribute samples > that work with no dependencies, and put on the website/wiki other > scripts that have dependencies. But such scripts with dependencies can > be very useful to show how to integrate modules, which, for > understandable reasons, is not generally done in test scripts either. And if the collection of the Wiki grows suitably, then the scripts could all be packaged up as a separate download. Rob. |
From: Brian M. <bmi...@hu...> - 2006-09-28 01:08:18
|
I'll go ahead an add the example to the Wiki (as soon as I figure out = how) BTW, I just created a new project on sourceforge for my Win32::GUI::Skin module. It's currently pending approval. Brian Millham This message traveled at least 44,000 miles to reach you! Creator of the DW6000 Monitor http://www.millham.net/dw6000 bmi...@hu... -----Original Message----- From: Robert May [mailto:rm...@po...]=20 Sent: Wednesday, September 27, 2006 2:42 PM To: Brian Millham Cc: 'Steve Loughran'; per...@li... Subject: Re: [perl-win32-gui-users] [win32-gui] DIBitmap and Animated = GIFs? Brian Millham wrote: > I've got a simple script that can display an animated gif. [snip] > I think that it could be improved. It's a bit slow loading the gif, = and it > doesn't handle the missing information from some frames (changes from > I-frames [in MPEG speak]) and it doesn't handle transparent = backgrounds. > Oh, and there's no error checking. >=20 > I tried to add enough comments so everyone can understand what I did. >=20 > If you make any improvements, please share them with the list (or at = least > with me) >=20 > Would this be a good script to add as an example script with the Win32::GUI > distribution? Very nice. There's plenty of alternatives for displaying the image=20 (e.g. drawing it directly into the DC), but this shows all the important = steps. I have a policy (open for discussion, of course) of not=20 distributing samples that require modules not distributed with=20 ActiveState Perl or Win32::GUI itself, as I think the samples we=20 distribute should run 'out of the box'. This is, however, exactly the sort of sample that I'd like to see on the = Wiki - http://perl-win32-gui.sourceforge.net/wiki/ Regards, Rob. --- avast! Antivirus: Inbound message clean. Virus Database (VPS): 0639-3, 09/27/2006 Tested on: 9/27/2006 7:40:19 PM avast! is copyright (c) 2000-2006 ALWIL Software. http://www.avast.com --- avast! Antivirus: Outbound message clean. Virus Database (VPS): 0639-3, 09/27/2006 Tested on: 9/27/2006 9:02:12 PM avast! is copyright (c) 2000-2006 ALWIL Software. http://www.avast.com |
From: Brian M. <bmi...@hu...> - 2006-09-28 03:02:07
|
I've added my example (with the Coalesce fix added) to the wiki on sourceforge. I didn't add Rob's changes, since I figure that Rob will post his on the Wiki, giving different ways to approach the problem (that's what Perl's all about, right?!) Brian Millham This message traveled at least 44,000 miles to reach you! Creator of the DW6000 Monitor http://www.millham.net/dw6000 bmi...@hu... --- avast! Antivirus: Outbound message clean. Virus Database (VPS): 0639-3, 09/27/2006 Tested on: 9/27/2006 11:01:20 PM avast! is copyright (c) 2000-2006 ALWIL Software. http://www.avast.com |
From: Robert M. <rm...@po...> - 2006-09-27 22:38:37
|
Brian Millham wrote: > I've got a simple script that can display an animated gif. > > I think that it could be improved. It's a bit slow loading the gif, and it > doesn't handle the missing information from some frames (changes from > I-frames [in MPEG speak]) and it doesn't handle transparent backgrounds. > Oh, and there's no error checking. OK, so I caught the bug too. I've added the 'coalesce()' call that Steve found, and am handling different delays for different frames. By using the Win32::GUI::DIBitmap AlphaCopyToDC method for drawing into the DC directly it copes with transparent colours, but as a result the drawing is a bit slow (and a bit flickery). It needs a recent Win32::GUI for the constants - if you haven't downloaded and installed the 1.04 beta yet(from http://www.robmay.me.uk/win32gui/) then you'll need to fix up the constants I've used. (If I remember correctly AlphaCopyToDC has a resource leak in earlier DIBitmaps too) My attempt below - enjoy. Rob. #!perl -w # (C) 2006 Brian Millham bmi...@hu... # The perl artistic license applies. # Modification for drawing into window DC by Robert May use strict; use warnings; use Win32::GUI 1.03_04, qw( CW_USEDEFAULT WM_ERASEBKGND); use Win32::GUI::DIBitmap(); use Image::Magick(); use Time::HiRes qw(gettimeofday tv_interval); my $anifile = shift; # Load frames as Win32::GUI::DIBitmap DIBs and store in array # array is list of delays in milliseconds and DIB pairs my @delay_frames = LoadDIBs($anifile); # Get the number of frames my $lastframe = $#delay_frames/2; my $width = $delay_frames[1]->Width(); my $height = $delay_frames[1]->Height(); # Sum the loop time my $loop_time = 0; $loop_time += $delay_frames[$_*2] for (0 .. $lastframe); # Confirm some info my $text = sprintf <<__LABELTEXT, $anifile, $width, $height, ($lastframe+1), $loop_time; Animation file:\t%s Width:\t%d pixels Height:\t%d pixels Length:\t%d frames Expected loop time:\t%d ms __LABELTEXT # Create the window, sized for the image my $W = Win32::GUI::Window->new( -title => "Animated GIF Test", -name => 'Window', -left => CW_USEDEFAULT, -size => [$width, $height], # adjust this below -background => 0xFF0000, # Show transparency working -onPaint => \&paint, -onTimer => \&timer, ) or die "Failed to create window"; #TODO: really want AdjustWindowRect() to make this easier my $cwidth = $W->ScaleWidth(); my $cheight = $W->ScaleHeight(); $W->Resize($width+$width-$cwidth,$height+$height-$cheight); #Create an owned window for the information my $W2 = Win32::GUI::Window->new( -parent => $W, -visible => 1, # owned window is hidden while parent is hidden -title => "Animation Information", -name => 'INFO', -pos => [$W->Left()+$W->Width(), $W->Top()], -size => [200,170], ) or die "Failed to create W2"; $W2->AddLabel( -name => 'LBL', -pos => [10,10], -size => [$W2->ScaleWidth()-20, $W2->ScaleHeight()-20], ) or die "Failed to create Label"; # Store away the frame info we'll need in the callbacks $W->UserData({ currentframe => 0, lastframe => $lastframe, timer => [gettimeofday], text => $text . "Actual loop time:\t\t%d ms", }); # Add the timer to advance and redraw the image $W->AddTimer('T1', $delay_frames[0]); # Show the main window. $W->Show(); Win32::GUI::Dialog(); # done, so hide main window and exit $W->Hide(); exit(0); # Load the frames, get the delay and convert frames to Win32::GUI::DIBitmap DIBs sub LoadDIBs { my $file = shift; my (@frames, @delay_dibs); # Create new Image::Magick object my $image = Image::Magick->new(); # Load the image(s) from file #TODO: error checking $image->Read($file); # Coalesce multiple images so that each frame is a whole image $image->Coalesce(); # Convert all ImageMagick frames to raw gif data push @frames, $image->[$_]->ImageToBlob() for (0 .. $#$image); # Get delay and Create DIBitmap objects for each frame for (0 .. $#$image) { # Get the frame delay. # convert delay from 1/100th seconds to milliseconds push @delay_dibs, $image->[$_]->Get('delay') * 10; # convert frame to DIB push @delay_dibs, Win32::GUI::DIBitmap->newFromData($frames[$_]); } return @delay_dibs; } sub timer { my ($win, $name) = @_; # Retrieve frame info my $info = $win->UserData(); # Advance current frame $info->{currentframe}++; # Wrap after last frame, and compute stats if($info->{currentframe} > $info->{lastframe}) { $info->{currentframe} = 0; # update stats in info window $win->INFO->LBL->Text( sprintf $info->{text}, int(tv_interval($info->{timer}) * 1000) ); $info->{timer} = [gettimeofday]; } # Store frame info $win->UserData($info); # Request system to repaint window $win->InvalidateRect(0); # Set the new delay $win->{$name}->Interval($delay_frames[$info->{currentframe}*2]); return 0; } sub paint { my ($win, $dc) = @_; # Retrieve frame info my $info = $win->UserData(); # Erase the background - erases the last image $win->SendMessage(WM_ERASEBKGND, $dc->{-handle}, 0); # Display the frame $delay_frames[($info->{currentframe}*2)+1]->AlphaCopyToDC($dc); #$delay_frames[($info->{currentframe}*2)+1]->AlphaStretchToDC($dc, 0, 0, $win->ScaleWidth(), $win->ScaleHeight()); $dc->Validate(); return 0; } __END__ |
From: Steve L. <ste...@sc...> - 2006-09-28 10:24:36
|
Ah, ImageToBlob() into newFromData Win32::GUI::DIBitmap was what I was looking for... that saves some time with intermediate disk files saving/loading. The memory leak in AlphaCopyToDC in 1.03_4 is fixed, so I do suggest updating if you use this call. I removed my flickering by "double-buffering" to a compatible DC and AlphaCopyToDC into that, then BitBlt the DC back into the window, but then I am updating the whole window area, copying multiple images into the window on each paint refresh, and it looked terrible when using AlphaCopyToDC directly into the window's DC. Steve Robert May wrote: > OK, so I caught the bug too. I've added the 'coalesce()' call that > Steve found, and am handling different delays for different frames. By > using the Win32::GUI::DIBitmap AlphaCopyToDC method for drawing into the > DC directly it copes with transparent colours, but as a result the > drawing is a bit slow (and a bit flickery). > # Load the frames, get the delay and convert frames to > Win32::GUI::DIBitmap DIBs > sub LoadDIBs { > my $file = shift; > my (@frames, @delay_dibs); > > # Create new Image::Magick object > my $image = Image::Magick->new(); > # Load the image(s) from file > #TODO: error checking > $image->Read($file); > # Coalesce multiple images so that each frame is a whole image > $image->Coalesce(); > > # Convert all ImageMagick frames to raw gif data > push @frames, $image->[$_]->ImageToBlob() for (0 .. $#$image); > > # Get delay and Create DIBitmap objects for each frame > for (0 .. $#$image) { > # Get the frame delay. > # convert delay from 1/100th seconds to milliseconds > push @delay_dibs, $image->[$_]->Get('delay') * 10; > > # convert frame to DIB > push @delay_dibs, Win32::GUI::DIBitmap->newFromData($frames[$_]); > } > > return @delay_dibs; > } |
From: Steve L. <ste...@sc...> - 2006-09-29 06:17:56
|
My code is usually very ugly, and nowhere near as "pro" looking as the offerings posted here, but i`ll knock something up so you can all laugh at it :) Steve Glenn Linderman wrote: > Will you be putting your TMTOWTDI offering on the Wiki also? > |
From: Robert M. <rm...@po...> - 2006-10-01 21:21:04
|
Glenn Linderman wrote: > Will you be putting your TMTOWTDI offering on the Wiki also? Steve Loughran wrote: > My code is usually very ugly, and nowhere near as "pro" looking as the > offerings posted here, but i`ll knock something up so you can all laugh > at it :) Please don't allow any particular coding style put you off posting examples. I for one certainly won't laugh at it - we all learn from seeing what others are doing, and comments often lead to better approaches - we all know that there are many ways of doing thing, particularly in Perl, and so getting lots of options out in the open allows us to mix and match the best parts of each solution, and makes the mailing list archives and the Wiki better resources for others. Regards, Rob. |