genesys: Don't modify sensor in *_led_calibration()

merge-requests/137/head
Povilas Kanapickas 2019-08-17 11:05:35 +03:00
rodzic 6e950209b6
commit f019f9e7b8
8 zmienionych plików z 51 dodań i 57 usunięć

Wyświetl plik

@ -2866,8 +2866,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)

Wyświetl plik

@ -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] };
}
/**

Wyświetl plik

@ -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;
}
/**

Wyświetl plik

@ -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, &regs, SANE_TRUE);
gl841_begin_scan(dev, calib_sensor, &regs, 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

Wyświetl plik

@ -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;
}

Wyświetl plik

@ -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] };
}
/**

Wyświetl plik

@ -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] };
}
/**

Wyświetl plik

@ -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);