• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /************************************************************************
2    lexmark.h - SANE library for Lexmark scanners.
3    Copyright (C) 2003-2004 Lexmark International, Inc. (original source)
4    Copyright (C) 2005 Fred Odendaal
5    Copyright (C) 2006-2010 Stéphane Voltz	<stef.dev@free.fr>
6    Copyright (C) 2010 "Torsten Houwaart" <ToHo@gmx.de> X74 support
7 
8    This file is part of the SANE package.
9 
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2 of the
13    License, or (at your option) any later version.
14 
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19 
20    You should have received a copy of the GNU General Public License
21    along with this program.  If not, see <https://www.gnu.org/licenses/>.
22 
23    As a special exception, the authors of SANE give permission for
24    additional uses of the libraries contained in this release of SANE.
25 
26    The exception is that, if you link a SANE library with other files
27    to produce an executable, this does not by itself cause the
28    resulting executable to be covered by the GNU General Public
29    License.  Your use of that executable is in no way restricted on
30    account of linking the SANE library code into it.
31 
32    This exception does not, however, invalidate any other reasons why
33    the executable file might be covered by the GNU General Public
34    License.
35 
36    If you submit changes to SANE to the maintainers to be included in
37    a subsequent release, you agree by submitting the changes that
38    those changes may be distributed with this exception intact.
39 
40    If you write modifications of your own for SANE, it is your choice
41    whether to permit this exception to apply to your modifications.
42    If you do not wish that, delete this exception notice.
43    **************************************************************************/
44 #ifndef LEXMARK_H
45 #define LEXMARK_H
46 
47 #undef DEEP_DEBUG
48 
49 #include "../include/sane/config.h"
50 
51 #include <errno.h>
52 #include <signal.h>
53 #include <stdio.h>
54 #include <stdlib.h>
55 #include <string.h>
56 #include <sys/types.h>
57 #include <sys/wait.h>
58 #include <time.h>
59 #include <unistd.h>
60 #include <fcntl.h>
61 #include <ctype.h>
62 #include <sys/time.h>
63 
64 #include "../include/_stdint.h"
65 #include "../include/sane/sane.h"
66 #include "../include/sane/sanei.h"
67 #include "../include/sane/saneopts.h"
68 #include "../include/sane/sanei_config.h"
69 #include "../include/sane/sanei_usb.h"
70 #include "../include/sane/sanei_backend.h"
71 
72 typedef enum
73 {
74   OPT_NUM_OPTS = 0,
75   OPT_MODE,
76   OPT_RESOLUTION,
77   OPT_PREVIEW,
78   OPT_THRESHOLD,
79 
80   OPT_GEOMETRY_GROUP,
81   OPT_TL_X,			/* top-left x */
82   OPT_TL_Y,			/* top-left y */
83   OPT_BR_X,			/* bottom-right x */
84   OPT_BR_Y,			/* bottom-right y */
85 
86   /* manual gain handling */
87   OPT_MANUAL_GAIN,		/* 6 */
88   OPT_GRAY_GAIN,
89   OPT_RED_GAIN,
90   OPT_GREEN_GAIN,
91   OPT_BLUE_GAIN,
92 
93   /* must come last: */
94   NUM_OPTIONS
95 }
96 Lexmark_Options;
97 
98 /*
99  * this struct is used to described the specific parts of each model
100  */
101 typedef struct Lexmark_Model
102 {
103   SANE_Int vendor_id;
104   SANE_Int product_id;
105   SANE_Byte mainboard_id;	/* matched against the content of reg B0 */
106   SANE_String_Const name;
107   SANE_String_Const vendor;
108   SANE_String_Const model;
109   SANE_Int motor_type;
110   SANE_Int sensor_type;
111   SANE_Int HomeEdgePoint1;
112   SANE_Int HomeEdgePoint2;
113 } Lexmark_Model;
114 
115 /*
116  * this struct is used to store per sensor model constants
117  */
118 typedef struct Lexmark_Sensor
119 {
120   SANE_Int id;
121   SANE_Int offset_startx;	/* starting x for offset calibration */
122   SANE_Int offset_endx;		/* end x for offset calibration */
123   SANE_Int offset_threshold;	/* target threshold for offset calibration */
124   SANE_Int xoffset;		/* number of unusable pixels on the start of the sensor */
125   SANE_Int default_gain;	/* value of the default gain for a scan */
126   SANE_Int red_gain_target;
127   SANE_Int green_gain_target;
128   SANE_Int blue_gain_target;
129   SANE_Int gray_gain_target;
130   SANE_Int red_shading_target;
131   SANE_Int green_shading_target;
132   SANE_Int blue_shading_target;
133   SANE_Int gray_shading_target;
134   SANE_Int offset_fallback;	/* offset to use in case offset calibration fails */
135   SANE_Int gain_fallback;	/* gain to use in case offset calibration fails */
136 } Lexmark_Sensor;
137 
138 typedef enum
139 {
140   RED = 0,
141   GREEN,
142   BLUE
143 }
144 Scan_Regions;
145 
146 /* struct to hold pre channel settings */
147 typedef struct Channels
148 {
149   SANE_Word red;
150   SANE_Word green;
151   SANE_Word blue;
152   SANE_Word gray;
153 }
154 Channels;
155 
156 /** @name Option_Value union
157  * convenience union to access option values given to the backend
158  * @{
159  */
160 #ifndef SANE_OPTION
161 #define SANE_OPTION 1
162 typedef union
163 {
164   SANE_Bool b;
165   SANE_Word w;
166   SANE_Word *wa;		/* word array */
167   SANE_String s;
168 }
169 Option_Value;
170 #endif
171 /* @} */
172 
173 typedef struct Read_Buffer
174 {
175   SANE_Int gray_offset;
176   SANE_Int max_gray_offset;
177   SANE_Int region;
178   SANE_Int red_offset;
179   SANE_Int green_offset;
180   SANE_Int blue_offset;
181   SANE_Int max_red_offset;
182   SANE_Int max_green_offset;
183   SANE_Int max_blue_offset;
184   SANE_Byte *data;
185   SANE_Byte *readptr;
186   SANE_Byte *writeptr;
187   SANE_Byte *max_writeptr;
188   size_t size;
189   size_t linesize;
190   SANE_Bool empty;
191   SANE_Int image_line_no;
192   SANE_Int bit_counter;
193   SANE_Int max_lineart_offset;
194 }
195 Read_Buffer;
196 
197 typedef struct Lexmark_Device
198 {
199   struct Lexmark_Device *next;
200   SANE_Bool missing;	/**< devices has been unplugged or swtiched off */
201 
202   SANE_Device sane;
203   SANE_Option_Descriptor opt[NUM_OPTIONS];
204   Option_Value val[NUM_OPTIONS];
205   SANE_Parameters params;
206   SANE_Int devnum;
207   long data_size;
208   SANE_Bool initialized;
209   SANE_Bool eof;
210   SANE_Int x_dpi;
211   SANE_Int y_dpi;
212   long data_ctr;
213   SANE_Bool device_cancelled;
214   SANE_Int cancel_ctr;
215   SANE_Byte *transfer_buffer;
216   size_t bytes_read;
217   size_t bytes_remaining;
218   size_t bytes_in_buffer;
219   SANE_Byte *read_pointer;
220   Read_Buffer *read_buffer;
221   SANE_Byte threshold;
222 
223   Lexmark_Model model;		/* per model data */
224   Lexmark_Sensor *sensor;
225   SANE_Byte shadow_regs[255];	/* shadow registers */
226   struct Channels offset;
227   struct Channels gain;
228   float *shading_coeff;
229 }
230 Lexmark_Device;
231 
232 /* Maximum transfer size */
233 #define MAX_XFER_SIZE 0xFFC0
234 
235 /* motors and sensors type defines */
236 #define X1100_MOTOR	1
237 #define A920_MOTOR	2
238 #define X74_MOTOR	3
239 
240 #define X1100_B2_SENSOR 4
241 #define A920_SENSOR     5
242 #define X1100_2C_SENSOR 6
243 #define X1200_SENSOR    7	/* X1200 on USB 1.0 */
244 #define X1200_USB2_SENSOR 8	/* X1200 on USB 2.0 */
245 #define X74_SENSOR	9
246 
247 /* Non-static Function Proto-types (called by lexmark.c) */
248 SANE_Status sanei_lexmark_low_init (Lexmark_Device * dev);
249 void sanei_lexmark_low_destroy (Lexmark_Device * dev);
250 SANE_Status sanei_lexmark_low_open_device (Lexmark_Device * dev);
251 void sanei_lexmark_low_close_device (Lexmark_Device * dev);
252 SANE_Bool sanei_lexmark_low_search_home_fwd (Lexmark_Device * dev);
253 void sanei_lexmark_low_move_fwd (SANE_Int distance, Lexmark_Device * dev,
254 				 SANE_Byte * regs);
255 SANE_Bool sanei_lexmark_low_X74_search_home (Lexmark_Device * dev,
256 					     SANE_Byte * regs);
257 SANE_Bool sanei_lexmark_low_search_home_bwd (Lexmark_Device * dev);
258 SANE_Int sanei_lexmark_low_find_start_line (Lexmark_Device * dev);
259 SANE_Status sanei_lexmark_low_set_scan_regs (Lexmark_Device * dev,
260 					     SANE_Int resolution,
261 					     SANE_Int offset,
262 					     SANE_Bool calibrated);
263 SANE_Status sanei_lexmark_low_start_scan (Lexmark_Device * dev);
264 long sanei_lexmark_low_read_scan_data (SANE_Byte * data, SANE_Int size,
265 				       Lexmark_Device * dev);
266 SANE_Status sanei_lexmark_low_assign_model (Lexmark_Device * dev,
267 					    SANE_String_Const devname,
268 					    SANE_Int vendor, SANE_Int product,
269 					    SANE_Byte mainboard);
270 
271 /*
272  * scanner calibration functions
273  */
274 SANE_Status sanei_lexmark_low_offset_calibration (Lexmark_Device * dev);
275 SANE_Status sanei_lexmark_low_gain_calibration (Lexmark_Device * dev);
276 SANE_Status sanei_lexmark_low_shading_calibration (Lexmark_Device * dev);
277 SANE_Status sanei_lexmark_low_calibration (Lexmark_Device * dev);
278 
279 #endif /* LEXMARK_H */
280