1 /*.............................................................................
2  * Project : SANE library for Plustek flatbed scanners.
3  *.............................................................................
4  */
5 
6 /** @file plustek.h
7  *  @brief Definitions for the backend.
8  *
9  * Based on Kazuhiro Sasayama previous
10  * work on plustek.[ch] file from the SANE package.<br>
11  *
12  * original code taken from sane-0.71<br>
13  * Copyright (C) 1997 Hypercore Software Design, Ltd.<br>
14  * Copyright (C) 2001-2007 Gerhard Jaeger <gerhard@gjaeger.de>
15  *
16  * History:
17  * - 0.30 - initial version
18  * - 0.31 - no changes
19  * - 0.32 - no changes
20  * - 0.33 - no changes
21  * - 0.34 - moved some definitions and typedefs from plustek.c
22  * - 0.35 - removed OPT_MODEL from options list
23  *        - added max_y to struct Plustek_Scan
24  * - 0.36 - added reader_pid, pipe and bytes_read to struct Plustek_Scanner
25  *        - removed unused variables from struct Plustek_Scanner
26  *        - moved fd from struct Plustek_Scanner to Plustek_Device
27  *        - added next members to struct Plustek_Scanner and Plustek_Device
28  * - 0.37 - added max_x to struct Plustek_Device
29  * - 0.38 - added caps to struct Plustek_Device
30  *        - added exit code to struct Plustek_Scanner
31  *        - removed dropout stuff
32  * - 0.39 - PORTTYPE enum
33  *        - added function pointers to control a scanner device
34  *          (Parport and USB)
35  * - 0.40 - added USB stuff
36  * - 0.41 - added configuration stuff
37  * - 0.42 - added custom gamma tables
38  *        - changed usbId to static array
39  *        - added _MAX_ID_LEN
40  * - 0.43 - no changes
41  * - 0.44 - added flag initialized
42  * - 0.45 - added readLine function
43  * - 0.46 - flag initialized is now used as device index
44  *        - added calFile to Plustek_Device
45  *        - removed _OPT_HALFTONE
46  * - 0.47 - added mov to adjustment
47  *        - changed stopScan function definition
48  *        - removed open function
49  *        - added OPT_LAMPSWITCH and OPT_WARMUPTIME
50  * - 0.48 - added OPT_CACHECAL, OPT_OVR_*, OPT_LAMPOFF_TIMER and
51  *          OPT_LAMPOFF_ONEND, also did some cleanup
52  *        - moved SCANDEF definitions to plustek-usb.h
53  *        - removed function pointer
54  *        - added OPT_BIT_DEPTH
55  * - 0.49 - added typedef struct DevList
56  *        - added button stuff
57  *        - added transferRate to struct Plustek_Device
58  * - 0.50 - cleanup
59  *        - added OPT_SPEEDUP
60  * - 0.51 - added OPT_CALIBRATE
61  * - 0.52 - added skipDarkStrip and incDarkTgt to struct AdjDef
62  *        - added OPT_LOFF4DARK
63  * .
64  * <hr>
65  * This file is part of the SANE package.
66  *
67  * This program is free software; you can redistribute it and/or
68  * modify it under the terms of the GNU General Public License as
69  * published by the Free Software Foundation; either version 2 of the
70  * License, or (at your option) any later version.
71  *
72  * This program is distributed in the hope that it will be useful, but
73  * WITHOUT ANY WARRANTY; without even the implied warranty of
74  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
75  * General Public License for more details.
76  *
77  * You should have received a copy of the GNU General Public License
78  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
79  *
80  * As a special exception, the authors of SANE give permission for
81  * additional uses of the libraries contained in this release of SANE.
82  *
83  * The exception is that, if you link a SANE library with other files
84  * to produce an executable, this does not by itself cause the
85  * resulting executable to be covered by the GNU General Public
86  * License.  Your use of that executable is in no way restricted on
87  * account of linking the SANE library code into it.
88  *
89  * This exception does not, however, invalidate any other reasons why
90  * the executable file might be covered by the GNU General Public
91  * License.
92  *
93  * If you submit changes to SANE to the maintainers to be included in
94  * a subsequent release, you agree by submitting the changes that
95  * those changes may be distributed with this exception intact.
96  *
97  * If you write modifications of your own for SANE, it is your choice
98  * whether to permit this exception to apply to your modifications.
99  * If you do not wish that, delete this exception notice.
100  * <hr>
101  */
102 #ifndef __PLUSTEK_H__
103 #define __PLUSTEK_H__
104 
105 /************************ some definitions ***********************************/
106 
107 
108 #define PLUSTEK_CONFIG_FILE	"plustek.conf"
109 
110 #ifndef PATH_MAX
111 # define PATH_MAX 1024
112 #endif
113 
114 #define _MEASURE_BASE       300UL
115 #define _DEF_DPI            50
116 #define DEFAULT_RATE        1000000
117 
118 /** the default image size
119  */
120 #define _DEFAULT_TLX          0     /* 0..216 mm */
121 #define _DEFAULT_TLY          0     /* 0..297 mm */
122 #define _DEFAULT_BRX        103     /* 0..216 mm */
123 #define _DEFAULT_BRY         76.21  /* 0..297 mm */
124 
125 #define _DEFAULT_TP_TLX      3.5    /* 0..42.3 mm */
126 #define _DEFAULT_TP_TLY     10.5    /* 0..43.1 mm */
127 #define _DEFAULT_TP_BRX     38.5    /* 0..42.3 mm */
128 #define _DEFAULT_TP_BRY     33.5    /* 0..43.1 mm */
129 
130 #define _DEFAULT_NEG_TLX     1.5    /* 0..38.9 mm */
131 #define _DEFAULT_NEG_TLY     1.5    /* 0..29.6 mm */
132 #define _DEFAULT_NEG_BRX    37.5    /* 0..38.9 mm */
133 #define _DEFAULT_NEG_BRY    25.5    /* 0..29.6 mm */
134 
135 /** image sizes for normal, transparent and negative modes
136  */
137 #define _TPAPageWidth        500UL
138 #define _TPAPageHeight       510UL
139 #define _TPALargePageWidth  1270UL
140 #define _TPALargePageHeight 1570UL
141 #define _TPAMinDpi           150
142 
143 #define _NegPageWidth        460UL
144 #define _NegPageHeight       350UL
145 #define _NegLargePageWidth  1270UL
146 #define _NegLargePageHeight 1570UL
147 
148 #define _SCALE(X) ((double)(X)/300.0 * MM_PER_INCH)
149 
150 /** scan modes
151  */
152 #define COLOR_BW        0
153 #define COLOR_256GRAY   1
154 #define COLOR_GRAY16    2
155 #define COLOR_TRUE24    3
156 #define COLOR_TRUE48    4
157 
158 /** usb id buffer
159  */
160 #define _MAX_ID_LEN 20
161 
162 /**
163  */
164 #define SFLAG_ADF   0x00000010  /* Automatic document feeder    */
165 #define SFLAG_TPA   0x00000080  /* has transparency adapter     */
166 
167 /**
168  */
169 #define SOURCE_Reflection   0
170 #define SOURCE_Transparency 1
171 #define SOURCE_Negative     2
172 #define SOURCE_ADF          3
173 
174 /** for Gamma tables
175  */
176 #define _MAP_RED    0
177 #define _MAP_GREEN  1
178 #define _MAP_BLUE   2
179 #define _MAP_MASTER 3
180 
181 /** generic error codes...
182  */
183 #define _FIRST_ERR -9000
184 
185 #define _E_ALLOC            (_FIRST_ERR-1)  /**< error allocating memory    */
186 #define _E_INVALID          (_FIRST_ERR-2)  /**< invalid parameter detected */
187 #define _E_INTERNAL         (_FIRST_ERR-3)  /**< internal error             */
188 #define _E_ABORT            (_FIRST_ERR-4)  /**< operation aborted          */
189 
190 #define _E_LAMP_NOT_IN_POS  (_FIRST_ERR-10)
191 #define _E_LAMP_NOT_STABLE  (_FIRST_ERR-11)
192 #define _E_NODATA           (_FIRST_ERR-12)
193 #define _E_BUFFER_TOO_SMALL (_FIRST_ERR-13)
194 #define _E_DATAREAD         (_FIRST_ERR-14)
195 
196 /************************ some structures ************************************/
197 
198 #define _ENABLE(option)  s->opt[option].cap &= ~SANE_CAP_INACTIVE
199 #define _DISABLE(option) s->opt[option].cap |=  SANE_CAP_INACTIVE
200 
201 enum {
202 	OPT_NUM_OPTS = 0,
203 	OPT_MODE_GROUP,
204 	OPT_MODE,
205 	OPT_BIT_DEPTH,
206 	OPT_EXT_MODE,
207 	OPT_RESOLUTION,
208 	OPT_PREVIEW,
209 	OPT_GEOMETRY_GROUP,
210 	OPT_TL_X,
211 	OPT_TL_Y,
212 	OPT_BR_X,
213 	OPT_BR_Y,
214 	OPT_ENHANCEMENT_GROUP,
215 	OPT_BRIGHTNESS,
216 	OPT_CONTRAST,
217 	OPT_CUSTOM_GAMMA,
218 	OPT_GAMMA_VECTOR,
219 	OPT_GAMMA_VECTOR_R,
220 	OPT_GAMMA_VECTOR_G,
221 	OPT_GAMMA_VECTOR_B,
222 	OPT_DEVICE_GROUP,
223 	OPT_LAMPSWITCH,
224 	OPT_LAMPOFF_TIMER,
225 	OPT_LAMPOFF_ONEND,
226 	OPT_WARMUPTIME,
227 	OPT_LOFF4DARK,
228 	OPT_CACHECAL,
229 	OPT_SPEEDUP,
230 	OPT_CALIBRATE,
231 	OPT_AFE_GROUP,
232 	OPT_OVR_REDGAIN,
233 	OPT_OVR_GREENGAIN,
234 	OPT_OVR_BLUEGAIN,
235 	OPT_OVR_REDOFS,
236 	OPT_OVR_GREENOFS,
237 	OPT_OVR_BLUEOFS,
238 	OPT_OVR_RED_LOFF,
239 	OPT_OVR_GREEN_LOFF,
240 	OPT_OVR_BLUE_LOFF,
241 	OPT_BUTTON_GROUP,
242 	OPT_BUTTON_0,
243 	OPT_BUTTON_1,
244 	OPT_BUTTON_2,
245 	OPT_BUTTON_3,
246 	OPT_BUTTON_4,
247 	OPT_BUTTON_LAST = OPT_BUTTON_4,
248 	NUM_OPTIONS
249 };
250 
251 /**
252  */
253 typedef struct {
254 	int x;
255 	int y;
256 } OffsDef, *pOffsDef;
257 
258 /** for adjusting the scanner settings
259  */
260 typedef struct {
261 	int     mov;                /**< model override */
262 	int     lampOff;
263 	int     lampOffOnEnd;
264 	int     warmup;
265 	int     enableTpa;
266 	int     skipCalibration;  /**< skip entire calibration */
267 	int     skipFine;
268 	int     skipFineWhite;
269 	int     skipDarkStrip;
270 	int     incDarkTgt;
271 	int     disableSpeedup;
272 	int     invertNegatives;
273 	int     cacheCalData;
274 	int     altCalibrate;  /* force use of the alternate canoscan autocal;
275 	                          perhaps other Canon scanners require the
276 	                          alternate autocalibration as well */
277 	/* AFE adjustemnts, gain and offset */
278 	int rgain;
279 	int ggain;
280 	int bgain;
281 	int rofs;
282 	int gofs;
283 	int bofs;
284 
285 	int rlampoff;   /* for red lamp off setting (CIS-scanner)   */
286 	int glampoff;   /* for green lamp off setting (CIS-scanner) */
287 	int blampoff;   /* for blue lamp off setting (CIS-scanner)  */
288 
289 	OffsDef pos;    /* for adjusting normal scan area       */
290 	OffsDef tpa;    /* for adjusting transparency scan area */
291 	OffsDef neg;    /* for adjusting negative scan area     */
292 
293 	int     posShadingY;
294 	int     tpaShadingY;
295 	int     negShadingY;
296 
297 	/* for adjusting the default gamma settings */
298 	double  rgamma;
299 	double  ggamma;
300 	double  bgamma;
301 
302 	double  graygamma;
303 
304 } AdjDef;
305 
306 typedef struct {
307 	unsigned short x;
308 	unsigned short y;
309 	unsigned short cx;
310 	unsigned short cy;
311 } CropRect;
312 
313 typedef struct image {
314 	unsigned long  dwFlag;
315 	CropRect       crArea;
316 	XY             xyDpi;
317 	unsigned short wDataType;
318 } ImgDef;
319 
320 typedef struct {
321 	unsigned long dwPixelsPerLine;
322 	unsigned long dwBytesPerLine;
323 	unsigned long dwLinesPerArea;
324 	ImgDef        ImgDef;
325 } CropInfo;
326 
327 typedef struct {
328 	ImgDef ImgDef;
329 	short  siBrightness;
330 	short  siContrast;
331 } ScanInfo;
332 
333 typedef struct {
334 	unsigned long  dwFlag;
335 	unsigned short wMaxExtentX; /**< scanarea width  */
336 	unsigned short wMaxExtentY; /**< scanarea height */
337 } ScannerCaps;
338 
339 typedef struct Plustek_Device
340 {
341 	SANE_Int               initialized;      /* device already initialized?  */
342 	struct Plustek_Device *next;             /* pointer to next dev in list  */
343 	int                    fd;               /* device handle                */
344 	char                  *name;             /* (to avoid compiler warnings!)*/
345 	char                  *calFile;          /* for saving calibration data  */
346 	unsigned long          transferRate;     /* detected USB-Speed in Bytes/s*/
347 	SANE_Device            sane;             /* info struct                  */
348 	SANE_Int               max_x;            /* max XY-extension of the scan-*/
349 	SANE_Int               max_y;            /* area                         */
350 	SANE_Range             dpi_range;        /* resolution range             */
351 	SANE_Range             x_range;          /* x-range of the scan-area     */
352 	SANE_Range             y_range;          /* y-range of the scan-area     */
353 	SANE_Int              *res_list;         /* to hold the available phys.  */
354 	SANE_Int               res_list_size;    /* resolution values            */
355 	ScannerCaps            caps;             /* caps reported by the driver  */
356 	AdjDef                 adj;              /* for driver adjustment        */
357 
358 	/**************************** USB-stuff **********************************/
359 	char                   usbId[_MAX_ID_LEN];/* to keep Vendor and product  */
360 	                                         /* ID string (from conf) file   */
361 	struct ScanDef         scanning;         /* here we hold all stuff for   */
362 	                                         /* the USB-scanner              */
363 	struct DeviceDef       usbDev;
364 #ifdef HAVE_SETITIMER
365 	struct itimerval       saveSettings;     /* for lamp timer               */
366 #endif
367 
368 } Plustek_Device;
369 
370 #ifndef SANE_OPTION
371 /* for compatibility with older versions */
372 typedef union
373 {
374 	SANE_Word   w;
375 	SANE_Word  *wa;
376 	SANE_String s;
377 } Option_Value;
378 #endif
379 
380 typedef struct Plustek_Scanner
381 {
382 	struct Plustek_Scanner *next;
383 	SANE_Pid                reader_pid;     /* process id of reader          */
384 	SANE_Status             exit_code;      /* status of the reader process  */
385 	int                     r_pipe;         /* pipe to reader process        */
386 	int                     w_pipe;         /* pipe from reader process      */
387 	unsigned long           bytes_read;     /* number of bytes currently read*/
388 	Plustek_Device         *hw;             /* pointer to current device     */
389 	Option_Value            val[NUM_OPTIONS];
390 	SANE_Byte              *buf;            /* the image buffer              */
391 	SANE_Bool               scanning;       /* TRUE during scan-process      */
392 	SANE_Bool               calibrating;    /* TRUE during calibration       */
393 	SANE_Bool               ipc_read_done;  /* TRUE after ipc has been red   */
394 	SANE_Parameters         params;         /* for keeping the parameter     */
395 
396 	/************************** gamma tables *********************************/
397 
398 	SANE_Word   gamma_table[4][4096];
399 	SANE_Range  gamma_range;
400 	int         gamma_length;
401 
402 	SANE_Option_Descriptor opt[NUM_OPTIONS];
403 
404 } Plustek_Scanner;
405 
406 /** for collecting configuration info...
407  */
408 typedef struct {
409 
410 	char     devName[PATH_MAX];
411 	char     usbId[_MAX_ID_LEN];
412 
413 	/* contains the stuff to adjust... */
414 	AdjDef   adj;
415 
416 } CnfDef;
417 
418 /** for supported device list
419  */
420 typedef struct DevList {
421 	SANE_Word       vendor_id;
422 	SANE_Word       device_id;
423 	SANE_Bool       attached;
424 	SANE_Char      *dev_name;
425 	struct DevList *next;
426 } DevList;
427 #endif	/* guard __PLUSTEK_H__ */
428 
429 /* END PLUSTEK.H.............................................................*/
430