summaryrefslogtreecommitdiff
path: root/backend/artec.h
blob: efb4bb47d5670a9ef62c2c71644b368f5b0a74c5 (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
/* sane - Scanner Access Now Easy.
   Copyright (C) 1996 David Mosberger-Tang
   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.

   This file implements a SANE backend for the Artec/Ultima scanners.

   Copyright (C) 1998,1999 Chris Pinkham
   Released under the terms of the GPL.
   *NO WARRANTY*

   *********************************************************************
   For feedback/information:

   cpinkham@corp.infi.net
   http://www4.infi.net/~cpinkham/sane/sane-artec-doc.html
   *********************************************************************
 */

#ifndef artec_h
#define artec_h

#include <sys/types.h>

#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))

#define ARTEC_MIN_X( hw )	( hw->horz_resolution_list[ 0 ] ? \
							hw->horz_resolution_list[ 1 ] : 0 )
#define ARTEC_MAX_X( hw )	( hw->horz_resolution_list[ 0 ] ? \
							hw->horz_resolution_list[ \
								hw->horz_resolution_list[ 0 ] ] : 0 )
#define ARTEC_MIN_Y( hw )	( hw->vert_resolution_list[ 0 ] ? \
							hw->vert_resolution_list[ 1 ] : 0 )
#define ARTEC_MAX_Y( hw )	( hw->vert_resolution_list[ 0 ] ? \
							hw->vert_resolution_list[ \
								hw->vert_resolution_list[ 0 ] ] : 0 )

typedef enum
  {
    OPT_NUM_OPTS = 0,

    OPT_MODE_GROUP,
    OPT_MODE,
    OPT_X_RESOLUTION,
    OPT_Y_RESOLUTION,
    OPT_RESOLUTION_BIND,
    OPT_PREVIEW,
    OPT_GRAY_PREVIEW,
    OPT_NEGATIVE,

    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_CONTRAST,
    OPT_BRIGHTNESS,
    OPT_THRESHOLD,
    OPT_HALFTONE_PATTERN,
    OPT_FILTER_TYPE,
    OPT_PIXEL_AVG,
    OPT_EDGE_ENH,

    OPT_CUSTOM_GAMMA, /* use custom gamma table */
    OPT_GAMMA_VECTOR,
    OPT_GAMMA_VECTOR_R,
    OPT_GAMMA_VECTOR_G,
    OPT_GAMMA_VECTOR_B,

    OPT_TRANSPARENCY,
    OPT_ADF,

    OPT_CALIBRATION_GROUP,
    OPT_QUALITY_CAL,
    OPT_SOFTWARE_CAL,

    /* must come last */
    NUM_OPTIONS
  }
ARTEC_Option;

/* Some FLAGS */
#define ARTEC_FLAG_CALIBRATE			0x00000001 /* supports hardware calib */
#define ARTEC_FLAG_CALIBRATE_RGB		0x00000003 /* yes 3, set CALIB. also */
#define ARTEC_FLAG_CALIBRATE_DARK_WHITE	0x00000005 /* yes 5, set CALIB. also */
#define ARTEC_FLAG_RGB_LINE_OFFSET		0x00000008 /* need line offset buffer */
#define ARTEC_FLAG_RGB_CHAR_SHIFT		0x00000010 /* RRRRGGGGBBBB line fmt */
#define ARTEC_FLAG_OPT_CONTRAST         0x00000020 /* supports set contrast */
#define ARTEC_FLAG_ONE_PASS_SCANNER		0x00000040 /* single pass scanner */
#define ARTEC_FLAG_GAMMA				0x00000080 /* supports set gamma */
#define ARTEC_FLAG_GAMMA_SINGLE			0x00000180 /* yes 180, implies GAMMA */
#define ARTEC_FLAG_SEPARATE_RES			0x00000200 /* separate x & y scan res */
#define ARTEC_FLAG_IMAGE_REV_LR         0x00000400 /* reversed left-right */
#define ARTEC_FLAG_ENHANCE_LINE_EDGE    0x00000800 /* line edge enhancement */
#define ARTEC_FLAG_HALFTONE_PATTERN     0x00001000 /* > 1 halftone  pattern */
#define ARTEC_FLAG_REVERSE_WINDOW       0x00002000 /* reverse selected area */
#define ARTEC_FLAG_SC_BUFFERS_LINES     0x00004000 /* scanner has line buffer */
#define ARTEC_FLAG_SC_HANDLES_OFFSET    0x00008000 /* sc. handles line offset */
#define ARTEC_FLAG_SENSE_HANDLER        0x00010000 /* supports sense handler */
#define ARTEC_FLAG_SENSE_ENH_18         0x00020000 /* supports enh. byte 18 */
#define ARTEC_FLAG_SENSE_BYTE_19        0x00040000 /* supports sense byte 19 */
#define ARTEC_FLAG_SENSE_BYTE_22        0x00080000 /* supports sense byte 22 */
#define ARTEC_FLAG_PIXEL_AVERAGING      0x00100000 /* supports pixel avg-ing */
#define ARTEC_FLAG_ADF                  0x00200000 /* auto document feeder */
#define ARTEC_FLAG_OPT_BRIGHTNESS       0x00400000 /* supports set brightness */
#define ARTEC_FLAG_MBPP_NEGATIVE        0x00800000 /* can negate > 1bpp modes */

typedef enum
  {
    ARTEC_COMP_LINEART = 0,
    ARTEC_COMP_HALFTONE,
    ARTEC_COMP_GRAY,
    ARTEC_COMP_UNSUPP1,
    ARTEC_COMP_UNSUPP2,
    ARTEC_COMP_COLOR
  }
ARTEC_Image_Composition;

typedef enum
  {
    ARTEC_DATA_IMAGE = 0,
    ARTEC_DATA_UNSUPP1,
    ARTEC_DATA_HALFTONE_PATTERN,	/* 2 */
    ARTEC_DATA_UNSUPP3,
    ARTEC_DATA_RED_SHADING,	/* 4 */
    ARTEC_DATA_GREEN_SHADING,	/* 5 */
    ARTEC_DATA_BLUE_SHADING,	/* 6 */
    ARTEC_DATA_WHITE_SHADING_OPT,	/* 7 */
    ARTEC_DATA_WHITE_SHADING_TRANS,	/* 8 */
    ARTEC_DATA_CAPABILITY_DATA,	/* 9 */
    ARTEC_DATA_DARK_SHADING,	/* 10, 0xA */
    ARTEC_DATA_RED_GAMMA_CURVE,	/* 11, 0xB */
    ARTEC_DATA_GREEN_GAMMA_CURVE,	/* 12, 0xC */
    ARTEC_DATA_BLUE_GAMMA_CURVE,	/* 13, 0xD */
    ARTEC_DATA_ALL_GAMMA_CURVE	/* 14, 0xE */
  }
ARTEC_Read_Data_Type;

typedef enum
  {
    ARTEC_CALIB_RGB = 0,
    ARTEC_CALIB_DARK_WHITE
  }
ARTEC_Calibrate_Method;

typedef enum
  {
    ARTEC_FILTER_MONO = 0,
    ARTEC_FILTER_RED,
    ARTEC_FILTER_GREEN,
    ARTEC_FILTER_BLUE
  }
ARTEC_Filter_Type;

typedef enum
  {
    ARTEC_SOFT_CALIB_RED = 0,
	ARTEC_SOFT_CALIB_GREEN,
	ARTEC_SOFT_CALIB_BLUE
  }
ARTEC_Software_Calibrate;


typedef struct ARTEC_Device
  {
    struct ARTEC_Device *next;
    SANE_Device sane;
    double width;
    SANE_Range x_range;
    SANE_Word *horz_resolution_list;
    double height;
    SANE_Range y_range;
    SANE_Word *vert_resolution_list;
    SANE_Range threshold_range;
    SANE_Range contrast_range;
    SANE_Range brightness_range;
    SANE_Word setwindow_cmd_size;
    SANE_Word calibrate_method;
	SANE_Word max_read_size;

    long flags;
    SANE_Bool support_cap_data_retrieve;
    SANE_Bool req_shading_calibrate;
    SANE_Bool req_rgb_line_offset;
    SANE_Bool req_rgb_char_shift;

    /* info for 1-pass vs. 3-pass */
    SANE_Bool onepass;

    SANE_Bool support_gamma;
    SANE_Bool single_gamma;
	SANE_Int gamma_length;
  }
ARTEC_Device;

typedef struct ARTEC_Scanner
  {
    /* all the state needed to define a scan request: */
    struct ARTEC_Scanner *next;

    SANE_Option_Descriptor opt[NUM_OPTIONS];
    Option_Value val[NUM_OPTIONS];

	SANE_Int gamma_table[4][4096];
	double soft_calibrate_data[3][2592];
	SANE_Int halftone_pattern[64];
	SANE_Range gamma_range;
	int gamma_length;

    int scanning;
    SANE_Parameters params;
    size_t bytes_to_read;
    SANE_Int line_offset;

    /* scan parameters */
    char *mode;
    SANE_Int x_resolution;
    SANE_Int y_resolution;
    SANE_Int tl_x;
    SANE_Int tl_y;

    /* info for 1-pass vs. 3-pass */
    int this_pass;
    SANE_Bool onepasscolor;
    SANE_Bool threepasscolor;

    int fd;			/* SCSI filedescriptor */

    /* scanner dependent/low-level state: */
    ARTEC_Device *hw;
  }
ARTEC_Scanner;

#endif /* artec_h */