1 /* sane - Scanner Access Now Easy. 2 (C) 2003 Henning Meier-Geinitz <henning@meier-geinitz.de>. 3 4 Based on the mustek (SCSI) backend. 5 6 This file is part of the SANE package. 7 8 This program is free software; you can redistribute it and/or 9 modify it under the terms of the GNU General Public License as 10 published by the Free Software Foundation; either version 2 of the 11 License, or (at your option) any later version. 12 13 This program is distributed in the hope that it will be useful, but 14 WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with this program. If not, see <https://www.gnu.org/licenses/>. 20 21 As a special exception, the authors of SANE give permission for 22 additional uses of the libraries contained in this release of SANE. 23 24 The exception is that, if you link a SANE library with other files 25 to produce an executable, this does not by itself cause the 26 resulting executable to be covered by the GNU General Public 27 License. Your use of that executable is in no way restricted on 28 account of linking the SANE library code into it. 29 30 This exception does not, however, invalidate any other reasons why 31 the executable file might be covered by the GNU General Public 32 License. 33 34 If you submit changes to SANE to the maintainers to be included in 35 a subsequent release, you agree by submitting the changes that 36 those changes may be distributed with this exception intact. 37 38 If you write modifications of your own for SANE, it is your choice 39 whether to permit this exception to apply to your modifications. 40 If you do not wish that, delete this exception notice. 41 42 This file implements a SANE backend for scanners based on the Mustek 43 MA-1509 chipset. Currently the Mustek BearPaw 1200F is known to work. 44 */ 45 46 #ifndef ma1509_h 47 #define ma1509_h 48 49 #include "../include/sane/config.h" 50 #include <sys/types.h> 51 52 /* Some constants */ 53 #define INQ_LEN 0x60 /* Length of SCSI inquiry */ 54 #define MA1509_COMMAND_LENGTH 8 55 #define MA1509_GAMMA_SIZE 1024 56 #define MA1509_BUFFER_SIZE (1024 * 128) 57 #define MA1509_WARMUP_TIME 30 58 59 #ifndef PATH_MAX 60 # define PATH_MAX 1024 61 #endif 62 63 #define MA1509_CONFIG_FILE "ma1509.conf" 64 65 /* Convenience macros */ 66 #if defined(MIN) 67 #undef MIN 68 #endif 69 #if defined(MAX) 70 #undef MAX 71 #endif 72 #define MIN(a,b) ((a) < (b) ? (a) : (b)) 73 #define MAX(a,b) ((a) > (b) ? (a) : (b)) 74 75 /* Copy values to memory ('L' = little endian, 'B' = big endian */ 76 #define STORE16L(cp,v) \ 77 do { \ 78 int value = (v); \ 79 \ 80 *(cp)++ = (value >> 0) & 0xff; \ 81 *(cp)++ = (value >> 8) & 0xff; \ 82 } while (0) 83 #define STORE16B(cp,v) \ 84 do { \ 85 int value = (v); \ 86 \ 87 *(cp)++ = (value >> 8) & 0xff; \ 88 *(cp)++ = (value >> 0) & 0xff; \ 89 } while (0) 90 #define STORE32B(cp,v) \ 91 do { \ 92 long int value = (v); \ 93 \ 94 *(cp)++ = (value >> 24) & 0xff; \ 95 *(cp)++ = (value >> 16) & 0xff; \ 96 *(cp)++ = (value >> 8) & 0xff; \ 97 *(cp)++ = (value >> 0) & 0xff; \ 98 } while (0) 99 100 /* declarations */ 101 enum Ma1509_Option 102 { 103 OPT_NUM_OPTS = 0, 104 105 OPT_MODE_GROUP, 106 OPT_MODE, 107 OPT_RESOLUTION, 108 OPT_SOURCE, 109 OPT_PREVIEW, 110 111 OPT_GEOMETRY_GROUP, 112 OPT_TL_X, /* top-left x */ 113 OPT_TL_Y, /* top-left y */ 114 OPT_BR_X, /* bottom-right x */ 115 OPT_BR_Y, /* bottom-right y */ 116 117 OPT_ENHANCEMENT_GROUP, 118 OPT_THRESHOLD, 119 OPT_CUSTOM_GAMMA, /* use custom gamma tables? */ 120 OPT_GAMMA_VECTOR_R, 121 OPT_GAMMA_VECTOR_G, 122 OPT_GAMMA_VECTOR_B, 123 /* must come last: */ 124 NUM_OPTIONS 125 }; 126 127 typedef struct Ma1509_Device 128 { 129 struct Ma1509_Device *next; 130 SANE_String name; 131 SANE_Device sane; 132 SANE_Bool has_ta; 133 SANE_Bool has_adf; 134 SANE_Range x_range; 135 SANE_Range y_range; 136 /* scan area when transparency adapter is used: */ 137 SANE_Range x_trans_range; 138 SANE_Range y_trans_range; 139 /* values actually used by scanner, not necessarily the desired! */ 140 SANE_Int bpl, ppl, lines; 141 } 142 Ma1509_Device; 143 144 typedef struct Ma1509_Scanner 145 { 146 /* all the state needed to define a scan request: */ 147 struct Ma1509_Scanner *next; 148 149 SANE_Option_Descriptor opt[NUM_OPTIONS]; 150 Option_Value val[NUM_OPTIONS]; 151 152 SANE_Bool scanning; 153 SANE_Bool cancelled; 154 SANE_Parameters params; 155 156 /* Parsed option values and variables that are valid only during 157 actual scanning: */ 158 int fd; /* filedescriptor */ 159 long start_time; /* at this time the scan started */ 160 long lamp_time; /* at this time the lamp was turned on */ 161 SANE_Word total_bytes; /* bytes read from scanner */ 162 SANE_Word read_bytes; /* bytes transmitted by sane_read */ 163 164 SANE_Int red_gamma_table[MA1509_GAMMA_SIZE]; 165 SANE_Int green_gamma_table[MA1509_GAMMA_SIZE]; 166 SANE_Int blue_gamma_table[MA1509_GAMMA_SIZE]; 167 168 SANE_Byte *buffer, *buffer_start; 169 SANE_Int buffer_bytes; 170 /* scanner dependent/low-level state: */ 171 Ma1509_Device *hw; 172 } 173 Ma1509_Scanner; 174 175 #endif /* ma1509_h */ 176