/*
 * Scan 'C' Header File
 * Written by Thomas Krehbiel
 *
 * Buffers and related structures.
 *
 */

#ifndef SCAN_BUF_H


#ifndef EXEC_TYPES_H
#include <exec/types.h>
#endif

#ifndef EXEC_NODES_H
#include <exec/nodes.h>
#endif

#ifndef SCAN_DRAW_H
#include <scan/draw.h>     /* for enum Region_Tag */
#endif

/*
 * Directional masks for BuildFeatherMask():
 */
#define DIR_UP       0x01
#define DIR_DOWN     0x02
#define DIR_LEFT     0x04
#define DIR_RIGHT    0x08


/*
 * Mask - Used for defining a 1-bitplane mask plane for regions.
 */
struct Mask {
   short             OffsetX;
   short             OffsetY;
   short             Width;         /* Width of rectangle */
   short             Height;        /* Height of rectangle */
   long              Size;          /* Size of mask data in bytes */
   short             BytesPerRow;   /* Bytes per mask row */
   UBYTE            *Mask;          /* Pointer to mask data (CHIP mem) */
   enum Area_Tag     Type;          /* Type of mask */
   UWORD             Reserved[7];   /* Reserved for future expansion */
};

/*
 * Blend - used to define a blend plane (for feathered edges and such).
 *         Returned by the CreateBlend() function.
 */

struct Blend {
   short             Width, Height;    /* Dimensions in pixels */
   ULONG             Size;             /* Size of plane in bytes */
   UBYTE            *Blend;            /* Pointer to 8-bit blend data */
   ULONG             Reserved[8];      /* Reserved for future expansion */
};

/*
 * Clip - used to save a portion of the displayed (after-render)
 *        preview screen, so we can quickly restore it to the
 *        screen without having to re-render.
 */

struct Clip {
   short          LeftEdge,            /* Left Corner in screen pixels */
                  TopEdge;             /* Top Corner in screen pixels */
   short          Width,               /* Clip width in screen pixels */
                  Height;              /* Clip height in screen pixels */
   short          OffsetX,             /* Attributes of the view that */
                  OffsetY;             /*  the clip came from for */
   short          ViewX,               /*  comparison later */
                  ViewY;
   struct BitMap  BitMap_old;          /* BitMap */
   UBYTE         *Stencil;             /* Stencil plane */
   ULONG          StencilSize;         /* Size of the stencil plane */
   APTR           PreviewPtr;          /* Used only by the preview module */
   struct BitMap  SwapBM_old;          /* Swap area for brushes. */
   short          SwapLE, SwapTE,      /* Where swap came from. */
                  SwapW, SwapH;
   struct BitMap *NewBM, *NewSwapBM;
   ULONG          Reserved[6];
};

/*
 * Buffer - Defines an 8-bit or 24-bit image buffer.  Also used
 *          to define a Brush.  This structure should only be
 *          obtained via. the AllocBuffer() routine.
 */
struct Buffer {
   struct Node       Node;             /* Exec Node - unused for now */

   char              Name[130];        /* Filename of this buffer */
   char              Type[16];         /* Filetype for status display */
   char              Locked;           /* (unused) */
   unsigned char     Flags;            /* Various flag bits (see below) */
   short             Width, Height;    /* PIXEL width and height */
   char              BitsPerPlane;     /* Number of bits per pixel = 8 */
   char              Depth;            /* Number of planes (1 or 3) */
   short             BytesPerRow;      /* Number of bytes per row */
   long              PlaneSize;        /* Size of each plane */
   UBYTE            *Planes[8];        /* Pointers to the planes */

   UBYTE            *Red, *Grn, *Blu;  /* Temp line pointers */
   ULONG             TempSize;         /* Size of temp line buffers */

   /*
    * These are used for disk buffers, and should not be modified.
    */
   struct VM_Handle *DHandle;          /* VMem handle */
   short             LastGet;          /* Row/column of last GetBufLine() */
   /* Unfortunately, this is not long aligned anymore */

   /*
    * For Brushes, this defines the area of the brush.
    * For Buffers, this defines what area to affect with processes.
    */
   struct Mask      *Mask;             /* Region mask */

   /*
    * These are used mostly for Brushes.  Contains the rendered version
    * of the brush for display.  Do not touch.
    */
   struct Clip      *Clip;             /* Fast display clip */

   /*
    * These are used for mapping the buffer onto the preview display.
    * They maintain the "viewport" of the buffer.  Do not touch.
    */
   short             OffsetX,          /* Pan position */
                     OffsetY;
   short             ViewX,            /* Virtual (zoomed) screen size */
                     ViewY;

   /*
    * Some stuff for reading multiple lines from a buffer at
    * once into contiguous lines.  Do not touch.
    */
   UBYTE            *DLines[3];        /* Temp line pointers */
   UWORD             DLineOffset;      /* Start line */
   UWORD             DLineCount;       /* Number of temp lines allocated */
   ULONG             DSize;            /* Bytes in each allocated line */

   /*
    * See aspect discussion below.
    */
   short             AspectX,          /* Screen aspect ratio for this */
                     AspectY;          /*  image buffer. */

   /*
    * The "handle" for a brush.  The upper-left corner is found by
    * subtracting these numbers from the mouse position.  Thus if
    * the handle is in the upper-left, HandleX = HandleY = 0.
    */
   short             HandleX,          /* X & Y handle for brushes. */
                     HandleY;

   /*
    * Dots per inch in the horizontal and vertical directions.  Used
    * for storing in a DPI chunk and for possible printing applications.
    * These can be converted to other system (eg. metric) fairly easily.
    */
   short             DPIX,
                     DPIY;

   /*
    * The pixel aspect ratio is different from the screen aspect
    * ratio!  PIXEL aspect ratio defines how square the pixels are,
    * the SCREEN aspect ratio defines how square the screen is.
    * On a Macintosh, the pixel aspect is always 1:1 (so I'm told),
    * whereas on the Amiga the pixel aspect ratios change from
    * mode to mode (lores = 10:11, hires = 5:11, lores+lace = 20:11,
    * hires+lace = 10:11).
    */
   short             PixAspectX,       /* PIXEL aspect ratio for this */
                     PixAspectY;       /*  image buffer. */

   /*
    * Scale tables used for displaying on the preview screen.
    * Each buffer has its own scaling table attached to it.  Thus
    * we should be able to handle a brush bigger than the buffer
    * it is being displayed over.  Do not touch.
    */
   short            *Prev2BufX,        /* Preview coords to Buffer coords */
                    *Prev2BufY,
                    *Buf2PrevX,        /* Buffer coords to Preview coords */
                    *Buf2PrevY,
                    *TableX,           /* Incremental offsets to convert */
                    *TableY;           /*    from preview to buffer coords */
   long              PrevSizeX,        /* Size of preview->buffer tables */
                     PrevSizeY,
                     BufSizeX,         /* Size of buffer->preview tables */
                     BufSizeY;

   /*
    * Blend Alpha channel for use with brushes and feathering....
    */
   UBYTE            *BlendPlane;       /* 8-bit blend plane for feathering */
   UBYTE             FeatherAmt;       /* Blend plane feather amount..
                                          used to keep from re-calculating
                                          the same feather amount twice. */

   UBYTE             ExtFlags;         /* More flags */
   UWORD             pad2;

   /*
    * These are used by Loaders to store what kind of file the buffer
    * was before it was loaded.  It stores an Amiga ViewModes.
    */
   ULONG             OriginalModes;    /* ViewModes before turned into 24-bit */
   ULONG             OriginalDepth;    /* Depth of image before 24-bit */

   ULONG             UserData1,        /* Untouched by ImageFX */
                     UserData2;

   char              ANNO[96];         /* ANNO chunk */

   short             ViewLeft,         /* Preview containing box */
                     ViewTop,
                     ViewWidth,
                     ViewHeight;

   long              Reserved[4];      /* Reserved for future expansion */
};


/*
 * Flag bits:
 */
#define BUFF_DISK    0x01              /* Buffer maintained on disk */
#define BUFF_MOD     0x02              /* Buffer is modified */
#define BUFF_BRUSH   0x04              /* This buffer is a brush */
#define BUFF_UNDO    0x08              /* This is an undo buffer */

#define BUFF_NOVMEM  0x80              /* Passed to AllocBuffer disallows virtual memory */

/*
 * ExtFlag bits:
 */
#define XBUFF_EXTERNAL     0x01        /* This buffer has been IMPORT'ed */


/* these are longwords for a reason!  so we can use them directly with Ged */
struct SepInfo {
   LONG     UCR,
            GCR,
            Magenta,
            Yellow;
   LONG     Type;
   LONG     Plane;
   LONG     Depth;
   LONG     CMAP;
};

struct SepBuf {
   UBYTE   *Planes[32];
   ULONG    PlaneSize;
   UWORD    Width, Height;
   UBYTE    Depth;
   UBYTE    Bits;
   UBYTE    Plane;
   UBYTE    Flags;
   UWORD    MapSize;
   UBYTE   *ColorMap[4];
};

/* Type of separation: */
#define SEP_CMYK     (0)
#define SEP_CMY      (1)
#define SEP_RGB      (2)

/* Output colormap: */
#define SEP_GREY     (0)
#define SEP_COLOR    (1)

/* Depth: */
#define SEP_24BIT    (0)
#define SEP_12BIT    (1)

/* Flags: */
#define SEP_QUIET    (0x01)         /* No edit window */
#define SEP_1PLANE   (0x02)         /* Only output 1 plane */
#define SEP_CHUNKY   (0x04)         /* Output chunky planes instead of bitplanes */


#define SCAN_BUF_H
#endif
