1 /* sane - Scanner Access Now Easy.
2
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 #ifndef ibm_h
42 #define ibm_h 1
43
44 #include <sys/types.h>
45
46 #include "../include/sane/config.h"
47
48 /* defines for scan_image_mode field */
49 #define IBM_BINARY_MONOCHROME 0
50 #define IBM_DITHERED_MONOCHROME 1
51 #define IBM_GRAYSCALE 2
52
53 /* defines for paper field */
54 #define IBM_PAPER_USER_DEFINED 0
55 #define IBM_PAPER_A3 1
56 #define IBM_PAPER_A4 2
57 #define IBM_PAPER_A4L 3
58 #define IBM_PAPER_A5 4
59 #define IBM_PAPER_A5L 5
60 #define IBM_PAPER_A6 6
61 #define IBM_PAPER_B4 7
62 #define IBM_PAPER_B5 8
63 #define IBM_PAPER_LEGAL 9
64 #define IBM_PAPER_LETTER 10
65
66 /* sizes for mode parameter's base_measurement_unit */
67 #define INCHES 0
68 #define MILLIMETERS 1
69 #define POINTS 2
70 #define DEFAULT_MUD 1200
71 #define MEASUREMENTS_PAGE (SANE_Byte)(0x03)
72
73 /* Mode Page Control */
74 #define PC_CURRENT 0x00
75 #define PC_CHANGE 0x40
76 #define PC_DEFAULT 0x80
77 #define PC_SAVED 0xc0
78
79 static const SANE_String_Const mode_list[] =
80 {
81 SANE_VALUE_SCAN_MODE_LINEART,
82 SANE_VALUE_SCAN_MODE_HALFTONE,
83 SANE_VALUE_SCAN_MODE_GRAY,
84 0
85 };
86
87 static const SANE_String_Const paper_list[] =
88 {
89 "User",
90 "A3",
91 "A4", "A4R",
92 "A5", "A5R",
93 "A6",
94 "B4", "B5",
95 "Legal", "Letter",
96 0
97 };
98
99 #define PAPER_A3_W 14032
100 #define PAPER_A3_H 19842
101 #define PAPER_A4_W 9921
102 #define PAPER_A4_H 14032
103 #define PAPER_A4R_W 14032
104 #define PAPER_A4R_H 9921
105 #define PAPER_A5_W 7016
106 #define PAPER_A5_H 9921
107 #define PAPER_A5R_W 9921
108 #define PAPER_A5R_H 7016
109 #define PAPER_A6_W 4960
110 #define PAPER_A6_H 7016
111 #define PAPER_B4_W 11811
112 #define PAPER_B4_H 16677
113 #define PAPER_B5_W 8598
114 #define PAPER_B5_H 12142
115 #define PAPER_LEGAL_W 10200
116 #define PAPER_LEGAL_H 16800
117 #define PAPER_LETTER_W 10200
118 #define PAPER_LETTER_H 13200
119
120 static const SANE_Range u8_range =
121 {
122 0, /* minimum */
123 255, /* maximum */
124 0 /* quantization */
125 };
126
127 static const SANE_Range ibm2456_res_range =
128 {
129 100, /* minimum */
130 600, /* maximum */
131 0 /* quantization */
132 };
133
134 static const SANE_Range default_x_range =
135 {
136 0, /* minimum */
137 /* (SANE_Word) ( * DEFAULT_MUD), maximum */
138 14032, /* maximum (found empirically for Gray mode) */
139 /* in Lineart mode it works till 14062 */
140 2 /* quantization */
141 };
142
143 static const SANE_Range default_y_range =
144 {
145 0, /* minimum */
146 /* (SANE_Word) (14 * DEFAULT_MUD), maximum */
147 20410, /* maximum (found empirically) */
148 2 /* quantization */
149 };
150
151
152
153 static inline void
_lto2b(SANE_Int val,SANE_Byte * bytes)154 _lto2b(SANE_Int val, SANE_Byte *bytes)
155
156 {
157
158 bytes[0] = (val >> 8) & 0xff;
159 bytes[1] = val & 0xff;
160 }
161
162 static inline void
_lto3b(SANE_Int val,SANE_Byte * bytes)163 _lto3b(SANE_Int val, SANE_Byte *bytes)
164
165 {
166
167 bytes[0] = (val >> 16) & 0xff;
168 bytes[1] = (val >> 8) & 0xff;
169 bytes[2] = val & 0xff;
170 }
171
172 static inline void
_lto4b(SANE_Int val,SANE_Byte * bytes)173 _lto4b(SANE_Int val, SANE_Byte *bytes)
174 {
175
176 bytes[0] = (val >> 24) & 0xff;
177 bytes[1] = (val >> 16) & 0xff;
178 bytes[2] = (val >> 8) & 0xff;
179 bytes[3] = val & 0xff;
180 }
181
182 static inline SANE_Int
_2btol(SANE_Byte * bytes)183 _2btol(SANE_Byte *bytes)
184 {
185 SANE_Int rv;
186
187 rv = (bytes[0] << 8) |
188 bytes[1];
189 return (rv);
190 }
191
192 static inline SANE_Int
_3btol(SANE_Byte * bytes)193 _3btol(SANE_Byte *bytes)
194 {
195 SANE_Int rv;
196
197 rv = (bytes[0] << 16) |
198 (bytes[1] << 8) |
199 bytes[2];
200 return (rv);
201 }
202
203 static inline SANE_Int
_4btol(SANE_Byte * bytes)204 _4btol(SANE_Byte *bytes)
205 {
206 SANE_Int rv;
207
208 rv = (bytes[0] << 24) |
209 (bytes[1] << 16) |
210 (bytes[2] << 8) |
211 bytes[3];
212 return (rv);
213 }
214
215 typedef enum
216 {
217 OPT_NUM_OPTS = 0,
218
219 OPT_MODE_GROUP,
220 OPT_MODE,
221 OPT_X_RESOLUTION,
222 OPT_Y_RESOLUTION,
223 OPT_ADF,
224
225 OPT_GEOMETRY_GROUP,
226 OPT_PAPER, /* predefined formats */
227 OPT_TL_X, /* top-left x */
228 OPT_TL_Y, /* top-left y */
229 OPT_BR_X, /* bottom-right x */
230 OPT_BR_Y, /* bottom-right y */
231
232 OPT_ENHANCEMENT_GROUP,
233 OPT_BRIGHTNESS,
234 OPT_CONTRAST,
235
236 /* must come last: */
237 NUM_OPTIONS
238 }
239 Ibm_Option;
240
241 typedef struct Ibm_Info
242 {
243 SANE_Range xres_range;
244 SANE_Range yres_range;
245 SANE_Range x_range;
246 SANE_Range y_range;
247 SANE_Range brightness_range;
248 SANE_Range contrast_range;
249
250 SANE_Int xres_default;
251 SANE_Int yres_default;
252 SANE_Int image_mode_default;
253 SANE_Int paper_default;
254 SANE_Int brightness_default;
255 SANE_Int contrast_default;
256 SANE_Int adf_default;
257
258 SANE_Int bmu;
259 SANE_Int mud;
260 }
261 Ibm_Info;
262
263 typedef struct Ibm_Device
264 {
265 struct Ibm_Device *next;
266 SANE_Device sane;
267 Ibm_Info info;
268 }
269 Ibm_Device;
270
271 typedef struct Ibm_Scanner
272 {
273 /* all the state needed to define a scan request: */
274 struct Ibm_Scanner *next;
275 int fd; /* SCSI filedescriptor */
276
277 SANE_Option_Descriptor opt[NUM_OPTIONS];
278 Option_Value val[NUM_OPTIONS];
279 SANE_Parameters params;
280 /* scanner dependent/low-level state: */
281 Ibm_Device *hw;
282
283 SANE_Int xres;
284 SANE_Int yres;
285 SANE_Int ulx;
286 SANE_Int uly;
287 SANE_Int width;
288 SANE_Int length;
289 SANE_Int brightness;
290 SANE_Int contrast;
291 SANE_Int image_composition;
292 SANE_Int bpp;
293 SANE_Bool reverse;
294 /* next lines by mf */
295 SANE_Int adf_state;
296 #define ADF_UNUSED 0 /* scan from flatbed, not ADF */
297 #define ADF_ARMED 1 /* scan from ADF, everything's set up */
298 #define ADF_CLEANUP 2 /* eject paper from ADF on close */
299 /* end lines by mf */
300 size_t bytes_to_read;
301 int scanning;
302 }
303 Ibm_Scanner;
304
305 struct inquiry_data {
306 SANE_Byte devtype;
307 SANE_Byte byte2;
308 SANE_Byte byte3;
309 SANE_Byte byte4;
310 SANE_Byte byte5;
311 SANE_Byte res1[2];
312 SANE_Byte flags;
313 SANE_Byte vendor[8];
314 SANE_Byte product[8];
315 SANE_Byte revision[4];
316 SANE_Byte byte[60];
317 };
318
319 #define IBM_WINDOW_DATA_SIZE 320
320 struct ibm_window_data {
321 /* header */
322 SANE_Byte reserved[6];
323 SANE_Byte len[2];
324 /* data */
325 SANE_Byte window_id; /* must be zero */
326 SANE_Byte reserved0;
327 SANE_Byte x_res[2];
328 SANE_Byte y_res[2];
329 SANE_Byte x_org[4];
330 SANE_Byte y_org[4];
331 SANE_Byte width[4];
332 SANE_Byte length[4];
333 SANE_Byte brightness;
334 SANE_Byte threshold;
335 SANE_Byte contrast;
336 SANE_Byte image_comp; /* image composition (data type) */
337 SANE_Byte bits_per_pixel;
338 SANE_Byte halftone_code; /* halftone_pattern[0] in ricoh.h */
339 SANE_Byte halftone_id; /* halftone_pattern[1] in ricoh.h */
340 SANE_Byte pad_type;
341 SANE_Byte bit_ordering[2];
342 SANE_Byte compression_type;
343 SANE_Byte compression_arg;
344 SANE_Byte res3[6];
345
346 /* Vendor Specific parameter byte(s) */
347 /* Ricoh specific, follow the scsi2 standard ones */
348 SANE_Byte byte1;
349 SANE_Byte byte2;
350 SANE_Byte mrif_filtering_gamma_id;
351 SANE_Byte byte3;
352 SANE_Byte byte4;
353 SANE_Byte binary_filter;
354 SANE_Byte reserved2[18];
355
356 SANE_Byte reserved3[256];
357
358 };
359
360 struct measurements_units_page {
361 SANE_Byte page_code; /* 0x03 */
362 SANE_Byte parameter_length; /* 0x06 */
363 SANE_Byte bmu;
364 SANE_Byte res1;
365 SANE_Byte mud[2];
366 SANE_Byte res2[2]; /* anybody know what `COH' may mean ??? */
367 /* next 4 lines by mf */
368 SANE_Byte adf_page_code;
369 SANE_Byte adf_parameter_length;
370 SANE_Byte adf_control;
371 SANE_Byte res3[5];
372 };
373
374 struct mode_pages {
375 SANE_Byte page_code;
376 SANE_Byte parameter_length;
377 SANE_Byte rest[14]; /* modified by mf; it was 6; see above */
378 #if 0
379 SANE_Byte more_pages[243]; /* maximum size 255 bytes (incl header) */
380 #endif
381 };
382
383
384 #endif /* ibm_h */
385