• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef CANON_DR_H
2 #define CANON_DR_H
3 
4 /*
5  * Part of SANE - Scanner Access Now Easy.
6  * Please see opening comments in canon_dr.c
7  */
8 
9 /* -------------------------------------------------------------------------
10  * This option list has to contain all options for all scanners supported by
11  * this driver. If a certain scanner cannot handle a certain option, there's
12  * still the possibility to say so, later.
13  */
14 enum scanner_Option
15 {
16   OPT_NUM_OPTS = 0,
17 
18   OPT_STANDARD_GROUP,
19   OPT_SOURCE, /*fb/adf/front/back/duplex*/
20   OPT_MODE,   /*mono/gray/color*/
21   OPT_RES,    /*a range or a list*/
22 
23   OPT_GEOMETRY_GROUP,
24   OPT_PAGE_WIDTH,
25   OPT_PAGE_HEIGHT,
26   OPT_TL_X,
27   OPT_TL_Y,
28   OPT_BR_X,
29   OPT_BR_Y,
30 
31   OPT_ENHANCEMENT_GROUP,
32   OPT_BRIGHTNESS,
33   OPT_CONTRAST,
34   OPT_THRESHOLD,
35   OPT_RIF,
36 
37   OPT_ADVANCED_GROUP,
38   OPT_COMPRESS,
39   OPT_COMPRESS_ARG,
40   OPT_DF_THICKNESS,
41   OPT_DF_LENGTH,
42   OPT_ROLLERDESKEW,
43   OPT_SWDESKEW,
44   OPT_SWDESPECK,
45   OPT_SWCROP,
46   OPT_SWSKIP,
47   OPT_STAPLEDETECT,
48   OPT_DROPOUT_COLOR_F,
49   OPT_DROPOUT_COLOR_B,
50   OPT_BUFFERMODE,
51   OPT_SIDE,
52   OPT_HW_CROP,
53 
54   /*imprinter option group*/
55   OPT_IMPRINT_GROUP,
56   OPT_PRE_IMPRINT_SPECSTRING,
57   OPT_PRE_IMPRINT_H_OFFSET,
58   OPT_PRE_IMPRINT_V_OFFSET,
59   OPT_PRE_IMPRINT_FONT_SIZE,
60   OPT_PRE_IMPRINT_FONT_ROT,
61   OPT_PRE_IMPRINT_SPACING,
62   OPT_POST_IMPRINT_SPECSTRING,
63   OPT_POST_IMPRINT_H_OFFSET,
64   OPT_POST_IMPRINT_V_OFFSET,
65   OPT_POST_IMPRINT_FONT_SIZE,
66   OPT_POST_IMPRINT_FONT_ROT,
67   OPT_POST_IMPRINT_SPACING,
68   OPT_POST_IMPRINT_ADDON_MODE,
69 
70   /*sensor group*/
71   OPT_SENSOR_GROUP,
72   OPT_START,
73   OPT_STOP,
74   OPT_BUTT3,
75   OPT_NEWFILE,
76   OPT_COUNTONLY,
77   OPT_BYPASSMODE,
78   OPT_COUNTER,
79   OPT_ROLLERCOUNTER,
80   OPT_TOTALCOUNTER,
81   OPT_ADF_LOADED,
82   OPT_CARD_LOADED,
83 
84   /* must come last: */
85   NUM_OPTIONS
86 };
87 
88 struct img_params
89 {
90   int mode;           /*color,lineart,etc*/
91   int source;         /*fb,adf front,adf duplex,etc*/
92 
93   int dpi_x;          /*these are in dpi */
94   int dpi_y;
95 
96   int tl_x;           /*these are in 1200dpi units */
97   int tl_y;
98   int br_x;
99   int br_y;
100   int page_x;
101   int page_y;
102 
103   int width;          /*these are in pixels*/
104   int height;
105 
106   SANE_Frame format;  /*SANE_FRAME_**/
107   int bpp;            /* 1,8,24 */
108   int Bpl;            /* in bytes */
109 
110   int valid_width;    /*some machines have black padding*/
111   int valid_Bpl;
112 
113   /* done yet? */
114   int eof[2];
115 
116   /* how far we have read/written */
117   int bytes_sent[2];
118 
119   /* total to read/write */
120   int bytes_tot[2];
121 
122   /* dumb scanners send extra data */
123   int skip_lines[2];
124 
125 };
126 
127 struct imprint_params
128 {
129   /* ------------------------------------------------------------------------------ */
130   /*  allowed values for post imprinter (in mm units):                              */
131   /* 21, 35, 47, 59, 72, 99, 114, 143, 155, 167, 196, 211, 239, 251, 263, 275, 289  */
132   /*  allowed values for pre imprinter (in mm units):                               */
133   /* 14, 28, 41, 53, 65, 106                                                        */
134   int h_offset;
135   /* --------------------------------------- */
136   /*  allowed values: 0 to 500 (in mm units) */
137   int v_offset;
138 
139   int font_size;
140   int font_rot;
141   int spacing;
142 
143 #define IMPRINT_SPECSTRING_LEN 64
144   /* ---------------------------------- */
145   /*  special tokens:                   */
146   /*  \TIME       time in HH:MM:SS      */
147   /*  \DMY        date in DD/MM/YYYY    */
148   /*  \YMD        date in YYYY/MM/DD    */
149   /*  [[0-9]+]    scan page count       */
150   char specstring[IMPRINT_SPECSTRING_LEN];
151 };
152 
153 struct scanner
154 {
155   /* --------------------------------------------------------------------- */
156   /* immutable values which are set during init of scanner.                */
157   struct scanner *next;
158   char device_name[1024];             /* The name of the device from sanei */
159   int missing; 				/* used to mark unplugged scanners */
160 
161   /* --------------------------------------------------------------------- */
162   /* immutable values which are set during reading of config file.         */
163   int connection;       /* hardware interface type */
164   int buffer_size;
165   int duplex_offset;    /* number of lines of padding added to front (1/1200)*/
166   int extra_status;     /* some machines need extra status read after cmd */
167   int inquiry_length;   /* some models are particular about inquiry size */
168   int padded_read;      /* some machines need extra 12 bytes on reads */
169   int tur_timeout;      /* some models are slow to wake up */
170   int vpd_length;       /* some models are particular about vpd size */
171 
172   /* --------------------------------------------------------------------- */
173   /* immutable values which are set during inquiry probing of the scanner. */
174   /* members in order found in scsi data. These can also be in config file */
175   char vendor_name[9];          /* raw data as returned by SCSI inquiry.   */
176   char model_name[17];          /* raw data as returned by SCSI inquiry.   */
177   char version_name[5];         /* raw data as returned by SCSI inquiry.   */
178 
179   /* --------------------------------------------------------------------- */
180   /* immutable values which are set during std VPD probing of the scanner. */
181   /* members in order found in scsi data...                                */
182   int basic_x_res;
183   int basic_y_res;
184   int step_x_res;
185   int step_y_res;
186   int max_x_res;
187   int max_y_res;
188   int min_x_res;
189   int min_y_res;
190 
191   int std_res_x[16];
192   int std_res_y[16];
193 
194   /* max scan size in pixels converted to 1200dpi units */
195   int max_x;
196   int max_y;
197 
198   /*FIXME: 4 more unknown values here*/
199   int can_grayscale;
200   int can_halftone;
201   int can_monochrome;
202   int can_overflow;
203 
204   /* --------------------------------------------------------------------- */
205   /* immutable values which are hard coded because they are not in vpd     */
206 
207   int brightness_steps;
208   int threshold_steps;
209   int contrast_steps;
210   int ppl_mod;       /* modulus of scanline width */
211 
212   /* the scan size in 1/1200th inches, NOT basic_units or sane units */
213   int min_x;
214   int min_y;
215   int valid_x;
216   int max_x_fb;
217   int max_y_fb;
218 
219   int can_color;     /* actually might be in vpd, but which bit? */
220 
221   int need_ccal;     /* scanner needs software to help with afe calibration */
222   int ccal_version;  /* 0 in most scanners, 3 in newer ones */
223 
224   int fcal_src;      /* where fine offset/gain calibration data comes from */
225   int fcal_dest;     /* where fine offset/gain calibration data is used */
226 
227 #define FCAL_SRC_NONE 0  /* scanner does not require fine calibration */
228 #define FCAL_SRC_SCAN 1  /* make calibration scans, store gain/offset in struct */
229 #define FCAL_SRC_HW 2    /* calibration permanently stored in scanner, downloaded into struct */
230 
231 #define FCAL_DEST_NONE 0 /* scanner does not require fine calibration */
232 #define FCAL_DEST_SW 1   /* use gain/offset in struct to adjust output in software */
233 #define FCAL_DEST_HW 2   /* send calibration data into scanner for use in hardware */
234 
235   int has_counter;
236   int has_rif;
237   int has_adf;
238   int has_flatbed;
239   int has_duplex;
240   int has_back;         /* not all duplex scanners can do adf back side only */
241   int has_card;         /* P215 has a card reader instead of fb */
242   int has_comp_JPEG;
243   int has_buffer;
244   int has_df;
245   int has_df_ultra;
246   int has_btc;
247   int has_ssm;           /* older scanners use this set scan mode command */
248   int has_ssm2;          /* newer scanners user this similar command */
249   int has_ssm_pay_head_len; /* newer scanners put the length twice in ssm */
250   int has_hwcrop;
251   int has_pre_imprinter;
252   int has_post_imprinter;
253   int can_read_sensors;
254   int can_read_panel;
255   int can_write_panel;
256   int can_read_lifecycle_counters;
257   int rgb_format;       /* meaning unknown */
258   int padding;          /* meaning unknown */
259 
260   int always_op;        /* send object pos between pages */
261   int invert_tly;       /* weird bug in some smaller scanners */
262   int unknown_byte2;    /* weird byte, required, meaning unknown */
263   int fixed_width;      /* some machines always scan full width */
264   int even_Bpl;         /* some machines require even bytes per line */
265 
266   int gray_interlace[2];  /* different models interlace heads differently    */
267   int color_interlace[2]; /* different models interlace colors differently   */
268   int color_inter_by_res[16]; /* and some even change by resolution */
269   int duplex_interlace; /* different models interlace sides differently      */
270   int jpeg_interlace;   /* different models interlace jpeg sides differently */
271   int duplex_offset_side; /* padding added to front or back? */
272 
273   int sw_lut;           /* no hardware brightness/contrast support */
274   int bg_color;         /* needed to fill in after rotation */
275 
276   int reverse_by_mode[6]; /* mode specific */
277 
278   /* --------------------------------------------------------------------- */
279   /* immutable values which are set during serial number probing scanner   */
280   char serial_name[28];        /* 16 char model, ':', 10 byte serial, null */
281 
282   /* --------------------------------------------------------------------- */
283   /* struct with pointers to device/vendor/model names, and a type value */
284   /* used to inform sane frontend about the device */
285   SANE_Device sane;
286 
287   /* --------------------------------------------------------------------- */
288   /* changeable SANE_Option structs provide our interface to frontend.     */
289   /* some options require lists of strings or numbers, we keep them here   */
290   /* instead of in global vars so that they can differ for each scanner    */
291 
292   /* long array of option structs */
293   SANE_Option_Descriptor opt[NUM_OPTIONS];
294 
295   /*mode group*/
296   SANE_String_Const mode_list[7];
297   SANE_String_Const source_list[8];
298 
299   SANE_Int res_list[17];
300   SANE_Range res_range;
301 
302   /*geometry group*/
303   SANE_Range tl_x_range;
304   SANE_Range tl_y_range;
305   SANE_Range br_x_range;
306   SANE_Range br_y_range;
307   SANE_Range paper_x_range;
308   SANE_Range paper_y_range;
309 
310   /*enhancement group*/
311   SANE_Range brightness_range;
312   SANE_Range contrast_range;
313   SANE_Range threshold_range;
314 
315   /*advanced group*/
316   SANE_String_Const compress_list[3];
317   SANE_Range compress_arg_range;
318   SANE_Range swdespeck_range;
319   SANE_Range swskip_range;
320   SANE_String_Const do_color_list[8];
321 
322   /*sensor group*/
323   SANE_Range counter_range;
324 
325   /* --------------------------------------------------------------------- */
326   /* changeable vars to hold user input. modified by SANE_Options above    */
327 
328   /* the user's requested image params */
329   /* exposed in standard and geometry option groups */
330   struct img_params u;
331 
332   /*enhancement group*/
333   int brightness;
334   int contrast;
335   int threshold;
336   int rif;
337 
338   /*advanced group*/
339   int compress;
340   int compress_arg;
341   int df_length;
342   int df_thickness;
343   int dropout_color[2];
344   int buffermode;
345   int rollerdeskew;
346   int swdeskew;
347   int swdespeck;
348   int swcrop;
349   int swskip;
350   int stapledetect;
351   int hwcrop;
352 
353   /* --------------------------------------------------------------------- */
354   /* values which are derived from setting the options above */
355   /* the user never directly modifies these */
356 
357   /* the scanner image params (what we ask from scanner) */
358   struct img_params s;
359 
360   /* the intermediate image params (like user, but possible higher depth) */
361   struct img_params i;
362 
363   /* the brightness/contrast LUT for dumb scanners */
364   unsigned char lut[256];
365 
366   /* --------------------------------------------------------------------- */
367   /* values used by the software enhancement code (deskew, crop, etc)      */
368   SANE_Status deskew_stat;
369   int deskew_vals[2];
370   double deskew_slope;
371 
372   int crop_vals[4];
373 
374   /* imprinter params */
375   struct imprint_params pre_imprint;
376   struct imprint_params post_imprint;
377   enum {
378     /*Black-on-White*/
379     ADDON_BoW = 0,
380     /*White-on-Black*/
381     ADDON_WoB,
382     /*Black-on-Image*/
383     ADDON_BoI,
384     ADDON_DISABLED
385   } post_imprint_addon_mode;
386 
387   /* imprinter param constraints */
388   SANE_Int pre_imprinter_h_offset_list[7];
389   SANE_Int post_imprinter_h_offset_list[18];
390   SANE_Range imprinter_v_offset_range;
391   SANE_String_Const imprint_font_size_list[3];
392   SANE_Int imprinter_font_angle_list[5];
393   SANE_String_Const imprint_addon_mode_list[5];
394 
395   /* this is defined in sane spec as a struct containing:
396         SANE_Frame format;
397         SANE_Bool last_frame;
398         SANE_Int lines;
399         SANE_Int depth; ( binary=1, gray=8, color=8 (!24) )
400         SANE_Int pixels_per_line;
401         SANE_Int bytes_per_line;
402   */
403   SANE_Parameters s_params;
404 
405   /* --------------------------------------------------------------------- */
406   /* values which are set by calibration functions                         */
407   int c_res;
408   int c_mode;
409 
410   int c_offset[2];
411   int c_gain[2];
412   int c_exposure[2][3];
413 
414   int f_res;
415   int f_mode;
416 
417   unsigned char * f_offset[2];
418   unsigned char * f_gain[2];
419 
420   /* --------------------------------------------------------------------- */
421   /* values which are set by scanning functions to keep track of pages, etc */
422   int started;
423   int reading;
424   int cancelled;
425   int side;
426   int prev_page;
427   int jpeg_stage;
428   int jpeg_ff_offset;
429 
430   unsigned char * buffers[2];
431 
432   /* --------------------------------------------------------------------- */
433   /* values used by the command and data sending functions (scsi/usb)      */
434   int fd;                      /* The scanner device file descriptor.      */
435   size_t rs_info;
436 
437   /* --------------------------------------------------------------------- */
438   /* values used to hold hardware or control panel status                  */
439 
440   int panel_start;
441   int panel_stop;
442   int panel_butt3;
443   int panel_new_file;
444   int panel_count_only;
445   int panel_bypass_mode;
446   int panel_enable_led;
447   int panel_counter;
448   int sensor_adf_loaded;
449   int sensor_card_loaded;
450   int roller_counter;
451   int total_counter;
452 
453   /* values which are used to track the frontend's access to sensors  */
454   char panel_read[OPT_COUNTER - OPT_START + 1];
455   char sensors_read[OPT_CARD_LOADED - OPT_ADF_LOADED + 1];
456 };
457 
458 #define CONNECTION_SCSI   0 /* SCSI interface */
459 #define CONNECTION_USB    1 /* USB interface */
460 
461 #define SIDE_FRONT 0
462 #define SIDE_BACK 1
463 
464 #define CHAN_RED 0
465 #define CHAN_GREEN 1
466 #define CHAN_BLUE 2
467 
468 #define SOURCE_FLATBED 0
469 #define SOURCE_ADF_FRONT 1
470 #define SOURCE_ADF_BACK 2
471 #define SOURCE_ADF_DUPLEX 3
472 #define SOURCE_CARD_FRONT 4
473 #define SOURCE_CARD_BACK 5
474 #define SOURCE_CARD_DUPLEX 6
475 
476 static const int dpi_list[] = {
477 60,75,100,120,150,160,180,200,
478 240,300,320,400,480,600,800,1200
479 };
480 
481 #define DPI_60 0
482 #define DPI_75 1
483 #define DPI_100 2
484 #define DPI_120 3
485 #define DPI_150 4
486 #define DPI_160 5
487 #define DPI_180 6
488 #define DPI_200 7
489 #define DPI_240 8
490 #define DPI_300 9
491 #define DPI_320 10
492 #define DPI_400 11
493 #define DPI_480 12
494 #define DPI_600 13
495 #define DPI_800 14
496 #define DPI_1200 15
497 
498 #define COMP_NONE WD_cmp_NONE
499 #define COMP_JPEG WD_cmp_JPEG
500 
501 #define JPEG_STAGE_NONE 0
502 #define JPEG_STAGE_SOF 1
503 
504 /* these are same as scsi data to make code easier */
505 #define MODE_LINEART WD_comp_LA
506 #define MODE_HALFTONE WD_comp_HT
507 #define MODE_GRAYSCALE WD_comp_GS
508 #define MODE_COLOR WD_comp_CG
509 
510 enum {
511  COLOR_NONE = 0,
512  COLOR_RED,
513  COLOR_GREEN,
514  COLOR_BLUE,
515  COLOR_EN_RED,
516  COLOR_EN_GREEN,
517  COLOR_EN_BLUE
518 };
519 
520 /* these are same as scsi data to make code easier */
521 #define COLOR_WHITE 1
522 #define COLOR_BLACK 2
523 
524 #define GRAY_INTERLACE_NONE 0
525 #define GRAY_INTERLACE_2510 1
526 #define GRAY_INTERLACE_gG 2
527 #define GRAY_INTERLACE_C120 3
528 
529 #define COLOR_INTERLACE_UNK 0
530 #define COLOR_INTERLACE_RGB 1
531 #define COLOR_INTERLACE_BGR 2
532 #define COLOR_INTERLACE_BRG 3
533 #define COLOR_INTERLACE_GBR 4
534 #define COLOR_INTERLACE_RRGGBB 5
535 #define COLOR_INTERLACE_rRgGbB 6
536 #define COLOR_INTERLACE_2510 7
537 #define COLOR_INTERLACE_C120 8
538 
539 #define DUPLEX_INTERLACE_NONE 0
540 #define DUPLEX_INTERLACE_FfBb 1
541 #define DUPLEX_INTERLACE_FBfb 2
542 #define DUPLEX_INTERLACE_2510 3
543 #define DUPLEX_INTERLACE_fFBb 4
544 #define DUPLEX_INTERLACE_PER_CHANNEL 5
545 
546 #define JPEG_INTERLACE_ALT 0
547 #define JPEG_INTERLACE_NONE 1
548 
549 #define CROP_RELATIVE 0
550 #define CROP_ABSOLUTE 1
551 
552 /* ------------------------------------------------------------------------- */
553 
554 #define MM_PER_UNIT_UNFIX SANE_UNFIX(SANE_FIX(MM_PER_INCH / 1200.0))
555 #define MM_PER_UNIT_FIX SANE_FIX(SANE_UNFIX(SANE_FIX(MM_PER_INCH / 1200.0)))
556 
557 #define SCANNER_UNIT_TO_FIXED_MM(number) SANE_FIX((number) * MM_PER_UNIT_UNFIX)
558 #define FIXED_MM_TO_SCANNER_UNIT(number) SANE_UNFIX(number) / MM_PER_UNIT_UNFIX
559 
560 #define CANON_DR_CONFIG_FILE "canon_dr.conf"
561 
562 #ifndef PATH_MAX
563 #  define PATH_MAX 1024
564 #endif
565 
566 /* ------------------------------------------------------------------------- */
567 
568 SANE_Status sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize);
569 
570 SANE_Status sane_get_devices (const SANE_Device *** device_list,
571                               SANE_Bool local_only);
572 
573 SANE_Status sane_open (SANE_String_Const name, SANE_Handle * handle);
574 
575 SANE_Status sane_set_io_mode (SANE_Handle h, SANE_Bool non_blocking);
576 
577 SANE_Status sane_get_select_fd (SANE_Handle h, SANE_Int * fdp);
578 
579 const SANE_Option_Descriptor * sane_get_option_descriptor (SANE_Handle handle,
580                                                           SANE_Int option);
581 
582 SANE_Status sane_control_option (SANE_Handle handle, SANE_Int option,
583                                  SANE_Action action, void *val,
584                                  SANE_Int * info);
585 
586 SANE_Status sane_start (SANE_Handle handle);
587 
588 SANE_Status sane_get_parameters (SANE_Handle handle,
589                                  SANE_Parameters * params);
590 
591 SANE_Status sane_read (SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len,
592                        SANE_Int * len);
593 
594 void sane_cancel (SANE_Handle h);
595 
596 void sane_close (SANE_Handle h);
597 
598 void sane_exit (void);
599 
600 /* ------------------------------------------------------------------------- */
601 
602 static SANE_Status attach_one_scsi (const char *name);
603 static SANE_Status attach_one_usb (const char *name);
604 static SANE_Status attach_one (const char *devicename, int connType);
605 
606 static SANE_Status connect_fd (struct scanner *s);
607 static SANE_Status disconnect_fd (struct scanner *s);
608 
609 static SANE_Status sense_handler (int scsi_fd, u_char * result, void *arg);
610 
611 static SANE_Status init_inquire (struct scanner *s);
612 static SANE_Status init_vpd (struct scanner *s);
613 static SANE_Status init_model (struct scanner *s);
614 static SANE_Status init_imprinters (struct scanner *s);
615 static SANE_Status init_panel (struct scanner *s);
616 static SANE_Status init_counters (struct scanner *s);
617 static SANE_Status init_user (struct scanner *s);
618 static SANE_Status init_options (struct scanner *s);
619 
620 static SANE_Status
621 do_cmd(struct scanner *s, int runRS, int shortTime,
622  unsigned char * cmdBuff, size_t cmdLen,
623  unsigned char * outBuff, size_t outLen,
624  unsigned char * inBuff, size_t * inLen
625 );
626 
627 static SANE_Status
628 do_scsi_cmd(struct scanner *s, int runRS, int shortTime,
629  unsigned char * cmdBuff, size_t cmdLen,
630  unsigned char * outBuff, size_t outLen,
631  unsigned char * inBuff, size_t * inLen
632 );
633 
634 static SANE_Status
635 do_usb_cmd(struct scanner *s, int runRS, int shortTime,
636  unsigned char * cmdBuff, size_t cmdLen,
637  unsigned char * outBuff, size_t outLen,
638  unsigned char * inBuff, size_t * inLen
639 );
640 
641 static SANE_Status
642 do_usb_status(struct scanner *s, int runRS, int shortTime, size_t * extraLength);
643 
644 static SANE_Status do_usb_clear(struct scanner *s, int clear, int runRS);
645 
646 static SANE_Status wait_scanner (struct scanner *s);
647 
648 static SANE_Status object_position (struct scanner *s, int i_load);
649 
650 static SANE_Status ssm_buffer (struct scanner *s);
651 static SANE_Status ssm_do (struct scanner *s);
652 static SANE_Status ssm_df (struct scanner *s);
653 
654 static int get_color_inter(struct scanner *s, int side, int res);
655 
656 static int get_page_width (struct scanner *s);
657 static int get_page_height (struct scanner *s);
658 
659 static SANE_Status set_window (struct scanner *s);
660 static SANE_Status update_params (struct scanner *s, int calib);
661 static SANE_Status update_i_params (struct scanner *s);
662 static SANE_Status clean_params (struct scanner *s);
663 
664 static SANE_Status read_counters(struct scanner *s);
665 static SANE_Status read_sensors(struct scanner *s, SANE_Int option);
666 static SANE_Status read_panel(struct scanner *s, SANE_Int option);
667 static SANE_Status send_panel(struct scanner *s);
668 
669 static SANE_Status start_scan (struct scanner *s, int type);
670 
671 static SANE_Status check_for_cancel(struct scanner *s);
672 
673 static SANE_Status read_from_scanner(struct scanner *s, int side, int exact);
674 static SANE_Status read_from_scanner_duplex(struct scanner *s, int exact);
675 
676 static SANE_Status copy_simplex(struct scanner *s, unsigned char * buf, int len, int side);
677 static SANE_Status copy_duplex(struct scanner *s, unsigned char * buf, int len);
678 static SANE_Status copy_line(struct scanner *s, unsigned char * buf, int side);
679 static SANE_Status fill_image(struct scanner *s,int side);
680 
681 static int must_downsample (struct scanner *s);
682 static int must_fully_buffer (struct scanner *s);
683 static unsigned char calc_bg_color(struct scanner *s);
684 
685 static SANE_Status buffer_despeck(struct scanner *s, int side);
686 static SANE_Status buffer_deskew(struct scanner *s, int side);
687 static SANE_Status buffer_crop(struct scanner *s, int side);
688 static int buffer_isblank(struct scanner *s, int side);
689 
690 static SANE_Status load_lut (unsigned char * lut, int in_bits, int out_bits,
691   int out_min, int out_max, int slope, int offset);
692 
693 static SANE_Status read_from_buffer(struct scanner *s, SANE_Byte * buf, SANE_Int max_len, SANE_Int * len, int side);
694 
695 static SANE_Status image_buffers (struct scanner *s, int setup);
696 static SANE_Status offset_buffers (struct scanner *s, int setup);
697 static SANE_Status gain_buffers (struct scanner *s, int setup);
698 
699 static SANE_Status calibrate_AFE(struct scanner *s);
700 static SANE_Status calibrate_fine(struct scanner *s);
701 static SANE_Status calibrate_fine_src_scan(struct scanner *s);
702 static SANE_Status calibrate_fine_src_hw(struct scanner *s);
703 static SANE_Status calibrate_fine_dest_hw(struct scanner *s);
704 
705 static SANE_Status write_AFE (struct scanner *s);
706 static SANE_Status calibration_scan (struct scanner *s, int);
707 
708 static SANE_Status send_imprint_positioning(struct scanner* s, int is_postimprint, int enabled);
709 static SANE_Status send_imprint_specstring(struct scanner* s, int is_postimprint);
710 static SANE_Status send_imprint_date_and_time(struct scanner* s);
711 static SANE_Status load_imprinting_settings(struct scanner *s);
712 static SANE_Status detect_imprinter(struct scanner *s, SANE_Int option);
713 
714 static void hexdump (int level, char *comment, unsigned char *p, int l);
715 static void default_globals (void);
716 
717 static size_t maxStringSize (const SANE_String_Const strings[]);
718 
719 static void rmemcpy(void* dest, const void* src, size_t count, size_t stride);
720 
721 #endif /* CANON_DR_H */
722