/**********************************************************************
*
*   libraries/dctv.h
*
*   Copyright (C) 1991, 1992 Digital Creations, Inc.
*
*   v3.0 - 22 May 1992
*
**********************************************************************/

#ifndef LIBRARIES_DCTV_H
#define LIBRARIES_DCTV_H

#ifndef GRAPHICS_GFX_H
  #include <graphics/gfx.h>
#endif

#ifndef UTILIITY_TAGITEM_H
  #include <utility/tagitem.h>
#endif


/* -------------------- Library version */

#define DCTVLIB_Minimum 1           /* Minimum supported library version #. */


/* -------------------- DCTVCvtHandle structure */

/*
    This is the conversion environment structure returned by
    AllocDCTVCvtTagList() and used by all dctv.library conversion
    functions.

    All fields, unless otherwise noted, are READ-ONLY.
*/

struct DCTVCvtHandle {
    UBYTE *Red, *Green, *Blue;      /* 24-bit RGB 70ns chunky line buffer.

                                       DCTVCVTT_RGBtoDCTV:
                                           Buffer contents are input to
                                           CvtDCTVLine().  CvtDCTVLine()
                                           preserves the contents of this
                                           buffer.

                                       DCTVCVTT_DCTVtoRGB:
                                           Buffer contents are output from
                                           CvtDCTVLine().

                                       Data maps pixel for pixel with
                                       the output BitMap (i.e. Red[0]
                                       maps to the leftmost pixel in the
                                       the BitMap; Red[Width-1] maps to
                                       the rightmost pixel in the
                                       BitMap).

                                       This buffer is automatically
                                       allocated by AllocDCTVCvtTagList()
                                       when DCTVCVTF_CustomRGBBuf isn't
                                       specified.  In this case these
                                       pointers are read-only (the buffer
                                       may still be written to, though).

                                       When DCTVCVTF_CustomRGBBuf is
                                       specified, these pointers start
                                       out being NULL.  The Client must set these
                                       pointers to a custom RGB line buffer
                                       set before calling CvtDCTVLine().
                                       Also, in this case, these pointers may
                                       be changed between calls to CvtDCTVLine().
                                    */

    struct BitMap *BitMap;          /* Pointer to client-supplied BitMap.
                                       DCTVCVTT_RGBtoDCTV:
                                           Output of conversion.
                                       DCTVCVTT_DCTVtoRGB:
                                           Input to conversion.  Contents
                                           are preserved.

                                       The BitMap structure itself is read-only
                                       (i.e. don't change dimensions or Planes[] pointers).
                                   */

    WORD Width;                     /* Width of RGB line buffers (derived from DCTVCVTA_Width). */
    WORD Height;                    /* Conversion Height (derived from DCTVCVTA_Height). */

    struct Rectangle ImageBounds;   /* Visible image area within BitMap.
                                       Pixels outside this rectangle are
                                       used for DCTV control
                                       information.  RGB data supplied
                                       outside this rectangle are be
                                       ignored by CvtDCTVLine(). */

    UWORD *ColorTable;              /* RGB4 color table for DCTV display.
                                       The data in this array is also
                                       read-only.

                                       DCTVCVTT_RGBtoDCTV:
                                           Allocated and supplied by
                                           dctv.library.
                                       DCTVCVTT_DCTVtoRGB:
                                           Supplied by client in
                                           DCTVCVTA_ColorTable.
                                           The contents can be changed
                                           with SetDCTVColorTable(). */

    UBYTE NColors;                  /* # of colors in ColorTable. */

    BYTE NDelayLines;               /* # of lines delay between input
                                       and output data.  Actual value
                                       depends on conversion type and
                                       options.  May change from one
                                       release of the library to another. */

        /* Line numbers incremented by calls to CvtDCTVLine(). */
    WORD SrcLineNum;                /* # of source lines converted.
                                       (0 <= SrcLineNum <= Height+NDelayLines) */
    WORD DstLineNum;                /* # of destination lines output.
                                       (-NDelayLines <= DstLineNum <= Height) */

        /* padding */
    ULONG pad[4];

    /* private stuff allocated below here */
};


/* -------------------- AllocDCTVCvtTagList() tags */

    /* V3 tags */
#define DCTVCVTA_base       (TAG_USER+1)

#define DCTVCVTA_Type       (DCTVCVTA_base+0)   /* (UWORD) - DCTVCVTT_ types defined below.
                                                   Default is DCTVCVTT_RGBtoDCTV. */

#define DCTVCVTA_Width      (DCTVCVTA_base+1)   /* (WORD) - Pixel width of conversion.
                                                   Truncated to a multiple of 16.
                                                   Default is derived from the BitMap. */

#define DCTVCVTA_Height     (DCTVCVTA_base+2)   /* (WORD) - Height of conversion.
                                                   Default is derived from the BitMap. */

#define DCTVCVTA_Flags      (DCTVCVTA_base+3)   /* (UWORD) - DCTVCVTF_ flags defined below.
                                                   Default is 0. */

#define DCTVCVTA_ColorTable (DCTVCVTA_base+4)   /* (UWORD *) - Initial ColorTable for DCTVCVTT_DCTVtoRGB.
                                                   RGB4 color array containing 1<<bitmap->Depth entries.
                                                   Required for DCTVCVTT_DCTVtoRGB; ignored for
                                                   DCTVCVTT_RGBtoDCTV.  Subsequent palette changes
                                                   must be registered with SetDCTVColorTable().
                                                   Array must remain valid until it is replaced with
                                                   SetDCTVColorTAble() or the conversion environment is freed. */

#define DCTVCVTA_ErrorCode  (DCTVCVTA_base+5)   /* (ULONG *) - Pointer to a ULONG where an
                                                   extended error code is placed if AllocDCTVCvtTagList()
                                                   fails.  Results are DCTVCVTERR_ defined below.
                                                   Error code buffer isn't changed if there is no error. */


/* -------------------- DCTVCVTA_Type types */

enum {
    DCTVCVTT_RGBtoDCTV,                 /* RGB to DCTV conversion */
    DCTVCVTT_DCTVtoRGB                  /* DCTV to RGB conversion */
};


/* -------------------- AllocDCTVCvt() / DCTVCVTA_Flags flags */

#define DCTVCVTF_Lace           0x01    /* Interlaced DCTV display image. */
#define DCTVCVTF_Filter         0x02    /* Apply RGB filtering for DCTVCVTT_RGBtoDCTV.
                                           Ignored for DCTVCVTT_DCTVtoRGB. */
#define DCTVCVTF_1LineBM        0x04    /* Use BitMap as a single-line buffer. */

    /* V3 flags */
#define DCTVCVTF_CustomRGBBuf   0x08    /* Don't allocate RGB line buffer, client will be supplying his own. */


/* -------------------- DCTVCVTERR_ error codes */

enum {
    DCTVCVTERR_NoMem = 1,               /* Not enough memory. */
    DCTVCVTERR_BadBitMap,               /* Supplied BitMap is invalid:  invalid depth or dimensions. */
    DCTVCVTERR_UnknownType,             /* Unknown conversion type. */
    DCTVCVTERR_BadParams                /* Invalid parameters for conversion type. */
};


#endif
