home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 1: Amiga
/
FrozenFish-Apr94.iso
/
bbs
/
alib
/
d6xx
/
d680
/
sattrack.lha
/
SatTrack
/
ifflib20.lzh
/
IFFLib.doc
< prev
next >
Wrap
Text File
|
1990-10-09
|
16KB
|
542 lines
THE UNIVERSAL IFF LIBRARY FOR THE AMIGA
VERSION 19.1 09-OCT-90
BY CHRISTIAN A. WEBER, ZURICH/SWITZERLAND
(UUCP: cbmvax.commodore.com!cbmehq!cbmswi!zethos!mighty!chris, BIX: chw)
THIS PROGRAM IS IN THE PUBLIC DOMAIN. IT MAY BE FREELY DISTRUBUTED, COPIED
AND USED FOR COMMERCIAL OR NON-COMMERCIAL PURPOSES. IT MAY BE DISTRIBUTED
WITH OR WITHOUT THIS DOCUMENTATION FILE. IF YOU INCLUDE THE LIBRARY WITH
A COMMERCIAL PRODUCT, FEEL FREE TO SEND ME A FREE COPY OF THE PRODUCT.
TO MAINTAIN COMPATIBILITY, YOU SHOULD NOT MAKE ANY CHANGES TO THE LIBRARY.
UPDATES WILL BE RELEASED BY THE AUTHOR.
WHAT IFF FILES CAN BE HANDLED?
------------------------------
I wrote this library to provide an easy way for reading and writing simple
IFF files, such as pictures, animations, sound samples etc.
In order to keep things easy, the IFF parser is NOT recursive. This means
that it cannot handle files which contain recursive FORM or CAT definitions
(e.g. a FORM containing another FORM).
This restriction is not as important as you might think, since over 97%
of all currently existing IFF files are not recursive. (Aren't statistics
nice? ;-)
If you really need a recursive IFF parser, you should use the original
Electronic Arts code, or the WB 2.0 iffparse.library.
Note that the iff.library can deal with ANIM files, although they contain
nested FORMs. This is done with a little trick, see 'AnimExample.c' for
details.
WHAT WILL BE CHANGED IN THE FUTURE
----------------------------------
The SaveBitMap() and SaveClip() functions currently are the only way to
generate IFF files with this library. This is very un-flexible, since
there is no way to add specific chunks to a file. So, I will add some
general-purpose functions which allow you to easily write any IFF files
of any type. Also, there will be a new method for specifying view modes,
because there are lots of new modes in Kickstart 2.0.
The new version (V20) should be ready in a few weeks.
LIBRARY FUNCTION OVERVIEW
-------------------------
Name Offset Description
OpenIFF -30 Allocate memory for an IFF-file and load it
CloseIFF -36 Finish access to an IFF-file and deallocate memory
FindChunk -42 Find a specific chunk in an IFF file
GetBMHD -48 Find the BitMapHeader of an ILBM file
GetColorTab -54 Find CMAP chunk, convert it to an Amiga ColorTable
DecodePic -60 Decode the BODY of an ILBM file into a BitMap
SaveBitMap -66 Save the contents of a BitMap as an IFF-file
SaveClip -72 Save a part of a BitMap as an IFF-file
IFFError -78 Get detailed error descrpition if a routine fails
GetViewModes -84 Get the Amiga-specific ViewModes
NewOpenIFF -90 Allocate specific memory for an IFF-file and load it
ModifyFrame -96 Modify an anim frame using a DLTA chunk
(to be continued)
DETAILED DESCRIPTION OF THE LIBRARY FUNCTIONS
---------------------------------------------
(This documentation was translated from German to English in half an hour,
so please be tolerant!)
iff.library/NewOpenIFF iff.library/NewOpenIFF
NAME
NewOpenIFF -- allocate memory for an IFF-file and read it
SYNOPSIS
ifffile = NewOpenIFF(filename,memattr)
D0 A0 D0
LIBRARY OFFSET
-90
FUNCTION
This function opens a file on a disk and looks whether it's an IFF
file or not. If it is an IFF file, memory is allocated and the file
is read into memory. The 'memattr' argument is taken to define the
memory type. Normally memattr is set to 0 or MEMF_PUBLIC.
If an error occurs, 0 is returned, and you can call IFFError() to
get the error number.
INPUTS
filename - Pointer to a null-terminated string
memattr - Memory requirements as used for Exec's AllocMem(),
such as MEMF_CHIP, MEMF_PUBLIC ...
(MEMF_CLEAR is not necessary)
RESULT
ifffile - 'FileHandle', points to the beginning of the IFF file
("FORM...."), Zero if unsuccessful. Call IFFError() to get the
reason of the failure.
SEE ALSO
OpenIFF, CloseIFF, IFFError
BUGS
None known
iff.library/OpenIFF iff.library/OpenIFF
NAME
OpenIFF -- allocate memory for an IFF-file and read it
SYNOPSIS
ifffile = OpenIFF(filename)
D0 A0
LIBRARY OFFSET
-90
FUNCTION
This function does the same as the NewOpenIFF() routine above,
except that you cannot specify the type of memory which is
allocated for the file. Normally the type is 0 which means 'any
memory', but if the IFF file type is '8SVX', the file is ALWAYS
loaded into CHIP memory. If you wish to override these defaults,
use NewOpenIFF() instead of OpenIFF().
INPUTS
filename - Pointer to a null-terminated string
RESULT
ifffile - 'FileHandle', points to the beginning of the IFF file
("FORM...."), 0 if unsuccessful. Call IFFError() to get the
reason of the failure.
SEE ALSO
NewOpenIFF, CloseIFF, IFFError
BUGS
None
iff.library/CloseIFF iff.library/CloseIFF
NAME
CloseIFF -- finish access to an IFF-file and deallocate memory
SYNOPSIS
CloseIFF(ifffile)
A1
LIBRARY OFFSET
-36
FUNCTION
Returns the memory previously allocated by OpenIFF().
INPUTS
ifffile - IFF file pointer, from OpenIFF()
RESULT
none
SEE ALSO
OpenIFF
BUGS
If A1 contains garbage, an 81000005 Guru will visit you...
iff.library/FindChunk iff.library/FindChunk
NAME
FindChunk -- find an IFF-chunk
SYNOPSIS
chunk = FindChunk(ifffile,chunkname)
D0 A1 D0
LIBRARY OFFSET
-42
FUNCTION
Find a specific chunk in an IFF file
INPUTS
ifffile - pointer to a FORM, normally the result of OpenIFF()
chunkname - 4 characters packed ASCII ('BODY', 'VHDR' ...)
if chunkname is 0, FindChunk() returns a pointer to the
first byte after the end of the current FORM. This can
be used byANIM readers for jumping from FORM to FORM.
RESULT
Pointer to the beginning of the chunk (that means to the chunk
name itself, followed by the chunk size), zero if chunk not found
SEE ALSO
GetBMHD, GetColorTab
BUGS
none known
iff.library/GetBMHD iff.library/GetBMHD
NAME
GetBMHD -- find a BitMapHeader of an IFF-file
SYNOPSIS
header = GetBMHD(ifffile)
D0 A1
LIBRARY OFFSET
-48
FUNCTION
Returns a pointer to a 'BitMapHeader' structure as defined in
iff.h and iff.i
INPUTS
ifffile - IFF file pointer, returned by OpenIFF()
RESULT
Pointer to the BitMapHeader, or 0 if no BMHD chunk found
SEE ALSO
FindChunk, GetColorTab
BUGS
none
iff.library/GetColorTab iff.library/GetColorTab
NAME
GetColorTab -- find a CMAP chunk and convert it to a ColorTable
SYNOPSIS
count = GetColorTab(ifffile,colortable)
D0 A1 A0
LIBRARY OFFSET
-54
FUNCTION
Searches the CMAP chunk of an IFF file and converts it, if it's
there, to an Amiga color table structure. This colortable can
directly be used as a parameter for the LoadRGB4() function.
INPUTS
ifffile - IFF file pointer, returned by OpenIFF()
colortable - Pointer to a block of memory which must be large
enough to hold the colortable (2 bytes per color)
RESULT
Number of colors actually found, or zero if the file has no
CMAP chunk
SEE ALSO
FindChunk, GetBMHD
WARNING
the colortable must be WORD aligned
iff.library/DecodePic iff.library/DecodePic
NAME
DecodePic -- decode the BODY of an ILBM file into a BitMap
SYNOPSIS
success = DecodePic(ifffile,bitmap)
D0 A1 A0
LIBRARY OFFSET
-60
FUNCTION
Decodes and decrunches a picture into the user supplied BitMap.
If the picture is larger than your BitMap's planes, it will be
truncated. If your BitMap is larger than the picture, the picture
will be drawn into the top left corner of your BitMap.
If the picture has less planes than the BitMap, the unused planes
are NOT touched by this routine, so you may wish to clear them
before calling DecodePic(). If the picture has more planes than
your BitMap, the surplus planes of the picture are ignored.
INPUTS
ifffile - IFF file pointer, from OpenIFF()
bitmap - Pointer to a properly initialized BitMap structure:
bm_Planes[] must point to valid BitPlanes,
bm_Depth contains the number of planes.
bm_Width and bm_Height must be set according to the
size of your bit planes.
RESULT
Non-zero if OK, 0 if error, Call IFFError() to know the reason
of the failure
WARNING
This routine needs 620 bytes of stack space
iff.library/SaveBitMap iff.library/SaveBitMap
NAME
SaveBitMap -- save the planes of a BitMap as an IFF-file
SYNOPSIS
result = SaveBitMap(filename,bitmap,colortable,flags)
D0 A0 A1 A2 D0
LIBRARY OFFSET
-66
FUNCTION
Save the planes of a BitMap as an IFF-file, optionally with a
colortable. The IFF file will contain the following chunks:
FORM - The IFF header, with the type ILBM
BMHD - The BitMap Header structre
CMAP - The color map, this chunk is omitted if colortable is zero
CAMG - The Amiga ViewModes word, contains the special ViewModes
information (HAM, LACE, HIRES ...)
BODY - The (crunched or uncompressed) picture
INPUTS
filename - Name of the IFF file to create
bitmap - Pointer to the BitMap holding your picture
colortable - Pointer to an Amiga ColorTable structure or zero
(if colortable = 0, no CMAP chunk will be generated).
flags - Bit 0: 1 = Use the "CmpByteRun1" compression algorythm,
0 = Save the file uncompressed
Bit 7: 1 = This is a HAM (Hold and modify) picture
0 = This is a normal or Extra-Halfbrite picture
RESULT
Non-zero if successful, 0 if error, Call IFFError() to know the
reason of the failure
WARNING
This routine needs 620 bytes of stack space
SEE ALSO
SaveClip
iff.library/SaveClip iff.library/SaveClip
NAME
SaveClip -- save a part of a BitMap as an IFF-file
SYNOPSIS
result = SaveClip(filename,bitmap,coltab,flags,xoff,yoff,width,height)
D0 A0 A1 A2 D0 D1 D2 D3 D4
LIBRARY OFFSET
-72
FUNCTION
Save a part of a BitMap as an IFF file
INPUTS
filename - Name of the IFF file to create
bitmap - Pointer to the BitMap holding your picture
colortable - Pointer to an Amiga ColorTable structure or zero
(if colortable = 0, no CMAP chunk will be generated).
flags - Bit 0: 1 = Use the "CmpByteRun1" compression algorythm,
0 = Save the file uncompressed
Bit 7: 1 = This is a HAM (Hold and modify) picture
0 = This is a normal or Extra-Halfbrite picture
xoff - X offset of the clip to be saved (bytes from the left)
yoff - Y offset of the clip to be saved (lines from the top)
width - width in bytes of the rectangle
height - height in lines of the rectangle
RESULT
Non-zero if successful, 0 if error, Call IFFError() to know the
reason of the failure
WARNING
This routine needs 620 bytes of stack space
SEE ALSO
SaveBitMap
BUGS
The width of the rectangle will be rounded to WORD boundaries,
because DPAINT wants it!
iff.library/IFFError iff.library/IFFError
NAME
IFFError -- Get detailed error descrpition
SYNOPSIS
error = IFFError()
D0
LIBRARY OFFSET
-78
FUNCTION
If one of the above functions returns zero, you can call IFFError()
to know the reason for the failure. An error code is returned,
please refer to the files 'iff.h' or 'iff.i' for the complete
list of errors.
INPUTS
none
RESULT
Error-number generated by the latest function call, or zero if
no error
Cuurently the following numbers are used:
Nr. Symbol Function Description
16 IFF_CANTOPENFILE OpenIFF() File not found
17 IFF_READERROR OpenIFF() Read() returned an error
18 IFF_NOMEM OpenIFF() Not enough memory for the file
19 IFF_NOTIFF OpenIFF() File is not IFF
20 IFF_WRITEERROR SaveBitMap() Cannot write the file
24 IFF_NOILBM DecodePic() IFF file is not an ILBM file
25 IFF_NOBMHD DecodePic() BMHD chunk not found
26 IFF_NOBODY DecodePic() BODY chunk not found
27 IFF_TOOMANYPLANES DecodePic() Picture has more planes than the
BitMap (OBSOLETE SINCE 18.7!)
28 IFF_UNKNOWNCOMPRESSION " Unknown compression type
29 IFF_NOANHD ModifyFrame() ANHD chunk not found
30 IFF_NODLTA ModifyFrame() DLTA chunk not found
-1 IFF_BADTASK A task which did not open the IFF library
tried to call IFFError(). Since the IFF
library is capable of multi-tasking, the
error-values are stored for each task
separately.
SEE ALSO
BUGS
If you don't close the IFF library at the end of your program
(using CloseLibrary()) the error node will not be freed. The
same task will then not be able to re-open the iff.library.
(This is not a bug, it's a feature ;-))
iff.library/GetViewModes iff.library/GetViewModes
NAME
GetViewModes -- Get Amiga-specific ViewModes
SYNOPSIS
viewmodes = GetViewModes(ifffile)
D0 A1
LIBRARY OFFSET
-84
FUNCTION
Searches the IFF file for a 'CAMG' chunk which holds the view modes
information. If there is no CAMG chunk, the view modes are calcu-
lated using the information in the BitMapHeader structure.
You can directly put the low WORD of the result of a GetViewModes()
call into the ns_ViewModes field of a NewScreen structure. All
forbidden bits are masked out, as suggested by CBM.
INPUTS
ifffile - IFF file pointer, returned from OpenIFF()
RESULT
viewmodes - LONG containing the view modes (HAM, LACE, HIRES ...)
Under Kickstart V1.3, only the lower WORD is used.
SEE ALSO
BUGS
If the IFF file has no CAMG chunk and 6 bitplanes, the HAM bit
will be set. This is not always correct since the picture could
be in the Extra Halfbrite mode. You can load such Halfbrite
pictures into DPaint III and save them again, DPaint will generate
the correct CAMG chunk.
iff.library/ModifyFrame iff.library/ModifyFrame
NAME
ModifyFrame -- Modify an anim frame using a DLTA chunk
SYNOPSIS
success = ModifyFrame(modifyform,bitmap)
D0 A1 A0
LIBRARY OFFSET
-96
FUNCTION
Uses the DLTA chunk of the supplied FORM to modify the planes-data
of the bitmap. Usually, playback of ANIMs will require two buffers,
and double-buffering between them. So the data in the bitmap must
be two frames back, and the DLTA chunk is used to modify the hidden
frame to the next frame to be shown.
INPUTS
modifyform - pointer to the FORM containing the actual DLTA chunk
bitmap - Pointer to a properly initialized BitMap structure,
the planes must contain the image which was displayed
to frames back (using double-buffering)
RESULT
Non-zero if OK, 0 if error; call IFFError() to know the reason
of the failure
RESTRICTIONS
Currently, only compression type 5 (Byte Vertical Delta Mode) is
implemented. If you have animations which use modes 1 to 4, try
loading them with DPaint III and saving them again.
Sculpt-Animate pictures do not work, because I have no documentation
about the compression scheme they use.
I will implement some more compression types upon request.
WARNINGS
This routine needs at least 820 bytes of stack.
The size of the bitmap is not checked by this routine, the planes
must have at least the size described in the BMHD of the anim
file.
BUGS