1 /* sane - Scanner Access Now Easy.
2    Copyright (C) 1999,2000 Tom Martone
3    This file is part of a SANE backend for Bell and Howell Copiscan II
4    Scanners using the Remote SCSI Controller(RSC).
5 
6    This file is part of the SANE package.
7 
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2 of the
11    License, or (at your option) any later version.
12 
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17 
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <https://www.gnu.org/licenses/>.
20 
21    As a special exception, the authors of SANE give permission for
22    additional uses of the libraries contained in this release of SANE.
23 
24    The exception is that, if you link a SANE library with other files
25    to produce an executable, this does not by itself cause the
26    resulting executable to be covered by the GNU General Public
27    License.  Your use of that executable is in no way restricted on
28    account of linking the SANE library code into it.
29 
30    This exception does not, however, invalidate any other reasons why
31    the executable file might be covered by the GNU General Public
32    License.
33 
34    If you submit changes to SANE to the maintainers to be included in
35    a subsequent release, you agree by submitting the changes that
36    those changes may be distributed with this exception intact.
37 
38    If you write modifications of your own for SANE, it is your choice
39    whether to permit this exception to apply to your modifications.
40    If you do not wish that, delete this exception notice.  */
41 
42 #ifndef BH_H
43 #define BH_H 1
44 
45 #ifndef PATH_MAX
46 #define PATH_MAX (1024)
47 #endif
48 
49 #define BH_CONFIG_FILE "bh.conf"
50 
51 /* number of barcode types that can be searched at one time */
52 #define NUM_SEARCH_BARS 6
53 /* number of additional scanning/decoding sections supported */
54 #define NUM_SECTIONS 8
55 /* number of possible reads per scan plus the extra one for
56  * the barcode file
57  */
58 #define NUM_READS 56 + 1
59 
60 /* specify sanity limits for autoborder detection and barcode decoding */
61 #define BH_AUTOBORDER_TRIES 100
62 #define BH_DECODE_TRIES 100
63 /* specify a fudge factor in mm for border around decoded barcodes */
64 #define BH_DECODE_FUDGE 1.0
65 
66 /* section flags - what operation(s) to perform on section */
67 #define BH_SECTION_FRONT_IMAGE (1 << 0)
68 #define BH_SECTION_BACK_IMAGE (1 << 1)
69 #define BH_SECTION_FRONT_BAR (1 << 2)
70 #define BH_SECTION_BACK_BAR (1 << 3)
71 #define BH_SECTION_FRONT_PATCH (1 << 4)
72 #define BH_SECTION_BACK_PATCH (1 << 5)
73 
74 typedef enum
75 {
76   BH_UNIT_INCH,
77   BH_UNIT_MM,
78   BH_UNIT_POINT
79 } bh_measureUnit;
80 
81 typedef enum
82 {
83   BH_COMP_NONE,
84   BH_COMP_G31D,
85   BH_COMP_G32D,
86   BH_COMP_G42D
87 } bh_compress;
88 
89 typedef enum
90 {
91   BH_ROTATION_0,
92   BH_ROTATION_90,
93   BH_ROTATION_180,
94   BH_ROTATION_270
95 } bh_rotation;
96 
97 typedef enum
98 {
99   OPT_NUM_OPTS = 0,
100 
101   OPT_MODE_GROUP,
102   /* inquiry string */
103   OPT_INQUIRY,
104   /* preview mode */
105   OPT_PREVIEW,
106   /* scan mode */
107   OPT_SCAN_MODE,
108   /* resolution */
109   OPT_RESOLUTION,
110   /* hardware compression */
111   OPT_COMPRESSION,
112 
113   OPT_GEOMETRY_GROUP,
114   /* automatic border detection */
115   OPT_AUTOBORDER,
116   /* hardware rotation */
117   OPT_ROTATION,
118   /* hardware deskew */
119   OPT_DESKEW,
120   /* paper size */
121   OPT_PAPER_SIZE,
122   /* top-left x */
123   OPT_TL_X,
124   /* top-left y */
125   OPT_TL_Y,
126   /* bottom-right x */
127   OPT_BR_X,
128   /* bottom-right y */
129   OPT_BR_Y,
130 
131   OPT_FEEDER_GROUP,
132   /* scan source (eg. ADF) */
133   OPT_SCAN_SOURCE,
134   /* scan in batch mode */
135   OPT_BATCH,
136   /* scan both sides of the page */
137   OPT_DUPLEX,
138   /* timeout in seconds with manual feed */
139   OPT_TIMEOUT_MANUAL,
140   /* timeout in seconds with ADF */
141   OPT_TIMEOUT_ADF,
142   /* check for page in ADF before scanning */
143   OPT_CHECK_ADF,
144 
145   OPT_ENHANCEMENT_GROUP,
146   /* Enables the scanner's control panel */
147   OPT_CONTROL_PANEL,
148   /* ACE Function */
149   OPT_ACE_FUNCTION,
150   /* ACE Sensitivity */
151   OPT_ACE_SENSITIVITY,
152   /* Brightness */
153   OPT_BRIGHTNESS,
154   /* Threshold */
155   OPT_THRESHOLD,
156   /* Contrast */
157   OPT_CONTRAST,
158   /* Negative (reverse image) */
159   OPT_NEGATIVE,
160 
161   OPT_ICON_GROUP,
162   /* Width of icon (thumbnail) image in pixels */
163   OPT_ICON_WIDTH,
164   /* Length of icon (thumbnail) image in pixels */
165   OPT_ICON_LENGTH,
166 
167   OPT_BARCODE_GROUP,
168   /* Add <name> to barcode search priority. */
169   OPT_BARCODE_SEARCH_BAR,
170   /* Barcode search count (1-7, default 3). */
171   OPT_BARCODE_SEARCH_COUNT,
172   /* Barcode search mode.
173    * (1 = horizontal,2 = vertical, 6 = v then h, 9 = h then v).
174    */
175   OPT_BARCODE_SEARCH_MODE,
176   /* Patch code min height (def=127 (5mm)) */
177   OPT_BARCODE_HMIN,
178   /* Barcode search timeout in ms
179    * (20-65535,default is disabled).
180    */
181   OPT_BARCODE_SEARCH_TIMEOUT,
182   /* Specify image sections and functions
183    */
184   OPT_SECTION,
185   /* Specifies the maximum relation from the widest to
186    * the smallest bar
187    */
188   OPT_BARCODE_RELMAX,
189   /* Specifies the minimum number of bars in Bar/Patch code */
190   OPT_BARCODE_BARMIN,
191   /* Specifies the maximum number of bars in a Bar/Patch code */
192   OPT_BARCODE_BARMAX,
193   /* Specifies the image contrast used in decoding.
194    * Use higher values when there are more white pixels
195    * in the code
196    */
197   OPT_BARCODE_CONTRAST,
198   /* Controls Patch Code detection. */
199   OPT_BARCODE_PATCHMODE,
200 
201   /* must come last: */
202   NUM_OPTIONS
203 
204 } BH_Option;
205 
206 /* macros for accessing the value for an option within a scanning context */
207 #define _OPT_VAL_WORD(s, o) ((s)->val[(o)].w)
208 #define _OPT_VAL_WORD_THOUSANDTHS(s, o) \
209     (SANE_UNFIX(_OPT_VAL_WORD((s), (o))) * 1000.0 / MM_PER_INCH)
210 #define _OPT_VAL_STRING(s, o) ((s)->val[(o)].s)
211 #define _OPT_VAL_WORD_ARRAY(s, o) ((s)->val[(o)].wa)
212 
213 
214 typedef struct _BH_Paper
215 {
216   SANE_String name;
217 
218   /* paper dimensions in mm */
219   double width, length;
220 } BH_Paper;
221 
222 typedef struct _BH_Section
223 {
224   /* section dimensions - in millimeters */
225   u_long top, left, width, length;
226 
227   /* compression type/arg/frameformat */
228   SANE_Byte compressiontype;
229   SANE_Byte compressionarg;
230   SANE_Frame format;
231 
232   /* Flags (see BH_SECTION_...) indicating operation(s) to perform
233    * on the section.  If zero, the section is completely disabled
234    * and will not even be defined in set_window.
235    */
236   SANE_Word flags;
237 
238 } BH_Section;
239 
240 typedef struct _BH_Info
241 {
242   SANE_Range x_range;
243   SANE_Range y_range;
244 
245   SANE_Int res_default;
246   SANE_Bool autoborder_default;
247   SANE_Bool batch_default;
248   SANE_Bool deskew_default;
249   SANE_Bool check_adf_default;
250   SANE_Bool duplex_default;
251   SANE_Int timeout_adf_default;
252   SANE_Int timeout_manual_default;
253   SANE_Bool control_panel_default;
254 
255   /* additional discovered/guessed capabilities */
256   SANE_Bool canACE;
257   SANE_Bool canDuplex;
258   SANE_Bool canCheckADF;
259 
260   /* standard information */
261   SANE_Byte devtype;
262   SANE_Char vendor[9];	/* model name */
263   SANE_Char product[17];	/* product name */
264   SANE_Char revision[5];	/* revision */
265 
266   /* VPD information */
267   SANE_Bool canADF;		/* is there an ADF available */
268   SANE_Bool colorBandW;	/* can scanner do black and white */
269   SANE_Bool colorHalftone;	/* can scanner do Halftone */
270   SANE_Bool canWhiteFrame;	/* data processing: White Framing */
271   SANE_Bool canBlackFrame;	/* data processing: Black Framing */
272   SANE_Bool canEdgeExtract;	/* data processing: ACE: Edge Extraction */
273   SANE_Bool canNoiseFilter;	/* data processing: ACE: Noise Filtering */
274   SANE_Bool canSmooth;	/* data processing: ACE: Smoothing */
275   SANE_Bool canLineBold;	/* data processing: ACE: LineBolding */
276   SANE_Bool comprG3_1D;	/* compression: Group 3, 1 dimensional */
277   SANE_Bool comprG3_2D;	/* compression: Group 3, 2 dimensional */
278   SANE_Bool comprG4;		/* compression: Group 4 */
279   SANE_Bool canBorderRecog;	/* can do border recognition */
280   SANE_Bool canBarCode;	/* bar code support available */
281   SANE_Bool canIcon;		/* icon support available */
282   SANE_Bool canSection;	/* section support available */
283   SANE_Int lineMaxBytes;	/* maximum bytes per scan-line */
284 
285   /* jis information */
286   SANE_Int resBasicX;		/* basic X resolution */
287   SANE_Int resBasicY;		/* basic Y resolution */
288   SANE_Int resMaxX;		/* maximum X resolution */
289   SANE_Int resMaxY;		/* maximum Y resolution */
290   SANE_Int resMinX;		/* minimum X resolution */
291   SANE_Int resMinY;		/* minimum Y resolution */
292   SANE_Int resStdList[16+1];    /* list of available standard resolutions
293 				 * (first slot is the length)
294 				 */
295   SANE_Int winWidth;		/* length of window (in BasicX res DPI) */
296   SANE_Int winHeight;		/* height of window (in BasicY res DPI) */
297 } BH_Info;
298 
299 typedef struct _BH_Device BH_Device;
300 
301 struct _BH_Device
302 {
303   BH_Device *next;
304   SANE_Device sane;
305   BH_Info info;
306 };
307 
308 
309 typedef struct _BH_Scanner BH_Scanner;
310 struct _BH_Scanner
311 {
312   /* all the state needed to define a scan request: */
313 
314   /* linked list for housekeeping */
315   BH_Scanner *next;
316 
317   /* scanner dependent/low-level state: */
318   BH_Device *hw;
319 
320   /* SCSI filedescriptor */
321   int fd;
322 
323   /* tempfile which is used to send decoded barcode data */
324   FILE *barf;
325   char barfname[PATH_MAX+1];
326 
327   /* SANE option descriptors and values */
328   SANE_Option_Descriptor opt[NUM_OPTIONS];
329   Option_Value val[NUM_OPTIONS];
330 
331   /* additional values that don't fit into Option_Value representation */
332   SANE_Byte search_bars[NUM_SEARCH_BARS];
333   BH_Section sections[NUM_SECTIONS];
334   SANE_Int num_sections;
335 
336   /* SANE image parameters */
337   SANE_Parameters params;
338 
339   /* state information - not options */
340 
341   /* Basic Measurement Unit */
342   SANE_Int bmu;
343   /* Measurement Unit Divisor */
344   SANE_Int mud;
345 
346   /* track data to be read.  ReadList contains the codes of the read types
347    * (see BH_READ_TYPE...) to perform, readcnt is the total number of reads
348    * for this scan and readptr points to the current read operation.
349    */
350   SANE_Byte readlist[NUM_READS];
351   SANE_Int readcnt, readptr;
352 
353   u_long InvalidBytes;
354   SANE_Bool scanning;
355   SANE_Bool cancelled;
356   SANE_Bool backpage;
357   SANE_Bool barcodes;
358   SANE_Bool patchcodes;
359   SANE_Bool icons;
360   u_long iconwidth, iconlength;
361   SANE_Bool barcode_not_found;
362 };
363 
364 static const SANE_Range u8_range =
365 {
366     0,		/* minimum */
367     255,	/* maximum */
368     0		/* quantization */
369 };
370 
371 static const SANE_Range u16_range =
372 {
373     0,		/* minimum */
374     65535, 	/* maximum */
375     0		/* quantization */
376 };
377 
378 static const SANE_Range icon_range =
379 {
380     0,		/* minimum */
381     3600, 	/* maximum */
382     8		/* quantization */
383 };
384 
385 static const SANE_Range barcode_search_timeout_range =
386 {
387     20,		/* minimum */
388     65535, 	/* maximum */
389     0		/* quantization */
390 };
391 
392 static const SANE_Range barcode_hmin_range =
393 {
394     1,		/* minimum */
395     1660, 	/* maximum (when converted from mm
396 		 * to thousandths will still be less
397 		 * than 65536)
398 		 */
399     0		/* quantization */
400 };
401 
402 static const SANE_Range barcode_search_count_range =
403 {
404     1,		/* minimum */
405     7,  	/* maximum */
406     0		/* quantization */
407 };
408 
409 static const SANE_Range barcode_relmax_range =
410 {
411     0,		/* minimum */
412     6,  	/* maximum */
413     0		/* quantization */
414 };
415 
416 static const SANE_Range barcode_contrast_range =
417 {
418     0,		/* minimum */
419     6,  	/* maximum */
420     0		/* quantization */
421 };
422 
423 static const SANE_Range barcode_patchmode_range =
424 {
425     0,		/* minimum */
426     1,  	/* maximum */
427     0		/* quantization */
428 };
429 
430 static const SANE_Range ace_function_range =
431 {
432     -4,		/* minimum */
433     4,  	/* maximum */
434     0		/* quantization */
435 };
436 
437 static const SANE_Range ace_sensitivity_range =
438 {
439     0,		/* minimum */
440     9,  	/* maximum */
441     0		/* quantization */
442 };
443 
444 static SANE_String_Const scan_mode_list[] =
445 {
446   "lineart",
447   "halftone",
448   0
449 };
450 
451 static SANE_String_Const scan_mode_min_list[] =
452 {
453   "lineart",
454   0
455 };
456 
457 static SANE_String_Const barcode_search_mode_list[] =
458 {
459   "horiz-vert", /* 9 */
460   "horizontal", /* 1 */
461   "vertical",   /* 2 */
462   "vert-horiz", /* 6 */
463   0
464 };
465 
466 static SANE_String_Const scan_source_list[] =
467 {
468   "Automatic Document Feeder",
469   "Manual Feed Tray",
470   0
471 };
472 
473 static SANE_String_Const compression_list[] =
474 {
475   "none",
476   "g31d",
477   "g32d",
478   "g42d",
479   0
480 };
481 
482 /* list of supported bar/patch codes */
483 static SANE_String_Const barcode_search_bar_list[] =
484 {
485   "none",
486   "ean-8",
487   "ean-13",
488   "reserved-ean-add",
489   "code39",
490   "code2-5-interleaved",
491   "code2-5-3lines-matrix",
492   "code2-5-3lines-datalogic",
493   "code2-5-5lines-industrial",
494   "patchcode",
495   "codabar",
496   "codabar-with-start-stop",
497   "code39ascii",
498   "code128",
499   "code2-5-5lines-iata",
500   0
501 };
502 
503 /* list of supported rotation angles */
504 static SANE_String_Const rotation_list[] =
505 {
506   "0",
507   "90",
508   "180",
509   "270",
510   0
511 };
512 
513 /* list of support paper sizes */
514 /* 'custom' MUST be item 0; otherwise a width or length of 0 indicates
515  * the maximum value supported by the scanner
516  */
517 static const BH_Paper paper_sizes[] =
518 {
519   {"Custom", 0.0, 0.0},
520   {"Letter", 215.9, 279.4},
521   {"Legal", 215.9, 355.6},
522   {"A3", 297, 420},
523   {"A4", 210, 297},
524   {"A5", 148.5, 210},
525   {"A6", 105, 148.5},
526   {"B4", 250, 353},
527   {"B5", 182, 257},
528   {"Full", 0.0, 0.0},
529 };
530 
531 /* MUST be kept in sync with paper_sizes */
532 static SANE_String_Const paper_list[] =
533 {
534   "Custom",
535   "Letter",
536   "Legal",
537   "A3",
538   "A4",
539   "A5",
540   "A6",
541   "B4",
542   "B5",
543   "Full",
544   0
545 };
546 
547 static /* inline */ int _is_host_little_endian(void);
548 static /* inline */ int
_is_host_little_endian()549 _is_host_little_endian()
550 {
551   SANE_Int val = 255;
552   unsigned char *firstbyte = (unsigned char *) &val;
553 
554   return (*firstbyte == 255) ? SANE_TRUE : SANE_FALSE;
555 }
556 
557 static /* inline */ void
_lto2b(u_long val, SANE_Byte *bytes)558 _lto2b(u_long val, SANE_Byte *bytes)
559 {
560   bytes[0] = (val >> 8) & 0xff;
561   bytes[1] = val & 0xff;
562 }
563 
564 static /* inline */ void
_lto3b(u_long val, SANE_Byte *bytes)565 _lto3b(u_long val, SANE_Byte *bytes)
566 {
567   bytes[0] = (val >> 16) & 0xff;
568   bytes[1] = (val >> 8) & 0xff;
569   bytes[2] = val & 0xff;
570 }
571 
572 static /* inline */ void
_lto4b(u_long val, SANE_Byte *bytes)573 _lto4b(u_long val, SANE_Byte *bytes)
574 {
575   bytes[0] = (val >> 24) & 0xff;
576   bytes[1] = (val >> 16) & 0xff;
577   bytes[2] = (val >> 8) & 0xff;
578   bytes[3] = val & 0xff;
579 }
580 
581 static /* inline */ u_long
_2btol(SANE_Byte *bytes)582 _2btol(SANE_Byte *bytes)
583 {
584   u_long rv;
585 
586   rv = (bytes[0] << 8) | bytes[1];
587 
588   return rv;
589 }
590 
591 static /* inline */ u_long
_4btol(SANE_Byte *bytes)592 _4btol(SANE_Byte *bytes)
593 {
594   u_long rv;
595 
596   rv = (bytes[0] << 24) |
597     (bytes[1] << 16) |
598     (bytes[2] << 8) |
599     bytes[3];
600 
601   return rv;
602 }
603 
604 #define SANE_TITLE_SCAN_MODE_GROUP "Scan Mode"
605 #define SANE_TITLE_GEOMETRY_GROUP "Geometry"
606 #define SANE_TITLE_FEEDER_GROUP "Feeder"
607 #define SANE_TITLE_ENHANCEMENT_GROUP "Enhancement"
608 #define SANE_TITLE_ICON_GROUP "Icon"
609 #define SANE_TITLE_BARCODE_GROUP "Barcode"
610 
611 #define SANE_NAME_AUTOBORDER "autoborder"
612 #define SANE_TITLE_AUTOBORDER "Autoborder"
613 #define SANE_DESC_AUTOBORDER "Enable Automatic Border Detection"
614 
615 #define SANE_NAME_COMPRESSION "compression"
616 #define SANE_TITLE_COMPRESSION "Data Compression"
617 #define SANE_DESC_COMPRESSION "Sets the compression mode of the scanner"
618 
619 #define SANE_NAME_ROTATION "rotation"
620 #define SANE_TITLE_ROTATION "Page Rotation"
621 #define SANE_DESC_ROTATION "Sets the page rotation mode of the scanner"
622 
623 #define SANE_NAME_DESKEW "deskew"
624 #define SANE_TITLE_DESKEW "Page Deskew"
625 #define SANE_DESC_DESKEW "Enable Deskew Mode"
626 
627 #define SANE_NAME_TIMEOUT_ADF "timeout-adf"
628 #define SANE_TITLE_TIMEOUT_ADF "ADF Timeout"
629 #define SANE_DESC_TIMEOUT_ADF "Sets the timeout in seconds for the ADF"
630 
631 #define SANE_NAME_TIMEOUT_MANUAL "timeout-manual"
632 #define SANE_TITLE_TIMEOUT_MANUAL "Manual Timeout"
633 #define SANE_DESC_TIMEOUT_MANUAL "Sets the timeout in seconds for manual feeder"
634 
635 #define SANE_NAME_BATCH "batch"
636 #define SANE_TITLE_BATCH "Batch"
637 #define SANE_DESC_BATCH "Enable Batch Mode"
638 
639 #define SANE_NAME_CHECK_ADF "check-adf"
640 #define SANE_TITLE_CHECK_ADF "Check ADF"
641 #define SANE_DESC_CHECK_ADF "Check ADF Status prior to starting scan"
642 
643 #define SANE_NAME_DUPLEX "duplex"
644 #define SANE_TITLE_DUPLEX "Duplex"
645 #define SANE_DESC_DUPLEX "Enable Duplex (Dual-Sided) Scanning"
646 
647 #define SANE_NAME_BARCODE_SEARCH_COUNT "barcode-search-count"
648 #define SANE_TITLE_BARCODE_SEARCH_COUNT "Barcode Search Count"
649 #define SANE_DESC_BARCODE_SEARCH_COUNT "Number of barcodes to search for in the scanned image"
650 
651 #define SANE_NAME_BARCODE_HMIN "barcode-hmin"
652 #define SANE_TITLE_BARCODE_HMIN "Barcode Minimum Height"
653 #define SANE_DESC_BARCODE_HMIN "Sets the Barcode Minimum Height (larger values increase recognition speed)"
654 
655 #define SANE_NAME_BARCODE_SEARCH_MODE "barcode-search-mode"
656 #define SANE_TITLE_BARCODE_SEARCH_MODE "Barcode Search Mode"
657 #define SANE_DESC_BARCODE_SEARCH_MODE "Chooses the orientation of barcodes to be searched"
658 
659 #define SANE_NAME_BARCODE_SEARCH_TIMEOUT "barcode-search-timeout"
660 #define SANE_TITLE_BARCODE_SEARCH_TIMEOUT "Barcode Search Timeout"
661 #define SANE_DESC_BARCODE_SEARCH_TIMEOUT "Sets the timeout for barcode searching"
662 
663 #define SANE_NAME_BARCODE_SEARCH_BAR "barcode-search-bar"
664 #define SANE_TITLE_BARCODE_SEARCH_BAR "Barcode Search Bar"
665 #define SANE_DESC_BARCODE_SEARCH_BAR "Specifies the barcode type to search for"
666 
667 #define SANE_NAME_SECTION "section"
668 #define SANE_TITLE_SECTION "Image/Barcode Search Sections"
669 #define SANE_DESC_SECTION "Specifies an image section and/or a barcode search region"
670 
671 #define SANE_NAME_BARCODE_RELMAX "barcode-relmax"
672 #define SANE_TITLE_BARCODE_RELMAX "Barcode RelMax"
673 #define SANE_DESC_BARCODE_RELMAX "Specifies the maximum relation from the widest to the smallest bar"
674 
675 #define SANE_NAME_BARCODE_BARMIN "barcode-barmin"
676 #define SANE_TITLE_BARCODE_BARMIN "Barcode Bar Minimum"
677 #define SANE_DESC_BARCODE_BARMIN "Specifies the minimum number of bars in Bar/Patch code"
678 
679 #define SANE_NAME_BARCODE_BARMAX "barcode-barmax"
680 #define SANE_TITLE_BARCODE_BARMAX "Barcode Bar Maximum"
681 #define SANE_DESC_BARCODE_BARMAX "Specifies the maximum number of bars in a Bar/Patch code"
682 
683 #define SANE_NAME_BARCODE_CONTRAST "barcode-contrast"
684 #define SANE_TITLE_BARCODE_CONTRAST "Barcode Contrast"
685 #define SANE_DESC_BARCODE_CONTRAST "Specifies the image contrast used in decoding.  Use higher values when " \
686 "there are more white pixels in the code"
687 
688 #define SANE_NAME_BARCODE_PATCHMODE "barcode-patchmode"
689 #define SANE_TITLE_BARCODE_PATCHMODE "Barcode Patch Mode"
690 #define SANE_DESC_BARCODE_PATCHMODE "Controls Patch Code detection."
691 
692 #define SANE_NAME_CONTROL_PANEL "control-panel"
693 #define SANE_TITLE_CONTROL_PANEL "Control Panel "
694 #define SANE_DESC_CONTROL_PANEL "Enables the scanner's control panel"
695 
696 #define SANE_NAME_ACE_FUNCTION "ace-function"
697 #define SANE_TITLE_ACE_FUNCTION "ACE Function"
698 #define SANE_DESC_ACE_FUNCTION "ACE Function"
699 
700 #define SANE_NAME_ACE_SENSITIVITY "ace-sensitivity"
701 #define SANE_TITLE_ACE_SENSITIVITY "ACE Sensitivity"
702 #define SANE_DESC_ACE_SENSITIVITY "ACE Sensitivity"
703 
704 #define SANE_NAME_ICON_WIDTH "icon-width"
705 #define SANE_TITLE_ICON_WIDTH "Icon Width"
706 #define SANE_DESC_ICON_WIDTH "Width of icon (thumbnail) image in pixels"
707 
708 #define SANE_NAME_ICON_LENGTH "icon-length"
709 #define SANE_TITLE_ICON_LENGTH "Icon Length"
710 #define SANE_DESC_ICON_LENGTH "Length of icon (thumbnail) image in pixels"
711 
712 #define SANE_NAME_PAPER_SIZE "paper-size"
713 #define SANE_TITLE_PAPER_SIZE "Paper Size"
714 #define SANE_DESC_PAPER_SIZE "Specify the scan window geometry by specifying the paper size " \
715 "of the documents to be scanned"
716 
717 #define SANE_NAME_INQUIRY "inquiry"
718 #define SANE_TITLE_INQUIRY "Inquiry Data"
719 #define SANE_DESC_INQUIRY "Displays scanner inquiry data"
720 
721 /* low level SCSI commands and buffers */
722 
723 /* SCSI commands */
724 #define BH_SCSI_TEST_UNIT_READY 0x00
725 #define BH_SCSI_SET_WINDOW 0x24
726 #define BH_SCSI_GET_WINDOW 0x25
727 #define BH_SCSI_READ_SCANNED_DATA 0x28
728 #define BH_SCSI_INQUIRY	0x12
729 #define BH_SCSI_MODE_SELECT 0x15
730 #define BH_SCSI_START_SCAN 0x1b
731 #define BH_SCSI_MODE_SENSE 0x1a
732 #define BH_SCSI_GET_BUFFER_STATUS 0x34
733 #define BH_SCSI_OBJECT_POSITION 0x31
734 
735 /* page codes used with BH_SCSI_INQUIRY */
736 #define BH_INQUIRY_STANDARD_PAGE_CODE 0x00
737 #define BH_INQUIRY_VPD_PAGE_CODE 0xC0
738 #define BH_INQUIRY_JIS_PAGE_CODE 0xF0
739 
740 /* page codes used with BH_SCSI_MODE_SELECT and BH_SCSI_MODE_SENSE */
741 #define BH_MODE_MEASUREMENT_PAGE_CODE 0x03
742 #define BH_MODE_TIMEOUT_PAGE_CODE 0x20
743 #define BH_MODE_ICON_PAGE_CODE 0x21
744 #define BH_MODE_BARCODE_PRIORITY_PAGE_CODE 0x30
745 #define BH_MODE_BARCODE_PARAM1_PAGE_CODE 0x31
746 #define BH_MODE_BARCODE_PARAM2_PAGE_CODE 0x32
747 #define BH_MODE_BARCODE_PARAM3_PAGE_CODE 0x32
748 
749 /* data type codes used with BH_SCSI_READ_SCANNED_DATA */
750 #define BH_SCSI_READ_TYPE_FRONT 0x80
751 /* 0x81 thru 0x88 read front page sections 1 thru 8 respectively */
752 #define BH_SCSI_READ_TYPE_BACK 0x90
753 /* 0x91 thru 0x98 read back page sections 1 thru 8 respectively */
754 #define BH_SCSI_READ_TYPE_FRONT_BARCODE 0xA0
755 /* 0xA1 thru 0xA8 read front page barcodes in sections 1 thru 8 respectively */
756 #define BH_SCSI_READ_TYPE_BACK_BARCODE 0xB0
757 /* 0xB1 thru 0xB8 read back page barcodes in sections 1 thru 8 respectively */
758 #define BH_SCSI_READ_TYPE_FRONT_PATCHCODE 0xC0
759 /* 0xC1 thru 0xC8 read front page patchcodes in sections 1 thru 8 respectively */
760 #define BH_SCSI_READ_TYPE_BACK_PATCHCODE 0xD0
761 /* 0xD1 thru 0xD8 read back page patchcodes in sections 1 thru 8 respectively */
762 #define BH_SCSI_READ_TYPE_FRONT_ICON 0x89
763 #define BH_SCSI_READ_TYPE_BACK_ICON 0x99
764 
765 /* this one is not a real readtype; it's used to help transfer the barcode file */
766 #define BH_SCSI_READ_TYPE_SENDBARFILE 0xBB
767 
768 #define BH_HAS_IMAGE_DATA(i) ((i) >= BH_SCSI_READ_TYPE_FRONT && \
769    (i) <= BH_SCSI_READ_TYPE_BACK_ICON)
770 
771 /* batchmode codes used with BH_SCSI_SET_WINDOW */
772 #define BH_BATCH_DISABLE 0x00
773 #define BH_BATCH_ENABLE 0x01
774 #define BH_BATCH_TERMINATE 0x02
775 #define BH_BATCH_ABORT 0x03
776 
777 /* deskew mode codes used with BH_SCSI_SET_WINDOW */
778 #define BH_DESKEW_DISABLE 0x00       /* border detection is assumed, see page 3-37 of 8000 manual */
779 #define BH_DESKEW_ENABLE 0x04        /* deskew and border detection */
780 
781 /* used with BH_SCSI_SET_WINDOW, BH_SCSI_GET_WINDOW */
782 typedef struct _BH_SectionBlock {
783   SANE_Byte ul_x[4];
784   SANE_Byte ul_y[4];
785   SANE_Byte width[4];
786   SANE_Byte length[4];
787   SANE_Byte compressiontype;
788   SANE_Byte compressionarg;
789   SANE_Byte reserved[6];
790 } BH_SectionBlock;
791 
792 /* used with BH_SCSI_SET_WINDOW, BH_SCSI_GET_WINDOW */
793 struct window_data {           /* window descriptor block byte layout */
794   SANE_Byte windowid;          /* 0 */
795   SANE_Byte autoborder;        /* 1 */
796   SANE_Byte xres[2];           /* 2,3 */
797   SANE_Byte yres[2];           /* 4,5 */
798   SANE_Byte ulx[4];            /* 6-9 */
799   SANE_Byte uly[4];            /* 10-13 */
800   SANE_Byte windowwidth[4];    /* 14-17 */
801   SANE_Byte windowlength[4];   /* 18-21 */
802   SANE_Byte brightness;        /* 22 */
803   SANE_Byte threshold;         /* 23 */
804   SANE_Byte contrast;          /* 24 */
805   SANE_Byte imagecomposition;  /* 25 */
806   SANE_Byte bitsperpixel;      /* 26 */
807   SANE_Byte halftonecode;      /* 27 */
808   SANE_Byte halftoneid;        /* 28 */
809   SANE_Byte paddingtype;       /* 29 */
810   SANE_Byte bitordering[2];    /* 30,31 */
811   SANE_Byte compressiontype;   /* 32 */
812   SANE_Byte compressionarg;    /* 33 */
813   SANE_Byte reserved2[6];      /* 34-39 */
814   SANE_Byte remote;            /* 40 */
815   SANE_Byte acefunction;       /* 41 */
816   SANE_Byte acesensitivity;    /* 42 */
817   SANE_Byte batchmode;         /* 43 */
818   SANE_Byte reserved3[2];      /* 44,45 */
819   SANE_Byte border_rotation;   /* 46     added this for copiscan 8080 */
820   SANE_Byte reserved4[17];     /* 47-63  added this for copiscan 8080 */
821   BH_SectionBlock sectionblock[NUM_SECTIONS];
822 };
823 
824 /* used with BH_SCSI_READ_SCANNED_DATA */
825 /* structure for returned decoded barcode data */
826 struct barcode_data {
827   SANE_Byte reserved1[2];
828   SANE_Byte barcodetype[2];
829   SANE_Byte statusflag[2];
830   SANE_Byte barcodeorientation[2];
831   SANE_Byte posxa[2];
832   SANE_Byte posya[2];
833   SANE_Byte posxb[2];
834   SANE_Byte posyb[2];
835   SANE_Byte posxc[2];
836   SANE_Byte posyc[2];
837   SANE_Byte posxd[2];
838   SANE_Byte posyd[2];
839   SANE_Byte barcodesearchtime[2];
840   SANE_Byte reserved2[13];
841   SANE_Byte barcodelen;
842   SANE_Byte barcodedata[160];
843 };
844 
845 /* structure for returned icon data block */
846 struct icon_data {
847   SANE_Byte windowwidth[4];
848   SANE_Byte windowlength[4];
849   SANE_Byte iconwidth[4];
850   SANE_Byte iconwidthbytes[4];
851   SANE_Byte iconlength[4];
852   SANE_Byte bitordering;
853   SANE_Byte reserved[7];
854   SANE_Byte icondatalen[4];
855 };
856 
857 
858 /* used with BH_SCSI_INQUIRY */
859 
860 /* Standard Data [EVPD=0] */
861 struct inquiry_standard_data {
862   SANE_Byte devtype;
863   SANE_Byte reserved[7];
864   SANE_Byte vendor[8];
865   SANE_Byte product[16];
866   SANE_Byte revision[4];
867 };
868 
869 /* VPD Information [EVPD=1, PageCode=C0H] */
870 struct inquiry_vpd_data {
871   SANE_Byte devtype;
872   SANE_Byte pagecode;
873   SANE_Byte reserved1;
874   SANE_Byte alloclen;
875   SANE_Byte adf;
876   SANE_Byte reserved2[2];
877   SANE_Byte imagecomposition;
878   SANE_Byte imagedataprocessing[2];
879   SANE_Byte compression;
880   SANE_Byte reserved3;
881   SANE_Byte sizerecognition;
882   SANE_Byte optionalfeatures;
883   SANE_Byte xmaxoutputbytes[2];
884 };
885 
886 
887 /* JIS Information [EVPD=1, PageCode=F0H] */
888 struct inquiry_jis_data {
889   SANE_Byte devtype;
890   SANE_Byte pagecode;
891   SANE_Byte jisversion;
892   SANE_Byte reserved1;
893   SANE_Byte alloclen;
894   SANE_Byte basicxres[2];
895   SANE_Byte basicyres[2];
896   SANE_Byte resolutionstep;
897   SANE_Byte maxxres[2];
898   SANE_Byte maxyres[2];
899   SANE_Byte minxres[2];
900   SANE_Byte minyres[2];
901   SANE_Byte standardres[2];
902   SANE_Byte windowwidth[4];
903   SANE_Byte windowlength[4];
904   SANE_Byte functions;
905   SANE_Byte reserved2;
906 };
907 
908 /* used with BH_SCSI_MODE_SELECT and BH_SCSI_MODE_SENSE */
909 
910 /* Scanning Measurement Parameters PageCode=03H */
911 struct mode_page_03 {
912   SANE_Byte modedatalen;
913   SANE_Byte mediumtype;
914   SANE_Byte devicespecificparam;
915   SANE_Byte blockdescriptorlen;
916 
917   SANE_Byte pagecode;
918   SANE_Byte paramlen;
919   SANE_Byte bmu;
920   SANE_Byte reserved1;
921   SANE_Byte mud[2];
922   SANE_Byte reserved2[2];
923 };
924 
925 /* Scan Command Timeout PageCode=20H */
926 struct mode_page_20 {
927   SANE_Byte modedatalen;
928   SANE_Byte mediumtype;
929   SANE_Byte devicespecificparam;
930   SANE_Byte blockdescriptorlen;
931 
932   SANE_Byte pagecode;
933   SANE_Byte paramlen;
934   SANE_Byte timeoutmanual;
935   SANE_Byte timeoutadf;
936   SANE_Byte reserved[4];
937 };
938 
939 /* Icon Definition PageCode=21H */
940 struct mode_page_21 {
941   SANE_Byte modedatalen;
942   SANE_Byte mediumtype;
943   SANE_Byte devicespecificparam;
944   SANE_Byte blockdescriptorlen;
945 
946   SANE_Byte pagecode;
947   SANE_Byte paramlen;
948   SANE_Byte iconwidth[2];
949   SANE_Byte iconlength[2];
950   SANE_Byte reserved[2];
951 };
952 
953 /* Bar/Patch Code search priority order PageCode=30H */
954 struct mode_page_30 {
955   SANE_Byte modedatalen;
956   SANE_Byte mediumtype;
957   SANE_Byte devicespecificparam;
958   SANE_Byte blockdescriptorlen;
959 
960   SANE_Byte pagecode;
961   SANE_Byte paramlen;
962   SANE_Byte priority[6];
963 };
964 
965 /* Bar/Patch Code search parameters 1 of 3 PageCode=31H */
966 struct mode_page_31 {
967   SANE_Byte modedatalen;
968   SANE_Byte mediumtype;
969   SANE_Byte devicespecificparam;
970   SANE_Byte blockdescriptorlen;
971 
972   SANE_Byte pagecode;
973   SANE_Byte paramlen;
974   SANE_Byte minbarheight[2];
975   SANE_Byte searchcount;
976   SANE_Byte searchmode;
977   SANE_Byte searchtimeout[2];
978 };
979 
980 /* Bar/Patch Code search parameters 2 of 3 PageCode=32H */
981 struct mode_page_32 {
982   SANE_Byte modedatalen;
983   SANE_Byte mediumtype;
984   SANE_Byte devicespecificparam;
985   SANE_Byte blockdescriptorlen;
986 
987   SANE_Byte pagecode;
988   SANE_Byte paramlen;
989   SANE_Byte relmax[2];
990   SANE_Byte barmin[2];
991   SANE_Byte barmax[2];
992 };
993 
994 /* Bar/Patch Code search parameters 3 of 3 PageCode=33H */
995 struct mode_page_33 {
996   SANE_Byte modedatalen;
997   SANE_Byte mediumtype;
998   SANE_Byte devicespecificparam;
999   SANE_Byte blockdescriptorlen;
1000 
1001   SANE_Byte pagecode;
1002   SANE_Byte paramlen;
1003   SANE_Byte barcodecontrast[2];
1004   SANE_Byte patchmode[2];
1005   SANE_Byte reserved[2];
1006 };
1007 
1008 #ifndef sane_isbasicframe
1009 #define SANE_FRAME_TEXT 10
1010 #define SANE_FRAME_JPEG 11
1011 #define SANE_FRAME_G31D 12
1012 #define SANE_FRAME_G32D 13
1013 #define SANE_FRAME_G42D 14
1014 #define sane_strframe(f) ( (f) == SANE_FRAME_GRAY ? "gray" : \
1015   (f) == SANE_FRAME_RGB ? "RGB" : \
1016   (f) == SANE_FRAME_RED ? "red" : \
1017   (f) == SANE_FRAME_GREEN ? "green" : \
1018   (f) == SANE_FRAME_BLUE ? "blue" : \
1019   (f) == SANE_FRAME_TEXT ? "text" : \
1020   (f) == SANE_FRAME_JPEG ? "jpeg" : \
1021   (f) == SANE_FRAME_G31D ? "g31d" : \
1022   (f) == SANE_FRAME_G32D ? "g32d" : \
1023   (f) == SANE_FRAME_G42D ? "g42d" : \
1024   "unknown" )
1025 
1026 #define sane_isbasicframe(f) ( (f) == SANE_FRAME_GRAY || \
1027   (f) == SANE_FRAME_RGB || \
1028   (f) == SANE_FRAME_RED || \
1029   (f) == SANE_FRAME_GREEN || \
1030   (f) == SANE_FRAME_BLUE )
1031 
1032 #endif
1033 
1034 #endif /* BH_H */
1035