1 #ifndef KODAK_H 2 #define KODAK_H 3 4 /* 5 * Part of SANE - Scanner Access Now Easy. 6 * Please see opening comment in kodak.c 7 */ 8 9 /* ------------------------------------------------------------------------- 10 * This option list has to contain all options for all scanners supported by 11 * this driver. If a certain scanner cannot handle a certain option, there's 12 * still the possibility to say so, later. 13 */ 14 enum kodak_Option 15 { 16 OPT_NUM_OPTS = 0, 17 18 OPT_MODE_GROUP, 19 OPT_SOURCE, /*front/back/duplex*/ 20 OPT_MODE, /*mono/ht/gray/color*/ 21 OPT_RES, 22 23 OPT_GEOMETRY_GROUP, 24 OPT_TL_X, 25 OPT_TL_Y, 26 OPT_BR_X, 27 OPT_BR_Y, 28 OPT_PAGE_WIDTH, 29 OPT_PAGE_HEIGHT, 30 31 OPT_ENHANCEMENT_GROUP, 32 OPT_BRIGHTNESS, 33 OPT_CONTRAST, 34 OPT_THRESHOLD, 35 OPT_RIF, 36 37 /* must come last: */ 38 NUM_OPTIONS 39 }; 40 41 struct scanner 42 { 43 /* --------------------------------------------------------------------- */ 44 /* immutable values which are set during init of scanner. */ 45 struct scanner *next; 46 char *device_name; /* The name of the scanner device for sane */ 47 48 /* --------------------------------------------------------------------- */ 49 /* immutable values which are set during reading of config file. */ 50 int buffer_size; 51 52 /* --------------------------------------------------------------------- */ 53 /* immutable values which are set during inquiry probing of the scanner. */ 54 /* members in order found in scsi data... */ 55 SANE_Device sane; 56 57 char vendor_name[9]; /* null-term data returned by SCSI inquiry.*/ 58 char product_name[17]; /* null-term data returned by SCSI inquiry.*/ 59 char version_name[5]; /* null-term data returned by SCSI inquiry.*/ 60 char build_name[3]; /* null-term data returned by SCSI inquiry.*/ 61 62 /* --------------------------------------------------------------------- */ 63 /* immutable values which are set during INQUIRY probing of the scanner, */ 64 /* or in the init_model cleanup routine... */ 65 66 /* which modes scanner has */ 67 int s_mode[4]; 68 69 /* min and max resolution for each mode */ 70 int s_res_min[4]; 71 int s_res_max[4]; 72 73 /* in 1/1200th inches, NOT sane units */ 74 int s_width_min; 75 int s_width_max; 76 int s_length_min; 77 int s_length_max; 78 79 int s_brightness_steps; 80 int s_contrast_steps; 81 int s_threshold_steps; 82 int s_rif; 83 84 /* --------------------------------------------------------------------- */ 85 /* changeable SANE_Option structs provide our interface to frontend. */ 86 /* some options require lists of strings or numbers, we keep them here */ 87 /* instead of in global vars so that they can differ for each scanner */ 88 89 /* long array of option structs */ 90 SANE_Option_Descriptor opt[NUM_OPTIONS]; 91 92 /*mode group*/ 93 SANE_String_Const o_source_list[4]; 94 SANE_String_Const o_mode_list[5]; 95 SANE_Int o_res_list[4][6]; 96 97 /*geometry group*/ 98 SANE_Range o_tl_x_range; 99 SANE_Range o_tl_y_range; 100 SANE_Range o_br_x_range; 101 SANE_Range o_br_y_range; 102 SANE_Range o_page_x_range; 103 SANE_Range o_page_y_range; 104 105 /*enhancement group*/ 106 SANE_Range o_brightness_range; 107 SANE_Range o_contrast_range; 108 SANE_Range o_threshold_range; 109 110 /* --------------------------------------------------------------------- */ 111 /* changeable vars to hold user input. modified by SANE_Options above */ 112 113 /*mode group*/ 114 int u_mode; /* color,lineart,etc */ 115 int u_source; /* adf front,adf duplex,etc */ 116 int u_res; /* resolution in dpi */ 117 118 /*geometry group*/ 119 /* The desired size of the scan, all in 1/1200 inch */ 120 int u_tl_x; 121 int u_tl_y; 122 int u_br_x; 123 int u_br_y; 124 int u_page_width; 125 int u_page_height; 126 127 /*enhancement group*/ 128 int u_brightness; 129 int u_contrast; 130 int u_threshold; 131 int u_rif; 132 int u_compr; 133 134 /* --------------------------------------------------------------------- */ 135 /* values which are set by the scanner's post-scan image header */ 136 int i_bytes; 137 int i_id; 138 int i_dpi; 139 int i_tlx; 140 int i_tly; 141 int i_width; 142 int i_length; 143 int i_bpp; 144 int i_compr; 145 146 /* --------------------------------------------------------------------- */ 147 /* values which are set by scanning functions to keep track of pages, etc */ 148 int started; 149 150 /* total to read/write */ 151 int bytes_tot; 152 153 /* how far we have read */ 154 int bytes_rx; 155 156 /* how far we have written */ 157 int bytes_tx; 158 159 /* size of buffer */ 160 int bytes_buf; 161 162 /* the buffer */ 163 unsigned char * buffer; 164 165 /* --------------------------------------------------------------------- */ 166 /* values which used by the command and data sending functions (scsi/usb)*/ 167 int fd; /* The scanner device file descriptor. */ 168 size_t rs_info; 169 170 }; 171 172 #define DEFAULT_BUFFER_SIZE 32768 173 174 #define SIDE_FRONT 0 175 #define SIDE_BACK 1 176 177 #define SOURCE_ADF_FRONT 0 178 #define SOURCE_ADF_BACK 1 179 #define SOURCE_ADF_DUPLEX 2 180 181 #define MODE_LINEART 0 182 #define MODE_HALFTONE 1 183 #define MODE_GRAYSCALE 2 184 #define MODE_COLOR 3 185 186 /* ------------------------------------------------------------------------- */ 187 188 #define MM_PER_INCH 25.4 189 #define MM_PER_UNIT_UNFIX SANE_UNFIX(SANE_FIX(MM_PER_INCH / 1200.0)) 190 #define MM_PER_UNIT_FIX SANE_FIX(SANE_UNFIX(SANE_FIX(MM_PER_INCH / 1200.0))) 191 192 #define SCANNER_UNIT_TO_FIXED_MM(number) SANE_FIX((number) * MM_PER_UNIT_UNFIX) 193 #define FIXED_MM_TO_SCANNER_UNIT(number) SANE_UNFIX(number) / MM_PER_UNIT_UNFIX 194 195 #define KODAK_CONFIG_FILE "kodak.conf" 196 197 #ifndef PATH_MAX 198 # define PATH_MAX 1024 199 #endif 200 201 /* ------------------------------------------------------------------------- */ 202 203 SANE_Status sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize); 204 205 SANE_Status sane_get_devices (const SANE_Device *** device_list, 206 SANE_Bool local_only); 207 208 SANE_Status sane_open (SANE_String_Const name, SANE_Handle * handle); 209 210 SANE_Status sane_set_io_mode (SANE_Handle h, SANE_Bool non_blocking); 211 212 SANE_Status sane_get_select_fd (SANE_Handle h, SANE_Int * fdp); 213 214 const SANE_Option_Descriptor * sane_get_option_descriptor (SANE_Handle handle, 215 SANE_Int option); 216 217 SANE_Status sane_control_option (SANE_Handle handle, SANE_Int option, 218 SANE_Action action, void *val, 219 SANE_Int * info); 220 221 SANE_Status sane_start (SANE_Handle handle); 222 223 SANE_Status sane_get_parameters (SANE_Handle handle, 224 SANE_Parameters * params); 225 226 SANE_Status sane_read (SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, 227 SANE_Int * len); 228 229 void sane_cancel (SANE_Handle h); 230 231 void sane_close (SANE_Handle h); 232 233 void sane_exit (void); 234 235 /* ------------------------------------------------------------------------- */ 236 237 static SANE_Status attach_one (const char *name); 238 static SANE_Status connect_fd (struct scanner *s); 239 static SANE_Status disconnect_fd (struct scanner *s); 240 static SANE_Status sense_handler (int scsi_fd, u_char * result, void *arg); 241 242 static SANE_Status init_inquire (struct scanner *s); 243 static SANE_Status init_model (struct scanner *s); 244 static SANE_Status init_user (struct scanner *s); 245 static SANE_Status init_options (struct scanner *s); 246 247 static SANE_Status 248 do_cmd(struct scanner *s, int runRS, int shortTime, 249 unsigned char * cmdBuff, size_t cmdLen, 250 unsigned char * outBuff, size_t outLen, 251 unsigned char * inBuff, size_t * inLen 252 ); 253 254 #if 0 /* unused */ 255 static SANE_Status wait_scanner (struct scanner *s); 256 #endif 257 258 static SANE_Status do_cancel (struct scanner *scanner); 259 260 static SANE_Status set_window (struct scanner *s); 261 static SANE_Status read_imageheader(struct scanner *s); 262 static SANE_Status send_sc(struct scanner *s); 263 264 static SANE_Status read_from_scanner(struct scanner *s); 265 static SANE_Status copy_buffer(struct scanner *s, unsigned char * buf, int len); 266 static SANE_Status read_from_buffer(struct scanner *s, SANE_Byte * buf, SANE_Int max_len, SANE_Int * len); 267 268 static void hexdump (int level, char *comment, unsigned char *p, int l); 269 270 static size_t maxStringSize (const SANE_String_Const strings[]); 271 272 #endif /* KODAK_H */ 273