genesys: Use motor profiles from motor tables

merge-requests/318/head
Povilas Kanapickas 2020-01-31 20:13:14 +02:00
rodzic e5e8ea3d3f
commit 002d2ff2db
10 zmienionych plików z 34 dodań i 433 usunięć

Wyświetl plik

@ -535,7 +535,6 @@ libgenesys_la_SOURCES = genesys/genesys.cpp genesys/genesys.h \
genesys/tables_gpo.cpp \
genesys/tables_model.cpp \
genesys/tables_motor.cpp \
genesys/tables_motor_profile.cpp \
genesys/tables_sensor.cpp \
genesys/test_scanner_interface.h genesys/test_scanner_interface.cpp \
genesys/test_settings.h genesys/test_settings.cpp \

Wyświetl plik

@ -89,11 +89,11 @@ struct RawPixel;
// low.h
struct Genesys_USB_Device_Entry;
struct Motor_Profile;
// motor.h
struct Genesys_Motor;
struct MotorSlope;
struct MotorProfile;
struct MotorSlopeTable;
// register.h

Wyświetl plik

@ -4865,7 +4865,6 @@ void sane_init_impl(SANE_Int * version_code, SANE_Auth_Callback authorize)
genesys_init_frontend_tables();
genesys_init_gpo_tables();
genesys_init_motor_tables();
genesys_init_motor_profile_tables();
genesys_init_usb_device_tables();

Wyświetl plik

@ -466,7 +466,7 @@ void CommandSetGl124::set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor,
static void gl124_init_motor_regs_scan(Genesys_Device* dev,
const Genesys_Sensor& sensor,
Genesys_Register_Set* reg,
const Motor_Profile& motor_profile,
const MotorProfile& motor_profile,
unsigned int scan_exposure_time,
unsigned scan_yres,
unsigned int scan_lines,
@ -856,9 +856,7 @@ void CommandSetGl124::init_regs_for_scan_session(Genesys_Device* dev, const Gene
} else {
exposure_time = sensor.exposure_lperiod;
}
const auto& motor_profile = sanei_genesys_get_motor_profile(*s_motor_profiles,
dev->model->motor_id,
exposure_time);
const auto& motor_profile = get_motor_profile_by_exposure(dev->motor, exposure_time);
DBG(DBG_info, "%s : exposure_time=%d pixels\n", __func__, exposure_time);
DBG(DBG_info, "%s : scan_step_type=%d\n", __func__, static_cast<unsigned>(motor_profile.step_type));

Wyświetl plik

@ -801,7 +801,7 @@ void CommandSetGl843::set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor,
static void gl843_init_motor_regs_scan(Genesys_Device* dev,
const Genesys_Sensor& sensor,
Genesys_Register_Set* reg,
const Motor_Profile& motor_profile,
const MotorProfile& motor_profile,
unsigned int exposure,
unsigned scan_yres,
unsigned int scan_lines,
@ -1170,9 +1170,7 @@ void CommandSetGl843::init_regs_for_scan_session(Genesys_Device* dev, const Gene
if (exposure < 0) {
throw std::runtime_error("Exposure not defined in sensor definition");
}
const auto& motor_profile = sanei_genesys_get_motor_profile(*s_motor_profiles,
dev->model->motor_id,
exposure);
const auto& motor_profile = get_motor_profile_by_exposure(dev->motor, exposure);
DBG(DBG_info, "%s : exposure=%d pixels\n", __func__, exposure);
DBG(DBG_info, "%s : scan_step_type=%d\n", __func__,

Wyświetl plik

@ -327,7 +327,7 @@ void CommandSetGl846::set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor,
static void gl846_init_motor_regs_scan(Genesys_Device* dev,
const Genesys_Sensor& sensor,
Genesys_Register_Set* reg,
const Motor_Profile& motor_profile,
const MotorProfile& motor_profile,
unsigned int scan_exposure_time,
unsigned scan_yres,
unsigned int scan_lines,
@ -400,7 +400,7 @@ static void gl846_init_motor_regs_scan(Genesys_Device* dev,
fast_step_type = StepType::QUARTER;
}
Motor_Profile fast_motor_profile = motor_profile;
MotorProfile fast_motor_profile = motor_profile;
fast_motor_profile.step_type = fast_step_type;
auto fast_table = sanei_genesys_slope_table(dev->model->asic_type, fast_dpi,
@ -705,9 +705,7 @@ void CommandSetGl846::init_regs_for_scan_session(Genesys_Device* dev, const Gene
slope_dpi = slope_dpi * (1 + dummy);
exposure_time = sensor.exposure_lperiod;
const auto& motor_profile = sanei_genesys_get_motor_profile(*s_motor_profiles,
dev->model->motor_id,
exposure_time);
const auto& motor_profile = get_motor_profile_by_exposure(dev->motor, exposure_time);
DBG(DBG_info, "%s : exposure_time=%d pixels\n", __func__, exposure_time);
DBG(DBG_info, "%s : scan_step_type=%d\n", __func__,

Wyświetl plik

@ -354,7 +354,7 @@ void CommandSetGl847::set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor,
static void gl847_init_motor_regs_scan(Genesys_Device* dev,
const Genesys_Sensor& sensor,
Genesys_Register_Set* reg,
const Motor_Profile& motor_profile,
const MotorProfile& motor_profile,
unsigned int scan_exposure_time,
unsigned scan_yres,
unsigned int scan_lines,
@ -429,7 +429,7 @@ static void gl847_init_motor_regs_scan(Genesys_Device* dev,
fast_step_type = StepType::QUARTER;
}
Motor_Profile fast_motor_profile = motor_profile;
MotorProfile fast_motor_profile = motor_profile;
fast_motor_profile.step_type = fast_step_type;
auto fast_table = sanei_genesys_slope_table(dev->model->asic_type, fast_dpi,
@ -712,9 +712,7 @@ void CommandSetGl847::init_regs_for_scan_session(Genesys_Device* dev, const Gene
slope_dpi = slope_dpi * (1 + dummy);
exposure_time = sensor.exposure_lperiod;
const auto& motor_profile = sanei_genesys_get_motor_profile(*s_motor_profiles,
dev->model->motor_id,
exposure_time);
const auto& motor_profile = get_motor_profile_by_exposure(dev->motor, exposure_time);
DBG(DBG_info, "%s : exposure_time=%d pixels\n", __func__, exposure_time);
DBG(DBG_info, "%s : scan_step_type=%d\n", __func__,

Wyświetl plik

@ -1727,55 +1727,42 @@ void sanei_genesys_wait_for_home(Genesys_Device* dev)
* @param motors motor profile database
* @param motor_type motor id
* @param exposure exposure time
* @return a pointer to a Motor_Profile struct
* @return a pointer to a MotorProfile struct
*/
const Motor_Profile& sanei_genesys_get_motor_profile(const std::vector<Motor_Profile>& motors,
MotorId motor_id, int exposure)
const MotorProfile& get_motor_profile_by_exposure(const Genesys_Motor& motor, unsigned exposure)
{
int idx;
int best_i = -1;
idx=-1;
for (std::size_t i = 0; i < motors.size(); ++i) {
// exact match
if (motors[i].motor_id == motor_id && motors[i].exposure==exposure) {
return motors[i];
for (unsigned i = 0; i < motor.profiles.size(); ++i) {
const auto& profile = motor.profiles[i];
if (profile.max_exposure == exposure) {
return profile;
}
// closest match
if (motors[i].motor_id == motor_id) {
/* if profile exposure is higher than the required one,
* the entry is a candidate for the closest match */
if (motors[i].exposure == 0 || motors[i].exposure >= exposure)
{
if(idx<0)
{
/* no match found yet */
idx=i;
}
else
{
/* test for better match */
if(motors[i].exposure<motors[idx].exposure)
{
idx=i;
}
if (profile.max_exposure == 0 || profile.max_exposure >= exposure) {
if (best_i < 0) {
// no match found yet
best_i = i;
} else {
// test for better match
if (motor.profiles[i].max_exposure < motor.profiles[best_i].max_exposure) {
best_i = i;
}
}
}
}
/* default fallback */
if(idx<0)
{
if (best_i < 0) {
throw SaneException("Motor slope is not configured");
}
return motors[idx];
return motor.profiles[best_i];
}
MotorSlopeTable sanei_genesys_slope_table(AsicType asic_type, int dpi, int exposure, int base_dpi,
unsigned step_multiplier,
const Motor_Profile& motor_profile)
const MotorProfile& motor_profile)
{
unsigned target_speed_w = ((exposure * dpi) / base_dpi);
@ -1786,7 +1773,7 @@ MotorSlopeTable sanei_genesys_slope_table(AsicType asic_type, int dpi, int expos
}
MotorSlopeTable create_slope_table_fastest(AsicType asic_type, unsigned step_multiplier,
const Motor_Profile& motor_profile)
const MotorProfile& motor_profile)
{
return create_slope_table(motor_profile.slope, motor_profile.slope.max_speed_w,
motor_profile.step_type,

Wyświetl plik

@ -215,19 +215,6 @@ struct Genesys_USB_Device_Entry {
Genesys_Model model;
};
/**
* structure for motor database
*/
struct Motor_Profile
{
MotorId motor_id;
int exposure; // used only to select the wanted motor
StepType step_type; // default step type for given exposure
MotorSlope slope;
};
extern StaticInit<std::vector<Motor_Profile>> s_motor_profiles;
/*--------------------------------------------------------------------------*/
/* common functions needed by low level specific functions */
/*--------------------------------------------------------------------------*/
@ -401,15 +388,14 @@ void scanner_stop_action_no_move(Genesys_Device& dev, Genesys_Register_Set& regs
bool scanner_is_motor_stopped(Genesys_Device& dev);
const Motor_Profile& sanei_genesys_get_motor_profile(const std::vector<Motor_Profile>& motors,
MotorId motor_id, int exposure);
const MotorProfile& get_motor_profile_by_exposure(const Genesys_Motor& motor, unsigned exposure);
MotorSlopeTable sanei_genesys_slope_table(AsicType asic_type, int dpi, int exposure, int base_dpi,
unsigned step_multiplier,
const Motor_Profile& motor_profile);
const MotorProfile& motor_profile);
MotorSlopeTable create_slope_table_fastest(AsicType asic_type, unsigned step_multiplier,
const Motor_Profile& motor_profile);
const MotorProfile& motor_profile);
/** @brief find lowest motor resolution for the device.
* Parses the resolution list for motor and
@ -506,7 +492,6 @@ void genesys_init_sensor_tables();
void genesys_init_frontend_tables();
void genesys_init_gpo_tables();
void genesys_init_motor_tables();
void genesys_init_motor_profile_tables();
void genesys_init_usb_device_tables();
template<class T>

Wyświetl plik

@ -1,361 +0,0 @@
/* sane - Scanner Access Now Easy.
Copyright (C) 2019 Povilas Kanapickas <povilas@radix.lt>
This file is part of the SANE package.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, the authors of SANE give permission for
additional uses of the libraries contained in this release of SANE.
The exception is that, if you link a SANE library with other files
to produce an executable, this does not by itself cause the
resulting executable to be covered by the GNU General Public
License. Your use of that executable is in no way restricted on
account of linking the SANE library code into it.
This exception does not, however, invalidate any other reasons why
the executable file might be covered by the GNU General Public
License.
If you submit changes to SANE to the maintainers to be included in
a subsequent release, you agree by submitting the changes that
those changes may be distributed with this exception intact.
If you write modifications of your own for SANE, it is your choice
whether to permit this exception to apply to your modifications.
If you do not wish that, delete this exception notice.
*/
#define DEBUG_DECLARE_ONLY
#include "low.h"
namespace genesys {
StaticInit<std::vector<Motor_Profile>> s_motor_profiles;
void genesys_init_motor_profile_tables()
{
s_motor_profiles.init();
// gl843
auto profile = Motor_Profile();
profile.motor_id = MotorId::KVSS080;
profile.exposure = 8000;
profile.step_type = StepType::HALF;
profile.slope = MotorSlope::create_from_steps(44444, 500, 489);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::G4050;
profile.exposure = 8016;
profile.step_type = StepType::HALF;
profile.slope = MotorSlope::create_from_steps(7842, 320, 602);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::G4050;
profile.exposure = 15624;
profile.step_type = StepType::HALF;
profile.slope = MotorSlope::create_from_steps(9422, 254, 1004);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::G4050;
profile.exposure = 42752;
profile.step_type = StepType::QUARTER;
profile.slope = MotorSlope::create_from_steps(42752, 1706, 610);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::G4050;
profile.exposure = 56064;
profile.step_type = StepType::HALF;
profile.slope = MotorSlope::create_from_steps(28032, 2238, 604);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::CANON_4400F;
profile.exposure = 11640;
profile.step_type = StepType::HALF;
profile.slope = MotorSlope::create_from_steps(49152, 484, 1014);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::CANON_8400F;
profile.exposure = 50000;
profile.step_type = StepType::QUARTER;
profile.slope = MotorSlope::create_from_steps(8743, 300, 794);
s_motor_profiles->push_back(profile);
profile = Motor_Profile(); // BUG: this is a fallback slope that was selected previously
profile.motor_id = MotorId::CANON_8600F;
profile.exposure = 0;
profile.step_type = StepType::HALF;
profile.slope = MotorSlope::create_from_steps(44444, 500, 489);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::CANON_8600F;
profile.exposure = 0x59d8;
profile.step_type = StepType::QUARTER;
// FIXME: if the exposure is lower then we'll select another motor
profile.slope = MotorSlope::create_from_steps(54612, 1500, 219);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::PLUSTEK_OPTICFILM_7200I;
profile.exposure = 0;
profile.step_type = StepType::HALF;
profile.slope = MotorSlope::create_from_steps(39682, 1191, 15);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::PLUSTEK_OPTICFILM_7300;
profile.exposure = 0x2f44;
profile.step_type = StepType::QUARTER;
profile.slope = MotorSlope::create_from_steps(31250, 1512, 6);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::PLUSTEK_OPTICFILM_7500I;
profile.exposure = 0;
profile.step_type = StepType::QUARTER;
profile.slope = MotorSlope::create_from_steps(31250, 1375, 7);
s_motor_profiles->push_back(profile);
// gl846
profile = Motor_Profile();
profile.motor_id = MotorId::IMG101;
profile.exposure = 11000;
profile.step_type = StepType::HALF;
profile.slope = MotorSlope::create_from_steps(22000, 1000, 1017);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::PLUSTEK_OPTICBOOK_3800;
profile.exposure = 11000;
profile.step_type = StepType::HALF;
profile.slope = MotorSlope::create_from_steps(22000, 1000, 1017);
s_motor_profiles->push_back(profile);
// gl847
profile = Motor_Profile();
profile.motor_id = MotorId::CANON_LIDE_100;
profile.exposure = 2848;
profile.step_type = StepType::HALF;
profile.slope = MotorSlope::create_from_steps(46876, 534, 255);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::CANON_LIDE_100;
profile.exposure = 1424;
profile.step_type = StepType::HALF;
profile.slope = MotorSlope::create_from_steps(46876, 534, 255);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::CANON_LIDE_100;
profile.exposure = 1432;
profile.step_type = StepType::HALF;
profile.slope = MotorSlope::create_from_steps(46876, 534, 255);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::CANON_LIDE_100;
profile.exposure = 2712;
profile.step_type = StepType::QUARTER;
profile.slope = MotorSlope::create_from_steps(46876, 534, 279);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::CANON_LIDE_100;
profile.exposure = 5280;
profile.step_type = StepType::EIGHTH;
profile.slope = MotorSlope::create_from_steps(31680, 534, 247);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::CANON_LIDE_200;
profile.exposure = 2848;
profile.step_type = StepType::HALF;
profile.slope = MotorSlope::create_from_steps(46876, 534, 255);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::CANON_LIDE_200;
profile.exposure = 1424;
profile.step_type = StepType::HALF;
profile.slope = MotorSlope::create_from_steps(46876, 534, 255);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::CANON_LIDE_200;
profile.exposure = 1432;
profile.step_type = StepType::HALF;
profile.slope = MotorSlope::create_from_steps(46876, 534, 255);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::CANON_LIDE_200;
profile.exposure = 2712;
profile.step_type = StepType::QUARTER;
profile.slope = MotorSlope::create_from_steps(46876, 534, 279);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::CANON_LIDE_200;
profile.exposure = 5280;
profile.step_type = StepType::EIGHTH;
profile.slope = MotorSlope::create_from_steps(31680, 534, 247);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::CANON_LIDE_200;
profile.exposure = 10416;
profile.step_type = StepType::EIGHTH;
profile.slope = MotorSlope::create_from_steps(31680, 534, 247);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::CANON_LIDE_700;
profile.exposure = 2848;
profile.step_type = StepType::HALF;
profile.slope = MotorSlope::create_from_steps(46876, 534, 255);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::CANON_LIDE_700;
profile.exposure = 1424;
profile.step_type = StepType::HALF;
profile.slope = MotorSlope::create_from_steps(46876, 534, 255);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::CANON_LIDE_700;
profile.exposure = 1504;
profile.step_type = StepType::HALF;
profile.slope = MotorSlope::create_from_steps(46876, 534, 255);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::CANON_LIDE_700;
profile.exposure = 2696;
profile.step_type = StepType::HALF;
profile.slope = MotorSlope::create_from_steps(46876, 2022, 127);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::CANON_LIDE_700;
profile.exposure = 10576;
profile.step_type = StepType::EIGHTH;
profile.slope = MotorSlope::create_from_steps(46876, 15864, 2);
s_motor_profiles->push_back(profile);
// gl124
// NEXT LPERIOD=PREVIOUS*2-192
profile = Motor_Profile();
profile.motor_id = MotorId::CANON_LIDE_110;
profile.exposure = 2768;
profile.step_type = StepType::FULL;
profile.slope = MotorSlope::create_from_steps(62496, 335, 255);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::CANON_LIDE_110;
profile.exposure = 5360;
profile.step_type = StepType::HALF;
profile.slope = MotorSlope::create_from_steps(62496, 335, 469);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::CANON_LIDE_110;
profile.exposure = 10528;
profile.step_type = StepType::HALF;
profile.slope = MotorSlope::create_from_steps(62496, 2632, 3);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::CANON_LIDE_110;
profile.exposure = 20864;
profile.step_type = StepType::QUARTER;
profile.slope = MotorSlope::create_from_steps(62496, 10432, 3);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::CANON_LIDE_120;
profile.exposure = 4608;
profile.step_type = StepType::FULL;
profile.slope = MotorSlope::create_from_steps(62496, 864, 127);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::CANON_LIDE_120;
profile.exposure = 5360;
profile.step_type = StepType::HALF;
profile.slope = MotorSlope::create_from_steps(62496, 2010, 63);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::CANON_LIDE_120;
profile.exposure = 10528;
profile.step_type = StepType::QUARTER;
profile.slope = MotorSlope::create_from_steps(62464, 2632, 3);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::CANON_LIDE_120;
profile.exposure = 20864;
profile.step_type = StepType::QUARTER;
profile.slope = MotorSlope::create_from_steps(62592, 10432, 5);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::CANON_LIDE_210;
profile.exposure = 2768;
profile.step_type = StepType::FULL;
profile.slope = MotorSlope::create_from_steps(62496, 335, 255);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::CANON_LIDE_210;
profile.exposure = 5360;
profile.step_type = StepType::HALF;
profile.slope = MotorSlope::create_from_steps(62496, 335, 469);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::CANON_LIDE_210;
profile.exposure = 10528;
profile.step_type = StepType::HALF;
profile.slope = MotorSlope::create_from_steps(62496, 2632, 3);
s_motor_profiles->push_back(profile);
profile = Motor_Profile();
profile.motor_id = MotorId::CANON_LIDE_210;
profile.exposure = 20864;
profile.step_type = StepType::QUARTER;
profile.slope = MotorSlope::create_from_steps(62496, 10432, 4);
s_motor_profiles->push_back(profile);
}
} // namespace genesys