Taking this thread in a slightly different direction, here is a quick and dirty little routine (well, I don't exactly have much time on my hands at the moment!) for viewing animated GIFs in SBASIC. The attachment contains two of David Westbury's extension files used by the program - FGIF from phgtk to convert GIF to PIC, and FPIC_LOAD from his FUN.ZIP package elsewhere on this forum. These are included in the attachment, along with a few example animated gif files. Only tested in mode 32 on QPC2 v4.04, no idea how well (or if at all) it works on other systems. I think it will only work on a GD2 system in mode 16, 32, or 33.
1. Unzip the attached anim1.zip to somewhere on your SMSQ/E system. For best (fastest) results, put the .GIF files in ram1_
2. LRESPR the two BIN files FGIF_BIN and FUN_BIN
3. LOAD ANIM1_BAS - this is the program listed below.
4. Put the filename of one of the gif files in line 130 (or if you have menu extension use FILE_SELECT$ if you want to choose files from a menu)
5. If using MODE 16 (Aurora) or MODE 33 (Q40/Q60) change the 32 in line 5070 to 16 or 33 as appropriate.
6. RUN the program in SBASIC.
Some notes:
Line 160: the procedure ANIMATE is called with 4 parameters, the channel number in which the animation is to occur, the x and y co-ordinate of the top left of the animation, and the filename of the gif file.
Line 5020: uses MGIF to extract the number of frames of animation in the file
The program outputs each frame of the animation in turn to a temporary PIC file in RAM1_ (filename set in line 5060, extracted by line 5070 - the +1024 in line 5070 is to swap black/white transparency, omit if you don't want to swap white for black), gets the inter-frame timing (line 5100), displays the frame (line 5110), deletes the temporary frame PIC file (line 5120), waits between frames giving you the option to press ESC (line 5130). Obviously, this real-time frame extraction will slow things down a bit on slower systems, but at least it prevents generating large numbers of potentially large graphics frame files in ramdisk!
If you are using a different screen mode, change the 32 in line 5070 to 16 (Aurora mode) or 33 (Q40/Q60) as appropriate.
The repeat loop called 'animating' keeps the animation going over and over until you press ESC.
Where the inter-frame timing has a value of 1, you may find the animation goes too fast - you'll see this with the badpc.gif (Derek Stewart's avatar on this Forum - sorry Derek!). In essence, I think PAUSE 1 only waits until the nearest 1/50th second comes along, not necessarily a full 1/50th second
Line 5080 has a potential bad practice - an EXIT loop within a FOR loop exiting a REPeat loop. It seems to work, but I'm not sure if programming purists will give me a black mark for that one.
Code: Select all
100 REMark simple animated gif viewer for SBASIC
110 REMark needs David Westbury's FGIF, MGIF and FPIC_LOAD
120 :
130 gif_file$ = 'ram1_ag_whack.gif'
140 :
150 CLS : CLS #0
160 Animate #1,0,0,gif_file$
170 :
5000 DEFine PROCedure Animate (channel, x, y, ip$)
5010 LOCal animating,no_of_frames%,frame_no%,op$,err%
5020 no_of_frames% = MGIF(ip$,-1,-1)
5030 IF no_of_frames% < 0 THEN RETurn : REMark oops
5040 REPeat animating
5050 FOR frame_no% = 0 TO no_of_frames%-1
5060 op$ = 'ram1_frame'&frame_no%&'_pic'
5070 err% = FGIF(ip$,op$,32+512+1024,frame_no%)
5080 IF err% THEN EXIT animating : REMark oops
5090 REMark get frame timing
5100 OPEN_IN #3,op$ : BGET #3\9,frame_time% : CLOSE #3
5110 err% = FPIC_LOAD(#1,op$) : REMark display this frame
5120 DELETE op$ : REMark delete this frame from ramdisk
5130 IF INKEY$(frame_time%) = CHR$(27) THEN EXIT animating
5140 END FOR frame_no%
5150 END REPeat animating
5160 END DEFine Animate