home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 2 / FFMCD02.bin / new / gfx / edit / tsmorph / iffp / ilbm.h < prev    next >
C/C++ Source or Header  |  1993-12-21  |  10KB  |  276 lines

  1. /* 
  2.  *
  3.  * ilbm.h:    Definitions for IFFParse ILBM reader.
  4.  *
  5.  * 5/92
  6.  */
  7.  
  8. // Minor changes MJP
  9.  
  10. #ifndef IFFP_ILBM_H
  11. #define IFFP_ILBM_H
  12.  
  13. #ifndef IFFP_IFF_H
  14. #include "iffp/iff.h"
  15. #endif
  16.  
  17. #ifndef INTUITION_INTUITION_H
  18. #include <intuition/intuition.h>
  19. #endif
  20. #ifndef GRAPHICS_VIDEOCONTROL_H
  21. #include <graphics/videocontrol.h>
  22. #endif
  23.  
  24. #ifndef NO_PROTOS
  25. #include <clib/graphics_protos.h>
  26. #include <clib/intuition_protos.h>
  27. //#include <clib/alib_protos.h>        // MJP
  28. #endif
  29. #ifndef NO_SAS_PRAGMAS
  30. extern struct Library *IntuitionBase;
  31. #include <pragmas/intuition_pragmas.h>
  32. extern struct Library *GfxBase;
  33. #include <pragmas/graphics_pragmas.h>
  34. #endif
  35.  
  36. /*  IFF types we may encounter  */
  37. #define    ID_ILBM        MAKE_ID('I','L','B','M')
  38.  
  39. /* ILBM Chunk ID's we may encounter
  40.  * (see iffp/iff.h for some other generic chunks)
  41.  */
  42. #define    ID_BMHD        MAKE_ID('B','M','H','D')
  43. #define    ID_CMAP        MAKE_ID('C','M','A','P')
  44. #define    ID_CRNG        MAKE_ID('C','R','N','G')
  45. #define    ID_CCRT        MAKE_ID('C','C','R','T')
  46. #define    ID_GRAB        MAKE_ID('G','R','A','B')
  47. #define    ID_SPRT        MAKE_ID('S','P','R','T')
  48. #define    ID_DEST        MAKE_ID('D','E','S','T')
  49. #define    ID_CAMG        MAKE_ID('C','A','M','G')
  50.  
  51. /* Use this constant instead of sizeof(ColorRegister). */
  52. #define sizeofColorRegister  3
  53.  
  54. typedef WORD Color4;   /* Amiga RAM version of a color-register,
  55.           * with 4 bits each RGB in low 12 bits.*/
  56.  
  57. /* Maximum number of bitplanes storable in BitMap structure */
  58. #define MAXAMDEPTH 8
  59.  
  60. /* Use ViewPort->ColorMap.Count instead 
  61. #define MAXAMCOLORREG 32
  62. */
  63.  
  64. /* Maximum planes we can save */
  65. #define MAXSAVEDEPTH 24
  66.  
  67. /* Convert image width to even number of BytesPerRow for ILBM save.
  68.  * Do NOT use this macro to determine the actual number of bytes per row
  69.  * in an Amiga BitMap scan line.  For that, use BitMap->BytesPerRow.
  70.  */
  71. #define    BytesPerRow(w)    ((w) + 15 >> 4 << 1)
  72. #define BitsPerRow(w)    ((w) + 15 >> 4 << 4)
  73.  
  74. /* Flags that should be masked out of old 16-bit CAMG before save or use.
  75.  * Note that 32-bit mode id (non-zero high word) bits should not be twiddled
  76.  */
  77. #define BADFLAGS  (SPRITES|VP_HIDE|GENLOCK_AUDIO|GENLOCK_VIDEO)
  78. #define OLDCAMGMASK  (~BADFLAGS)
  79.  
  80.  
  81. /*  Masking techniques  */
  82. #define    mskNone            0
  83. #define    mskHasMask        1
  84. #define    mskHasTransparentColor    2
  85. #define    mskLasso        3
  86.  
  87. /*  Compression techniques  */
  88. #define    cmpNone            0
  89. #define    cmpByteRun1        1
  90.  
  91. #define RowBytes(w)    ((((w) + 15) >> 4) << 1)
  92.  
  93. /* ---------- BitMapHeader ---------------------------------------------*/
  94. /*  Required Bitmap header (BMHD) structure describes an ILBM */
  95. typedef struct {
  96.     UWORD    w, h;        /* Width, height in pixels */
  97.     WORD    x, y;        /* x, y position for this bitmap  */
  98.     UBYTE    nPlanes;    /* # of planes (not including mask) */
  99.     UBYTE    masking;    /* a masking technique listed above */
  100.     UBYTE    compression;    /* cmpNone or cmpByteRun1 */
  101.     UBYTE    reserved1;    /* must be zero for now */
  102.     UWORD    transparentColor;
  103.     UBYTE    xAspect, yAspect;
  104.     WORD    pageWidth, pageHeight;
  105. } BitMapHeader;
  106.  
  107. /* ---------- ColorRegister --------------------------------------------*/
  108. /* A CMAP chunk is a packed array of ColorRegisters (3 bytes each). */
  109. typedef struct {
  110.     UBYTE red, green, blue;   /* MUST be UBYTEs so ">> 4" won't sign extend.*/
  111.     } ColorRegister;
  112.  
  113. /* ---------- Point2D --------------------------------------------------*/
  114. /* A Point2D is stored in a GRAB chunk. */
  115. typedef struct {
  116.     WORD x, y;      /* coordinates (pixels) */
  117.     } Point2D;
  118.  
  119. /* ---------- DestMerge ------------------------------------------------*/
  120. /* A DestMerge is stored in a DEST chunk. */
  121. typedef struct {
  122.     UBYTE depth;   /* # bitplanes in the original source */
  123.     UBYTE pad1;      /* UNUSED; for consistency store 0 here */
  124.     UWORD planePick;   /* how to scatter source bitplanes into destination */
  125.     UWORD planeOnOff;   /* default bitplane data for planePick */
  126.     UWORD planeMask;   /* selects which bitplanes to store into */
  127.     } DestMerge;
  128.  
  129. /* ---------- SpritePrecedence -----------------------------------------*/
  130. /* A SpritePrecedence is stored in a SPRT chunk. */
  131. typedef UWORD SpritePrecedence;
  132.  
  133. /* ---------- Camg Amiga Viewport Mode Display ID ----------------------*/
  134. /* The CAMG chunk is used to store the Amiga display mode in which
  135.  * an ILBM is meant to be displayed.  This is very important, especially
  136.  * for special display modes such as HAM and HALFBRITE where the
  137.  * pixels are interpreted differently.
  138.  * Under V37 and higher, store a 32-bit Amiga DisplayID (aka. ModeID)
  139.  * in the ULONG ViewModes CAMG variable (from GetVPModeID(viewport)).
  140.  * Pre-V37, instead store the 16-bit viewport->Modes.
  141.  * See the current IFF manual for information on screening for bad CAMG
  142.  * chunks when interpreting a CAMG as a 32-bit DisplayID or 16-bit ViewMode.
  143.  * The chunk's content is declared as a ULONG.
  144.  */
  145. typedef struct {
  146.    ULONG ViewModes;
  147.    } CamgChunk;
  148.  
  149. /* ---------- CRange cycling chunk -------------------------------------*/
  150. #define RNG_NORATE  36   /* Dpaint uses this rate to mean non-active */
  151. /* A CRange is store in a CRNG chunk. */
  152. typedef struct {
  153.     WORD  pad1;              /* reserved for future use; store 0 here */
  154.     WORD  rate;      /* 60/sec=16384, 30/sec=8192, 1/sec=16384/60=273 */
  155.     WORD  active;     /* bit0 set = active, bit 1 set = reverse */
  156.     UBYTE low, high;   /* lower and upper color registers selected */
  157.     } CRange;
  158.  
  159. /* ---------- Ccrt (Graphicraft) cycling chunk -------------------------*/
  160. /* A Ccrt is stored in a CCRT chunk. */
  161. typedef struct {
  162.    WORD  direction;  /* 0=don't cycle, 1=forward, -1=backwards */
  163.    UBYTE start;      /* range lower */
  164.    UBYTE end;        /* range upper */
  165.    LONG  seconds;    /* seconds between cycling */
  166.    LONG  microseconds; /* msecs between cycling */
  167.    WORD  pad;        /* future exp - store 0 here */
  168.    } CcrtChunk;
  169.  
  170. /* If you are writing all of your chunks by hand,
  171.  * you can use these macros for these simple chunks.
  172.  */
  173. #define putbmhd(iff, bmHdr)  \
  174.     PutCk(iff, ID_BMHD, sizeof(BitMapHeader), (BYTE *)bmHdr)
  175. #define putgrab(iff, point2D)  \
  176.     PutCk(iff, ID_GRAB, sizeof(Point2D), (BYTE *)point2D)
  177. #define putdest(iff, destMerge)  \
  178.     PutCk(iff, ID_DEST, sizeof(DestMerge), (BYTE *)destMerge)
  179. #define putsprt(iff, spritePrec)  \
  180.     PutCk(iff, ID_SPRT, sizeof(SpritePrecedence), (BYTE *)spritePrec)
  181. #define putcamg(iff, camg)  \
  182.     PutCk(iff, ID_CAMG, sizeof(CamgChunk),(BYTE *)camg)
  183. #define putcrng(iff, crng)  \
  184.     PutCk(iff, ID_CRNG, sizeof(CRange),(BYTE *)crng)
  185. #define putccrt(iff, ccrt)  \
  186.     PutCk(iff, ID_CCRT, sizeof(CcrtChunk),(BYTE *)ccrt)
  187.  
  188. #ifndef NO_PROTOS
  189. /* unpacker.c */
  190. BOOL unpackrow(BYTE **pSource, BYTE **pDest, WORD srcBytes0, WORD dstBytes0);
  191.  
  192. /* packer.c */
  193. LONG packrow(BYTE **pSource, BYTE **pDest, LONG rowSize);
  194.  
  195. /* ilbmr.c  ILBM reader routines */
  196. LONG loadbody(struct IFFHandle *iff, struct BitMap *bitmap,
  197.         BitMapHeader *bmhd);
  198. LONG loadbody2(struct IFFHandle *iff, struct BitMap *bitmap, 
  199.         BYTE *mask, BitMapHeader *bmhd, 
  200.         BYTE *buffer, ULONG bufsize);
  201. LONG loadcmap(struct IFFHandle *, WORD *colortable, USHORT *pNcolors,struct ILBMInfo *ilbm);
  202. LONG getcolors(struct ILBMInfo *ilbm);
  203. void freecolors(struct ILBMInfo *ilbm);
  204. LONG alloccolortable(struct ILBMInfo *ilbm);
  205. ULONG getcamg(struct ILBMInfo *ilbm);
  206.  
  207. /* ilbmw.c  ILBM writer routines */
  208. long initbmhd(BitMapHeader *bmhd, struct BitMap *bitmap,
  209.               WORD masking, WORD compression, WORD transparentColor,
  210.               WORD width, WORD height, WORD pageWidth, WORD pageHeight,
  211.               ULONG modeid);
  212. long putcmap(struct IFFHandle *iff,APTR colortable,UWORD ncolors,UWORD bitspergun);
  213. long putbody(struct IFFHandle *iff, struct BitMap *bitmap,
  214.         BYTE *mask, BitMapHeader *bmHdr,
  215.         BYTE *buffer, LONG bufsize);
  216.  
  217. /* getdisplay.c (used to load a display) */
  218. LONG showilbm(struct ILBMInfo *ilbm, UBYTE *filename);
  219. BOOL unshowilbm(struct ILBMInfo *ilbm);
  220. LONG createdisplay(struct ILBMInfo *);
  221. BOOL deletedisplay(struct ILBMInfo *);
  222. LONG getdisplay(struct ILBMInfo *);
  223. BOOL freedisplay(struct ILBMInfo *);
  224.  
  225. /* getbitmap.c (used if just loading brush or bitmap) */
  226. LONG createbrush(struct ILBMInfo *);
  227. void deletebrush(struct ILBMInfo *);
  228. LONG getbitmap(struct ILBMInfo *);
  229. void freebitmap(struct ILBMInfo *);
  230.  
  231. /* screen.c (opens 1.3 or 2.0 screen)