rianimlib
This library plays IFF animations (ANIM files) in the two common delta
formats, ANIM5 and ANIM7. The animation must be loaded into memory by
the program, in chip or fast memory; the library works on its address.
Frames are drawn into bitmap objects, at any position inside the
bitmap, and colour changes of the frames go into a palette object.
RIAnimWidth, RIAnimHeight and RIAnimDepth tell the size of the
animation, so suitable bitmaps can be made before playing it.
RIAnimInit unpacks the first frame into a bitmap and sets the
palette; each RINextAnimFrame then changes a bitmap into the next
frame. In these formats every frame is stored as the change against
the frame two steps before it, so an animation is played double
buffered: two bitmaps that both start with the first frame, and the
frames drawn into them in turn. A first frame stored as a delta
instead of a full picture is not supported.
RIAnimInit refuses a bitmap that is too narrow or not deep enough
for the first frame. It checks neither the height nor whether the
animation fits at the chosen position, so make the bitmaps large
enough. With runtime error checking, a position outside the bitmap
stops the program with the runtime error “Animation position outside
the bitmap”.
Place an ANIM7 animation at an even byte of the bitmap: an x of 0
to 7, 16 to 23 and so on, or an even byte offset. At an odd byte its
frames crash a 68000; with runtime error checking, RINextAnimFrame
stops before such a frame with the runtime error “Animation position
on an odd byte for ANIM7”.
The library steps through the animation from chunk to chunk, within
its length, and skips the pad byte the IFF standard puts behind a
chunk of odd length; chunks other than frames, such as annotations,
may lie between the frames. RIAnimInit refuses an animation written
without those pad bytes.
The library uses the RI Pack library to unpack the first frame and to read the palettes, so that library must be installed too.
With an animation loaded at address m, played once through bitmaps
0 and 1:
w=RIAnimWidth(m) : h=RIAnimHeight(m) : d=RIAnimDepth(m)
BitMap 0,w,h,d
BitMap 1,w,h,d
If RIAnimInit(m,0,0)
CopyBitMap 0,1
AnimLoop Off
b=1
While RINextAnimFrame(b)
; show bitmap b here
b=1-b
Wend
EndIfThe fixed bugs of the library are listed in Fixes in rianimlib.
Based on the RI Anim Lib guide by Reflective Images.
Library number 57.
Commands
AnimLoop
With On, the default at the start of every run, RINextAnimFrame goes on with the third frame after the last one; with Off it stops there.
Statement. Help text: On|Off
Arguments: .b
RIAnimDepth
The number of bitplanes of the animation at address, 0 if it is not an animation with a bitmap header or a chunk before that header starts at an odd address because a pad byte is missing.
Function, result .w. Help text: address -- address of your animation file
Arguments: .l
RIAnimFrameCount
The number of frames of the animation started with RIAnimInit, 0 before the first RIAnimInit.
Function, result .w. No help text.
No arguments.
RIAnimHeight
The height in pixels of the animation at address, 0 if it is not an animation with a bitmap header or a chunk before that header starts at an odd address because a pad byte is missing.
Function, result .w. Help text: address -- address of your animation file
Arguments: .l
RIAnimInit
Starts an animation held in memory at address - unpacks its first frame into the bitmap and copies its palette into the palette object. Returns -1 on success and 0 on failure.
Statement or function, result .l. Help text: (address,bitmap#,palette# [,xy_offset]|[,x,y])
3 forms:
.l, .l, .l.l, .l, .l, .l.l, .l, .l, .l, .l
It returns 0 if:
- the data is not an animation with a first frame and a bitmap header
- its width is 0
- its depth is 0 or above 8
- a chunk in it starts at an odd address because a pad byte is missing
- the bitmap is too narrow or not deep enough for the first frame
The bitmap header must be in the first frame. After a failed call
there is no animation: RIAnimFrameCount and RINextAnimFrame
return 0.
The optional position is either a byte offset into the bitplanes,
(x/8)+y*(bytes per row), or a pixel position x,y; x is rounded
down to a multiple of 8. The frames that RINextAnimFrame draws use
the same position. With runtime error checking, an x,y outside
the bitmap stops the program with the runtime error “Animation
position outside the bitmap”; nothing checks that the whole
animation fits into the bitmap at the position. An ANIM7 animation
must be placed at an even byte, as the introduction above explains;
ANIM5 plays at any position.
RIAnimWidth
The width in pixels of the animation at address, 0 if it is not an animation with a bitmap header or a chunk before that header starts at an odd address because a pad byte is missing.
Function, result .w. Help text: address -- address of your animation file
Arguments: .l
RINextAnimFrame
Changes the bitmap into the next frame of the animation started with RIAnimInit; a new palette of the frame goes into the palette object given to RIAnimInit. Returns -1 if a frame was drawn, 0 if not.
Statement or function, result .l. Help text: (bitmap#)
Arguments: .b
After the last frame it goes on with the third frame if AnimLoop is
on, the default, and returns 0 if it is off. Animations end with two
loop frames that lead back to the start; without them, keep
AnimLoop off.
It also returns 0:
- before an
RIAnimInit - for a frame of another delta format
- for a frame without delta data
- for a frame whose chunks claim to be longer than the frame
- for a frame whose delta data points outside its chunk, or, for ANIM7, to an odd offset in it
Other chunks between the frames, or before the delta data of a frame,
are skipped. ANIM7 is played with short (word) and with long data.
With runtime error checking, an ANIM7 frame at an odd byte position
of RIAnimInit stops the program with the runtime error “Animation
position on an odd byte for ANIM7”.
ANIM7 long data covers a row 32 pixels at a time. In a row with an odd number of words, such as a width of 33 to 48 pixels, its last 16 pixels are not updated by frames with long data, since the format does not say what the data holds there. An animation up to 16 pixels wide is therefore not changed by such frames.
Kept from the original on purpose: a run or copy count of 0 in the delta data counts as 256 rows; the ANIM format does not define a count of 0, and encoders do not write one (#508).
Also kept, for speed: only the start of each plane’s delta data is checked against the chunk, not the runs and copies inside the columns, so a corrupt animation can still read beyond its delta data and write beyond the bitmap (#1120).