Lines Matching defs:dev

59 	. - sane_open() : open a particular scanner-device and attach_scanner(devicename,&dev)
338 static void umax_print_inquiry(Umax_Device *dev)
343 inquiry_block=dev->buffer[0];
348 DBG(DBG_inquiry,"vendor........................: '%s'\n", dev->vendor);
349 DBG(DBG_inquiry,"product.......................: '%s'\n", dev->product);
350 DBG(DBG_inquiry,"version.......................: '%s'\n", dev->version);
360 DBG(DBG_inquiry,"CBHS value range..............: %s\n", cbhs_str[dev->inquiry_cbhs]);
362 if (dev->inquiry_transavail)
374 DBG(DBG_inquiry,"inquiry block length..........: %d bytes\n", dev->inquiry_len);
375 if (dev->inquiry_len<=0x8e)
407 if (dev->inquiry_len<=0x24)
415 DBG_inq_nz(" - quality calibration\n", dev->inquiry_quality_ctrl);
416 DBG_inq_nz(" - fast preview function\n", dev->inquiry_preview);
419 DBG_inq_nz(" - lamp intensity control\n", dev->inquiry_lamp_ctrl);
466 if (dev->inquiry_len<=0x60)
476 DBG_inq_nz(" - lineart mode\n", dev->inquiry_lineart);
477 DBG_inq_nz(" - halftone mode\n", dev->inquiry_halftone);
478 DBG_inq_nz(" - gray mode\n", dev->inquiry_gray);
479 DBG_inq_nz(" - color mode\n", dev->inquiry_color);
480 DBG_inq_nz(" - transparency (UTA)\n", dev->inquiry_uta);
481 DBG_inq_nz(" - automatic document feeder (ADF)\n", dev->inquiry_adf);
484 if (dev->inquiry_len<=0x61)
495 DBG_inq_nz(" - double resolution\n", dev->inquiry_dor);
497 DBG_inq_nz(" - bi-level image reverse\n", dev->inquiry_reverse);
498 DBG_inq_nz(" - multi-level image reverse\n", dev->inquiry_reverse_multi);
499 DBG_inq_nz(" - support shadow function\n", dev->inquiry_shadow);
500 DBG_inq_nz(" - support highlight function\n", dev->inquiry_highlight);
505 if (dev->inquiry_len<=0x62)
511 DBG_inq_nz(" - analog gamma correction\n", dev->inquiry_analog_gamma);
519 if (dev->inquiry_len<=0x63)
534 if (dev->inquiry_len<=0x68)
539 if (dev->inquiry_gamma_dwload)
579 if (dev->inquiry_len<=0x69)
594 if (dev->inquiry_len<=0x6a)
612 if (dev->inquiry_len<=0x6d)
632 if (dev->inquiry_len<=0x71)
638 DBG(DBG_inquiry,"maximum video memory......................: %d KB\n", dev->inquiry_vidmem/1024);
646 if (dev->inquiry_len<=0x75)
651 DBG(DBG_inquiry,"optical resolution........................: %d dpi\n", dev->inquiry_optical_res);
652 DBG(DBG_inquiry,"maximum x-resolution......................: %d dpi\n", dev->inquiry_x_res);
653 DBG(DBG_inquiry,"maximum y-resolution......................: %d dpi\n", dev->inquiry_y_res);
658 if (dev->inquiry_len<=0x77)
665 DBG(DBG_inquiry,"FB maximum scan width.....................: %2.2f inch\n", dev->inquiry_fb_width);
666 DBG(DBG_inquiry,"FB maximum scan length....................: %2.2f inch\n", dev->inquiry_fb_length);
671 if (dev->inquiry_len<=0x81)
678 DBG(DBG_inquiry,"UTA x-original point......................: %2.2f inch\n", dev->inquiry_uta_x_off);
679 DBG(DBG_inquiry,"UTA y-original point......................: %2.2f inch\n", dev->inquiry_uta_y_off);
680 DBG(DBG_inquiry,"UTA maximum scan width....................: %2.2f inch\n", dev->inquiry_uta_width);
681 DBG(DBG_inquiry,"UTA maximum scan length...................: %2.2f inch\n", dev->inquiry_uta_length);
692 if (dev->inquiry_len<=0x85)
699 DBG(DBG_inquiry,"DOR optical resolution....................: %d dpi\n", dev->inquiry_dor_optical_res);
700 DBG(DBG_inquiry,"DOR maximum x-resolution..................: %d dpi\n", dev->inquiry_dor_x_res);
701 DBG(DBG_inquiry,"DOR maximum y-resolution..................: %d dpi\n", dev->inquiry_dor_y_res);
704 if (dev->inquiry_len<=0x8d)
709 DBG(DBG_inquiry,"DOR x-original point......................: %2.2f inch\n", dev->inquiry_dor_x_off);
710 DBG(DBG_inquiry,"DOR y-original point......................: %2.2f inch\n", dev->inquiry_dor_y_off);
711 DBG(DBG_inquiry,"DOR maximum scan width....................: %2.2f inch\n", dev->inquiry_dor_width);
712 DBG(DBG_inquiry,"DOR maximum scan length...................: %2.2f inch\n", dev->inquiry_dor_length);
724 if (dev->inquiry_len<=0x8f)
738 if (dev->inquiry_len<=0x91)
743 DBG(DBG_inquiry,"lamp warmup maximum time..................: %d sec\n", dev->inquiry_max_warmup_time);
746 if (dev->inquiry_len<=0x93)
756 if (dev->inquiry_len<=0x97)
777 if (dev->inquiry_len<=0x9a)
786 if (dev->inquiry_len<=0x9b)
795 if (dev->inquiry_len<=0x9c)
804 if (dev->inquiry_len<=0x9d)
816 if (dev->inquiry_len<=0xa2)
822 for(i=0xa3; i<dev->inquiry_len; i++)
852 Umax_Device *dev = arg;
866 switch (dev->handle_bad_sense_error)
890 memset(dev->buffer[0], 0, rs_return_block_size); /* clear sense data buffer */
891 memcpy(dev->buffer[0], result, len+1); /* copy sense data to buffer */
1039 dev->button0_pressed = 1;
1045 dev->button1_pressed = 1;
1051 dev->button2_pressed = 1;
1064 if (dev)
1066 dev->do_calibration = 1; /* set flag for calibration by driver */
1222 static int umax_forget_line(Umax_Device *dev, int color)
1226 unsigned int opt_res = dev->relevant_optical_res * dev->scale_y;
1229 dev->pixelline_opt_res++; /* increment number of lines in optical res */
1231 if (opt_res != dev->y_resolution) /* are there any lines to skip ? */
1234 forget = (dev->pixelline_del[color] * opt_res)/(opt_res - dev->y_resolution);
1236 if (dev->pixelline_optic[color]++ == forget)
1238 dev->pixelline_del[color]++; /* inc pointer to next line to skip */
1250 static void umax_order_line_to_pixel(Umax_Device *dev, unsigned char *source, int color)
1256 unsigned int line = dev->pixelline_next[color]; /* bufferlinenumber */
1257 unsigned char *dest = dev->pixelbuffer;
1261 if (dev->bits_per_pixel_code == 1) /* 24 bpp */
1263 dest += line * dev->width_in_pixels * 3 + color;
1265 for (i=0; i<dev->width_in_pixels; i++) /* cp each pixel into pixelbuffer */
1274 dest += line * dev->width_in_pixels * 6 + color * 2;
1276 for(i=0; i<dev->width_in_pixels; i++) /* cp each pixel into pixelbuffer */
1287 if (line >= dev->pixelline_max)
1292 dev->pixelline_next[color] = line; /* next line of this color */
1293 dev->pixelline_ready[color]++; /* number of ready lines for color */
1295 DBG(DBG_read, "merged line as color %d to line %d\n", color, dev->pixelline_ready[color]);
1303 static void umax_order_line(Umax_Device *dev, unsigned char *source)
1305 unsigned int CCD_distance = dev->CCD_distance * dev->scale_y;
1306 unsigned int length = (dev->scanlength * dev->scale_y * dev->relevant_optical_res) / dev->y_coordinate_base;
1311 if (dev->pixelline_opt_res < CCD_distance)
1313 color = dev->CCD_color[0]; /* color 0 */
1315 else if (dev->pixelline_opt_res < CCD_distance * 3)
1317 color = dev->CCD_color[1 + ((dev->pixelline_opt_res - CCD_distance) % 2)]; /* color 1,2 */
1319 else if (dev->pixelline_opt_res < length * 3 - CCD_distance * 3)
1321 color = dev->CCD_color[3 + (dev->pixelline_opt_res % 3)]; /* color 3,4,5 */
1323 else if (dev->pixelline_opt_res < length * 3 - CCD_distance)
1325 color = dev->CCD_color[6 + ((dev->pixelline_opt_res - length*3 + CCD_distance*3) % 2)]; /* color 6,7 */
1329 color = dev->CCD_color[8]; /* color 8 */
1331 } while(umax_forget_line(dev, color) != 0); /* until found correct line */
1333 umax_order_line_to_pixel(dev, source, color);
1340 static unsigned char * umax_get_pixel_line(Umax_Device *dev)
1344 if (dev->pixelbuffer != NULL)
1346 if ( (dev->pixelline_ready[0] > dev->pixelline_written) &&
1347 (dev->pixelline_ready[1] > dev->pixelline_written) &&
1348 (dev->pixelline_ready[2] > dev->pixelline_written) )
1350 source = dev->pixelbuffer + dev->pixelline_read * dev->width_in_pixels * 3;
1352 dev->pixelline_written++;
1353 dev->pixelline_read++;
1355 if (dev->pixelline_read >= dev->pixelline_max)
1357 dev->pixelline_read = 0;
1370 static SANE_Status umax_scsi_cmd(Umax_Device *dev, const void *src, size_t src_size, void *dst, size_t * dst_size)
1372 switch (dev->connection_type)
1375 return sanei_scsi_cmd(dev->sfd, src, src_size, dst, dst_size);
1380 return sanei_umaxusb_cmd(dev->sfd, src, src_size, dst, dst_size);
1391 static SANE_Status umax_scsi_open_extended(const char *devicename, Umax_Device *dev,
1394 switch (dev->connection_type)
1397 return sanei_scsi_open_extended(devicename, &dev->sfd, handler, handler_arg, buffersize);
1402 return sanei_umaxusb_open_extended(devicename, &dev->sfd, handler, handler_arg, buffersize);
1413 static SANE_Status umax_scsi_open(const char *devicename, Umax_Device *dev,
1416 switch (dev->connection_type)
1419 return sanei_scsi_open(devicename, &dev->sfd, handler, handler_arg);
1424 return sanei_umaxusb_open(devicename, &dev->sfd, handler, handler_arg);
1435 static void umax_scsi_close(Umax_Device *dev)
1437 switch (dev->connection_type)
1440 sanei_scsi_close(dev->sfd);
1441 dev->sfd=-1;
1446 sanei_umaxusb_close(dev->sfd);
1447 dev->sfd=-1;
1455 static SANE_Status umax_scsi_req_enter(Umax_Device *dev, const void *src, size_t src_size,
1458 switch (dev->connection_type)
1461 return sanei_scsi_req_enter (dev->sfd, src, src_size, dst, dst_size, idp);
1466 return sanei_umaxusb_req_enter (dev->sfd, src, src_size, dst, dst_size, idp);
1477 static SANE_Status umax_scsi_req_wait(Umax_Device *dev, void *id)
1479 switch (dev->connection_type)
1499 static SANE_Status umax_scsi_get_lamp_status(Umax_Device *dev, int *lamp_on)
1506 status = umax_scsi_cmd(dev, get_lamp_status.cmd, get_lamp_status.size, dev->buffer[0], &size);
1513 *lamp_on = get_lamp_status_lamp_on(dev->buffer[0]);
1523 static SANE_Status umax_scsi_set_lamp_status(Umax_Device *dev, int lamp_on)
1531 status = umax_scsi_cmd(dev, set_lamp_status.cmd, set_lamp_status.size, NULL, NULL);
1574 static SANE_Status umax_get_data_buffer_status(Umax_Device *dev)
1580 status = umax_scsi_cmd(dev, get_data_buffer_status.cmd, get_data_buffer_status.size, NULL, NULL);
1594 static void umax_do_request_sense(Umax_Device *dev)
1601 status = umax_scsi_cmd(dev, request_sense.cmd, request_sense.size, dev->buffer[0], &size);
1612 static SANE_Status umax_wait_scanner(Umax_Device *dev)
1627 status = umax_scsi_cmd(dev, test_unit_ready.cmd, test_unit_ready.size, NULL, NULL);
1646 #define WAIT_SCANNER { int status = umax_wait_scanner(dev); if (status) return status; }
1652 static int umax_grab_scanner(Umax_Device *dev)
1659 status = umax_scsi_cmd(dev, reserve_unit.cmd, reserve_unit.size, NULL, NULL);
1677 static int umax_reposition_scanner(Umax_Device *dev)
1682 pause = dev->pause_after_reposition + dev->pause_for_moving * (dev->upper_left_y + dev->scanlength) /
1683 ( (dev->inquiry_fb_length * dev->y_coordinate_base) );
1686 status = umax_scsi_cmd(dev, object_position.cmd, object_position.size, NULL, NULL);
1716 static int umax_give_scanner(Umax_Device *dev)
1721 status = umax_scsi_cmd(dev, release_unit.cmd, release_unit.size, NULL, NULL);
1731 if (!dev->batch_scan || dev->batch_end)
1733 umax_reposition_scanner(dev);
1747 static void umax_send_gamma_data(Umax_Device *dev, void *gamma_data, int color)
1756 if (dev->inquiry_gamma_dwload == 0)
1762 memcpy(dev->buffer[0], send.cmd, send.size); /* send */
1763 set_S_datatype_code(dev->buffer[0], S_datatype_gamma); /* gamma curve */
1765 dest = dev->buffer[0] + send.size;
1767 if (dev->inquiry_gamma_DCF == 0) /* gamma format type 0 */
1778 if ( (dev->colormode == RGB) && (dev->three_pass != 0) ) /* 3 pass color */
1780 set_DCF0_gamma_color(dest, 0, dev->three_pass_color); /* set color */
1786 set_S_xfer_length(dev->buffer[0], 1026); /* set length */
1787 status = umax_scsi_cmd(dev, dev->buffer[0], send.size + 1026, NULL, NULL);
1812 set_S_xfer_length(dev->buffer[0], 3076); /* set length */
1813 status = umax_scsi_cmd(dev, dev->buffer[0], send.size + 3076, NULL, NULL);
1820 else if (dev->inquiry_gamma_DCF == 1) /* gamma format type 1 */
1827 if ( (dev->colormode == RGB) && (dev->three_pass != 0) ) /* 3 pass color */
1829 set_DCF1_gamma_color(dest, dev->three_pass_color); /* set color */
1835 set_S_xfer_length(dev->buffer[0], 258); /* set length */
1836 status = umax_scsi_cmd(dev, dev->buffer[0], send.size + 258, NULL, NULL);
1842 else if (dev->inquiry_gamma_DCF == 2) /* gamma format type 2 */
1849 if ( (dev->colormode == RGB) && (dev->three_pass != 0) ) /* 3 pass color */
1850 { set_DCF2_gamma_color(dest, dev->three_pass_color); } /* set color */
1861 set_DCF2_gamma_input_bits(dest, dev->gamma_input_bits_code);
1862 set_DCF2_gamma_output_bits(dest, dev->bits_per_pixel_code);
1864 dest = dev->buffer[0] + send.size + gamma_DCF2.size; /* write to dest */
1866 if (dev->gamma_input_bits_code & 32)
1870 else if (dev->gamma_input_bits_code & 16)
1874 else if (dev->gamma_input_bits_code & 8)
1878 else if (dev->gamma_input_bits_code & 4)
1882 else if (dev->gamma_input_bits_code & 2)
1891 if (dev->bits_per_pixel_code != 1) /* more than 8 output bits per pixel */
1896 if (dev->bufsize >= color*length+gamma_DCF2.size)
1898 set_S_xfer_length(dev->buffer[0], color*length+gamma_DCF2.size); /* set length */
1901 status = umax_scsi_cmd(dev, dev->buffer[0], send.size+gamma_DCF2.size + length * color, NULL, NULL);
1909 DBG(DBG_error, "ERROR: too small scsi buffer (%d bytes) to send gamma data\n", dev->bufsize);
1922 static void umax_send_data(Umax_Device *dev, void *data, int size, int datatype)
1927 memcpy(dev->buffer[0], send.cmd, send.size); /* send */
1928 set_S_datatype_code(dev->buffer[0], datatype); /* set datatype */
1929 set_S_xfer_length(dev->buffer[0], size); /* bytes */
1931 dest=dev->buffer[0] + send.size;
1934 status = umax_scsi_cmd(dev, dev->buffer[0], send.size + size, NULL, NULL);
1946 static void umax_send_halftone_pattern(Umax_Device *dev, void *data, int size)
1949 umax_send_data(dev, data, size*size, S_datatype_halftone);
1957 static void umax_send_shading_data(Umax_Device *dev, void *data, int size)
1960 umax_send_data(dev, data, size, S_datatype_shading);
1967 static void umax_send_gain_data(Umax_Device *dev, void *data, int size)
1970 umax_send_data(dev, data, size, S_datatype_gain);
1977 static SANE_Status umax_queue_read_image_data_req(Umax_Device *dev, unsigned int length, int bufnr)
1986 dev->length_queued[bufnr] = length; /* set length request */
1987 dev->length_read[bufnr] = length; /* set length request, can be changed asynchronous by umax_scsi_req_enter */
1989 status = umax_scsi_req_enter(dev, sread.cmd, sread.size, dev->buffer[bufnr], &(dev->length_read[bufnr]), &(dev->queue_id[bufnr]));
1997 DBG(DBG_info2, "umax_queue_read_image_data_req: id for buffer[%d] is %p\n", bufnr, dev->queue_id[bufnr]);
2006 static int umax_wait_queued_image_data(Umax_Device *dev, int bufnr)
2010 DBG(DBG_proc, "umax_wait_queued_image_data for buffer[%d] (id=%p)\n", bufnr, dev->queue_id[bufnr]);
2012 status = umax_scsi_req_wait(dev, dev->queue_id[bufnr]);
2026 static int umax_read_data(Umax_Device *dev, size_t length, int datatype)
2033 status = umax_scsi_cmd(dev, sread.cmd, sread.size, dev->buffer[0], &length);
2047 static int umax_read_shading_data(Umax_Device *dev, unsigned int length)
2050 return umax_read_data(dev, length, R_datatype_shading);
2058 static int umax_read_gain_data(Umax_Device *dev, unsigned int length)
2061 return umax_read_data(dev, length, R_datatype_gain);
2070 static int umax_read_image_data(Umax_Device *dev, unsigned int length)
2074 return umax_read_data(dev, length, R_datatype_imagedata);
2096 static SANE_Status umax_set_window_param(Umax_Device *dev)
2104 set_WDB_length(dev->wdb_len); /* length of win descriptor block */
2108 set_WD_auto(buffer_r, dev->set_auto); /* 0 or 1: don't know what it is */
2111 set_WD_Xres(buffer_r, dev->x_resolution); /* x resolution in dpi */
2112 set_WD_Yres(buffer_r, dev->y_resolution); /* y resolution in dpi */
2113 set_WD_ULX(buffer_r, dev->upper_left_x); /* left_edge x */
2114 set_WD_ULY(buffer_r, dev->upper_left_y); /* upper_edge y */
2115 set_WD_width(buffer_r, dev->scanwidth); /* width */
2116 set_WD_length(buffer_r, dev->scanlength); /* length */
2119 set_WD_brightness(buffer_r, dev->brightness); /* brightness, only halftone */
2120 set_WD_threshold(buffer_r, dev->threshold); /* threshold, only lineart */
2121 set_WD_contrast(buffer_r, dev->contrast); /* contrast, only halftone */
2127 set_WD_halftone(buffer_r, dev->halftone); /* select halftone-pattern */
2128 set_WD_RIF(buffer_r, dev->reverse); /* reverse, invert black and white */
2129 set_WD_speed(buffer_r, dev->WD_speed); /* set speed */
2133 set_WD_highlight(buffer_r, umax_correct_light(dev->highlight_r, dev->analog_gamma_r));
2134 set_WD_shadow(buffer_r, umax_correct_light(dev->shadow_r, dev->analog_gamma_r));
2137 set_WD_gamma(buffer_r, dev->digital_gamma_r); /* set digital gamma */
2138 set_WD_module(buffer_r, dev->module); /* flatbed or transparency */
2139 set_WD_CBHS(buffer_r, dev->cbhs_range); /* 50 or 255 */
2140 set_WD_FF(buffer_r, dev->fix_focus_position); /* fix focus position */
2141 set_WD_RMIF(buffer_r, dev->reverse_multi); /* reverse color-values */
2142 set_WD_FDC(buffer_r, dev->lens_cal_in_doc_pos); /* lens calibration in document position */
2143 set_WD_PF(buffer_r, dev->disable_pre_focus); /* disable pre focus */
2144 set_WD_LCL(buffer_r, dev->holder_focus_pos_0mm); /* 0.6mm <-> 0.0mm holder focus position */
2145 set_WD_HBT(buffer_r, dev->low_byte_first); /* set byte order for 16 bit scanners */
2146 set_WD_DOR(buffer_r, dev->dor); /* double-resolution-mode */
2147 set_WD_scan_exposure_level(buffer_r, dev->exposure_time_scan_r); /* scan exposure time */
2148 set_WD_calibration_exposure_level(buffer_r, dev->exposure_time_calibration_r);/* calibration exposure time */
2150 set_WD_batch(buffer_r, dev->batch_scan); /* batch or normal scan */
2151 set_WD_MF(buffer_r, dev->manual_focus); /* automatic <-> manual focus */
2153 set_WD_warmup(buffer_r, dev->warmup); /* warmup */
2155 set_WD_calibration(buffer_r, dev->calibration); /* image calibration */
2159 set_WD_analog_gamma(buffer_r, dev->analog_gamma_r ); /* analog gamma */
2160 set_WD_lamp_c_density(buffer_r, dev->c_density); /* calibrat. lamp density */
2161 set_WD_lamp_s_density(buffer_r, dev->s_density); /* scan lamp density */
2162 set_WD_next_upper_left(buffer_r, dev->batch_next_tl_y); /* batch scan next top left y position */
2163 set_WD_pixel_count(buffer_r, dev->width_in_pixels); /* pixel count */
2164 set_WD_line_count(buffer_r, dev->length_in_pixels); /* line count */
2165 set_WD_x_coordinate_base(buffer_r, dev->x_coordinate_base); /* dpi (1200) */
2166 set_WD_y_coordinate_base(buffer_r, dev->y_coordinate_base); /* dpi (1200) */
2167 set_WD_calibration_data_lines(buffer_r, dev->calib_lines); /* required lines for calibration by driver */
2170 switch(dev->colormode)
2188 set_WD_bitsperpixel(buffer_r, dev->bits_per_pixel);
2196 if (dev->colormode == RGB_LINEART )
2201 else if (dev->colormode == RGB_HALFTONE )
2209 set_WD_bitsperpixel(buffer_r, dev->bits_per_pixel);
2212 if (dev->three_pass == 0)
2216 if (dev->do_color_ordering != 0)
2220 if (dev->CCD_distance == 0)
2241 set_WD_gamma(buffer_r, dev->digital_gamma_r); /* digital gamma */
2242 set_WD_gamma(buffer_g, dev->digital_gamma_g);
2243 set_WD_gamma(buffer_b, dev->digital_gamma_b);
2245 set_WD_analog_gamma(buffer_r, dev->analog_gamma_r); /* analog gamma */
2246 set_WD_analog_gamma(buffer_g, dev->analog_gamma_g);
2247 set_WD_analog_gamma(buffer_b, dev->analog_gamma_b);
2250 set_WD_highlight(buffer_r, umax_correct_light(dev->highlight_r, dev->analog_gamma_r));
2251 set_WD_highlight(buffer_g, umax_correct_light(dev->highlight_g, dev->analog_gamma_g));
2252 set_WD_highlight(buffer_b, umax_correct_light(dev->highlight_b, dev->analog_gamma_b));
2255 set_WD_shadow(buffer_r, umax_correct_light(dev->shadow_r, dev->analog_gamma_r));
2256 set_WD_shadow(buffer_g, umax_correct_light(dev->shadow_g, dev->analog_gamma_g));
2257 set_WD_shadow(buffer_b, umax_correct_light(dev->shadow_b, dev->analog_gamma_b));
2259 set_WD_scan_exposure_level(buffer_r, dev->exposure_time_scan_r); /* set scan exposure times */
2260 set_WD_scan_exposure_level(buffer_g, dev->exposure_time_scan_g);
2261 set_WD_scan_exposure_level(buffer_b, dev->exposure_time_scan_b);
2263 set_WD_calibration_exposure_level(buffer_r, dev->exposure_time_calibration_r);/* set calib exp times */
2264 set_WD_calibration_exposure_level(buffer_g, dev->exposure_time_calibration_g);
2265 set_WD_calibration_exposure_level(buffer_b, dev->exposure_time_calibration_b);
2272 if (dev->colormode == RGB_LINEART )
2276 else if (dev->colormode == RGB_HALFTONE )
2285 switch (dev->three_pass_color)
2289 set_WD_gamma(buffer_r, dev->digital_gamma_r);
2290 set_WD_analog_gamma(buffer_r, dev->analog_gamma_r);
2291 set_WD_highlight(buffer_r, umax_correct_light(dev->highlight_r, dev->analog_gamma_r));
2292 set_WD_shadow(buffer_r, umax_correct_light(dev->shadow_r, dev->analog_gamma_r));
2293 set_WD_scan_exposure_level(buffer_r, dev->exposure_time_scan_r);
2294 set_WD_calibration_exposure_level(buffer_r, dev->exposure_time_calibration_r);
2299 set_WD_gamma(buffer_r, dev->digital_gamma_g);
2300 set_WD_analog_gamma(buffer_r, dev->analog_gamma_g);
2301 set_WD_highlight(buffer_r, umax_correct_light(dev->highlight_g, dev->analog_gamma_g));
2302 set_WD_shadow(buffer_r, umax_correct_light(dev->shadow_g, dev->analog_gamma_g));
2303 set_WD_scan_exposure_level(buffer_r, dev->exposure_time_scan_g);
2304 set_WD_calibration_exposure_level(buffer_r, dev->exposure_time_calibration_g);
2309 set_WD_gamma(buffer_r, dev->digital_gamma_b);
2310 set_WD_analog_gamma(buffer_r, dev->analog_gamma_b);
2311 set_WD_highlight(buffer_r, umax_correct_light(dev->highlight_b, dev->analog_gamma_b));
2312 set_WD_shadow(buffer_r, umax_correct_light(dev->shadow_b, dev->analog_gamma_b));
2313 set_WD_scan_exposure_level(buffer_r, dev->exposure_time_scan_b);
2314 set_WD_calibration_exposure_level(buffer_r, dev->exposure_time_calibration_b);
2317 } /* switch dev->three_pass_color */
2321 } /* switch dev->colormode, case RGB */
2324 memcpy(dev->buffer[0], set_window.cmd, set_window.size); /* SET-WINDOW cmd */
2325 memcpy(WPDB_OFF(dev->buffer[0]), window_parameter_data_block.cmd, window_parameter_data_block.size); /* WPDB */
2326 set_WPDB_wdbnum(WPDB_OFF(dev->buffer[0]), num_dblocks); /* set WD_len */
2327 memcpy(WDB_OFF(dev->buffer[0],1), buffer_r, window_descriptor_block.size); /* add WD_block */
2331 memcpy(WDB_OFF(dev->buffer[0],2), buffer_g, window_descriptor_block.size); /* add green */
2332 memcpy(WDB_OFF(dev->buffer[0],3), buffer_b, window_descriptor_block.size); /* add blue */
2336 DBG(DBG_info2, "window descriptor block created with %d bytes\n", dev->wdb_len);
2338 set_SW_xferlen(dev->buffer[0], (window_parameter_data_block.size + (window_descriptor_block.size * num_dblocks)));
2340 status = umax_scsi_cmd(dev, dev->buffer[0], set_window.size + window_parameter_data_block.size +
2358 static void umax_do_inquiry(Umax_Device *dev)
2364 memset(dev->buffer[0], '\0', 256); /* clear buffer */
2369 status = umax_scsi_cmd(dev, inquiry.cmd, inquiry.size, dev->buffer[0], &size);
2375 size = get_inquiry_additional_length(dev->buffer[0]) + 5;
2378 status = umax_scsi_cmd(dev, inquiry.cmd, inquiry.size, dev->buffer[0], &size);
2389 static SANE_Status umax_start_scan(Umax_Device *dev)
2396 if (dev->adf) /* ADF selected: test for ADF errors */
2398 umax_do_inquiry(dev); /* get inquiry */
2400 if (get_inquiry_ADF_paper_jam(dev->buffer[0])) /* test for ADF paper jam */
2405 else if (get_inquiry_ADF_cover_open(dev->buffer[0])) /* test for ADF cover open */
2410 else if (get_inquiry_ADF_no_paper(dev->buffer[0])) /* test for ADF no paper */
2417 set_SC_quality(scan.cmd, dev->quality); /* 1=qual, 0=fast */
2418 set_SC_adf( scan.cmd, dev->adf); /* ADF, 0=off, 1=use */
2419 set_SC_preview(scan.cmd, dev->preview); /* 1=preview */
2427 status = umax_scsi_cmd(dev, scan.cmd, scan.size + size, NULL, NULL);
2440 static SANE_Status umax_do_calibration(Umax_Device *dev)
2449 status = umax_wait_scanner(dev);
2451 if ((status == SANE_STATUS_GOOD) && (dev->do_calibration != 0)) /* calibration by driver */
2464 memset(dev->buffer[0], 0, rs_return_block_size); /* clear sense data buffer */
2465 umax_do_request_sense(dev); /* new request-sense call to get all data */
2472 if (get_RS_SCC_condition_code(dev->buffer[0]) != 1)
2477 if ((dev->calibration_area != UMAX_CALIBRATION_AREA_CCD) && (!dev->batch_scan))
2482 width = dev->scanwidth * dev->relevant_optical_res / dev->x_coordinate_base;
2484 if (dev->calibration_width_offset > -99999) /* driver or user (umax.conf) define an offset */
2486 width = width + dev->calibration_width_offset;
2487 DBG(DBG_warning," Using calibration width offset of %d\n", dev->calibration_width_offset);
2490 if (dev->colormode == RGB)
2495 lines = dev->calib_lines;
2497 if (dev->gamma_input_bits_code <= 1)
2510 width = (int)(dev->inquiry_fb_width * dev->inquiry_optical_res);
2512 if (dev->batch_scan)
2514 if (dev->calibration_width_offset_batch > -99999) /* driver or user (umax.conf) define an offset for batch scanning */
2516 width = width + dev->calibration_width_offset_batch;
2517 DBG(DBG_warning," Using calibration width offset for batch scanning of %d\n", dev->calibration_width_offset_batch);
2522 if (dev->calibration_width_offset > -99999) /* driver or user (umax.conf) define an offset */
2524 width = width + dev->calibration_width_offset;
2525 DBG(DBG_warning," Using calibration width offset of %d\n", dev->calibration_width_offset);
2529 if (dev->colormode == RGB)
2534 lines = dev->calib_lines;
2536 if (dev->gamma_input_bits_code <= 1)
2548 lines = get_RS_SCC_calibration_lines(dev->buffer[0]);
2549 bytespp = get_RS_SCC_calibration_bytespp(dev->buffer[0]);
2550 width = get_RS_SCC_calibration_bytesperline(dev->buffer[0]) / bytespp;
2553 if (dev->calibration_bytespp > 0) /* correct bytespp if necessary and driver knows about it or user did select it */
2555 bytespp = dev->calibration_bytespp;
2560 if (width * bytespp > dev->bufsize)
2591 umax_read_shading_data(dev, width * bytespp);
2595 average[j] += (long) dev->buffer[0][j];
2606 else if (dev->low_byte_first) /* 2 bytes per pixel with low byte first */
2611 umax_read_shading_data(dev, width * bytespp);
2615 average[j] += (long) 256 * dev->buffer[0][2*j+1] + dev->buffer[0][2*j] ;
2632 umax_read_shading_data(dev, width * bytespp);
2636 average[j] += (long) 256 * dev->buffer[0][2*j] + dev->buffer[0][2*j + 1] ;
2651 if ( (dev->invert_shading_data) ) /* invert data */
2678 umax_send_shading_data(dev, shading_data, width * bytespp);
2682 status = umax_start_scan(dev); /* now start real scan */
2684 dev->do_calibration = 0;
2694 static void umax_do_new_inquiry(Umax_Device *dev, size_t size) /* call inquiry again if wrong length */
2699 memset(dev->buffer[0], '\0', 256); /* clear buffer */
2702 status = umax_scsi_cmd(dev, inquiry.cmd, inquiry.size, dev->buffer[0], &size);
2713 static void umax_correct_inquiry(Umax_Device *dev, char *vendor, char *product, char *version)
2721 int add_len = get_inquiry_additional_length(dev->buffer[0]);
2728 umax_do_new_inquiry(dev, 0x9b); /* get inquiry with correct length */
2729 set_inquiry_length(dev->buffer[0], 0x9e); /* correct inquiry len */
2731 set_inquiry_color_order(dev->buffer[0], IN_color_ordering_line_w_ccd);
2732 set_inquiry_fb_uta_line_arrangement_mode(dev->buffer[0], 32);
2733 set_inquiry_CCD_line_distance(dev->buffer[0], 8);
2736 if (dev->invert_shading_data == -1) /* nothing defined in umax.conf */
2739 dev->invert_shading_data = 1;
2745 int add_len = get_inquiry_additional_length(dev->buffer[0]);
2752 umax_do_new_inquiry(dev, 0x9b); /* get inquiry with correct length */
2753 set_inquiry_length(dev->buffer[0], 0x9e); /* correct inquiry len */
2755 set_inquiry_color_order(dev->buffer[0], IN_color_ordering_line_w_ccd);
2756 set_inquiry_fb_uta_line_arrangement_mode(dev->buffer[0], 33);
2757 set_inquiry_CCD_line_distance(dev->buffer[0], 8);
2759 if (dev->invert_shading_data == -1) /* nothing defined in umax.conf */
2762 dev->invert_shading_data = 1;
2775 if (dev->gamma_lsb_padded == -1) /* nothing defined in umax.conf and not by backend */
2778 dev->gamma_lsb_padded = 1;
2784 dev->lamp_control_available = 1;
2791 dev->lamp_control_available = 1;
2793 if (dev->calibration_bytespp == -1) /* no calibration-bytespp defined in umax.conf */
2796 dev->calibration_bytespp = 1; /* scanner says 2 bytespp for calibration but 1 bytepp is correct */
2803 dev->lamp_control_available = 1;
2805 if (dev->calibration_area == -1) /* no calibration area defined in umax.conf */
2808 dev->calibration_area = UMAX_CALIBRATION_AREA_CCD;
2811 if (dev->calibration_bytespp == -1) /* no calibration-bytespp defined in umax.conf */
2814 dev->calibration_bytespp = 2;
2818 dev->common_xy_resolutions = 1;
2820 if (dev->connection_type == SANE_UMAX_USB)
2823 set_inquiry_fw_quality(dev->buffer[0], 0);
2830 dev->pause_for_color_calibration = 7000; /* pause between start_scan and do_calibration in ms */
2831 dev->pause_for_gray_calibration = 4000; /* pause between start_scan and do_calibration in ms */
2832 dev->pause_after_calibration = 0000; /* pause between do_calibration and read data in ms */
2833 dev->pause_after_reposition = 3000; /* pause after repostion scanner in ms */
2834 dev->pause_for_moving = 3000; /* pause for moving scanhead over full area */
2837 set_inquiry_sc_adf(dev->buffer[0], 1); /* set second bit that indicates ADF is supported */
2843 if (dev->slow == -1) /* option is not predefined in umax.conf */
2846 dev->slow = 1;
2853 dev->pause_after_reposition = 0; /* call wait_scanner */
2859 dev->pause_after_reposition = 0; /* call wait_scanner */
2865 dev->inquiry_gamma_DCF = 1; /* define gamma download curve format */
2867 dev->pause_after_reposition = 0; /* call wait_scanner */
2873 dev->inquiry_gamma_DCF = 1; /* define gamma download curve format */
2879 dev->inquiry_gamma_DCF = 0; /* define gamma download curve format */
2885 dev->inquiry_gamma_DCF = 0; /* define gamma download curve format */
2894 set_inquiry_max_calibration_data_lines(dev->buffer[0], 66);
2896 if (dev->calibration_width_offset == -99999) /* no calibration-width-offset defined in umax.conf */
2898 dev->calibration_width_offset = -1;
2899 DBG(DBG_warning," - adding calibration width offset of %d pixels\n", dev->calibration_width_offset);
2902 if (dev->calibration_area == -1) /* no calibration area defined in umax.conf */
2905 dev->calibration_area = UMAX_CALIBRATION_AREA_CCD;
2911 if (dev->calibration_area == -1) /* no calibration area defined in umax.conf */
2914 dev->calibration_area = UMAX_CALIBRATION_AREA_CCD;
2917 if (dev->calibration_width_offset == -99999) /* no calibration-width-offset defined in umax.conf */
2919 dev->calibration_width_offset = 308;
2920 DBG(DBG_warning," - adding calibration width offset of %d pixels\n", dev->calibration_width_offset);
2927 if (dev->calibration_width_offset == -99999) /* no calibration-width-offset defined in umax.conf */
2929 dev->calibration_width_offset = 28;
2930 DBG(DBG_warning," - adding calibration width offset of %d pixels\n", dev->calibration_width_offset);
2934 if (dev->calibration_width_offset_batch == -99999) /* no calibration-width-offset for batch scanning defined in umax.conf */
2936 dev->calibration_width_offset_batch = 828;
2937 DBG(DBG_warning," - adding calibration width offset for batch scanning of %d pixels\n", dev->calibration_width_offset_batch);
2944 if (dev->calibration_width_offset == -99999) /* no calibration-width-offset defined in umax.conf */
2946 dev->calibration_width_offset = 22;
2947 DBG(DBG_warning," - adding calibration width offset of %d pixels\n", dev->calibration_width_offset);
2951 if (dev->calibration_width_offset_batch == -99999) /* no calibration-width-offset for batch scanning defined in umax.conf */
2953 dev->calibration_width_offset_batch = 24;
2954 DBG(DBG_warning," - adding calibration width offset for batch scanning of %d pixels\n", dev->calibration_width_offset_batch);
2961 if (dev->calibration_width_offset == -99999) /* no calibration-width-offset defined in umax.conf */
2963 dev->calibration_width_offset = 52;
2964 DBG(DBG_warning," - adding calibration width offset of %d pixels\n", dev->calibration_width_offset);
2968 if (dev->calibration_width_offset_batch == -99999) /* no calibration-width-offset for batch scanning defined in umax.conf */
2970 dev->calibration_width_offset_batch = 1052;
2971 DBG(DBG_warning," - adding calibration width offset for batch scanning of %d pixels\n", dev->calibration_width_offset_batch);
2974 dev->force_quality_calibration = 1;
2983 if (dev->calibration_width_offset == -99999) /* no calibration-width-offset defined in umax.conf */
2985 dev->calibration_width_offset = 52;
2986 DBG(DBG_warning," - adding calibration width offset of %d pixels\n", dev->calibration_width_offset);
2990 if (dev->calibration_width_offset_batch == -99999) /* no calibration-width-offset for batch scanning defined in umax.conf */
2993 dev->calibration_width_offset_batch = 1052;
2994 DBG(DBG_warning," - adding calibration width offset for batch scanning of %d pixels\n", dev->calibration_width_offset_batch);
3009 set_inquiry_max_calibration_data_lines(dev->buffer[0], 66);
3011 if (dev->calibration_width_offset == -99999) /* no calibration-width-offset defined in umax.conf */
3013 dev->calibration_width_offset = -1;
3014 DBG(DBG_warning," - adding calibration width offset of %d pixels\n", dev->calibration_width_offset);
3017 if (dev->calibration_area == -1) /* no calibration area defined in umax.conf */
3020 dev->calibration_area = UMAX_CALIBRATION_AREA_CCD;
3027 if (dev->gamma_lsb_padded == -1) /* nothing defined in umax.conf and not by backend */
3030 dev->gamma_lsb_padded = 1;
3040 if (dev->calibration_width_offset == -99999) /* no calibration-width-offset defined in umax.conf */
3042 dev->calibration_width_offset = 28;
3043 DBG(DBG_warning," - adding calibration width offset of %d pixels\n", dev->calibration_width_offset);
3047 if (dev->calibration_width_offset_batch == -99999) /* no calibration-width-offset for batch scanning defined in umax.conf */
3049 dev->calibration_width_offset_batch = 828;
3050 DBG(DBG_warning," - adding calibration width offset for batch scanning of %d pixels\n", dev->calibration_width_offset_batch);
3060 if (dev->calibration_width_offset == -99999) /* no calibration-width-offset defined in umax.conf */
3062 dev->calibration_width_offset = 28;
3063 DBG(DBG_warning," - adding calibration width offset of %d pixels\n", dev->calibration_width_offset);
3067 if (dev->calibration_width_offset_batch == -99999) /* no calibration-width-offset for batch scanning defined in umax.conf */
3069 dev->calibration_width_offset_batch = 828;
3070 DBG(DBG_warning," - adding calibration width offset for batch scanning of %d pixels\n", dev->calibration_width_offset_batch);
3078 int add_len = get_inquiry_additional_length(dev->buffer[0]);
3085 umax_do_new_inquiry(dev, 0x9b); /* get inquiry with correct length */
3086 set_inquiry_length(dev->buffer[0], 0x9e); /* correct inquiry len */
3088 set_inquiry_color_order(dev->buffer[0], IN_color_ordering_line_w_ccd);
3089 set_inquiry_fb_uta_line_arrangement_mode(dev->buffer[0], 32);
3090 set_inquiry_CCD_line_distance(dev->buffer[0], 8);
3093 if (dev->invert_shading_data == -1) /* nothing defined in umax.conf */
3096 dev->invert_shading_data = 1;
3108 set_inquiry_max_calibration_data_lines(dev->buffer[0], 66);
3110 if (dev->calibration_width_offset == -99999) /* no calibration-width-offset defined in umax.conf */
3112 dev->calibration_width_offset = -1;
3113 DBG(DBG_warning," - adding calibration width offset of %d pixels\n", dev->calibration_width_offset);
3116 if (dev->calibration_area == -1) /* no calibration area defined in umax.conf */
3119 dev->calibration_area = UMAX_CALIBRATION_AREA_CCD;
3129 static int umax_identify_scanner(Umax_Device *dev)
3137 umax_do_inquiry(dev); /* get inquiry */
3138 if (get_inquiry_periph_devtype(dev->buffer[0]) != IN_periph_devtype_scanner) { return 1; } /* no scanner */
3140 get_inquiry_vendor( (char *)dev->buffer[0], vendor); vendor[8] = ' '; vendor[9] = '\0';
3141 get_inquiry_product((char *)dev->buffer[0], product); product[16] = ' '; product[17] = '\0';
3142 get_inquiry_version((char *)dev->buffer[0], version); version[4] = ' '; version[5] = '\0';
3162 DBG(DBG_info, "Found %s scanner %sversion %s on device %s\n", vendor, product, version, dev->devicename);
3167 if (get_inquiry_additional_length(dev->buffer[0])>=0x8f)
3176 umax_correct_inquiry(dev, vendor, product, version);
3190 vendor, product, version, dev->devicename);
3213 DBG(DBG_warning, "inquiry-block-length: %d\n", get_inquiry_additional_length(dev->buffer[0])+5);
3217 memcpy(dev->buffer[0]+0x24, inq_data.inquiry, inq_data.inquiry_len-0x24);
3220 set_inquiry_sc_uta(dev->buffer[0], get_inquiry_transavail(dev->buffer[0])); /* transparency available ? */
3221 set_inquiry_sc_adf(dev->buffer[0], get_inquiry_scanmode(dev->buffer[0])); /* automatic document feeder available ? */
3223 set_inquiry_length(dev->buffer[0], inq_data.inquiry_len);
3224 umax_correct_inquiry(dev, vendor, product, version);
3237 vendor, product, version, dev->devicename);
3247 static void umax_trim_rowbufsize(Umax_Device *dev)
3251 if (dev->row_bufsize > dev->row_len)
3253 lines = dev->row_bufsize / dev->row_len;
3255 if (lines > dev->lines_max) /* reduce number of lines to scan if set up in config file */
3257 lines = dev->lines_max;
3260 dev->row_bufsize = lines * dev->row_len;
3263 DBG(DBG_proc,"trim_rowbufsize: row_bufsize = %d bytes = %d lines\n", dev->row_bufsize, lines);
3270 static void umax_calculate_exposure_time(Umax_Device *dev, int def, int *value)
3280 level = (*value) / dev->inquiry_exposure_time_step_unit;
3281 (*value) = inrange(dev->use_exposure_time_min, level, dev->inquiry_exposure_time_max);
3290 static int umax_check_values(Umax_Device *dev)
3303 dev->module = WD_module_flatbed; /* reset scanmode to flatbed first */
3307 if (dev->uta != 0)
3309 dev->module = WD_module_transparency;
3310 if ( (dev->inquiry_uta == 0) || (dev->inquiry_transavail == 0) )
3319 if (dev->adf != 0)
3321 if (dev->inquiry_adf == 0)
3330 if (dev->dor != 0)
3332 if (dev->inquiry_dor == 0)
3341 if (dev->dor == 0) /* standard (FB) */
3343 dev->relevant_optical_res = dev->inquiry_optical_res;
3344 dev->relevant_max_x_res = dev->inquiry_x_res;
3345 dev->relevant_max_y_res = dev->inquiry_y_res;
3349 dev->relevant_optical_res = dev->inquiry_dor_optical_res;
3350 dev->relevant_max_x_res = dev->inquiry_dor_x_res;
3351 dev->relevant_max_y_res = dev->inquiry_dor_y_res;
3354 if (dev->x_resolution <= 0)
3360 if (dev->x_resolution > dev->relevant_max_x_res)
3362 dev->x_resolution = dev->relevant_max_x_res;
3365 if (dev->x_resolution > dev->relevant_optical_res)
3367 dev->scale_x = 2;
3371 dev->scale_x = 1;
3374 if (dev->y_resolution <= 0)
3380 if (dev->y_resolution > dev->relevant_max_y_res)
3382 dev->y_resolution = dev->relevant_max_y_res;
3385 if (dev->y_resolution > dev->relevant_optical_res)
3387 dev->scale_y = 2;
3389 else if (dev->y_resolution > dev->relevant_optical_res/2)
3391 dev->scale_y = 1;
3396 dev->scale_y = 0.5;
3402 if (dev->module == WD_module_flatbed) /* flatbed mode */
3406 inquiry_width = dev->inquiry_fb_width; /* flatbed width */
3407 inquiry_length = dev->inquiry_fb_length;
3411 inquiry_x_orig = dev->inquiry_uta_x_off; /* uta origin */
3412 inquiry_y_orig = dev->inquiry_uta_y_off;
3413 inquiry_width = dev->inquiry_uta_x_off + dev->inquiry_uta_width; /* uta width */
3414 inquiry_length = dev->inquiry_uta_y_off + dev->inquiry_uta_length;
3417 if (dev->dor != 0)
3419 inquiry_x_orig = dev->inquiry_dor_x_off; /* dor origin */
3420 inquiry_y_orig = dev->inquiry_dor_y_off;
3421 inquiry_width = dev->inquiry_dor_x_off + dev->inquiry_dor_width; /* dor width */
3422 inquiry_length = dev->inquiry_dor_y_off + dev->inquiry_dor_length;
3430 maxwidth = inquiry_width * dev->x_coordinate_base - dev->upper_left_x - 1;
3432 if ( (dev->scanwidth <= 0) || (dev->scanwidth > maxwidth) )
3434 dev->scanwidth = maxwidth;
3437 if (dev->upper_left_x < inquiry_x_orig)
3439 dev->upper_left_x = inquiry_x_orig;
3443 maxlength = inquiry_length * dev->y_coordinate_base - dev->upper_left_y - 1;
3445 if ( (dev->scanlength <= 0) || (dev->scanlength > maxlength) )
3447 dev->scanlength = maxlength;
3450 if (dev->upper_left_y < inquiry_y_orig)
3452 dev->upper_left_y = inquiry_y_orig;
3457 dev->width_in_pixels = umax_calculate_pixels(dev->scanwidth, dev->x_resolution,
3458 dev->relevant_optical_res * dev->scale_x, dev->x_coordinate_base);
3460 dev->length_in_pixels = umax_calculate_pixels(dev->scanlength, dev->y_resolution,
3461 dev->relevant_optical_res * dev->scale_y, dev->y_coordinate_base);
3463 if ((dev->scanwidth <= 0) || (dev->scanlength <= 0))
3469 if (dev->bits_per_pixel_code == 1)
3471 dev->bytes_per_color = 1;
3475 dev->bytes_per_color = 2;
3478 switch(dev->colormode)
3481 dev->width_in_pixels -= dev->width_in_pixels % 8;
3482 dev->row_len = (dev->width_in_pixels / 8);
3486 dev->width_in_pixels -= dev->width_in_pixels % 8;
3487 dev->row_len = (dev->width_in_pixels / 8);
3491 dev->row_len = dev->width_in_pixels * dev->bytes_per_color;
3496 if (dev->three_pass)
3498 dev->row_len = dev->width_in_pixels / 8 ;
3502 dev->row_len = (dev->width_in_pixels / 8 ) * 3;
3507 if (dev->three_pass) /* three (24bpp) or six (30bpp) bytes per pixel */
3509 dev->row_len = dev->width_in_pixels * dev->bytes_per_color;
3513 dev->row_len = dev->width_in_pixels * 3 * dev->bytes_per_color;
3521 if (dev->wdb_len <= 0)
3523 dev->wdb_len = dev->inquiry_wdb_len;
3524 if (dev->wdb_len <= 0)
3531 if (dev->wdb_len > used_WDB_size)
3534 dev->wdb_len = used_WDB_size;
3539 dev->threshold = umax_cbhs_correct(dev->inquiry_threshold_min, dev->threshold , dev->inquiry_threshold_max);
3540 dev->contrast = umax_cbhs_correct(dev->inquiry_contrast_min, dev->contrast , dev->inquiry_contrast_max);
3541 dev->brightness = umax_cbhs_correct(dev->inquiry_brightness_min, dev->brightness, dev->inquiry_brightness_max);
3543 dev->highlight_r = umax_cbhs_correct(dev->inquiry_highlight_min, dev->highlight_r, dev->inquiry_highlight_max);
3544 dev->highlight_g = umax_cbhs_correct(dev->inquiry_highlight_min, dev->highlight_g, dev->inquiry_highlight_max);
3545 dev->highlight_b = umax_cbhs_correct(dev->inquiry_highlight_min, dev->highlight_b, dev->inquiry_highlight_max);
3547 dev->shadow_r = umax_cbhs_correct(dev->inquiry_shadow_min, dev->shadow_r, dev->inquiry_shadow_max-1);
3548 dev->shadow_g = umax_cbhs_correct(dev->inquiry_shadow_min, dev->shadow_g, dev->inquiry_shadow_max-1);
3549 dev->shadow_b = umax_cbhs_correct(dev->inquiry_shadow_min, dev->shadow_b, dev->inquiry_shadow_max-1);
3551 if (dev->shadow_r >= dev->highlight_r)
3553 dev->shadow_r = dev->highlight_r-1;
3555 if (dev->shadow_g >= dev->highlight_g)
3557 dev->shadow_g = dev->highlight_g-1;
3559 if (dev->shadow_b >= dev->highlight_b)
3561 dev->shadow_b = dev->highlight_b-1;
3566 if (dev->inquiry_preview == 0)
3568 if (dev->preview)
3571 dev->preview = 0;
3577 dev->calib_lines = dev->inquiry_max_calib_lines;
3579 if (dev->force_quality_calibration)
3581 dev->quality = 1; /* always use quality calibration */
3583 else if (dev->inquiry_quality_ctrl == 0)
3585 if (dev->quality)
3588 dev->quality = 0;
3593 if (dev->preview != 0)
3596 dev->quality = 0; /* do not use quality calibration in preview mode */
3602 if (dev->inquiry_lamp_ctrl == 0)
3604 if (dev->c_density || dev->s_density)
3608 dev->c_density = dev->s_density = 0;
3614 if (dev->reverse != 0)
3616 if ( (dev->colormode == LINEART) || (dev->colormode == HALFTONE) ||
3617 (dev->colormode == RGB_LINEART) || (dev->colormode == RGB_HALFTONE) )
3619 if (dev->inquiry_reverse == 0)
3626 { dev->reverse = 0; }
3629 if (dev->reverse_multi != 0)
3631 if ((dev->colormode == RGB) || (dev->colormode == GRAYSCALE) )
3633 if (dev->inquiry_reverse_multi == 0)
3641 dev->reverse_multi = 0;
3647 if (dev->inquiry_analog_gamma == 0)
3649 if (dev->analog_gamma_r + dev->analog_gamma_g + dev->analog_gamma_b != 0)
3653 dev->analog_gamma_r = dev->analog_gamma_g = dev->analog_gamma_b = 0;
3658 if ( (dev->digital_gamma_r == 0) || (dev->digital_gamma_g == 0) ||
3659 (dev->digital_gamma_b == 0) )
3661 if (dev->inquiry_gamma_dwload == 0)
3664 dev->digital_gamma_r = dev->digital_gamma_g = dev->digital_gamma_b = 15;
3670 if (dev->slow == 1)
3672 dev->WD_speed = WD_speed_slow;
3676 dev->WD_speed = WD_speed_fast;
3679 if (dev->smear == 1)
3681 dev->WD_speed += WD_speed_smear;
3686 if ( ( (dev->inquiry_GIB | 1) & dev->gamma_input_bits_code) == 0 )
3689 dev->gamma_input_bits_code = 1;
3690 dev->digital_gamma_r = dev->digital_gamma_g = dev->digital_gamma_b = 15;
3693 if ( ( (dev->inquiry_GOB | 1) & dev->bits_per_pixel_code) == 0 )
3701 switch(dev->colormode)
3705 dev->use_exposure_time_min = dev->inquiry_exposure_time_l_min;
3707 if (dev->module == WD_module_flatbed)
3709 dev->use_exposure_time_def_r = dev->inquiry_exposure_time_l_fb_def;
3713 dev->use_exposure_time_def_r = dev->inquiry_exposure_time_l_uta_def;
3716 if (dev->inquiry_lineart == 0)
3725 dev->use_exposure_time_min = dev->inquiry_exposure_time_h_min;
3726 if (dev->module == WD_module_flatbed)
3728 dev->use_exposure_time_def_r = dev->inquiry_exposure_time_h_fb_def;
3732 dev->use_exposure_time_def_r = dev->inquiry_exposure_time_h_uta_def;
3735 if (dev->inquiry_halftone == 0)
3743 dev->use_exposure_time_min = dev->inquiry_exposure_time_g_min;
3745 if (dev->module == WD_module_flatbed)
3747 dev->use_exposure_time_def_r = dev->inquiry_exposure_time_g_fb_def;
3751 dev->use_exposure_time_def_r = dev->inquiry_exposure_time_g_uta_def;
3754 if (dev->inquiry_gray == 0)
3762 dev->use_exposure_time_min = dev->inquiry_exposure_time_c_min;
3763 if (dev->module == WD_module_flatbed)
3765 dev->use_exposure_time_def_r = dev->inquiry_exposure_time_c_fb_def_r;
3766 dev->use_exposure_time_def_g = dev->inquiry_exposure_time_c_fb_def_g;
3767 dev->use_exposure_time_def_b = dev->inquiry_exposure_time_c_fb_def_b;
3771 dev->use_exposure_time_def_r = dev->inquiry_exposure_time_c_uta_def_r;
3772 dev->use_exposure_time_def_g = dev->inquiry_exposure_time_c_uta_def_g;
3773 dev->use_exposure_time_def_b = dev->inquiry_exposure_time_c_uta_def_b;
3776 if (dev->inquiry_color == 0)
3782 if (dev->inquiry_one_pass_color)
3786 if (dev->inquiry_color_order & IN_color_ordering_pixel)
3790 else if (dev->inquiry_color_order & IN_color_ordering_line_no_ccd)
3792 dev->CCD_distance = 0;
3793 dev->do_color_ordering = 1;
3796 else if (dev->inquiry_color_order & IN_color_ordering_line_w_ccd)
3798 dev->CCD_distance = dev->inquiry_CCD_line_distance;
3799 dev->do_color_ordering = 1;
3800 switch (dev->inquiry_fb_uta_color_arrangement) /* define color order for line ordering */
3803 dev->CCD_color[0] = CCD_color_green;
3805 dev->CCD_color[1] = CCD_color_blue;
3806 dev->CCD_color[2] = CCD_color_green;
3808 dev->CCD_color[3] = CCD_color_blue;
3809 dev->CCD_color[4] = CCD_color_red;
3810 dev->CCD_color[5] = CCD_color_green;
3812 dev->CCD_color[6] = CCD_color_blue;
3813 dev->CCD_color[7] = CCD_color_red;
3815 dev->CCD_color[8] = CCD_color_red;
3819 dev->CCD_color[0] = CCD_color_blue;
3821 dev->CCD_color[1] = CCD_color_green;
3822 dev->CCD_color[2] = CCD_color_blue;
3824 dev->CCD_color[3] = CCD_color_green;
3825 dev->CCD_color[4] = CCD_color_red;
3826 dev->CCD_color[5] = CCD_color_blue;
3828 dev->CCD_color[6] = CCD_color_green;
3829 dev->CCD_color[7] = CCD_color_red;
3831 dev->CCD_color[8] = CCD_color_red;
3835 dev->CCD_color[0] = CCD_color_red;
3837 dev->CCD_color[1] = CCD_color_blue;
3838 dev->CCD_color[2] = CCD_color_red;
3840 dev->CCD_color[3] = CCD_color_blue;
3841 dev->CCD_color[4] = CCD_color_green;
3842 dev->CCD_color[5] = CCD_color_red;
3844 dev->CCD_color[6] = CCD_color_blue;
3845 dev->CCD_color[7] = CCD_color_green;
3847 dev->CCD_color[8] = CCD_color_green;
3851 dev->CCD_color[0] = CCD_color_red;
3853 dev->CCD_color[1] = CCD_color_green;
3854 dev->CCD_color[2] = CCD_color_red;
3856 dev->CCD_color[3] = CCD_color_green;
3857 dev->CCD_color[4] = CCD_color_red;
3858 dev->CCD_color[5] = CCD_color_blue;
3860 dev->CCD_color[6] = CCD_color_green;
3861 dev->CCD_color[7] = CCD_color_blue;
3863 dev->CCD_color[8] = CCD_color_blue;
3867 dev->CCD_color[0] = CCD_color_green;
3869 dev->CCD_color[1] = CCD_color_green;
3870 dev->CCD_color[2] = CCD_color_blue;
3872 dev->CCD_color[3] = CCD_color_green;
3873 dev->CCD_color[4] = CCD_color_red;
3874 dev->CCD_color[5] = CCD_color_blue;
3876 dev->CCD_color[6] = CCD_color_red;
3877 dev->CCD_color[7] = CCD_color_blue;
3879 dev->CCD_color[8] = CCD_color_red;
3883 dev->CCD_color[0] = CCD_color_red;
3885 dev->CCD_color[1] = CCD_color_red;
3886 dev->CCD_color[2] = CCD_color_blue;
3888 dev->CCD_color[3] = CCD_color_red;
3889 dev->CCD_color[4] = CCD_color_green;
3890 dev->CCD_color[5] = CCD_color_blue;
3892 dev->CCD_color[6] = CCD_color_green;
3893 dev->CCD_color[7] = CCD_color_blue;
3895 dev->CCD_color[8] = CCD_color_green;
3899 dev->CCD_color[0] = CCD_color_green;
3901 dev->CCD_color[1] = CCD_color_blue;
3902 dev->CCD_color[2] = CCD_color_green;
3904 dev->CCD_color[3] = CCD_color_blue;
3905 dev->CCD_color[4] = CCD_color_red;
3906 dev->CCD_color[5] = CCD_color_green;
3908 dev->CCD_color[6] = CCD_color_blue;
3909 dev->CCD_color[7] = CCD_color_red;
3911 dev->CCD_color[8] = CCD_color_red;
3913 DBG(DBG_info,"scanner uses color-line-ordering with CCD-distance of %d lines\n", dev->CCD_distance);
3924 dev->three_pass=1;
3931 if (dev->do_color_ordering != 0)
3933 if ( (dev->colormode != RGB) || (dev->three_pass != 0) )
3935 dev->do_color_ordering = 0; /* color ordering not necessary */
3946 static void umax_get_inquiry_values(Umax_Device *dev)
3952 inquiry_block = dev->buffer[0];
3953 dev->inquiry_len = get_inquiry_additional_length(dev->buffer[0])+5;
3954 dev->cbhs_range = dev->inquiry_cbhs = get_inquiry_CBHS(inquiry_block);
3956 if (dev->cbhs_range > IN_CBHS_255)
3958 dev->cbhs_range = IN_CBHS_255;
3961 if (dev->cbhs_range == IN_CBHS_50)
3963 dev->inquiry_contrast_min = 103; /* minimum value for c */
3964 dev->inquiry_contrast_max = 153; /* maximum value for c */
3965 dev->inquiry_brightness_min = 78; /* minimum value for b */
3966 dev->inquiry_brightness_max = 178; /* maximum value for b */
3967 dev->inquiry_threshold_min = 78; /* minimum value for t */
3968 dev->inquiry_threshold_max = 178; /* maximum value for t */
3969 dev->inquiry_highlight_min = 1; /* minimum value for h */
3970 dev->inquiry_highlight_max = 50; /* maximum value for h */
3971 dev->inquiry_shadow_min = 0; /* minimum value for s */
3972 dev->inquiry_shadow_max = 49; /* maximum value for s */
3975 get_inquiry_vendor( (char *)inquiry_block, dev->vendor); dev->vendor[8] ='\0';
3976 get_inquiry_product((char *)inquiry_block, dev->product); dev->product[16]='\0';
3977 get_inquiry_version((char *)inquiry_block, dev->version); dev->version[4] ='\0';
3979 dev->inquiry_batch_scan = get_inquiry_fw_batch_scan(inquiry_block);
3980 dev->inquiry_quality_ctrl = get_inquiry_fw_quality(inquiry_block);
3981 dev->inquiry_preview = get_inquiry_fw_fast_preview(inquiry_block);
3982 dev->inquiry_lamp_ctrl = get_inquiry_fw_lamp_int_cont(inquiry_block);
3983 dev->inquiry_calibration = get_inquiry_fw_calibration(inquiry_block);
3984 dev->inquiry_transavail = get_inquiry_transavail(inquiry_block);
3985 dev->inquiry_adfmode = get_inquiry_scanmode(inquiry_block);
3987 if (dev->inquiry_len<=0x8f)
3992 dev->inquiry_uta = get_inquiry_sc_uta(inquiry_block);
3993 dev->inquiry_adf = get_inquiry_sc_adf(inquiry_block);
3995 dev->inquiry_one_pass_color = get_inquiry_sc_one_pass_color(inquiry_block);
3996 dev->inquiry_three_pass_color = get_inquiry_sc_three_pass_color(inquiry_block);
3997 dev->inquiry_color = get_inquiry_sc_color(inquiry_block);
3998 dev->inquiry_gray = get_inquiry_sc_gray(inquiry_block);
3999 dev->inquiry_halftone = get_inquiry_sc_halftone(inquiry_block);
4000 dev->inquiry_lineart = get_inquiry_sc_lineart(inquiry_block);
4002 dev->inquiry_exposure_adj = get_inquiry_fw_adjust_exposure_tf(inquiry_block);
4003 dev->inquiry_exposure_time_step_unit = get_inquiry_exposure_time_step_unit(inquiry_block);
4004 dev->inquiry_exposure_time_max = get_inquiry_exposure_time_max(inquiry_block);
4007 dev->inquiry_exposure_time_l_min = get_inquiry_exposure_time_lhg_min(inquiry_block);
4008 dev->inquiry_exposure_time_l_fb_def = get_inquiry_exposure_time_lh_def_fb(inquiry_block);
4009 dev->inquiry_exposure_time_l_uta_def = get_inquiry_exposure_time_lh_def_uta(inquiry_block);
4012 dev->inquiry_exposure_time_h_min = get_inquiry_exposure_time_lhg_min(inquiry_block);
4013 dev->inquiry_exposure_time_h_fb_def = get_inquiry_exposure_time_lh_def_fb(inquiry_block);
4014 dev->inquiry_exposure_time_h_uta_def = get_inquiry_exposure_time_lh_def_uta(inquiry_block);
4017 dev->inquiry_exposure_time_g_min = get_inquiry_exposure_time_lhg_min(inquiry_block);
4018 dev->inquiry_exposure_time_g_fb_def = get_inquiry_exposure_time_gray_def_fb(inquiry_block);
4019 dev->inquiry_exposure_time_g_uta_def = get_inquiry_exposure_time_gray_def_uta(inquiry_block);
4022 dev->inquiry_exposure_time_c_min = get_inquiry_exposure_time_color_min(inquiry_block);
4023 dev->inquiry_exposure_time_c_fb_def_r = get_inquiry_exposure_time_def_r_fb(inquiry_block);
4024 dev->inquiry_exposure_time_c_fb_def_g = get_inquiry_exposure_time_def_g_fb(inquiry_block);
4025 dev->inquiry_exposure_time_c_fb_def_b = get_inquiry_exposure_time_def_g_fb(inquiry_block);
4026 dev->inquiry_exposure_time_c_uta_def_r = get_inquiry_exposure_time_def_r_uta(inquiry_block);
4027 dev->inquiry_exposure_time_c_uta_def_g = get_inquiry_exposure_time_def_g_uta(inquiry_block);
4028 dev->inquiry_exposure_time_c_uta_def_b = get_inquiry_exposure_time_def_b_uta(inquiry_block);
4031 dev->inquiry_dor = get_inquiry_sc_double_res(inquiry_block);
4032 dev->inquiry_reverse = get_inquiry_sc_bi_image_reverse(inquiry_block);
4033 dev->inquiry_reverse_multi = get_inquiry_sc_multi_image_reverse(inquiry_block);
4034 dev->inquiry_shadow = 1 - get_inquiry_sc_no_shadow(inquiry_block);
4035 dev->inquiry_highlight = 1 - get_inquiry_sc_no_highlight(inquiry_block);
4036 dev->inquiry_analog_gamma = get_inquiry_analog_gamma(inquiry_block);
4037 dev->inquiry_lineart_order = get_inquiry_lineart_order(inquiry_block);
4039 dev->inquiry_lens_cal_in_doc_pos = get_inquiry_manual_focus(inquiry_block);
4040 dev->inquiry_manual_focus = get_inquiry_manual_focus(inquiry_block);
4041 dev->inquiry_sel_uta_lens_cal_pos = get_inquiry_manual_focus(inquiry_block);
4043 dev->inquiry_gamma_dwload = get_inquiry_gamma_download_available(inquiry_block);
4047 dev->inquiry_gamma_DCF = 2;
4050 dev->inquiry_GIB = get_inquiry_gib(inquiry_block);
4051 dev->inquiry_GOB = get_inquiry_gob(inquiry_block);
4052 dev->inquiry_color_order = get_inquiry_color_order(inquiry_block);
4053 dev->inquiry_vidmem = get_inquiry_max_vidmem(inquiry_block);
4056 dev->inquiry_optical_res = 100 * get_inquiry_max_opt_res(inquiry_block);
4057 if (dev->inquiry_len > 0x94)
4059 dev->inquiry_optical_res += get_inquiry_optical_resolution_residue(inquiry_block);
4063 dev->inquiry_x_res = 100 * get_inquiry_max_x_res(inquiry_block);
4064 if (dev->inquiry_len > 0x95)
4066 dev->inquiry_x_res+= get_inquiry_x_resolution_residue(inquiry_block);
4070 dev->inquiry_y_res = 100 * get_inquiry_max_y_res(inquiry_block);
4071 if (dev->inquiry_len > 0x96)
4073 dev->inquiry_y_res+= get_inquiry_y_resolution_residue(inquiry_block);
4078 dev->inquiry_dor_optical_res = 100 * get_inquiry_dor_max_opt_res(inquiry_block);
4079 if (dev->inquiry_len > 0xa0)
4081 dev->inquiry_dor_optical_res += get_inquiry_dor_optical_resolution_residue(inquiry_block);
4085 dev->inquiry_dor_x_res = 100 * get_inquiry_dor_max_x_res(inquiry_block);
4086 if (dev->inquiry_len > 0xa1)
4088 dev->inquiry_dor_x_res+= get_inquiry_dor_x_resolution_residue(inquiry_block);
4092 dev->inquiry_dor_y_res = 100 * get_inquiry_dor_max_y_res(inquiry_block);
4093 if (dev->inquiry_len > 0xa2)
4095 dev->inquiry_dor_y_res+= get_inquiry_dor_y_resolution_residue(inquiry_block);
4098 if (dev->inquiry_dor) /* DOR mode available ? */
4102 if (dev->inquiry_dor_optical_res == 0)
4104 dev->inquiry_dor_optical_res = dev->inquiry_optical_res * 2;
4107 if (dev->inquiry_dor_x_res == 0)
4109 dev->inquiry_dor_x_res = dev->inquiry_x_res * 2;
4112 if (dev->inquiry_dor_y_res == 0)
4114 dev->inquiry_dor_y_res = dev->inquiry_y_res * 2;
4118 dev->inquiry_fb_width = (double)get_inquiry_fb_max_scan_width(inquiry_block) * 0.01;
4119 dev->inquiry_fb_length = (double)get_inquiry_fb_max_scan_length(inquiry_block) * 0.01;
4121 dev->inquiry_uta_width = (double)get_inquiry_uta_max_scan_width(inquiry_block) * 0.01;
4122 dev->inquiry_uta_length = (double)get_inquiry_uta_max_scan_length(inquiry_block) * 0.01;
4123 dev->inquiry_uta_x_off = (double)get_inquiry_uta_x_original_point(inquiry_block) * 0.01;
4124 dev->inquiry_uta_y_off = (double)get_inquiry_uta_y_original_point(inquiry_block) * 0.01;
4126 dev->inquiry_dor_width = (double)get_inquiry_dor_max_scan_width(inquiry_block) * 0.01;
4127 dev->inquiry_dor_length = (double)get_inquiry_dor_max_scan_length(inquiry_block) * 0.01;
4128 dev->inquiry_dor_x_off = (double)get_inquiry_dor_x_original_point(inquiry_block) * 0.01;
4129 dev->inquiry_dor_y_off = (double)get_inquiry_dor_y_original_point(inquiry_block) * 0.01;
4131 dev->inquiry_max_warmup_time = get_inquiry_lamp_warmup_maximum_time(inquiry_block) * 2;
4133 dev->inquiry_wdb_len = get_inquiry_wdb_length(inquiry_block);
4138 if (dev->inquiry_len<=0x9a)
4142 dev->inquiry_max_calib_lines = get_inquiry_max_calibration_data_lines(inquiry_block);
4145 if (dev->inquiry_len<=0x9b)
4149 dev->inquiry_fb_uta_color_arrangement = get_inquiry_fb_uta_line_arrangement_mode(inquiry_block);
4152 if (dev->inquiry_len<=0x9c)
4156 dev->inquiry_adf_color_arrangement = get_inquiry_adf_line_arrangement_mode(inquiry_block);
4159 if (dev->inquiry_len<=0x9d)
4163 dev->inquiry_CCD_line_distance = get_inquiry_CCD_line_distance(inquiry_block);
4201 static void umax_output_image_data(Umax_Device *dev, FILE *fp, unsigned int data_to_read, int bufnr)
4203 if (dev->do_color_ordering == 0) /* pixel ordering */
4205 if ((dev->inquiry_lineart_order) && (dev->colormode == LINEART)) /* lineart with LSB first */
4212 old = dev->buffer[bufnr][i];
4219 dev->buffer[bufnr][i]=new;
4222 fwrite(dev->buffer[bufnr], 1, data_to_read, fp);
4226 unsigned char *linesource = dev->buffer[bufnr];
4232 if (dev->bits_per_pixel_code != 1) /* >24 bpp */
4237 lines = data_to_read / (dev->width_in_pixels * bytes);
4241 umax_order_line(dev, linesource);
4242 linesource += dev->width_in_pixels * bytes;
4244 pixelsource = umax_get_pixel_line(dev);
4247 fwrite(pixelsource, bytes, dev->width_in_pixels * 3, fp);
4256 static int umax_reader_process(Umax_Device *dev, FILE *fp, unsigned int image_size)
4268 dev->row_bufsize = dev->bufsize;
4269 umax_trim_rowbufsize(dev); /* trim bufsize */
4271 if (dev->bits_per_pixel_code != 1) /* >24 bpp */
4276 DBG(DBG_read,"reading %u bytes in blocks of %u bytes\n", image_size, dev->row_bufsize);
4278 if (dev->pixelbuffer != NULL) /* buffer exists? */
4280 free(dev->pixelbuffer);
4281 dev->pixelbuffer = NULL;
4284 if (dev->do_color_ordering != 0)
4288 dev->pixelline_max = 3 * dev->CCD_distance * dev->scale_y + 2;
4290 dev->pixelbuffer = malloc(dev->width_in_pixels * dev->pixelline_max * bytes * 3);
4292 if (dev->pixelbuffer == NULL) /* NO MEMORY */
4304 data_to_queue = (data_left_to_queue < dev->row_bufsize) ? data_left_to_queue : dev->row_bufsize;
4306 /* umax_get_data_buffer_status(dev); */
4308 status = umax_queue_read_image_data_req(dev, data_to_queue, bufnr_queue);
4318 free(dev->pixelbuffer);
4319 dev->pixelbuffer = NULL;
4327 if (bufnr_queue >= dev->scsi_maxqueue)
4341 status = umax_wait_queued_image_data(dev, bufnr_read);
4346 free(dev->pixelbuffer);
4347 dev->pixelbuffer = NULL;
4351 data_to_read = dev->length_read[bufnr_read]; /* number of bytes in buffer */
4352 umax_output_image_data(dev, fp, data_to_read, bufnr_read);
4358 if (dev->length_read[bufnr_read] != dev->length_queued[bufnr_read])
4360 data_left_to_queue += dev->length_queued[bufnr_read] - dev->length_read[bufnr_read];
4364 if (bufnr_read >= dev->scsi_maxqueue)
4371 free(dev->pixelbuffer);
4372 dev->pixelbuffer = NULL;
4381 static void umax_initialize_values(Umax_Device *dev) /* called each time before setting scan-values */
4382 { /* Initialize dev structure */
4385 dev->three_pass = 0; /* 1 if threepas_mode only */
4386 dev->row_len = -1;
4387 dev->max_value = 255; /* maximum value */
4389 dev->wdb_len = 0;
4390 dev->width_in_pixels = 0; /* scan width in pixels */
4391 dev->length_in_pixels = 0; /* scan length in pixels */
4392 dev->scanwidth = 0; /* width in inch at x_coordinate_base dpi */
4393 dev->scanlength = 0; /* length in inch at y_coordinate_base dpi */
4394 dev->x_resolution = 0;
4395 dev->y_resolution = 0;
4396 dev->upper_left_x = 0; /* at 1200pt/inch */
4397 dev->upper_left_y = 0; /* at 1200pt/inch */
4398 dev->bytes_per_color = 0; /* bytes for each color */
4400 dev->bits_per_pixel = 8; /* number of bits per pixel */
4401 dev->bits_per_pixel_code = 1; /* 1 = 8/24 bpp, 2 = 9/27 bpp, 4 = 10/30 bpp */
4402 dev->gamma_input_bits_code = 1; /* 8 = 12/36 bpp, 16 = 14/42 bpp, 32 = 16/48 bpp */
4403 dev->set_auto = 0; /* 0 or 1 */
4404 dev->preview = 0; /* 1 for preview */
4405 dev->quality = 0; /* quality calibration */
4406 dev->warmup = 0; /* warmup-bit */
4407 dev->fix_focus_position = 0; /* fix focus position */
4408 dev->lens_cal_in_doc_pos = 0; /* lens calibration in document position */
4409 dev->disable_pre_focus = 0; /* disable pre focus */
4410 dev->holder_focus_pos_0mm = 0; /* 0.6mm <-> 0.0mm holder focus position */
4411 dev->manual_focus = 0; /* automatic <-> manual focus */
4412 dev->colormode = 0; /* LINEART, HALFTONE, GRAYSCALE or RGB */
4413 dev->adf = 0; /* 1 if adf shall be used */
4414 dev->uta = 0; /* 1 if uta shall be used */
4415 dev->module = WD_module_flatbed;
4416 dev->cbhs_range = WD_CBHS_255;
4417 dev->dor = 0;
4418 dev->halftone = WD_halftone_8x8_1;
4419 dev->reverse = 0;
4420 dev->reverse_multi = 0;
4421 dev->calibration = 0;
4423 dev->exposure_time_calibration_r = 0; /* use this for calibration */
4424 dev->exposure_time_calibration_g = 0; /* use this for calibration */
4425 dev->exposure_time_calibration_b = 0; /* use this for calibration */
4426 dev->exposure_time_scan_r = 0; /* use this for scan */
4427 dev->exposure_time_scan_g = 0; /* use this for scan */
4428 dev->exposure_time_scan_b = 0; /* use this for scan */
4430 dev->c_density = WD_lamp_c_density_auto; /* calibration lamp density */
4431 dev->s_density = WD_lamp_s_density_auto; /* next scan lamp density */
4433 dev->threshold = 128; /* threshold for lineart mode */
4434 dev->brightness = 128; /* brightness for halftone mode */
4435 dev->contrast = 128; /* contrast for halftone mode */
4436 dev->highlight_r = 255; /* highlight gray/red */
4437 dev->highlight_g = 255; /* highlight green */
4438 dev->highlight_b = 255; /* highlight blue */
4439 dev->shadow_r = 0; /* shadow gray/red */
4440 dev->shadow_g = 0; /* shadow green */
4441 dev->shadow_b = 0; /* shadow blue */
4443 dev->digital_gamma_r = WD_gamma_normal;
4444 dev->digital_gamma_g = WD_gamma_normal;
4445 dev->digital_gamma_b = WD_gamma_normal;
4447 dev->analog_gamma_r = 0; /* analog gamma for red and gray to 1.0 */
4448 dev->analog_gamma_g = 0; /* analog gamma for green to 1.0 */
4449 dev->analog_gamma_b = 0; /* analog gamma for blue to 1.0 */
4452 dev->pixelline_ready[0] = 0; /* reset all values for color ordering */
4453 dev->pixelline_ready[1] = 0;
4454 dev->pixelline_ready[2] = 0;
4455 dev->pixelline_next[0] = 0;
4456 dev->pixelline_next[1] = 0;
4457 dev->pixelline_next[2] = 0;
4458 dev->pixelline_del[0] = 1;
4459 dev->pixelline_del[1] = 1;
4460 dev->pixelline_del[2] = 1;
4461 dev->pixelline_optic[0] = 1;
4462 dev->pixelline_optic[1] = 1;
4463 dev->pixelline_optic[2] = 1;
4464 dev->pixelline_max = 0;
4465 dev->pixelline_opt_res = 0;
4466 dev->pixelline_read = 0;
4467 dev->pixelline_written = 0;
4468 dev->CCD_distance = 0;
4470 dev->calib_lines = 0; /* request calibration lines */
4471 dev->do_calibration = 0; /* no calibration by driver */
4472 dev->do_color_ordering = 0; /* no line- to pixel-mode ordering */
4474 dev->button0_pressed = 0; /* reset button 0 pressed flag */
4475 dev->button1_pressed = 0; /* reset button 1 pressed flag */
4476 dev->button2_pressed = 0; /* reset button 2 pressed flag */
4483 static void umax_init(Umax_Device *dev) /* umax_init is called once while driver-initialization */
4487 dev->devicename = NULL;
4488 dev->pixelbuffer = NULL;
4491 if (dev->connection_type == SANE_UMAX_SCSI)
4493 dev->request_scsi_maxqueue = umax_scsi_maxqueue;
4498 dev->request_scsi_maxqueue = 1;
4501 dev->request_preview_lines = umax_preview_lines;
4502 dev->request_scan_lines = umax_scan_lines;
4503 dev->handle_bad_sense_error = umax_handle_bad_sense_error;
4504 dev->execute_request_sense = umax_execute_request_sense;
4505 dev->scsi_buffer_size_min = umax_scsi_buffer_size_min;
4506 dev->scsi_buffer_size_max = umax_scsi_buffer_size_max;
4507 dev->force_preview_bit_rgb = umax_force_preview_bit_rgb;
4508 dev->slow = umax_slow;
4509 dev->smear = umax_smear;
4510 dev->calibration_area = umax_calibration_area;
4511 dev->calibration_width_offset = umax_calibration_width_offset;
4512 dev->calibration_width_offset_batch = umax_calibration_width_offset_batch;
4513 dev->calibration_bytespp = umax_calibration_bytespp;
4514 dev->exposure_time_rgb_bind = umax_exposure_time_rgb_bind;
4515 dev->invert_shading_data = umax_invert_shading_data;
4516 dev->lamp_control_available = umax_lamp_control_available;
4517 dev->gamma_lsb_padded = umax_gamma_lsb_padded;
4519 DBG(DBG_info, "request_scsi_maxqueue = %d\n", dev->request_scsi_maxqueue);
4520 DBG(DBG_info, "request_preview_lines = %d\n", dev->request_preview_lines);
4521 DBG(DBG_info, "request_scan_lines = %d\n", dev->request_scan_lines);
4522 DBG(DBG_info, "handle_bad_sense_error = %d\n", dev->handle_bad_sense_error);
4523 DBG(DBG_info, "execute_request_sense = %d\n", dev->execute_request_sense);
4524 DBG(DBG_info, "scsi_buffer_size_min = %d\n", dev->scsi_buffer_size_min);
4525 DBG(DBG_info, "scsi_buffer_size_max = %d\n", dev->scsi_buffer_size_max);
4526 DBG(DBG_info, "force_preview_bit_rgb = %d\n", dev->force_preview_bit_rgb);
4527 DBG(DBG_info, "slow = %d\n", dev->slow);
4528 DBG(DBG_info, "smear = %d\n", dev->smear);
4529 DBG(DBG_info, "calibration_area = %d\n", dev->calibration_area);
4530 DBG(DBG_info, "calibration_width_offset = %d\n", dev->calibration_width_offset);
4531 DBG(DBG_info, "calibration_width_offset_batch = %d\n", dev->calibration_width_offset_batch);
4532 DBG(DBG_info, "calibration_bytespp = %d\n", dev->calibration_bytespp);
4533 DBG(DBG_info, "exposure_time_rgb_bind = %d\n", dev->exposure_time_rgb_bind);
4534 DBG(DBG_info, "invert_shading_data = %d\n", dev->invert_shading_data);
4535 DBG(DBG_info, "lamp_control_available = %d\n", dev->lamp_control_available);
4538 dev->inquiry_len = 0;
4539 dev->inquiry_wdb_len = -1;
4540 dev->inquiry_optical_res = -1;
4541 dev->inquiry_x_res = -1;
4542 dev->inquiry_y_res = -1;
4543 dev->inquiry_fb_width = -1;
4544 dev->inquiry_fb_length = -1;
4545 dev->inquiry_uta_width = -1;
4546 dev->inquiry_uta_length = -1;
4547 dev->inquiry_dor_width = -1;
4548 dev->inquiry_dor_length = -1;
4549 dev->inquiry_exposure_adj = 0;
4550 dev->inquiry_exposure_time_step_unit = -1; /* exposure time unit in micro sec */
4551 dev->inquiry_exposure_time_max = -1; /* exposure time maximum */
4552 dev->inquiry_exposure_time_l_min = -1; /* exposure time minimum for lineart */
4553 dev->inquiry_exposure_time_l_fb_def = -1; /* exposure time default for lineart flatbed */
4554 dev->inquiry_exposure_time_l_uta_def = -1; /* exposure time default for lineart uta */
4555 dev->inquiry_exposure_time_h_min = -1; /* exposure time minimum for halftone */
4556 dev->inquiry_exposure_time_h_fb_def = -1; /* exposure time default for halftone flatbed */
4557 dev->inquiry_exposure_time_h_uta_def = -1; /* exposure time default for halftone uta */
4558 dev->inquiry_exposure_time_g_min = -1; /* exposure time minimum for grayscale */
4559 dev->inquiry_exposure_time_g_fb_def = -1; /* exposure time default for grayscale flatbed */
4560 dev->inquiry_exposure_time_g_uta_def = -1; /* exposure time default for grayscale uta */
4561 dev->inquiry_exposure_time_c_min = -1; /* exposure time minimum for color */
4562 dev->inquiry_exposure_time_c_fb_def_r = -1; /* exposure time default for color flatbed red */
4563 dev->inquiry_exposure_time_c_fb_def_g = -1; /* exposure time default for color flatbed green */
4564 dev->inquiry_exposure_time_c_fb_def_b = -1; /* exposure time default for color flatbed blue */
4565 dev->inquiry_exposure_time_c_uta_def_r = -1; /* exposure time default for color uta red */
4566 dev->inquiry_exposure_time_c_uta_def_g = -1; /* exposure time default for color uta green */
4567 dev->inquiry_exposure_time_c_uta_def_b = -1; /* exposure time default for color uta blue */
4568 dev->inquiry_max_warmup_time = 0; /* maximum warmup time */
4569 dev->inquiry_cbhs = WD_CBHS_255;
4570 dev->inquiry_contrast_min = 1; /* minimum value for c */
4571 dev->inquiry_contrast_max = 255; /* maximum value for c */
4572 dev->inquiry_brightness_min = 1; /* minimum value for b */
4573 dev->inquiry_brightness_max = 255; /* maximum value for b */
4574 dev->inquiry_threshold_min = 1; /* minimum value for t */
4575 dev->inquiry_threshold_max = 255; /* maximum value for t */
4576 dev->inquiry_highlight_min = 1; /* minimum value for h */
4577 dev->inquiry_highlight_max = 255; /* maximum value for h */
4578 dev->inquiry_shadow_min = 0; /* minimum value for s */
4579 dev->inquiry_shadow_max = 254; /* maximum value for s */
4580 dev->inquiry_quality_ctrl = 0;
4581 dev->inquiry_preview = 0;
4582 dev->inquiry_lamp_ctrl = 0;
4583 dev->inquiry_transavail = 0;
4584 dev->inquiry_uta = 0;
4585 dev->inquiry_adfmode = 0;
4586 dev->inquiry_adf = 0;
4587 dev->inquiry_dor = 0;
4588 dev->inquiry_reverse = 0;
4589 dev->inquiry_reverse_multi = 0;
4590 dev->inquiry_analog_gamma = 0;
4591 dev->inquiry_gamma_dwload = 0;
4592 dev->inquiry_one_pass_color = 0;
4593 dev->inquiry_three_pass_color = 0;
4594 dev->inquiry_color = 0;
4595 dev->inquiry_gray = 0;
4596 dev->inquiry_halftone = 0;
4597 dev->inquiry_lineart = 0;
4598 dev->inquiry_calibration = 1;
4599 dev->inquiry_shadow = 0;
4600 dev->inquiry_highlight = 0;
4601 dev->inquiry_gamma_DCF = -1;
4602 dev->inquiry_max_calib_lines = 66; /* most scanners use 66 lines, so lets define it as default */
4604 dev->common_xy_resolutions = 0;
4606 dev->x_coordinate_base = 1200; /* these are the 1200pt/inch */
4607 dev->y_coordinate_base = 1200; /* these are the 1200pt/inch */
4609 dev->button0_pressed = 0; /* reset button 0 pressed flag */
4610 dev->button1_pressed = 0; /* reset button 1 pressed flag */
4611 dev->button2_pressed = 0; /* reset button 2 pressed flag */
4613 dev->pause_for_color_calibration = 0; /* pause between start_scan and do_calibration in ms */
4614 dev->pause_for_gray_calibration = 0; /* pause between start_scan and do_calibration in ms */
4615 dev->pause_after_calibration = 0; /* pause between do_calibration and read data in ms */
4616 dev->pause_after_reposition = -1; /* pause after repostion scanner in ms, -1 = do not wait */
4617 dev->pause_for_moving = 0; /* pause for moving scanhead over full area */
4621 dev->low_byte_first = 1; /* in 2 byte mode send lowbyte first */
4626 dev->low_byte_first = 0; /* in 2 byte mode send highbyte first */
4716 Umax_Device *dev;
4721 for (dev = first_dev; dev; dev = dev->next) /* search is scanner already is listed in devicelist */
4723 if (strcmp(dev->sane.name, devicename) == 0) /* scanner is already listed */
4727 *devp = dev; /* return pointer to device */
4735 dev = malloc( sizeof(*dev) );
4736 if (!dev)
4740 memset(dev, '\0', sizeof(Umax_Device)); /* clear structure */
4746 dev->connection_type = connection_type; /* 0 = unknown, 1=scsi, 2=usb */
4748 if (dev->connection_type != SANE_UMAX_SCSI)
4750 dev->bufsize = 16384; /* 16KB */
4753 if (sanei_umaxusb_open(devicename, &dev->sfd, sense_handler, dev) == SANE_STATUS_GOOD)
4755 dev->connection_type = SANE_UMAX_USB;
4759 if (dev->connection_type == SANE_UMAX_USB) /* we know it is not a scsi device: error */
4762 free(dev);
4770 dev->connection_type = SANE_UMAX_SCSI;
4773 if (dev->connection_type != SANE_UMAX_USB) /* not an USB device, then try as SCSI */
4776 dev->bufsize = 16384; /* 16KB */
4779 if (sanei_scsi_open_extended(devicename, &dev->sfd, sense_handler, dev, (int *) &dev->bufsize) != 0)
4782 free(dev);
4786 if (dev->bufsize < 4096) /* < 4KB */
4789 umax_scsi_close(dev);
4790 free(dev);
4794 DBG(DBG_info, "attach_scanner: sanei_scsi_open_extended returned scsi buffer size = %d\n", dev->bufsize);
4796 dev->bufsize = sanei_scsi_max_request_size;
4798 if (sanei_scsi_open(devicename, dev, sense_handler, dev) != 0)
4801 free(dev);
4805 dev->connection_type = SANE_UMAX_SCSI; /* set connection type (may have been unknown == 0) */
4809 dev->buffer[0] = malloc(dev->bufsize); /* allocate buffer */
4813 dev->buffer[i] = NULL;
4816 if (!dev->buffer[0]) /* malloc failed */
4819 umax_scsi_close(dev);
4820 free(dev);
4824 dev->scsi_maxqueue = 1; /* only one buffer outside the reader process */
4826 umax_init(dev); /* preset values in structure dev */
4827 umax_initialize_values(dev); /* reset values */
4829 dev->devicename = strdup(devicename);
4831 if (umax_identify_scanner(dev) != 0)
4834 umax_scsi_close(dev);
4835 free(dev->buffer[0]);
4836 free(dev);
4840 if (dev->slow == -1) /* option is not predefined in umax.conf and not by backend */
4842 dev->slow = 0;
4845 if (dev->smear == -1) /* option is not predefined in umax.conf and not by backend */
4847 dev->smear = 0;
4850 if (dev->invert_shading_data == -1) /* nothing defined in umax.conf and not by backend */
4852 dev->invert_shading_data = 0;
4855 if (dev->gamma_lsb_padded == -1) /* nothing defined in umax.conf and not by backend */
4857 dev->gamma_lsb_padded = 0;
4860 umax_get_inquiry_values(dev);
4861 umax_print_inquiry(dev);
4866 umax_scsi_close(dev);
4868 dev->sane.name = dev->devicename;
4869 dev->sane.vendor = dev->vendor;
4870 dev->sane.model = dev->product;
4871 dev->sane.type = "flatbed scanner";
4873 if (strcmp(dev->sane.model,"PSD ") == 0)
4875 dev->sane.type = "page scanner";
4878 dev->x_range.min = SANE_FIX(0);
4879 dev->x_range.quant = SANE_FIX(0);
4880 dev->x_range.max = SANE_FIX(dev->inquiry_fb_width * MM_PER_INCH);
4882 dev->y_range.min = SANE_FIX(0);
4883 dev->y_range.quant = SANE_FIX(0);
4884 dev->y_range.max = SANE_FIX(dev->inquiry_fb_length * MM_PER_INCH);
4887 dev->x_dpi_range.min = SANE_FIX(dev->inquiry_optical_res/100);
4888 dev->x_dpi_range.quant = SANE_FIX(dev->inquiry_optical_res/100);
4890 dev->x_dpi_range.min = SANE_FIX(5);
4891 dev->x_dpi_range.quant = SANE_FIX(5);
4893 dev->x_dpi_range.max = SANE_FIX(dev->inquiry_x_res);
4896 dev->y_dpi_range.min = SANE_FIX(dev->inquiry_optical_res/100);
4897 dev->y_dpi_range.quant = SANE_FIX(dev->inquiry_optical_res/100);
4899 dev->y_dpi_range.min = SANE_FIX(5);
4900 dev->y_dpi_range.quant = SANE_FIX(5);
4902 dev->y_dpi_range.max = SANE_FIX(dev->inquiry_y_res);
4904 dev->analog_gamma_range.min = SANE_FIX(1.0);
4905 dev->analog_gamma_range.quant = SANE_FIX(0.01);
4906 dev->analog_gamma_range.max = SANE_FIX(2.0);
4908 DBG(DBG_info,"x_range.max = %f\n", SANE_UNFIX(dev->x_range.max));
4909 DBG(DBG_info,"y_range.max = %f\n", SANE_UNFIX(dev->y_range.max));
4910 DBG(DBG_info,"x_dpi_range.max = %f\n", SANE_UNFIX(dev->x_dpi_range.max));
4911 DBG(DBG_info,"y_dpi_range.max = %f\n", SANE_UNFIX(dev->y_dpi_range.max));
4914 dev->next = first_dev;
4915 first_dev = dev;
4919 *devp = dev;
6016 /* no config-file: try /dev/scanner and /dev/usbscanner. */
6017 attach_scanner("/dev/scanner", 0, SANE_UMAX_SCSI);
6019 attach_scanner("/dev/usbscanner", 0, SANE_UMAX_USB);
6103 Umax_Device *dev, *next;
6107 for (dev = first_dev; dev; dev = next)
6109 next = dev->next;
6110 free(dev->devicename);
6111 free(dev);
6126 Umax_Device *dev;
6144 for (dev = first_dev; i < num_devices; dev = dev->next)
6146 devlist[i++] = &dev->sane;
6162 Umax_Device *dev;
6173 for (dev = first_dev; dev; dev = dev->next)
6175 if (strcmp(dev->sane.name, devicename) == 0)
6181 if (!dev) /* no device found */
6183 status = attach_scanner(devicename, &dev, 0 /* connection-type not known */); /* try to open devicename and set dev */
6193 dev = first_dev; /* empty devicename -> use first device */
6196 if (!dev) /* no device found */
6209 scanner->device = dev;