1 /* sane - Scanner Access Now Easy. 2 3 Copyright (C) 1998, 1999 Kazuya Fukuda, Abel Deuring 4 5 This file is part of the SANE package. 6 7 This program is free software; you can redistribute it and/or 8 modify it under the terms of the GNU General Public License as 9 published by the Free Software Foundation; either version 2 of the 10 License, or (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, but 13 WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program. If not, see <https://www.gnu.org/licenses/>. 19 20 As a special exception, the authors of SANE give permission for 21 additional uses of the libraries contained in this release of SANE. 22 23 The exception is that, if you link a SANE library with other files 24 to produce an executable, this does not by itself cause the 25 resulting executable to be covered by the GNU General Public 26 License. Your use of that executable is in no way restricted on 27 account of linking the SANE library code into it. 28 29 This exception does not, however, invalidate any other reasons why 30 the executable file might be covered by the GNU General Public 31 License. 32 33 If you submit changes to SANE to the maintainers to be included in 34 a subsequent release, you agree by submitting the changes that 35 those changes may be distributed with this exception intact. 36 37 If you write modifications of your own for SANE, it is your choice 38 whether to permit this exception to apply to your modifications. 39 If you do not wish that, delete this exception notice. */ 40 41 #ifndef sharp_h 42 #define sharp_h 1 43 44 #include <sys/types.h> 45 46 /* default values for configurable options. 47 Though these options are only meaningful if USE_FORK is defined, 48 they are 49 DEFAULT_BUFFERS: number of buffers allocated as shared memory 50 for the data transfer from reader_process to 51 read_data. The minimum value is 2 52 DEFAULT_BUFSIZE: default size of one buffer. Must be greater 53 than zero. 54 DEFAULT_QUEUED_READS: number of read requests queued by 55 sanei_scsi_req_enter. Since queued read requests 56 are currently only supported for Linux and 57 DomainOS, this value should automatically be set 58 dependent on the target OS... 59 For Linux, 2 is the optimum; for DomainOS, I 60 don't have any recommendation; other OS 61 should use the value zero. 62 63 The value for DEFAULT_BUFSIZE is probably too Linux-oriented... 64 */ 65 66 #define DEFAULT_BUFFERS 12 67 #define DEFAULT_BUFSIZE 128 * 1024 68 #define DEFAULT_QUEUED_READS 2 69 70 typedef enum 71 { 72 OPT_NUM_OPTS = 0, 73 74 OPT_MODE_GROUP, 75 OPT_MODE, 76 OPT_HALFTONE, 77 OPT_PAPER, 78 OPT_SCANSOURCE, 79 OPT_GAMMA, 80 #ifdef USE_CUSTOM_GAMMA 81 OPT_CUSTOM_GAMMA, 82 #endif 83 OPT_SPEED, 84 85 OPT_RESOLUTION_GROUP, 86 #ifdef USE_RESOLUTION_LIST 87 OPT_RESOLUTION_LIST, 88 #endif 89 OPT_X_RESOLUTION, 90 #ifdef USE_SEPARATE_Y_RESOLUTION 91 OPT_Y_RESOLUTION, 92 #endif 93 94 OPT_GEOMETRY_GROUP, 95 OPT_TL_X, /* top-left x */ 96 OPT_TL_Y, /* top-left y */ 97 OPT_BR_X, /* bottom-right x */ 98 OPT_BR_Y, /* bottom-right y */ 99 100 OPT_ENHANCEMENT_GROUP, 101 OPT_EDGE_EMPHASIS, 102 OPT_THRESHOLD, 103 #ifdef USE_COLOR_THRESHOLD 104 OPT_THRESHOLD_R, 105 OPT_THRESHOLD_G, 106 OPT_THRESHOLD_B, 107 #endif 108 OPT_LIGHTCOLOR, 109 OPT_PREVIEW, 110 111 #ifdef USE_CUSTOM_GAMMA 112 OPT_GAMMA_VECTOR, 113 OPT_GAMMA_VECTOR_R, 114 OPT_GAMMA_VECTOR_G, 115 OPT_GAMMA_VECTOR_B, 116 #endif 117 /* must come last: */ 118 NUM_OPTIONS 119 } 120 SHARP_Option; 121 122 #ifdef USE_FORK 123 124 /* status defines for a buffer: 125 buffer not used / read request queued / buffer contains data 126 */ 127 #define SHM_EMPTY 0 128 #define SHM_BUSY 1 129 #define SHM_FULL 2 130 typedef struct SHARP_shmem_ctl 131 { 132 int shm_status; /* can be SHM_EMPTY, SHM_BUSY, SHM_FULL */ 133 size_t used; /* number of bytes successfully read from scanner */ 134 size_t nreq; /* number of bytes requested from scanner */ 135 size_t start; /* index of the begin of used area of the buffer */ 136 void *qid; 137 SANE_Byte *buffer; 138 } 139 SHARP_shmem_ctl; 140 141 typedef struct SHARP_rdr_ctl 142 { 143 int cancel; /* 1 = flag for the reader process to cancel */ 144 int running; /* 1 indicates that the reader process is alive */ 145 SANE_Status status; /* return status of the reader process */ 146 SHARP_shmem_ctl *buf_ctl; 147 } 148 SHARP_rdr_ctl; 149 #endif /* USE_FORK */ 150 151 typedef enum 152 { 153 /* JX250, JX330, JX350, JX610 are used as array indices, so the 154 corresponding numbers should start at 0 155 */ 156 unknown = -1, 157 JX250, 158 JX320, 159 JX330, 160 JX350, 161 JX610 162 } 163 SHARP_Model; 164 165 typedef struct SHARP_Info 166 { 167 SANE_Range xres_range; 168 SANE_Range yres_range; 169 SANE_Range tl_x_ranges[3]; /* normal / FSU / ADF */ 170 SANE_Range br_x_ranges[3]; /* normal / FSU / ADF */ 171 SANE_Range tl_y_ranges[3]; /* normal / FSU / ADF */ 172 SANE_Range br_y_ranges[3]; /* normal / FSU / ADF */ 173 SANE_Range threshold_range; 174 175 SANE_Int xres_default; 176 SANE_Int yres_default; 177 SANE_Int x_default; 178 SANE_Int y_default; 179 SANE_Int bmu; 180 SANE_Int mud; 181 SANE_Int adf_fsu_installed; 182 SANE_String_Const scansources[5]; 183 size_t buffers; 184 size_t bufsize; 185 int wanted_bufsize; 186 size_t queued_reads; 187 int complain_on_errors; 188 /* default scan mode: 189 -1 -> "automatic": Use the ADF, if installed, 190 else use the FSU, if installed. 191 or: SCAN_ADF, SCAN_FSU, SCAN_SIMPLE 192 */ 193 int default_scan_mode; 194 } 195 SHARP_Info; 196 197 #define COMPLAIN_ON_FSU_ERROR 2 198 #define COMPLAIN_ON_ADF_ERROR 1 199 typedef struct SHARP_Sense_Data 200 { 201 SHARP_Model model; 202 /* flag, if conditions like "paper jam" or "cover open" 203 are considered as an error. Should be 0 for attach, else 204 a frontend might refuse to start, if the scanner returns 205 these errors. 206 */ 207 int complain_on_errors; 208 /* Linux returns only 16 bytes of sense data... */ 209 u_char sb[16]; 210 } 211 SHARP_Sense_Data; 212 213 typedef struct SHARP_Device 214 { 215 struct SHARP_Device *next; 216 SANE_Device sane; 217 SHARP_Info info; 218 /* xxx now part of sense data SHARP_Model model; */ 219 SHARP_Sense_Data sensedat; 220 } 221 SHARP_Device; 222 223 typedef struct SHARP_New_Device 224 { 225 struct SHARP_Device *dev; 226 struct SHARP_New_Device *next; 227 } 228 SHARP_New_Device; 229 230 typedef struct SHARP_Scanner 231 { 232 struct SHARP_Scanner *next; 233 int fd; 234 SHARP_Device *dev; 235 SANE_Option_Descriptor opt[NUM_OPTIONS]; 236 Option_Value val[NUM_OPTIONS]; 237 SANE_Parameters params; 238 239 int get_params_called; 240 SANE_Byte *buffer; /* for color data re-ordering, required for JX 250 */ 241 SANE_Int buf_used; 242 SANE_Int buf_pos; 243 SANE_Int modes; 244 SANE_Int xres; 245 SANE_Int yres; 246 SANE_Int ulx; 247 SANE_Int uly; 248 SANE_Int width; 249 SANE_Int length; 250 SANE_Int threshold; 251 SANE_Int image_composition; 252 SANE_Int bpp; 253 SANE_Int halftone; 254 SANE_Bool reverse; 255 SANE_Bool speed; 256 SANE_Int gamma; 257 SANE_Int edge; 258 SANE_Int lightcolor; 259 SANE_Int adf_fsu_mode; /* mode selected by user */ 260 SANE_Int adf_scan; /* flag, if the actual scan is an ADF scan */ 261 262 size_t bytes_to_read; 263 size_t max_lines_to_read; 264 size_t unscanned_lines; 265 SANE_Bool scanning; 266 SANE_Bool busy; 267 SANE_Bool cancel; 268 #ifdef USE_CUSTOM_GAMMA 269 SANE_Int gamma_table[4][256]; 270 #endif 271 #ifdef USE_FORK 272 pid_t reader_pid; 273 SHARP_rdr_ctl *rdr_ctl; 274 int shmid; 275 size_t read_buff; /* index of the buffer actually used by read_data */ 276 #endif /* USE_FORK */ 277 } 278 SHARP_Scanner; 279 280 typedef struct SHARP_Send 281 { 282 SANE_Int dtc; 283 SANE_Int dtq; 284 SANE_Int length; 285 SANE_Byte *data; 286 } 287 SHARP_Send; 288 289 typedef struct WPDH 290 { 291 u_char wpdh[6]; 292 u_char wdl[2]; 293 } 294 WPDH; 295 296 typedef struct WDB 297 { 298 SANE_Byte wid; 299 SANE_Byte autobit; 300 SANE_Byte x_res[2]; 301 SANE_Byte y_res[2]; 302 303 SANE_Byte x_ul[4]; 304 SANE_Byte y_ul[4]; 305 SANE_Byte width[4]; 306 SANE_Byte length[4]; 307 308 SANE_Byte brightness; 309 SANE_Byte threshold; 310 SANE_Byte null_1; 311 312 SANE_Byte image_composition; 313 SANE_Byte bpp; 314 315 SANE_Byte ht_pattern[2]; 316 SANE_Byte rif_padding; 317 SANE_Byte null_2[4]; 318 SANE_Byte null_3[6]; 319 SANE_Byte eletu; 320 SANE_Byte zooming_x[2]; 321 SANE_Byte zooming_y[2]; 322 SANE_Byte lightness_r[2]; 323 SANE_Byte lightness_g[2]; 324 SANE_Byte lightness_b[2]; 325 SANE_Byte lightness_bw[2]; 326 327 } 328 WDB; 329 330 /* "extension" of the window descriptor block for the JX 330 */ 331 typedef struct WDBX330 332 { 333 SANE_Byte moire_reduction[2]; 334 } 335 WDBX330; 336 337 /* "extension" of the window descriptor block for the JX 250 */ 338 typedef struct XWDBX250 339 { 340 SANE_Byte threshold_red; 341 SANE_Byte threshold_green; 342 SANE_Byte threshold_blue; 343 SANE_Byte draft; 344 SANE_Byte scanning_time[4]; 345 SANE_Byte fixed_gamma; 346 SANE_Byte x_axis_res_qualifier[2]; 347 SANE_Byte y_axis_res_qualifier[2]; 348 } 349 WDBX250; 350 351 typedef struct window_param 352 { 353 WPDH wpdh; 354 WDB wdb; 355 WDBX330 wdbx330; 356 WDBX250 wdbx250; 357 } 358 window_param; 359 360 typedef struct mode_sense_param 361 { 362 SANE_Byte mode_data_length; 363 SANE_Byte mode_param_header2; 364 SANE_Byte mode_param_header3; 365 SANE_Byte mode_desciptor_length; 366 SANE_Byte resereved[5]; 367 SANE_Byte blocklength[3]; 368 SANE_Byte page_code; 369 SANE_Byte page_length; /* 6 */ 370 SANE_Byte bmu; 371 SANE_Byte res2; 372 SANE_Byte mud[2]; 373 SANE_Byte res3; 374 SANE_Byte res4; 375 } 376 mode_sense_param; 377 378 typedef struct mode_sense_subdevice 379 { 380 /* This definition reflects the JX250. The JX330 would need a slightly 381 different definition, but the bytes used right now (for ADF and FSU) 382 are identical. 383 */ 384 SANE_Byte mode_data_length; 385 SANE_Byte mode_param_header2; 386 SANE_Byte mode_param_header3; 387 SANE_Byte mode_desciptor_length; 388 SANE_Byte res1[5]; 389 SANE_Byte blocklength[3]; 390 SANE_Byte page_code; 391 SANE_Byte page_length; /* 0x1a */ 392 SANE_Byte a_mode_type; 393 SANE_Byte f_mode_type; 394 SANE_Byte res2; 395 SANE_Byte max_x[4]; 396 SANE_Byte max_y[4]; 397 SANE_Byte res3[2]; 398 SANE_Byte x_basic_resolution[2]; 399 SANE_Byte y_basic_resolution[2]; 400 SANE_Byte x_max_resolution[2]; 401 SANE_Byte y_max_resolution[2]; 402 SANE_Byte x_min_resolution[2]; 403 SANE_Byte y_min_resolution[2]; 404 SANE_Byte res4; 405 } 406 mode_sense_subdevice; 407 408 typedef struct mode_select_param 409 { 410 SANE_Byte mode_param_header1; 411 SANE_Byte mode_param_header2; 412 SANE_Byte mode_param_header3; 413 SANE_Byte mode_param_header4; 414 SANE_Byte page_code; 415 SANE_Byte page_length; /* 6 */ 416 SANE_Byte res1; 417 SANE_Byte res2; 418 SANE_Byte mud[2]; 419 SANE_Byte res3; 420 SANE_Byte res4; 421 } 422 mode_select_param; 423 424 typedef struct mode_select_subdevice 425 { 426 SANE_Byte mode_param_header1; 427 SANE_Byte mode_param_header2; 428 SANE_Byte mode_param_header3; 429 SANE_Byte mode_param_header4; 430 SANE_Byte page_code; 431 SANE_Byte page_length; /* 0x1A */ 432 SANE_Byte a_mode; 433 SANE_Byte f_mode; 434 SANE_Byte res[24]; 435 } 436 mode_select_subdevice; 437 438 /* SCSI commands */ 439 #define TEST_UNIT_READY 0x00 440 #define REQUEST_SENSE 0x03 441 #define INQUIRY 0x12 442 #define MODE_SELECT6 0x15 443 #define RESERVE_UNIT 0x16 444 #define RELEASE_UNIT 0x17 445 #define MODE_SENSE6 0x1a 446 #define SCAN 0x1b 447 #define SEND_DIAGNOSTIC 0x1d 448 #define SET_WINDOW 0x24 449 #define GET_WINDOW 0x25 450 #define READ 0x28 451 #define SEND 0x2a 452 #define OBJECT_POSITION 0x31 453 454 #define SENSE_LEN 18 455 #define INQUIRY_LEN 36 456 #define MODEPARAM_LEN 12 457 #define MODE_SUBDEV_LEN 32 458 #define WINDOW_LEN 76 459 460 #endif /* not sharp_h */ 461