Merge branch 'genesys-cleanup' into 'master'

genesys: Cleanups

See merge request sane-project/backends!106
merge-requests/107/head
Povilas Kanapickas 2019-08-09 08:45:38 +00:00
commit 239147d4c7
10 zmienionych plików z 150 dodań i 181 usunięć

Wyświetl plik

@ -1573,47 +1573,6 @@ static void genesys_coarse_calibration(Genesys_Device* dev, Genesys_Sensor& sens
dark[i * 3 + 0] = dark[i * 3 + 1] = dark[i * 3 + 2] =
genesys_average_black (dev, 0, calibration_data.data(), black_pixels);
}
if (i == 3)
{
if (dev->settings.scan_mode == ScanColorMode::COLOR_SINGLE_PASS)
{
/* todo: huh? */
dev->dark[0] =
(uint16_t) (1.6925 * dark[i * 3 + 0] + 0.1895 * 256);
dev->dark[1] =
(uint16_t) (1.4013 * dark[i * 3 + 1] + 0.3147 * 256);
dev->dark[2] =
(uint16_t) (1.2931 * dark[i * 3 + 2] + 0.1558 * 256);
}
else /* one color-component modes */
{
switch (dev->settings.color_filter)
{
case ColorFilter::RED:
default:
dev->dark[0] =
(uint16_t) (1.6925 * dark[i * 3 + 0] +
(1.1895 - 1.0) * 256);
dev->dark[1] = dev->dark[2] = dev->dark[0];
break;
case ColorFilter::GREEN:
dev->dark[1] =
(uint16_t) (1.4013 * dark[i * 3 + 1] +
(1.3147 - 1.0) * 256);
dev->dark[0] = dev->dark[2] = dev->dark[1];
break;
case ColorFilter::BLUE:
dev->dark[2] =
(uint16_t) (1.2931 * dark[i * 3 + 2] +
(1.1558 - 1.0) * 256);
dev->dark[0] = dev->dark[1] = dev->dark[2];
break;
}
}
}
} /* for (i = 0; i < 4; i++) */
DBG(DBG_info, "%s: final: gain: %d/%d/%d, offset: %d/%d/%d\n", __func__,

Wyświetl plik

@ -582,6 +582,33 @@ void genesys_init_frontend_tables()
s_frontends->push_back(fe);
}
inline unsigned default_get_logical_hwdpi(const Genesys_Sensor& sensor, unsigned xres)
{
// can't be below 600 dpi
if (xres <= 600) {
return 600;
}
if (xres <= static_cast<unsigned>(sensor.optical_res) / 4) {
return sensor.optical_res / 4;
}
if (xres <= static_cast<unsigned>(sensor.optical_res) / 2) {
return sensor.optical_res / 2;
}
return sensor.optical_res;
}
inline unsigned get_sensor_optical_with_ccd_divisor(const Genesys_Sensor& sensor, unsigned xres)
{
unsigned hwres = sensor.optical_res / sensor.get_ccd_size_divisor_for_dpi(xres);
if (xres <= hwres / 4) {
return hwres / 4;
}
if (xres <= hwres / 2) {
return hwres / 2;
}
return hwres;
}
/** for setting up the sensor-specific settings:
* Optical Resolution, number of black pixels, number of dummy pixels,
@ -632,6 +659,8 @@ void genesys_init_sensor_tables()
{ 0x5e, 0x00 },
};
sensor.gamma = {1.0, 1.0, 1.0};
sensor.get_logical_hwdpi_fun = default_get_logical_hwdpi;
sensor.get_register_hwdpi_fun = default_get_logical_hwdpi;
s_sensors->push_back(sensor);
@ -673,6 +702,8 @@ void genesys_init_sensor_tables()
{ 0x5e, 0x00 },
};
sensor.gamma = {1.0, 1.0, 1.0};
sensor.get_logical_hwdpi_fun = default_get_logical_hwdpi;
sensor.get_register_hwdpi_fun = default_get_logical_hwdpi;
s_sensors->push_back(sensor);
@ -714,6 +745,8 @@ void genesys_init_sensor_tables()
{ 0x5e, 0x00 },
};
sensor.gamma = {1.0, 1.0, 1.0};
sensor.get_logical_hwdpi_fun = default_get_logical_hwdpi;
sensor.get_register_hwdpi_fun = default_get_logical_hwdpi;
s_sensors->push_back(sensor);
@ -756,6 +789,8 @@ void genesys_init_sensor_tables()
{ 0x5e, 0x00 },
};
sensor.gamma = {2.38, 2.35, 2.34};
sensor.get_logical_hwdpi_fun = default_get_logical_hwdpi;
sensor.get_register_hwdpi_fun = default_get_logical_hwdpi;
s_sensors->push_back(sensor);
@ -797,6 +832,8 @@ void genesys_init_sensor_tables()
{ 0x5e, 0x00 },
};
sensor.gamma = {2.1, 2.1, 2.1};
sensor.get_logical_hwdpi_fun = default_get_logical_hwdpi;
sensor.get_register_hwdpi_fun = default_get_logical_hwdpi;
s_sensors->push_back(sensor);
@ -839,6 +876,8 @@ void genesys_init_sensor_tables()
{ 0x5e, 0x16 },
};
sensor.gamma = {2.1, 2.1, 2.1};
sensor.get_logical_hwdpi_fun = default_get_logical_hwdpi;
sensor.get_register_hwdpi_fun = default_get_logical_hwdpi;
s_sensors->push_back(sensor);
@ -881,6 +920,8 @@ void genesys_init_sensor_tables()
{ 0x5e, 0x00 },
};
sensor.gamma = {1.0, 1.0, 1.0};
sensor.get_logical_hwdpi_fun = default_get_logical_hwdpi;
sensor.get_register_hwdpi_fun = default_get_logical_hwdpi;
s_sensors->push_back(sensor);
@ -922,6 +963,8 @@ void genesys_init_sensor_tables()
{ 0x5e, 0x16 },
};
sensor.gamma = {2.1, 2.1, 2.1};
sensor.get_logical_hwdpi_fun = default_get_logical_hwdpi;
sensor.get_register_hwdpi_fun = default_get_logical_hwdpi;
s_sensors->push_back(sensor);
@ -963,6 +1006,8 @@ void genesys_init_sensor_tables()
{ 0x5e, 0x00 },
};
sensor.gamma = {1.0, 1.0, 1.0};
sensor.get_logical_hwdpi_fun = default_get_logical_hwdpi;
sensor.get_register_hwdpi_fun = default_get_logical_hwdpi;
s_sensors->push_back(sensor);
@ -1004,6 +1049,8 @@ void genesys_init_sensor_tables()
{ 0x5e, 0x01 },
};
sensor.gamma = {1.0, 1.0, 1.0};
sensor.get_logical_hwdpi_fun = default_get_logical_hwdpi;
sensor.get_register_hwdpi_fun = default_get_logical_hwdpi;
s_sensors->push_back(sensor);
@ -1045,6 +1092,8 @@ void genesys_init_sensor_tables()
{ 0x5e, 0x01 },
};
sensor.gamma = {1.0, 1.0, 1.0};
sensor.get_logical_hwdpi_fun = default_get_logical_hwdpi;
sensor.get_register_hwdpi_fun = default_get_logical_hwdpi;
s_sensors->push_back(sensor);
@ -1086,6 +1135,8 @@ void genesys_init_sensor_tables()
{ 0x5e, 0x01 },
};
sensor.gamma = {1.0, 1.0, 1.0};
sensor.get_logical_hwdpi_fun = default_get_logical_hwdpi;
sensor.get_register_hwdpi_fun = default_get_logical_hwdpi;
s_sensors->push_back(sensor);
@ -1127,6 +1178,8 @@ void genesys_init_sensor_tables()
{ 0x5e, 0x01 },
};
sensor.gamma = {1.0, 1.0, 1.0};
sensor.get_logical_hwdpi_fun = default_get_logical_hwdpi;
sensor.get_register_hwdpi_fun = default_get_logical_hwdpi;
s_sensors->push_back(sensor);
@ -1168,6 +1221,8 @@ void genesys_init_sensor_tables()
{ 0x5e, 0x01 },
};
sensor.gamma = {1.0, 1.0, 1.0};
sensor.get_logical_hwdpi_fun = default_get_logical_hwdpi;
sensor.get_register_hwdpi_fun = default_get_logical_hwdpi;
s_sensors->push_back(sensor);
@ -1209,6 +1264,8 @@ void genesys_init_sensor_tables()
{ 0x5e, 0x41 },
};
sensor.gamma = {1.7, 1.7, 1.7};
sensor.get_logical_hwdpi_fun = default_get_logical_hwdpi;
sensor.get_register_hwdpi_fun = default_get_logical_hwdpi;
s_sensors->push_back(sensor);
@ -1252,6 +1309,8 @@ void genesys_init_sensor_tables()
{ 0x5e, 0x41 },
};
sensor.gamma = {1.0, 1.0, 1.0};
sensor.get_logical_hwdpi_fun = default_get_logical_hwdpi;
sensor.get_register_hwdpi_fun = default_get_logical_hwdpi;
s_sensors->push_back(sensor);
@ -1293,6 +1352,8 @@ void genesys_init_sensor_tables()
{ 0x5e, 0x41 },
};
sensor.gamma = {1.7, 1.7, 1.7};
sensor.get_logical_hwdpi_fun = default_get_logical_hwdpi;
sensor.get_register_hwdpi_fun = default_get_logical_hwdpi;
s_sensors->push_back(sensor);
@ -1335,6 +1396,8 @@ void genesys_init_sensor_tables()
{ 0x5a, 0xc0 },
};
sensor.gamma = {1.0, 1.0, 1.0};
sensor.get_logical_hwdpi_fun = default_get_logical_hwdpi;
sensor.get_register_hwdpi_fun = default_get_logical_hwdpi;
s_sensors->push_back(sensor);
@ -1351,6 +1414,8 @@ void genesys_init_sensor_tables()
sensor.exposure = { 0x2c09, 0x22b8, 0x10f0 };
sensor.custom_regs = {};
sensor.gamma = {1.0, 1.0, 1.0};
sensor.get_logical_hwdpi_fun = default_get_logical_hwdpi;
sensor.get_register_hwdpi_fun = default_get_logical_hwdpi;
{
struct CustomSensorSettings {
@ -1559,6 +1624,8 @@ void genesys_init_sensor_tables()
{ 0x5a, 0x40 },
};
sensor.gamma = {1.0, 1.0, 1.0};
sensor.get_logical_hwdpi_fun = get_sensor_optical_with_ccd_divisor;
sensor.get_register_hwdpi_fun = [](const Genesys_Sensor&, unsigned) { return 4800; };
s_sensors->push_back(sensor);
@ -1577,6 +1644,9 @@ void genesys_init_sensor_tables()
sensor.exposure = { 0x9c40, 0x9c40, 0x9c40 };
sensor.custom_regs = {};
sensor.gamma = {1.0, 1.0, 1.0};
sensor.get_logical_hwdpi_fun = get_sensor_optical_with_ccd_divisor;
sensor.get_register_hwdpi_fun = [](const Genesys_Sensor&, unsigned) { return 4800; };
{
struct CustomSensorSettings {
int min_resolution;
@ -1787,6 +1857,8 @@ void genesys_init_sensor_tables()
sensor.exposure = { 0x9c40, 0x9c40, 0x9c40 };
sensor.custom_regs = {};
sensor.gamma = {1.0, 1.0, 1.0};
sensor.get_logical_hwdpi_fun = get_sensor_optical_with_ccd_divisor;
sensor.get_register_hwdpi_fun = [](const Genesys_Sensor&, unsigned) { return 4800; };
{
struct CustomSensorSettings {
@ -2007,6 +2079,8 @@ void genesys_init_sensor_tables()
{ 0x5e, 0x6f },
};
sensor.gamma = {1.0, 1.0, 1.0};
sensor.get_logical_hwdpi_fun = default_get_logical_hwdpi;
sensor.get_register_hwdpi_fun = default_get_logical_hwdpi;
s_sensors->push_back(sensor);
@ -2049,6 +2123,8 @@ void genesys_init_sensor_tables()
{ 0x5e, 0x00 },
};
sensor.gamma = {2.1, 2.1, 2.1};
sensor.get_logical_hwdpi_fun = default_get_logical_hwdpi;
sensor.get_register_hwdpi_fun = default_get_logical_hwdpi;
s_sensors->push_back(sensor);
@ -2092,6 +2168,8 @@ void genesys_init_sensor_tables()
{ 0x5e, 0x1f },
};
sensor.gamma = {2.1, 2.1, 2.1};
sensor.get_logical_hwdpi_fun = default_get_logical_hwdpi;
sensor.get_register_hwdpi_fun = default_get_logical_hwdpi;
s_sensors->push_back(sensor);
@ -2134,6 +2212,8 @@ void genesys_init_sensor_tables()
{ 0x5e, 0x00 },
};
sensor.gamma = {2.1, 2.1, 2.1};
sensor.get_logical_hwdpi_fun = default_get_logical_hwdpi;
sensor.get_register_hwdpi_fun = default_get_logical_hwdpi;
s_sensors->push_back(sensor);
@ -2176,6 +2256,8 @@ void genesys_init_sensor_tables()
{ 0x5e, 0x00 },
};
sensor.gamma = {2.1, 2.1, 2.1};
sensor.get_logical_hwdpi_fun = default_get_logical_hwdpi;
sensor.get_register_hwdpi_fun = default_get_logical_hwdpi;
s_sensors->push_back(sensor);
@ -2218,6 +2300,8 @@ void genesys_init_sensor_tables()
{ 0x5e, 0x02 },
};
sensor.gamma = {1.0, 1.0, 1.0};
sensor.get_logical_hwdpi_fun = default_get_logical_hwdpi;
sensor.get_register_hwdpi_fun = default_get_logical_hwdpi;
s_sensors->push_back(sensor);
@ -2259,6 +2343,8 @@ void genesys_init_sensor_tables()
{ 0x5e, 0x1f },
};
sensor.gamma = {1.7, 1.7, 1.7};
sensor.get_logical_hwdpi_fun = default_get_logical_hwdpi;
sensor.get_register_hwdpi_fun = default_get_logical_hwdpi;
s_sensors->push_back(sensor);
@ -2300,6 +2386,8 @@ void genesys_init_sensor_tables()
{ 0x5e, 0x1f },
};
sensor.gamma = {1.7, 1.7, 1.7};
sensor.get_logical_hwdpi_fun = default_get_logical_hwdpi;
sensor.get_register_hwdpi_fun = default_get_logical_hwdpi;
s_sensors->push_back(sensor);
@ -2346,6 +2434,8 @@ void genesys_init_sensor_tables()
{ 0x5e, 0x41 },
};
sensor.gamma = {1.0, 1.0, 1.0};
sensor.get_logical_hwdpi_fun = default_get_logical_hwdpi;
sensor.get_register_hwdpi_fun = default_get_logical_hwdpi;
s_sensors->push_back(sensor);
}

Wyświetl plik

@ -842,8 +842,8 @@ static void gl124_setup_sensor(Genesys_Device * dev,
regs->set8(addr, sensor.custom_regs.get_value(addr));
}
/* set EXPDUMMY and CKxMAP */
dpihw = sanei_genesys_compute_dpihw(dev, sensor, dpi);
// set EXPDUMMY and CKxMAP
dpihw = sensor.get_register_hwdpi(dpi);
Sensor_Profile* sensor_profile = get_sensor_profile(dev->model->ccd_type, dpihw, half_ccd);
regs->set8(0x18, sensor_profile->reg18);
@ -929,9 +929,9 @@ static void gl124_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens
unsigned ccd_pixels_per_system_pixel = sensor.ccd_pixels_per_system_pixel();
DBG(DBG_io2, "%s: ccd_pixels_per_system_pixel=%d\n", __func__, ccd_pixels_per_system_pixel);
/* to manage high resolution device while keeping good
* low resolution scanning speed, we make hardware dpi vary */
dpihw = sanei_genesys_compute_dpihw(dev, sensor, used_res * ccd_pixels_per_system_pixel);
// to manage high resolution device while keeping good low resolution scanning speed, we
// make hardware dpi vary
dpihw = sensor.get_register_hwdpi(used_res * ccd_pixels_per_system_pixel);
factor=sensor.optical_res/dpihw;
DBG (DBG_io2, "%s: dpihw=%d (factor=%d)\n", __func__, dpihw, factor);
@ -1451,8 +1451,8 @@ gl124_calculate_current_setup (Genesys_Device * dev, const Genesys_Sensor& senso
/* max_shift */
max_shift=sanei_genesys_compute_max_shift(dev, params.channels, params.yres, 0);
/* compute hw dpi for sensor */
dpihw=sanei_genesys_compute_dpihw(dev, sensor,used_res);
// compute hw dpi for sensor
dpihw = sensor.get_register_hwdpi(used_res);
Sensor_Profile* sensor_profile = get_sensor_profile(dev->model->ccd_type, dpihw, half_ccd);
dev->segnb=sensor_profile->reg98 & 0x0f;
@ -1787,9 +1787,7 @@ static void gl124_slow_back_home(Genesys_Device* dev, SANE_Bool wait_until_home)
try {
gl124_start_action(dev);
} catch (...) {
try {
gl124_stop_action (dev);
} catch (...) {}
catch_all_exceptions(__func__, [&]() { gl124_stop_action(dev); });
// restore original registers
catch_all_exceptions(__func__, [&]()
{
@ -2037,7 +2035,7 @@ static void gl124_init_regs_for_shading(Genesys_Device* dev, const Genesys_Senso
dev->calib_channels = 3;
dev->calib_lines = dev->model->shading_lines;
dpihw=sanei_genesys_compute_dpihw(dev, sensor, dev->settings.xres);
dpihw = sensor.get_register_hwdpi(dev->settings.xres);
if(dpihw>=2400)
{
dev->calib_lines *= 2;
@ -2213,7 +2211,7 @@ static void gl124_send_shading_data(Genesys_Device* dev, const Genesys_Sensor& s
/* compute deletion factor */
sanei_genesys_get_double(&dev->reg,REG_DPISET,&dpiset);
dpihw=sanei_genesys_compute_dpihw(dev, sensor, dpiset);
dpihw = sensor.get_register_hwdpi(dpiset);
factor=dpihw/dpiset;
DBG( DBG_io2, "%s: factor=%d\n",__func__,factor);
@ -2383,7 +2381,7 @@ static void gl124_led_calibration(Genesys_Device* dev, Genesys_Sensor& sensor,
/* offset calibration is always done in 16 bit depth color mode */
channels = 3;
depth=16;
dpihw=sanei_genesys_compute_dpihw(dev, sensor, dev->settings.xres);
dpihw = sensor.get_register_hwdpi(dev->settings.xres);
half_ccd=compute_half_ccd(sensor, dev->settings.xres);
if(half_ccd==SANE_TRUE)
{

Wyświetl plik

@ -3291,7 +3291,6 @@ static void gl646_init(Genesys_Device* dev)
DBG_INIT();
DBG_HELPER(dbg);
struct timeval tv;
uint8_t cold = 0, val = 0;
uint32_t addr = 0xdead;
size_t len;
@ -3319,8 +3318,6 @@ static void gl646_init(Genesys_Device* dev)
dev->white_average_data.clear();
dev->settings.color_filter = ColorFilter::GREEN;
gettimeofday (&tv, NULL);
dev->init_date = tv.tv_sec;
/* Set default values for registers */
gl646_init_regs (dev);

Wyświetl plik

@ -2554,9 +2554,7 @@ static void gl841_eject_document(Genesys_Device* dev)
try {
gl841_start_action(dev);
} catch (...) {
try {
gl841_stop_action(dev);
} catch (...) {}
catch_all_exceptions(__func__, [&]() { gl841_stop_action(dev); });
// restore original registers
catch_all_exceptions(__func__, [&]()
{
@ -2803,9 +2801,7 @@ static void gl841_feed(Genesys_Device* dev, int steps)
try {
gl841_start_action(dev);
} catch (...) {
try {
gl841_stop_action (dev);
} catch (...) {}
catch_all_exceptions(__func__, [&]() { gl841_stop_action (dev); });
// restore original registers
catch_all_exceptions(__func__, [&]()
{
@ -2918,9 +2914,7 @@ static void gl841_slow_back_home(Genesys_Device* dev, SANE_Bool wait_until_home)
try {
gl841_start_action(dev);
} catch (...) {
try {
gl841_stop_action(dev);
} catch (...) {}
catch_all_exceptions(__func__, [&]() { gl841_stop_action(dev); });
// restore original registers
catch_all_exceptions(__func__, [&]()
{

Wyświetl plik

@ -996,7 +996,7 @@ static void gl843_init_motor_regs_scan(Genesys_Device* dev,
if (!(dev->model->flags & GENESYS_FLAG_FULL_HWDPI_MODE))
{
r->value = 0x50;
coeff=sensor.optical_res/sanei_genesys_compute_dpihw(dev, sensor, scan_yres);
coeff=sensor.optical_res / sensor.get_register_hwdpi(scan_yres);
if (dev->model->motor_type == MOTOR_KVSS080)
{
if(coeff>=1)
@ -1058,9 +1058,9 @@ static void gl843_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens
tgtime = exposure / 65536 + 1;
DBG(DBG_io2, "%s: tgtime=%d\n", __func__, tgtime);
/* to manage high resolution device while keeping good
* low resolution scanning speed, we make hardware dpi vary */
dpihw=sanei_genesys_compute_dpihw(dev, sensor, used_res);
// to manage high resolution device while keeping good low resolution scanning speed, we make
// hardware dpi vary
dpihw = sensor.get_register_hwdpi(used_res);
factor=sensor.optical_res/dpihw;
DBG(DBG_io2, "%s: dpihw=%d (factor=%d)\n", __func__, dpihw, factor);
@ -2089,7 +2089,7 @@ static void gl843_begin_scan(Genesys_Device* dev, const Genesys_Sensor& sensor,
/* get back the target dpihw */
sanei_genesys_get_double (reg, REG_DPISET, &dpiset);
dpihw = sanei_genesys_compute_dpihw(dev, sensor, dpiset);
dpihw = sensor.get_register_hwdpi(dpiset);
/* set up GPIO for scan */
switch(dev->model->gpo_type)
@ -2212,9 +2212,7 @@ static void gl843_park_xpa_lamp(Genesys_Device* dev)
try {
gl843_start_action(dev);
} catch (...) {
try {
gl843_stop_action(dev);
} catch (...) {}
catch_all_exceptions(__func__, [&]() { gl843_stop_action(dev); });
// restore original registers
catch_all_exceptions(__func__, [&]()
{
@ -2324,9 +2322,7 @@ static void gl843_slow_back_home(Genesys_Device* dev, SANE_Bool wait_until_home)
try {
gl843_start_action(dev);
} catch (...) {
try {
gl843_stop_action(dev);
} catch (...) {}
catch_all_exceptions(__func__, [&]() { gl843_stop_action(dev); });
// restore original registers
catch_all_exceptions(__func__, [&]()
{
@ -2543,9 +2539,7 @@ static void gl843_feed(Genesys_Device* dev, unsigned int steps)
try {
gl843_start_action(dev);
} catch (...) {
try {
gl843_stop_action(dev);
} catch (...) {}
catch_all_exceptions(__func__, [&]() { gl843_stop_action(dev); });
// restore original registers
catch_all_exceptions(__func__, [&]()
{
@ -2586,7 +2580,7 @@ static void gl843_init_regs_for_shading(Genesys_Device* dev, const Genesys_Senso
dev->calib_lines = dev->model->shading_lines;
}
dpihw = sanei_genesys_compute_dpihw_calibration(dev, sensor, dev->settings.xres);
dpihw = sensor.get_logical_hwdpi(dev->settings.xres);
factor=sensor.optical_res/dpihw;
resolution=dpihw;
@ -3025,8 +3019,8 @@ static void gl843_offset_calibration(Genesys_Device* dev, const Genesys_Sensor&
lines = 8;
bpp = 8;
/* compute divider factor to compute final pixels number */
dpihw = sanei_genesys_compute_dpihw_calibration(dev, sensor, dev->settings.xres);
// compute divider factor to compute final pixels number
dpihw = sensor.get_logical_hwdpi(dev->settings.xres);
factor = sensor.optical_res / dpihw;
resolution = dpihw;
@ -3246,7 +3240,7 @@ static void gl843_coarse_gain_calibration(Genesys_Device* dev, const Genesys_Sen
int resolution;
int bpp;
dpihw=sanei_genesys_compute_dpihw_calibration(dev, sensor, dpi);
dpihw = sensor.get_logical_hwdpi(dpi);
factor=sensor.optical_res/dpihw;
/* coarse gain calibration is always done in color mode */
@ -3432,7 +3426,7 @@ static void gl843_init_regs_for_warmup(Genesys_Device* dev, const Genesys_Sensor
/* setup scan */
*channels=3;
resolution=600;
dpihw=sanei_genesys_compute_dpihw_calibration(dev, sensor, resolution);
dpihw = sensor.get_logical_hwdpi(resolution);
resolution=dpihw;
const auto& calib_sensor = sanei_genesys_find_sensor(dev, resolution,
@ -3878,7 +3872,7 @@ static void gl843_send_shading_data(Genesys_Device* dev, const Genesys_Sensor& s
* compute offset within data for SHDAREA case */
r = sanei_genesys_get_address(&dev->reg, REG18);
sanei_genesys_get_double(&dev->reg,REG_DPISET,&dpiset);
factor=sensor.optical_res/sanei_genesys_compute_dpihw(dev, sensor, dpiset);
factor = sensor.optical_res / sensor.get_register_hwdpi(dpiset);
/* start coordinate in optical dpi coordinates */
startx = (sensor.dummy_pixel / sensor.ccd_pixels_per_system_pixel()) / factor;
@ -3891,8 +3885,7 @@ static void gl843_send_shading_data(Genesys_Device* dev, const Genesys_Sensor& s
{
int optical_res = sensor.optical_res / dev->current_setup.ccd_size_divisor;
int dpiset_real = dpiset / dev->current_setup.ccd_size_divisor;
int half_ccd_factor = optical_res /
sanei_genesys_compute_dpihw_calibration(dev, sensor, dpiset_real);
int half_ccd_factor = optical_res / sensor.get_logical_hwdpi(dpiset_real);
strpixel /= half_ccd_factor;
endpixel /= half_ccd_factor;
}

Wyświetl plik

@ -218,7 +218,7 @@ static void gl846_setup_sensor(Genesys_Device * dev, const Genesys_Sensor& senso
int dpihw;
uint16_t exp;
dpihw=sanei_genesys_compute_dpihw(dev, sensor, dpi);
dpihw = sensor.get_register_hwdpi(dpi);
for (uint16_t addr = 0x16; addr < 0x1e; addr++) {
regs->set8(addr, sensor.custom_regs.get_value(addr));
@ -228,8 +228,8 @@ static void gl846_setup_sensor(Genesys_Device * dev, const Genesys_Sensor& senso
regs->set8(addr, sensor.custom_regs.get_value(addr));
}
/* set EXPDUMMY and CKxMAP */
dpihw=sanei_genesys_compute_dpihw(dev, sensor, dpi);
// set EXPDUMMY and CKxMAP
dpihw = sensor.get_register_hwdpi(dpi);
Sensor_Profile* sensor_profile = get_sensor_profile(dev->model->ccd_type, dpihw);
sanei_genesys_set_reg_from_set(regs,REG_EXPDMY,(uint8_t)((sensor_profile->expdummy) & 0xff));
@ -696,8 +696,7 @@ static void gl846_init_motor_regs_scan(Genesys_Device* dev,
if(dev->model->gpo_type==GPO_IMG101)
{
if(scan_yres==sanei_genesys_compute_dpihw(dev, sensor,scan_yres))
{
if (scan_yres == sensor.get_register_hwdpi(scan_yres)) {
val=1;
}
else
@ -795,7 +794,7 @@ static void gl846_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens
// to manage high resolution device while keeping good low resolution scanning speed,
// we make hardware dpi vary
dpihw = sanei_genesys_compute_dpihw(dev, sensor, used_res * ccd_pixels_per_system_pixel);
dpihw = sensor.get_register_hwdpi(used_res * ccd_pixels_per_system_pixel);
factor = sensor.optical_res/dpihw;
DBG(DBG_io2, "%s: dpihw=%d (factor=%d)\n", __func__, dpihw, factor);
@ -1780,7 +1779,7 @@ static void gl846_init_regs_for_shading(Genesys_Device* dev, const Genesys_Senso
/* initial calibration reg values */
regs = dev->reg;
dev->calib_resolution = sanei_genesys_compute_dpihw(dev, sensor, dev->settings.xres);
dev->calib_resolution = sensor.get_register_hwdpi(dev->settings.xres);
dev->calib_total_bytes_to_read = 0;
dev->calib_lines = dev->model->shading_lines;
if(dev->calib_resolution==4800)
@ -1955,7 +1954,7 @@ static void gl846_send_shading_data(Genesys_Device* dev, const Genesys_Sensor& s
dpiset=tempo;
DBG(DBG_io2, "%s: STRPIXEL=%d, ENDPIXEL=%d, PIXELS=%d, DPISET=%d\n", __func__, strpixel, endpixel,
endpixel-strpixel, dpiset);
dpihw=sanei_genesys_compute_dpihw(dev, sensor, dpiset);
dpihw = sensor.get_register_hwdpi(dpiset);
factor=dpihw/dpiset;
DBG(DBG_io2, "%s: factor=%d\n", __func__, factor);
@ -2047,7 +2046,7 @@ static void gl846_led_calibration(Genesys_Device* dev, Genesys_Sensor& sensor,
/* offset calibration is always done in color mode */
channels = 3;
depth=16;
used_res=sanei_genesys_compute_dpihw(dev, sensor, dev->settings.xres);
used_res = sensor.get_register_hwdpi(dev->settings.xres);
Sensor_Profile* sensor_profile = get_sensor_profile(dev->model->ccd_type, used_res);
num_pixels = (sensor.sensor_pixels*used_res)/sensor.optical_res;

Wyświetl plik

@ -213,7 +213,7 @@ static void gl847_setup_sensor(Genesys_Device * dev, const Genesys_Sensor& senso
int dpihw;
uint16_t exp;
dpihw=sanei_genesys_compute_dpihw(dev, sensor, dpi);
dpihw = sensor.get_register_hwdpi(dpi);
for (uint16_t addr = 0x16; addr < 0x1e; addr++) {
regs->set8(addr, sensor.custom_regs.get_value(addr));
@ -223,8 +223,8 @@ static void gl847_setup_sensor(Genesys_Device * dev, const Genesys_Sensor& senso
regs->set8(addr, sensor.custom_regs.get_value(addr));
}
/* set EXPDUMMY and CKxMAP */
dpihw=sanei_genesys_compute_dpihw(dev, sensor, dpi);
// set EXPDUMMY and CKxMAP
dpihw = sensor.get_register_hwdpi(dpi);
Sensor_Profile* sensor_profile=get_sensor_profile(dev->model->ccd_type, dpihw);
sanei_genesys_set_reg_from_set(regs,REG_EXPDMY,(uint8_t)((sensor_profile->expdummy) & 0xff));
@ -809,7 +809,7 @@ static void gl847_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens
// to manage high resolution device while keeping good low resolution scanning speed, we make
// hardware dpi vary
dpihw = sanei_genesys_compute_dpihw(dev, sensor, used_res * ccd_pixels_per_system_pixel);
dpihw = sensor.get_register_hwdpi(used_res * ccd_pixels_per_system_pixel);
factor=sensor.optical_res/dpihw;
DBG(DBG_io2, "%s: dpihw=%d (factor=%d)\n", __func__, dpihw, factor);
@ -1594,9 +1594,7 @@ static void gl847_slow_back_home(Genesys_Device* dev, SANE_Bool wait_until_home)
try {
gl847_start_action(dev);
} catch (...) {
try {
gl847_stop_action(dev);
} catch (...) {}
catch_all_exceptions(__func__, [&]() { gl847_stop_action(dev); });
// restore original registers
catch_all_exceptions(__func__, [&]()
{
@ -1802,13 +1800,12 @@ static void gl847_feed(Genesys_Device* dev, unsigned int steps)
try {
gl847_start_action(dev);
} catch (...) {
try {
gl847_stop_action(dev);
} catch (...) {}
try {
// restore original registers
catch_all_exceptions(__func__, [&]() { gl847_stop_action(dev); });
// restore original registers
catch_all_exceptions(__func__, [&]()
{
dev->model->cmd_set->bulk_write_register(dev, dev->reg);
} catch (...) {}
});
throw;
}
@ -1835,7 +1832,7 @@ static void gl847_init_regs_for_shading(Genesys_Device* dev, const Genesys_Senso
/* initial calibration reg values */
regs = dev->reg;
dev->calib_resolution = sanei_genesys_compute_dpihw(dev, sensor, dev->settings.xres);
dev->calib_resolution = sensor.get_register_hwdpi(dev->settings.xres);
dev->calib_total_bytes_to_read = 0;
dev->calib_lines = dev->model->shading_lines;
if(dev->calib_resolution==4800)
@ -2010,7 +2007,7 @@ static void gl847_send_shading_data(Genesys_Device* dev, const Genesys_Sensor& s
dpiset=tempo;
DBG(DBG_io2, "%s: STRPIXEL=%d, ENDPIXEL=%d, PIXELS=%d, DPISET=%d\n", __func__, strpixel, endpixel,
endpixel-strpixel, dpiset);
dpihw=sanei_genesys_compute_dpihw(dev, sensor, dpiset);
dpihw = sensor.get_register_hwdpi(dpiset);
factor=dpihw/dpiset;
DBG(DBG_io2, "%s: factor=%d\n", __func__, factor);
@ -2102,7 +2099,7 @@ static void gl847_led_calibration(Genesys_Device* dev, Genesys_Sensor& sensor,
/* offset calibration is always done in color mode */
channels = 3;
depth=16;
used_res=sanei_genesys_compute_dpihw(dev, sensor, dev->settings.xres);
used_res = sensor.get_register_hwdpi(dev->settings.xres);
Sensor_Profile* sensor_profile=get_sensor_profile(dev->model->ccd_type, used_res);
num_pixels = (sensor.sensor_pixels*used_res)/sensor.optical_res;

Wyświetl plik

@ -1306,62 +1306,6 @@ void sanei_genesys_wait_for_home(Genesys_Device* dev)
}
}
/**@brief compute hardware sensor dpi to use
* compute the sensor hardware dpi based on target resolution.
* A lower dpihw enable faster scans.
* @param dev device used for the scan
* @param xres x resolution of the scan
* @return the hardware dpi to use
*/
int sanei_genesys_compute_dpihw(Genesys_Device *dev, const Genesys_Sensor& sensor, int xres)
{
/* some scanners use always hardware dpi for sensor */
if (dev->model->flags & GENESYS_FLAG_FULL_HWDPI_MODE)
{
return sensor.optical_res;
}
/* can't be below 600 dpi */
if (xres <= 600)
{
return 600;
}
if (xres <= sensor.optical_res / 4)
{
return sensor.optical_res / 4;
}
if (xres <= sensor.optical_res / 2)
{
return sensor.optical_res / 2;
}
return sensor.optical_res;
}
// sanei_genesys_compute_dpihw returns the dpihw that is written to register.
// However the number of pixels depends on half_ccd mode
int sanei_genesys_compute_dpihw_calibration(Genesys_Device *dev, const Genesys_Sensor& sensor,
int xres)
{
if (dev->model->model_id == MODEL_CANON_CANOSCAN_8400F ||
dev->model->model_id == MODEL_CANON_CANOSCAN_8600F)
{
// real resolution is half of the "official" resolution - half_ccd mode
int hwres = sensor.optical_res / sensor.get_ccd_size_divisor_for_dpi(xres);
if (xres <= hwres / 4)
{
return hwres / 4;
}
if (xres <= hwres / 2)
{
return hwres / 2;
}
return hwres;
}
return sanei_genesys_compute_dpihw(dev, sensor, xres);
}
/** @brief motor profile
* search for the database of motor profiles and get the best one. Each
* profile is at full step and at a reference exposure. Use first entry
@ -1597,8 +1541,8 @@ bool sanei_genesys_is_compatible_calibration(Genesys_Device * dev, const Genesys
}
else
{
resolution=sanei_genesys_compute_dpihw(dev, sensor, dev->settings.xres);
compatible = (resolution == ((int) sanei_genesys_compute_dpihw(dev, sensor,cache->used_setup.xres)));
compatible = (sensor.get_register_hwdpi(dev->settings.xres) ==
sensor.get_register_hwdpi(cache->used_setup.xres));
}
DBG (DBG_io, "%s: after resolution check current compatible=%d\n", __func__, compatible);
if (dev->current_setup.ccd_size_divisor != cache->used_setup.ccd_size_divisor)

Wyświetl plik

@ -678,6 +678,12 @@ struct Genesys_Sensor {
// red, green and blue gamma coefficient for default gamma tables
AssignableArray<float, 3> gamma;
std::function<unsigned(const Genesys_Sensor&, unsigned)> get_logical_hwdpi_fun;
std::function<unsigned(const Genesys_Sensor&, unsigned)> get_register_hwdpi_fun;
unsigned get_logical_hwdpi(unsigned xres) const { return get_logical_hwdpi_fun(*this, xres); }
unsigned get_register_hwdpi(unsigned xres) const { return get_register_hwdpi_fun(*this, xres); }
int get_ccd_size_divisor_for_dpi(int xres) const
{
if (ccd_size_divisor >= 4 && xres * 4 <= optical_res) {
@ -1562,7 +1568,6 @@ struct Genesys_Device
Genesys_Gpo gpo;
Genesys_Motor motor;
uint8_t control[6] = {};
time_t init_date = 0;
size_t average_size = 0;
// number of pixels used during shading calibration
@ -1584,11 +1589,9 @@ struct Genesys_Device
std::vector<uint8_t> white_average_data;
std::vector<uint8_t> dark_average_data;
uint16_t dark[3] = {};
SANE_Bool already_initialized = 0;
SANE_Int scanhead_position_in_steps = 0;
SANE_Int lamp_off_time = 0;
SANE_Bool read_active = 0;
// signal wether the park command has been issued
@ -1605,9 +1608,9 @@ struct Genesys_Device
Genesys_Buffer out_buffer;
// buffer for digital lineart from gray data
Genesys_Buffer binarize_buffer = {};
Genesys_Buffer binarize_buffer;
// local buffer for gray data during dynamix lineart
Genesys_Buffer local_buffer = {};
Genesys_Buffer local_buffer;
// bytes to read from scanner
size_t read_bytes_left = 0;
@ -1947,11 +1950,6 @@ extern void sanei_genesys_wait_for_home(Genesys_Device* dev);
extern void sanei_genesys_asic_init(Genesys_Device* dev, SANE_Bool cold);
int sanei_genesys_compute_dpihw(Genesys_Device *dev, const Genesys_Sensor& sensor, int xres);
int sanei_genesys_compute_dpihw_calibration(Genesys_Device *dev, const Genesys_Sensor& sensor,
int xres);
extern
Motor_Profile *sanei_genesys_get_motor_profile(Motor_Profile *motors, int motor_type, int exposure);