home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 403.lha / VediSrc / include / iff / ilbm.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-06  |  13.0 KB  |  324 lines

  1. #ifndef ILBM_H
  2. #define ILBM_H
  3. /*********************************************************************
  4.  *
  5.  * ILBM.H Definitions for InterLeaved BitMap raster image  23-Jan-86
  6.  *
  7.  * By Jerry Morrison and Steve Shaw, Electronic Arts.
  8.  * This software is in the public domain.
  9.  *
  10.  * This version for the Commodore-Amiga computer.
  11.  *
  12.  *********************************************************************
  13.  *
  14.  * Modified to accept a BEAM chunk in an ILBM FORM. Search for lines
  15.  *
  16.  * containing 'dp' to find the difference from the original EA files
  17.  *
  18.  * Date: 20-Feb-89       Registered Developer: ECI004 - Diego Perini
  19.  *
  20.  ********************************************************************/
  21.  
  22. #ifndef COMPILER_H
  23. #include "iff/compiler.h"
  24. #endif
  25.  
  26. #ifndef GRAPHICS_GFX_H
  27. #include "graphics/gfx.h"
  28. #endif
  29.  
  30. #include "iff/iff.h"
  31.  
  32. #define ID_ILBM MakeID('I','L','B','M')
  33. #define ID_BMHD MakeID('B','M','H','D')
  34. #define ID_CMAP MakeID('C','M','A','P')
  35. #define ID_BEAM MakeID('B','E','A','M') /* dp */
  36. #define ID_CAMG MakeID('C','A','M','G') /* cs */
  37. #define ID_CRNG MakeID('C','R','N','G') /* cs */
  38. #define ID_CCRT MakeID('C','C','R','T') /* cs */
  39. #define ID_BODY MakeID('B','O','D','Y')
  40.  
  41. #define ID_GRAB MakeID('G','R','A','B')
  42. #define ID_DEST MakeID('D','E','S','T')
  43. #define ID_SPRT MakeID('S','P','R','T')
  44.  
  45.  
  46.  
  47. /* ---------- BitMapHeader ---------------------------------------------*/
  48.  
  49. typedef UBYTE Masking;      /* Choice of masking technique.*/
  50. #define mskNone                 0L /* dp */
  51. #define mskHasMask              1L
  52. #define mskHasTransparentColor  2L
  53. #define mskLasso                3L
  54.  
  55. typedef UBYTE Compression;   /* Choice of compression algorithm applied to
  56.      * each row of the source and mask planes. "cmpByteRun1" is the byte run
  57.      * encoding generated by Mac's PackBits. See Packer.h . */
  58. #define cmpNone      0L /* dp */
  59. #define cmpByteRun1  1L
  60.  
  61. /* Aspect ratios: The proper fraction xAspect/yAspect represents the pixel
  62.  * aspect ratio pixel_width/pixel_height.
  63.  *
  64.  * For the 4 Amiga display modes:
  65.  *   320 x 200: 10/11  (these pixels are taller than they are wide)
  66.  *   320 x 400: 20/11
  67.  *   640 x 200:  5/11
  68.  *   640 x 400: 10/11      */
  69. #define x320x200Aspect 10L /* dp */
  70. #define y320x200Aspect 11L
  71. #define x320x400Aspect 20L
  72. #define y320x400Aspect 11L
  73. #define x640x200Aspect  5L
  74. #define y640x200Aspect 11L
  75. #define x640x400Aspect 10L
  76. #define y640x400Aspect 11L
  77.  
  78. /* A BitMapHeader is stored in a BMHD chunk. */
  79. typedef struct {
  80.     UWORD w, h;         /* raster width & height in pixels */
  81.     WORD  x, y;         /* position for this image */
  82.     UBYTE nPlanes;      /* # source bitplanes */
  83.     Masking masking;      /* masking technique */
  84.     Compression compression;   /* compression algorithm */ /* dp */
  85.     UBYTE pad1;         /* UNUSED.  For consistency, put 0 here.*/
  86.     UWORD transparentColor;   /* transparent "color number" */
  87.     UBYTE xAspect, yAspect;   /* aspect ratio, a rational number x/y */
  88.     WORD  pageWidth, pageHeight;  /* source "page" size in pixels */
  89.     } BitMapHeader;
  90.  
  91. /* RowBytes computes the number of bytes in a row, from the width in pixels.*/
  92. #define RowBytes(w)   (((w) + 15L) >> 4L << 1L) /* dp */
  93.  
  94.  
  95. /* ---------- ColorRegister --------------------------------------------*/
  96. /* A CMAP chunk is a packed array of ColorRegisters (3 bytes each). */
  97. typedef struct {
  98.     UBYTE red, green, blue;   /* MUST be UBYTEs so ">> 4" won't sign extend.*/
  99.     } ColorRegister;
  100.  
  101. /* Use this constant instead of sizeof(ColorRegister). */
  102. #define sizeofColorRegister  3L /* dp */
  103.  
  104. typedef WORD Color4;   /* Amiga RAM version of a color-register,
  105.           * with 4 bits each RGB in low 12 bits.*/
  106.  
  107. /* Maximum number of bitplanes in RAM. Current Amiga max w/dual playfield. */
  108. #define MaxAmDepth 6L
  109.  
  110. /* ---------- Point2D --------------------------------------------------*/
  111. /* A Point2D is stored in a GRAB chunk. */
  112. typedef struct {
  113.     WORD x, y;      /* coordinates (pixels) */
  114.     } Point2D;
  115.  
  116. /* ---------- DestMerge ------------------------------------------------*/
  117. /* A DestMerge is stored in a DEST chunk. */
  118. typedef struct {
  119.     UBYTE depth;   /* # bitplanes in the original source */
  120.     UBYTE pad1;      /* UNUSED; for consistency store 0 here */
  121.     UWORD planePick;   /* how to scatter source bitplanes into destination */
  122.     UWORD planeOnOff;   /* default bitplane data for planePick */
  123.     UWORD planeMask;   /* selects which bitplanes to store into */
  124.     } DestMerge;
  125.  
  126. /* ---------- SpritePrecedence -----------------------------------------*/
  127. /* A SpritePrecedence is stored in a SPRT chunk. */
  128. typedef UWORD SpritePrecedence;
  129.  
  130. /* ---------- Beam Palette ---------------------------------------------*/
  131. /* A Commodore Amiga Beam Palette is stored in a BEAM chunk. */
  132. typedef struct {    /* dp */
  133.     UWORD Version;
  134.     UWORD Future;
  135.     ULONG *Palettes;
  136.     } BeamChunk;
  137.  
  138. /* ---------- Camg Amiga Viewport Mode ---------------------------------*/
  139. /* A Commodore Amiga ViewPort->Modes is stored in a CAMG chunk. */
  140. /* The chunk's content is declared as a LONG. */
  141. typedef struct {    /* cs */
  142.     ULONG ViewModes;
  143.     } CamgChunk;
  144.  
  145. /* ---------- Crng cycling chunk -------------------------------------*/
  146. /* A Crng is store in a CRNG chunk. */
  147. typedef struct {    /* cs */
  148.     WORD  pad1;              /* reserved for future use; store 0 here */
  149.     WORD  rate;      /* 60/sec=16384, 30/sec=8192, 1/sec=16384/60=273 */
  150.     WORD  active;     /* bit0 set = active, bit 1 set = reverse */
  151.     UBYTE low, high;   /* lower and upper color registers selected */
  152.     } CrngChunk;
  153.  
  154. /* ---------- Ccrt (Graphicraft) cycling chunk -------------------------*/
  155. /* A Ccrt is stored in a CCRT chunk. */
  156. typedef struct {    /* cs */
  157.    WORD  direction;  /* 0=don't cycle, 1=forward, -1=backwards */
  158.    UBYTE start;      /* range lower */
  159.    UBYTE end;        /* range upper */
  160.    LONG  seconds;    /* seconds between cycling */
  161.    LONG  microseconds; /* msecs between cycling */
  162.    WORD  pad;        /* future exp - store 0 here */
  163.    } CcrtChunk;
  164.  
  165. /* ---------- ILBM Writer Support Routines -----------------------------*/
  166.  
  167. /* Note: Just call PutCk to write a BMHD, GRAB, DEST, SPRT, or CAMG
  168.  * chunk. As below. */ /* dp */ /* cs */
  169. #define PutBMHD(context, bmHdr)  \
  170.     PutCk(context, ID_BMHD, (LONG)sizeof(BitMapHeader), (BYTE *)bmHdr)
  171. #define PutGRAB(context, point2D)  \
  172.     PutCk(context, ID_GRAB, (LONG)sizeof(Point2D), (BYTE *)point2D)
  173. #define PutDEST(context, destMerge)  \
  174.     PutCk(context, ID_DEST, (LONG)sizeof(DestMerge), (BYTE *)destMerge)
  175. #define PutSPRT(context, spritePrec)  \
  176.     PutCk(context, ID_SPRT, (LONG)sizeof(SpritePrecedence), (BYTE *)spritePrec)
  177. #define PutCAMG(context, camg)  \
  178.     PutCk(context, ID_CAMG, (LONG)sizeof(CamgChunk),(BYTE *)camg)
  179. #define PutCRNG(context, crng)  \
  180.     PutCk(context, ID_CRNG, (LONG)sizeof(CrngChunk),(BYTE *)crng)
  181. #define PutCCRT(context, ccrt)  \
  182.     PutCk(context, ID_CCRT, (LONG)sizeof(CcrtChunk),(BYTE *)ccrt)
  183.  
  184. #ifdef FDwAT
  185.  
  186. /* Initialize a BitMapHeader record for a full-BitMap ILBM picture.
  187.  * This gets w, h, and nPlanes from the BitMap fields BytesPerRow, Rows, and
  188.  * Depth. It assumes you want  w = bitmap->BytesPerRow * 8 .
  189.  * CLIENT_ERROR if bitmap->BytesPerRow isn't even, as required by ILBM format.
  190.  *
  191.  * If (pageWidth, pageHeight) is (320, 200), (320, 400), (640, 200), or
  192.  * (640, 400) this sets (xAspect, yAspect) based on those 4 Amiga display
  193.  * modes. Otherwise, it sets them to (1, 1).
  194.  * 
  195.  * After calling this, store directly into the BitMapHeader if you want to
  196.  * override any settings, e.g. to make nPlanes smaller, to reduce w a little,
  197.  * or to set a position (x, y) other than (0, 0).*/
  198. extern IFFP InitBMHdr(BitMapHeader *, struct BitMap *,
  199.         /*  bmHdr,          bitmap  */
  200.      LONG,    LONG,        LONG,             WORD,      WORD); /* dp */
  201.  /*  masking, compression, transparentColor, pageWidth, pageHeight */
  202.  /*  Masking, Compression, UWORD -- are the desired types, but get
  203.   *  compiler warnings if use them.               */
  204.  
  205. /* Output a CMAP chunk to an open FORM ILBM write context. */
  206. extern IFFP PutCMAP(GroupContext *, WORD *,   UBYTE);
  207.       /*  context,        colorMap, depth  */
  208.  
  209. /* This procedure outputs a BitMap as an ILBM's BODY chunk with
  210.  * bitplane and mask data. Compressed if bmHdr->compression == cmpByteRun1.
  211.  * If the "mask" argument isn't NULL, it merges in the mask plane, too.
  212.  * (A fancier routine could write a rectangular portion of an image.)
  213.  * This gets Planes (bitplane ptrs) from "bitmap".
  214.  *
  215.  * CLIENT_ERROR if bitmap->Rows != bmHdr->h, or if
  216.  * bitmap->BytesPerRow != RowBytes(bmHdr->w), or if
  217.  * bitmap->Depth < bmHdr->nPlanes, or if bmHdr->nPlanes > MaxAmDepth, or if
  218.  * bufsize < MaxPackedSize(bitmap->BytesPerRow), or if
  219.  * bmHdr->compression > cmpByteRun1. */
  220. extern IFFP PutBODY(
  221.     GroupContext *, struct BitMap *, BYTE *, BitMapHeader *, BYTE *, LONG);
  222.     /*  context,           bitmap,   mask,   bmHdr,         buffer, bufsize */
  223.  
  224. #else /*not FDwAT*/
  225.  
  226. extern IFFP InitBMHdr();
  227. extern IFFP PutCMAP();
  228. extern IFFP PutBODY();
  229.  
  230. #endif FDwAT
  231.  
  232. /* ---------- ILBM Reader Support Routines -----------------------------*/
  233.  
  234. /* Note: Just call IFFReadBytes to read a BMHD, GRAB, DEST, SPRT, or CAMG
  235.  * chunk. As below. */ /* dp */ /* cs */
  236. #define GetBMHD(context, bmHdr)  \
  237.     IFFReadBytes(context, (BYTE *)bmHdr, (LONG)sizeof(BitMapHeader))
  238. #define GetGRAB(context, point2D)  \
  239.     IFFReadBytes(context, (BYTE *)point2D, (LONG)sizeof(Point2D))
  240. #define GetDEST(context, destMerge)  \
  241.     IFFReadBytes(context, (BYTE *)destMerge, (LONG)sizeof(DestMerge))
  242. #define GetSPRT(context, spritePrec)  \
  243.     IFFReadBytes(context, (BYTE *)spritePrec, (LONG)sizeof(SpritePrecedence))
  244. #define GetCAMG(context, camg)  \
  245.     IFFReadBytes(context, (BYTE *)camg, (LONG)sizeof(CamgChunk))
  246. #define GetCRNG(context, crng)  \
  247.     IFFReadBytes(context, (BYTE *)crng, (LONG)sizeof(CrngChunk))
  248. #define GetCCRT(context, ccrt)  \
  249.     IFFReadBytes(context, (BYTE *)ccrt, (LONG)sizeof(CcrtChunk))
  250.  
  251.  
  252. /* GetBODY can handle a file with up to 16 planes plus a mask.*/
  253. #define MaxSrcPlanes (LONG)(16+1) /* dp */
  254.  
  255. #ifdef FDwAT
  256.  
  257. /* Input a CMAP chunk from an open FORM ILBM read context.
  258.  * This converts to an Amiga color map: 4 bits each of red, green, blue packed
  259.  * into a 16 bit color register.
  260.  * pNColorRegs is passed in as a pointer to a UBYTE variable that holds
  261.  * the number of ColorRegisters the caller has space to hold. GetCMAP sets
  262.  * that variable to the number of color registers actually read.*/
  263. extern IFFP GetCMAP(GroupContext *, WORD *,   UBYTE *);
  264.                 /*  context,        colorMap, pNColorRegs  */
  265.  
  266. /* Input a BEAM chunk from an open FORM ILBM read context.
  267.  * This converts to an Amiga color map: 4 bits each of red, green, blue
  268.  * packed into a 16 bit color register.
  269.  * pNColorRegs is passed in as a pointer to a UBYTE variable that holds
  270.  * the number of ColorRegisters the caller has space to hold. GetBEAM sets
  271.  * that variable to the number of color registers actually read.*/
  272. extern IFFP GetBEAM(GroupContext *, UWORD *, UWORD);
  273.                 /*  context,        beamMap, nRows */
  274.  
  275. /* GetBODY reads an ILBM's BODY into a client's bitmap, de-interleaving and
  276.  * decompressing.
  277.  *
  278.  * Caller should first compare bmHdr dimensions (rowWords, h, nPlanes) with
  279.  * bitmap dimensions, and consider reallocating the bitmap.
  280.  * If file has more bitplanes than bitmap, this reads first few planes (low
  281.  * order ones). If bitmap has more bitplanes, the last few are untouched.
  282.  * This reads the MIN(bmHdr->h, bitmap->Rows) rows, discarding the bottom
  283.  * part of the source or leaving the bottom part of the bitmap untouched.
  284.  *
  285.  * GetBODY returns CLIENT_ERROR if asked to perform a conversion it doesn't
  286.  * handle. It only understands compression algorithms cmpNone and cmpByteRun1.
  287.  * The filed row width (# words) must agree with bitmap->BytesPerRow.
  288.  *
  289.  * Caller should use bmHdr.w; GetBODY only uses it to compute the row width
  290.  * in words. Pixels to the right of bmHdr.w are not defined.
  291.  *
  292.  * [TBD] In the future, GetBODY could clip the stored image horizontally or
  293.  * fill (with transparentColor) untouched parts of the destination bitmap.
  294.  *
  295.  * GetBODY stores the mask plane, if any, in the buffer pointed to by mask.
  296.  * If mask == NULL, GetBODY will skip any mask plane. If
  297.  * (bmHdr.masking != mskHasMask) GetBODY just leaves the caller's mask alone.
  298.  *
  299.  * GetBODY needs a buffer large enough for two compressed rows.
  300.  * It returns CLIENT_ERROR if bufsize < 2 * MaxPackedSize(bmHdr.rowWords * 2).
  301.  *
  302.  * GetBODY can handle a file with up to MaxSrcPlanes planes. It returns
  303.  * CLIENT_ERROR if the file has more. (Could be due to a bum file, though.)
  304.  * If GetBODY fails, itt might've modified the client's bitmap. Sorry.*/
  305. extern IFFP GetBODY(
  306.     GroupContext *, struct BitMap *, BYTE *, BitMapHeader *, BYTE *, LONG);
  307.     /*  context,           bitmap,   mask,   bmHdr,         buffer, bufsize */
  308.  
  309. /* [TBD] Add routine(s) to create masks when reading ILBMs whose
  310.  * masking != mskHasMask. For mskNone, create a rectangular mask. For
  311.  * mskHasTransparentColor, create a mask from transparentColor. For mskLasso,
  312.  * create an "auto mask" by filling transparent color from the edges. */
  313.  
  314. #else /*not FDwAT*/
  315.  
  316. extern IFFP GetCMAP();
  317. extern IFFP GetBEAM(); /* dp */
  318. extern IFFP GetBODY();
  319.  
  320. #endif FDwAT
  321.  
  322. #endif ILBM_H
  323.  
  324.