1 /* sane - Scanner Access Now Easy.
2    Copyright (C) 1997 David Mosberger-Tang
3    This file is part of the SANE package.
4 
5    As a special exception, the authors of SANE give permission for
6    additional uses of the libraries contained in this release of SANE.
7 
8    The exception is that, if you link a SANE library with other files
9    to produce an executable, this does not by itself cause the
10    resulting executable to be covered by the GNU General Public
11    License.  Your use of that executable is in no way restricted on
12    account of linking the SANE library code into it.
13 
14    This exception does not, however, invalidate any other reasons why
15    the executable file might be covered by the GNU General Public
16    License.
17 
18    If you submit changes to SANE to the maintainers to be included in
19    a subsequent release, you agree by submitting the changes that
20    those changes may be distributed with this exception intact.
21 
22    If you write modifications of your own for SANE, it is your choice
23    whether to permit this exception to apply to your modifications.
24    If you do not wish that, delete this exception notice.
25 
26    Portions of this code are derived from Scott Laird's qcam driver.
27    It's copyright notice is reproduced here:
28 
29    Copyright (C) 1996 by Scott Laird
30 
31    Permission is hereby granted, free of charge, to any person
32    obtaining a copy of this software and associated documentation
33    files (the "Software"), to deal in the Software without
34    restriction, including without limitation the rights to use, copy,
35    modify, merge, publish, distribute, sublicense, and/or sell copies
36    of the Software, and to permit persons to whom the Software is
37    furnished to do so, subject to the following conditions:
38 
39    The above copyright notice and this permission notice shall be
40    included in all copies or substantial portions of the Software.
41 
42    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
43    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
45    NONINFRINGEMENT.  IN NO EVENT SHALL SCOTT LAIRD BE LIABLE FOR ANY
46    CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
47    CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
48    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
49 
50 #ifndef qcam_h
51 #define qcam_h
52 
53 #include "../include/sane/sane.h"
54 
55 typedef enum
56   {
57     QC_MONO	= 0x01,
58     QC_COLOR	= 0x10
59   }
60 QC_Model;
61 
62 typedef enum
63   {
64     QC_RES_LOW = 0,
65     QC_RES_HIGH
66   }
67 QC_Resolution;
68 
69 /* commands common to all quick-cameras: */
70 typedef enum
71   {
72     QC_SEND_VIDEO_FRAME		=  7,
73     QC_SET_BRIGHTNESS		= 11,
74     QC_SET_TOP			= 13,
75     QC_SET_LEFT			= 15,
76     QC_SET_NUM_V		= 17,
77     QC_SET_NUM_H		= 19,
78     QC_SEND_VERSION		= 23,
79     QC_SET_BLACK		= 29,
80     QC_SET_WHITE		= 31,
81     QC_SET_SATURATION		= 35,
82     QC_SEND_STATUS		= 41,
83     QC_SET_SPEED		= 45
84   }
85 QC_Command;
86 
87 /* commands for grayscale camera: */
88 typedef enum
89   {
90     QC_MONO_SET_CONTRAST	= 25,
91     QC_MONO_AUTO_ADJUST_OFFSET	= 27,
92     QC_MONO_GET_OFFSET		= 33
93   }
94 QC_Mono_Command;
95 
96 /* commands for color camera: */
97 typedef enum
98   {
99     QC_COL_LOAD_RAM		= 27,
100     QC_COL_SET_HUE		= 33,
101     QC_COL_SET_CONTRAST		= 37
102   }
103 QC_Col_Command;
104 
105 typedef enum
106   {
107     OPT_NUM_OPTS = 0,
108 
109     OPT_MODE_GROUP,
110     OPT_DEPTH,			/* 4 or 6 (b&w) or 24 (color) */
111     OPT_RESOLUTION,		/* resolution in pixels */
112     OPT_XFER_SCALE,		/* transfer-scale */
113     OPT_DESPECKLE,		/* turn on despeckling? */
114     OPT_TEST,			/* test image */
115 
116     OPT_GEOMETRY_GROUP,
117     OPT_TL_X,			/* top-left x */
118     OPT_TL_Y,			/* top-left y */
119     OPT_BR_X,			/* bottom-right x */
120     OPT_BR_Y,			/* bottom-right y */
121 
122     OPT_ENHANCEMENT_GROUP,
123     OPT_BRIGHTNESS,
124     OPT_CONTRAST,
125     OPT_BLACK_LEVEL,
126     OPT_WHITE_LEVEL,
127     OPT_HUE,
128     OPT_SATURATION,
129 
130     /* must come last: */
131     NUM_OPTIONS
132   }
133 QC_Option;
134 
135 typedef enum
136   {
137     QC_UNIDIR,
138     QC_BIDIR
139   } QC_Port_Mode;
140 
141 typedef struct
142   {
143     size_t num_bytes;		/* # of bytes to read */
144     QC_Resolution resolution;	/* high-resolution? */
145     SANE_Parameters params;	/* other parameters */
146     u_int mode;			/* qcam scan code (get video data command) */
147     int despeckle;		/* apply despeckling filter? */
148   }
149 QC_Scan_Request;
150 
151 typedef struct QC_Device
152   {
153     struct QC_Device * next;
154     SANE_Device sane;
155     QC_Port_Mode port_mode;
156     int port;			/* i/o port address */
157     int version;		/* camera version */
158     int lock_fd;		/* used for locking protocol */
159   }
160 QC_Device;
161 
162 typedef struct QC_Scanner
163   {
164     struct QC_Scanner *next;
165 
166     SANE_Option_Descriptor opt[NUM_OPTIONS];
167     Option_Value val[NUM_OPTIONS];
168     QC_Resolution resolution;
169     SANE_Parameters params;
170     QC_Device *hw;
171     SANE_Int user_corner;	/* bitmask of user-selected coordinates */
172     SANE_Int value_changed;	/* bitmask of options that were set */
173     SANE_Bool scanning;
174     SANE_Bool deliver_eof;
175     SANE_Bool holding_lock;	/* are we holding the lock? */
176     /* state for reading a frame: */
177     size_t num_bytes;		/* # of bytes read so far */
178     size_t bytes_per_frame;	/* total number of bytes in frame */
179     /* state relating to the reader-process */
180     int reader_pid;		/* -1 if there is no reader process (yet) */
181     int from_child;		/* fd to read from child process*/
182     int to_child;		/* fd to write to child */
183     int read_fd;		/* used to read data */
184     /* internal state for qc_readbytes(): */
185     int readbytes_state;
186     unsigned int saved_bits;
187   }
188 QC_Scanner;
189 
190 #endif /* qcam_h */
191