diff --git a/backend/genesys.cc b/backend/genesys.cc index 6cbe7369b..cb02a5a65 100644 --- a/backend/genesys.cc +++ b/backend/genesys.cc @@ -182,16 +182,6 @@ static const SANE_Range expiration_range = { 1 /* quantization */ }; -Genesys_Sensor& sanei_genesys_find_sensor_any_for_write(Genesys_Device* dev) -{ - for (auto& sensor : *s_sensors) { - if (dev->model->ccd_type == sensor.sensor_id) { - return sensor; - } - } - throw std::runtime_error("Given device does not have sensor defined"); -} - const Genesys_Sensor& sanei_genesys_find_sensor_any(Genesys_Device* dev) { for (const auto& sensor : *s_sensors) { @@ -2864,8 +2854,8 @@ static void genesys_flatbed_calibration(Genesys_Device* dev, Genesys_Sensor& sen if (dev->model->is_cis) { /* the afe now sends valid data for doing led calibration */ - sanei_usb_testing_record_message("led_calibration"); - dev->cmd_set->led_calibration(dev, sensor, dev->calib_reg); + sanei_usb_testing_record_message("led_calibration"); + sensor.exposure = dev->cmd_set->led_calibration(dev, sensor, dev->calib_reg); /* calibrate afe again to match new exposure */ if (dev->model->flags & GENESYS_FLAG_OFFSET_CALIBRATION) @@ -5650,8 +5640,8 @@ get_option_value (Genesys_Scanner * s, int option, void *val) unsigned option_size = 0; SANE_Status status = SANE_STATUS_GOOD; - // FIXME: we should pick correct sensor here - const Genesys_Sensor& sensor = sanei_genesys_find_sensor_any(s->dev); + const Genesys_Sensor& sensor = sanei_genesys_find_sensor(s->dev, s->resolution, + s->dev->settings.scan_method); switch (option) { @@ -5862,9 +5852,6 @@ set_option_value (Genesys_Scanner * s, int option, void *val, SANE_Range *x_range, *y_range; unsigned option_size = 0; - // FIXME: we should modify device-specific sensor - auto& sensor = sanei_genesys_find_sensor_any_for_write(s->dev); - switch (option) { case OPT_TL_X: @@ -6182,6 +6169,8 @@ set_option_value (Genesys_Scanner * s, int option, void *val, } break; case OPT_CALIBRATE: { + auto& sensor = sanei_genesys_find_sensor_for_write(s->dev, s->resolution, + s->dev->settings.scan_method); catch_all_exceptions(__func__, [&]() { s->dev->cmd_set->save_power(s->dev, SANE_FALSE); diff --git a/backend/genesys_gl124.cc b/backend/genesys_gl124.cc index b8d7f0f97..a99b20d70 100644 --- a/backend/genesys_gl124.cc +++ b/backend/genesys_gl124.cc @@ -1813,9 +1813,9 @@ static void gl124_search_start_position(Genesys_Device* dev) /* sets for a 200 lines * 600 pixels */ /* normal scan with no shading */ - // FIXME: the current approach of doing search only for one resolution does not work on scanners - // whith employ different sensors with potentially different settings. - auto& sensor = sanei_genesys_find_sensor_for_write(dev, dpi, ScanMethod::FLATBED); + // FIXME: the current approach of doing search only for one resolution does not work on scanners + // whith employ different sensors with potentially different settings. + const auto& sensor = sanei_genesys_find_sensor(dev, dpi, ScanMethod::FLATBED); ScanSession session; session.params.xres = dpi; @@ -2250,8 +2250,8 @@ static void move_to_calibration_area(Genesys_Device* dev, const Genesys_Sensor& -needs working coarse/gain */ -static void gl124_led_calibration(Genesys_Device* dev, Genesys_Sensor& sensor, - Genesys_Register_Set& regs) +static SensorExposure gl124_led_calibration(Genesys_Device* dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs) { DBG_HELPER(dbg); int num_pixels; @@ -2385,10 +2385,7 @@ static void gl124_led_calibration(Genesys_Device* dev, Genesys_Sensor& sensor, dev->reg.set24(REG_EXPG, exp[1]); dev->reg.set24(REG_EXPB, exp[2]); - /* store in this struct since it is the one used by cache calibration */ - sensor.exposure.red = exp[0]; - sensor.exposure.green = exp[1]; - sensor.exposure.blue = exp[2]; + return { exp[0], exp[1], exp[2] }; } /** diff --git a/backend/genesys_gl646.cc b/backend/genesys_gl646.cc index 1229ae874..976cbf053 100644 --- a/backend/genesys_gl646.cc +++ b/backend/genesys_gl646.cc @@ -2110,9 +2110,9 @@ static void gl646_search_start_position(Genesys_Device* dev) /* we scan at 300 dpi */ resolution = get_closest_resolution(dev->model->ccd_type, 300, 1); - // FIXME: the current approach of doing search only for one resolution does not work on scanners - // whith employ different sensors with potentially different settings. - auto& sensor = sanei_genesys_find_sensor_for_write(dev, resolution, ScanMethod::FLATBED); + // FIXME: the current approach of doing search only for one resolution does not work on scanners + // whith employ different sensors with potentially different settings. + const auto& sensor = sanei_genesys_find_sensor(dev, resolution, ScanMethod::FLATBED); /* fill settings for a gray level scan */ settings.scan_method = ScanMethod::FLATBED; @@ -2455,7 +2455,8 @@ static void gl646_send_gamma_table(Genesys_Device* dev, const Genesys_Sensor& se * area below scanner's top on white strip. The scope of this function is * currently limited to the XP200 */ -static void gl646_led_calibration(Genesys_Device* dev, Genesys_Sensor& sensor, Genesys_Register_Set& regs) +static SensorExposure gl646_led_calibration(Genesys_Device* dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs) { DBG_HELPER(dbg); (void) regs; @@ -2471,12 +2472,6 @@ static void gl646_led_calibration(Genesys_Device* dev, Genesys_Sensor& sensor, G SANE_Bool acceptable = SANE_FALSE; - if (!dev->model->is_cis) - { - DBG(DBG_proc, "%s: not a cis scanner, nothing to do...\n", __func__); - return; - } - /* get led calibration resolution */ if (dev->settings.scan_mode == ScanColorMode::COLOR_SINGLE_PASS) { @@ -2526,15 +2521,16 @@ static void gl646_led_calibration(Genesys_Device* dev, Genesys_Sensor& sensor, G turn = 0; - do - { - sensor.exposure.red = expr; - sensor.exposure.green = expg; - sensor.exposure.blue = expb; + auto calib_sensor = sensor; + + do { + calib_sensor.exposure.red = expr; + calib_sensor.exposure.green = expg; + calib_sensor.exposure.blue = expb; DBG(DBG_info, "%s: starting first line reading\n", __func__); - simple_scan(dev, sensor, settings, SANE_FALSE, SANE_TRUE, SANE_FALSE, line); + simple_scan(dev, calib_sensor, settings, SANE_FALSE, SANE_TRUE, SANE_FALSE, line); if (DBG_LEVEL >= DBG_data) { @@ -2597,6 +2593,8 @@ static void gl646_led_calibration(Genesys_Device* dev, Genesys_Sensor& sensor, G while (!acceptable && turn < 100); DBG(DBG_info,"%s: acceptable exposure: 0x%04x,0x%04x,0x%04x\n", __func__, expr, expg, expb); + // BUG: we don't store the result of the last iteration to the sensor + return calib_sensor.exposure; } /** diff --git a/backend/genesys_gl841.cc b/backend/genesys_gl841.cc index 35e26fdc2..20a43e343 100644 --- a/backend/genesys_gl841.cc +++ b/backend/genesys_gl841.cc @@ -2892,9 +2892,9 @@ static void gl841_search_start_position(Genesys_Device* dev) /* sets for a 200 lines * 600 pixels */ /* normal scan with no shading */ - // FIXME: the current approach of doing search only for one resolution does not work on scanners - // whith employ different sensors with potentially different settings. - auto& sensor = sanei_genesys_find_sensor_for_write(dev, dpi, ScanMethod::FLATBED); + // FIXME: the current approach of doing search only for one resolution does not work on scanners + // whith employ different sensors with potentially different settings. + const auto& sensor = sanei_genesys_find_sensor(dev, dpi, ScanMethod::FLATBED); ScanSession session; session.params.xres = dpi; @@ -3195,8 +3195,8 @@ static void gl841_send_gamma_table(Genesys_Device* dev, const Genesys_Sensor& se -needs working coarse/gain */ -static void gl841_led_calibration(Genesys_Device* dev, Genesys_Sensor& sensor, - Genesys_Register_Set& regs) +static SensorExposure gl841_led_calibration(Genesys_Device* dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs) { DBG_HELPER(dbg); int num_pixels; @@ -3274,23 +3274,25 @@ static void gl841_led_calibration(Genesys_Device* dev, Genesys_Sensor& sensor, max_exposure=((exp[0]+exp[1]+exp[2])/3)*2; target=sensor.gain_white_ref*256; - do { - sensor.exposure.red = exp[0]; - sensor.exposure.green = exp[1]; - sensor.exposure.blue = exp[2]; + auto calib_sensor = sensor; - sanei_genesys_set_exposure(regs, sensor.exposure); - dev->write_register(0x10, (sensor.exposure.red >> 8) & 0xff); - dev->write_register(0x11, sensor.exposure.red & 0xff); - dev->write_register(0x12, (sensor.exposure.green >> 8) & 0xff); - dev->write_register(0x13, sensor.exposure.green & 0xff); - dev->write_register(0x14, (sensor.exposure.blue >> 8) & 0xff); - dev->write_register(0x15, sensor.exposure.blue & 0xff); + do { + calib_sensor.exposure.red = exp[0]; + calib_sensor.exposure.green = exp[1]; + calib_sensor.exposure.blue = exp[2]; + + sanei_genesys_set_exposure(regs, calib_sensor.exposure); + dev->write_register(0x10, (calib_sensor.exposure.red >> 8) & 0xff); + dev->write_register(0x11, calib_sensor.exposure.red & 0xff); + dev->write_register(0x12, (calib_sensor.exposure.green >> 8) & 0xff); + dev->write_register(0x13, calib_sensor.exposure.green & 0xff); + dev->write_register(0x14, (calib_sensor.exposure.blue >> 8) & 0xff); + dev->write_register(0x15, calib_sensor.exposure.blue & 0xff); dev->write_registers(regs); DBG(DBG_info, "%s: starting line reading\n", __func__); - gl841_begin_scan(dev, sensor, ®s, SANE_TRUE); + gl841_begin_scan(dev, calib_sensor, ®s, SANE_TRUE); sanei_genesys_read_data_from_scanner(dev, line.data(), total_size); if (DBG_LEVEL >= DBG_data) { @@ -3393,6 +3395,8 @@ static void gl841_led_calibration(Genesys_Device* dev, Genesys_Sensor& sensor, DBG(DBG_info,"%s: acceptable exposure: %d,%d,%d\n", __func__, exp[0], exp[1], exp[2]); gl841_slow_back_home(dev, SANE_TRUE); + + return calib_sensor.exposure; } /** @brief calibration for AD frontend devices diff --git a/backend/genesys_gl843.cc b/backend/genesys_gl843.cc index 1ba121333..fd4a69ef0 100644 --- a/backend/genesys_gl843.cc +++ b/backend/genesys_gl843.cc @@ -2234,7 +2234,7 @@ static void gl843_search_start_position(Genesys_Device* dev) // FIXME: the current approach of doing search only for one resolution does not work on scanners // whith employ different sensors with potentially different settings. - auto& sensor = sanei_genesys_find_sensor_for_write(dev, dpi, ScanMethod::FLATBED); + const auto& sensor = sanei_genesys_find_sensor(dev, dpi, ScanMethod::FLATBED); ScanSession session; session.params.xres = dpi; @@ -2648,8 +2648,8 @@ static void gl843_send_gamma_table(Genesys_Device* dev, const Genesys_Sensor& se -needs working coarse/gain */ -static void gl843_led_calibration(Genesys_Device* dev, Genesys_Sensor& sensor, - Genesys_Register_Set& regs) +static SensorExposure gl843_led_calibration(Genesys_Device* dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs) { DBG_HELPER(dbg); int num_pixels; @@ -2669,8 +2669,9 @@ static void gl843_led_calibration(Genesys_Device* dev, Genesys_Sensor& sensor, depth = 16; used_res = sensor.optical_res; - auto& calib_sensor = sanei_genesys_find_sensor_for_write(dev, used_res, - dev->settings.scan_method); + // take a copy, as we're going to modify exposure + auto calib_sensor = sanei_genesys_find_sensor(dev, used_res, dev->settings.scan_method); + num_pixels = (calib_sensor.sensor_pixels * used_res) / calib_sensor.optical_res; @@ -2810,9 +2811,9 @@ static void gl843_led_calibration(Genesys_Device* dev, Genesys_Sensor& sensor, DBG(DBG_info, "%s: acceptable exposure: %d,%d,%d\n", __func__, expr, expg, expb); - sensor.exposure = calib_sensor.exposure; - gl843_slow_back_home (dev, SANE_TRUE); + + return calib_sensor.exposure; } diff --git a/backend/genesys_gl846.cc b/backend/genesys_gl846.cc index e26207e2b..964684e42 100644 --- a/backend/genesys_gl846.cc +++ b/backend/genesys_gl846.cc @@ -1498,9 +1498,9 @@ static void gl846_search_start_position(Genesys_Device* dev) /* sets for a 200 lines * 600 pixels */ /* normal scan with no shading */ - // FIXME: the current approach of doing search only for one resolution does not work on scanners - // whith employ different sensors with potentially different settings. - auto& sensor = sanei_genesys_find_sensor_for_write(dev, dpi, ScanMethod::FLATBED); + // FIXME: the current approach of doing search only for one resolution does not work on scanners + // whith employ different sensors with potentially different settings. + const auto& sensor = sanei_genesys_find_sensor(dev, dpi, ScanMethod::FLATBED); ScanSession session; session.params.xres = dpi; @@ -1925,8 +1925,8 @@ static void gl846_send_shading_data(Genesys_Device* dev, const Genesys_Sensor& s * data white enough. * @param dev device to calibrate */ -static void gl846_led_calibration(Genesys_Device* dev, Genesys_Sensor& sensor, - Genesys_Register_Set& regs) +static SensorExposure gl846_led_calibration(Genesys_Device* dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs) { DBG_HELPER(dbg); int num_pixels; @@ -2072,16 +2072,13 @@ static void gl846_led_calibration(Genesys_Device* dev, Genesys_Sensor& sensor, dev->reg.set16(REG_EXPG, exp[1]); dev->reg.set16(REG_EXPB, exp[2]); - /* store in this struct since it is the one used by cache calibration */ - sensor.exposure.red = exp[0]; - sensor.exposure.green = exp[1]; - sensor.exposure.blue = exp[2]; - /* go back home */ if(move>20) { gl846_slow_back_home(dev, SANE_TRUE); } + + return { exp[0], exp[1], exp[2] }; } /** diff --git a/backend/genesys_gl847.cc b/backend/genesys_gl847.cc index b159680bd..17283bbae 100644 --- a/backend/genesys_gl847.cc +++ b/backend/genesys_gl847.cc @@ -1555,9 +1555,9 @@ static void gl847_search_start_position(Genesys_Device* dev) /* sets for a 200 lines * 600 pixels */ /* normal scan with no shading */ - // FIXME: the current approach of doing search only for one resolution does not work on scanners - // whith employ different sensors with potentially different settings. - auto& sensor = sanei_genesys_find_sensor_for_write(dev, dpi, ScanMethod::FLATBED); + // FIXME: the current approach of doing search only for one resolution does not work on scanners + // whith employ different sensors with potentially different settings. + const auto& sensor = sanei_genesys_find_sensor(dev, dpi, ScanMethod::FLATBED); ScanSession session; session.params.xres = dpi; @@ -1981,8 +1981,8 @@ static void gl847_send_shading_data(Genesys_Device* dev, const Genesys_Sensor& s * data white enough. * @param dev device to calibrate */ -static void gl847_led_calibration(Genesys_Device* dev, Genesys_Sensor& sensor, - Genesys_Register_Set& regs) +static SensorExposure gl847_led_calibration(Genesys_Device* dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs) { DBG_HELPER(dbg); int num_pixels; @@ -2128,15 +2128,12 @@ static void gl847_led_calibration(Genesys_Device* dev, Genesys_Sensor& sensor, dev->reg.set16(REG_EXPG, exp[1]); dev->reg.set16(REG_EXPB, exp[2]); - /* store in this struct since it is the one used by cache calibration */ - sensor.exposure.red = exp[0]; - sensor.exposure.green = exp[1]; - sensor.exposure.blue = exp[2]; - // go back home if (move>20) { gl847_slow_back_home(dev, SANE_TRUE); } + + return { exp[0], exp[1], exp[2] }; } /** diff --git a/backend/genesys_low.h b/backend/genesys_low.h index b89eeea28..f03115112 100644 --- a/backend/genesys_low.h +++ b/backend/genesys_low.h @@ -265,8 +265,8 @@ struct Genesys_Command_Set Genesys_Register_Set& regs); void (*coarse_gain_calibration) (Genesys_Device* dev, const Genesys_Sensor& sensor, Genesys_Register_Set& regs, int dpi); - void (*led_calibration) (Genesys_Device* dev, Genesys_Sensor& sensor, - Genesys_Register_Set& regs); + SensorExposure (*led_calibration) (Genesys_Device* dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs); void (*wait_for_motor_stop) (Genesys_Device* dev); void (*slow_back_home) (Genesys_Device* dev, SANE_Bool wait_until_home); @@ -427,7 +427,6 @@ extern void sanei_genesys_write_ahb(Genesys_Device* dev, uint32_t addr, uint32_t extern void sanei_genesys_init_structs (Genesys_Device * dev); const Genesys_Sensor& sanei_genesys_find_sensor_any(Genesys_Device* dev); -Genesys_Sensor& sanei_genesys_find_sensor_any_for_write(Genesys_Device* dev); const Genesys_Sensor& sanei_genesys_find_sensor(Genesys_Device* dev, int dpi, ScanMethod scan_method); Genesys_Sensor& sanei_genesys_find_sensor_for_write(Genesys_Device* dev, int dpi,