1 /* sane - Scanner Access Now Easy.
2 
3    Copyright (C) 1998 Milon Firikis based on David Mosberger-Tang previous
4    Work on mustek.c file from the SANE package.
5 
6    This program is free software; you can redistribute it and/or
7    modify it under the terms of the GNU General Public License as
8    published by the Free Software Foundation; either version 2 of the
9    License, or (at your option) any later version.
10 
11    This program is distributed in the hope that it will be useful, but
12    WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    General Public License for more details.
15 
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <https://www.gnu.org/licenses/>.
18 
19    As a special exception, the authors of SANE give permission for
20    additional uses of the libraries contained in this release of SANE.
21 
22    The exception is that, if you link a SANE library with other files
23    to produce an executable, this does not by itself cause the
24    resulting executable to be covered by the GNU General Public
25    License.  Your use of that executable is in no way restricted on
26    account of linking the SANE library code into it.
27 
28    This exception does not, however, invalidate any other reasons why
29    the executable file might be covered by the GNU General Public
30    License.
31 
32    If you submit changes to SANE to the maintainers to be included in
33    a subsequent release, you agree by submitting the changes that
34    those changes may be distributed with this exception intact.
35 
36    If you write modifications of your own for SANE, it is your choice
37    whether to permit this exception to apply to your modifications.
38    If you do not wish that, delete this exception notice.  */
39 #ifndef apple_h
40 #define apple_h
41 
42 #include <sys/types.h>
43 
44 
45 /*
46 Warning: if you uncomment the next line you 'll get
47 zero functionality. All the scanner specific function
48 such as sane_read, attach and the others will return
49 without doing  anything. This way you can run the backend
50 without an attached scanner just to see if it gets
51 its control variables in a proper way.
52 
53 TODO: This could be a nice thing to do as a sane config
54 option at runtime. This way one can debug the gui-ipc
55 part of the backend without actually has the scanner.
56 
57 */
58 
59 #if 0
60 #define NEUTRALIZE_BACKEND
61 #define APPLE_MODEL_SELECT APPLESCANNER
62 #endif
63 #undef CALIBRATION_FUNCTIONALITY
64 #undef RESERVE_RELEASE_HACK
65 
66 #ifdef RESERVE_RELEASE_HACK
67 /* Also Try these with zero */
68 #define CONTROLLER_SCSI_ID 7
69 #define SETTHIRDPARTY 0x10
70 #endif
71 
72 
73 #define ERROR_MESSAGE	1
74 #define USER_MESSAGE	5
75 #define FLOW_CONTROL	50
76 #define VARIABLE_CONTROL 70
77 #define DEBUG_SPECIAL	100
78 #define IO_MESSAGE	110
79 #define INNER_LOOP	120
80 
81 
82 /* mode values: */
83 enum Apple_Modes
84   {
85   APPLE_MODE_LINEART=0,
86   APPLE_MODE_HALFTONE,
87   APPLE_MODE_GRAY,
88   APPLE_MODE_BICOLOR,
89   EMPTY_DONT_USE_IT,
90   APPLE_MODE_COLOR
91   };
92 
93 enum Apple_Option
94   {
95     OPT_NUM_OPTS = 0,
96 
97     OPT_HWDETECT_GROUP,
98     OPT_MODEL,
99 
100     OPT_MODE_GROUP,
101     OPT_MODE,
102     OPT_RESOLUTION,
103     OPT_PREVIEW,
104 
105     OPT_GEOMETRY_GROUP,
106     OPT_TL_X,			/* top-left x */
107     OPT_TL_Y,			/* top-left y */
108     OPT_BR_X,			/* bottom-right x */
109     OPT_BR_Y,			/* bottom-right y */
110 
111 
112     OPT_ENHANCEMENT_GROUP,
113     /* COMMON				*/
114     OPT_BRIGHTNESS,
115     OPT_CONTRAST,
116     OPT_THRESHOLD,
117 
118     /* AppleScanner only		*/
119     OPT_GRAYMAP,
120     OPT_AUTOBACKGROUND,
121     OPT_AUTOBACKGROUND_THRESHOLD,
122 
123     /* AppleScanner & OneScanner	*/
124     OPT_HALFTONE_PATTERN,
125     OPT_HALFTONE_FILE,
126 
127     /* ColorOneScanner Only		*/
128     OPT_VOLT_REF,
129     OPT_VOLT_REF_TOP,
130     OPT_VOLT_REF_BOTTOM,
131 
132     /* misc : advanced			*/
133     OPT_MISC_GROUP,
134 
135     /* all				*/
136     OPT_LAMP,
137 
138     /* AppleScanner Only		*/
139     OPT_WAIT,
140 
141     /* OneScanner only			*/
142     OPT_CALIBRATE,
143     OPT_SPEED,
144 
145     /* OneScanner && ColorOneScanner	*/
146     OPT_LED,
147     OPT_CCD,
148 
149     /* ColorOneScanner only		*/
150 
151     OPT_MTF_CIRCUIT,
152     OPT_ICP,
153     OPT_POLARITY,
154 
155     /* color group : advanced		*/
156 
157     OPT_COLOR_GROUP,
158 
159 
160 #ifdef CALIBRATION_FUNCTIONALITY
161 
162     /* OneScanner			*/
163     OPT_CALIBRATION_VECTOR,
164 
165     /* ColorOneScanner			*/
166 
167     OPT_CALIBRATION_VECTOR_RED,
168     OPT_CALIBRATION_VECTOR_GREEN,
169     OPT_CALIBRATION_VECTOR_BLUE,
170 #endif
171 
172 
173     /* OneScanner && ColorOneScanner	*/
174     OPT_DOWNLOAD_CALIBRATION_VECTOR,
175 
176     /* ColorOneScanner			*/
177 
178     OPT_CUSTOM_CCT,
179     OPT_CCT,
180     OPT_DOWNLOAD_CCT,
181 
182     OPT_CUSTOM_GAMMA,
183 
184     OPT_GAMMA_VECTOR_R,
185     OPT_GAMMA_VECTOR_G,
186     OPT_GAMMA_VECTOR_B,
187 
188     OPT_DOWNLOAD_GAMMA,
189     OPT_COLOR_SENSOR,
190 
191     /* must come last: */
192     NUM_OPTIONS
193   };
194 
195 
196 /* This is a hack to get fast the model of the Attached Scanner	*/
197 /* But it Works well and I am not considering in "fix" it	*/
198 enum SCANNERMODEL
199   {
200     OPT_NUM_SCANNERS = 0,
201 
202     APPLESCANNER, ONESCANNER, COLORONESCANNER,
203     NUM_SCANNERS
204   };
205 
206 typedef struct Apple_Device
207   {
208     struct Apple_Device *next;
209     SANE_Int ScannerModel;
210     SANE_Device sane;
211     SANE_Range dpi_range;
212     SANE_Range x_range;
213     SANE_Range y_range;
214     SANE_Int MaxWidth;
215     SANE_Int MaxHeight;
216     unsigned flags;
217   }
218 Apple_Device;
219 
220 typedef struct Apple_Scanner
221   {
222     /* all the state needed to define a scan request: */
223     struct Apple_Scanner *next;
224 
225     SANE_Option_Descriptor opt[NUM_OPTIONS];
226     Option_Value val[NUM_OPTIONS];
227 
228     /* First we put here all the scan variables */
229 
230     /* These are needed for converting back and forth the scan area */
231 
232     SANE_Int bpp;	/* The actual bpp, before scaling */
233 
234     double ulx;
235     double uly;
236     double wx;
237     double wy;
238     SANE_Int ULx;
239     SANE_Int ULy;
240     SANE_Int Width;
241     SANE_Int Height;
242 
243 /*
244 TODO: Initialize this beasts with malloc instead of statically allocation.
245 */
246     SANE_Int calibration_vector[2550];
247     SANE_Int calibration_vector_red[2700];
248     SANE_Int calibration_vector_green[2700];
249     SANE_Int calibration_vector_blue[2700];
250     SANE_Fixed cct3x3[9];
251     SANE_Int gamma_table[3][256];
252     SANE_Int halftone_pattern[64];
253 
254     SANE_Bool scanning;
255     SANE_Bool AbortedByUser;
256 
257     int pass;			/* pass number */
258     SANE_Parameters params;
259 
260     int fd;			/* SCSI filedescriptor */
261 
262     /* scanner dependent/low-level state: */
263     Apple_Device *hw;
264 
265   }
266 Apple_Scanner;
267 
268 #endif /* apple_h */
269