• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /***************************************************************************
2  * SANE - Scanner Access Now Easy.
3 
4    microtek.h
5 
6    This file Copyright 2002 Matthew Marjanovic
7 
8    This file is part of the SANE package.
9 
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2 of the
13    License, or (at your option) any later version.
14 
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19 
20    You should have received a copy of the GNU General Public License
21    along with this program.  If not, see <https://www.gnu.org/licenses/>.
22 
23    As a special exception, the authors of SANE give permission for
24    additional uses of the libraries contained in this release of SANE.
25 
26    The exception is that, if you link a SANE library with other files
27    to produce an executable, this does not by itself cause the
28    resulting executable to be covered by the GNU General Public
29    License.  Your use of that executable is in no way restricted on
30    account of linking the SANE library code into it.
31 
32    This exception does not, however, invalidate any other reasons why
33    the executable file might be covered by the GNU General Public
34    License.
35 
36    If you submit changes to SANE to the maintainers to be included in
37    a subsequent release, you agree by submitting the changes that
38    those changes may be distributed with this exception intact.
39 
40    If you write modifications of your own for SANE, it is your choice
41    whether to permit this exception to apply to your modifications.
42    If you do not wish that, delete this exception notice.
43 
44  ***************************************************************************
45 
46    This file implements a SANE backend for Microtek scanners.
47 
48    (feedback to:  mtek-bugs@mir.com)
49    (for latest info:  http://www.mir.com/mtek/)
50 
51  ***************************************************************************/
52 
53 
54 #ifndef microtek_h
55 #define microtek_h
56 
57 #include <sys/types.h>
58 
59 
60 /*******************************************************************/
61 /***** enumeration of Option Descriptors                       *****/
62 /*******************************************************************/
63 
64 enum Mtek_Option
65 {
66   OPT_NUM_OPTS = 0,
67 
68   OPT_MODE_GROUP,
69   OPT_MODE,             /* -a,b,c,g */
70   OPT_HALFTONE_PATTERN, /* -H */
71   OPT_RESOLUTION,       /* -r */
72   OPT_EXP_RES,
73   OPT_NEGATIVE,         /* -n */
74   OPT_SPEED,            /* -v */
75   OPT_SOURCE,           /* -t */
76   OPT_PREVIEW,
77   OPT_CALIB_ONCE,
78 
79   OPT_GEOMETRY_GROUP,   /* -f .... */
80   OPT_TL_X,             /* top-left x */
81   OPT_TL_Y,             /* top-left y */
82   OPT_BR_X,             /* bottom-right x */
83   OPT_BR_Y,             /* bottom-right y */
84 
85   OPT_ENHANCEMENT_GROUP,
86   OPT_EXPOSURE,
87   OPT_BRIGHTNESS,       /* -d */
88   OPT_CONTRAST,         /* -k */
89   OPT_HIGHLIGHT,        /* -l */
90   OPT_SHADOW,           /* -s */
91   OPT_MIDTONE,          /* -m */
92 
93   OPT_GAMMA_GROUP,
94   OPT_CUSTOM_GAMMA,
95   OPT_ANALOG_GAMMA,
96   OPT_ANALOG_GAMMA_R,
97   OPT_ANALOG_GAMMA_G,
98   OPT_ANALOG_GAMMA_B,
99   /* "The gamma vectors MUST appear in the order gray, red, green, blue." */
100   OPT_GAMMA_VECTOR,
101   OPT_GAMMA_VECTOR_R,
102   OPT_GAMMA_VECTOR_G,
103   OPT_GAMMA_VECTOR_B,
104   OPT_GAMMA_BIND,
105 
106   NUM_OPTIONS,
107 
108   OPT_BACKTRACK,        /* -B */
109 
110   /* must come last: */
111   RNUM_OPTIONS
112 };
113 
114 
115 /*******************************************************************/
116 /***** scanner hardware information (as discovered by INQUIRY) *****/
117 /*******************************************************************/
118 
119 typedef struct Microtek_Info {
120   char vendor_id[9];
121   char model_name[17];
122   char revision_num[5];
123   char vendor_string[21];
124   SANE_Byte device_type;
125   SANE_Byte SCSI_firmware_ver_major;
126   SANE_Byte SCSI_firmware_ver_minor;
127   SANE_Byte scanner_firmware_ver_major;
128   SANE_Byte scanner_firmware_ver_minor;
129   SANE_Byte response_data_format;
130 #define MI_RESSTEP_1PER 0x01
131 #define MI_RESSTEP_5PER 0x02
132   SANE_Byte res_step;
133 #define MI_MODES_LINEART  0x01
134 #define MI_MODES_HALFTONE 0x02
135 #define MI_MODES_GRAY     0x04  /* ??????? or "MultiBit"??? XXXXX*/
136 #define MI_MODES_COLOR    0x08
137 #define MI_MODES_TRANSMSV 0x20
138 #define MI_MODES_ONEPASS  0x40
139 #define MI_MODES_NEGATIVE 0x80
140   SANE_Byte modes;
141   SANE_Int pattern_count;
142   SANE_Byte pattern_dwnld;
143 #define MI_FEED_FLATBED  0x01
144 #define MI_FEED_EDGEFEED 0x02
145 #define MI_FEED_AUTOSUPP 0x04
146   SANE_Byte feed_type;
147 #define MI_COMPRSS_HUFF  0x10
148 #define MI_COMPRSS_RD    0x20
149   SANE_Byte compress_type;
150 #define MI_UNIT_8TH_INCH 0x40
151 #define MI_UNIT_PIXELS   0x80
152   SANE_Byte unit_type;
153   SANE_Byte doc_size_code;
154   SANE_Int max_x; /* pixels */
155   SANE_Int max_y; /* pixels */
156   SANE_Range doc_x_range; /* mm */
157   SANE_Range doc_y_range; /* mm */
158   SANE_Int cont_settings;
159   SANE_Int exp_settings;
160   SANE_Byte model_code;
161   SANE_Int base_resolution; /* dpi, guessed by backend, per model code */
162 #define MI_SRC_FEED_SUPP 0x01 /* support for feeder                    */
163 #define MI_SRC_FEED_BT   0x02 /* support for feed backtracking control */
164 #define MI_SRC_HAS_FEED  0x04 /* feeder installed                      */
165 #define MI_SRC_FEED_RDY  0x08 /* feeder ready                          */
166 #define MI_SRC_GET_FEED  0x10 /* if opaque:  get from feeder           */
167 #define MI_SRC_GET_TRANS 0x20 /* get transparency (not opaque)         */
168 #define MI_SRC_HAS_TRANS 0x40 /* transparency adapter installed        */
169   SANE_Byte source_options;
170   SANE_Byte expanded_resolution;
171 #define MI_ENH_CAP_SHADOW  0x01  /* can adjust shadow/highlight */
172 #define MI_ENH_CAP_MIDTONE 0x02  /* can adjust midtone          */
173   SANE_Byte enhance_cap;
174   SANE_Int max_lookup_size;     /* max. size of gamma LUT            */
175   SANE_Int max_gamma_bit_depth; /* max. bits of a gamma LUT element  */
176   SANE_Int gamma_size;          /* size (bytes) of each LUT element  */
177   SANE_Byte fast_color_preview; /* allows fast color preview?        */
178   SANE_Byte xfer_format_select; /* allows select of transfer format? */
179 #define MI_COLSEQ_PLANE  0x00
180 #define MI_COLSEQ_PIXEL  0x01
181 #define MI_COLSEQ_RGB    0x02
182 #define MI_COLSEQ_NONRGB 0x03
183 #define MI_COLSEQ_2PIXEL 0x11       /* Agfa StudioStar */
184   SANE_Byte color_sequence;     /* color sequence spec. code         */
185   SANE_Byte does_3pass;         /* allows 3-pass scanning?           */
186   SANE_Byte does_mode1;         /* allows MODE1 sense/select comm's? */
187 #define MI_FMT_CAP_4BPP  0x01
188 #define MI_FMT_CAP_10BPP 0x02
189 #define MI_FMT_CAP_12BPP 0x04
190 #define MI_FMT_CAP_16BPP 0x08
191   SANE_Byte bit_formats;        /* output bit formats capabilities   */
192 #define MI_EXCAP_OFF_CTL   0x01
193 #define MI_EXCAP_DIS_LNTBL 0x02
194 #define MI_EXCAP_DIS_RECAL 0x04
195   SANE_Byte extra_cap;
196   /*  SANE_Int contrast_vals;  rolled into cont_settings */
197   SANE_Int min_contrast;
198   SANE_Int max_contrast;
199   /*  SANE_Int exposure_vals;  rolled into exp_settings */
200   SANE_Int min_exposure;
201   SANE_Int max_exposure;
202   SANE_Byte does_expansion;     /* does expanded-mode expansion internally? */
203 } Microtek_Info;
204 
205 
206 
207 /*******************************************************************/
208 /***** device structure (one for each device discovered)       *****/
209 /*******************************************************************/
210 
211 typedef struct Microtek_Device {
212   struct Microtek_Device *next; /* next, for linked list     */
213   SANE_Device sane;             /* SANE generic device block */
214   Microtek_Info info;           /* detailed scanner spec     */
215 } Microtek_Device;
216 
217 
218 
219 /*******************************************************************/
220 /***** ring buffer structure                                   *****/
221 /*****       ....image workspace during scan                   *****/
222 /*******************************************************************/
223 
224 typedef struct ring_buffer {
225   size_t bpl;  /* bytes per line */
226   size_t ppl;  /* pixels per line */
227 
228   uint8_t *base;  /* base address of buffer */
229 
230   size_t size;         /* size (bytes) of ring buffer */
231   size_t initial_size; /* initial size of ring buffer */
232 
233   size_t tail_blue;   /* byte index, next blue line  */
234   size_t tail_green;  /* byte index, next green line */
235   size_t tail_red;    /* byte index, next red line   */
236 
237   size_t blue_extra;  /* unmatched blue bytes  */
238   size_t green_extra; /* unmatched green bytes */
239   size_t red_extra;   /* unmatched red bytes   */
240 
241   size_t complete_count;
242   size_t head_complete;
243 
244 } ring_buffer;
245 
246 
247 
248 
249 /*******************************************************************/
250 /***** scanner structure (one for each device in use)          *****/
251 /*****       ....all the state needed to define a scan request *****/
252 /*******************************************************************/
253 
254 typedef struct Microtek_Scanner {
255   struct Microtek_Scanner *next;  /* for linked list */
256   Microtek_Device *dev;           /* raw device info */
257 
258   SANE_Option_Descriptor sod[RNUM_OPTIONS]; /* option list for session   */
259   Option_Value val[RNUM_OPTIONS];  /* option values for session */
260 
261   /*  SANE_Int gamma_table[4][256];*/
262   SANE_Int *gray_lut;
263   SANE_Int *red_lut;
264   SANE_Int *green_lut;
265   SANE_Int *blue_lut;
266 
267   SANE_Range res_range;      /* range desc. for resolution */
268   SANE_Range exp_res_range;  /* range desc. for exp. resolution */
269 
270   /* scan parameters, ready to toss to SCSI commands*/
271 
272   /* ...set by sane_open  (i.e. general/default scanner parameters) */
273 #define MS_UNIT_PIXELS 0
274 #define MS_UNIT_18INCH 1
275   SANE_Byte unit_type;  /* pixels or 1/8" */
276 #define MS_RES_1PER 0
277 #define MS_RES_5PER 1
278   SANE_Byte res_type; /* 1% or 5% */
279   SANE_Bool midtone_support;
280   SANE_Int paper_length; /* whatever unit */
281 
282   SANE_Bool do_clever_precal;  /* calibrate scanner once, via fake scan */
283   SANE_Bool do_real_calib;     /* calibrate via magic commands */
284   SANE_Bool calib_once;        /*  ...only calibrate magically once */
285 
286   SANE_Bool allow_calibrate;
287   SANE_Bool onepass;
288   SANE_Bool prescan, allowbacktrack;
289   SANE_Bool reversecolors;
290   SANE_Bool fastprescan;
291   SANE_Int bits_per_color;
292   SANE_Int gamma_entries;
293   SANE_Int gamma_entry_size;
294   SANE_Int gamma_bit_depth;
295   /*  SANE_Int gamma_max_entry;*/
296 
297   SANE_Range gamma_entry_range;
298   SANE_Range contrast_range;
299   SANE_Range exposure_range;
300 
301   /* ...set by sane_get_parameters  (i.e. parameters specified by options) */
302   SANE_Parameters params;   /* format, lastframe, lines, depth, ppl, bpl */
303   SANE_Int x1;  /* in 'units' */
304   SANE_Int y1;
305   SANE_Int x2;
306   SANE_Int y2;
307 #define MS_MODE_LINEART 0
308 #define MS_MODE_HALFTONE 1
309 #define MS_MODE_GRAY 2
310 #define MS_MODE_COLOR 3
311   SANE_Int mode;
312 #define MS_FILT_CLEAR 0
313 #define MS_FILT_RED 1
314 #define MS_FILT_GREEN 2
315 #define MS_FILT_BLUE 3
316   SANE_Byte filter;
317   SANE_Bool onepasscolor, transparency, useADF;
318   SANE_Bool threepasscolor, expandedresolution;
319   SANE_Int resolution;
320   SANE_Byte resolution_code;
321   SANE_Byte exposure, contrast;
322   SANE_Byte pattern;
323   SANE_Byte velocity;
324   SANE_Byte shadow, highlight, midtone;
325   SANE_Byte bright_r, bright_g, bright_b; /* ??? XXXXXXXX signed char */
326   SANE_Bool multibit;
327   SANE_Byte color_seq;
328 
329   /* ...stuff needed while in mid-scan */
330 #define MS_LNFMT_FLAT 0
331 #define MS_LNFMT_SEQ_RGB 1
332 #define MS_LNFMT_GOOFY_RGB 2
333 #define MS_LNFMT_SEQ_2R2G2B 3
334   SANE_Int line_format; /* specify how we need to repackage scanlines */
335 
336   SANE_Int pixel_bpl;   /* bytes per line, pixels  */
337   SANE_Int header_bpl;  /* bytes per line, headers */
338   SANE_Int ppl;         /* pixels per line         */
339   SANE_Int planes;      /* color planes            */
340 
341   SANE_Bool doexpansion;
342   double exp_aspect;
343   SANE_Int dest_pixel_bpl;
344   SANE_Int dest_ppl;
345 
346   SANE_Int unscanned_lines;    /* lines still to be read from scanner */
347   SANE_Int undelivered_bytes;  /* bytes still to be returned to frontend */
348   SANE_Int max_scsi_lines; /* max number of lines that fit in SCSI buffer */
349 
350 
351   int sfd;	 /* SCSI device file descriptor, -1 when not opened       */
352   int scanning;  /* true == mid-pass (between sane_start & sane_read=EOF) */
353   int scan_started; /* true == start_scan has scanner going...            */
354   int woe;  /* Woe! */
355   int this_pass; /* non-zero => in midst of a multipass scan (1,2,3)      */
356   int cancel;
357 
358   /* we cleverly compare mode_sense results between scans to detect
359      if the scanner may have been reset/power-cycled in the meantime */
360   SANE_Byte mode_sense_cache[10];
361 #define MS_PRECAL_NONE 0
362 #define MS_PRECAL_GRAY 1
363 #define MS_PRECAL_COLOR 2
364 #define MS_PRECAL_EXP_COLOR 3
365   SANE_Byte precal_record; /* record what precalibrations have been done */
366 
367 #define MS_SENSE_IGNORE 1
368   int sense_flags;  /* flags passed to the sense handler */
369 
370   uint8_t *scsi_buffer;
371   ring_buffer *rb;
372 
373 } Microtek_Scanner;
374 
375 
376 #endif /* microtek_h */
377