1 /* epson.h - SANE library for Epson flatbed scanners.
2 
3    based on Kazuhiro Sasayama previous
4    Work on epson.[ch] file from the SANE package.
5 
6    original code taken from sane-0.71
7    Copyright (C) 1997 Hypercore Software Design, Ltd.
8 
9    modifications
10    Copyright (C) 1998-1999 Christian Bucher <bucher@vernetzt.at>
11    Copyright (C) 1998-1999 Kling & Hautzinger GmbH
12    Copyright (C) 1999 Norihiko Sawa <sawa@yb3.so-net.ne.jp>
13    Copyright (C) 2000 Karl Heinz Kremer <khk@khk.net>
14 
15    This file is part of the SANE package.
16 
17    This program is free software; you can redistribute it and/or
18    modify it under the terms of the GNU General Public License as
19    published by the Free Software Foundation; either version 2 of the
20    License, or (at your option) any later version.
21 
22    This program is distributed in the hope that it will be useful, but
23    WITHOUT ANY WARRANTY; without even the implied warranty of
24    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
25    General Public License for more details.
26 
27    You should have received a copy of the GNU General Public License
28    along with this program.  If not, see <https://www.gnu.org/licenses/>.
29 
30    As a special exception, the authors of SANE give permission for
31    additional uses of the libraries contained in this release of SANE.
32 
33    The exception is that, if you link a SANE library with other files
34    to produce an executable, this does not by itself cause the
35    resulting executable to be covered by the GNU General Public
36    License.  Your use of that executable is in no way restricted on
37    account of linking the SANE library code into it.
38 
39    This exception does not, however, invalidate any other reasons why
40    the executable file might be covered by the GNU General Public
41    License.
42 
43    If you submit changes to SANE to the maintainers to be included in
44    a subsequent release, you agree by submitting the changes that
45    those changes may be distributed with this exception intact.
46 
47    If you write modifications of your own for SANE, it is your choice
48    whether to permit this exception to apply to your modifications.
49    If you do not wish that, delete this exception notice.  */
50 
51 #ifndef epson_h
52 #define epson_h
53 
54 #include <sys/ioctl.h>
55 
56 #include <sys/types.h>
57 
58 /* some string constants that are used in the config file */
59 
60 #define SANE_EPSON_CONFIG_USB "usb"
61 #define SANE_EPSON_CONFIG_PIO "pio"
62 
63 /* string constants for GUI elements that are not defined SANE-wide */
64 
65 #define SANE_NAME_GAMMA_CORRECTION "gamma-correction"
66 #define SANE_TITLE_GAMMA_CORRECTION SANE_I18N("Gamma Correction")
67 #define SANE_DESC_GAMMA_CORRECTION SANE_I18N("Selects the gamma correction value from a list of pre-defined devices or the user defined table, which can be downloaded to the scanner")
68 
69 #define SANE_EPSON_FOCUS_NAME "focus-position"
70 #define SANE_EPSON_FOCUS_TITLE SANE_I18N("Focus Position")
71 #define SANE_EPSON_FOCUS_DESC SANE_I18N("Sets the focus position to either the glass or 2.5mm above the glass")
72 #define SANE_EPSON_WAIT_FOR_BUTTON_NAME "wait-for-button"
73 #define SANE_EPSON_WAIT_FOR_BUTTON_TITLE SANE_I18N("Wait for Button")
74 #define SANE_EPSON_WAIT_FOR_BUTTON_DESC SANE_I18N("After sending the scan command, wait until the button on the scanner is pressed to actually start the scan process.");
75 
76 
77 #define LINES_SHUFFLE_MAX	(17)	/* 2 x 8 lines plus 1 */
78 
79 #define SANE_EPSON_MAX_RETRIES	(120)	/* how often do we retry during warmup ? */
80 
81 typedef struct
82 {
83   char *level;
84 
85   unsigned char request_identity;
86   unsigned char request_identity2;	/* new request identity command for Dx command level */
87   unsigned char request_status;
88   unsigned char request_condition;
89   unsigned char set_color_mode;
90   unsigned char start_scanning;
91   unsigned char set_data_format;
92   unsigned char set_resolution;
93   unsigned char set_zoom;
94   unsigned char set_scan_area;
95   unsigned char set_bright;
96   SANE_Range bright_range;
97   unsigned char set_gamma;
98   unsigned char set_halftoning;
99   unsigned char set_color_correction;
100   unsigned char initialize_scanner;
101   unsigned char set_speed;	/* B4 and later */
102   unsigned char set_lcount;
103   unsigned char mirror_image;	/* B5 and later */
104   unsigned char set_gamma_table;	/* B4 and later */
105   unsigned char set_outline_emphasis;	/* B4 and later */
106   unsigned char set_dither;	/* B4 and later */
107   unsigned char set_color_correction_coefficients;	/* B3 and later */
108   unsigned char request_extended_status;	/* get extended status from scanner */
109   unsigned char control_an_extension;	/* for extension control */
110   unsigned char eject;		/* for extension control */
111   unsigned char feed;
112   unsigned char request_push_button_status;
113   unsigned char control_auto_area_segmentation;
114   unsigned char set_film_type;	/* for extension control */
115   unsigned char set_exposure_time;	/* F5 only */
116   unsigned char set_bay;	/* F5 only */
117   unsigned char set_threshold;
118   unsigned char set_focus_position;	/* B8 only */
119   unsigned char request_focus_position;	/* B8 only */
120 } EpsonCmdRec, *EpsonCmd;
121 
122 enum
123 { OPT_NUM_OPTS =
124     0, OPT_MODE_GROUP, OPT_MODE, OPT_BIT_DEPTH, OPT_HALFTONE, OPT_DROPOUT,
125     OPT_BRIGHTNESS, OPT_SHARPNESS, OPT_GAMMA_CORRECTION, OPT_COLOR_CORRECTION,
126     OPT_RESOLUTION, OPT_THRESHOLD, OPT_ADVANCED_GROUP, OPT_MIRROR, OPT_SPEED,
127     OPT_AAS, OPT_LIMIT_RESOLUTION, OPT_ZOOM, /*	OPT_GAMMA_VECTOR */
128     OPT_GAMMA_VECTOR_R, OPT_GAMMA_VECTOR_G, OPT_GAMMA_VECTOR_B,
129     OPT_WAIT_FOR_BUTTON, OPT_CCT_GROUP, OPT_CCT_1, OPT_CCT_2, OPT_CCT_3,
130     OPT_CCT_4, OPT_CCT_5, OPT_CCT_6, OPT_CCT_7, OPT_CCT_8, OPT_CCT_9,
131     OPT_PREVIEW_GROUP, OPT_PREVIEW, OPT_PREVIEW_SPEED, OPT_GEOMETRY_GROUP,
132     OPT_TL_X, OPT_TL_Y, OPT_BR_X, OPT_BR_Y, OPT_QUICK_FORMAT, OPT_EQU_GROUP,
133     OPT_SOURCE, OPT_AUTO_EJECT, OPT_FILM_TYPE, OPT_FOCUS, OPT_BAY,
134     OPT_EJECT, OPT_ADF_MODE, NUM_OPTIONS
135 };
136 
137 typedef enum
138 {				/* hardware connection to the scanner */
139   SANE_EPSON_NODEV,		/* default, no HW specified yet */
140   SANE_EPSON_SCSI,		/* SCSI interface */
141   SANE_EPSON_PIO,		/* parallel interface */
142   SANE_EPSON_USB		/* USB interface */
143 } Epson_Connection_Type;
144 
145 
146 typedef struct
147 {
148   u_short opt_resolution;
149   u_char sensor;
150   u_char scan_order;
151   u_char line_dist1;
152   u_char line_dist2;
153 
154   u_short main_res1;
155   u_short main_res2;
156   u_short main_res3;
157   u_short main_res4;
158   u_short main_res5;
159   u_short main_res6;
160   u_short main_res7;
161 
162   u_short sub_res1;
163   u_short sub_res2;
164   u_short sub_res3;
165   u_short sub_res4;
166   u_short sub_res5;
167   u_short sub_res6;
168 } Epson_Identity2;
169 
170 
171 struct Epson_Device
172 {
173   struct Epson_Device *next;
174   SANE_Device sane;
175   SANE_Int level;
176   SANE_Range dpi_range;
177 
178   SANE_Range *x_range;		/* x range w/out extension */
179   SANE_Range *y_range;		/* y range w/out extension */
180 
181   SANE_Range fbf_x_range;	/* flattbed x range */
182   SANE_Range fbf_y_range;	/* flattbed y range */
183   SANE_Range adf_x_range;	/* autom. document feeder x range */
184   SANE_Range adf_y_range;	/* autom. document feeder y range */
185   SANE_Range tpu_x_range;	/* transparency unit x range */
186   SANE_Range tpu_y_range;	/* transparency unit y range */
187 
188   Epson_Connection_Type connection;
189   /* hardware interface type */
190 
191   SANE_Int *res_list;		/* list of resolutions */
192   SANE_Int res_list_size;	/* number of entries in this list */
193   SANE_Int last_res;		/* last selected resolution */
194   SANE_Int last_res_preview;	/* last selected preview resolution */
195 
196   SANE_Word *resolution_list;	/* for display purposes we store a second copy */
197 
198   SANE_Bool extension;		/* extension is installed */
199   SANE_Int use_extension;	/* use the installed extension */
200   SANE_Bool TPU;		/* TPU is installed */
201   SANE_Bool ADF;		/* ADF is installed */
202   SANE_Bool duplexSupport;	/* does the ADF handle duplex scanning */
203   SANE_Bool focusSupport;	/* does this scanner have support for "set focus position" ? */
204   SANE_Bool color_shuffle;	/* does this scanner need color shuffling */
205   SANE_Int maxDepth;		/* max. color depth */
206 
207   SANE_Int optical_res;		/* optical resolution */
208   SANE_Int max_line_distance;
209 
210   SANE_Bool need_double_vertical;
211   SANE_Bool need_color_reorder;
212   SANE_Bool need_reset_on_source_change;
213 
214   SANE_Bool wait_for_button;	/* do we have to wait until the scanner button is pressed? */
215 
216   SANE_Int fbf_max_x;
217   SANE_Int fbf_max_y;
218   SANE_Int adf_max_x;
219   SANE_Int adf_max_y;
220 
221   SANE_Int devtype;
222 
223 
224   EpsonCmd cmd;
225 };
226 
227 typedef struct Epson_Device Epson_Device;
228 
229 
230 
231 struct Epson_Scanner
232 {
233   struct Epson_Scanner *next;
234   int fd;
235   Epson_Device *hw;
236   SANE_Option_Descriptor opt[NUM_OPTIONS];
237   Option_Value val[NUM_OPTIONS];
238   SANE_Parameters params;
239   SANE_Bool block;
240   SANE_Bool eof;
241   SANE_Byte *buf, *end, *ptr;
242   SANE_Bool canceling;
243   SANE_Bool invert_image;
244   SANE_Bool focusOnGlass;
245   SANE_Byte currentFocusPosition;
246 /*	SANE_Word gamma_table [ 4] [ 256]; */
247   SANE_Word gamma_table[3][256];
248   SANE_Int retry_count;
249   SANE_Byte *line_buffer[LINES_SHUFFLE_MAX];
250   /* buffer lines for color shuffling */
251   SANE_Int color_shuffle_line;	/* current line number for color shuffling */
252   SANE_Int line_distance;	/* current line distance */
253   SANE_Int current_output_line;	/* line counter when color shuffling */
254   SANE_Int lines_written;	/* debug variable */
255   SANE_Bool option_has_changed;	/* did one of the options change it's value? */
256 };
257 
258 typedef struct Epson_Scanner Epson_Scanner;
259 
260 #endif /* not epson_h */
261