1 /* sane - Scanner Access Now Easy.
2    Copyright (C) 1998, Feico W. Dillema
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 #ifndef ricoh_h
41 #define ricoh_h 1
42 
43 #include <sys/types.h>
44 
45 #include "../include/sane/config.h"
46 
47 /* defines for scan_image_mode field */
48 #define RICOH_BINARY_MONOCHROME   0
49 #define RICOH_DITHERED_MONOCHROME 1
50 #define RICOH_GRAYSCALE           2
51 
52 /* sizes for mode parameter's base_measurement_unit */
53 #define INCHES                    0
54 #define MILLIMETERS               1
55 #define POINTS                    2
56 #define DEFAULT_MUD               1200
57 #define MEASUREMENTS_PAGE         (SANE_Byte)(0x03)
58 
59 /* Mode Page Control */
60 #define PC_CURRENT 0x00
61 #define PC_CHANGE  0x40
62 #define PC_DEFAULT 0x80
63 #define PC_SAVED   0xc0
64 
65 static const SANE_String_Const mode_list[] =
66   {
67     SANE_VALUE_SCAN_MODE_LINEART,
68     SANE_VALUE_SCAN_MODE_HALFTONE,
69     SANE_VALUE_SCAN_MODE_GRAY,
70     0
71   };
72 
73 static const SANE_Range u8_range =
74   {
75       0,				/* minimum */
76     255,				/* maximum */
77       0				        /* quantization */
78   };
79 static const SANE_Range is50_res_range =
80   {
81      75,                                /* minimum */
82     400,                                /* maximum */
83       0                                 /* quantization */
84   };
85 
86 static const SANE_Range is60_res_range =
87   {
88     100,				/* minimum */
89     600,				/* maximum */
90       0				        /* quantization */
91   };
92 
93 static const SANE_Range default_x_range =
94   {
95     0,				        /* minimum */
96     (SANE_Word) (8 * DEFAULT_MUD),	/* maximum */
97     2				        /* quantization */
98   };
99 
100 static const SANE_Range default_y_range =
101   {
102     0,				        /* minimum */
103     (SANE_Word) (14 * DEFAULT_MUD),	/* maximum */
104     2				        /* quantization */
105   };
106 
107 
108 
109 static inline void
_lto2b(SANE_Int val, SANE_Byte *bytes)110 _lto2b(SANE_Int val, SANE_Byte *bytes)
111 {
112 
113         bytes[0] = (val >> 8) & 0xff;
114         bytes[1] = val & 0xff;
115 }
116 
117 static inline void
_lto3b(SANE_Int val, SANE_Byte *bytes)118 _lto3b(SANE_Int val, SANE_Byte *bytes)
119 {
120 
121         bytes[0] = (val >> 16) & 0xff;
122         bytes[1] = (val >> 8) & 0xff;
123         bytes[2] = val & 0xff;
124 }
125 
126 static inline void
_lto4b(SANE_Int val, SANE_Byte *bytes)127 _lto4b(SANE_Int val, SANE_Byte *bytes)
128 {
129 
130         bytes[0] = (val >> 24) & 0xff;
131         bytes[1] = (val >> 16) & 0xff;
132         bytes[2] = (val >> 8) & 0xff;
133         bytes[3] = val & 0xff;
134 }
135 
136 static inline SANE_Int
_2btol(SANE_Byte *bytes)137 _2btol(SANE_Byte *bytes)
138 {
139         SANE_Int rv;
140 
141         rv = (bytes[0] << 8) |
142              bytes[1];
143         return (rv);
144 }
145 
146 static inline SANE_Int
_3btol(SANE_Byte *bytes)147 _3btol(SANE_Byte *bytes)
148 {
149         SANE_Int rv;
150 
151         rv = (bytes[0] << 16) |
152              (bytes[1] << 8) |
153              bytes[2];
154         return (rv);
155 }
156 
157 static inline SANE_Int
_4btol(SANE_Byte *bytes)158 _4btol(SANE_Byte *bytes)
159 {
160         SANE_Int rv;
161 
162         rv = (bytes[0] << 24) |
163              (bytes[1] << 16) |
164              (bytes[2] << 8) |
165              bytes[3];
166         return (rv);
167 }
168 
169 typedef enum
170   {
171     OPT_NUM_OPTS = 0,
172 
173     OPT_MODE_GROUP,
174     OPT_MODE,
175     OPT_X_RESOLUTION,
176     OPT_Y_RESOLUTION,
177 
178     OPT_GEOMETRY_GROUP,
179     OPT_TL_X,			/* top-left x */
180     OPT_TL_Y,			/* top-left y */
181     OPT_BR_X,			/* bottom-right x */
182     OPT_BR_Y,			/* bottom-right y */
183 
184     OPT_ENHANCEMENT_GROUP,
185     OPT_BRIGHTNESS,
186     OPT_CONTRAST,
187 
188     /* must come last: */
189     NUM_OPTIONS
190   }
191 Ricoh_Option;
192 
193 typedef struct Ricoh_Info
194   {
195     SANE_Range xres_range;
196     SANE_Range yres_range;
197     SANE_Range x_range;
198     SANE_Range y_range;
199     SANE_Range brightness_range;
200     SANE_Range contrast_range;
201 
202     SANE_Int xres_default;
203     SANE_Int yres_default;
204     SANE_Int image_mode_default;
205     SANE_Int brightness_default;
206     SANE_Int contrast_default;
207 
208     SANE_Int bmu;
209     SANE_Int mud;
210   }
211 Ricoh_Info;
212 
213 typedef struct Ricoh_Device
214   {
215     struct Ricoh_Device *next;
216     SANE_Device sane;
217     Ricoh_Info info;
218   }
219 Ricoh_Device;
220 
221 typedef struct Ricoh_Scanner
222   {
223     /* all the state needed to define a scan request: */
224     struct Ricoh_Scanner *next;
225     int fd;			/* SCSI filedescriptor */
226 
227     SANE_Option_Descriptor opt[NUM_OPTIONS];
228     Option_Value val[NUM_OPTIONS];
229     SANE_Parameters params;
230     /* scanner dependent/low-level state: */
231     Ricoh_Device *hw;
232 
233     SANE_Int xres;
234     SANE_Int yres;
235     SANE_Int ulx;
236     SANE_Int uly;
237     SANE_Int width;
238     SANE_Int length;
239     SANE_Int brightness;
240     SANE_Int contrast;
241     SANE_Int image_composition;
242     SANE_Int bpp;
243     SANE_Bool reverse;
244 
245     size_t bytes_to_read;
246     int scanning;
247   }
248 Ricoh_Scanner;
249 
250 struct inquiry_data {
251         SANE_Byte devtype;
252         SANE_Byte byte2;
253         SANE_Byte byte3;
254         SANE_Byte byte4;
255         SANE_Byte byte5;
256         SANE_Byte res1[2];
257         SANE_Byte flags;
258         SANE_Byte vendor[8];
259         SANE_Byte product[8];
260         SANE_Byte revision[4];
261         SANE_Byte byte[60];
262 };
263 
264 #define RICOH_WINDOW_DATA_SIZE 328
265 struct ricoh_window_data {
266         /* header */
267         SANE_Byte reserved[6];
268         SANE_Byte len[2];
269         /* data */
270         SANE_Byte window_id;         /* must be zero */
271         SANE_Byte auto_bit;
272         SANE_Byte x_res[2];
273         SANE_Byte y_res[2];
274         SANE_Byte x_org[4];
275         SANE_Byte y_org[4];
276         SANE_Byte width[4];
277         SANE_Byte length[4];
278         SANE_Byte brightness;
279         SANE_Byte threshold;
280         SANE_Byte contrast;
281         SANE_Byte image_comp;        /* image composition (data type) */
282         SANE_Byte bits_per_pixel;
283         SANE_Byte halftone_pattern[2];
284         SANE_Byte pad_type;
285         SANE_Byte bit_ordering[2];
286         SANE_Byte compression_type;
287         SANE_Byte compression_arg;
288         SANE_Byte res3[6];
289 
290         /* Vendor Specific parameter byte(s) */
291         /* Ricoh specific, follow the scsi2 standard ones */
292         SANE_Byte byte1;
293         SANE_Byte byte2;
294         SANE_Byte mrif_filtering_gamma_id;
295         SANE_Byte byte3;
296         SANE_Byte byte4;
297         SANE_Byte binary_filter;
298         SANE_Byte reserved2[18];
299 
300         SANE_Byte reserved3[256];
301 };
302 
303 struct measurements_units_page {
304         SANE_Byte page_code; /* 0x03 */
305         SANE_Byte parameter_length; /* 0x06 */
306         SANE_Byte bmu;
307         SANE_Byte res1;
308         SANE_Byte mud[2];
309         SANE_Byte res2[2];  /* anybody know what `COH' may mean ??? */
310 #if 0
311         SANE_Byte more_pages[243]; /* maximum size 255 bytes (incl header) */
312 #endif
313 };
314 
315 struct mode_pages {
316         SANE_Byte page_code;
317         SANE_Byte parameter_length;
318         SANE_Byte rest[6];
319 #if 0
320         SANE_Byte more_pages[243]; /* maximum size 255 bytes (incl header) */
321 #endif
322 };
323 
324 
325 #endif /* ricoh_h */
326