1 /* sane - Scanner Access Now Easy. 2 Copyright (C) 2000-2003 Jochen Eisinger <jochen.eisinger@gmx.net> 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 #ifndef mustek_pp_h 40 #define mustek_pp_h 41 42 #if defined(HAVE_SYS_TYPES_H) 43 # include <sys/types.h> 44 #endif 45 #if defined(HAVE_SYS_TIME_H) 46 # include <sys/time.h> 47 #endif 48 49 #define DEBUG_NOT_STATIC 50 #include "../include/sane/sanei_debug.h" 51 52 /* Please note: ASSERT won't go away if you define NDEBUG, it just won't 53 * output a message when ASSERT fails. So if "cond" does anything, it will 54 * be executed, even if NDEBUG is defined... 55 */ 56 #define ASSERT(cond, retval) do { \ 57 if (!(cond)) { \ 58 DBG(2, "assertion %s failed\n", \ 59 STRINGIFY(cond)); \ 60 if (retval >= 0) \ 61 return retval; \ 62 else \ 63 return; \ 64 } \ 65 } 66 67 /* This macro uses a otherwise unused argument */ 68 #if defined(__GNUC__) 69 # define __UNUSED__ __attribute__ ((unused)) 70 #else 71 # define __UNUSED__ 72 #endif 73 74 75 /* the function init uses this callback to register a device to the backend */ 76 typedef SANE_Status (*SANE_Attach_Callback) (SANE_String_Const port, SANE_String_Const name, 77 SANE_Int driver, SANE_Int info); 78 79 typedef struct { 80 81 const char *driver; 82 const char *author; 83 const char *version; 84 85 /* this function detects the presence of a scanner at the 86 * given location */ 87 SANE_Status (*init)(SANE_Int options, 88 SANE_String_Const port, 89 SANE_String_Const name, 90 SANE_Attach_Callback attach); 91 /* this function returns the information needed to set up 92 * the device entry. the info parameter is passed from 93 * init to the attach_callback to this function, to 94 * help to identify the device, before it is registered 95 */ 96 void (*capabilities)(SANE_Int info, 97 SANE_String *model, 98 SANE_String *vendor, 99 SANE_String *type, 100 SANE_Int *maxres, 101 SANE_Int *minres, 102 SANE_Int *maxhsize, 103 SANE_Int *maxvsize, 104 SANE_Int *caps); 105 106 /* tries to open the given device. returns a fd on success */ 107 SANE_Status (*open)(SANE_String port, SANE_Int caps, SANE_Int *fd); 108 109 /* start scanning session */ 110 void (*setup)(SANE_Handle hndl); 111 112 /* processes a configuration option */ 113 SANE_Status (*config)(SANE_Handle hndl, 114 SANE_String_Const optname, 115 SANE_String_Const optval); 116 117 /* stop scanning session */ 118 void (*close)(SANE_Handle hndl); 119 120 /* start actual scan */ 121 SANE_Status (*start)(SANE_Handle hndl); 122 123 /* read data (one line) */ 124 void (*read)(SANE_Handle hndl, SANE_Byte *buffer); 125 126 /* stop scanner and return scanhead home */ 127 void (*stop)(SANE_Handle hndl); 128 129 } Mustek_pp_Functions; 130 131 /* Drivers */ 132 133 134 135 #define MUSTEK_PP_NUM_DRIVERS ((int)(sizeof(Mustek_pp_Drivers) / \ 136 sizeof(Mustek_pp_Functions))) 137 138 #define CAP_NOTHING 0 139 #define CAP_GAMMA_CORRECT 1 140 #define CAP_INVERT 2 141 #define CAP_SPEED_SELECT 4 142 #define CAP_LAMP_OFF 8 143 #define CAP_TA 16 144 #define CAP_DEPTH 32 145 146 /* Structure for holding name/value options from the configuration file */ 147 typedef struct Mustek_pp_config_option { 148 149 SANE_String name; 150 SANE_String value; 151 152 } Mustek_pp_config_option; 153 154 typedef struct Mustek_pp_Device { 155 156 struct Mustek_pp_Device *next; 157 158 SANE_Device sane; 159 160 /* non-const copy of SANE_Device */ 161 SANE_String name, vendor, model, type; 162 163 /* port */ 164 SANE_String port; 165 166 /* part describing hardware capabilities */ 167 int minres; 168 int maxres; 169 int maxhsize; 170 int maxvsize; 171 int caps; 172 173 /* functions */ 174 Mustek_pp_Functions *func; 175 176 /* Modified by EDG: device identification is needed to initialize 177 private device descriptor */ 178 SANE_Int info; 179 180 /* Array of configuration file options */ 181 int numcfgoptions; 182 Mustek_pp_config_option *cfgoptions; 183 184 } Mustek_pp_Device; 185 186 #define STATE_IDLE 0 187 #define STATE_CANCELLED 1 188 #define STATE_SCANNING 2 189 190 #define MODE_BW 0 191 #define MODE_GRAYSCALE 1 192 #define MODE_COLOR 2 193 194 #define SPEED_SLOWEST 0 195 #define SPEED_SLOWER 1 196 #define SPEED_NORMAL 2 197 #define SPEED_FASTER 3 198 #define SPEED_FASTEST 4 199 200 201 enum Mustek_pp_Option 202 { 203 OPT_NUM_OPTS = 0, 204 205 OPT_MODE_GROUP, 206 OPT_MODE, 207 OPT_DEPTH, 208 OPT_RESOLUTION, 209 OPT_PREVIEW, 210 OPT_GRAY_PREVIEW, 211 OPT_SPEED, 212 213 OPT_GEOMETRY_GROUP, 214 OPT_TL_X, /* top-left x */ 215 OPT_TL_Y, /* top-left y */ 216 OPT_BR_X, /* bottom-right x */ 217 OPT_BR_Y, /* bottom-right y */ 218 219 OPT_ENHANCEMENT_GROUP, 220 221 222 OPT_INVERT, 223 224 OPT_CUSTOM_GAMMA, /* use custom gamma tables? */ 225 /* The gamma vectors MUST appear in the order gray, red, green, 226 blue. */ 227 OPT_GAMMA_VECTOR, 228 OPT_GAMMA_VECTOR_R, 229 OPT_GAMMA_VECTOR_G, 230 OPT_GAMMA_VECTOR_B, 231 232 /* must come last: */ 233 NUM_OPTIONS 234 }; 235 236 237 typedef struct Mustek_pp_Handle { 238 239 struct Mustek_pp_Handle *next; 240 241 242 243 Mustek_pp_Device *dev; 244 245 int fd; 246 247 int reader; 248 int pipe; 249 250 int state; 251 252 int topX, topY; 253 int bottomX, bottomY; 254 int mode; 255 int res; 256 257 /* gamma table, etc... */ 258 SANE_Int gamma_table[4][256]; 259 int do_gamma; 260 int invert; 261 int use_ta; 262 int depth; 263 int speed; 264 265 /* current parameters */ 266 SANE_Parameters params; 267 268 SANE_Range dpi_range; 269 SANE_Range x_range; 270 SANE_Range y_range; 271 SANE_Range gamma_range; 272 273 /* options */ 274 SANE_Option_Descriptor opt[NUM_OPTIONS]; 275 Option_Value val[NUM_OPTIONS]; 276 277 278 time_t lamp_on; 279 280 void *priv; 281 282 } Mustek_pp_Handle; 283 284 #endif /* mustek_pp_h */ 285