home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 004.lha / Dpaintx_source / ILBM.h < prev    next >
C/C++ Source or Header  |  1986-03-02  |  10KB  |  236 lines

  1. #ifndef ILBM_H
  2. #define ILBM_H
  3. /*----------------------------------------------------------------------*
  4.  * ILBM.H  Definitions for InterLeaved BitMap raster image.    11/11/85
  5.  *
  6.  * By Jerry Morrison and Steve Shaw, Electronic Arts.
  7.  * This software is in the public domain.
  8.  *
  9.  * This version for the Commodore-Amiga computer.
  10.  *
  11.  *  ( expects iff.h in include/iff/  )
  12.  *----------------------------------------------------------------------*/
  13. #ifndef EXEC_TYPES_H
  14. #include "exec/types.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_BODY MakeID('B','O','D','Y')
  31.  
  32. /* ---------- BitMapHeader ---------------------------------------------*/
  33.  
  34. typedef UBYTE Masking;      /* Choice of masking technique.*/
  35. #define mskNone                 0
  36. #define mskHasMask              1
  37. #define mskHasTransparentColor  2
  38. #define mskLasso                3
  39.  
  40. typedef UBYTE Compression;   /* Choice of compression algorithm applied to
  41.      * each row of the source and mask planes. "cmpByteRun1" is the byte run
  42.      * encoding generated by Mac's PackBits. See Packer.h . */
  43. #define cmpNone      0
  44. #define cmpByteRun1  1
  45.  
  46. /* Aspect ratios: The proper fraction xAspect/yAspect represents the pixel
  47.  * aspect ratio pixel_width/pixel_height.
  48.  *
  49.  * For the 4 Amiga display modes:
  50.  *   320 x 200: 10/11  (these pixels are taller than they are wide)
  51.  *   320 x 400: 20/11
  52.  *   640 x 200:  5/11
  53.  *   640 x 400: 10/11      */
  54. #define x320x200Aspect 10
  55. #define y320x200Aspect 11
  56. #define x320x400Aspect 20
  57. #define y320x400Aspect 11
  58. #define x640x200Aspect  5
  59. #define y640x200Aspect 11
  60. #define x640x400Aspect 10
  61. #define y640x400Aspect 11
  62.  
  63. /* A BitMapHeader is stored in a BMHD chunk. */
  64. typedef struct {
  65.     UWORD w, h;         /* raster width & height in pixels */
  66.     WORD  x, y;         /* position for this image */
  67.     UBYTE nPlanes;      /* # source bitplanes */
  68.     Masking masking;      /* masking technique */
  69.     Compression compression;   /* compression algoithm */
  70.     UBYTE pad1;         /* UNUSED.  For consistency, put 0 here.*/
  71.     UWORD transparentColor;   /* transparent "color number" */
  72.     UBYTE xAspect, yAspect;   /* aspect ratio, a rational number x/y */
  73.     WORD  pageWidth, pageHeight;  /* source "page" size in pixels */
  74.     } BitMapHeader;
  75.  
  76. /* RowBytes computes the number of bytes in a row, from the width in pixels.*/
  77. #define RowBytes(w)   (((w) + 15) >> 4 << 1)
  78.  
  79.  
  80. /* ---------- ColorRegister --------------------------------------------*/
  81. /* A CMAP chunk is a packed array of ColorRegisters (3 bytes each). */
  82. typedef struct {
  83.     UBYTE red, green, blue;   /* MUST be UBYTEs so ">> 4" won't sign extend.*/
  84.     } ColorRegister;
  85.  
  86. /* Use this constant instead of sizeof(ColorRegister). */
  87. #define sizeofColorRegister  3
  88.  
  89. typedef WORD Color4;   /* Amiga RAM version of a color-register,
  90.           * with 4 bits each RGB in low 12 bits.*/
  91.  
  92. /* Maximum number of bitplanes in RAM. Current Amiga max w/dual playfield. */
  93. #define MaxAmDepth 6
  94.  
  95. /* ---------- Point2D --------------------------------------------------*/
  96. /* A Point2D is stored in a GRAB chunk. */
  97. typedef struct {
  98.     WORD x, y;      /* coordinates (pixels) */
  99.     } Point2D;
  100.  
  101. /* ---------- DestMerge ------------------------------------------------*/
  102. /* A DestMerge is stored in a DEST chunk. */
  103. typedef struct {
  104.     UBYTE depth;   /* # bitplanes in the original source */
  105.     UBYTE pad1;      /* UNUSED; for consistency store 0 here */
  106.     UWORD planePick;   /* how to scatter source bitplanes into destination */
  107.     UWORD planeOnOff;   /* default bitplane data for planePick */
  108.     UWORD planeMask;   /* selects which bitplanes to store into */
  109.     } DestMerge;
  110.  
  111. /* ---------- SpritePrecedence -----------------------------------------*/
  112. /* A SpritePrecedence is stored in a SPRT chunk. */
  113. typedef UWORD SpritePrecedence;
  114.  
  115. /* ---------- Viewport Mode --------------------------------------------*/
  116. /* A Commodore Amiga Viewport Mode is stored in a CAMG chunk. */
  117. #if 0
  118. typedef UWORD ViewportMode;   /* [TBD] Is this right? */
  119. #endif
  120.  
  121. /* ---------- ILBM Writer Support Routines -----------------------------*/
  122.  
  123. /* Note: Just call PutCk to write a BMHD, GRAB, DEST, SPRT, or CAMG
  124.  * chunk. As below. */
  125. #define PutBMHD(context, bmHdr)  \
  126.     PutCk(context, ID_BMHD, sizeof(BitMapHeader), (BYTE *)bmHdr)
  127. #define PutGRAB(context, point2D)  \
  128.     PutCk(context, ID_GRAB, sizeof(Point2D), (BYTE *)point2D)
  129. #define PutDEST(context, destMerge)  \
  130.     PutCk(context, ID_DEST, sizeof(DestMerge), (BYTE *)destMerge)
  131. #define PutSPRT(context, spritePrec)  \
  132.     PutCk(context, ID_SPRT, sizeof(SpritePrecedence), (BYTE *)spritePrec)
  133.  
  134. /* Initialize a BitMapHeader record for a full-BitMap ILBM picture.
  135.  * This gets w, h, and nPlanes from the BitMap fields BytesPerRow, Rows, and
  136.  * Depth. It assumes you want  w = bitmap->BytesPerRow * 8 .
  137.  * CLIENT_ERROR if bitmap->BytesPerRow isn't even, as required by ILBM format.
  138.  *
  139.  * If (pageWidth, pageHeight) is (320, 200), (320, 400), (640, 200), or
  140.  * (640, 400) this sets (xAspect, yAspect) based on those 4 Amiga display
  141.  * modes. Otherwise, it sets them to (1, 1).
  142.  * 
  143.  * After calling this, store directly into the BitMapHeader if you want to
  144.  * override any settings, e.g. to make nPlanes smaller, to reduce w a little,
  145.  * or to set a position (x, y) other than (0, 0).*/
  146. extern IFFP InitBMHdr(/* BitMapHeader *, struct BitMap *, */
  147.             /* bmHdr,          bitmap  */
  148.      /* int,     int,         int,              int,       int */);
  149.      /* masking, compression, transparentColor, pageWidth, pageHeight  */
  150.      /* Masking, Compression, UWORD,            WORD,      WORD  */
  151.  
  152. /* Output a CMAP chunk to an open FORM ILBM write context. */
  153. extern IFFP PutCMAP(/* GroupContext *, WORD *,   UBYTE */);
  154.           /* context,        colorMap, depth  */
  155.  
  156. /* This procedure outputs a BitMap as an ILBM's BODY chunk with
  157.  * bitplane and mask data. Compressed if bmHdr->compression == cmpByteRun1.
  158.  * If the "mask" argument isn't NULL, it merges in the mask plane, too.
  159.  * (A fancier routine could write a rectangular portion of an image.)
  160.  * This gets Planes (bitplane ptrs) from "bitmap".
  161.  *
  162.  * CLIENT_ERROR if bitmap->Rows != bmHdr->h, or if
  163.  * bitmap->BytesPerRow != RowBytes(bmHdr->w), or if
  164.  * bitmap->Depth < bmHdr->nPlanes, or if bmHdr->nPlanes > MaxAmDepth, or if
  165.  * bufsize < MaxPackedSize(bitmap->BytesPerRow), or if
  166.  * bmHdr->compression > cmpByteRun1. */
  167. extern IFFP PutBODY(/*
  168.     GroupContext *, struct BitMap *, BYTE *, BitMapHeader *, BYTE *, LONG */);
  169.     /*  context,           bitmap,   mask,   bmHdr,         buffer, bufsize */
  170.  
  171. /* ---------- ILBM Reader Support Routines -----------------------------*/
  172.  
  173. /* Note: Just call IFFReadBytes to read a BMHD, GRAB, DEST, SPRT, or CAMG
  174.  * chunk. As below. */
  175. #define GetBMHD(context, bmHdr)  IFFReadBytes(context, (BYTE *)bmHdr, sizeof(BitMapHeader))
  176. #define GetGRAB(context, point2D)  \
  177.     IFFReadBytes(context, (BYTE *)point2D, sizeof(Point2D))
  178. #define GetDEST(context, destMerge)  \
  179.     IFFReadBytes(context, (BYTE *)destMerge, sizeof(DestMerge))
  180. #define GetSPRT(context, spritePrec)  \
  181.     IFFReadBytes(context, (BYTE *)spritePrec, sizeof(SpritePrecedence))
  182.  
  183. /* Input a CMAP chunk from an open FORM ILBM read context.
  184.  * This converts to an Amiga color map: 4 bits each of red, green, blue packed
  185.  * into a 16 bit color register.
  186.  * pNColorRegs is passed in as a pointer to a UBYTE variable that holds
  187.  * the number of ColorRegisters the caller has space to hold. GetCMAP sets
  188.  * that variable to the number of color registers actually read.*/
  189. extern IFFP GetCMAP(/* GroupContext *, WORD *,   UBYTE * */);
  190.           /* context,        colorMap, pNColorRegs  */
  191.  
  192. /* GetBODY can handle a file with up to 16 planes plus a mask.*/
  193. #define MaxSrcPlanes 16+1
  194.  
  195. /* GetBODY reads an ILBM's BODY into a client's bitmap, de-interleaving and
  196.  * decompressing.
  197.  *
  198.  * Caller should first compare bmHdr dimensions (rowWords, h, nPlanes) with
  199.  * bitmap dimensions, and consider reallocating the bitmap.
  200.  * If file has more bitplanes than bitmap, this reads first few planes (low
  201.  * order ones). If bitmap has more bitplanes, the last few are untouched.
  202.  * This reads the MIN(bmHdr->h, bitmap->Rows) rows, discarding the bottom
  203.  * part of the source or leaving the bottom part of the bitmap untouched.
  204.  *
  205.  * GetBODY returns CLIENT_ERROR if asked to perform a conversion it doesn't
  206.  * handle. It only understands compression algorithms cmpNone and cmpByteRun1.
  207.  * The filed row width (# words) must agree with bitmap->BytesPerRow.
  208.  *
  209.  * Caller should use bmHdr.w; GetBODY only uses it to compute the row width
  210.  * in words. Pixels to the right of bmHdr.w are not defined.
  211.  *
  212.  * [TBD] In the future, GetBODY could clip the stored image horizontally or
  213.  * fill (with transparentColor) untouched parts of the destination bitmap.
  214.  *
  215.  * GetBODY stores the mask plane, if any, in the buffer pointed to by mask.
  216.  * If mask == NULL, GetBODY will skip any mask plane. If
  217.  * (bmHdr.masking != mskHasMask) GetBODY just leaves the caller's mask alone.
  218.  *
  219.  * GetBODY needs a buffer large enough for two compressed rows.
  220.  * It returns CLIENT_ERROR if bufsize < 2 * MaxPackedSize(bmHdr.rowWords * 2).
  221.  *
  222.  * GetBODY can handle a file with up to MaxSrcPlanes planes. It returns
  223.  * CLIENT_ERROR if the file has more. (Could be due to a bum file, though.)
  224.  * If GetBODY fails, it might've modified the client's bitmap. Sorry.*/
  225. extern IFFP GetBODY(/*
  226.     GroupContext *, struct BitMap *, BYTE *, BitMapHeader *, BYTE *, LONG */);
  227.     /*  context,           bitmap,   mask,   bmHdr,         buffer, bufsize */
  228.  
  229. /* [TBD] Add routine(s) to create masks when reading ILBMs whose
  230.  * masking != mskHasMask. For mskNone, create a rectangular mask. For
  231.  * mskHasTransparentColor, create a mask from transparentColor. For mskLasso,
  232.  * create an "auto mask" by filling transparent color from the edges. */
  233.  
  234. #endif
  235.  
  236.