1 #ifndef SCANNER_H
    2 #define SCANNER_H
    3 
    4 /*
    5 	Copyright © 2017 The MorphOS Development Team, All Rights Reserved.
    6  */
    7 
    8 
    9 
   10 #include <exec/types.h>
   11 #include <exec/io.h>
   12 
   13 
   14 
   15 
   16 // Non standard command for a scanner device driver
   17 #define SCANCMD_CONTROL    CMD_NONSTD
   18 #define SCANCMD_READOPTION CMD_NONSTD+1
   19 
   20 // Status codes
   21 #define SCAN_STATUS_OK           0
   22 #define SCAN_STATUS_EOF          1
   23 #define SCAN_STATUS_ABORTED      2
   24 
   25 // Open error codes
   26 #define SCAN_OPNERR_DEVICE       5
   27 #define SCAN_OPNERR_NOT_SCANNER  6
   28 #define SCAN_OPNERR_UNKNOWN      7
   29 #define SCAN_OPNERR_MEMORY       8
   30 #define SCAN_OPNERR_FATAL        9
   31 
   32 #define SCAN_ERR_NOTSCANNING    10
   33 #define SCAN_ERR_BUSY           11
   34 #define SCAN_ERR_MEMORY         12
   35 #define SCAN_ERR_READY          13
   36 #define SCAN_ERR_PARAMETER      14
   37 #define SCAN_ERR_HARDWARE       15
   38 #define SCAN_ERR_COMMUNICATION  16
   39 #define SCAN_ERR_MISC           17
   40 #define SCAN_ERR_NOPAPER        18
   41 
   42 
   43 
   44 // double <-> fixed point conversion
   45 #define DOUBLE_FIX(v) ((int)   ((v)*(1 << 16)))
   46 #define FIX_DOUBLE(v) (((double)(v)/(double)(1 << 16)))
   47 #define FIX_INT(v) ((v)>>16)
   48 #define INT_FIX(v) ((v)<<16)
   49 
   50 typedef enum
   51 {
   52   ID_NONE = 0,
   53   ID_SCANMODE,        // 1
   54   ID_TL_X,            // 2  /* upper left corner of scan area     */
   55   ID_TL_Y,            // 3  /* upper left corner of scan area     */
   56   ID_BR_X,            // 4  /* bottom right corner of scan area   */
   57   ID_BR_Y,            // 5  /* bottom right corner of scan area   */
   58   ID_RESOLUTION,      // 6  /* scan resolution (combined x and y) */
   59   ID_HALFTONEPATTERN, // 7
   60   ID_BRIGHTNESS,      // 8
   61   ID_CONTRAST,        // 9
   62   ID_ANALOGGAMMA,     // 10
   63   ID_BLACKLEVEL,      // 11  /* some times called shadow           */
   64   ID_WHITELEVEL,      // 12  /* some times called highlight        */
   65   ID_THRESHOLD,       // 13
   66   ID_EXPOSURETIME,    // 14
   67   ID_ADF,             // 15
   68   ID_SPEED,           // 16
   69   ID_NEGATIVE,        // 17
   70   ID_SCAN_SOURCE,     // 18
   71   ID_PREVIEW,         // 19
   72   ID_SHARPNESS,		  // 20
   73   ID_COLORCORRECTION, // 21
   74   ID_DUPLEXOFFSET,    // 22
   75   ID_PAGEWIDTH,       // 23
   76   ID_PAGEHEIGHT,      // 24
   77   ID_FIRMWARE,        // 25
   78   ID_NUMBER_OF_OPTIONS
   79 } OptionId;
   80 
   81 typedef enum
   82 {
   83   TYPE_BOOL = 0,
   84   TYPE_INT,
   85   TYPE_FIXED,    /* Fixed point number - use DOUBLE_FIX and  */
   86                  /* FIX_DOUBLE macros to convert to double   */
   87   TYPE_STRING
   88 } ValueType;
   89 
   90 typedef enum
   91 {
   92   UNIT_NONE = 0,         /* the value is unit-less (e.g., # of scans) */
   93   UNIT_PIXEL,            /* don't use!                                */
   94   UNIT_BIT,              /* value is number of bits                   */
   95   UNIT_MM,               /* value is millimeters                      */
   96   UNIT_DPI,              /* value is dots per inch                    */
   97   UNIT_PERCENT,          /* value is a percentage                     */
   98   UNIT_MICROSECOND       /* value is micro seconds                    */
   99 } ValueUnit;
  100 
  101 typedef enum
  102 {
  103   CONSTRAINT_NONE = 0,
  104   CONSTRAINT_RANGE,
  105   CONSTRAINT_WORD_LIST,
  106   CONSTRAINT_STRING_LIST
  107 } Constraint;
  108 
  109 
  110 typedef struct
  111 {
  112   int min;
  113   int max;
  114   int quant;
  115 }
  116 Range;
  117 
  118 
  119 typedef enum
  120 {
  121 	FEATURE_NONE  = 0,
  122 	FEATURE_TA    = 1,
  123 	FEATURE_ADF   = 2
  124 } Feature;
  125  
  126 #pragma pack(2)
  127 struct OptionDescriptor
  128 {
  129   OptionId   od_optionID;
  130   ValueType  od_valueType;
  131   ValueUnit  od_valueUnit;
  132   Constraint od_constraintType;
  133   union
  134   {
  135     char** stringList;  /* Null terminated array of string values  */
  136     int*   numberList;  /* Legal values - numberList[0] = number   */
  137     Range* numberRange;
  138   }
  139   od_constraint;
  140   void* od_specialInfo; /* See below                               */
  141 };
  142 #pragma pack()
  143 
  144 //
  145 // If not NULL, special info has a null terminated int list 
  146 // depending of option id:
  147 //
  148 //  ID_SCANMODE:        If constraint type is a list specialInfo is
  149 //                      a pointer to an int list of scan depth values
  150 //
  151 //  ID_HALFTONEPATTERN: A pointer to an int list of boolean values
  152 //                      telling if the pattern works for the
  153 //                      corresponding scan mode
  154 //
  155 //  ID_BRIGHTNESS:      If ValueType is not UNIT_PERCENT and 
  156 //  ID_CONTRAST:        constraint type is a list specialInfo is
  157 //                      a pointer to an int list of percentage
  158 //                      values corresponding to each value in the
  159 //                      constraint list.
  160 //
  161 //  ID_THRESHOLD:       To be able to make real time threshold
  162 //                      corrections (B/W), BetaScan scans in gray
  163 //                      scale.
  164 //                      Special Info is a pointer to a list of int
  165 //                      telling BetaScan where Gray mode is. For
  166 //                      example:
  167 //                        if modes are:
  168 //                          {"LineArt","Halftone","Gray","Color"}
  169 //                        then set special info to:
  170 //                          {2,1,2,3}
  171 //
  172 //                        This tells BetaScan:
  173 //                          if mode is 0 (LineArt) scan in mode 2 (Gray)
  174 //                          if mode is 1 (Halftone) scan in mode 1
  175 //                          if mode is 2 (Gray) scan in mode 2
  176 //                          if mode is 3 (Color) scan in mode 3
  177 //  ID_SCAN_SOURCE:     If constraint type is a list specialInfo is
  178 //                      a pointer to an int list of Feature (bitset)
  179 // 
  180 
  181 #pragma pack(2)
  182 struct ScannerOptions
  183 {
  184   char   so_scannerVendor[40];
  185   char   so_scannerModel[40];
  186   UBYTE  so_driverVersion;
  187   UBYTE  so_driverRevision;
  188 
  189   double so_docWidth;                      /* Paper size in mm             */
  190   double so_docHeight;
  191 
  192   UWORD  so_flags;                         /* Not used                     */
  193   UWORD  so_optionNum;                     /* Number of option descriptors */
  194   struct OptionDescriptor* so_descriptor;
  195 };
  196 #pragma pack()
  197 //
  198 // Structure to be used by controlOption routine
  199 //
  200 #pragma pack(2)
  201 struct OptionValue
  202 {
  203   OptionId sp_optionID;
  204   int      sp_value;
  205   ULONG    sp_flags;
  206 };
  207 #pragma pack()
  208 
  209 // optionValue flags
  210 //
  211 #define CONTROL_SET        (1<<0)      /* Set new value              */ 
  212 #define CONTROL_GET        (1<<1)      /* Return current value       */
  213                                        /* If both bits are set then  */
  214                                        /* SET is exec. before GET    */
  215 
  216 #define CONTROL_ROUNDED    (1<<16)     /* Value set is not exact     */
  217 #define CONTROL_RANGE      (1<<17)     /* Out of range - not set     */
  218 #define CONTROL_DISABLED   (1<<18)     /* Option disabled - not set  */
  219 #define CONTROL_INVALID    (1<<19)     /* Option not supported       */
  220 #define CONTROL_RELOAD     (1<<20)     /* Other options are affected */
  221 
  222 #define CONTROL_CALLMASK   0x0000FFFF
  223 #define CONTROL_RETURNMASK 0xFFFF0000
  224 
  225 
  226 typedef enum
  227 {
  228   FORMAT_BW = 0,
  229   FORMAT_GRAY,                /* 8 bit gray scale                    */
  230   FORMAT_RED,
  231   FORMAT_GREEN,
  232   FORMAT_BLUE,
  233   FORMAT_RGB,                 /* Each pixel as 3 (24bit) byte RGB    */
  234   FORMAT_RGB_RANDOM           /* Colors separated in 8 bit red,      */
  235 } LineFormat;                 /* green and blue components ariving   */
  236                               /* (posibly) in random order. Used by  */
  237                               /* 3 pass scanners.                    */
  238 
  239 struct ScanInformation
  240 {
  241   double     sv_xResolution;  /* actual horizontal resolution        */
  242   double     sv_yResolution;  /* actual vertical resolution          */
  243   LineFormat sv_lineFormat;   /* format of scan lines                */
  244   UWORD      sv_imageWidth;   /* image width in pixels               */
  245   UWORD      sv_imageHeight;  /* image height in pixels              */
  246   UWORD      sv_imageDepth;   /* image depth in bits                 */
  247   UWORD      sv_bytesPerLine; /* bytes per line read                 */
  248   ULONG      sv_Flags;        /* data information flags              */
  249 };
  250 
  251 struct ScanLine
  252 {
  253   UBYTE*     sl_data;
  254   LineFormat sl_color;   /* If sv_lineFormat is FORMAT_RGB_RANDOM    */
  255 };                       /* this is either FORMAT_RED, FORMAT_GREEN  */
  256                          /* or FORMAT_BLUE. Otherwise it must be the */
  257                          /* same as sv_lineFormat.                   */
  258 
  259 
  260 struct ScannerIO
  261 {
  262     struct IOStdReq       IOScan;
  263     struct ScannerOptions option;
  264 };
  265 
  266 #endif /* SCANNER_H */
  267