IFF Animation

This Chapter explains how AMOS Professional is capable of taking data saved in Interchangeable File Format (IFF), and transforming it into superb animations. Old hands and less experienced AMOS users alike will discover a new potential for exploiting programming kills.

IFF graphics have already been discussed as sources for screen pictures and Bob images, and you should be familiar with the LOAD IFF and SAVE IFF commands in the relevant Screens and Bobs Chapters. Here is a brief reminder:

LOAD IFF

instruction: load an IFF screen from a disc
Load IFF "filename"
Load IFF "filename",any screen number

Flash Off Load Iff"AMOSPro Examples:Logo.Iff"

SAVE IFF
instruction: save an IFF screen
Save Iff "filename"
Save Iff "filename", compression flag

Save Iff "My Programs:Iff/Picture_Name.Iff" : Rem Compressed Save Iff "My_Programs:Iff/Picture_Name.Iff",0 : Rem Uncompressed

Remember that the saved IFF data includes any pre-sets such as SCREEN DISPLAY, SCREEN OFFSET, SCREEN HIDE and SCREEN SHOW.

Optimising IFF animation

It is perfectly possible to create high definition "true video" animation on your Amiga with AMOS Professional. Unfortunately, you are normally restricted by available memory. Smooth animations need to display at least 24 "frames" (separate still pictures) every second, and every 16-colour, full-screen picture requires about 32k of storage space. This means that you would need to invest in a lot of expensive memory storage to run a few seconds of animation, or the memory of an unexpanded Amiga would be exhausted within two seconds! One solution is to use tiny images, reduce the number of colours and compact these images using the SPACK command, but the AMOS Professional programmer deserves better than that.

Adapting the "delta-encoding" technique from the latest video research, AMOS Professional is able to optimise IFF data, concentrating on those parts of the image that actually appear to "move", and disregarding the much larger area of the screen that remains more or less the same. So instead of needing to store a long sequence of complete images, only the differences between one image and the next are recorded. This only requires a fraction of the conventional storage space and as a bonus it means that data can be unpacked extremely quickly.

An overview of IFF animation

AMOS Professional IFF animation files are divided into a number of separate components, the "frames" of your animation sequence. A frame may be either a normal screen or one image in the sequence, but it is important to understand that the first frame sets up the background reference image for the entire animation, and this first frame is a standard IFF picture. All of the following frames are then stored using the delta-encoding system, to be saved as a list of the differences between the new image and the current display.

AMOS Professional offers several alternative methods of exploiting your animations, which may be displayed as an entire sequential video in a single operation, or played in any combination of frames, providing the sequence runs forwards. Maximum use is made of the double buffering system, to ensure smooth screen displays, although you are free to ignore this feature and summon up some flickering screen effects.

IFF animation can be used directly with most other AMOS Professional graphics commands, including SCREEN COPY and SCROLL, and you can experiment with any area that is not being currently animated. Obviously, if you try to draw over the area of the animation, the display will become corrupted. It should also be noted that IFF animation is not compatible with the standard Bob routines. When using Bobs, it is safe to hide the IFF animation on an invisible background screen and copy the results to the main display. Please see Chapter 7.3 for an explanation of updating objects. Of course, the easiest solution is to bypass the problem entirely and use sprites instead of Bobs!

It is important to remember that IFF animations can only be played forwards. Never attempt to run your frames in reverse order. A special function is provided for skipping over any frames you want to miss out.

You should be aware that even with delta-encoding, large, colourful and lengthy animations will still consume huge amounts of memory, but AMOS Professional can release this memory ready for re-use, as you are about to discover.

Creating an IFF animation

Many hours can be spent in the creative art of designing home-grown IFF pictures, and adapting them for animation sequences. On the other hand, you can cheat! If a video digitiser is beyond your budget there are plenty of public domain images to be found, but the most flexible method is to use commercial packages like Deluxe Paint. III or IV. AMOS Professional uses compressed" (Mode 5) animations, which should be selected from the menu of a commercially available drawing package. Deluxe Paint uses this mode as a default, allowing you to draw your frames one by one on the screen, and then generate the necessary ANIM files automatically. Deluxe Paint users can produce animations using the following procedure:

Playing an IFF animation

IFF ANIM

instruction: play an animation file
Iff Anim "filename" To screen number
Iff Anim "filename" To screen number, times

This function provides the most straightforward way of displaying a complete IFF animation sequence directly on screen. The "filename" must refer to a valid IFF animation saved in "compressed" (Mode 5) format. The screen number defines the screen to be created for the animation sequence. If the requested screen number already exists, it will be replaced by the new definition automatically. There is an optional parameter to set the number of times the animated sequence is to be played. If this number is omitted, the animation will be played once.

Remember that frame number 1 is the background screen that serves as the basis for the entire sequence, so that your animation will always re-start from frame number 2.

After the animation has been played the requested number of times it will stop. The memory consumed will automatically be released back to AMOS Professional for re-use.

If you have a disc containing an IFF animation file, place it into any drive and call up the standard file selector, like this:

Iff Anim Fsel$("**") To 0,10

When the file is requested, your animation sequence will be loaded into screen 0 and cycled through ten times.

Direct IFF animation

Because the standard AMOS Professional drawing commands may be used with IFF animations, you are provided with a range of functions for loading and manipulating animated sequences directly in your programs.

FRAME LOAD

function: load frames into memory
frames=Frame Load(channel To bank/address)
frames=Frame Load(channel To bank/address,number of frames)

Use this function to load one or more IFF frames directly into memory. The parameters in brackets are as follows:

The channel number is the number of an animation file that is currently opened using the OPEN IN command.

Next, specify the memory address or bank number where the frames are to be stored. If an address is specified, the entire file will be loaded into the chosen memory area, exactly like a BLOAD instruction. If you give a bank number, a new memory bank will be reserved automatically. It will hold your animation frames and be a permanent data bank in fast memory, called "IFF". Please note that bank numbers can range from 1 to 65535. To avoid overrunning your memory area and crashing the system, it is vital that enough space is reserved to hold the entire animation sequence in memory. The actual storage requirements may be calculated with the FRAME LENGTH function, which is explained later.

Finally, there is an optional parameter that specifies the number of animation frames to be loaded. If this number is omitted, only Frame 1 will be loaded, but if your request is greater than the total number of available frames, all of the images will be grabbed in the current file, if memory allows. This can be exploited to load entire sequences no matter what their length, by setting this optional parameter to an overlarge number, as no error will be generated.

FRAME LOAD returns the number of frames that have been successfully loaded into memory. This value may be saved into a variable once the animation has been loaded, and made use of when the sequence is to be played. For example:

Rem Open animation file for reading Open In 1,"AMOSPro_Tutorial:Iff_Anim/AMOS.Anim" Rem Load all frames in current file Rem use overlarge value of 1000 to grab all available images to bank 10 N=Frame Load (1 To 10,1000) Close Rem N now holds the number of actual frames Print "Number of frames in this file is ";N

FRAME LENGTH

function: return the length of frames in bytes
size=Frame Length(channel)
size=Frame Length(channel,number of frames)

This function is used to calculate the precise amount of memory needed to hold the selected frames of an IFF animation file. To find the exact size of the required data area with FRAME

LENGTH, simply give the channel number of the IFF file previously opened with the OPEN IN command.

You may also specify the number of frames to be taken into consideration. If this number is omitted, only the first frame in the animation with be checked. Alternatively, if an overlarge number is specified, the exact memory requirements of all the frames in the current file will be returned.

FRAME LENGTH does not change the position of the file pointer, but leaves it at the start of the next animation frame to be loaded. So it can be used immediately before a FRAME LOAD command to check the memory requirement of your new animation. For example:

Open In 1 ,"AMOSPro_Tutorial:Iff_Anim/AMOS.Anim" Rem Load first frame only into memory L=Frame Length(1) Rem Reserve space for the frame in Bank 10 Reserve As Work 10,L N=Frame Load(1 To 10) Close Print "Required memory for frame 1=";L

FRAME PLAY

function: play frames on screen
frame=Frame Play(bank/address,number)
frame=Frame Play(bank/address,number,screen)

Use this function to display animations on screen at the appropriate points in your programs. Specify the memory address or bank number containing an IFF animation sequence that has already been loaded by FRAME LOAD. Please note that addresses must be even and that the first bytes must be a valid IFF Frame definition. Next specify the number of frames that you want to play.

The optional screen parameter is the identifier of a new screen to be created for the animation, and it can be used to automatically define a screen as the first frame of the animation to be displayed. If this screen number is omitted, an attempt will be made to use the current screen.

Please note that your new screen will not be set up for double buffering, and you should activate this directly from your program with the DOUBLE BUFFER command, if required. Also, the IFF animation will be displayed on the logical screen, and when using double buffering SCREEN SWAP must be employed, otherwise the animation will run invisibly in the background!

Once the FRAME PLAY function has been called, the start address of the next frame in the sequence will be returned, and this address can be used to display the following frame of the animation.

For example:

Rem Play the first frame in Bank 10 using screen 0 F=Frame Play(10,1,0) Double Buffer : Rem activate non automatic double buffer Rem Display next frame F=Frame Play(F,1)

When the end of the animation sequence has been reached, your F variable points to the last frame of the animation. Because the exact number of frames is returned to the FRAME LOAD function, FRAME PLAY can be enclosed in a loop for simplicity, like this:

Open In 1,"AMOSPro_Tutorialiff_Anim/AMOS.Anim" L=Frame Load(1 To 10,1000) Close Rem Play first frame from Bank 0 and define new screen 0 Do P=Frame Play(10,1,0) Double Buffer For X=2 To L-1 : Rem Play sequence to the end P=Frame Play(P,1) : Rem Play next frame Screen Swap : Rem Make animation visible Wait Vbl : Wait Vbl : Wait Vbl Next X Loop

FRAME SKIP

function: skip past an animation frame
s=Frame Skip(bank/address)
s=Frame Skip(bank/address,number)

This is exactly the same as FRAME PLAY, except that no output is made to the screen. FRAME SKIP omits any selected frames and returns the address of the next frame to be played in the sequence. The bank or address number of a valid IFF animation frame is given, followed by the number of frames to be skipped over.

Use FRAME SKIP carefully, because frames are stored relative to the existing screen background. This means that the animation will only re-commence when an identical frame is reached to the one currently being displayed.

FRAME PARAM

function: return a parameter after playing a frame
p=Frame Param

This function returns the amount of time needed to successfully display an animation on screen, measured in 50ths of a second. It is used after FRAME PLAY or FRAME SKIP to delay the program until the screen has been totally re-drawn.

Deluxe Paint users may need to slow down the speed of AMOS Professional animations by one fiftieth of a second, in order to harmonise the display, like this:

Wait Form Param+1

This has nothing to do with the Deluxe Paint package, but takes into account the extra efficiency of the AMOS Professional double buffering and copper calculations, when compared to the standard Workbench routines!

IFF Masking

AMOS Professional does not restrict you to loading all of an IFF picture file. It is possible to load specific parts of the file that hold such items as the palette and the bit-maps only. The PICTURE function is used in conjunction with the MASK IFF function to achieve this.

PICTURE

function: return mask details of an IFF image
mask=Picture

MASK IFF

instruction: mask IFF picture data
Mask Iff bit-map

The PICTURE function returns the precise format of the mask used by a picture, and it is used like this:

Mask Iff Picture Load Iff "Picture_Name"

Here are some typical settings that can be used to load masked data from an IFF file:

Mask Iff %100 : Rem Load palette of picture only Mask Iff %10000 : Rem Load bitmaps only

Freezing the display

In the next Chapter, the AMOS Professional animation language AMAL is explained. AMAL animations can be frozen with an AMAL FREEZE instruction, and unfrozen with AMAL ON. The following commands are equivalents to these two instructions, and also offer STOS compatibility.

FREEZE

instruction: freeze the display
Freeze

UNFREEZE

instruction: unfreeze the display
Unfreeze

Use these commands in your AMOS Professional programs to perform a simple freezing and unfreezing of moving displays.