summaryrefslogtreecommitdiff
path: root/backend/bh.h
blob: 62115c63a2abc16450705f1dd3a9ab1535a6b181 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
/* sane - Scanner Access Now Easy.
   Copyright (C) 1999,2000 Tom Martone
   This file is part of a SANE backend for Bell and Howell Copiscan II
   Scanners using the Remote SCSI Controller(RSC).

   This file is part of the SANE package.

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston,
   MA 02111-1307, USA.

   As a special exception, the authors of SANE give permission for
   additional uses of the libraries contained in this release of SANE.

   The exception is that, if you link a SANE library with other files
   to produce an executable, this does not by itself cause the
   resulting executable to be covered by the GNU General Public
   License.  Your use of that executable is in no way restricted on
   account of linking the SANE library code into it.

   This exception does not, however, invalidate any other reasons why
   the executable file might be covered by the GNU General Public
   License.

   If you submit changes to SANE to the maintainers to be included in
   a subsequent release, you agree by submitting the changes that
   those changes may be distributed with this exception intact.

   If you write modifications of your own for SANE, it is your choice
   whether to permit this exception to apply to your modifications.
   If you do not wish that, delete this exception notice.  */

#ifndef BH_H
#define BH_H 1

#ifndef PATH_MAX
#define PATH_MAX (1024)
#endif

#define BH_CONFIG_FILE "bh.conf"

/* number of barcode types that can be searched at one time */
#define NUM_SEARCH_BARS 6
/* number of additional scanning/decoding sections supported */
#define NUM_SECTIONS 8
/* number of possible reads per scan plus the extra one for
 * the barcode file
 */
#define NUM_READS 56 + 1

/* specify sanity limits for autoborder detection and barcode decoding */
#define BH_AUTOBORDER_TRIES 100
#define BH_DECODE_TRIES 100
/* specify a fudge factor in mm for border around decoded barcodes */
#define BH_DECODE_FUDGE 1.0

/* section flags - what operation(s) to perform on section */
#define BH_SECTION_FRONT_IMAGE (1 << 0)
#define BH_SECTION_BACK_IMAGE (1 << 1)
#define BH_SECTION_FRONT_BAR (1 << 2)
#define BH_SECTION_BACK_BAR (1 << 3)
#define BH_SECTION_FRONT_PATCH (1 << 4)
#define BH_SECTION_BACK_PATCH (1 << 5)

typedef enum 
{ 
  BH_UNIT_INCH, 
  BH_UNIT_MM, 
  BH_UNIT_POINT
} bh_measureUnit;

typedef enum
{
  BH_COMP_NONE, 
  BH_COMP_G31D,
  BH_COMP_G32D,
  BH_COMP_G42D
} bh_compress;

typedef enum
{
  BH_ROTATION_0, 
  BH_ROTATION_90,
  BH_ROTATION_180,
  BH_ROTATION_270
} bh_rotation;

typedef enum 
{
  OPT_NUM_OPTS = 0,

  OPT_MODE_GROUP,
  /* inquiry string */
  OPT_INQUIRY,
  /* preview mode */
  OPT_PREVIEW,
  /* scan mode */
  OPT_SCAN_MODE,
  /* resolution */
  OPT_RESOLUTION,
  /* hardware compression */
  OPT_COMPRESSION,

  OPT_GEOMETRY_GROUP,
  /* automatic border detection */
  OPT_AUTOBORDER,
  /* hardware rotation */
  OPT_ROTATION,
  /* hardware deskew */
  OPT_DESKEW,
  /* paper size */
  OPT_PAPER_SIZE,
  /* top-left x */
  OPT_TL_X,
  /* top-left y */
  OPT_TL_Y,
  /* bottom-right x */
  OPT_BR_X,
  /* bottom-right y */
  OPT_BR_Y,

  OPT_FEEDER_GROUP,
  /* scan source (eg. ADF) */
  OPT_SCAN_SOURCE,
  /* scan in batch mode */
  OPT_BATCH,
  /* scan both sides of the page */
  OPT_DUPLEX,
  /* timeout in seconds with manual feed */
  OPT_TIMEOUT_MANUAL,
  /* timeout in seconds with ADF */
  OPT_TIMEOUT_ADF,
  /* check for page in ADF before scanning */
  OPT_CHECK_ADF,

  OPT_ENHANCEMENT_GROUP,
  /* Enables the scanner's control panel */
  OPT_CONTROL_PANEL,
  /* ACE Function */
  OPT_ACE_FUNCTION,
  /* ACE Sensitivity */
  OPT_ACE_SENSITIVITY,
  /* Brightness */
  OPT_BRIGHTNESS,
  /* Threshold */
  OPT_THRESHOLD,
  /* Contrast */
  OPT_CONTRAST,
  /* Negative (reverse image) */
  OPT_NEGATIVE,

  OPT_ICON_GROUP,
  /* Width of icon (thumbnail) image in pixels */
  OPT_ICON_WIDTH,
  /* Length of icon (thumbnail) image in pixels */
  OPT_ICON_LENGTH,

  OPT_BARCODE_GROUP,
  /* Add <name> to barcode search priority. */
  OPT_BARCODE_SEARCH_BAR,
  /* Barcode search count (1-7, default 3). */
  OPT_BARCODE_SEARCH_COUNT,
  /* Barcode search mode. 
   * (1 = horizontal,2 = vertical, 6 = v then h, 9 = h then v). 
   */
  OPT_BARCODE_SEARCH_MODE,
  /* Patch code min height (def=127 (5mm)) */
  OPT_BARCODE_HMIN,       
  /* Barcode search timeout in ms 
   * (20-65535,default is disabled). 
   */
  OPT_BARCODE_SEARCH_TIMEOUT,
  /* Specify image sections and functions
   */
  OPT_SECTION,
  /* Specifies the maximum relation from the widest to 
   * the smallest bar 
   */
  OPT_BARCODE_RELMAX,
  /* Specifies the minimum number of bars in Bar/Patch code */
  OPT_BARCODE_BARMIN,
  /* Specifies the maximum number of bars in a Bar/Patch code */
  OPT_BARCODE_BARMAX,
  /* Specifies the image contrast used in decoding.  
   * Use higher values when there are more white pixels 
   * in the code 
   */
  OPT_BARCODE_CONTRAST,
  /* Controls Patch Code detection. */
  OPT_BARCODE_PATCHMODE,

  /* must come last: */
  NUM_OPTIONS

} BH_Option;

/* macros for accessing the value for an option within a scanning context */
#define _OPT_VAL_WORD(s, o) ((s)->val[(o)].w)
#define _OPT_VAL_WORD_THOUSANDTHS(s, o) \
    (SANE_UNFIX(_OPT_VAL_WORD((s), (o))) * 1000.0 / MM_PER_INCH)
#define _OPT_VAL_STRING(s, o) ((s)->val[(o)].s)
#define _OPT_VAL_WORD_ARRAY(s, o) ((s)->val[(o)].wa)


typedef struct _BH_Paper
{
  SANE_String name;

  /* paper dimensions in mm */
  double width, length;
} BH_Paper;

typedef struct _BH_Section
{
  /* section dimensions - in millimeters */
  u_long top, left, width, length;

  /* compression type/arg/frameformat */
  SANE_Byte compressiontype;
  SANE_Byte compressionarg;
  SANE_Frame format;

  /* Flags (see BH_SECTION_...) indicating operation(s) to perform
   * on the section.  If zero, the section is completely disabled
   * and will not even be defined in set_window.
   */
  SANE_Word flags;

} BH_Section;

typedef struct _BH_Info
{
  SANE_Range x_range;
  SANE_Range y_range;

  SANE_Int res_default;
  SANE_Bool autoborder_default;
  SANE_Bool batch_default;
  SANE_Bool deskew_default;
  SANE_Bool check_adf_default;
  SANE_Bool duplex_default;
  SANE_Int timeout_adf_default;
  SANE_Int timeout_manual_default;
  SANE_Bool control_panel_default;

  /* additional discovered/guessed capabilities */
  SANE_Bool canACE;
  SANE_Bool canDuplex;
  SANE_Bool canCheckADF;

  /* standard information */
  SANE_Byte devtype;
  SANE_Char vendor[9];	/* model name */
  SANE_Char product[17];	/* product name */
  SANE_Char revision[5];	/* revision */

  /* VPD information */
  SANE_Bool canADF;		/* is there an ADF available */
  SANE_Bool colorBandW;	/* can scanner do black and white */
  SANE_Bool colorHalftone;	/* can scanner do Halftone */
  SANE_Bool canWhiteFrame;	/* data processing: White Framing */
  SANE_Bool canBlackFrame;	/* data processing: Black Framing */
  SANE_Bool canEdgeExtract;	/* data processing: ACE: Edge Extraction */
  SANE_Bool canNoiseFilter;	/* data processing: ACE: Noise Filtering */
  SANE_Bool canSmooth;	/* data processing: ACE: Smoothing */
  SANE_Bool canLineBold;	/* data processing: ACE: LineBolding */
  SANE_Bool comprG3_1D;	/* compression: Group 3, 1 dimensional */
  SANE_Bool comprG3_2D;	/* compression: Group 3, 2 dimensional */
  SANE_Bool comprG4;		/* compression: Group 4 */
  SANE_Bool canBorderRecog;	/* can do border recognition */
  SANE_Bool canBarCode;	/* bar code support available */
  SANE_Bool canIcon;		/* icon support available */
  SANE_Bool canSection;	/* section support available */
  SANE_Int lineMaxBytes;	/* maximum bytes per scan-line */

  /* jis information */
  SANE_Int resBasicX;		/* basic X resolution */
  SANE_Int resBasicY;		/* basic Y resolution */
  SANE_Int resMaxX;		/* maximum X resolution */
  SANE_Int resMaxY;		/* maximum Y resolution */
  SANE_Int resMinX;		/* minimum X resolution */
  SANE_Int resMinY;		/* minimum Y resolution */
  SANE_Int resStdList[16+1];    /* list of available standard resolutions 
				 * (first slot is the length) 
				 */
  SANE_Int winWidth;		/* length of window (in BasicX res DPI) */
  SANE_Int winHeight;		/* height of window (in BasicY res DPI) */
} BH_Info;

typedef struct _BH_Device BH_Device;

struct _BH_Device
{
  BH_Device *next;
  SANE_Device sane;
  BH_Info info;
};


typedef struct _BH_Scanner BH_Scanner;
struct _BH_Scanner
{
  /* all the state needed to define a scan request: */

  /* linked list for housekeeping */
  BH_Scanner *next;

  /* scanner dependent/low-level state: */
  BH_Device *hw;

  /* SCSI filedescriptor */
  int fd;
  
  /* tempfile which is used to send decoded barcode data */
  FILE *barf;
  char barfname[PATH_MAX+1];

  /* SANE option descriptors and values */
  SANE_Option_Descriptor opt[NUM_OPTIONS];
  Option_Value val[NUM_OPTIONS];

  /* additional values that don't fit into Option_Value representation */
  SANE_Byte search_bars[NUM_SEARCH_BARS];
  BH_Section sections[NUM_SECTIONS];
  SANE_Int num_sections;

  /* SANE image parameters */
  SANE_Parameters params;
  
  /* state information - not options */

  /* Basic Measurement Unit */
  SANE_Int bmu;
  /* Measurement Unit Divisor */
  SANE_Int mud;

  /* track data to be read.  ReadList contains the codes of the read types
   * (see BH_READ_TYPE...) to perform, readcnt is the total number of reads
   * for this scan and readptr points to the current read operation.
   */
  SANE_Byte readlist[NUM_READS];
  SANE_Int readcnt, readptr;

  u_long InvalidBytes;
  SANE_Bool scanning;
  SANE_Bool cancelled;
  SANE_Bool backpage;
  SANE_Bool barcodes;
  SANE_Bool patchcodes;
  SANE_Bool icons;
  u_long iconwidth, iconlength;
  SANE_Bool barcode_not_found;
};

static const SANE_Range u8_range =
{
    0,		/* minimum */
    255,	/* maximum */
    0		/* quantization */
};

static const SANE_Range u16_range =
{
    0,		/* minimum */
    65535, 	/* maximum */
    0		/* quantization */
};

static const SANE_Range icon_range =
{
    0,		/* minimum */
    3600, 	/* maximum */
    8		/* quantization */
};

static const SANE_Range barcode_search_timeout_range =
{
    20,		/* minimum */
    65535, 	/* maximum */
    0		/* quantization */
};

static const SANE_Range barcode_hmin_range =
{
    1,		/* minimum */
    1660, 	/* maximum (when converted from mm 
		 * to thousandths will still be less 
		 * than 65536) 
		 */
    0		/* quantization */
};

static const SANE_Range barcode_search_count_range =
{
    1,		/* minimum */
    7,  	/* maximum */
    0		/* quantization */
};

static const SANE_Range barcode_relmax_range =
{
    0,		/* minimum */
    6,  	/* maximum */
    0		/* quantization */
};

static const SANE_Range barcode_contrast_range =
{
    0,		/* minimum */
    6,  	/* maximum */
    0		/* quantization */
};

static const SANE_Range barcode_patchmode_range =
{
    0,		/* minimum */
    1,  	/* maximum */
    0		/* quantization */
};

static const SANE_Range ace_function_range =
{
    -4,		/* minimum */
    4,  	/* maximum */
    0		/* quantization */
};

static const SANE_Range ace_sensitivity_range =
{
    0,		/* minimum */
    9,  	/* maximum */
    0		/* quantization */
};

static SANE_String_Const scan_mode_list[] =
{
  "lineart",
  "halftone",
  0
};

static SANE_String_Const scan_mode_min_list[] =
{
  "lineart",
  0
};

static SANE_String_Const barcode_search_mode_list[] =
{
  "horiz-vert", /* 9 */
  "horizontal", /* 1 */
  "vertical",   /* 2 */
  "vert-horiz", /* 6 */
  0
};

static SANE_String_Const scan_source_list[] =
{
  "Automatic Document Feeder",
  "Manual Feed Tray",
  0
};

static SANE_String_Const compression_list[] =
{
  "none",
  "g31d",
  "g32d",
  "g42d",
  0
};

/* list of supported bar/patch codes */
static SANE_String_Const barcode_search_bar_list[] =
{
  "none",
  "ean-8",
  "ean-13",
  "reserved-ean-add",
  "code39",
  "code2-5-interleaved",
  "code2-5-3lines-matrix",
  "code2-5-3lines-datalogic",
  "code2-5-5lines-industrial",
  "patchcode",
  "codabar",
  "codabar-with-start-stop",
  "code39ascii",
  "code128",
  "code2-5-5lines-iata",
  0
};

/* list of supported rotation angles */
static SANE_String_Const rotation_list[] =
{
  "0",
  "90",
  "180",
  "270",
  0
};

/* list of support paper sizes */
/* 'custom' MUST be item 0; otherwise a width or length of 0 indicates
 * the maximum value supported by the scanner
 */
static const BH_Paper paper_sizes[] =
{
  {"Custom", 0.0, 0.0},
  {"Letter", 215.9, 279.4},
  {"Legal", 215.9, 355.6},
  {"A3", 297, 420},
  {"A4", 210, 297},
  {"A5", 148.5, 210},
  {"A6", 105, 148.5},
  {"B4", 250, 353},
  {"B5", 182, 257},
  {"Full", 0.0, 0.0},
};

/* MUST be kept in sync with paper_sizes */
static SANE_String_Const paper_list[] =
{
  "Custom",
  "Letter",
  "Legal",
  "A3",
  "A4",
  "A5",
  "A6",
  "B4",
  "B5",
  "Full",
  0
};

static /* inline */ int _is_host_little_endian(void);
static /* inline */ int
_is_host_little_endian()
{
  SANE_Int val = 255;
  unsigned char *firstbyte = (unsigned char *) &val;

  return (*firstbyte == 255) ? SANE_TRUE : SANE_FALSE;
}

static /* inline */ void
_lto2b(u_long val, SANE_Byte *bytes)
{
  bytes[0] = (val >> 8) & 0xff;
  bytes[1] = val & 0xff;
}

static /* inline */ void
_lto3b(u_long val, SANE_Byte *bytes)
{
  bytes[0] = (val >> 16) & 0xff;
  bytes[1] = (val >> 8) & 0xff;
  bytes[2] = val & 0xff;
}

static /* inline */ void
_lto4b(u_long val, SANE_Byte *bytes)
{
  bytes[0] = (val >> 24) & 0xff;
  bytes[1] = (val >> 16) & 0xff;
  bytes[2] = (val >> 8) & 0xff;
  bytes[3] = val & 0xff;
}

static /* inline */ u_long
_2btol(SANE_Byte *bytes)
{
  u_long rv;

  rv = (bytes[0] << 8) | bytes[1];

  return rv;
}

static /* inline */ u_long
_4btol(SANE_Byte *bytes)
{
  u_long rv;

  rv = (bytes[0] << 24) |
    (bytes[1] << 16) |
    (bytes[2] << 8) |
    bytes[3];

  return rv;
}

#define SANE_TITLE_SCAN_MODE_GROUP "Scan Mode"
#define SANE_TITLE_GEOMETRY_GROUP "Geometry"
#define SANE_TITLE_FEEDER_GROUP "Feeder"
#define SANE_TITLE_ENHANCEMENT_GROUP "Enhancement"
#define SANE_TITLE_ICON_GROUP "Icon"
#define SANE_TITLE_BARCODE_GROUP "Barcode"

#define SANE_NAME_AUTOBORDER "autoborder"
#define SANE_TITLE_AUTOBORDER "Autoborder"
#define SANE_DESC_AUTOBORDER "Enable Automatic Border Detection"

#define SANE_NAME_COMPRESSION "compression"
#define SANE_TITLE_COMPRESSION "Data Compression"
#define SANE_DESC_COMPRESSION "Sets the compression mode of the scanner"

#define SANE_NAME_ROTATION "rotation"
#define SANE_TITLE_ROTATION "Page Rotation"
#define SANE_DESC_ROTATION "Sets the page rotation mode of the scanner"

#define SANE_NAME_DESKEW "deskew"
#define SANE_TITLE_DESKEW "Page Deskew"
#define SANE_DESC_DESKEW "Enable Deskew Mode"

#define SANE_NAME_TIMEOUT_ADF "timeout-adf"
#define SANE_TITLE_TIMEOUT_ADF "ADF Timeout"
#define SANE_DESC_TIMEOUT_ADF "Sets the timeout in seconds for the ADF"

#define SANE_NAME_TIMEOUT_MANUAL "timeout-manual"
#define SANE_TITLE_TIMEOUT_MANUAL "Manual Timeout"
#define SANE_DESC_TIMEOUT_MANUAL "Sets the timeout in seconds for manual feeder"

#define SANE_NAME_BATCH "batch"
#define SANE_TITLE_BATCH "Batch"
#define SANE_DESC_BATCH "Enable Batch Mode"

#define SANE_NAME_CHECK_ADF "check-adf"
#define SANE_TITLE_CHECK_ADF "Check ADF"
#define SANE_DESC_CHECK_ADF "Check ADF Status prior to starting scan"

#define SANE_NAME_DUPLEX "duplex"
#define SANE_TITLE_DUPLEX "Duplex"
#define SANE_DESC_DUPLEX "Enable Duplex (Dual-Sided) Scanning"

#define SANE_NAME_BARCODE_SEARCH_COUNT "barcode-search-count"
#define SANE_TITLE_BARCODE_SEARCH_COUNT "Barcode Search Count"
#define SANE_DESC_BARCODE_SEARCH_COUNT "Number of barcodes to search for in the scanned image"

#define SANE_NAME_BARCODE_HMIN "barcode-hmin"
#define SANE_TITLE_BARCODE_HMIN "Barcode Minimum Height"
#define SANE_DESC_BARCODE_HMIN "Sets the Barcode Minimun Height (larger values increase recognition speed)"

#define SANE_NAME_BARCODE_SEARCH_MODE "barcode-search-mode"
#define SANE_TITLE_BARCODE_SEARCH_MODE "Barcode Search Mode"
#define SANE_DESC_BARCODE_SEARCH_MODE "Chooses the orientation of barcodes to be searched"

#define SANE_NAME_BARCODE_SEARCH_TIMEOUT "barcode-search-timeout"
#define SANE_TITLE_BARCODE_SEARCH_TIMEOUT "Barcode Search Timeout"
#define SANE_DESC_BARCODE_SEARCH_TIMEOUT "Sets the timeout for barcode searching"

#define SANE_NAME_BARCODE_SEARCH_BAR "barcode-search-bar"
#define SANE_TITLE_BARCODE_SEARCH_BAR "Barcode Search Bar"
#define SANE_DESC_BARCODE_SEARCH_BAR "Specifies the barcode type to search for"

#define SANE_NAME_SECTION "section"
#define SANE_TITLE_SECTION "Image/Barcode Search Sections"
#define SANE_DESC_SECTION "Specifies an image section and/or a barcode search region"

#define SANE_NAME_BARCODE_RELMAX "barcode-relmax"
#define SANE_TITLE_BARCODE_RELMAX "Barcode RelMax"
#define SANE_DESC_BARCODE_RELMAX "Specifies the maximum relation from the widest to the smallest bar"

#define SANE_NAME_BARCODE_BARMIN "barcode-barmin"
#define SANE_TITLE_BARCODE_BARMIN "Barcode Bar Minimum"
#define SANE_DESC_BARCODE_BARMIN "Specifies the minimum number of bars in Bar/Patch code"

#define SANE_NAME_BARCODE_BARMAX "barcode-barmax"
#define SANE_TITLE_BARCODE_BARMAX "Barcode Bar Maximum"
#define SANE_DESC_BARCODE_BARMAX "Specifies the maximum number of bars in a Bar/Patch code"

#define SANE_NAME_BARCODE_CONTRAST "barcode-contrast"
#define SANE_TITLE_BARCODE_CONTRAST "Barcode Contrast"
#define SANE_DESC_BARCODE_CONTRAST "Specifies the image contrast used in decoding.  Use higher values when " \
"there are more white pixels in the code"

#define SANE_NAME_BARCODE_PATCHMODE "barcode-patchmode"
#define SANE_TITLE_BARCODE_PATCHMODE "Barcode Patch Mode"
#define SANE_DESC_BARCODE_PATCHMODE "Controls Patch Code detection."

#define SANE_NAME_CONTROL_PANEL "control-panel"
#define SANE_TITLE_CONTROL_PANEL "Control Panel "
#define SANE_DESC_CONTROL_PANEL "Enables the scanner's control panel"

#define SANE_NAME_ACE_FUNCTION "ace-function"
#define SANE_TITLE_ACE_FUNCTION "ACE Function"
#define SANE_DESC_ACE_FUNCTION "ACE Function"

#define SANE_NAME_ACE_SENSITIVITY "ace-sensitivity"
#define SANE_TITLE_ACE_SENSITIVITY "ACE Sensitivity"
#define SANE_DESC_ACE_SENSITIVITY "ACE Sensitivity"

#define SANE_NAME_ICON_WIDTH "icon-width"
#define SANE_TITLE_ICON_WIDTH "Icon Width"
#define SANE_DESC_ICON_WIDTH "Width of icon (thumbnail) image in pixels"

#define SANE_NAME_ICON_LENGTH "icon-length"
#define SANE_TITLE_ICON_LENGTH "Icon Length"
#define SANE_DESC_ICON_LENGTH "Length of icon (thumbnail) image in pixels"

#define SANE_NAME_PAPER_SIZE "paper-size"
#define SANE_TITLE_PAPER_SIZE "Paper Size"
#define SANE_DESC_PAPER_SIZE "Specify the scan window geometry by specifying the paper size " \
"of the documents to be scanned"

#define SANE_NAME_INQUIRY "inquiry"
#define SANE_TITLE_INQUIRY "Inquiry Data"
#define SANE_DESC_INQUIRY "Displays scanner inquiry data"

/* low level SCSI commands and buffers */

/* SCSI commands */
#define BH_SCSI_TEST_UNIT_READY 0x00
#define BH_SCSI_SET_WINDOW 0x24
#define BH_SCSI_GET_WINDOW 0x25
#define BH_SCSI_READ_SCANNED_DATA 0x28
#define BH_SCSI_INQUIRY	0x12
#define BH_SCSI_MODE_SELECT 0x15
#define BH_SCSI_START_SCAN 0x1b
#define BH_SCSI_MODE_SENSE 0x1a
#define BH_SCSI_GET_BUFFER_STATUS 0x34
#define BH_SCSI_OBJECT_POSITION 0x31

/* page codes used with BH_SCSI_INQUIRY */
#define BH_INQUIRY_STANDARD_PAGE_CODE 0x00
#define BH_INQUIRY_VPD_PAGE_CODE 0xC0
#define BH_INQUIRY_JIS_PAGE_CODE 0xF0

/* page codes used with BH_SCSI_MODE_SELECT and BH_SCSI_MODE_SENSE */
#define BH_MODE_MEASUREMENT_PAGE_CODE 0x03
#define BH_MODE_TIMEOUT_PAGE_CODE 0x20
#define BH_MODE_ICON_PAGE_CODE 0x21
#define BH_MODE_BARCODE_PRIORITY_PAGE_CODE 0x30
#define BH_MODE_BARCODE_PARAM1_PAGE_CODE 0x31
#define BH_MODE_BARCODE_PARAM2_PAGE_CODE 0x32
#define BH_MODE_BARCODE_PARAM3_PAGE_CODE 0x32

/* data type codes used with BH_SCSI_READ_SCANNED_DATA */
#define BH_SCSI_READ_TYPE_FRONT 0x80
/* 0x81 thru 0x88 read front page sections 1 thru 8 respectively */
#define BH_SCSI_READ_TYPE_BACK 0x90
/* 0x91 thru 0x98 read back page sections 1 thru 8 respectively */
#define BH_SCSI_READ_TYPE_FRONT_BARCODE 0xA0
/* 0xA1 thru 0xA8 read front page barcodes in sections 1 thru 8 respectively */
#define BH_SCSI_READ_TYPE_BACK_BARCODE 0xB0
/* 0xB1 thru 0xB8 read back page barcodes in sections 1 thru 8 respectively */
#define BH_SCSI_READ_TYPE_FRONT_PATCHCODE 0xC0
/* 0xC1 thru 0xC8 read front page patchcodes in sections 1 thru 8 respectively */
#define BH_SCSI_READ_TYPE_BACK_PATCHCODE 0xD0
/* 0xD1 thru 0xD8 read back page patchcodes in sections 1 thru 8 respectively */
#define BH_SCSI_READ_TYPE_FRONT_ICON 0x89
#define BH_SCSI_READ_TYPE_BACK_ICON 0x99

/* this one is not a real readtype; it's used to help transfer the barcode file */
#define BH_SCSI_READ_TYPE_SENDBARFILE 0xBB

#define BH_HAS_IMAGE_DATA(i) ((i) >= BH_SCSI_READ_TYPE_FRONT && \
   (i) <= BH_SCSI_READ_TYPE_BACK_ICON)

/* batchmode codes used with BH_SCSI_SET_WINDOW */
#define BH_BATCH_DISABLE 0x00
#define BH_BATCH_ENABLE 0x01
#define BH_BATCH_TERMINATE 0x02
#define BH_BATCH_ABORT 0x03

/* deskew mode codes used with BH_SCSI_SET_WINDOW */
#define BH_DESKEW_DISABLE 0x00       /* border detection is assumed, see page 3-37 of 8000 manual */
#define BH_DESKEW_ENABLE 0x04        /* deskew and border detection */

/* used with BH_SCSI_SET_WINDOW, BH_SCSI_GET_WINDOW */
typedef struct _BH_SectionBlock {
  SANE_Byte ul_x[4];
  SANE_Byte ul_y[4];
  SANE_Byte width[4];
  SANE_Byte length[4];
  SANE_Byte compressiontype;
  SANE_Byte compressionarg;
  SANE_Byte reserved[6];
} BH_SectionBlock;

/* used with BH_SCSI_SET_WINDOW, BH_SCSI_GET_WINDOW */
struct window_data {           /* window descriptor block byte layout */
  SANE_Byte windowid;          /* 0 */
  SANE_Byte autoborder;        /* 1 */
  SANE_Byte xres[2];           /* 2,3 */
  SANE_Byte yres[2];           /* 4,5 */
  SANE_Byte ulx[4];            /* 6-9 */
  SANE_Byte uly[4];            /* 10-13 */
  SANE_Byte windowwidth[4];    /* 14-17 */
  SANE_Byte windowlength[4];   /* 18-21 */
  SANE_Byte brightness;        /* 22 */
  SANE_Byte threshold;         /* 23 */
  SANE_Byte contrast;          /* 24 */
  SANE_Byte imagecomposition;  /* 25 */
  SANE_Byte bitsperpixel;      /* 26 */
  SANE_Byte halftonecode;      /* 27 */
  SANE_Byte halftoneid;        /* 28 */
  SANE_Byte paddingtype;       /* 29 */
  SANE_Byte bitordering[2];    /* 30,31 */
  SANE_Byte compressiontype;   /* 32 */
  SANE_Byte compressionarg;    /* 33 */
  SANE_Byte reserved2[6];      /* 34-39 */
  SANE_Byte remote;            /* 40 */
  SANE_Byte acefunction;       /* 41 */
  SANE_Byte acesensitivity;    /* 42 */
  SANE_Byte batchmode;         /* 43 */
  SANE_Byte reserved3[2];      /* 44,45 */
  SANE_Byte border_rotation;   /* 46     added this for copiscan 8080 */
  SANE_Byte reserved4[17];     /* 47-63  added this for copiscan 8080 */
  BH_SectionBlock sectionblock[NUM_SECTIONS];
};

/* used with BH_SCSI_READ_SCANNED_DATA */
/* structure for returned decoded barcode data */
struct barcode_data {
  SANE_Byte reserved1[2];
  SANE_Byte barcodetype[2];
  SANE_Byte statusflag[2];
  SANE_Byte barcodeorientation[2];
  SANE_Byte posxa[2];
  SANE_Byte posya[2];
  SANE_Byte posxb[2];
  SANE_Byte posyb[2];
  SANE_Byte posxc[2];
  SANE_Byte posyc[2];
  SANE_Byte posxd[2];
  SANE_Byte posyd[2];
  SANE_Byte barcodesearchtime[2];
  SANE_Byte reserved2[13];
  SANE_Byte barcodelen;
  SANE_Byte barcodedata[160];
};

/* structure for returned icon data block */
struct icon_data {
  SANE_Byte windowwidth[4];
  SANE_Byte windowlength[4];
  SANE_Byte iconwidth[4];
  SANE_Byte iconwidthbytes[4];
  SANE_Byte iconlength[4];
  SANE_Byte bitordering;
  SANE_Byte reserved[7];
  SANE_Byte icondatalen[4];
};


/* used with BH_SCSI_INQUIRY */

/* Standard Data [EVPD=0] */
struct inquiry_standard_data {
  SANE_Byte devtype;
  SANE_Byte reserved[7];
  SANE_Byte vendor[8];
  SANE_Byte product[16];
  SANE_Byte revision[4];
};

/* VPD Information [EVPD=1, PageCode=C0H] */
struct inquiry_vpd_data {
  SANE_Byte devtype;
  SANE_Byte pagecode;
  SANE_Byte reserved1;
  SANE_Byte alloclen;
  SANE_Byte adf;
  SANE_Byte reserved2[2];
  SANE_Byte imagecomposition;
  SANE_Byte imagedataprocessing[2];
  SANE_Byte compression;
  SANE_Byte reserved3;
  SANE_Byte sizerecognition;
  SANE_Byte optionalfeatures;
  SANE_Byte xmaxoutputbytes[2];
};


/* JIS Information [EVPD=1, PageCode=F0H] */
struct inquiry_jis_data {
  SANE_Byte devtype;
  SANE_Byte pagecode;
  SANE_Byte jisversion;
  SANE_Byte reserved1;
  SANE_Byte alloclen;
  SANE_Byte basicxres[2];
  SANE_Byte basicyres[2];
  SANE_Byte resolutionstep;
  SANE_Byte maxxres[2];
  SANE_Byte maxyres[2];
  SANE_Byte minxres[2];
  SANE_Byte minyres[2];
  SANE_Byte standardres[2];
  SANE_Byte windowwidth[4];
  SANE_Byte windowlength[4];
  SANE_Byte functions;
  SANE_Byte reserved2;
};

/* used with BH_SCSI_MODE_SELECT and BH_SCSI_MODE_SENSE */

/* Scanning Measurement Parameters PageCode=03H */
struct mode_page_03 {
  SANE_Byte modedatalen;
  SANE_Byte mediumtype;
  SANE_Byte devicespecificparam;
  SANE_Byte blockdescriptorlen;
  
  SANE_Byte pagecode;
  SANE_Byte paramlen;
  SANE_Byte bmu;
  SANE_Byte reserved1;
  SANE_Byte mud[2];
  SANE_Byte reserved2[2];
};

/* Scan Command Timeout PageCode=20H */
struct mode_page_20 {
  SANE_Byte modedatalen;
  SANE_Byte mediumtype;
  SANE_Byte devicespecificparam;
  SANE_Byte blockdescriptorlen;

  SANE_Byte pagecode;
  SANE_Byte paramlen;
  SANE_Byte timeoutmanual;
  SANE_Byte timeoutadf;
  SANE_Byte reserved[4];
};

/* Icon Definition PageCode=21H */
struct mode_page_21 {
  SANE_Byte modedatalen;
  SANE_Byte mediumtype;
  SANE_Byte devicespecificparam;
  SANE_Byte blockdescriptorlen;

  SANE_Byte pagecode;
  SANE_Byte paramlen;
  SANE_Byte iconwidth[2];
  SANE_Byte iconlength[2];
  SANE_Byte reserved[2];
};

/* Bar/Patch Code search priority order PageCode=30H */
struct mode_page_30 {
  SANE_Byte modedatalen;
  SANE_Byte mediumtype;
  SANE_Byte devicespecificparam;
  SANE_Byte blockdescriptorlen;

  SANE_Byte pagecode;
  SANE_Byte paramlen;
  SANE_Byte priority[6];
};

/* Bar/Patch Code search parameters 1 of 3 PageCode=31H */
struct mode_page_31 {
  SANE_Byte modedatalen;
  SANE_Byte mediumtype;
  SANE_Byte devicespecificparam;
  SANE_Byte blockdescriptorlen;

  SANE_Byte pagecode;
  SANE_Byte paramlen;
  SANE_Byte minbarheight[2];
  SANE_Byte searchcount;
  SANE_Byte searchmode;
  SANE_Byte searchtimeout[2];
};

/* Bar/Patch Code search parameters 2 of 3 PageCode=32H */
struct mode_page_32 {
  SANE_Byte modedatalen;
  SANE_Byte mediumtype;
  SANE_Byte devicespecificparam;
  SANE_Byte blockdescriptorlen;

  SANE_Byte pagecode;
  SANE_Byte paramlen;
  SANE_Byte relmax[2];
  SANE_Byte barmin[2];
  SANE_Byte barmax[2];
};

/* Bar/Patch Code search parameters 3 of 3 PageCode=33H */
struct mode_page_33 {
  SANE_Byte modedatalen;
  SANE_Byte mediumtype;
  SANE_Byte devicespecificparam;
  SANE_Byte blockdescriptorlen;

  SANE_Byte pagecode;
  SANE_Byte paramlen;
  SANE_Byte barcodecontrast[2];
  SANE_Byte patchmode[2];
  SANE_Byte reserved[2];
};

#ifndef sane_isbasicframe
#define SANE_FRAME_TEXT 10
#define SANE_FRAME_JPEG 11
#define SANE_FRAME_G31D 12
#define SANE_FRAME_G32D 13
#define SANE_FRAME_G42D 14
#define sane_strframe(f) ( (f) == SANE_FRAME_GRAY ? "gray" : \
  (f) == SANE_FRAME_RGB ? "RGB" : \
  (f) == SANE_FRAME_RED ? "red" : \
  (f) == SANE_FRAME_GREEN ? "green" : \
  (f) == SANE_FRAME_BLUE ? "blue" : \
  (f) == SANE_FRAME_TEXT ? "text" : \
  (f) == SANE_FRAME_JPEG ? "jpeg" : \
  (f) == SANE_FRAME_G31D ? "g31d" : \
  (f) == SANE_FRAME_G32D ? "g32d" : \
  (f) == SANE_FRAME_G42D ? "g42d" : \
  "unknown" )

#define sane_isbasicframe(f) ( (f) == SANE_FRAME_GRAY || \
  (f) == SANE_FRAME_RGB || \
  (f) == SANE_FRAME_RED || \
  (f) == SANE_FRAME_GREEN || \
  (f) == SANE_FRAME_BLUE )

#endif

#endif /* BH_H */