/***********************************************************************/
/*                  Scanner Driver ToolKit                             */
/*                   C Driver Program Header                           */
/***********************************************************************/

#define GLOBAL                          /* for all functions use  */
#define LOCAL           static          /* for local file use */
#define PRIVATE         static          /* for local function use */
#define IMPORT          extern          /* from other file import */

typedef short   BOOL;           /* 2-byte Boolean (TRUE/FALSE, YES/NO) */
typedef unsigned char   BYTE;
typedef unsigned short  WORD;
typedef unsigned long  DWORD;
typedef BYTE far *LPBYTE;

typedef char *PSTR;
typedef char near *NPSTR;
typedef char far  *LPSTR;

typedef struct
{
    WORD    wLinesOfBuffer;         /* Number of lines in buffer */
    LPSTR   lpBuf;                  /* pointer to Buffer */
} BUFLIST;
typedef BUFLIST far *LPBUFLIST;

typedef struct
{
    LPBUFLIST  lpbuflistScan;   /*  Buffer list */
    WORD wLineWidth;            /*  Line Width in bytes */
    WORD wBufNumber;            /*  Numbers of buffers in list */
    WORD wOptions;              /*  Scan options */
    WORD far *lpDisplayBuf;     /* current AP display buffer address */
    WORD far *lpDisplayLine;    /* current AP display line address */
} SS;                           /*  Start Scan Parameter Packet */
typedef SS far  *LPSS;

/* note: Each buffer is under 64 KB limit, the numbers of buffers are
         not limited by the scanner driver. */
/* Scan Options masks */
#define WRAPAROUND 0x0001      /* Tell the scanner driver to fill the buffers
                                    in a circular way */
#define AP_ANSWER  0x8000      /* Tell the scanner driver the answer buffer
                                    is prepared by Application S/W */
typedef struct
{
    WORD wCurrentBuf;       /* current buffer in Buffer List */
    WORD wCurrentLine;      /* current line in current buffer */
    WORD wScanStatus;       /* Scanner status */
    WORD wLineCount;        /* Scan Line Count */
}  SP;                      /* Scan Position Structure */
typedef SP far  *LPSP;

/* notes:
   - wCurrentBuf is the number of the buffer that the next scan line will be
     read into, with 0 being the first buffer.
   - wCurrentLine is the number of the last scan line read (in the current
     buffer), with 0 being the top line of the image. wCurrentLine is equal
     to -1 as long as the scan process did not start.
*/
/* Scan Status masks */
#define SS_ACTIVE   0x0001      /* scan process is active */
#define SS_TIMEOUT      0x0008  /* scan stopped due to time-out */
#define SS_ABORT        0x0010  /* scan stopped due to user abort */
#define SS_BUFFER_FULL  0x0020  /* scan stopped due to buffer full */
#define SS_PARAMETER    0x0040  /* scan stopped due to send parameter */

typedef struct
{
    short   nMode;              /* Scanner Current Scan mode */
                      /* Resolution in Dots per cm, Range from 40 to 160 */
    WORD    wHorizontalRes;     /* Scanner Current Horizontal Resolution */
    WORD    wVerticalRes;       /* Scanner Current Vertical Resolution */
    short   nBitsPerPixel;      /* Scanner Current Bits per Pixel */
    WORD    wMaxScanWidth;      /* Scanner Current Mode Maximum Scan Width
                                                in Bytes    */
    short   nIRQ;               /* Current Hardware IRQ number */
}   GETPB;
typedef GETPB far  *LPGETPB;

/* Scanner Mode Definition */
/* Gray Scanner */
#define GRAY_MODE   0x01
#define MONO_MODE   0x00
/* Color Scanner */
#define COLOR_DITHER_MODE   0x00
#define COLOR_GRAY_MODE     0x20
#define COLOR_MONO_MODE     0x10

typedef struct
{
    short   nMode;              /* Scanner Scan mode */
                      /* Resolution in Dots per cm, Range from 40 to 160 */
    WORD    wHorizontalRes;     /* Scanner Horizontal Resolution */
    WORD    wVerticalRes;       /* Scanner Vertical Resolution */
                       /* The following 4 settings are only valid for color */
                       /* scanner operated at color dithered mode or        */  
                       /* monochrome mode.                                  */            
    short   nGammaCorrection;    /* Scanner gamma correction */
    short   nBrightness;        /* Scanner Brightness Default 0x7f */
                                /* Brightness Range from 0 to 0xff */
    short   nContrast;          /* Scanner Contrast Default 0x80 */
                                /* Contrast Range from 0 to 0xff */
    short   nHue;               /* Scanner Hue Default 0x80 */
                                /* Hue Range from 0 to 0xff */
}   SETPB;
typedef SETPB far  *LPSETPB;

/* Scanner Gamma Correction for Color Scanner only */
#define HIGH_DENSITY_PRT    0x55
#define LOW_DENSITY_PRT     0x65
#define DOT_MATRIX_PRT      0x75
#define LETTER_AND_PHOTO    0x85
#define CRT_MONITOR         0x95
#define LINEAR              0xA5

short ScanOpen();
/* Open the scanner device for exclusive use by this application.
   You must call ScanOpen with a successful result before any further
   Scan operation.    */

short ScanClose();
/* Close the scanner device, relinquish its use by this application.
   After a ScanClose, you may not use any other Scan procedure until
   you make another successful ScanOpen call.   */

short ScanGetParameters( LPGETPB lpgetpbParameters );
/* Get All Configuration Parameters of scanner */

short ScanSetParameters( LPSETPB lpsetpbParameters );
/* Set All Configuration Parameters of scanner */

short ScanStart ( LPSS lpssScanBuf, LPSP far *lplpspScanPos);
/* Start a scan operation:

   If the scanner is configured to be used with interrupt, this call
   will return once the scan process is setup, to allow the application
   to monitor the scan process and implement a real time display.

   Else the ScanStart will only return once the scan process is over,
   after a timeout or and key press.

   In both case the scan process state can be checked with wScanStatus.
 */

short ScanStop ();
/* Stop scan operation. */

