1 /* sane - Scanner Access Now Easy.
2    Copyright (C) 1997 Geoffrey T. Dairiki
3    This file is part of the SANE package.
4 
5    This program is free software; you can redistribute it and/or
6    modify it under the terms of the GNU General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    License, or (at your option) any later version.
9 
10    This program is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14 
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 
18    As a special exception, the authors of SANE give permission for
19    additional uses of the libraries contained in this release of SANE.
20 
21    The exception is that, if you link a SANE library with other files
22    to produce an executable, this does not by itself cause the
23    resulting executable to be covered by the GNU General Public
24    License.  Your use of that executable is in no way restricted on
25    account of linking the SANE library code into it.
26 
27    This exception does not, however, invalidate any other reasons why
28    the executable file might be covered by the GNU General Public
29    License.
30 
31    If you submit changes to SANE to the maintainers to be included in
32    a subsequent release, you agree by submitting the changes that
33    those changes may be distributed with this exception intact.
34 
35    If you write modifications of your own for SANE, it is your choice
36    whether to permit this exception to apply to your modifications.
37    If you do not wish that, delete this exception notice.
38 
39    This file is part of a SANE backend for HP Scanners supporting
40    HP Scanner Control Language (SCL).
41 */
42 
43 #ifndef HP_H_INCLUDED
44 #define HP_H_INCLUDED
45 #include <limits.h>
46 #include <sys/types.h>
47 #include "../include/sane/sane.h"
48 
49 #undef BACKEND_NAME
50 #define BACKEND_NAME	hp
51 #define DEBUG_NOT_STATIC
52 #include "../include/sane/sanei_debug.h"
53 
54 /* FIXME: these should be options? */
55 #undef ENABLE_7x12_TONEMAPS
56 #define ENABLE_16x16_DITHERS
57 #define ENABLE_10BIT_MATRIXES
58 
59 #define FAKE_COLORSEP_MATRIXES
60 
61 #undef ENABLE_CUSTOM_MATRIX
62 
63 #define HP_CONFIG_FILE 	 STRINGIFY(BACKEND_NAME) ".conf"
64 
65 #define DEVPIX_PER_INCH		300.0
66 #define MM_PER_DEVPIX		(MM_PER_INCH / DEVPIX_PER_INCH)
67 
68 /*
69  * Macros for testing return values of functions which
70  * return SANE_Status types.
71  */
72 #define FAILED(status)		(status != SANE_STATUS_GOOD)
73 #define UNSUPPORTED(status)	(status == SANE_STATUS_UNSUPPORTED)
74 #define RETURN_IF_FAIL(try)	do {					\
75   SANE_Status status = (try);						\
76   if (FAILED(status))							\
77       return status;							\
78 } while (0)
79 #define CATCH_RET_FAIL(try, catch) do {					\
80   SANE_Status status = (try);						\
81   if (FAILED(status)) { (catch); return status; }			\
82 } while (0)
83 
84 #ifndef DBG_LEVEL
85 #define DBG_LEVEL	PASTE(sanei_debug_, BACKEND_NAME)
86 #endif
87 #ifndef NDEBUG
88 # define DBGDUMP(level, buf, size) \
89     do { if (DBG_LEVEL >= (level)) sanei_hp_dbgdump(buf, size); } while (0)
90 #else
91 # define DBGDUMP(level, buf, size)
92 #endif
93 
94 
95  /*
96   *
97   */
98 
99 typedef unsigned int	hp_bool_t;
100 typedef unsigned char	hp_byte_t;
101 
102 typedef enum { HP_CONNECT_SCSI, HP_CONNECT_DEVICE,
103                HP_CONNECT_PIO, HP_CONNECT_USB, HP_CONNECT_RESERVE } HpConnect;
104 
105 typedef struct
106 {
107   HpConnect connect;
108   hp_bool_t got_connect_type;
109   hp_bool_t use_scsi_request;
110   hp_bool_t use_image_buffering;
111   hp_bool_t dumb_read;
112 } HpDeviceConfig;
113 
114 #define HP_SCL_INQID_MIN   10306
115 #define HP_SCL_INQID_MAX   10971
116 
117 typedef struct
118 {
119   hp_bool_t checked, is_supported;
120   int minval, maxval;
121 } HpSclSupport;
122 
123 typedef struct
124 {                              /* Flags for simulated commands */
125   hp_bool_t sclsimulate[HP_SCL_INQID_MAX - HP_SCL_INQID_MIN + 1];
126   hp_bool_t gamma_simulate;
127   unsigned char brightness_map[256]; /* Map to simulate brightness level */
128   unsigned char contrast_map[256];   /* Map to simulate contrast level */
129   unsigned char gamma_map[256];      /* Map to simulate custom gamma table */
130 } HpSimulate;
131 
132 /* Information about a connected device */
133 typedef struct
134 {
135   char devname[64];            /* unique device name */
136 
137   hp_bool_t config_is_up;      /* flag if config-struct is valid */
138   HpDeviceConfig config;       /* device configuration*/
139                                /* List of command support */
140   HpSclSupport sclsupport[HP_SCL_INQID_MAX - HP_SCL_INQID_MIN + 1];
141 
142   HpSimulate simulate;         /* Info about simulations */
143 
144   hp_bool_t  unload_after_scan;
145   int        active_xpa;
146   int        max_model;
147 } HpDeviceInfo;
148 
149 HpDeviceInfo *sanei_hp_device_info_get (const char *dev_name);
150 
151 /* hp-scl.c */
152 #if INT_MAX > 30000
153 typedef	int HpScl;
154 #else
155 typedef long int HpScl;
156 #endif
157 
158 void sanei_hp_init_openfd (void);
159 
160 typedef struct
161 {
162   int lines;
163   int bytes_per_line;     /* as received from scanner */
164   int bits_per_channel;
165   hp_bool_t out8;         /* This flag is set and only set, when data with */
166                           /* depths > 8 is to be mapped to 8 bit output. */
167   hp_bool_t mirror_vertical;
168   hp_bool_t invert;
169   HpScl startscan;
170 } HpProcessData;
171 
172 /* hp-option.c */
173 typedef SANE_Option_Descriptor *	HpSaneOption;
174 
175 typedef const struct hp_choice_s *	HpChoice;
176 typedef struct hp_option_s *		HpOption;
177 typedef const struct hp_option_descriptor_s *	HpOptionDescriptor;
178 typedef struct hp_optset_s *		HpOptSet;
179 
180 /* hp-accessor.c */
181 typedef struct hp_data_s *		HpData;
182 typedef struct hp_accessor_s *	HpAccessor;
183 typedef struct hp_accessor_vector_s *	HpAccessorVector;
184 typedef struct hp_accessor_choice_s *	HpAccessorChoice;
185 
186 /* hp-device.c */
187 typedef struct hp_device_s *	HpDevice;
188 hp_bool_t sanei_hp_device_simulate_get (const char *devname, HpScl scl);
189 HpDevice sanei_hp_device_get (const char *dev_name);
190 
191 /* hp-handle.c */
192 typedef struct hp_handle_s *	HpHandle;
193 
194 /* hp-scsi.c */
195 typedef struct hp_scsi_s * 	HpScsi;
196 
197 /* hp-scl.c */
198 hp_bool_t sanei_hp_is_active_xpa (HpScsi scsi);
199 int sanei_hp_get_max_model (HpScsi scsi);
200 int sanei_hp_is_flatbed_adf (HpScsi scsi);
201 HpConnect sanei_hp_get_connect (const char *devname);
202 HpConnect sanei_hp_scsi_get_connect (HpScsi this);
203 
204 /* hp.c */
205 #ifndef NDEBUG
206 void sanei_hp_dbgdump (const void * bufp, size_t len);
207 #endif
208 
209 /* hp-hpmem.c */
210 void *	sanei_hp_alloc(size_t sz);
211 void *	sanei_hp_allocz(size_t sz);
212 void *	sanei_hp_memdup(const void * src, size_t sz);
213 char *	sanei_hp_strdup(const char * str);
214 void *	sanei_hp_realloc(void * ptr, size_t sz);
215 void	sanei_hp_free(void * ptr);
216 void	sanei_hp_free_all(void);
217 
218 #endif /* HP_H_INCLUDED */
219