summaryrefslogtreecommitdiff
path: root/backend/sharp.h
blob: 67972243d86a1df4a8aa427f3594853adbfd35a8 (plain)
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
/* sane - Scanner Access Now Easy.

   Copyright (C) 1998, 1999 Kazuya Fukuda, Abel Deuring

   This file is part of the SANE package.

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston,
   MA 02111-1307, USA.

   As a special exception, the authors of SANE give permission for
   additional uses of the libraries contained in this release of SANE.

   The exception is that, if you link a SANE library with other files
   to produce an executable, this does not by itself cause the
   resulting executable to be covered by the GNU General Public
   License.  Your use of that executable is in no way restricted on
   account of linking the SANE library code into it.

   This exception does not, however, invalidate any other reasons why
   the executable file might be covered by the GNU General Public
   License.

   If you submit changes to SANE to the maintainers to be included in
   a subsequent release, you agree by submitting the changes that
   those changes may be distributed with this exception intact.

   If you write modifications of your own for SANE, it is your choice
   whether to permit this exception to apply to your modifications.
   If you do not wish that, delete this exception notice. */

#ifndef sharp_h
#define sharp_h 1

#include <sys/types.h>

/* default values for configurable options.
   Though these options are only meaningful if USE_FORK is defined,
   they are 
   DEFAULT_BUFFERS:      number of buffers allocated as shared memory
                         for the data transfer from reader_process to
                         read_data. The minimum value is 2
   DEFAULT_BUFSIZE:      default size of one buffer. Must be greater
                         than zero.
   DEFAULT_QUEUED_READS: number of read requests queued by 
                         sanei_scsi_req_enter. Since queued read requests
                         are currently only supported for Linux and 
                         DomainOS, this value should automatically be set
                         dependent on the target OS...
                         For Linux, 2 is the optimum; for DomainOS, I
                         don't have any recommendation; other OS
                         should use the value zero.
   
   The value for DEFAULT_BUFSIZE is probably too Linux-oriented...
*/

#define DEFAULT_BUFFERS 12
#define DEFAULT_BUFSIZE 128 * 1024
#define DEFAULT_QUEUED_READS 2

typedef enum
  {
    OPT_NUM_OPTS = 0,

    OPT_MODE_GROUP,
    OPT_MODE,
    OPT_HALFTONE,
    OPT_PAPER,
    OPT_SCANSOURCE,
    OPT_GAMMA,
#ifdef USE_CUSTOM_GAMMA
    OPT_CUSTOM_GAMMA,
#endif
    OPT_SPEED,

    OPT_RESOLUTION_GROUP,
#ifdef USE_RESOLUTION_LIST
    OPT_RESOLUTION_LIST,
#endif
    OPT_X_RESOLUTION,
#ifdef USE_SEPARATE_Y_RESOLUTION
    OPT_Y_RESOLUTION,
#endif

    OPT_GEOMETRY_GROUP,
    OPT_TL_X,			/* top-left x */
    OPT_TL_Y,			/* top-left y */
    OPT_BR_X,			/* bottom-right x */
    OPT_BR_Y,			/* bottom-right y */

    OPT_ENHANCEMENT_GROUP,
    OPT_EDGE_EMPHASIS,
    OPT_THRESHOLD,
#ifdef USE_COLOR_THRESHOLD
    OPT_THRESHOLD_R,
    OPT_THRESHOLD_G,
    OPT_THRESHOLD_B,
#endif
    OPT_LIGHTCOLOR,
    OPT_PREVIEW,

#ifdef USE_CUSTOM_GAMMA 
    OPT_GAMMA_VECTOR,
    OPT_GAMMA_VECTOR_R,
    OPT_GAMMA_VECTOR_G,
    OPT_GAMMA_VECTOR_B,
#endif
    /* must come last: */
    NUM_OPTIONS
  }
SHARP_Option;

#ifdef USE_FORK

/* status defines for a buffer: 
   buffer not used / read request queued / buffer contains data
*/
#define SHM_EMPTY 0
#define SHM_BUSY  1
#define SHM_FULL  2
typedef struct SHARP_shmem_ctl
  {
    int shm_status;   /* can be SHM_EMPTY, SHM_BUSY, SHM_FULL */
    size_t used;      /* number of bytes successfully read from scanner */
    size_t nreq;      /* number of bytes requested from scanner */
    size_t start;    /* index of the begin of used area of the buffer */
    void *qid;
    SANE_Byte *buffer;
  }
SHARP_shmem_ctl;

typedef struct SHARP_rdr_ctl
  {
    int cancel;      /* 1 = flag for the reader process to cancel */
    int running; /* 1 indicates that the reader process is alive */
    SANE_Status status; /* return status of the reader process */
    SHARP_shmem_ctl *buf_ctl;
  }
SHARP_rdr_ctl;
#endif /* USE_FORK */

typedef enum 
  {
    /* JX250, JX330, JX350, JX610 are used as array indices, so the
       corresponding numbers should start at 0
    */
    unknown = -1,
    JX250,
    JX320,
    JX330,
    JX350,
    JX610
  }
SHARP_Model;

typedef struct SHARP_Info
  {
    SANE_Range xres_range;
    SANE_Range yres_range;
    SANE_Range tl_x_ranges[3]; /* normal / FSU / ADF */
    SANE_Range br_x_ranges[3]; /* normal / FSU / ADF */
    SANE_Range tl_y_ranges[3]; /* normal / FSU / ADF */
    SANE_Range br_y_ranges[3]; /* normal / FSU / ADF */
    SANE_Range threshold_range;

    SANE_Int xres_default;
    SANE_Int yres_default;
    SANE_Int x_default;
    SANE_Int y_default;
    SANE_Int bmu;
    SANE_Int mud;
    SANE_Int adf_fsu_installed;
    SANE_String_Const scansources[5];
    size_t buffers;
    size_t bufsize;
    int wanted_bufsize;
    size_t queued_reads;
    int complain_on_errors;
    /* default scan mode: 
      -1 -> "automatic": Use the ADF, if installed, 
              else use the FSU, if installed.
      or: SCAN_ADF, SCAN_FSU, SCAN_SIMPLE
    */
    int default_scan_mode;
  }
SHARP_Info;

#define COMPLAIN_ON_FSU_ERROR 2
#define COMPLAIN_ON_ADF_ERROR 1
typedef struct SHARP_Sense_Data
  {
    SHARP_Model model;
    /* flag, if conditions like "paper jam" or "cover open" 
       are considered as an error. Should be 0 for attach, else
       a frontend might refuse to start, if the scanner returns
       these errors.
    */
    int complain_on_errors;
    /* Linux returns only 16 bytes of sense data... */
    u_char sb[16]; 
  }
SHARP_Sense_Data;

typedef struct SHARP_Device
  {
    struct SHARP_Device *next;
    SANE_Device sane;
    SHARP_Info info;
    /* xxx now part of sense data SHARP_Model model; */
    SHARP_Sense_Data sensedat;
  }
SHARP_Device;

typedef struct SHARP_New_Device 
  {
    struct SHARP_Device *dev;
    struct SHARP_New_Device *next;
  }
SHARP_New_Device;

typedef struct SHARP_Scanner
  {
    struct SHARP_Scanner *next;
    int fd;
    SHARP_Device *dev;
    SANE_Option_Descriptor opt[NUM_OPTIONS];
    Option_Value val[NUM_OPTIONS];
    SANE_Parameters params;

    int    get_params_called;
    SANE_Byte *buffer;    /* for color data re-ordering, required for JX 250 */
    SANE_Int buf_used;
    SANE_Int buf_pos;
    SANE_Int modes;
    SANE_Int xres;
    SANE_Int yres;
    SANE_Int ulx;
    SANE_Int uly;
    SANE_Int width;
    SANE_Int length;
    SANE_Int threshold;
    SANE_Int image_composition;
    SANE_Int bpp;
    SANE_Int halftone;
    SANE_Bool reverse;
    SANE_Bool speed;
    SANE_Int gamma;
    SANE_Int edge;
    SANE_Int lightcolor;
    SANE_Int adf_fsu_mode; /* mode selected by user */
    SANE_Int adf_scan; /* flag, if the actual scan is an ADF scan */

    size_t bytes_to_read;
    size_t max_lines_to_read;
    size_t unscanned_lines;
    SANE_Bool scanning;
    SANE_Bool busy;
    SANE_Bool cancel;
#ifdef USE_CUSTOM_GAMMA
    SANE_Int gamma_table[4][256];
#endif
#ifdef USE_FORK
    pid_t reader_pid;
    SHARP_rdr_ctl   *rdr_ctl;
    int shmid;
    size_t read_buff; /* index of the buffer actually used by read_data */
#endif /* USE_FORK */
  }
SHARP_Scanner;

typedef struct SHARP_Send
{
    SANE_Int dtc;
    SANE_Int dtq;
    SANE_Int length;
    SANE_Byte *data;
}
SHARP_Send;

typedef struct WPDH
{
    u_char wpdh[6];
    u_char wdl[2];
} 
WPDH;

typedef struct WDB
{
    SANE_Byte wid;
    SANE_Byte autobit;
    SANE_Byte x_res[2];
    SANE_Byte y_res[2];

    SANE_Byte x_ul[4];
    SANE_Byte y_ul[4];
    SANE_Byte width[4];
    SANE_Byte length[4];

    SANE_Byte brightness;
    SANE_Byte threshold;
    SANE_Byte null_1;

    SANE_Byte image_composition;
    SANE_Byte bpp;

    SANE_Byte ht_pattern[2];
    SANE_Byte rif_padding;
    SANE_Byte null_2[4];
    SANE_Byte null_3[6];
    SANE_Byte eletu;
    SANE_Byte zooming_x[2];
    SANE_Byte zooming_y[2];
    SANE_Byte lightness_r[2];
    SANE_Byte lightness_g[2];
    SANE_Byte lightness_b[2];
    SANE_Byte lightness_bw[2];
    
}
WDB;

/* "extension" of the window descriptor block for the JX 330 */
typedef struct WDBX330
  {
    SANE_Byte moire_reduction[2];
  }
WDBX330;

/* "extension" of the window descriptor block for the JX 250 */
typedef struct XWDBX250
  {
    SANE_Byte threshold_red;
    SANE_Byte threshold_green;
    SANE_Byte threshold_blue;
    SANE_Byte draft;
    SANE_Byte scanning_time[4];
    SANE_Byte fixed_gamma;
    SANE_Byte x_axis_res_qualifier[2];
    SANE_Byte y_axis_res_qualifier[2];
  }
WDBX250;

typedef struct window_param
{
    WPDH wpdh;
    WDB wdb;
    WDBX330 wdbx330;
    WDBX250 wdbx250;
}
window_param;

typedef struct mode_sense_param
{
    SANE_Byte mode_data_length;
    SANE_Byte mode_param_header2;
    SANE_Byte mode_param_header3;
    SANE_Byte mode_desciptor_length;
    SANE_Byte resereved[5];
    SANE_Byte blocklength[3];
    SANE_Byte page_code;
    SANE_Byte page_length; /* 6 */
    SANE_Byte bmu;
    SANE_Byte res2;
    SANE_Byte mud[2];
    SANE_Byte res3;
    SANE_Byte res4;
}
mode_sense_param;

typedef struct mode_sense_subdevice
{
  /* This definition reflects the JX250. The JX330 would need a slightly
     different definition, but the bytes used right now (for ADF and FSU)
     are identical.
  */
    SANE_Byte mode_data_length;
    SANE_Byte mode_param_header2;
    SANE_Byte mode_param_header3;
    SANE_Byte mode_desciptor_length;
    SANE_Byte res1[5];
    SANE_Byte blocklength[3];
    SANE_Byte page_code;
    SANE_Byte page_length; /* 0x1a */
    SANE_Byte a_mode_type;
    SANE_Byte f_mode_type;
    SANE_Byte res2;
    SANE_Byte max_x[4];
    SANE_Byte max_y[4];
    SANE_Byte res3[2];
    SANE_Byte x_basic_resolution[2];
    SANE_Byte y_basic_resolution[2];
    SANE_Byte x_max_resolution[2];
    SANE_Byte y_max_resolution[2];
    SANE_Byte x_min_resolution[2];
    SANE_Byte y_min_resolution[2];
    SANE_Byte res4;
}
mode_sense_subdevice;

typedef struct mode_select_param
{
    SANE_Byte mode_param_header1;
    SANE_Byte mode_param_header2;
    SANE_Byte mode_param_header3;
    SANE_Byte mode_param_header4;
    SANE_Byte page_code;
    SANE_Byte page_length; /* 6 */
    SANE_Byte res1;
    SANE_Byte res2;
    SANE_Byte mud[2];
    SANE_Byte res3;
    SANE_Byte res4;
}
mode_select_param;

typedef struct mode_select_subdevice
{
    SANE_Byte mode_param_header1;
    SANE_Byte mode_param_header2;
    SANE_Byte mode_param_header3;
    SANE_Byte mode_param_header4;
    SANE_Byte page_code;
    SANE_Byte page_length; /*  0x1A */
    SANE_Byte a_mode;
    SANE_Byte f_mode;
    SANE_Byte res[24];
}
mode_select_subdevice;

/* SCSI commands */
#define TEST_UNIT_READY        0x00
#define REQUEST_SENSE          0x03
#define INQUIRY                0x12
#define MODE_SELECT6           0x15
#define RESERVE_UNIT           0x16
#define RELEASE_UNIT           0x17
#define MODE_SENSE6            0x1a
#define SCAN                   0x1b
#define SEND_DIAGNOSTIC        0x1d
#define SET_WINDOW             0x24
#define GET_WINDOW             0x25
#define READ                   0x28
#define SEND                   0x2a
#define OBJECT_POSITION        0x31

#define SENSE_LEN              18
#define INQUIRY_LEN            36
#define MODEPARAM_LEN          12
#define MODE_SUBDEV_LEN        32
#define WINDOW_LEN             76

#endif /* not sharp_h */