kopia lustrzana https://gitlab.com/sane-project/backends
genesys: Remove get_closest_resolution()
All gl646 scanners have sensors for all supported resolutionspixma-axis-driver
rodzic
428293c1e2
commit
255da97fcb
|
@ -104,44 +104,6 @@ static void gl646_stop_motor(Genesys_Device* dev)
|
||||||
dev->interface->write_register(0x0f, 0x00);
|
dev->interface->write_register(0x0f, 0x00);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* find the closest match in mode tables for the given resolution and scan mode.
|
|
||||||
* @param sensor id of the sensor
|
|
||||||
* @param required required resolution
|
|
||||||
* @param color true is color mode
|
|
||||||
* @return the closest resolution for the sensor and mode
|
|
||||||
*/
|
|
||||||
static unsigned get_closest_resolution(SensorId sensor_id, int required, unsigned channels)
|
|
||||||
{
|
|
||||||
unsigned best_res = 0;
|
|
||||||
unsigned best_diff = 9600;
|
|
||||||
|
|
||||||
for (const auto& sensor : *s_sensors) {
|
|
||||||
if (sensor_id != sensor.sensor_id)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// exit on perfect match
|
|
||||||
if (sensor.resolutions.matches(required) && sensor.matches_channel_count(channels)) {
|
|
||||||
DBG(DBG_info, "%s: match found for %d\n", __func__, required);
|
|
||||||
return required;
|
|
||||||
}
|
|
||||||
|
|
||||||
// computes distance and keep mode if it is closer than previous
|
|
||||||
if (sensor.matches_channel_count(channels)) {
|
|
||||||
for (auto res : sensor.resolutions.resolutions()) {
|
|
||||||
unsigned curr_diff = std::abs(static_cast<int>(res) - static_cast<int>(required));
|
|
||||||
if (curr_diff < best_diff) {
|
|
||||||
best_res = res;
|
|
||||||
best_diff = curr_diff;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DBG(DBG_info, "%s: closest match for %d is %d\n", __func__, required, best_res);
|
|
||||||
return best_res;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the cksel values used by the required scan mode.
|
* Returns the cksel values used by the required scan mode.
|
||||||
* @param sensor id of the sensor
|
* @param sensor id of the sensor
|
||||||
|
@ -1820,7 +1782,6 @@ SensorExposure CommandSetGl646::led_calibration(Genesys_Device* dev, const Genes
|
||||||
int turn;
|
int turn;
|
||||||
uint16_t expr, expg, expb;
|
uint16_t expr, expg, expb;
|
||||||
Genesys_Settings settings;
|
Genesys_Settings settings;
|
||||||
SANE_Int resolution;
|
|
||||||
|
|
||||||
unsigned channels = dev->settings.get_channels();
|
unsigned channels = dev->settings.get_channels();
|
||||||
|
|
||||||
|
@ -1833,15 +1794,14 @@ SensorExposure CommandSetGl646::led_calibration(Genesys_Device* dev, const Genes
|
||||||
{
|
{
|
||||||
settings.scan_mode = ScanColorMode::GRAY;
|
settings.scan_mode = ScanColorMode::GRAY;
|
||||||
}
|
}
|
||||||
resolution = get_closest_resolution(dev->model->sensor_id, sensor.optical_res, channels);
|
|
||||||
|
|
||||||
/* offset calibration is always done in color mode */
|
// offset calibration is always done in color mode
|
||||||
settings.scan_method = dev->model->default_method;
|
settings.scan_method = dev->model->default_method;
|
||||||
settings.xres = resolution;
|
settings.xres = sensor.optical_res;
|
||||||
settings.yres = resolution;
|
settings.yres = sensor.optical_res;
|
||||||
settings.tl_x = 0;
|
settings.tl_x = 0;
|
||||||
settings.tl_y = 0;
|
settings.tl_y = 0;
|
||||||
settings.pixels = dev->model->x_size_calib_mm * resolution / MM_PER_INCH;
|
settings.pixels = dev->model->x_size_calib_mm * sensor.optical_res / MM_PER_INCH;
|
||||||
settings.requested_pixels = settings.pixels;
|
settings.requested_pixels = settings.pixels;
|
||||||
settings.lines = 1;
|
settings.lines = 1;
|
||||||
settings.depth = 16;
|
settings.depth = 16;
|
||||||
|
@ -1998,24 +1958,25 @@ static void ad_fe_offset_calibration(Genesys_Device* dev, const Genesys_Sensor&
|
||||||
|
|
||||||
unsigned int channels;
|
unsigned int channels;
|
||||||
int pass = 0;
|
int pass = 0;
|
||||||
SANE_Int resolution;
|
|
||||||
Genesys_Settings settings;
|
Genesys_Settings settings;
|
||||||
unsigned int x, y, adr, min;
|
unsigned int x, y, adr, min;
|
||||||
unsigned int bottom, black_pixels;
|
unsigned int bottom, black_pixels;
|
||||||
|
|
||||||
channels = 3;
|
channels = 3;
|
||||||
resolution = get_closest_resolution(dev->model->sensor_id, sensor.optical_res, channels);
|
|
||||||
const auto& calib_sensor = sanei_genesys_find_sensor(dev, resolution, 3, ScanMethod::FLATBED);
|
// FIXME: maybe reuse `sensor`
|
||||||
black_pixels = (calib_sensor.black_pixels * resolution) / calib_sensor.optical_res;
|
const auto& calib_sensor = sanei_genesys_find_sensor(dev, sensor.optical_res, 3,
|
||||||
|
ScanMethod::FLATBED);
|
||||||
|
black_pixels = (calib_sensor.black_pixels * sensor.optical_res) / calib_sensor.optical_res;
|
||||||
DBG(DBG_io2, "%s: black_pixels=%d\n", __func__, black_pixels);
|
DBG(DBG_io2, "%s: black_pixels=%d\n", __func__, black_pixels);
|
||||||
|
|
||||||
settings.scan_method = dev->model->default_method;
|
settings.scan_method = dev->model->default_method;
|
||||||
settings.scan_mode = ScanColorMode::COLOR_SINGLE_PASS;
|
settings.scan_mode = ScanColorMode::COLOR_SINGLE_PASS;
|
||||||
settings.xres = resolution;
|
settings.xres = sensor.optical_res;
|
||||||
settings.yres = resolution;
|
settings.yres = sensor.optical_res;
|
||||||
settings.tl_x = 0;
|
settings.tl_x = 0;
|
||||||
settings.tl_y = 0;
|
settings.tl_y = 0;
|
||||||
settings.pixels = dev->model->x_size_calib_mm * resolution / MM_PER_INCH;
|
settings.pixels = dev->model->x_size_calib_mm * sensor.optical_res / MM_PER_INCH;
|
||||||
settings.requested_pixels = settings.pixels;
|
settings.requested_pixels = settings.pixels;
|
||||||
settings.lines = CALIBRATION_LINES;
|
settings.lines = CALIBRATION_LINES;
|
||||||
settings.depth = 8;
|
settings.depth = 8;
|
||||||
|
@ -2097,7 +2058,6 @@ void CommandSetGl646::offset_calibration(Genesys_Device* dev, const Genesys_Sens
|
||||||
DBG_HELPER(dbg);
|
DBG_HELPER(dbg);
|
||||||
(void) regs;
|
(void) regs;
|
||||||
|
|
||||||
unsigned int channels;
|
|
||||||
int pass = 0, avg;
|
int pass = 0, avg;
|
||||||
Genesys_Settings settings;
|
Genesys_Settings settings;
|
||||||
int topavg, bottomavg;
|
int topavg, bottomavg;
|
||||||
|
@ -2112,10 +2072,11 @@ void CommandSetGl646::offset_calibration(Genesys_Device* dev, const Genesys_Sens
|
||||||
|
|
||||||
/* setup for a RGB scan, one full sensor's width line */
|
/* setup for a RGB scan, one full sensor's width line */
|
||||||
/* resolution is the one from the final scan */
|
/* resolution is the one from the final scan */
|
||||||
channels = 3;
|
unsigned resolution = dev->settings.xres;
|
||||||
int resolution = get_closest_resolution(dev->model->sensor_id, dev->settings.xres, channels);
|
unsigned channels = 3;
|
||||||
|
|
||||||
const auto& calib_sensor = sanei_genesys_find_sensor(dev, resolution, 3, ScanMethod::FLATBED);
|
const auto& calib_sensor = sanei_genesys_find_sensor(dev, resolution, channels,
|
||||||
|
ScanMethod::FLATBED);
|
||||||
black_pixels = (calib_sensor.black_pixels * resolution) / calib_sensor.optical_res;
|
black_pixels = (calib_sensor.black_pixels * resolution) / calib_sensor.optical_res;
|
||||||
|
|
||||||
DBG(DBG_io2, "%s: black_pixels=%d\n", __func__, black_pixels);
|
DBG(DBG_io2, "%s: black_pixels=%d\n", __func__, black_pixels);
|
||||||
|
@ -2243,7 +2204,7 @@ static void ad_fe_coarse_gain_calibration(Genesys_Device* dev, const Genesys_Sen
|
||||||
(void) regs;
|
(void) regs;
|
||||||
|
|
||||||
unsigned int i, channels, val;
|
unsigned int i, channels, val;
|
||||||
unsigned int size, count, resolution, pass;
|
unsigned int size, count, pass;
|
||||||
float average;
|
float average;
|
||||||
Genesys_Settings settings;
|
Genesys_Settings settings;
|
||||||
char title[32];
|
char title[32];
|
||||||
|
@ -2251,18 +2212,16 @@ static void ad_fe_coarse_gain_calibration(Genesys_Device* dev, const Genesys_Sen
|
||||||
/* setup for a RGB scan, one full sensor's width line */
|
/* setup for a RGB scan, one full sensor's width line */
|
||||||
/* resolution is the one from the final scan */
|
/* resolution is the one from the final scan */
|
||||||
channels = 3;
|
channels = 3;
|
||||||
resolution = get_closest_resolution(dev->model->sensor_id, dpi, channels);
|
const auto& calib_sensor = sanei_genesys_find_sensor(dev, dpi, 3, ScanMethod::FLATBED);
|
||||||
|
|
||||||
const auto& calib_sensor = sanei_genesys_find_sensor(dev, resolution, 3, ScanMethod::FLATBED);
|
|
||||||
|
|
||||||
settings.scan_mode = ScanColorMode::COLOR_SINGLE_PASS;
|
settings.scan_mode = ScanColorMode::COLOR_SINGLE_PASS;
|
||||||
|
|
||||||
settings.scan_method = dev->model->default_method;
|
settings.scan_method = dev->model->default_method;
|
||||||
settings.xres = resolution;
|
settings.xres = dpi;
|
||||||
settings.yres = resolution;
|
settings.yres = dpi;
|
||||||
settings.tl_x = 0;
|
settings.tl_x = 0;
|
||||||
settings.tl_y = 0;
|
settings.tl_y = 0;
|
||||||
settings.pixels = dev->model->x_size_calib_mm * resolution / MM_PER_INCH;
|
settings.pixels = dev->model->x_size_calib_mm * dpi / MM_PER_INCH;
|
||||||
settings.requested_pixels = settings.pixels;
|
settings.requested_pixels = settings.pixels;
|
||||||
settings.lines = CALIBRATION_LINES;
|
settings.lines = CALIBRATION_LINES;
|
||||||
settings.depth = 8;
|
settings.depth = 8;
|
||||||
|
@ -2342,7 +2301,7 @@ void CommandSetGl646::coarse_gain_calibration(Genesys_Device* dev, const Genesys
|
||||||
(void) dpi;
|
(void) dpi;
|
||||||
|
|
||||||
unsigned int i, j, k, channels, val, maximum, idx;
|
unsigned int i, j, k, channels, val, maximum, idx;
|
||||||
unsigned int count, resolution, pass;
|
unsigned count, pass;
|
||||||
float average[3];
|
float average[3];
|
||||||
Genesys_Settings settings;
|
Genesys_Settings settings;
|
||||||
char title[32];
|
char title[32];
|
||||||
|
@ -2355,26 +2314,26 @@ void CommandSetGl646::coarse_gain_calibration(Genesys_Device* dev, const Genesys
|
||||||
/* resolution is the one from the final scan */
|
/* resolution is the one from the final scan */
|
||||||
channels = 3;
|
channels = 3;
|
||||||
|
|
||||||
/* we are searching a sensor resolution */
|
// BUG: the following comment is incorrect
|
||||||
resolution = get_closest_resolution(dev->model->sensor_id, dev->settings.xres, channels);
|
// we are searching a sensor resolution */
|
||||||
|
const auto& calib_sensor = sanei_genesys_find_sensor(dev, dev->settings.xres, channels,
|
||||||
const auto& calib_sensor = sanei_genesys_find_sensor(dev, resolution, channels,
|
|
||||||
ScanMethod::FLATBED);
|
ScanMethod::FLATBED);
|
||||||
|
|
||||||
settings.scan_method = dev->settings.scan_method;
|
settings.scan_method = dev->settings.scan_method;
|
||||||
settings.scan_mode = ScanColorMode::COLOR_SINGLE_PASS;
|
settings.scan_mode = ScanColorMode::COLOR_SINGLE_PASS;
|
||||||
settings.xres = resolution;
|
settings.xres = dev->settings.xres;
|
||||||
settings.yres = resolution;
|
settings.yres = dev->settings.xres;
|
||||||
settings.tl_y = 0;
|
settings.tl_y = 0;
|
||||||
if (settings.scan_method == ScanMethod::FLATBED)
|
if (settings.scan_method == ScanMethod::FLATBED)
|
||||||
{
|
{
|
||||||
settings.tl_x = 0;
|
settings.tl_x = 0;
|
||||||
settings.pixels = dev->model->x_size_calib_mm * resolution / MM_PER_INCH;
|
settings.pixels = dev->model->x_size_calib_mm * dev->settings.xres / MM_PER_INCH;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
settings.tl_x = dev->model->x_offset_ta;
|
settings.tl_x = dev->model->x_offset_ta;
|
||||||
settings.pixels = static_cast<unsigned>((dev->model->x_size_ta * resolution) / MM_PER_INCH);
|
settings.pixels = static_cast<unsigned>(
|
||||||
|
(dev->model->x_size_ta * dev->settings.xres) / MM_PER_INCH);
|
||||||
}
|
}
|
||||||
settings.requested_pixels = settings.pixels;
|
settings.requested_pixels = settings.pixels;
|
||||||
settings.lines = CALIBRATION_LINES;
|
settings.lines = CALIBRATION_LINES;
|
||||||
|
@ -2502,12 +2461,11 @@ void CommandSetGl646::init_regs_for_warmup(Genesys_Device* dev, const Genesys_Se
|
||||||
(void) sensor;
|
(void) sensor;
|
||||||
|
|
||||||
Genesys_Settings settings;
|
Genesys_Settings settings;
|
||||||
int resolution, lines;
|
int lines;
|
||||||
|
|
||||||
dev->frontend = dev->frontend_initial;
|
dev->frontend = dev->frontend_initial;
|
||||||
|
|
||||||
resolution = get_closest_resolution(dev->model->sensor_id, 300, 1);
|
unsigned resolution = 300;
|
||||||
|
|
||||||
const auto& local_sensor = sanei_genesys_find_sensor(dev, resolution, 1,
|
const auto& local_sensor = sanei_genesys_find_sensor(dev, resolution, 1,
|
||||||
dev->settings.scan_method);
|
dev->settings.scan_method);
|
||||||
|
|
||||||
|
@ -2565,7 +2523,8 @@ static void gl646_repark_head(Genesys_Device* dev)
|
||||||
|
|
||||||
settings.scan_method = dev->model->default_method;
|
settings.scan_method = dev->model->default_method;
|
||||||
settings.scan_mode = ScanColorMode::COLOR_SINGLE_PASS;
|
settings.scan_mode = ScanColorMode::COLOR_SINGLE_PASS;
|
||||||
settings.xres = get_closest_resolution(dev->model->sensor_id, 75, 1);
|
settings.xres = dev->model->get_resolution_settings(dev->model->default_method)
|
||||||
|
.get_min_resolution_y();
|
||||||
settings.yres = settings.xres;
|
settings.yres = settings.xres;
|
||||||
settings.tl_x = 0;
|
settings.tl_x = 0;
|
||||||
settings.tl_y = 5;
|
settings.tl_y = 5;
|
||||||
|
|
Ładowanie…
Reference in New Issue