kopia lustrzana https://gitlab.com/sane-project/backends
genesys: Use calib_session to retrieve pixel counts
rodzic
87b2713628
commit
10fb42cd68
|
@ -63,7 +63,7 @@ struct Genesys_Calibration_Cache
|
|||
Genesys_Frontend frontend;
|
||||
Genesys_Sensor sensor;
|
||||
|
||||
size_t calib_pixels = 0;
|
||||
ScanSession session;
|
||||
size_t calib_channels = 0;
|
||||
size_t average_size = 0;
|
||||
std::vector<std::uint16_t> white_average_data;
|
||||
|
@ -75,7 +75,7 @@ struct Genesys_Calibration_Cache
|
|||
last_calibration == other.last_calibration &&
|
||||
frontend == other.frontend &&
|
||||
sensor == other.sensor &&
|
||||
calib_pixels == other.calib_pixels &&
|
||||
session == other.session &&
|
||||
calib_channels == other.calib_channels &&
|
||||
average_size == other.average_size &&
|
||||
white_average_data == other.white_average_data &&
|
||||
|
@ -94,7 +94,7 @@ void serialize(Stream& str, Genesys_Calibration_Cache& x)
|
|||
serialize_newline(str);
|
||||
serialize(str, x.sensor);
|
||||
serialize_newline(str);
|
||||
serialize(str, x.calib_pixels);
|
||||
serialize(str, x.session);
|
||||
serialize(str, x.calib_channels);
|
||||
serialize(str, x.average_size);
|
||||
serialize_newline(str);
|
||||
|
|
|
@ -239,13 +239,11 @@ std::ostream& operator<<(std::ostream& out, const Genesys_Device& dev)
|
|||
<< static_cast<unsigned>(dev.control[4]) << ' '
|
||||
<< static_cast<unsigned>(dev.control[5]) << '\n' << std::dec
|
||||
<< " average_size: " << dev.average_size << '\n'
|
||||
<< " calib_pixels: " << dev.calib_pixels << '\n'
|
||||
<< " calib_lines: " << dev.calib_lines << '\n'
|
||||
<< " calib_channels: " << dev.calib_channels << '\n'
|
||||
<< " calib_resolution: " << dev.calib_resolution << '\n'
|
||||
<< " calib_total_bytes_to_read: " << dev.calib_total_bytes_to_read << '\n'
|
||||
<< " calib_session: " << format_indent_braced_list(4, dev.calib_session) << '\n'
|
||||
<< " calib_pixels_offset: " << dev.calib_pixels_offset << '\n'
|
||||
<< " gamma_override_tables[0].size(): " << dev.gamma_override_tables[0].size() << '\n'
|
||||
<< " gamma_override_tables[1].size(): " << dev.gamma_override_tables[1].size() << '\n'
|
||||
<< " gamma_override_tables[2].size(): " << dev.gamma_override_tables[2].size() << '\n'
|
||||
|
|
|
@ -269,8 +269,6 @@ struct Genesys_Device
|
|||
std::uint8_t control[6] = {};
|
||||
|
||||
size_t average_size = 0;
|
||||
// number of pixels used during shading calibration
|
||||
size_t calib_pixels = 0;
|
||||
// number of lines used during shading calibration
|
||||
size_t calib_lines = 0;
|
||||
size_t calib_channels = 0;
|
||||
|
@ -281,11 +279,6 @@ struct Genesys_Device
|
|||
// the session that was configured for calibration
|
||||
ScanSession calib_session;
|
||||
|
||||
// certain scanners support much higher resolution when scanning transparency, but we can't
|
||||
// read whole width of the scanner as a single line at that resolution. Thus for stuff like
|
||||
// calibration we want to read only the possible calibration area.
|
||||
size_t calib_pixels_offset = 0;
|
||||
|
||||
// gamma overrides. If a respective array is not empty then it means that the gamma for that
|
||||
// color is overridden.
|
||||
std::vector<std::uint16_t> gamma_override_tables[3];
|
||||
|
|
|
@ -1669,11 +1669,14 @@ static void genesys_shading_calibration_impl(Genesys_Device* dev, const Genesys_
|
|||
uint32_t pixels_per_line;
|
||||
uint8_t channels;
|
||||
|
||||
/* end pixel - start pixel */
|
||||
pixels_per_line = dev->calib_pixels;
|
||||
if (dev->model->asic_type == AsicType::GL843) {
|
||||
pixels_per_line = dev->calib_session.output_pixels;
|
||||
} else {
|
||||
pixels_per_line = dev->calib_session.params.pixels;
|
||||
}
|
||||
channels = dev->calib_channels;
|
||||
|
||||
uint32_t out_pixels_per_line = pixels_per_line + dev->calib_pixels_offset;
|
||||
unsigned out_pixels_per_line = pixels_per_line + dev->calib_session.params.startx;
|
||||
|
||||
// FIXME: we set this during both dark and white calibration. A cleaner approach should
|
||||
// probably be used
|
||||
|
@ -1750,9 +1753,10 @@ static void genesys_shading_calibration_impl(Genesys_Device* dev, const Genesys_
|
|||
}
|
||||
|
||||
std::fill(out_average_data.begin(),
|
||||
out_average_data.begin() + dev->calib_pixels_offset * channels, 0);
|
||||
out_average_data.begin() + dev->calib_session.params.startx * channels, 0);
|
||||
|
||||
compute_array_percentile_approx(out_average_data.data() + dev->calib_pixels_offset * channels,
|
||||
compute_array_percentile_approx(out_average_data.data() +
|
||||
dev->calib_session.params.startx * channels,
|
||||
calibration_data.data(),
|
||||
dev->calib_lines, pixels_per_line * channels,
|
||||
0.5f);
|
||||
|
@ -1792,10 +1796,15 @@ static void genesys_dummy_dark_shading(Genesys_Device* dev, const Genesys_Sensor
|
|||
uint32_t skip, xend;
|
||||
int dummy1, dummy2, dummy3; /* dummy black average per channel */
|
||||
|
||||
pixels_per_line = dev->calib_pixels;
|
||||
if (dev->model->asic_type == AsicType::GL843) {
|
||||
pixels_per_line = dev->calib_session.output_pixels;
|
||||
} else {
|
||||
pixels_per_line = dev->calib_session.params.pixels;
|
||||
}
|
||||
|
||||
channels = dev->calib_channels;
|
||||
|
||||
uint32_t out_pixels_per_line = pixels_per_line + dev->calib_pixels_offset;
|
||||
unsigned out_pixels_per_line = pixels_per_line + dev->calib_session.params.startx;
|
||||
|
||||
dev->average_size = channels * out_pixels_per_line;
|
||||
dev->dark_average_data.clear();
|
||||
|
@ -1917,10 +1926,15 @@ static void genesys_dark_white_shading_calibration(Genesys_Device* dev,
|
|||
uint32_t dark, white, dark_sum, white_sum, dark_count, white_count, col,
|
||||
dif;
|
||||
|
||||
pixels_per_line = dev->calib_pixels;
|
||||
if (dev->model->asic_type == AsicType::GL843) {
|
||||
pixels_per_line = dev->calib_session.output_pixels;
|
||||
} else {
|
||||
pixels_per_line = dev->calib_session.params.pixels;
|
||||
}
|
||||
|
||||
channels = dev->calib_channels;
|
||||
|
||||
uint32_t out_pixels_per_line = pixels_per_line + dev->calib_pixels_offset;
|
||||
unsigned out_pixels_per_line = pixels_per_line + dev->calib_session.params.startx;
|
||||
|
||||
dev->average_size = channels * out_pixels_per_line;
|
||||
|
||||
|
@ -1978,12 +1992,14 @@ static void genesys_dark_white_shading_calibration(Genesys_Device* dev,
|
|||
|
||||
|
||||
std::fill(dev->dark_average_data.begin(),
|
||||
dev->dark_average_data.begin() + dev->calib_pixels_offset * channels, 0);
|
||||
dev->dark_average_data.begin() + dev->calib_session.params.startx * channels, 0);
|
||||
std::fill(dev->white_average_data.begin(),
|
||||
dev->white_average_data.begin() + dev->calib_pixels_offset * channels, 0);
|
||||
dev->white_average_data.begin() + dev->calib_session.params.startx * channels, 0);
|
||||
|
||||
uint16_t* average_white = dev->white_average_data.data() + dev->calib_pixels_offset * channels;
|
||||
uint16_t* average_dark = dev->dark_average_data.data() + dev->calib_pixels_offset * channels;
|
||||
uint16_t* average_white = dev->white_average_data.data() +
|
||||
dev->calib_session.params.startx * channels;
|
||||
uint16_t* average_dark = dev->dark_average_data.data() +
|
||||
dev->calib_session.params.startx * channels;
|
||||
|
||||
for (x = 0; x < pixels_per_line * channels; x++)
|
||||
{
|
||||
|
@ -2529,7 +2545,12 @@ static void genesys_send_shading_coefficient(Genesys_Device* dev, const Genesys_
|
|||
unsigned int factor;
|
||||
unsigned int coeff, target_code, words_per_color = 0;
|
||||
|
||||
pixels_per_line = dev->calib_pixels + dev->calib_pixels_offset;
|
||||
if (dev->model->asic_type == AsicType::GL843) {
|
||||
pixels_per_line = dev->calib_session.output_pixels + dev->calib_session.params.startx;
|
||||
} else {
|
||||
pixels_per_line = dev->calib_session.params.pixels + dev->calib_session.params.startx;
|
||||
}
|
||||
|
||||
channels = dev->calib_channels;
|
||||
|
||||
/* we always build data for three channels, even for gray
|
||||
|
@ -2823,8 +2844,8 @@ genesys_restore_calibration(Genesys_Device * dev, Genesys_Sensor& sensor)
|
|||
/* we don't restore the gamma fields */
|
||||
sensor.exposure = cache.sensor.exposure;
|
||||
|
||||
dev->calib_session = cache.session;
|
||||
dev->average_size = cache.average_size;
|
||||
dev->calib_pixels = cache.calib_pixels;
|
||||
dev->calib_channels = cache.calib_channels;
|
||||
|
||||
dev->dark_average_data = cache.dark_average_data;
|
||||
|
@ -2879,7 +2900,7 @@ static void genesys_save_calibration(Genesys_Device* dev, const Genesys_Sensor&
|
|||
found_cache_it->frontend = dev->frontend;
|
||||
found_cache_it->sensor = sensor;
|
||||
|
||||
found_cache_it->calib_pixels = dev->calib_pixels;
|
||||
found_cache_it->session = dev->calib_session;
|
||||
found_cache_it->calib_channels = dev->calib_channels;
|
||||
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
|
@ -4688,7 +4709,7 @@ static void probe_genesys_devices()
|
|||
of Genesys_Calibration_Cache as is.
|
||||
*/
|
||||
static const char* CALIBRATION_IDENT = "sane_genesys";
|
||||
static const int CALIBRATION_VERSION = 23;
|
||||
static const int CALIBRATION_VERSION = 24;
|
||||
|
||||
bool read_calibration(std::istream& str, Genesys_Device::Calibration& calibration,
|
||||
const std::string& path)
|
||||
|
|
|
@ -1198,7 +1198,6 @@ void CommandSetGl124::init_regs_for_shading(Genesys_Device* dev, const Genesys_S
|
|||
dev->calib_resolution = resolution;
|
||||
dev->calib_total_bytes_to_read = 0;
|
||||
factor = calib_sensor.optical_res / resolution;
|
||||
dev->calib_pixels = calib_sensor.sensor_pixels / factor;
|
||||
|
||||
/* distance to move to reach white target at high resolution */
|
||||
move=0;
|
||||
|
@ -1213,7 +1212,7 @@ void CommandSetGl124::init_regs_for_shading(Genesys_Device* dev, const Genesys_S
|
|||
session.params.yres = resolution;
|
||||
session.params.startx = 0;
|
||||
session.params.starty = move;
|
||||
session.params.pixels = dev->calib_pixels;
|
||||
session.params.pixels = calib_sensor.sensor_pixels / factor;
|
||||
session.params.lines = dev->calib_lines;
|
||||
session.params.depth = 16;
|
||||
session.params.channels = dev->calib_channels;
|
||||
|
@ -1665,7 +1664,6 @@ void CommandSetGl124::offset_calibration(Genesys_Device* dev, const Genesys_Sens
|
|||
|
||||
/* offset calibration is always done in color mode */
|
||||
channels = 3;
|
||||
dev->calib_pixels = sensor.sensor_pixels;
|
||||
lines=1;
|
||||
pixels = (sensor.sensor_pixels * sensor.optical_res) / sensor.optical_res;
|
||||
black_pixels = (sensor.black_pixels * sensor.optical_res) / sensor.optical_res;
|
||||
|
|
|
@ -1709,7 +1709,6 @@ void CommandSetGl646::init_regs_for_shading(Genesys_Device* dev, const Genesys_S
|
|||
true, false, false, false);
|
||||
|
||||
/* used when sending shading calibration data */
|
||||
dev->calib_pixels = settings.pixels;
|
||||
dev->calib_channels = dev->session.params.channels;
|
||||
if (!dev->model->is_cis) {
|
||||
dev->calib_channels = 3;
|
||||
|
|
|
@ -2464,14 +2464,12 @@ void CommandSetGl841::init_regs_for_shading(Genesys_Device* dev, const Genesys_S
|
|||
const auto& calib_sensor = sanei_genesys_find_sensor(dev, resolution, dev->calib_channels,
|
||||
dev->settings.scan_method);
|
||||
|
||||
dev->calib_pixels = calib_sensor.sensor_pixels / factor;
|
||||
|
||||
ScanSession session;
|
||||
session.params.xres = resolution;
|
||||
session.params.yres = ydpi;
|
||||
session.params.startx = 0;
|
||||
session.params.starty = starty;
|
||||
session.params.pixels = dev->calib_pixels;
|
||||
session.params.pixels = calib_sensor.sensor_pixels / factor;
|
||||
session.params.lines = dev->calib_lines;
|
||||
session.params.depth = 16;
|
||||
session.params.channels = dev->calib_channels;
|
||||
|
|
|
@ -1715,6 +1715,9 @@ void CommandSetGl843::init_regs_for_shading(Genesys_Device* dev, const Genesys_S
|
|||
const auto& calib_sensor = sanei_genesys_find_sensor(dev, resolution, dev->calib_channels,
|
||||
dev->settings.scan_method);
|
||||
|
||||
unsigned calib_pixels = 0;
|
||||
unsigned calib_pixels_offset = 0;
|
||||
|
||||
if (should_calibrate_only_active_area(*dev, dev->settings)) {
|
||||
float offset = get_model_x_offset_ta(*dev, dev->settings);
|
||||
offset /= calib_sensor.get_ccd_size_divisor_for_dpi(resolution);
|
||||
|
@ -1724,13 +1727,11 @@ void CommandSetGl843::init_regs_for_shading(Genesys_Device* dev, const Genesys_S
|
|||
size /= calib_sensor.get_ccd_size_divisor_for_dpi(resolution);
|
||||
size = static_cast<float>((size * resolution) / MM_PER_INCH);
|
||||
|
||||
dev->calib_pixels_offset = static_cast<std::size_t>(offset);
|
||||
dev->calib_pixels = static_cast<std::size_t>(size);
|
||||
}
|
||||
else
|
||||
{
|
||||
dev->calib_pixels_offset = 0;
|
||||
dev->calib_pixels = calib_sensor.sensor_pixels / factor;
|
||||
calib_pixels_offset = static_cast<std::size_t>(offset);
|
||||
calib_pixels = static_cast<std::size_t>(size);
|
||||
} else {
|
||||
calib_pixels_offset = 0;
|
||||
calib_pixels = calib_sensor.sensor_pixels / factor;
|
||||
}
|
||||
|
||||
dev->calib_resolution = resolution;
|
||||
|
@ -1756,9 +1757,9 @@ void CommandSetGl843::init_regs_for_shading(Genesys_Device* dev, const Genesys_S
|
|||
ScanSession session;
|
||||
session.params.xres = resolution;
|
||||
session.params.yres = resolution;
|
||||
session.params.startx = dev->calib_pixels_offset;
|
||||
session.params.startx = calib_pixels_offset;
|
||||
session.params.starty = move;
|
||||
session.params.pixels = dev->calib_pixels;
|
||||
session.params.pixels = calib_pixels;
|
||||
session.params.lines = dev->calib_lines;
|
||||
session.params.depth = 16;
|
||||
session.params.channels = dev->calib_channels;
|
||||
|
@ -1770,9 +1771,6 @@ void CommandSetGl843::init_regs_for_shading(Genesys_Device* dev, const Genesys_S
|
|||
|
||||
init_regs_for_scan_session(dev, calib_sensor, ®s, session);
|
||||
|
||||
// the pixel number may be updated to conform to scanner constraints
|
||||
dev->calib_pixels = session.output_pixels;
|
||||
|
||||
dev->calib_session = session;
|
||||
dev->calib_total_bytes_to_read = session.output_total_bytes_raw;
|
||||
}
|
||||
|
|
|
@ -970,11 +970,11 @@ void CommandSetGl846::init_regs_for_shading(Genesys_Device* dev, const Genesys_S
|
|||
if (dev->calib_resolution==4800) {
|
||||
dev->calib_lines *= 2;
|
||||
}
|
||||
dev->calib_pixels = (calib_sensor.sensor_pixels * dev->calib_resolution) /
|
||||
calib_sensor.optical_res;
|
||||
unsigned calib_pixels = (calib_sensor.sensor_pixels * dev->calib_resolution) /
|
||||
calib_sensor.optical_res;
|
||||
|
||||
DBG(DBG_io, "%s: calib_lines = %zu\n", __func__, dev->calib_lines);
|
||||
DBG(DBG_io, "%s: calib_pixels = %zu\n", __func__, dev->calib_pixels);
|
||||
DBG(DBG_io, "%s: calib_pixels = %u\n", __func__, calib_pixels);
|
||||
|
||||
/* this is aworkaround insufficent distance for slope
|
||||
* motor acceleration TODO special motor slope for shading */
|
||||
|
@ -989,7 +989,7 @@ void CommandSetGl846::init_regs_for_shading(Genesys_Device* dev, const Genesys_S
|
|||
session.params.yres = dev->calib_resolution;
|
||||
session.params.startx = 0;
|
||||
session.params.starty = static_cast<unsigned>(move);
|
||||
session.params.pixels = dev->calib_pixels;
|
||||
session.params.pixels = calib_pixels;
|
||||
session.params.lines = dev->calib_lines;
|
||||
session.params.depth = 16;
|
||||
session.params.channels = dev->calib_channels;
|
||||
|
@ -1734,7 +1734,6 @@ void CommandSetGl846::offset_calibration(Genesys_Device* dev, const Genesys_Sens
|
|||
|
||||
/* offset calibration is always done in color mode */
|
||||
channels = 3;
|
||||
dev->calib_pixels = sensor.sensor_pixels;
|
||||
lines=1;
|
||||
pixels = (sensor.sensor_pixels * sensor.optical_res) / sensor.optical_res;
|
||||
black_pixels = (sensor.black_pixels * sensor.optical_res) / sensor.optical_res;
|
||||
|
|
|
@ -978,18 +978,18 @@ void CommandSetGl847::init_regs_for_shading(Genesys_Device* dev, const Genesys_S
|
|||
if (dev->calib_resolution == 4800) {
|
||||
dev->calib_lines *= 2;
|
||||
}
|
||||
dev->calib_pixels = (calib_sensor.sensor_pixels * dev->calib_resolution) /
|
||||
calib_sensor.optical_res;
|
||||
unsigned calib_pixels = (calib_sensor.sensor_pixels * dev->calib_resolution) /
|
||||
calib_sensor.optical_res;
|
||||
|
||||
DBG(DBG_io, "%s: calib_lines = %zu\n", __func__, dev->calib_lines);
|
||||
DBG(DBG_io, "%s: calib_pixels = %zu\n", __func__, dev->calib_pixels);
|
||||
DBG(DBG_io, "%s: calib_pixels = %u\n", __func__, calib_pixels);
|
||||
|
||||
ScanSession session;
|
||||
session.params.xres = dev->calib_resolution;
|
||||
session.params.yres = dev->motor.base_ydpi;
|
||||
session.params.startx = 0;
|
||||
session.params.starty = 20;
|
||||
session.params.pixels = dev->calib_pixels;
|
||||
session.params.pixels = calib_pixels;
|
||||
session.params.lines = dev->calib_lines;
|
||||
session.params.depth = 16;
|
||||
session.params.channels = dev->calib_channels;
|
||||
|
@ -1769,7 +1769,6 @@ void CommandSetGl847::offset_calibration(Genesys_Device* dev, const Genesys_Sens
|
|||
|
||||
/* offset calibration is always done in color mode */
|
||||
channels = 3;
|
||||
dev->calib_pixels = sensor.sensor_pixels;
|
||||
lines=1;
|
||||
pixels= (sensor.sensor_pixels * sensor.optical_res) / sensor.optical_res;
|
||||
black_pixels = (sensor.black_pixels * sensor.optical_res) / sensor.optical_res;
|
||||
|
|
|
@ -104,7 +104,6 @@ Genesys_Calibration_Cache create_fake_calibration_entry()
|
|||
sensor.gamma = {1.0, 1.0, 1.0};
|
||||
calib.sensor = sensor;
|
||||
|
||||
calib.calib_pixels = 12345;
|
||||
calib.calib_channels = 3;
|
||||
calib.average_size = 7;
|
||||
calib.white_average_data = { 8, 7, 6, 5, 4, 3, 2 };
|
||||
|
|
Ładowanie…
Reference in New Issue