Merge branch 'genesys-refactor-model-list' into 'master'

genesys: Refactor model list

See merge request sane-project/backends!103
merge-requests/107/head
Povilas Kanapickas 2019-08-09 07:33:28 +00:00
commit 153602308c
8 zmienionych plików z 440 dodań i 430 usunięć

Wyświetl plik

@ -4914,19 +4914,10 @@ calc_parameters (Genesys_Scanner * s)
} }
static SANE_Status static void create_bpp_list (Genesys_Scanner * s, const std::vector<unsigned>& bpp)
create_bpp_list (Genesys_Scanner * s, SANE_Int * bpp)
{ {
int count; s->bpp_list[0] = bpp.size();
std::reverse_copy(bpp.begin(), bpp.end(), s->bpp_list + 1);
for (count = 0; bpp[count] != 0; count++)
;
s->bpp_list[0] = count;
for (count = 0; bpp[count] != 0; count++)
{
s->bpp_list[s->bpp_list[0] - count] = bpp[count];
}
return SANE_STATUS_GOOD;
} }
/** @brief this function initialize a gamma vector based on the ASIC: /** @brief this function initialize a gamma vector based on the ASIC:
@ -5087,7 +5078,7 @@ static SANE_Status
init_options (Genesys_Scanner * s) init_options (Genesys_Scanner * s)
{ {
DBG_HELPER(dbg); DBG_HELPER(dbg);
SANE_Int option, count, min_dpi; SANE_Int option;
SANE_Status status = SANE_STATUS_GOOD; SANE_Status status = SANE_STATUS_GOOD;
SANE_Word *dpi_list; SANE_Word *dpi_list;
Genesys_Model *model = s->dev->model; Genesys_Model *model = s->dev->model;
@ -5170,20 +5161,15 @@ init_options (Genesys_Scanner * s)
DISABLE (OPT_BIT_DEPTH); DISABLE (OPT_BIT_DEPTH);
/* resolution */ /* resolution */
min_dpi=200000; unsigned min_dpi = *std::min_element(model->xdpi_values.begin(), model->xdpi_values.end());
for (count = 0; model->xdpi_values[count] != 0; count++)
{ dpi_list = (SANE_Word*) malloc((model->xdpi_values.size() + 1) * sizeof(SANE_Word));
if(model->xdpi_values[count]<min_dpi) if (!dpi_list) {
{ return SANE_STATUS_NO_MEM;
min_dpi=model->xdpi_values[count];
}
} }
dpi_list = (SANE_Word*) malloc((count + 1) * sizeof(SANE_Word)); dpi_list[0] = model->xdpi_values.size();
if (!dpi_list) std::copy(model->xdpi_values.begin(), model->xdpi_values.end(), dpi_list + 1);
return SANE_STATUS_NO_MEM;
dpi_list[0] = count;
for (count = 0; model->xdpi_values[count] != 0; count++)
dpi_list[count + 1] = model->xdpi_values[count];
s->opt[OPT_RESOLUTION].name = SANE_NAME_SCAN_RESOLUTION; s->opt[OPT_RESOLUTION].name = SANE_NAME_SCAN_RESOLUTION;
s->opt[OPT_RESOLUTION].title = SANE_TITLE_SCAN_RESOLUTION; s->opt[OPT_RESOLUTION].title = SANE_TITLE_SCAN_RESOLUTION;
s->opt[OPT_RESOLUTION].desc = SANE_DESC_SCAN_RESOLUTION; s->opt[OPT_RESOLUTION].desc = SANE_DESC_SCAN_RESOLUTION;
@ -5712,7 +5698,6 @@ attach (SANE_String_Const devname, Genesys_Device ** devp, SANE_Bool may_wait)
DBG_HELPER_ARGS(dbg, "devp %s NULL, may_wait = %d", devp ? "!=" : "==", may_wait); DBG_HELPER_ARGS(dbg, "devp %s NULL, may_wait = %d", devp ? "!=" : "==", may_wait);
Genesys_Device *dev = 0; Genesys_Device *dev = 0;
unsigned int i;
if (devp) if (devp)
*devp = 0; *devp = 0;
@ -5754,18 +5739,17 @@ attach (SANE_String_Const devname, Genesys_Device ** devp, SANE_Bool may_wait)
} }
} }
bool found_dev = false; Genesys_USB_Device_Entry* found_usb_dev = nullptr;
for (i = 0; i < MAX_SCANNERS && genesys_usb_device_list[i].model != 0; i++) for (auto& usb_dev : *s_usb_devices) {
{ if (usb_dev.vendor == static_cast<unsigned>(vendor) &&
if (vendor == genesys_usb_device_list[i].vendor && usb_dev.product == static_cast<unsigned>(product))
product == genesys_usb_device_list[i].product) {
{ found_usb_dev = &usb_dev;
found_dev = true;
break; break;
} }
} }
if (!found_dev) { if (found_usb_dev == nullptr) {
DBG(DBG_error, "%s: vendor 0x%xd product 0x%xd is not supported by this backend\n", __func__, DBG(DBG_error, "%s: vendor 0x%xd product 0x%xd is not supported by this backend\n", __func__,
vendor, product); vendor, product);
return SANE_STATUS_INVAL; return SANE_STATUS_INVAL;
@ -5780,9 +5764,9 @@ attach (SANE_String_Const devname, Genesys_Device ** devp, SANE_Bool may_wait)
dev = &s_devices->back(); dev = &s_devices->back();
dev->file_name = new_devname; dev->file_name = new_devname;
dev->model = genesys_usb_device_list[i].model; dev->model = &found_usb_dev->model;
dev->vendorId = genesys_usb_device_list[i].vendor; dev->vendorId = found_usb_dev->vendor;
dev->productId = genesys_usb_device_list[i].product; dev->productId = found_usb_dev->product;
dev->usb_mode = 0; /* i.e. unset */ dev->usb_mode = 0; /* i.e. unset */
dev->already_initialized = SANE_FALSE; dev->already_initialized = SANE_FALSE;
@ -6075,6 +6059,8 @@ sane_init_impl(SANE_Int * version_code, SANE_Auth_Callback authorize)
s_sane_devices_ptrs.init(); s_sane_devices_ptrs.init();
genesys_init_sensor_tables(); genesys_init_sensor_tables();
genesys_init_frontend_tables(); genesys_init_frontend_tables();
genesys_init_usb_device_tables();
DBG(DBG_info, "%s: %s endian machine\n", __func__, DBG(DBG_info, "%s: %s endian machine\n", __func__,
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN

Wyświetl plik

@ -4670,7 +4670,7 @@ gl841_search_strip(Genesys_Device * dev, const Genesys_Sensor& sensor,
SANE_Status status = SANE_STATUS_GOOD; SANE_Status status = SANE_STATUS_GOOD;
Genesys_Register_Set local_reg; Genesys_Register_Set local_reg;
size_t size; size_t size;
int steps, depth, dpi; int steps, depth;
unsigned int pass, count, found, x, y, length; unsigned int pass, count, found, x, y, length;
char title[80]; char title[80];
GenesysRegister *r; GenesysRegister *r;
@ -4694,13 +4694,9 @@ gl841_search_strip(Genesys_Device * dev, const Genesys_Sensor& sensor,
return status; return status;
} }
/* set up for a gray scan at lowest dpi */ // set up for a gray scan at lowest dpi
dpi = 9600; unsigned dpi = *std::min_element(dev->model->xdpi_values.begin(),
for (x = 0; x < MAX_RESOLUTIONS; x++) dev->model->xdpi_values.end());
{
if (dev->model->xdpi_values[x] > 0 && dev->model->xdpi_values[x] < dpi)
dpi = dev->model->xdpi_values[x];
}
channels = 1; channels = 1;
/* shading calibation is done with dev->motor.base_ydpi */ /* shading calibation is done with dev->motor.base_ydpi */

Wyświetl plik

@ -2051,7 +2051,7 @@ static void gl843_set_xpa_lamp_power(Genesys_Device *dev, bool set)
DBG_HELPER(dbg); DBG_HELPER(dbg);
struct LampSettings { struct LampSettings {
int model_id; unsigned model_id;
ScanMethod scan_method; ScanMethod scan_method;
GenesysRegisterSettingSet regs_on; GenesysRegisterSettingSet regs_on;
GenesysRegisterSettingSet regs_off; GenesysRegisterSettingSet regs_off;

Wyświetl plik

@ -2548,7 +2548,7 @@ gl846_search_strip(Genesys_Device * dev, const Genesys_Sensor& sensor,
SANE_Status status = SANE_STATUS_GOOD; SANE_Status status = SANE_STATUS_GOOD;
Genesys_Register_Set local_reg; Genesys_Register_Set local_reg;
size_t size; size_t size;
int steps, depth, dpi; int steps, depth;
unsigned int pass, count, found, x, y; unsigned int pass, count, found, x, y;
char title[80]; char title[80];
GenesysRegister *r; GenesysRegister *r;
@ -2562,13 +2562,9 @@ gl846_search_strip(Genesys_Device * dev, const Genesys_Sensor& sensor,
return status; return status;
} }
/* set up for a gray scan at lowest dpi */ // set up for a gray scan at lowest dpi
dpi = 9600; unsigned dpi = *std::min_element(dev->model->xdpi_values.begin(),
for (x = 0; x < MAX_RESOLUTIONS; x++) dev->model->xdpi_values.end());
{
if (dev->model->xdpi_values[x] > 0 && dev->model->xdpi_values[x] < dpi)
dpi = dev->model->xdpi_values[x];
}
channels = 1; channels = 1;
/* 10 MM */ /* 10 MM */
/* lines = (10 * dpi) / MM_PER_INCH; */ /* lines = (10 * dpi) / MM_PER_INCH; */

Wyświetl plik

@ -2642,7 +2642,7 @@ gl847_search_strip (Genesys_Device * dev, const Genesys_Sensor& sensor,
SANE_Status status = SANE_STATUS_GOOD; SANE_Status status = SANE_STATUS_GOOD;
Genesys_Register_Set local_reg; Genesys_Register_Set local_reg;
size_t size; size_t size;
int steps, depth, dpi; int steps, depth;
unsigned int pass, count, found, x, y; unsigned int pass, count, found, x, y;
char title[80]; char title[80];
GenesysRegister *r; GenesysRegister *r;
@ -2655,13 +2655,9 @@ gl847_search_strip (Genesys_Device * dev, const Genesys_Sensor& sensor,
return status; return status;
} }
/* set up for a gray scan at lowest dpi */ // set up for a gray scan at lowest dpi
dpi = 9600; unsigned dpi = *std::min_element(dev->model->xdpi_values.begin(),
for (x = 0; x < MAX_RESOLUTIONS; x++) dev->model->xdpi_values.end());
{
if (dev->model->xdpi_values[x] > 0 && dev->model->xdpi_values[x] < dpi)
dpi = dev->model->xdpi_values[x];
}
channels = 1; channels = 1;
/* 10 MM */ /* 10 MM */
/* lines = (10 * dpi) / MM_PER_INCH; */ /* lines = (10 * dpi) / MM_PER_INCH; */

Wyświetl plik

@ -1566,18 +1566,7 @@ Motor_Profile *profile;
*/ */
int sanei_genesys_get_lowest_ydpi(Genesys_Device *dev) int sanei_genesys_get_lowest_ydpi(Genesys_Device *dev)
{ {
int min=20000; return *std::min_element(dev->model->ydpi_values.begin(), dev->model->ydpi_values.end());
int i=0;
while(dev->model->ydpi_values[i]!=0)
{
if(dev->model->ydpi_values[i]<min)
{
min=dev->model->ydpi_values[i];
}
i++;
}
return min;
} }
/** @brief returns the lowest possible dpi for the device /** @brief returns the lowest possible dpi for the device
@ -1587,27 +1576,10 @@ int sanei_genesys_get_lowest_ydpi(Genesys_Device *dev)
*/ */
int sanei_genesys_get_lowest_dpi(Genesys_Device *dev) int sanei_genesys_get_lowest_dpi(Genesys_Device *dev)
{ {
int min=20000; return std::min(*std::min_element(dev->model->xdpi_values.begin(),
int i=0; dev->model->xdpi_values.end()),
*std::min_element(dev->model->ydpi_values.begin(),
while(dev->model->ydpi_values[i]!=0) dev->model->ydpi_values.end()));
{
if(dev->model->ydpi_values[i]<min)
{
min=dev->model->ydpi_values[i];
}
i++;
}
i=0;
while(dev->model->xdpi_values[i]!=0)
{
if(dev->model->xdpi_values[i]<min)
{
min=dev->model->xdpi_values[i];
}
i++;
}
return min;
} }
/** @brief check is a cache entry may be used /** @brief check is a cache entry may be used

Wyświetl plik

@ -1153,67 +1153,111 @@ struct Genesys_Command_Set
* This structure describes a model. It is composed of information on the * This structure describes a model. It is composed of information on the
* sensor, the motor, scanner geometry and flags to drive operation. * sensor, the motor, scanner geometry and flags to drive operation.
*/ */
typedef struct Genesys_Model struct Genesys_Model
{ {
SANE_String_Const name; Genesys_Model() = default;
SANE_String_Const vendor;
SANE_String_Const model;
SANE_Int model_id;
SANE_Int asic_type; /* ASIC type gl646 or gl841 */ const char* name = nullptr;
Genesys_Command_Set *cmd_set; /* pointers to low level functions */ const char* vendor = nullptr;
const char* model = nullptr;
unsigned model_id = 0;
SANE_Int xdpi_values[MAX_RESOLUTIONS]; /* possible x resolutions */ // ASIC type gl646 or gl841
SANE_Int ydpi_values[MAX_RESOLUTIONS]; /* possible y resolutions */ unsigned asic_type = 0;
SANE_Int bpp_gray_values[MAX_DPI]; /* possible depths in gray mode */
SANE_Int bpp_color_values[MAX_DPI]; /* possible depths in color mode */ // pointers to low level functions
Genesys_Command_Set* cmd_set = nullptr;
// possible x resolutions
std::vector<unsigned> xdpi_values;
// possible y resolutions
std::vector<unsigned> ydpi_values;
// possible depths in gray mode
std::vector<unsigned> bpp_gray_values;
// possible depths in color mode
std::vector<unsigned> bpp_color_values;
// All offsets below are with respect to the sensor home position // All offsets below are with respect to the sensor home position
SANE_Fixed x_offset; /* Start of scan area in mm */
SANE_Fixed y_offset; /* Start of scan area in mm (Amount of
feeding needed to get to the medium) */
SANE_Fixed x_size; /* Size of scan area in mm */
SANE_Fixed y_size; /* Size of scan area in mm */
SANE_Fixed y_offset_calib; /* Start of white strip in mm */ // Start of scan area in mm
SANE_Fixed x_offset_mark; /* Start of black mark in mm */ SANE_Fixed x_offset = 0;
SANE_Fixed x_offset_ta; /* Start of scan area in TA mode in mm */ // Start of scan area in mm (Amount of feeding needed to get to the medium)
SANE_Fixed y_offset_ta; /* Start of scan area in TA mode in mm */ SANE_Fixed y_offset = 0;
SANE_Fixed x_size_ta; /* Size of scan area in TA mode in mm */
SANE_Fixed y_size_ta; /* Size of scan area in TA mode in mm */
// The position of the sensor when it's aligned with the lamp for transparency scanning // Size of scan area in mm
SANE_Fixed y_offset_sensor_to_ta; SANE_Fixed x_size = 0;
SANE_Fixed y_offset_calib_ta; /* Start of white strip in TA mode in mm */ // Size of scan area in mm
SANE_Fixed y_size = 0;
SANE_Fixed post_scan; /* Size of scan area after paper sensor stops // Start of white strip in mm
sensing document in mm */ SANE_Fixed y_offset_calib = 0;
SANE_Fixed eject_feed; /* Amount of feeding needed to eject document
after finishing scanning in mm */
/* Line-distance correction (in pixel at optical_ydpi) for CCD scanners */ // Start of black mark in mm
SANE_Int ld_shift_r; /* red */ SANE_Fixed x_offset_mark = 0;
SANE_Int ld_shift_g; /* green */
SANE_Int ld_shift_b; /* blue */
Genesys_Color_Order line_mode_color_order; /* Order of the CCD/CIS colors */ // Start of scan area in TA mode in mm
SANE_Fixed x_offset_ta = 0;
SANE_Bool is_cis; /* Is this a CIS or CCD scanner? */ // Start of scan area in TA mode in mm
SANE_Bool is_sheetfed; /* Is this sheetfed scanner? */ SANE_Fixed y_offset_ta = 0;
SANE_Int ccd_type; /* which SENSOR type do we have ? */ // Size of scan area in TA mode in mm
SANE_Int dac_type; /* which DAC do we have ? */ SANE_Fixed x_size_ta = 0;
SANE_Int gpo_type; /* General purpose output type */
SANE_Int motor_type; /* stepper motor type */ // Size of scan area in TA mode in mm
SANE_Word flags; /* Which hacks are needed for this scanner? */ SANE_Fixed y_size_ta = 0;
SANE_Word buttons; /* Button flags, described existing buttons for the model */
/*@} */ // The position of the sensor when it's aligned with the lamp for transparency scanning
SANE_Int shading_lines; /* how many lines are used for shading calibration */ SANE_Fixed y_offset_sensor_to_ta = 0;
SANE_Int shading_ta_lines; // how many lines are used for shading calibration in TA mode
SANE_Int search_lines; /* how many lines are used to search start position */ // Start of white strip in TA mode in mm
} Genesys_Model; SANE_Fixed y_offset_calib_ta = 0;
// Size of scan area after paper sensor stop sensing document in mm
SANE_Fixed post_scan = 0;
// Amount of feeding needed to eject document after finishing scanning in mm
SANE_Fixed eject_feed = 0;
// Line-distance correction (in pixel at optical_ydpi) for CCD scanners
SANE_Int ld_shift_r = 0;
SANE_Int ld_shift_g = 0;
SANE_Int ld_shift_b = 0;
// Order of the CCD/CIS colors
Genesys_Color_Order line_mode_color_order = COLOR_ORDER_RGB;
// Is this a CIS or CCD scanner?
SANE_Bool is_cis = false;
// Is this sheetfed scanner?
SANE_Bool is_sheetfed = false;
// sensor type
SANE_Int ccd_type = 0;
// Digital-Analog converter type (TODO: rename to ADC)
SANE_Int dac_type = 0;
// General purpose output type
SANE_Int gpo_type = 0;
// stepper motor type
SANE_Int motor_type = 0;
// Which hacks are needed for this scanner?
SANE_Word flags = 0;
// Button flags, described existing buttons for the model
SANE_Word buttons = 0;
// how many lines are used for shading calibration
SANE_Int shading_lines = 0;
// how many lines are used for shading calibration in TA mode
SANE_Int shading_ta_lines = 0;
// how many lines are used to search start position
SANE_Int search_lines = 0;
};
struct Genesys_Settings struct Genesys_Settings
{ {
@ -1630,12 +1674,19 @@ struct Genesys_Device
FILE *binary = nullptr; FILE *binary = nullptr;
}; };
typedef struct Genesys_USB_Device_Entry struct Genesys_USB_Device_Entry {
{
SANE_Word vendor; /**< USB vendor identifier */ Genesys_USB_Device_Entry(unsigned v, unsigned p, const Genesys_Model& m) :
SANE_Word product; /**< USB product identifier */ vendor(v), product(p), model(m)
Genesys_Model *model; /**< Scanner model information */ {}
} Genesys_USB_Device_Entry;
// USB vendor identifier
unsigned vendor;
// USB product identifier
unsigned product;
// Scanner model information
Genesys_Model model;
};
/** /**
* structure for motor database * structure for motor database
@ -2037,6 +2088,7 @@ private:
extern StaticInit<std::vector<Genesys_Sensor>> s_sensors; extern StaticInit<std::vector<Genesys_Sensor>> s_sensors;
void genesys_init_sensor_tables(); void genesys_init_sensor_tables();
void genesys_init_frontend_tables(); void genesys_init_frontend_tables();
void genesys_init_usb_device_tables();
void debug_dump(unsigned level, const Genesys_Settings& settings); void debug_dump(unsigned level, const Genesys_Settings& settings);
void debug_dump(unsigned level, const SetupParams& params); void debug_dump(unsigned level, const SetupParams& params);