From 21f949bd8736ecffe0ed0ad1409bbe01d882d148 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Sat, 24 Aug 2019 10:00:50 +0300 Subject: [PATCH 1/3] genesys: Remove *_compute_exposure() wrappers --- backend/genesys_gl124.cc | 20 +++++--------------- backend/genesys_gl846.cc | 13 ++----------- backend/genesys_gl847.cc | 13 ++----------- 3 files changed, 9 insertions(+), 37 deletions(-) diff --git a/backend/genesys_gl124.cc b/backend/genesys_gl124.cc index 919d18361..43d5f7c9e 100644 --- a/backend/genesys_gl124.cc +++ b/backend/genesys_gl124.cc @@ -557,19 +557,6 @@ static void gl124_set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, uint } } - -/**@brief compute exposure to use - * compute the sensor exposure based on target resolution - * @param dev pointer to device description - * @param xres sensor's required resolution - * @param ccd_size_divisor how many CCD pixels are processed for output pixel - */ -static int gl124_compute_exposure(const Genesys_Sensor& sensor, int xres, unsigned ccd_size_divisor) -{ - return get_sensor_profile(sensor, xres, ccd_size_divisor).exposure_lperiod; -} - - static void gl124_init_motor_regs_scan(Genesys_Device* dev, const Genesys_Sensor& sensor, Genesys_Register_Set* reg, @@ -1152,7 +1139,8 @@ static void gl124_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens } else { - exposure_time = gl124_compute_exposure(sensor, used_res, session.ccd_size_divisor); + exposure_time = get_sensor_profile(sensor, used_res, + session.ccd_size_divisor).exposure_lperiod; scan_step_type = sanei_genesys_compute_step_type(gl124_motor_profiles, dev->model->motor_type, exposure_time); } @@ -1311,7 +1299,9 @@ gl124_calculate_current_setup (Genesys_Device * dev, const Genesys_Sensor& senso used_pixels = (session.params.pixels * optical_res) / session.params.xres; DBG (DBG_info, "%s: used_pixels=%d\n", __func__, used_pixels); - exposure_time = gl124_compute_exposure(sensor, session.params.xres, session.ccd_size_divisor); + exposure_time = get_sensor_profile(sensor, session.params.xres, + session.ccd_size_divisor).exposure_lperiod; + DBG (DBG_info, "%s : exposure_time=%d pixels\n", __func__, exposure_time); max_shift = sanei_genesys_compute_max_shift(dev, session.params.channels, diff --git a/backend/genesys_gl846.cc b/backend/genesys_gl846.cc index 686b25eaa..7a148d6cd 100644 --- a/backend/genesys_gl846.cc +++ b/backend/genesys_gl846.cc @@ -183,15 +183,6 @@ static const SensorProfile& get_sensor_profile(const Genesys_Sensor& sensor, uns return sensor.sensor_profiles[best_i]; } -/**@brief compute exposure to use - * compute the sensor exposure based on target resolution - */ -static unsigned gl846_compute_exposure(const Genesys_Sensor& sensor, unsigned xres) -{ - return get_sensor_profile(sensor, xres).exposure_lperiod; -} - - /** @brief sensor specific settings */ static void gl846_setup_sensor(Genesys_Device * dev, const Genesys_Sensor& sensor, @@ -1022,7 +1013,7 @@ static void gl846_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens slope_dpi = slope_dpi * (1 + dummy); - exposure_time = gl846_compute_exposure(sensor, used_res); + exposure_time = get_sensor_profile(sensor, used_res).exposure_lperiod; scan_step_type = sanei_genesys_compute_step_type(gl846_motor_profiles, dev->model->motor_type, exposure_time); @@ -1208,7 +1199,7 @@ gl846_calculate_current_setup(Genesys_Device * dev, const Genesys_Sensor& sensor slope_dpi = slope_dpi * (1 + dummy); - exposure_time = gl846_compute_exposure(sensor, used_res); + exposure_time = get_sensor_profile(sensor, used_res).exposure_lperiod; DBG(DBG_info, "%s : exposure_time=%d pixels\n", __func__, exposure_time); max_shift = sanei_genesys_compute_max_shift(dev, session.params.channels, session.params.yres, 0); diff --git a/backend/genesys_gl847.cc b/backend/genesys_gl847.cc index e74eb7d35..9eeb89d1f 100644 --- a/backend/genesys_gl847.cc +++ b/backend/genesys_gl847.cc @@ -178,15 +178,6 @@ static const SensorProfile& get_sensor_profile(const Genesys_Sensor& sensor, uns return sensor.sensor_profiles[best_i]; } -/**@brief compute exposure to use - * compute the sensor exposure based on target resolution - */ -static int gl847_compute_exposure(const Genesys_Sensor& sensor, unsigned xres) -{ - return get_sensor_profile(sensor, xres).exposure_lperiod; -} - - /** @brief sensor specific settings */ static void gl847_setup_sensor(Genesys_Device * dev, const Genesys_Sensor& sensor, @@ -1039,7 +1030,7 @@ static void gl847_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens slope_dpi = slope_dpi * (1 + dummy); - exposure_time = gl847_compute_exposure(sensor, used_res); + exposure_time = get_sensor_profile(sensor, used_res).exposure_lperiod; scan_step_type = sanei_genesys_compute_step_type(gl847_motor_profiles, dev->model->motor_type, exposure_time); @@ -1225,7 +1216,7 @@ gl847_calculate_current_setup(Genesys_Device * dev, const Genesys_Sensor& sensor slope_dpi = slope_dpi * (1 + dummy); - exposure_time = gl847_compute_exposure(sensor, used_res); + exposure_time = get_sensor_profile(sensor, used_res).exposure_lperiod; DBG(DBG_info, "%s : exposure_time=%d pixels\n", __func__, exposure_time); max_shift = sanei_genesys_compute_max_shift(dev, session.params.channels, session.params.yres, 0); From 9a21a8335fadc7f5722b85dc0172ee24f221b3b1 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Sat, 24 Aug 2019 10:00:51 +0300 Subject: [PATCH 2/3] genesys: Remove dead code related to SCAN_FLAG_USE_OPTICAL_RES --- backend/genesys_gl124.cc | 16 +--------------- backend/genesys_gl846.cc | 10 +--------- backend/genesys_gl847.cc | 9 +-------- 3 files changed, 3 insertions(+), 32 deletions(-) diff --git a/backend/genesys_gl124.cc b/backend/genesys_gl124.cc index 43d5f7c9e..ce96c2ed4 100644 --- a/backend/genesys_gl124.cc +++ b/backend/genesys_gl124.cc @@ -1062,7 +1062,6 @@ static void gl124_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens DBG_HELPER(dbg); session.assert_computed(); - int used_res; int start, used_pixels; int bytes_per_line; int move; @@ -1089,20 +1088,7 @@ static void gl124_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens } DBG (DBG_info, "gl124_init_scan_regs : stagger=%d lines\n", stagger); - /** @brief compute used resolution */ - if (session.params.flags & SCAN_FLAG_USE_OPTICAL_RES) { - used_res = session.optical_resolution; - } - else - { - // resolution is choosen from a fixed list and can be used directly, unless we have ydpi - // higher than sensor's maximum one */ - if (session.params.xres > session.optical_resolution) { - used_res = session.optical_resolution; - } else { - used_res = session.params.xres; - } - } + unsigned used_res = session.params.xres; /* compute scan parameters values */ /* pixels are allways given at full optical resolution */ diff --git a/backend/genesys_gl846.cc b/backend/genesys_gl846.cc index 7a148d6cd..03784d717 100644 --- a/backend/genesys_gl846.cc +++ b/backend/genesys_gl846.cc @@ -947,7 +947,6 @@ static void gl846_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens DBG_HELPER(dbg); session.assert_computed(); - int used_res; int start, used_pixels; int bytes_per_line; int move; @@ -972,14 +971,7 @@ static void gl846_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens } DBG(DBG_info, "%s : stagger=%d lines\n", __func__, stagger); - if (session.params.flags & SCAN_FLAG_USE_OPTICAL_RES) { - used_res = session.optical_resolution; - } - else - { - /* resolution is choosen from a list */ - used_res = session.params.xres; - } + unsigned used_res = session.params.xres; /* compute scan parameters values */ /* pixels are allways given at full optical resolution */ diff --git a/backend/genesys_gl847.cc b/backend/genesys_gl847.cc index 9eeb89d1f..d423622a4 100644 --- a/backend/genesys_gl847.cc +++ b/backend/genesys_gl847.cc @@ -966,7 +966,6 @@ static void gl847_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens DBG_HELPER(dbg); session.assert_computed(); - int used_res; int start, used_pixels; int bytes_per_line; int move; @@ -991,13 +990,7 @@ static void gl847_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens } DBG(DBG_info, "%s : stagger=%d lines\n", __func__, stagger); - /* used_res */ - if (session.params.flags & SCAN_FLAG_USE_OPTICAL_RES) { - used_res = session.optical_resolution; - } else { - /* resolution is choosen from a list */ - used_res = session.params.xres; - } + unsigned used_res = session.params.xres; /* compute scan parameters values */ /* pixels are allways given at full optical resolution */ From ec5225e1f8a165fd50786459383b16f5c0c39524 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Sat, 24 Aug 2019 10:00:52 +0300 Subject: [PATCH 3/3] genesys: Assume correct resolution is passed from high-level --- backend/genesys_gl124.cc | 6 +--- backend/genesys_gl646.cc | 8 ++--- backend/genesys_gl841.cc | 70 +++++++++++----------------------------- backend/genesys_gl843.cc | 7 +--- backend/genesys_low.cc | 9 ++---- 5 files changed, 25 insertions(+), 75 deletions(-) diff --git a/backend/genesys_gl124.cc b/backend/genesys_gl124.cc index ce96c2ed4..eeea8881a 100644 --- a/backend/genesys_gl124.cc +++ b/backend/genesys_gl124.cc @@ -1272,11 +1272,7 @@ gl124_calculate_current_setup (Genesys_Device * dev, const Genesys_Sensor& senso /* optical_res */ optical_res = sensor.optical_res; - if (session.params.xres <= (unsigned) optical_res) { - used_res = session.params.xres; - } else { - used_res = optical_res; - } + used_res = session.params.xres; /* compute scan parameters values */ /* pixels are allways given at half or full CCD optical resolution */ diff --git a/backend/genesys_gl646.cc b/backend/genesys_gl646.cc index 535976050..c578c1ced 100644 --- a/backend/genesys_gl646.cc +++ b/backend/genesys_gl646.cc @@ -2830,6 +2830,8 @@ static void gl646_coarse_gain_calibration(Genesys_Device* dev, const Genesys_Sen Genesys_Register_Set& regs, int dpi) { DBG_HELPER(dbg); + (void) dpi; + unsigned int i, j, k, channels, val, maximum, idx; unsigned int count, resolution, pass; float average[3]; @@ -2846,11 +2848,7 @@ static void gl646_coarse_gain_calibration(Genesys_Device* dev, const Genesys_Sen channels = 3; /* we are searching a sensor resolution */ - if (dpi > sensor.optical_res) { - resolution = sensor.optical_res; - } else { - resolution = get_closest_resolution(dev->model->ccd_type, dev->settings.xres, channels); - } + resolution = get_closest_resolution(dev->model->ccd_type, dev->settings.xres, channels); const auto& calib_sensor = sanei_genesys_find_sensor(dev, resolution, channels, ScanMethod::FLATBED); diff --git a/backend/genesys_gl841.cc b/backend/genesys_gl841.cc index 1be786944..c2966627a 100644 --- a/backend/genesys_gl841.cc +++ b/backend/genesys_gl841.cc @@ -1740,6 +1740,17 @@ static void gl841_compute_session(Genesys_Device* dev, ScanSession& s, s.computed = true; } +static void gl841_assert_supported_resolution(const ScanSession& session) +{ + for (unsigned factor : {1, 2, 3, 4, 5, 6, 8, 10, 12, 15}) { + if (session.output_resolution == session.optical_resolution / factor) { + return; + } + } + throw SaneException("Unsupported resolution %d for optical resolution %d", + session.output_resolution, session.optical_resolution); +} + // set up registers for an actual scan this function sets up the scanner to scan in normal or single // line mode static void gl841_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sensor, @@ -1754,7 +1765,6 @@ static void gl841_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens int move; unsigned int lincnt; int exposure_time; - int i; int stagger; int avg; @@ -1803,32 +1813,12 @@ independent of our calculated values: } DBG(DBG_info, "%s : stagger=%d lines\n", __func__, stagger); -/* used_res */ - i = session.optical_resolution / session.params.xres; - -/* gl841 supports 1/1 1/2 1/3 1/4 1/5 1/6 1/8 1/10 1/12 1/15 averaging */ - - if (i < 2 || (session.params.flags & SCAN_FLAG_USE_OPTICAL_RES)) { - // optical_res >= xres > optical_res/2 + if (session.params.flags & SCAN_FLAG_USE_OPTICAL_RES) { used_res = session.optical_resolution; - } else if (i < 3) /* optical_res/2 >= xres > optical_res/3 */ - used_res = session.optical_resolution/2; - else if (i < 4) /* optical_res/3 >= xres > optical_res/4 */ - used_res = session.optical_resolution/3; - else if (i < 5) /* optical_res/4 >= xres > optical_res/5 */ - used_res = session.optical_resolution/4; - else if (i < 6) /* optical_res/5 >= xres > optical_res/6 */ - used_res = session.optical_resolution/5; - else if (i < 8) /* optical_res/6 >= xres > optical_res/8 */ - used_res = session.optical_resolution/6; - else if (i < 10) /* optical_res/8 >= xres > optical_res/10 */ - used_res = session.optical_resolution/8; - else if (i < 12) /* optical_res/10 >= xres > optical_res/12 */ - used_res = session.optical_resolution/10; - else if (i < 15) /* optical_res/12 >= xres > optical_res/15 */ - used_res = session.optical_resolution/12; - else - used_res = session.optical_resolution/15; + } else { + used_res = session.params.xres; + } + gl841_assert_supported_resolution(session); /* compute scan parameters values */ /* pixels are allways given at half or full CCD optical resolution */ @@ -2035,7 +2025,6 @@ static void gl841_calculate_current_setup(Genesys_Device * dev, const Genesys_Se int used_pixels; unsigned int lincnt; int exposure_time; - int i; int stagger; int slope_dpi = 0; @@ -2082,31 +2071,8 @@ static void gl841_calculate_current_setup(Genesys_Device * dev, const Genesys_Se } DBG(DBG_info, "%s: stagger=%d lines\n", __func__, stagger); -/* used_res */ - i = session.optical_resolution / session.params.xres; - -/* gl841 supports 1/1 1/2 1/3 1/4 1/5 1/6 1/8 1/10 1/12 1/15 averaging */ - - if (i < 2) /* optical_res >= xres > optical_res/2 */ - used_res = session.optical_resolution; - else if (i < 3) /* optical_res/2 >= xres > optical_res/3 */ - used_res = session.optical_resolution / 2; - else if (i < 4) /* optical_res/3 >= xres > optical_res/4 */ - used_res = session.optical_resolution / 3; - else if (i < 5) /* optical_res/4 >= xres > optical_res/5 */ - used_res = session.optical_resolution / 4; - else if (i < 6) /* optical_res/5 >= xres > optical_res/6 */ - used_res = session.optical_resolution / 5; - else if (i < 8) /* optical_res/6 >= xres > optical_res/8 */ - used_res = session.optical_resolution / 6; - else if (i < 10) /* optical_res/8 >= xres > optical_res/10 */ - used_res = session.optical_resolution / 8; - else if (i < 12) /* optical_res/10 >= xres > optical_res/12 */ - used_res = session.optical_resolution / 10; - else if (i < 15) /* optical_res/12 >= xres > optical_res/15 */ - used_res = session.optical_resolution / 12; - else - used_res = session.optical_resolution / 15; + used_res = session.params.xres; + gl841_assert_supported_resolution(session); /* compute scan parameters values */ /* pixels are allways given at half or full CCD optical resolution */ diff --git a/backend/genesys_gl843.cc b/backend/genesys_gl843.cc index 7fc81128f..c204085d9 100644 --- a/backend/genesys_gl843.cc +++ b/backend/genesys_gl843.cc @@ -1402,7 +1402,6 @@ gl843_calculate_current_setup(Genesys_Device * dev, const Genesys_Sensor& sensor { int start; - int used_res; int used_pixels; unsigned int lincnt; int exposure; @@ -1462,11 +1461,7 @@ gl843_calculate_current_setup(Genesys_Device * dev, const Genesys_Sensor& sensor } DBG(DBG_info, "%s: stagger=%d lines\n", __func__, stagger); - if (session.params.xres <= (unsigned) session.optical_resolution) { - used_res = session.params.xres; - } else { - used_res = session.optical_resolution; - } + int used_res = session.params.xres; /* compute scan parameters values */ /* pixels are allways given at half or full CCD optical resolution */ diff --git a/backend/genesys_low.cc b/backend/genesys_low.cc index 65c2f737a..17fce1dad 100644 --- a/backend/genesys_low.cc +++ b/backend/genesys_low.cc @@ -1510,7 +1510,7 @@ bool sanei_genesys_is_compatible_calibration(Genesys_Device * dev, const Genesys #ifdef HAVE_SYS_TIME_H struct timeval time; #endif - int compatible = 1, resolution; + int compatible = 1; if(dev->cmd_set->calculate_current_setup == nullptr) { DBG (DBG_proc, "%s: no calculate_setup, non compatible cache\n", __func__); @@ -1525,12 +1525,7 @@ bool sanei_genesys_is_compatible_calibration(Genesys_Device * dev, const Genesys * requested scan. In the case of CIS scanners, dpi isn't a criteria */ if (dev->model->is_cis == SANE_FALSE) { - resolution = dev->settings.xres; - if(resolution>sensor.optical_res) - { - resolution=sensor.optical_res; - } - compatible = (resolution == ((int) cache->used_setup.xres)); + compatible = (dev->settings.xres == ((int) cache->used_setup.xres)); } else {