1 /* sane - Scanner Access Now Easy.
2    Copyright (C) 2001-2002 Matthew C. Duggan and Simon Krix
3    This file is part of the SANE package.
4 
5    This program is free software; you can redistribute it and/or
6    modify it under the terms of the GNU General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    License, or (at your option) any later version.
9 
10    This program is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14 
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 
18    As a special exception, the authors of SANE give permission for
19    additional uses of the libraries contained in this release of SANE.
20 
21    The exception is that, if you link a SANE library with other files
22    to produce an executable, this does not by itself cause the
23    resulting executable to be covered by the GNU General Public
24    License.  Your use of that executable is in no way restricted on
25    account of linking the SANE library code into it.
26 
27    This exception does not, however, invalidate any other reasons why
28    the executable file might be covered by the GNU General Public
29    License.
30 
31    If you submit changes to SANE to the maintainers to be included in
32    a subsequent release, you agree by submitting the changes that
33    those changes may be distributed with this exception intact.
34 
35    If you write modifications of your own for SANE, it is your choice
36    whether to permit this exception to apply to your modifications.
37    If you do not wish that, delete this exception notice.
38 
39    -----
40 
41    This file is part of the canon_pp backend, supporting Canon FBX30P
42    and NX40P scanners and also part of the stand-alone driver.
43 
44    Simon Krix <kinsei@users.sourceforge.net>
45    */
46 
47 #ifndef CANON_PP_DEV_H
48 
49 #define CANON_PP_DEV_H
50 
51 /* Signal names */
52 /* C port */
53 #define READY 0x1f
54 #define NSELECTIN 0x08
55 #define NINIT 0x04
56 #define HOSTBUSY 0x02
57 #define HOSTCLK 0x01
58 
59 /* S port */
60 #define BUSY 0x10
61 #define NACK 0x08
62 #define PTRCLK 0x08
63 #define PERROR 0x04
64 #define ACKDATAREQ 0x04
65 #define XFLAG 0x02
66 #define SELECT 0x02
67 #define NERROR 0x01
68 #define NFAULT 0x01
69 #define NDATAAVAIL 0x01
70 
71 /* Scanner things */
72 #define CALSIZE 18      /* Lines per calibration */
73 
74 /* Init modes */
75 #define INITMODE_20P 1
76 #define INITMODE_30P 2
77 #define INITMODE_AUTO 3
78 
79 /* Misc things */
80 #define T_SCAN 1
81 #define T_CALIBRATE 2
82 
83 /* Macros */
84 #define MAKE_SHORT(a,b) (((short)a)*0x100+(short)b)
85 #define LOW_BYTE(a) (a%0x100)
86 #define HIGH_BYTE(a) (a/0x100)
87 
88 typedef struct scanner_parameter_struct
89 {
90 	/* This is the port the scanner is on, in libieee1284-readable form */
91 	struct parport *port;
92 
93 	/* Width of the scanning head in pixels */
94 	int scanheadwidth;
95 	int scanbedlength;
96 
97 	/* Resolution of the scan head where dpi = 75 << natural_resolution */
98 	int natural_xresolution;
99 	int natural_yresolution;
100 
101 	int max_xresolution;
102 	int max_yresolution;
103 
104 	/* ID String. Should only be 38(?) bytes long, so we can
105 	   reduce the size later. */
106 	char id_string[80];
107 
108 	/* Short, readable scanner name, such as "FB330P" */
109 	char name[40];
110 
111 	/* Pixel weight values from calibration, one per pixel on the scan head.
112 	   These must be allocated before any scanning can be done. */
113 	unsigned long *blackweight;
114 	unsigned long *redweight;
115 	unsigned long *greenweight;
116 	unsigned long *blueweight;
117 
118 	/* Not understood white-balance/gain values */
119 	unsigned char gamma[32];
120 
121 	/* Type of scanner ( 0 = *20P, 1 = [*30P|*40P] ) */
122 	unsigned char type;
123 
124 	/* Are we aborting this scanner now */
125 	unsigned char abort_now;
126 
127 } scanner_parameters;
128 
129 typedef struct scan_parameter_struct
130 {
131 	/* Size of image */
132 	unsigned int width, height;
133 	/* Position of image on the scanner bed */
134 	unsigned int xoffset, yoffset;
135 	/* Resolution at which to scan (remember it's 75 << resolution) */
136 	int xresolution, yresolution;
137 	/* Mode of image. 0 = greyscale, 1 = truecolour */
138 	int mode;
139 } scan_parameters;
140 
141 typedef struct image_segment_struct
142 {
143 	/* Size of image segment */
144 	unsigned int width, height;
145 	/* Which part of the image this is */
146 	unsigned int start_scanline;
147 	/* Pointer to image data */
148 	unsigned char *image_data;
149 } image_segment;
150 
151 /* Scan-related functions ========================= */
152 
153 /* Brings the scanner in and out of transparent mode
154    and detects model information */
155 int sanei_canon_pp_initialise(scanner_parameters *sp, int mode);
156 int sanei_canon_pp_close_scanner(scanner_parameters *sp);
157 
158 /* Image scanning functions */
159 int sanei_canon_pp_init_scan(scanner_parameters *sp, scan_parameters *scanp);
160 
161 int sanei_canon_pp_read_segment(image_segment **dest, scanner_parameters *sp,
162 		scan_parameters *scanp, int scanline_count, int do_adjust,
163 		int scanlines_left);
164 
165 int sanei_canon_pp_abort_scan(scanner_parameters *sp);
166 
167 /* Loads the gain offset values. Needs a new name. */
168 int sanei_canon_pp_load_weights(const char *filename, scanner_parameters *sp);
169 
170 
171 int sanei_canon_pp_calibrate(scanner_parameters *sp, char *cal_file);
172 
173 int sanei_canon_pp_adjust_gamma(scanner_parameters *sp);
174 
175 /* Detect if a scanner is present on a given port */
176 int sanei_canon_pp_detect(struct parport *port, int mode);
177 
178 /* Put a scanner to sleep */
179 int sanei_canon_pp_sleep_scanner(struct parport *port);
180 
181 #endif
182