1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
|
#ifndef KODAK_H
#define KODAK_H
/*
* Part of SANE - Scanner Access Now Easy.
* Please see opening comment in kodak.c
*/
/* -------------------------------------------------------------------------
* This option list has to contain all options for all scanners supported by
* this driver. If a certain scanner cannot handle a certain option, there's
* still the possibility to say so, later.
*/
enum kodak_Option
{
OPT_NUM_OPTS = 0,
OPT_MODE_GROUP,
OPT_SOURCE, /*front/back/duplex*/
OPT_MODE, /*mono/ht/gray/color*/
OPT_RES,
OPT_GEOMETRY_GROUP,
OPT_TL_X,
OPT_TL_Y,
OPT_BR_X,
OPT_BR_Y,
OPT_PAGE_WIDTH,
OPT_PAGE_HEIGHT,
OPT_ENHANCEMENT_GROUP,
OPT_BRIGHTNESS,
OPT_CONTRAST,
OPT_THRESHOLD,
OPT_RIF,
/* must come last: */
NUM_OPTIONS
};
struct scanner
{
/* --------------------------------------------------------------------- */
/* immutable values which are set during init of scanner. */
struct scanner *next;
char *device_name; /* The name of the scanner device for sane */
/* --------------------------------------------------------------------- */
/* immutable values which are set during reading of config file. */
int buffer_size;
/* --------------------------------------------------------------------- */
/* immutable values which are set during inquiry probing of the scanner. */
/* members in order found in scsi data... */
SANE_Device sane;
char vendor_name[9]; /* null-term data returned by SCSI inquiry.*/
char product_name[17]; /* null-term data returned by SCSI inquiry.*/
char version_name[5]; /* null-term data returned by SCSI inquiry.*/
char build_name[3]; /* null-term data returned by SCSI inquiry.*/
/* --------------------------------------------------------------------- */
/* immutable values which are set during INQUIRY probing of the scanner, */
/* or in the init_model cleanup routine... */
/* which modes scanner has */
int s_mode[4];
/* min and max resolution for each mode */
int s_res_min[4];
int s_res_max[4];
/* in 1/1200th inches, NOT sane units */
int s_width_min;
int s_width_max;
int s_length_min;
int s_length_max;
int s_brightness_steps;
int s_contrast_steps;
int s_threshold_steps;
int s_rif;
/* --------------------------------------------------------------------- */
/* changeable SANE_Option structs provide our interface to frontend. */
/* some options require lists of strings or numbers, we keep them here */
/* instead of in global vars so that they can differ for each scanner */
/* long array of option structs */
SANE_Option_Descriptor opt[NUM_OPTIONS];
/*mode group*/
SANE_String_Const o_source_list[4];
SANE_String_Const o_mode_list[5];
SANE_Int o_res_list[4][6];
/*geometry group*/
SANE_Range o_tl_x_range;
SANE_Range o_tl_y_range;
SANE_Range o_br_x_range;
SANE_Range o_br_y_range;
SANE_Range o_page_x_range;
SANE_Range o_page_y_range;
/*enhancement group*/
SANE_Range o_brightness_range;
SANE_Range o_contrast_range;
SANE_Range o_threshold_range;
/* --------------------------------------------------------------------- */
/* changeable vars to hold user input. modified by SANE_Options above */
/*mode group*/
int u_mode; /* color,lineart,etc */
int u_source; /* adf front,adf duplex,etc */
int u_res; /* resolution in dpi */
/*geometry group*/
/* The desired size of the scan, all in 1/1200 inch */
int u_tl_x;
int u_tl_y;
int u_br_x;
int u_br_y;
int u_page_width;
int u_page_height;
/*enhancement group*/
int u_brightness;
int u_contrast;
int u_threshold;
int u_rif;
int u_compr;
/* --------------------------------------------------------------------- */
/* values which are set by the scanner's post-scan image header */
int i_bytes;
int i_id;
int i_dpi;
int i_tlx;
int i_tly;
int i_width;
int i_length;
int i_bpp;
int i_compr;
/* --------------------------------------------------------------------- */
/* values which are set by scanning functions to keep track of pages, etc */
int started;
/* total to read/write */
int bytes_tot;
/* how far we have read */
int bytes_rx;
/* how far we have written */
int bytes_tx;
/* size of buffer */
int bytes_buf;
/* the buffer */
unsigned char * buffer;
/* --------------------------------------------------------------------- */
/* values which used by the command and data sending functions (scsi/usb)*/
int fd; /* The scanner device file descriptor. */
size_t rs_info;
};
#define DEFAULT_BUFFER_SIZE 32768
#define SIDE_FRONT 0
#define SIDE_BACK 1
#define SOURCE_ADF_FRONT 0
#define SOURCE_ADF_BACK 1
#define SOURCE_ADF_DUPLEX 2
#define MODE_LINEART 0
#define MODE_HALFTONE 1
#define MODE_GRAYSCALE 2
#define MODE_COLOR 3
/* ------------------------------------------------------------------------- */
#define MM_PER_INCH 25.4
#define MM_PER_UNIT_UNFIX SANE_UNFIX(SANE_FIX(MM_PER_INCH / 1200.0))
#define MM_PER_UNIT_FIX SANE_FIX(SANE_UNFIX(SANE_FIX(MM_PER_INCH / 1200.0)))
#define SCANNER_UNIT_TO_FIXED_MM(number) SANE_FIX((number) * MM_PER_UNIT_UNFIX)
#define FIXED_MM_TO_SCANNER_UNIT(number) SANE_UNFIX(number) / MM_PER_UNIT_UNFIX
#define KODAK_CONFIG_FILE "kodak.conf"
#ifndef PATH_MAX
# define PATH_MAX 1024
#endif
/* ------------------------------------------------------------------------- */
SANE_Status sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize);
SANE_Status sane_get_devices (const SANE_Device *** device_list,
SANE_Bool local_only);
SANE_Status sane_open (SANE_String_Const name, SANE_Handle * handle);
SANE_Status sane_set_io_mode (SANE_Handle h, SANE_Bool non_blocking);
SANE_Status sane_get_select_fd (SANE_Handle h, SANE_Int * fdp);
const SANE_Option_Descriptor * sane_get_option_descriptor (SANE_Handle handle,
SANE_Int option);
SANE_Status sane_control_option (SANE_Handle handle, SANE_Int option,
SANE_Action action, void *val,
SANE_Int * info);
SANE_Status sane_start (SANE_Handle handle);
SANE_Status sane_get_parameters (SANE_Handle handle,
SANE_Parameters * params);
SANE_Status sane_read (SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len,
SANE_Int * len);
void sane_cancel (SANE_Handle h);
void sane_close (SANE_Handle h);
void sane_exit (void);
/* ------------------------------------------------------------------------- */
static SANE_Status attach_one (const char *name);
static SANE_Status connect_fd (struct scanner *s);
static SANE_Status disconnect_fd (struct scanner *s);
static SANE_Status sense_handler (int scsi_fd, u_char * result, void *arg);
static SANE_Status init_inquire (struct scanner *s);
static SANE_Status init_model (struct scanner *s);
static SANE_Status init_user (struct scanner *s);
static SANE_Status init_options (struct scanner *s);
static SANE_Status
do_cmd(struct scanner *s, int runRS, int shortTime,
unsigned char * cmdBuff, size_t cmdLen,
unsigned char * outBuff, size_t outLen,
unsigned char * inBuff, size_t * inLen
);
#if 0 /* unused */
static SANE_Status wait_scanner (struct scanner *s);
#endif
static SANE_Status do_cancel (struct scanner *scanner);
static SANE_Status set_window (struct scanner *s);
static SANE_Status read_imageheader(struct scanner *s);
static SANE_Status send_sc(struct scanner *s);
static SANE_Status read_from_scanner(struct scanner *s);
static SANE_Status copy_buffer(struct scanner *s, unsigned char * buf, int len);
static SANE_Status read_from_buffer(struct scanner *s, SANE_Byte * buf, SANE_Int max_len, SANE_Int * len);
static void hexdump (int level, char *comment, unsigned char *p, int l);
static size_t maxStringSize (const SANE_String_Const strings[]);
#endif /* KODAK_H */
|