1141cc406Sopenharmony_ci/* sane - Scanner Access Now Easy.
2141cc406Sopenharmony_ci   Copyright (C) 2001-2002 Matthew C. Duggan and Simon Krix
3141cc406Sopenharmony_ci   This file is part of the SANE package.
4141cc406Sopenharmony_ci
5141cc406Sopenharmony_ci   This program is free software; you can redistribute it and/or
6141cc406Sopenharmony_ci   modify it under the terms of the GNU General Public License as
7141cc406Sopenharmony_ci   published by the Free Software Foundation; either version 2 of the
8141cc406Sopenharmony_ci   License, or (at your option) any later version.
9141cc406Sopenharmony_ci
10141cc406Sopenharmony_ci   This program is distributed in the hope that it will be useful, but
11141cc406Sopenharmony_ci   WITHOUT ANY WARRANTY; without even the implied warranty of
12141cc406Sopenharmony_ci   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13141cc406Sopenharmony_ci   General Public License for more details.
14141cc406Sopenharmony_ci
15141cc406Sopenharmony_ci   You should have received a copy of the GNU General Public License
16141cc406Sopenharmony_ci   along with this program.  If not, see <https://www.gnu.org/licenses/>.
17141cc406Sopenharmony_ci
18141cc406Sopenharmony_ci   As a special exception, the authors of SANE give permission for
19141cc406Sopenharmony_ci   additional uses of the libraries contained in this release of SANE.
20141cc406Sopenharmony_ci
21141cc406Sopenharmony_ci   The exception is that, if you link a SANE library with other files
22141cc406Sopenharmony_ci   to produce an executable, this does not by itself cause the
23141cc406Sopenharmony_ci   resulting executable to be covered by the GNU General Public
24141cc406Sopenharmony_ci   License.  Your use of that executable is in no way restricted on
25141cc406Sopenharmony_ci   account of linking the SANE library code into it.
26141cc406Sopenharmony_ci
27141cc406Sopenharmony_ci   This exception does not, however, invalidate any other reasons why
28141cc406Sopenharmony_ci   the executable file might be covered by the GNU General Public
29141cc406Sopenharmony_ci   License.
30141cc406Sopenharmony_ci
31141cc406Sopenharmony_ci   If you submit changes to SANE to the maintainers to be included in
32141cc406Sopenharmony_ci   a subsequent release, you agree by submitting the changes that
33141cc406Sopenharmony_ci   those changes may be distributed with this exception intact.
34141cc406Sopenharmony_ci
35141cc406Sopenharmony_ci   If you write modifications of your own for SANE, it is your choice
36141cc406Sopenharmony_ci   whether to permit this exception to apply to your modifications.
37141cc406Sopenharmony_ci   If you do not wish that, delete this exception notice.
38141cc406Sopenharmony_ci
39141cc406Sopenharmony_ci   -----
40141cc406Sopenharmony_ci
41141cc406Sopenharmony_ci   This file is part of the canon_pp backend, supporting Canon FBX30P
42141cc406Sopenharmony_ci   and NX40P scanners and also part of the stand-alone driver.
43141cc406Sopenharmony_ci
44141cc406Sopenharmony_ci   Simon Krix <kinsei@users.sourceforge.net>
45141cc406Sopenharmony_ci   */
46141cc406Sopenharmony_ci
47141cc406Sopenharmony_ci#ifndef CANON_PP_DEV_H
48141cc406Sopenharmony_ci
49141cc406Sopenharmony_ci#define CANON_PP_DEV_H
50141cc406Sopenharmony_ci
51141cc406Sopenharmony_ci/* Signal names */
52141cc406Sopenharmony_ci/* C port */
53141cc406Sopenharmony_ci#define READY 0x1f
54141cc406Sopenharmony_ci#define NSELECTIN 0x08
55141cc406Sopenharmony_ci#define NINIT 0x04
56141cc406Sopenharmony_ci#define HOSTBUSY 0x02
57141cc406Sopenharmony_ci#define HOSTCLK 0x01
58141cc406Sopenharmony_ci
59141cc406Sopenharmony_ci/* S port */
60141cc406Sopenharmony_ci#define BUSY 0x10
61141cc406Sopenharmony_ci#define NACK 0x08
62141cc406Sopenharmony_ci#define PTRCLK 0x08
63141cc406Sopenharmony_ci#define PERROR 0x04
64141cc406Sopenharmony_ci#define ACKDATAREQ 0x04
65141cc406Sopenharmony_ci#define XFLAG 0x02
66141cc406Sopenharmony_ci#define SELECT 0x02
67141cc406Sopenharmony_ci#define NERROR 0x01
68141cc406Sopenharmony_ci#define NFAULT 0x01
69141cc406Sopenharmony_ci#define NDATAAVAIL 0x01
70141cc406Sopenharmony_ci
71141cc406Sopenharmony_ci/* Scanner things */
72141cc406Sopenharmony_ci#define CALSIZE 18      /* Lines per calibration */
73141cc406Sopenharmony_ci
74141cc406Sopenharmony_ci/* Init modes */
75141cc406Sopenharmony_ci#define INITMODE_20P 1
76141cc406Sopenharmony_ci#define INITMODE_30P 2
77141cc406Sopenharmony_ci#define INITMODE_AUTO 3
78141cc406Sopenharmony_ci
79141cc406Sopenharmony_ci/* Misc things */
80141cc406Sopenharmony_ci#define T_SCAN 1
81141cc406Sopenharmony_ci#define T_CALIBRATE 2
82141cc406Sopenharmony_ci
83141cc406Sopenharmony_ci/* Macros */
84141cc406Sopenharmony_ci#define MAKE_SHORT(a,b) (((short)a)*0x100+(short)b)
85141cc406Sopenharmony_ci#define LOW_BYTE(a) (a%0x100)
86141cc406Sopenharmony_ci#define HIGH_BYTE(a) (a/0x100)
87141cc406Sopenharmony_ci
88141cc406Sopenharmony_citypedef struct scanner_parameter_struct
89141cc406Sopenharmony_ci{
90141cc406Sopenharmony_ci	/* This is the port the scanner is on, in libieee1284-readable form */
91141cc406Sopenharmony_ci	struct parport *port;
92141cc406Sopenharmony_ci
93141cc406Sopenharmony_ci	/* Width of the scanning head in pixels */
94141cc406Sopenharmony_ci	int scanheadwidth;
95141cc406Sopenharmony_ci	int scanbedlength;
96141cc406Sopenharmony_ci
97141cc406Sopenharmony_ci	/* Resolution of the scan head where dpi = 75 << natural_resolution */
98141cc406Sopenharmony_ci	int natural_xresolution;
99141cc406Sopenharmony_ci	int natural_yresolution;
100141cc406Sopenharmony_ci
101141cc406Sopenharmony_ci	int max_xresolution;
102141cc406Sopenharmony_ci	int max_yresolution;
103141cc406Sopenharmony_ci
104141cc406Sopenharmony_ci	/* ID String. Should only be 38(?) bytes long, so we can
105141cc406Sopenharmony_ci	   reduce the size later. */
106141cc406Sopenharmony_ci	char id_string[80];
107141cc406Sopenharmony_ci
108141cc406Sopenharmony_ci	/* Short, readable scanner name, such as "FB330P" */
109141cc406Sopenharmony_ci	char name[40];
110141cc406Sopenharmony_ci
111141cc406Sopenharmony_ci	/* Pixel weight values from calibration, one per pixel on the scan head.
112141cc406Sopenharmony_ci	   These must be allocated before any scanning can be done. */
113141cc406Sopenharmony_ci	unsigned long *blackweight;
114141cc406Sopenharmony_ci	unsigned long *redweight;
115141cc406Sopenharmony_ci	unsigned long *greenweight;
116141cc406Sopenharmony_ci	unsigned long *blueweight;
117141cc406Sopenharmony_ci
118141cc406Sopenharmony_ci	/* Not understood white-balance/gain values */
119141cc406Sopenharmony_ci	unsigned char gamma[32];
120141cc406Sopenharmony_ci
121141cc406Sopenharmony_ci	/* Type of scanner ( 0 = *20P, 1 = [*30P|*40P] ) */
122141cc406Sopenharmony_ci	unsigned char type;
123141cc406Sopenharmony_ci
124141cc406Sopenharmony_ci	/* Are we aborting this scanner now */
125141cc406Sopenharmony_ci	unsigned char abort_now;
126141cc406Sopenharmony_ci
127141cc406Sopenharmony_ci} scanner_parameters;
128141cc406Sopenharmony_ci
129141cc406Sopenharmony_citypedef struct scan_parameter_struct
130141cc406Sopenharmony_ci{
131141cc406Sopenharmony_ci	/* Size of image */
132141cc406Sopenharmony_ci	unsigned int width, height;
133141cc406Sopenharmony_ci	/* Position of image on the scanner bed */
134141cc406Sopenharmony_ci	unsigned int xoffset, yoffset;
135141cc406Sopenharmony_ci	/* Resolution at which to scan (remember it's 75 << resolution) */
136141cc406Sopenharmony_ci	int xresolution, yresolution;
137141cc406Sopenharmony_ci	/* Mode of image. 0 = greyscale, 1 = truecolour */
138141cc406Sopenharmony_ci	int mode;
139141cc406Sopenharmony_ci} scan_parameters;
140141cc406Sopenharmony_ci
141141cc406Sopenharmony_citypedef struct image_segment_struct
142141cc406Sopenharmony_ci{
143141cc406Sopenharmony_ci	/* Size of image segment */
144141cc406Sopenharmony_ci	unsigned int width, height;
145141cc406Sopenharmony_ci	/* Which part of the image this is */
146141cc406Sopenharmony_ci	unsigned int start_scanline;
147141cc406Sopenharmony_ci	/* Pointer to image data */
148141cc406Sopenharmony_ci	unsigned char *image_data;
149141cc406Sopenharmony_ci} image_segment;
150141cc406Sopenharmony_ci
151141cc406Sopenharmony_ci/* Scan-related functions ========================= */
152141cc406Sopenharmony_ci
153141cc406Sopenharmony_ci/* Brings the scanner in and out of transparent mode
154141cc406Sopenharmony_ci   and detects model information */
155141cc406Sopenharmony_ciint sanei_canon_pp_initialise(scanner_parameters *sp, int mode);
156141cc406Sopenharmony_ciint sanei_canon_pp_close_scanner(scanner_parameters *sp);
157141cc406Sopenharmony_ci
158141cc406Sopenharmony_ci/* Image scanning functions */
159141cc406Sopenharmony_ciint sanei_canon_pp_init_scan(scanner_parameters *sp, scan_parameters *scanp);
160141cc406Sopenharmony_ci
161141cc406Sopenharmony_ciint sanei_canon_pp_read_segment(image_segment **dest, scanner_parameters *sp,
162141cc406Sopenharmony_ci		scan_parameters *scanp, int scanline_count, int do_adjust,
163141cc406Sopenharmony_ci		int scanlines_left);
164141cc406Sopenharmony_ci
165141cc406Sopenharmony_ciint sanei_canon_pp_abort_scan(scanner_parameters *sp);
166141cc406Sopenharmony_ci
167141cc406Sopenharmony_ci/* Loads the gain offset values. Needs a new name. */
168141cc406Sopenharmony_ciint sanei_canon_pp_load_weights(const char *filename, scanner_parameters *sp);
169141cc406Sopenharmony_ci
170141cc406Sopenharmony_ci
171141cc406Sopenharmony_ciint sanei_canon_pp_calibrate(scanner_parameters *sp, char *cal_file);
172141cc406Sopenharmony_ci
173141cc406Sopenharmony_ciint sanei_canon_pp_adjust_gamma(scanner_parameters *sp);
174141cc406Sopenharmony_ci
175141cc406Sopenharmony_ci/* Detect if a scanner is present on a given port */
176141cc406Sopenharmony_ciint sanei_canon_pp_detect(struct parport *port, int mode);
177141cc406Sopenharmony_ci
178141cc406Sopenharmony_ci/* Put a scanner to sleep */
179141cc406Sopenharmony_ciint sanei_canon_pp_sleep_scanner(struct parport *port);
180141cc406Sopenharmony_ci
181141cc406Sopenharmony_ci#endif
182