kopia lustrzana https://gitlab.com/sane-project/backends
genesys: Deduplicate different get_sensor_profile implementations
rodzic
e4e1a02733
commit
c0e465784e
|
@ -301,7 +301,6 @@ enum class AsicType : unsigned
|
||||||
GL845,
|
GL845,
|
||||||
GL846,
|
GL846,
|
||||||
GL847,
|
GL847,
|
||||||
GL848,
|
|
||||||
GL123,
|
GL123,
|
||||||
GL124,
|
GL124,
|
||||||
};
|
};
|
||||||
|
|
|
@ -93,49 +93,6 @@ gl124_test_motor_flag_bit (SANE_Byte val)
|
||||||
return SANE_FALSE;
|
return SANE_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @brief sensor profile
|
|
||||||
* search for the database of motor profiles and get the best one. Each
|
|
||||||
* profile is at a specific dpihw. Use LiDE 110 table by default.
|
|
||||||
* @param sensor_type sensor id
|
|
||||||
* @param dpi hardware dpi for the scan
|
|
||||||
* @param ccd_size_divisor flag to signal half ccd mode
|
|
||||||
* @return a pointer to a Sensor_Profile struct
|
|
||||||
*/
|
|
||||||
static const SensorProfile& get_sensor_profile(const Genesys_Sensor& sensor, unsigned dpi,
|
|
||||||
unsigned ccd_size_divisor)
|
|
||||||
{
|
|
||||||
int best_i = -1;
|
|
||||||
for (unsigned i = 0; i < sensor.sensor_profiles.size(); ++i) {
|
|
||||||
// exact match
|
|
||||||
if (sensor.sensor_profiles[i].dpi == dpi &&
|
|
||||||
sensor.sensor_profiles[i].ccd_size_divisor == ccd_size_divisor)
|
|
||||||
{
|
|
||||||
return sensor.sensor_profiles[i];
|
|
||||||
}
|
|
||||||
// closest match
|
|
||||||
if (sensor.sensor_profiles[i].ccd_size_divisor == ccd_size_divisor) {
|
|
||||||
if (best_i < 0) {
|
|
||||||
best_i = i;
|
|
||||||
} else {
|
|
||||||
if (sensor.sensor_profiles[i].dpi >= dpi &&
|
|
||||||
sensor.sensor_profiles[i].dpi < sensor.sensor_profiles[best_i].dpi)
|
|
||||||
{
|
|
||||||
best_i = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// default fallback
|
|
||||||
if (best_i < 0) {
|
|
||||||
DBG(DBG_warn,"%s: using default sensor profile\n",__func__);
|
|
||||||
return *s_fallback_sensor_profile_gl124;
|
|
||||||
}
|
|
||||||
|
|
||||||
return sensor.sensor_profiles[best_i];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void gl124_homsnr_gpio(Genesys_Device* dev)
|
static void gl124_homsnr_gpio(Genesys_Device* dev)
|
||||||
{
|
{
|
||||||
DBG_HELPER(dbg);
|
DBG_HELPER(dbg);
|
||||||
|
@ -841,7 +798,8 @@ static void gl124_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens
|
||||||
DBG(DBG_io2, "%s: dpihw=%d\n", __func__, dpihw);
|
DBG(DBG_io2, "%s: dpihw=%d\n", __func__, dpihw);
|
||||||
|
|
||||||
// sensor parameters
|
// sensor parameters
|
||||||
const auto& sensor_profile = get_sensor_profile(sensor, dpihw, session.ccd_size_divisor);
|
const auto& sensor_profile = get_sensor_profile(dev->model->asic_type, sensor, dpihw,
|
||||||
|
session.ccd_size_divisor);
|
||||||
gl124_setup_sensor(dev, sensor, sensor_profile, reg);
|
gl124_setup_sensor(dev, sensor, sensor_profile, reg);
|
||||||
|
|
||||||
/* start and end coordinate in optical dpi coordinates */
|
/* start and end coordinate in optical dpi coordinates */
|
||||||
|
@ -1078,7 +1036,7 @@ static void gl124_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
exposure_time = get_sensor_profile(sensor, session.params.xres,
|
exposure_time = get_sensor_profile(dev->model->asic_type, sensor, session.params.xres,
|
||||||
session.ccd_size_divisor).exposure_lperiod;
|
session.ccd_size_divisor).exposure_lperiod;
|
||||||
scan_step_type = sanei_genesys_compute_step_type(gl124_motor_profiles,
|
scan_step_type = sanei_genesys_compute_step_type(gl124_motor_profiles,
|
||||||
dev->model->motor_type, exposure_time);
|
dev->model->motor_type, exposure_time);
|
||||||
|
@ -1196,7 +1154,7 @@ gl124_calculate_current_setup (Genesys_Device * dev, const Genesys_Sensor& senso
|
||||||
|
|
||||||
DBG(DBG_info, "%s: used_pixels=%d\n", __func__, session.optical_pixels);
|
DBG(DBG_info, "%s: used_pixels=%d\n", __func__, session.optical_pixels);
|
||||||
|
|
||||||
exposure_time = get_sensor_profile(sensor, session.params.xres,
|
exposure_time = get_sensor_profile(dev->model->asic_type, sensor, session.params.xres,
|
||||||
session.ccd_size_divisor).exposure_lperiod;
|
session.ccd_size_divisor).exposure_lperiod;
|
||||||
|
|
||||||
DBG (DBG_info, "%s : exposure_time=%d pixels\n", __func__, exposure_time);
|
DBG (DBG_info, "%s : exposure_time=%d pixels\n", __func__, exposure_time);
|
||||||
|
@ -1204,7 +1162,7 @@ gl124_calculate_current_setup (Genesys_Device * dev, const Genesys_Sensor& senso
|
||||||
// compute hw dpi for sensor
|
// compute hw dpi for sensor
|
||||||
dpihw = sensor.get_register_hwdpi(session.params.xres);
|
dpihw = sensor.get_register_hwdpi(session.params.xres);
|
||||||
|
|
||||||
const SensorProfile& sensor_profile = get_sensor_profile(sensor, dpihw,
|
const SensorProfile& sensor_profile = get_sensor_profile(dev->model->asic_type, sensor, dpihw,
|
||||||
session.ccd_size_divisor);
|
session.ccd_size_divisor);
|
||||||
dev->deseg.segment_count = sensor_profile.custom_regs.get_value(0x98) & 0x0f;
|
dev->deseg.segment_count = sensor_profile.custom_regs.get_value(0x98) & 0x0f;
|
||||||
|
|
||||||
|
@ -2103,7 +2061,8 @@ static SensorExposure gl124_led_calibration(Genesys_Device* dev, const Genesys_S
|
||||||
unsigned ccd_size_divisor = sensor.get_ccd_size_divisor_for_dpi(dev->settings.xres);
|
unsigned ccd_size_divisor = sensor.get_ccd_size_divisor_for_dpi(dev->settings.xres);
|
||||||
resolution /= ccd_size_divisor;
|
resolution /= ccd_size_divisor;
|
||||||
|
|
||||||
const auto& sensor_profile = get_sensor_profile(sensor, dpihw, ccd_size_divisor);
|
const auto& sensor_profile = get_sensor_profile(dev->model->asic_type, sensor, dpihw,
|
||||||
|
ccd_size_divisor);
|
||||||
num_pixels = (sensor.sensor_pixels*resolution)/sensor.optical_res;
|
num_pixels = (sensor.sensor_pixels*resolution)/sensor.optical_res;
|
||||||
|
|
||||||
/* initial calibration reg values */
|
/* initial calibration reg values */
|
||||||
|
|
|
@ -147,42 +147,6 @@ gl846_get_step_multiplier (Genesys_Register_Set * regs)
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @brief sensor profile
|
|
||||||
* search for the database of motor profiles and get the best one. Each
|
|
||||||
* profile is at a specific dpihw. Use LiDE 110 table by default.
|
|
||||||
* @param sensor_type sensor id
|
|
||||||
* @param dpi hardware dpi for the scan
|
|
||||||
* @return a pointer to a Sensor_Profile struct
|
|
||||||
*/
|
|
||||||
static const SensorProfile& get_sensor_profile(const Genesys_Sensor& sensor, unsigned dpi)
|
|
||||||
{
|
|
||||||
int best_i = -1;
|
|
||||||
for (unsigned i = 0; i < sensor.sensor_profiles.size(); ++i) {
|
|
||||||
// exact match
|
|
||||||
if (sensor.sensor_profiles[i].dpi == dpi) {
|
|
||||||
return sensor.sensor_profiles[i];
|
|
||||||
}
|
|
||||||
// closest match
|
|
||||||
if (best_i < 0) {
|
|
||||||
best_i = i;
|
|
||||||
} else {
|
|
||||||
if (sensor.sensor_profiles[i].dpi >= dpi &&
|
|
||||||
sensor.sensor_profiles[i].dpi < sensor.sensor_profiles[best_i].dpi)
|
|
||||||
{
|
|
||||||
best_i = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// default fallback
|
|
||||||
if (best_i < 0) {
|
|
||||||
DBG(DBG_warn,"%s: using default sensor profile\n",__func__);
|
|
||||||
return *s_fallback_sensor_profile_gl846;
|
|
||||||
}
|
|
||||||
|
|
||||||
return sensor.sensor_profiles[best_i];
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @brief sensor specific settings
|
/** @brief sensor specific settings
|
||||||
*/
|
*/
|
||||||
static void gl846_setup_sensor(Genesys_Device * dev, const Genesys_Sensor& sensor,
|
static void gl846_setup_sensor(Genesys_Device * dev, const Genesys_Sensor& sensor,
|
||||||
|
@ -734,7 +698,7 @@ static void gl846_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens
|
||||||
DBG(DBG_io2, "%s: dpihw=%d\n", __func__, dpihw);
|
DBG(DBG_io2, "%s: dpihw=%d\n", __func__, dpihw);
|
||||||
|
|
||||||
// sensor parameters
|
// sensor parameters
|
||||||
const auto& sensor_profile = get_sensor_profile(sensor, dpihw);
|
const auto& sensor_profile = get_sensor_profile(dev->model->asic_type, sensor, dpihw, 1);
|
||||||
gl846_setup_sensor(dev, sensor, sensor_profile, reg);
|
gl846_setup_sensor(dev, sensor, sensor_profile, reg);
|
||||||
|
|
||||||
// start and end coordinate in optical dpi coordinates
|
// start and end coordinate in optical dpi coordinates
|
||||||
|
@ -957,7 +921,8 @@ static void gl846_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens
|
||||||
|
|
||||||
slope_dpi = slope_dpi * (1 + dummy);
|
slope_dpi = slope_dpi * (1 + dummy);
|
||||||
|
|
||||||
exposure_time = get_sensor_profile(sensor, session.params.xres).exposure_lperiod;
|
exposure_time = get_sensor_profile(dev->model->asic_type, sensor,
|
||||||
|
session.params.xres, 1).exposure_lperiod;
|
||||||
scan_step_type = sanei_genesys_compute_step_type(gl846_motor_profiles, dev->model->motor_type,
|
scan_step_type = sanei_genesys_compute_step_type(gl846_motor_profiles, dev->model->motor_type,
|
||||||
exposure_time);
|
exposure_time);
|
||||||
|
|
||||||
|
@ -1084,7 +1049,8 @@ gl846_calculate_current_setup(Genesys_Device * dev, const Genesys_Sensor& sensor
|
||||||
|
|
||||||
slope_dpi = slope_dpi * (1 + dummy);
|
slope_dpi = slope_dpi * (1 + dummy);
|
||||||
|
|
||||||
exposure_time = get_sensor_profile(sensor, session.params.xres).exposure_lperiod;
|
exposure_time = get_sensor_profile(dev->model->asic_type, sensor,
|
||||||
|
session.params.xres, 1).exposure_lperiod;
|
||||||
DBG(DBG_info, "%s : exposure_time=%d pixels\n", __func__, exposure_time);
|
DBG(DBG_info, "%s : exposure_time=%d pixels\n", __func__, exposure_time);
|
||||||
|
|
||||||
dev->session = session;
|
dev->session = session;
|
||||||
|
@ -1788,7 +1754,7 @@ static SensorExposure gl846_led_calibration(Genesys_Device* dev, const Genesys_S
|
||||||
channels = 3;
|
channels = 3;
|
||||||
depth=16;
|
depth=16;
|
||||||
used_res = sensor.get_register_hwdpi(dev->settings.xres);
|
used_res = sensor.get_register_hwdpi(dev->settings.xres);
|
||||||
const auto& sensor_profile = get_sensor_profile(sensor, used_res);
|
const auto& sensor_profile = get_sensor_profile(dev->model->asic_type, sensor, used_res, 1);
|
||||||
num_pixels = (sensor.sensor_pixels*used_res)/sensor.optical_res;
|
num_pixels = (sensor.sensor_pixels*used_res)/sensor.optical_res;
|
||||||
|
|
||||||
/* initial calibration reg values */
|
/* initial calibration reg values */
|
||||||
|
|
|
@ -142,42 +142,6 @@ gl847_get_step_multiplier (Genesys_Register_Set * regs)
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @brief sensor profile
|
|
||||||
* search for the database of motor profiles and get the best one. Each
|
|
||||||
* profile is at a specific dpihw. Use LiDE 110 table by default.
|
|
||||||
* @param sensor_type sensor id
|
|
||||||
* @param dpi hardware dpi for the scan
|
|
||||||
* @return a pointer to a Sensor_Profile struct
|
|
||||||
*/
|
|
||||||
static const SensorProfile& get_sensor_profile(const Genesys_Sensor& sensor, unsigned dpi)
|
|
||||||
{
|
|
||||||
int best_i = -1;
|
|
||||||
for (unsigned i = 0; i < sensor.sensor_profiles.size(); ++i) {
|
|
||||||
// exact match
|
|
||||||
if (sensor.sensor_profiles[i].dpi == dpi) {
|
|
||||||
return sensor.sensor_profiles[i];
|
|
||||||
}
|
|
||||||
// closest match
|
|
||||||
if (best_i < 0) {
|
|
||||||
best_i = i;
|
|
||||||
} else {
|
|
||||||
if (sensor.sensor_profiles[i].dpi >= dpi &&
|
|
||||||
sensor.sensor_profiles[i].dpi < sensor.sensor_profiles[best_i].dpi)
|
|
||||||
{
|
|
||||||
best_i = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// default fallback
|
|
||||||
if (best_i < 0) {
|
|
||||||
DBG(DBG_warn,"%s: using default sensor profile\n",__func__);
|
|
||||||
return *s_fallback_sensor_profile_gl847;
|
|
||||||
}
|
|
||||||
|
|
||||||
return sensor.sensor_profiles[best_i];
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @brief sensor specific settings
|
/** @brief sensor specific settings
|
||||||
*/
|
*/
|
||||||
static void gl847_setup_sensor(Genesys_Device * dev, const Genesys_Sensor& sensor,
|
static void gl847_setup_sensor(Genesys_Device * dev, const Genesys_Sensor& sensor,
|
||||||
|
@ -750,7 +714,7 @@ static void gl847_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens
|
||||||
DBG(DBG_io2, "%s: dpihw=%d\n", __func__, dpihw);
|
DBG(DBG_io2, "%s: dpihw=%d\n", __func__, dpihw);
|
||||||
|
|
||||||
// sensor parameters
|
// sensor parameters
|
||||||
const auto& sensor_profile = get_sensor_profile(sensor, dpihw);
|
const auto& sensor_profile = get_sensor_profile(dev->model->asic_type, sensor, dpihw, 1);
|
||||||
gl847_setup_sensor(dev, sensor, sensor_profile, reg);
|
gl847_setup_sensor(dev, sensor, sensor_profile, reg);
|
||||||
dpiset = session.params.xres * ccd_pixels_per_system_pixel;
|
dpiset = session.params.xres * ccd_pixels_per_system_pixel;
|
||||||
|
|
||||||
|
@ -971,7 +935,8 @@ static void gl847_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens
|
||||||
|
|
||||||
slope_dpi = slope_dpi * (1 + dummy);
|
slope_dpi = slope_dpi * (1 + dummy);
|
||||||
|
|
||||||
exposure_time = get_sensor_profile(sensor, session.params.xres).exposure_lperiod;
|
exposure_time = get_sensor_profile(dev->model->asic_type, sensor,
|
||||||
|
session.params.xres, 1).exposure_lperiod;
|
||||||
scan_step_type = sanei_genesys_compute_step_type(gl847_motor_profiles, dev->model->motor_type,
|
scan_step_type = sanei_genesys_compute_step_type(gl847_motor_profiles, dev->model->motor_type,
|
||||||
exposure_time);
|
exposure_time);
|
||||||
|
|
||||||
|
@ -1096,7 +1061,8 @@ gl847_calculate_current_setup(Genesys_Device * dev, const Genesys_Sensor& sensor
|
||||||
|
|
||||||
slope_dpi = slope_dpi * (1 + dummy);
|
slope_dpi = slope_dpi * (1 + dummy);
|
||||||
|
|
||||||
exposure_time = get_sensor_profile(sensor, session.params.xres).exposure_lperiod;
|
exposure_time = get_sensor_profile(dev->model->asic_type, sensor,
|
||||||
|
session.params.xres, 1).exposure_lperiod;
|
||||||
DBG(DBG_info, "%s : exposure_time=%d pixels\n", __func__, exposure_time);
|
DBG(DBG_info, "%s : exposure_time=%d pixels\n", __func__, exposure_time);
|
||||||
|
|
||||||
dev->session = session;
|
dev->session = session;
|
||||||
|
@ -1836,7 +1802,7 @@ static SensorExposure gl847_led_calibration(Genesys_Device* dev, const Genesys_S
|
||||||
channels = 3;
|
channels = 3;
|
||||||
depth=16;
|
depth=16;
|
||||||
used_res = sensor.get_register_hwdpi(dev->settings.xres);
|
used_res = sensor.get_register_hwdpi(dev->settings.xres);
|
||||||
const auto& sensor_profile = get_sensor_profile(sensor, used_res);
|
const auto& sensor_profile = get_sensor_profile(dev->model->asic_type, sensor, used_res, 1);
|
||||||
num_pixels = (sensor.sensor_pixels*used_res)/sensor.optical_res;
|
num_pixels = (sensor.sensor_pixels*used_res)/sensor.optical_res;
|
||||||
|
|
||||||
/* initial calibration reg values */
|
/* initial calibration reg values */
|
||||||
|
|
|
@ -1296,6 +1296,48 @@ void compute_session(Genesys_Device* dev, ScanSession& s, const Genesys_Sensor&
|
||||||
compute_session_buffer_sizes(dev->model->asic_type, s);
|
compute_session_buffer_sizes(dev->model->asic_type, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const SensorProfile& get_sensor_profile(AsicType asic_type, const Genesys_Sensor& sensor,
|
||||||
|
unsigned dpi, unsigned ccd_size_divisor)
|
||||||
|
{
|
||||||
|
int best_i = -1;
|
||||||
|
for (unsigned i = 0; i < sensor.sensor_profiles.size(); ++i) {
|
||||||
|
// exact match
|
||||||
|
if (sensor.sensor_profiles[i].dpi == dpi &&
|
||||||
|
sensor.sensor_profiles[i].ccd_size_divisor == ccd_size_divisor)
|
||||||
|
{
|
||||||
|
return sensor.sensor_profiles[i];
|
||||||
|
}
|
||||||
|
// closest match
|
||||||
|
if (sensor.sensor_profiles[i].ccd_size_divisor == ccd_size_divisor) {
|
||||||
|
if (best_i < 0) {
|
||||||
|
best_i = i;
|
||||||
|
} else {
|
||||||
|
if (sensor.sensor_profiles[i].dpi >= dpi &&
|
||||||
|
sensor.sensor_profiles[i].dpi < sensor.sensor_profiles[best_i].dpi)
|
||||||
|
{
|
||||||
|
best_i = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// default fallback
|
||||||
|
if (best_i < 0) {
|
||||||
|
DBG(DBG_warn, "%s: using default sensor profile\n", __func__);
|
||||||
|
if (asic_type == AsicType::GL123 || asic_type == AsicType::GL124)
|
||||||
|
return *s_fallback_sensor_profile_gl124;
|
||||||
|
if (asic_type == AsicType::GL845 || asic_type == AsicType::GL846)
|
||||||
|
return *s_fallback_sensor_profile_gl846;
|
||||||
|
if (asic_type == AsicType::GL847)
|
||||||
|
return *s_fallback_sensor_profile_gl847;
|
||||||
|
throw SaneException("Unknown asic type for default profile %d",
|
||||||
|
static_cast<unsigned>(asic_type));
|
||||||
|
}
|
||||||
|
|
||||||
|
return sensor.sensor_profiles[best_i];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/** @brief initialize device
|
/** @brief initialize device
|
||||||
* Initialize backend and ASIC : registers, motor tables, and gamma tables
|
* Initialize backend and ASIC : registers, motor tables, and gamma tables
|
||||||
* then ensure scanner's head is at home. Designed for gl846+ ASICs.
|
* then ensure scanner's head is at home. Designed for gl846+ ASICs.
|
||||||
|
|
|
@ -636,6 +636,9 @@ extern void sanei_genesys_generate_gamma_buffer(Genesys_Device* dev,
|
||||||
|
|
||||||
void compute_session(Genesys_Device* dev, ScanSession& s, const Genesys_Sensor& sensor);
|
void compute_session(Genesys_Device* dev, ScanSession& s, const Genesys_Sensor& sensor);
|
||||||
|
|
||||||
|
const SensorProfile& get_sensor_profile(AsicType asic_type, const Genesys_Sensor& sensor,
|
||||||
|
unsigned dpi, unsigned ccd_size_divisor);
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline T abs_diff(T a, T b)
|
inline T abs_diff(T a, T b)
|
||||||
{
|
{
|
||||||
|
|
Ładowanie…
Reference in New Issue