home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d536 / chemesthetics.lha / Chemesthetics / Source / Source.LZH / ilbm.h < prev    next >
C/C++ Source or Header  |  1991-06-12  |  12KB  |  297 lines

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