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