summaryrefslogtreecommitdiff
path: root/backend/ibm.h
blob: 3493cbc5ac796f6ed57cc93f9f095e1b33b6c9c9 (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
/* sane - Scanner Access Now Easy.

   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, see <https://www.gnu.org/licenses/>.

   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 ibm_h
#define ibm_h 1

#include <sys/types.h>

#include "../include/sane/config.h"

/* defines for scan_image_mode field */
#define IBM_BINARY_MONOCHROME   0
#define IBM_DITHERED_MONOCHROME 1
#define IBM_GRAYSCALE           2

/* defines for paper field */
#define IBM_PAPER_USER_DEFINED	0
#define IBM_PAPER_A3		1
#define IBM_PAPER_A4		2
#define IBM_PAPER_A4L		3
#define IBM_PAPER_A5		4
#define IBM_PAPER_A5L		5
#define IBM_PAPER_A6		6
#define IBM_PAPER_B4		7
#define IBM_PAPER_B5		8
#define IBM_PAPER_LEGAL		9
#define IBM_PAPER_LETTER	10

/* sizes for mode parameter's base_measurement_unit */
#define INCHES                    0
#define MILLIMETERS               1
#define POINTS                    2
#define DEFAULT_MUD               1200
#define MEASUREMENTS_PAGE         (SANE_Byte)(0x03)

/* Mode Page Control */
#define PC_CURRENT 0x00
#define PC_CHANGE  0x40
#define PC_DEFAULT 0x80
#define PC_SAVED   0xc0

static const SANE_String_Const mode_list[] =
  {
    SANE_VALUE_SCAN_MODE_LINEART,
    SANE_VALUE_SCAN_MODE_HALFTONE,
    SANE_VALUE_SCAN_MODE_GRAY,
    0
  };

static const SANE_String_Const paper_list[] =
  {
    "User",
    "A3",
    "A4", "A4R",
    "A5", "A5R",
    "A6",
    "B4", "B5",
    "Legal", "Letter",
    0
  };

#define PAPER_A3_W	14032
#define PAPER_A3_H	19842
#define PAPER_A4_W	9921
#define PAPER_A4_H	14032
#define PAPER_A4R_W	14032
#define PAPER_A4R_H	9921
#define PAPER_A5_W	7016
#define PAPER_A5_H	9921
#define PAPER_A5R_W	9921
#define PAPER_A5R_H	7016
#define PAPER_A6_W	4960
#define PAPER_A6_H	7016
#define PAPER_B4_W	11811
#define PAPER_B4_H	16677
#define PAPER_B5_W	8598
#define PAPER_B5_H	12142
#define PAPER_LEGAL_W	10200
#define PAPER_LEGAL_H	16800
#define PAPER_LETTER_W	10200
#define PAPER_LETTER_H	13200

static const SANE_Range u8_range =
  {
      0,				/* minimum */
    255,				/* maximum */
      0				        /* quantization */
  };

static const SANE_Range ibm2456_res_range =
  {
    100,				/* minimum */
    600,				/* maximum */
      0				        /* quantization */
  };

static const SANE_Range default_x_range =
  {
    0,				        /* minimum */
/*    (SANE_Word) ( * DEFAULT_MUD),	 maximum */
    14032,				/* maximum (found empirically for Gray mode) */
    					/* in Lineart mode it works till 14062 */
    2				        /* quantization */
  };

static const SANE_Range default_y_range =
  {
    0,				        /* minimum */
/*    (SANE_Word) (14 * DEFAULT_MUD),	 maximum */
    20410,				/* maximum (found empirically) */
    2				        /* quantization */
  };



static inline void
_lto2b(SANE_Int val, SANE_Byte *bytes)

{

        bytes[0] = (val >> 8) & 0xff;
        bytes[1] = val & 0xff;
}

static inline void
_lto3b(SANE_Int val, SANE_Byte *bytes)

{

        bytes[0] = (val >> 16) & 0xff;
        bytes[1] = (val >> 8) & 0xff;
        bytes[2] = val & 0xff;
}

static inline void
_lto4b(SANE_Int val, SANE_Byte *bytes)
{

        bytes[0] = (val >> 24) & 0xff;
        bytes[1] = (val >> 16) & 0xff;
        bytes[2] = (val >> 8) & 0xff;
        bytes[3] = val & 0xff;
}

static inline SANE_Int
_2btol(SANE_Byte *bytes)
{
        SANE_Int rv;

        rv = (bytes[0] << 8) |
             bytes[1];
        return (rv);
}

static inline SANE_Int
_3btol(SANE_Byte *bytes)
{
        SANE_Int rv;

        rv = (bytes[0] << 16) |
             (bytes[1] << 8) |
             bytes[2];
        return (rv);
}

static inline SANE_Int
_4btol(SANE_Byte *bytes)
{
        SANE_Int rv;

        rv = (bytes[0] << 24) |
             (bytes[1] << 16) |
             (bytes[2] << 8) |
             bytes[3];
        return (rv);
}

typedef enum
  {
    OPT_NUM_OPTS = 0,

    OPT_MODE_GROUP,
    OPT_MODE,
    OPT_X_RESOLUTION,
    OPT_Y_RESOLUTION,
    OPT_ADF,

    OPT_GEOMETRY_GROUP,
    OPT_PAPER,			/* predefined formats */
    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_BRIGHTNESS,
    OPT_CONTRAST,

    /* must come last: */
    NUM_OPTIONS
  }
Ibm_Option;

typedef struct Ibm_Info
  {
    SANE_Range xres_range;
    SANE_Range yres_range;
    SANE_Range x_range;
    SANE_Range y_range;
    SANE_Range brightness_range;
    SANE_Range contrast_range;

    SANE_Int xres_default;
    SANE_Int yres_default;
    SANE_Int image_mode_default;
    SANE_Int paper_default;
    SANE_Int brightness_default;
    SANE_Int contrast_default;
    SANE_Int adf_default;

    SANE_Int bmu;
    SANE_Int mud;
  }
Ibm_Info;

typedef struct Ibm_Device
  {
    struct Ibm_Device *next;
    SANE_Device sane;
    Ibm_Info info;
  }
Ibm_Device;

typedef struct Ibm_Scanner
  {
    /* all the state needed to define a scan request: */
    struct Ibm_Scanner *next;
    int fd;			/* SCSI filedescriptor */

    SANE_Option_Descriptor opt[NUM_OPTIONS];
    Option_Value val[NUM_OPTIONS];
    SANE_Parameters params;
    /* scanner dependent/low-level state: */
    Ibm_Device *hw;

    SANE_Int xres;
    SANE_Int yres;
    SANE_Int ulx;
    SANE_Int uly;
    SANE_Int width;
    SANE_Int length;
    SANE_Int brightness;
    SANE_Int contrast;
    SANE_Int image_composition;
    SANE_Int bpp;
    SANE_Bool reverse;
/* next lines by mf */
    SANE_Int adf_state;
#define ADF_UNUSED  0             /* scan from flatbed, not ADF */
#define ADF_ARMED   1             /* scan from ADF, everything's set up */
#define ADF_CLEANUP 2             /* eject paper from ADF on close */
/* end lines by mf */
    size_t bytes_to_read;
    int scanning;
  }
Ibm_Scanner;

struct inquiry_data {
        SANE_Byte devtype;
        SANE_Byte byte2;
        SANE_Byte byte3;
        SANE_Byte byte4;
        SANE_Byte byte5;
        SANE_Byte res1[2];
        SANE_Byte flags;
        SANE_Byte vendor[8];
        SANE_Byte product[8];
        SANE_Byte revision[4];
        SANE_Byte byte[60];
};

#define IBM_WINDOW_DATA_SIZE 320
struct ibm_window_data {
        /* header */
        SANE_Byte reserved[6];
        SANE_Byte len[2];
        /* data */
        SANE_Byte window_id;         /* must be zero */
        SANE_Byte reserved0;
        SANE_Byte x_res[2];
        SANE_Byte y_res[2];
        SANE_Byte x_org[4];
        SANE_Byte y_org[4];
        SANE_Byte width[4];
        SANE_Byte length[4];
        SANE_Byte brightness;
        SANE_Byte threshold;
        SANE_Byte contrast;
        SANE_Byte image_comp;        /* image composition (data type) */
        SANE_Byte bits_per_pixel;
        SANE_Byte halftone_code;     /* halftone_pattern[0] in ricoh.h */
        SANE_Byte halftone_id;       /* halftone_pattern[1] in ricoh.h */
        SANE_Byte pad_type;
        SANE_Byte bit_ordering[2];
        SANE_Byte compression_type;
        SANE_Byte compression_arg;
        SANE_Byte res3[6];

        /* Vendor Specific parameter byte(s) */
        /* Ricoh specific, follow the scsi2 standard ones */
        SANE_Byte byte1;
        SANE_Byte byte2;
        SANE_Byte mrif_filtering_gamma_id;
        SANE_Byte byte3;
        SANE_Byte byte4;
        SANE_Byte binary_filter;
        SANE_Byte reserved2[18];

        SANE_Byte reserved3[256];

};

struct measurements_units_page {
        SANE_Byte page_code; /* 0x03 */
        SANE_Byte parameter_length; /* 0x06 */
        SANE_Byte bmu;
        SANE_Byte res1;
        SANE_Byte mud[2];
        SANE_Byte res2[2];  /* anybody know what `COH' may mean ??? */
/* next 4 lines by mf */
	SANE_Byte adf_page_code;
	SANE_Byte adf_parameter_length;
	SANE_Byte adf_control;
	SANE_Byte res3[5];
};

struct mode_pages {
        SANE_Byte page_code;
        SANE_Byte parameter_length;
        SANE_Byte rest[14];  /* modified by mf; it was 6; see above */
#if 0
        SANE_Byte more_pages[243]; /* maximum size 255 bytes (incl header) */
#endif
};


#endif /* ibm_h */