1 /* sane - Scanner Access Now Easy.
2    Copyright (C) 1996 David Mosberger-Tang
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    This file implements a SANE backend for the Artec/Ultima scanners.
40 
41    Copyright (C) 1998,1999 Chris Pinkham
42    Released under the terms of the GPL.
43    *NO WARRANTY*
44 
45    *********************************************************************
46    For feedback/information:
47 
48    cpinkham@corp.infi.net
49    http://www4.infi.net/~cpinkham/sane/sane-artec-doc.html
50    *********************************************************************
51  */
52 
53 #ifndef artec_h
54 #define artec_h
55 
56 #include <sys/types.h>
57 
58 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
59 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
60 
61 #define ARTEC_MIN_X( hw )	( hw->horz_resolution_list[ 0 ] ? \
62 							hw->horz_resolution_list[ 1 ] : 0 )
63 #define ARTEC_MAX_X( hw )	( hw->horz_resolution_list[ 0 ] ? \
64 							hw->horz_resolution_list[ \
65 								hw->horz_resolution_list[ 0 ] ] : 0 )
66 #define ARTEC_MIN_Y( hw )	( hw->vert_resolution_list[ 0 ] ? \
67 							hw->vert_resolution_list[ 1 ] : 0 )
68 #define ARTEC_MAX_Y( hw )	( hw->vert_resolution_list[ 0 ] ? \
69 							hw->vert_resolution_list[ \
70 								hw->vert_resolution_list[ 0 ] ] : 0 )
71 
72 typedef enum
73   {
74     OPT_NUM_OPTS = 0,
75 
76     OPT_MODE_GROUP,
77     OPT_MODE,
78     OPT_X_RESOLUTION,
79     OPT_Y_RESOLUTION,
80     OPT_RESOLUTION_BIND,
81     OPT_PREVIEW,
82     OPT_GRAY_PREVIEW,
83     OPT_NEGATIVE,
84 
85     OPT_GEOMETRY_GROUP,
86     OPT_TL_X,			/* top-left x */
87     OPT_TL_Y,			/* top-left y */
88     OPT_BR_X,			/* bottom-right x */
89     OPT_BR_Y,			/* bottom-right y */
90 
91     OPT_ENHANCEMENT_GROUP,
92     OPT_CONTRAST,
93     OPT_BRIGHTNESS,
94     OPT_THRESHOLD,
95     OPT_HALFTONE_PATTERN,
96     OPT_FILTER_TYPE,
97     OPT_PIXEL_AVG,
98     OPT_EDGE_ENH,
99 
100     OPT_CUSTOM_GAMMA, /* use custom gamma table */
101     OPT_GAMMA_VECTOR,
102     OPT_GAMMA_VECTOR_R,
103     OPT_GAMMA_VECTOR_G,
104     OPT_GAMMA_VECTOR_B,
105 
106     OPT_TRANSPARENCY,
107     OPT_ADF,
108 
109     OPT_CALIBRATION_GROUP,
110     OPT_QUALITY_CAL,
111     OPT_SOFTWARE_CAL,
112 
113     /* must come last */
114     NUM_OPTIONS
115   }
116 ARTEC_Option;
117 
118 /* Some FLAGS */
119 #define ARTEC_FLAG_CALIBRATE			0x00000001 /* supports hardware calib */
120 #define ARTEC_FLAG_CALIBRATE_RGB		0x00000003 /* yes 3, set CALIB. also */
121 #define ARTEC_FLAG_CALIBRATE_DARK_WHITE	0x00000005 /* yes 5, set CALIB. also */
122 #define ARTEC_FLAG_RGB_LINE_OFFSET		0x00000008 /* need line offset buffer */
123 #define ARTEC_FLAG_RGB_CHAR_SHIFT		0x00000010 /* RRRRGGGGBBBB line fmt */
124 #define ARTEC_FLAG_OPT_CONTRAST         0x00000020 /* supports set contrast */
125 #define ARTEC_FLAG_ONE_PASS_SCANNER		0x00000040 /* single pass scanner */
126 #define ARTEC_FLAG_GAMMA				0x00000080 /* supports set gamma */
127 #define ARTEC_FLAG_GAMMA_SINGLE			0x00000180 /* yes 180, implies GAMMA */
128 #define ARTEC_FLAG_SEPARATE_RES			0x00000200 /* separate x & y scan res */
129 #define ARTEC_FLAG_IMAGE_REV_LR         0x00000400 /* reversed left-right */
130 #define ARTEC_FLAG_ENHANCE_LINE_EDGE    0x00000800 /* line edge enhancement */
131 #define ARTEC_FLAG_HALFTONE_PATTERN     0x00001000 /* > 1 halftone  pattern */
132 #define ARTEC_FLAG_REVERSE_WINDOW       0x00002000 /* reverse selected area */
133 #define ARTEC_FLAG_SC_BUFFERS_LINES     0x00004000 /* scanner has line buffer */
134 #define ARTEC_FLAG_SC_HANDLES_OFFSET    0x00008000 /* sc. handles line offset */
135 #define ARTEC_FLAG_SENSE_HANDLER        0x00010000 /* supports sense handler */
136 #define ARTEC_FLAG_SENSE_ENH_18         0x00020000 /* supports enh. byte 18 */
137 #define ARTEC_FLAG_SENSE_BYTE_19        0x00040000 /* supports sense byte 19 */
138 #define ARTEC_FLAG_SENSE_BYTE_22        0x00080000 /* supports sense byte 22 */
139 #define ARTEC_FLAG_PIXEL_AVERAGING      0x00100000 /* supports pixel avg-ing */
140 #define ARTEC_FLAG_ADF                  0x00200000 /* auto document feeder */
141 #define ARTEC_FLAG_OPT_BRIGHTNESS       0x00400000 /* supports set brightness */
142 #define ARTEC_FLAG_MBPP_NEGATIVE        0x00800000 /* can negate > 1bpp modes */
143 
144 typedef enum
145   {
146     ARTEC_COMP_LINEART = 0,
147     ARTEC_COMP_HALFTONE,
148     ARTEC_COMP_GRAY,
149     ARTEC_COMP_UNSUPP1,
150     ARTEC_COMP_UNSUPP2,
151     ARTEC_COMP_COLOR
152   }
153 ARTEC_Image_Composition;
154 
155 typedef enum
156   {
157     ARTEC_DATA_IMAGE = 0,
158     ARTEC_DATA_UNSUPP1,
159     ARTEC_DATA_HALFTONE_PATTERN,	/* 2 */
160     ARTEC_DATA_UNSUPP3,
161     ARTEC_DATA_RED_SHADING,	/* 4 */
162     ARTEC_DATA_GREEN_SHADING,	/* 5 */
163     ARTEC_DATA_BLUE_SHADING,	/* 6 */
164     ARTEC_DATA_WHITE_SHADING_OPT,	/* 7 */
165     ARTEC_DATA_WHITE_SHADING_TRANS,	/* 8 */
166     ARTEC_DATA_CAPABILITY_DATA,	/* 9 */
167     ARTEC_DATA_DARK_SHADING,	/* 10, 0xA */
168     ARTEC_DATA_RED_GAMMA_CURVE,	/* 11, 0xB */
169     ARTEC_DATA_GREEN_GAMMA_CURVE,	/* 12, 0xC */
170     ARTEC_DATA_BLUE_GAMMA_CURVE,	/* 13, 0xD */
171     ARTEC_DATA_ALL_GAMMA_CURVE	/* 14, 0xE */
172   }
173 ARTEC_Read_Data_Type;
174 
175 typedef enum
176   {
177     ARTEC_CALIB_RGB = 0,
178     ARTEC_CALIB_DARK_WHITE
179   }
180 ARTEC_Calibrate_Method;
181 
182 typedef enum
183   {
184     ARTEC_FILTER_MONO = 0,
185     ARTEC_FILTER_RED,
186     ARTEC_FILTER_GREEN,
187     ARTEC_FILTER_BLUE
188   }
189 ARTEC_Filter_Type;
190 
191 typedef enum
192   {
193     ARTEC_SOFT_CALIB_RED = 0,
194 	ARTEC_SOFT_CALIB_GREEN,
195 	ARTEC_SOFT_CALIB_BLUE
196   }
197 ARTEC_Software_Calibrate;
198 
199 
200 typedef struct ARTEC_Device
201   {
202     struct ARTEC_Device *next;
203     SANE_Device sane;
204     double width;
205     SANE_Range x_range;
206     SANE_Word *horz_resolution_list;
207     double height;
208     SANE_Range y_range;
209     SANE_Word *vert_resolution_list;
210     SANE_Range threshold_range;
211     SANE_Range contrast_range;
212     SANE_Range brightness_range;
213     SANE_Word setwindow_cmd_size;
214     SANE_Word calibrate_method;
215 	SANE_Word max_read_size;
216 
217     long flags;
218     SANE_Bool support_cap_data_retrieve;
219     SANE_Bool req_shading_calibrate;
220     SANE_Bool req_rgb_line_offset;
221     SANE_Bool req_rgb_char_shift;
222 
223     /* info for 1-pass vs. 3-pass */
224     SANE_Bool onepass;
225 
226     SANE_Bool support_gamma;
227     SANE_Bool single_gamma;
228 	SANE_Int gamma_length;
229   }
230 ARTEC_Device;
231 
232 typedef struct ARTEC_Scanner
233   {
234     /* all the state needed to define a scan request: */
235     struct ARTEC_Scanner *next;
236 
237     SANE_Option_Descriptor opt[NUM_OPTIONS];
238     Option_Value val[NUM_OPTIONS];
239 
240 	SANE_Int gamma_table[4][4096];
241 	double soft_calibrate_data[3][2592];
242 	SANE_Int halftone_pattern[64];
243 	SANE_Range gamma_range;
244 	int gamma_length;
245 
246     int scanning;
247     SANE_Parameters params;
248     size_t bytes_to_read;
249     SANE_Int line_offset;
250 
251     /* scan parameters */
252     char *mode;
253     SANE_Int x_resolution;
254     SANE_Int y_resolution;
255     SANE_Int tl_x;
256     SANE_Int tl_y;
257 
258     /* info for 1-pass vs. 3-pass */
259     int this_pass;
260     SANE_Bool onepasscolor;
261     SANE_Bool threepasscolor;
262 
263     int fd;			/* SCSI filedescriptor */
264 
265     /* scanner dependent/low-level state: */
266     ARTEC_Device *hw;
267   }
268 ARTEC_Scanner;
269 
270 #endif /* artec_h */
271