diff --git a/backend/genesys.cc b/backend/genesys.cc index 50a275c75..3ab1a324b 100644 --- a/backend/genesys.cc +++ b/backend/genesys.cc @@ -3666,7 +3666,7 @@ static void genesys_read_ordered_data(Genesys_Device* dev, SANE_Byte* destinatio needs_reorder = 0; needs_ccd = dev->current_setup.max_shift > 0; - needs_shrink = dev->settings.pixels != src_pixels; + needs_shrink = dev->settings.requested_pixels != src_pixels; needs_reverse = depth == 1; DBG(DBG_info, "%s: using filters:%s%s%s%s\n", __func__, @@ -3696,7 +3696,7 @@ static void genesys_read_ordered_data(Genesys_Device* dev, SANE_Byte* destinatio DBG(DBG_info, "%s: %lu lines left by output\n", __func__, ((dev->total_bytes_to_read - dev->total_bytes_read) * 8UL) / - (dev->settings.pixels * channels * depth)); + (dev->settings.requested_pixels * channels * depth)); DBG(DBG_info, "%s: %lu lines left by input\n", __func__, ((dev->read_bytes_left + dev->read_buffer.avail()) * 8UL) / (src_pixels * channels * depth)); @@ -3917,10 +3917,11 @@ Problems with the first approach: /* we are greedy. we work as much as possible */ bytes = dst_buffer->size() - dst_buffer->avail(); - if (dst_lines > (bytes * 8) / (dev->settings.pixels * channels * depth)) - dst_lines = (bytes * 8) / (dev->settings.pixels * channels * depth); + if (dst_lines > (bytes * 8) / (dev->settings.requested_pixels * channels * depth)) { + dst_lines = (bytes * 8) / (dev->settings.requested_pixels * channels * depth); + } - bytes = (dst_lines * dev->settings.pixels * channels * depth) / 8; + bytes = (dst_lines * dev->settings.requested_pixels * channels * depth) / 8; work_buffer_dst = dst_buffer->get_write_pos(bytes); @@ -3930,21 +3931,21 @@ Problems with the first approach: { if (depth == 1) genesys_shrink_lines_1(work_buffer_src, work_buffer_dst, dst_lines, src_pixels, - dev->settings.pixels, channels); + dev->settings.requested_pixels, channels); else if (depth == 8) genesys_shrink_lines_8(work_buffer_src, work_buffer_dst, dst_lines, src_pixels, - dev->settings.pixels, channels); + dev->settings.requested_pixels, channels); else genesys_shrink_lines_16(work_buffer_src, work_buffer_dst, dst_lines, src_pixels, - dev->settings.pixels, channels); + dev->settings.requested_pixels, channels); /* we just consumed this many bytes*/ bytes = (dst_lines * src_pixels * channels * depth) / 8; src_buffer->consume(bytes); /* we just created this many bytes*/ - bytes = (dst_lines * dev->settings.pixels * channels * depth) / 8; - dst_buffer->produce(bytes); + bytes = (dst_lines * dev->settings.requested_pixels * channels * depth) / 8; + dst_buffer->produce(bytes); } src_buffer = dst_buffer; } @@ -4118,6 +4119,7 @@ static void calc_parameters(Genesys_Scanner* s) s->dev->settings.lines = s->params.lines; s->dev->settings.pixels = pixels_per_line; + s->dev->settings.requested_pixels = pixels_per_line; s->params.pixels_per_line = pixels_per_line; s->params.bytes_per_line = bytes_per_line; s->dev->settings.tl_x = tl_x; @@ -5113,7 +5115,7 @@ probe_genesys_devices (void) of Genesys_Calibration_Cache as is. */ static const char* CALIBRATION_IDENT = "sane_genesys"; -static const int CALIBRATION_VERSION = 6; +static const int CALIBRATION_VERSION = 7; bool read_calibration(std::istream& str, Genesys_Device::Calibration& calibration, const std::string& path) diff --git a/backend/genesys_gl124.cc b/backend/genesys_gl124.cc index 9f6bf52f0..919d18361 100644 --- a/backend/genesys_gl124.cc +++ b/backend/genesys_gl124.cc @@ -1241,14 +1241,15 @@ static void gl124_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens dev->total_bytes_read = 0; if (session.params.depth == 1) { - dev->total_bytes_to_read = ((dev->settings.pixels * dev->settings.lines) / 8 + - (((dev->settings.pixels * dev->settings.lines) % 8) ? 1 : 0)) * session.params.channels; + dev->total_bytes_to_read = ((session.params.get_requested_pixels() * dev->settings.lines) / 8 + + (((session.params.get_requested_pixels() * dev->settings.lines) % 8) ? 1 : 0)) * session.params.channels; } else { - dev->total_bytes_to_read = dev->settings.pixels * dev->settings.lines * + dev->total_bytes_to_read = session.params.get_requested_pixels() * dev->settings.lines * session.params.channels * (session.params.depth / 8); } - DBG(DBG_info, "%s: total bytes to send = %lu\n", __func__, (u_long) dev->total_bytes_to_read); + DBG(DBG_info, "%s: total bytes to send to frontend = %lu\n", __func__, + (u_long) dev->total_bytes_to_read); } static void @@ -1280,6 +1281,7 @@ gl124_calculate_current_setup (Genesys_Device * dev, const Genesys_Sensor& senso session.params.startx = start; session.params.starty = 0; // not used session.params.pixels = dev->settings.pixels; + session.params.requested_pixels = dev->settings.requested_pixels; session.params.lines = dev->settings.lines; session.params.depth = dev->settings.get_depth(); session.params.channels = dev->settings.get_channels(); @@ -2012,6 +2014,7 @@ static void gl124_init_regs_for_scan(Genesys_Device* dev, const Genesys_Sensor& session.params.startx = start; session.params.starty = move; session.params.pixels = dev->settings.pixels; + session.params.requested_pixels = dev->settings.requested_pixels; session.params.lines = dev->settings.lines; session.params.depth = dev->settings.get_depth(); session.params.channels = dev->settings.get_channels(); diff --git a/backend/genesys_gl646.cc b/backend/genesys_gl646.cc index a66a338f7..535976050 100644 --- a/backend/genesys_gl646.cc +++ b/backend/genesys_gl646.cc @@ -816,6 +816,7 @@ static void gl646_setup_registers(Genesys_Device* dev, */ dev->total_bytes_read = 0; if (session.params.depth == 1) { + // BUG: should use settings.requested_pixels dev->total_bytes_to_read = ((session.params.pixels * session.params.lines) / 8 + (((session.params.pixels * session.params.lines) % 8) ? 1 : 0)) * session.params.channels; } else { diff --git a/backend/genesys_gl841.cc b/backend/genesys_gl841.cc index b1ebd88a8..1be786944 100644 --- a/backend/genesys_gl841.cc +++ b/backend/genesys_gl841.cc @@ -2016,11 +2016,11 @@ dummy \ scanned lines dev->total_bytes_read = 0; if (session.params.depth == 1) { - dev->total_bytes_to_read = ((dev->settings.pixels * dev->settings.lines) / 8 + - (((dev->settings.pixels * dev->settings.lines)%8)?1:0)) * session.params.channels; + dev->total_bytes_to_read = ((session.params.get_requested_pixels() * dev->settings.lines) / 8 + + (((session.params.get_requested_pixels() * dev->settings.lines)%8)?1:0)) * session.params.channels; } else { dev->total_bytes_to_read = - dev->settings.pixels * dev->settings.lines * session.params.channels * (session.params.depth / 8); + session.params.get_requested_pixels() * dev->settings.lines * session.params.channels * (session.params.depth / 8); } DBG(DBG_info, "%s: total bytes to send = %lu\n", __func__, (u_long) dev->total_bytes_to_read); @@ -2059,6 +2059,7 @@ static void gl841_calculate_current_setup(Genesys_Device * dev, const Genesys_Se session.params.startx = start; session.params.starty = 0; // not used session.params.pixels = dev->settings.pixels; + session.params.requested_pixels = dev->settings.requested_pixels; session.params.lines = dev->settings.lines; session.params.depth = dev->settings.get_depth(); session.params.channels = dev->settings.get_channels(); @@ -3109,6 +3110,7 @@ static void gl841_init_regs_for_scan(Genesys_Device* dev, const Genesys_Sensor& session.params.startx = start; session.params.starty = move; session.params.pixels = dev->settings.pixels; + session.params.requested_pixels = dev->settings.requested_pixels; session.params.lines = dev->settings.lines; session.params.depth = dev->settings.get_depth(); session.params.channels = dev->settings.get_channels(); diff --git a/backend/genesys_gl843.cc b/backend/genesys_gl843.cc index a78aa5c0b..7fc81128f 100644 --- a/backend/genesys_gl843.cc +++ b/backend/genesys_gl843.cc @@ -1386,11 +1386,11 @@ static void gl843_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens dev->total_bytes_read = 0; if (session.params.depth == 1) { - dev->total_bytes_to_read = ((session.params.pixels * session.params.lines) / 8 + - (((session.params.pixels * session.params.lines) % 8) ? 1 : 0)) * + dev->total_bytes_to_read = ((session.params.get_requested_pixels() * session.params.lines) / 8 + + (((session.params.get_requested_pixels() * session.params.lines) % 8) ? 1 : 0)) * session.params.channels; } else { - dev->total_bytes_to_read = session.params.pixels * session.params.lines * + dev->total_bytes_to_read = session.params.get_requested_pixels() * session.params.lines * session.params.channels * (session.params.depth / 8); } @@ -1440,6 +1440,7 @@ gl843_calculate_current_setup(Genesys_Device * dev, const Genesys_Sensor& sensor session.params.startx = start; // not used session.params.starty = 0; // not used session.params.pixels = dev->settings.pixels; + session.params.requested_pixels = dev->settings.requested_pixels; session.params.lines = dev->settings.lines; session.params.depth = dev->settings.get_depth(); session.params.channels = dev->settings.get_channels(); @@ -2556,6 +2557,7 @@ static void gl843_init_regs_for_scan(Genesys_Device* dev, const Genesys_Sensor& session.params.startx = start; session.params.starty = move; session.params.pixels = dev->settings.pixels; + session.params.requested_pixels = dev->settings.requested_pixels; session.params.lines = dev->settings.lines; session.params.depth = dev->settings.get_depth(); session.params.channels = dev->settings.get_channels(); diff --git a/backend/genesys_gl846.cc b/backend/genesys_gl846.cc index c395659ee..686b25eaa 100644 --- a/backend/genesys_gl846.cc +++ b/backend/genesys_gl846.cc @@ -1121,11 +1121,11 @@ static void gl846_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens dev->total_bytes_read = 0; if (session.params.depth == 1) { - dev->total_bytes_to_read = ((session.params.pixels * session.params.lines) / 8 + - (((session.params.pixels * session.params.lines) % 8) ? 1 : 0)) * + dev->total_bytes_to_read = ((session.params.get_requested_pixels() * session.params.lines) / 8 + + (((session.params.get_requested_pixels() * session.params.lines) % 8) ? 1 : 0)) * session.params.channels; } else { - dev->total_bytes_to_read = session.params.pixels * session.params.lines * session.params.channels * (session.params.depth / 8); + dev->total_bytes_to_read = session.params.get_requested_pixels() * session.params.lines * session.params.channels * (session.params.depth / 8); } DBG(DBG_info, "%s: total bytes to send = %lu\n", __func__, (u_long) dev->total_bytes_to_read); @@ -1163,6 +1163,7 @@ gl846_calculate_current_setup(Genesys_Device * dev, const Genesys_Sensor& sensor session.params.startx = start; // not used session.params.starty = 0; // not used session.params.pixels = dev->settings.pixels; + session.params.requested_pixels = dev->settings.requested_pixels; session.params.lines = dev->settings.lines; session.params.depth = dev->settings.get_depth(); session.params.channels = dev->settings.get_channels(); @@ -1781,6 +1782,7 @@ static void gl846_init_regs_for_scan(Genesys_Device* dev, const Genesys_Sensor& session.params.startx = start; session.params.starty = move; session.params.pixels = dev->settings.pixels; + session.params.requested_pixels = dev->settings.requested_pixels; session.params.lines = dev->settings.lines; session.params.depth = dev->settings.get_depth(); session.params.channels = dev->settings.get_channels(); diff --git a/backend/genesys_gl847.cc b/backend/genesys_gl847.cc index 35e313fca..e74eb7d35 100644 --- a/backend/genesys_gl847.cc +++ b/backend/genesys_gl847.cc @@ -1136,10 +1136,10 @@ static void gl847_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens dev->total_bytes_read = 0; if (session.params.depth == 1) { - dev->total_bytes_to_read = ((session.params.pixels * session.params.lines) / 8 + - (((session.params.pixels * session.params.lines) % 8) ? 1 : 0)) * session.params.channels; + dev->total_bytes_to_read = ((session.params.get_requested_pixels() * session.params.lines) / 8 + + (((session.params.get_requested_pixels() * session.params.lines) % 8) ? 1 : 0)) * session.params.channels; } else { - dev->total_bytes_to_read = session.params.pixels * session.params.lines * session.params.channels * (session.params.depth / 8); + dev->total_bytes_to_read = session.params.get_requested_pixels() * session.params.lines * session.params.channels * (session.params.depth / 8); } DBG(DBG_info, "%s: total bytes to send = %lu\n", __func__, (u_long) dev->total_bytes_to_read); @@ -1177,6 +1177,7 @@ gl847_calculate_current_setup(Genesys_Device * dev, const Genesys_Sensor& sensor session.params.startx = start; // not used session.params.starty = 0; // not used session.params.pixels = dev->settings.pixels; + session.params.requested_pixels = dev->settings.requested_pixels; session.params.lines = dev->settings.lines; session.params.depth = dev->settings.get_depth(); session.params.channels = dev->settings.get_channels(); @@ -1834,6 +1835,7 @@ static void gl847_init_regs_for_scan(Genesys_Device* dev, const Genesys_Sensor& session.params.startx = start; session.params.starty = move; session.params.pixels = dev->settings.pixels; + session.params.requested_pixels = dev->settings.requested_pixels; session.params.lines = dev->settings.lines; session.params.depth = dev->settings.get_depth(); session.params.channels = dev->settings.get_channels(); diff --git a/backend/genesys_low.cc b/backend/genesys_low.cc index cb43160b8..65c2f737a 100644 --- a/backend/genesys_low.cc +++ b/backend/genesys_low.cc @@ -1744,11 +1744,12 @@ void debug_dump(unsigned level, const Genesys_Settings& settings) "Resolution X/Y : %u / %u dpi\n" "Lines : %u\n" "Pixels per line : %u\n" + "Pixels per line (requested) : %u\n" "Depth : %u\n" "Start position X/Y : %.3f/%.3f\n" "Scan mode : %d\n\n", settings.xres, settings.yres, - settings.lines, settings.pixels, settings.depth, + settings.lines, settings.pixels, settings.requested_pixels, settings.depth, settings.tl_x, settings.tl_y, static_cast(settings.scan_mode)); } @@ -1759,6 +1760,7 @@ void debug_dump(unsigned level, const SetupParams& params) "Resolution X/Y : %u / %u dpi\n" "Lines : %u\n" "Pixels per line : %u\n" + "Pixels per line (requested) : %u\n" "Depth : %u\n" "Channels : %u\n" "Start position X/Y : %g / %g\n" @@ -1766,7 +1768,7 @@ void debug_dump(unsigned level, const SetupParams& params) "Color filter : %d\n" "Flags : %x\n", params.xres, params.yres, - params.lines, params.pixels, + params.lines, params.pixels, params.requested_pixels, params.depth, params.channels, params.startx, params.starty, static_cast(params.scan_mode), diff --git a/backend/genesys_settings.h b/backend/genesys_settings.h index 6a391ecf2..c0e898307 100644 --- a/backend/genesys_settings.h +++ b/backend/genesys_settings.h @@ -66,6 +66,8 @@ struct Genesys_Settings unsigned int lines = 0; // number of pixels at scan resolution unsigned int pixels = 0; + // number of pixels expected by the frontend + unsigned requested_pixels = 0; // bit depth of the scan unsigned int depth = 0; @@ -127,6 +129,10 @@ struct SetupParams { // the number of pixels in X direction. Note that each logical pixel may correspond to more // than one CCD pixel, see CKSEL and GenesysSensor::ccd_pixels_per_system_pixel() unsigned pixels = NOT_SET; + + // the number of pixels in the X direction as requested by the frontend. + unsigned requested_pixels = 0; + // the number of pixels in Y direction unsigned lines = NOT_SET; // the depth of the scan in bits. Allowed are 1, 8, 16 @@ -142,6 +148,14 @@ struct SetupParams { unsigned flags = NOT_SET; + unsigned get_requested_pixels() const + { + if (requested_pixels != 0) { + return requested_pixels; + } + return pixels; + } + void assert_valid() const { if (xres == NOT_SET || yres == NOT_SET || startx < 0 || starty < 0 || @@ -162,6 +176,7 @@ struct SetupParams { startx == other.startx && starty == other.starty && pixels == other.pixels && + requested_pixels == other.requested_pixels && lines == other.lines && depth == other.depth && channels == other.channels && @@ -180,6 +195,7 @@ void serialize(Stream& str, SetupParams& x) serialize(str, x.startx); serialize(str, x.starty); serialize(str, x.pixels); + serialize(str, x.requested_pixels); serialize(str, x.lines); serialize(str, x.depth); serialize(str, x.channels);