(*
   Name   : IFF.DEF
   Version: 1.0
   Author : Sascha Wildner
   Date   : 27-Jul-90

   Description: Benchmark Modula-2 interface to CHW's iff.library


   -== UPDATE HISTORY ==-

   Date          Version            Author          Comments
   --------------------------------------------------------------------------
   27-Jul-90       1.0              Sascha Wildner  First implementation
                                                                              *)


DEFINITION MODULE IFF;

   FROM SYSTEM    IMPORT ADDRESS, BYTE;
   FROM AmigaDOS  IMPORT FileHandle;
   FROM Graphics  IMPORT BitMap;
   FROM Libraries IMPORT LibraryPtr;
   FROM Memory    IMPORT MemReqSet;
   FROM Views     IMPORT ColorTable, ViewModesSet;


   CONST IFFName = "iff.library";

   VAR IFFBase: LibraryPtr;


   TYPE ChunkPtr = POINTER TO Chunk;
        Chunk = RECORD
                   ckID  : LONGINT;
                   ckSize: LONGINT;
                   ckData: BYTE;
                END;

        BitMapHeaderPtr = POINTER TO BitMapHeader;
        BitMapHeader = RECORD
                          Width           : CARDINAL;
                          Height          : CARDINAL;
                          X               : INTEGER;
                          Y               : INTEGER;
                          NPlanes         : BYTE;
                          Masking         : BYTE;
                          Compression     : BYTE;
                          Pad1            : BYTE;
                          TransparentColor: CARDINAL;
                          XAspect         : BYTE;
                          YAspect         : BYTE;
                          PageWidth       : INTEGER;
                          PageHeight      : INTEGER;
                       END;

        Asc4 = ARRAY [0..3] OF CHAR;


   (* Error codes *)
   CONST IFFBadTask = -1; (* IFFError() called by wrong task *)

         IFFCantOpenFile = 16; (* File not found *)
         IFFReadError    = 17; (* Error reading file *)
         IFFNoMem        = 18; (* Not enough memory *)
         IFFNotIFF       = 19; (* File is not an IFF file *)
         IFFWriteError   = 20; (* Error writing file *)

         IFFNoILBM             = 24; (* IFF file is not of type ILBM *)
         IFFNoBMHD             = 25; (* BMHD chunk not found *)
         IFFNoBODY             = 26; (* BODY chunk not found *)
         IFFTooManyPlanes      = 27; (* BODY has more planes than BitMap *)
         IFFUnknownCompression = 28; (* Unknown compression type *)



PROCEDURE NewOpenIFF(FileName: ADDRESS; MemAttr: MemReqSet): FileHandle;
(* Allocate memory for an IFF-file and read it *)

PROCEDURE OpenIFF(FileName: ADDRESS): FileHandle;
(* Allocate memory for an IFF-file and read it *)

PROCEDURE CloseIFF(IFFFile: FileHandle);
(* Finish access to an IFF-file and deallocate memory *)

PROCEDURE FindChunk(IFFFile: FileHandle; ChunkName: Asc4): ChunkPtr;
(* Find an IFF-Chunk *)

PROCEDURE GetBMHD(IFFFile: FileHandle): BitMapHeaderPtr;
(* Find a BitMapHeader of an IFF-file *)

PROCEDURE GetColorTab(IFFFile: FileHandle; VAR ColTab: ColorTable): LONGINT;
(* Find a CMAP chunk and convert it into a ColorTable *)

PROCEDURE DecodePic(IFFFile: FileHandle; BMap: BitMap): BOOLEAN;
(* Decode an IFF-BODY into a BitMap *)

PROCEDURE SaveBitMap(FileName: ADDRESS; BMap: BitMap; ColTab: ColorTable;
                     Flags: BYTE): BOOLEAN;
(* Save the planes of a BitMap as an IFF-file *)

PROCEDURE SaveClip(FileName: ADDRESS; BMap: BitMap; ColTab: ColorTable;
                   Flags: BYTE; XOff: CARDINAL; YOff: CARDINAL; Width: CARDINAL;
                   Height: CARDINAL): BOOLEAN;
(* Save a part of a BitMap as an IFF-file *)

PROCEDURE IFFError(): INTEGER;
(* Get detailed error description *)

PROCEDURE GetViewModes(IFFFile: FileHandle): ViewModesSet;
(* Get Amiga-Specific ViewModesSet *)

END IFF.
