Merge branch 'genesys-stagger-alignment' into 'master'

genesys: Align input pixel positions for unstaggering

See merge request sane-project/backends!465
merge-requests/244/head
Povilas Kanapickas 2020-05-23 11:18:09 +00:00
commit 51725d406f
4 zmienionych plików z 29 dodań i 62 usunięć

Wyświetl plik

@ -827,6 +827,12 @@ void compute_session_pixel_offsets(const Genesys_Device* dev, ScanSession& s,
s.pixel_endx = s.pixel_startx + s.optical_pixels_raw;
}
// align pixels to correct boundary for unstaggering
unsigned needed_x_alignment = std::max(s.stagger_x.size(), s.stagger_y.size());
unsigned aligned_pixel_startx = align_multiple_floor(s.pixel_startx, needed_x_alignment);
s.pixel_endx -= s.pixel_startx - aligned_pixel_startx;
s.pixel_startx = aligned_pixel_startx;
s.pixel_startx = sensor.pixel_count_ratio.apply(s.pixel_startx);
s.pixel_endx = sensor.pixel_count_ratio.apply(s.pixel_endx);
@ -838,49 +844,6 @@ void compute_session_pixel_offsets(const Genesys_Device* dev, ScanSession& s,
s.pixel_startx = align_multiple_floor(s.pixel_startx, sensor.pixel_count_ratio.divisor());
s.pixel_endx = align_multiple_floor(s.pixel_endx, sensor.pixel_count_ratio.divisor());
}
if (dev->model->asic_type == AsicType::GL646) {
if (sensor.stagger_y.max_shift() > 0 && (s.pixel_startx & 1) == 0)
{
s.pixel_startx++;
s.pixel_endx++;
}
} else if (dev->model->asic_type == AsicType::GL841 ||
dev->model->asic_type == AsicType::GL842 ||
dev->model->asic_type == AsicType::GL843)
{
// in case of stagger we have to start at an odd coordinate
// FIXME: we should probably just configure the image pipeline accordingly
bool stagger_starts_even = false;
if (dev->model->model_id == ModelId::CANON_4400F ||
dev->model->model_id == ModelId::CANON_8400F)
{
stagger_starts_even = true;
}
if (s.num_staggered_lines > 0) {
if (!stagger_starts_even && (s.pixel_startx & 1) == 0) {
s.pixel_startx++;
s.pixel_endx++;
} else if (stagger_starts_even && (s.pixel_startx & 1) != 0) {
s.pixel_startx++;
s.pixel_endx++;
}
}
} else if (dev->model->asic_type == AsicType::GL845 ||
dev->model->asic_type == AsicType::GL846 ||
dev->model->asic_type == AsicType::GL847)
{
if (s.num_staggered_lines > 0 && (s.pixel_startx & 1) == 0) {
s.pixel_startx++;
s.pixel_endx++;
}
} else if (dev->model->asic_type == AsicType::GL124) {
if (s.num_staggered_lines > 0 && (s.pixel_startx & 1) == 0) {
s.pixel_startx++;
s.pixel_endx++;
}
}
}
void compute_session(const Genesys_Device* dev, ScanSession& s, const Genesys_Sensor& sensor)
@ -1155,9 +1118,6 @@ void build_image_pipeline(Genesys_Device* dev, const ScanSession& session)
}
} else {
auto read_bytes_left_after_deseg = session.output_line_bytes * session.output_line_count;
if (dev->model->asic_type == AsicType::GL646) {
read_bytes_left_after_deseg *= dev->model->is_cis ? session.params.channels : 1;
}
dev->pipeline.push_first_node<ImagePipelineNodeBufferedGenesysUsb>(
width, lines, format, read_bytes_left_after_deseg,

Wyświetl plik

@ -443,11 +443,17 @@ inline T abs_diff(T a, T b)
inline uint64_t align_multiple_floor(uint64_t x, uint64_t multiple)
{
if (multiple == 0) {
return x;
}
return (x / multiple) * multiple;
}
inline uint64_t align_multiple_ceil(uint64_t x, uint64_t multiple)
{
if (multiple == 0) {
return x;
}
return ((x + multiple - 1) / multiple) * multiple;
}

Wyświetl plik

@ -87,6 +87,7 @@ public:
}
bool empty() const { return shifts_.empty(); }
std::size_t size() const { return shifts_.size(); }
const std::vector<std::size_t>& shifts() const { return shifts_; }
bool operator==(const StaggerConfig& other) const

Wyświetl plik

@ -275,7 +275,7 @@ void genesys_init_sensor_tables()
{ 0x5b, 0x00 }, { 0x5c, 0x00 }, { 0x5d, 0x00 }, { 0x5e, 0x00 }
}
},
{ { 1200 }, 1200, 1200, 11000, Ratio{1, 1}, 16, StaggerConfig{0, 4}, {
{ { 1200 }, 1200, 1200, 11000, Ratio{1, 1}, 16, StaggerConfig{4, 0}, {
{ 0x08, 0x0d }, { 0x09, 0x0f }, { 0x0a, 0x11 }, { 0x0b, 0x13 },
{ 0x16, 0x0b }, { 0x17, 0x0a }, { 0x18, 0x30 }, { 0x19, 0x2a },
{ 0x1a, 0x00 }, { 0x1b, 0x00 }, { 0x1c, 0x00 }, { 0x1d, 0x03 },
@ -368,7 +368,7 @@ void genesys_init_sensor_tables()
{ 0x5b, 0x00 }, { 0x5c, 0x00 }, { 0x5d, 0x00 }, { 0x5e, 0x00 }
}
},
{ { 1200 }, 1200, 21749, Ratio{1, 1}, 15, StaggerConfig{0, 4}, {
{ { 1200 }, 1200, 21749, Ratio{1, 1}, 15, StaggerConfig{4, 0}, {
{ 0x08, 0x02 }, { 0x09, 0x04 }, { 0x0a, 0x00 }, { 0x0b, 0x00 },
{ 0x16, 0xbf }, { 0x17, 0x08 }, { 0x18, 0x30 }, { 0x19, 0x2a },
{ 0x1a, 0x00 }, { 0x1b, 0x00 }, { 0x1c, 0xc0 }, { 0x1d, 0x42 },
@ -692,7 +692,7 @@ void genesys_init_sensor_tables()
{ 0x5b, 0x02 }, { 0x5c, 0x0e }, { 0x5d, 0x00 }, { 0x5e, 0x00 }
}
},
{ { 1200 }, 1200, 12750, Ratio{1, 1}, 16, StaggerConfig{0, 4}, {
{ { 1200 }, 1200, 12750, Ratio{1, 1}, 16, StaggerConfig{4, 0}, {
{ 0x08, 0x0d }, { 0x09, 0x0f }, { 0x0a, 0x11 }, { 0x0b, 0x13 },
{ 0x16, 0x2b }, { 0x17, 0x07 }, { 0x18, 0x30 }, { 0x19, 0x2a },
{ 0x1a, 0x00 }, { 0x1b, 0x00 }, { 0x1c, 0xc0 }, { 0x1d, 0x43 },
@ -1583,15 +1583,15 @@ void genesys_init_sensor_tables()
{ { 1200 }, 1200, 1200, 56064, ScanMethod::FLATBED, Ratio{1, 4}, 14,
StaggerConfig{}, regs_1200 },
{ { 2400 }, 2400, 2400, 56064, ScanMethod::FLATBED, Ratio{1, 2}, 29,
StaggerConfig{0, 4}, regs_2400 },
StaggerConfig{4, 0}, regs_2400 },
{ { 4800 }, 4800, 4800, 42752, ScanMethod::FLATBED, Ratio{1, 1}, 58,
StaggerConfig{0, 8}, regs_4800 },
StaggerConfig{8, 0}, regs_4800 },
{ { 100, 150, 200, 300, 400, 600, 1200 }, 600, 600, 15624, ScanMethod::TRANSPARENCY,
Ratio{1, 1}, 58, StaggerConfig{}, regs_ta_any }, // FIXME: may be incorrect
{ { 2400 }, 600, 600, 15624, ScanMethod::TRANSPARENCY,
Ratio{1, 1}, 58, StaggerConfig{0, 4}, regs_ta_any }, // FIXME: may be incorrect
Ratio{1, 1}, 58, StaggerConfig{4, 0}, regs_ta_any }, // FIXME: may be incorrect
{ { 4800 }, 600, 600, 15624, ScanMethod::TRANSPARENCY,
Ratio{1, 1}, 58, StaggerConfig{0, 8}, regs_ta_any }, // FIXME: may be incorrect
Ratio{1, 1}, 58, StaggerConfig{8, 0}, regs_ta_any }, // FIXME: may be incorrect
};
auto base_custom_regs = sensor.custom_regs;
@ -2186,7 +2186,7 @@ void genesys_init_sensor_tables()
},
{ { 4800 }, 4800, 4800, 45000, -1982, { ScanMethod::TRANSPARENCY,
ScanMethod::TRANSPARENCY_INFRARED },
StaggerConfig{0, 8}, {
StaggerConfig{8, 0}, {
{ 0x0c, 0x00 },
{ 0x16, 0x13 }, { 0x17, 0x15 }, { 0x18, 0x10 }, { 0x19, 0x2a },
{ 0x1a, 0x30 }, { 0x1b, 0x00 }, { 0x1c, 0x61 }, { 0x1d, 0x75 },
@ -3179,7 +3179,7 @@ void genesys_init_sensor_tables()
{ { 3600 }, ScanMethod::TRANSPARENCY, 3600, Ratio{2, 2}, 10, 0x2538, 600,
StaggerConfig{}, {} },
{ { 7200 }, ScanMethod::TRANSPARENCY, 7200, Ratio{1, 1}, 20, 0x19c8, 1200,
StaggerConfig{0, 4}, {
StaggerConfig{4, 0}, {
{ 0x02, 0x1b },
{ 0x03, 0x14 },
{ 0x04, 0x20 },
@ -3192,7 +3192,7 @@ void genesys_init_sensor_tables()
{ { 3600 }, ScanMethod::TRANSPARENCY_INFRARED, 3600, Ratio{2, 2}, 10, 0x1f54, 600,
StaggerConfig{}, {}},
{ { 7200 }, ScanMethod::TRANSPARENCY_INFRARED, 7200, Ratio{1, 1}, 20, 0x1f54, 1200,
StaggerConfig{0, 4}, {} },
StaggerConfig{4, 0}, {} },
};
for (const CustomSensorSettings& setting : custom_settings) {
@ -3267,7 +3267,7 @@ void genesys_init_sensor_tables()
{ { 900 }, 900, Ratio{8, 8}, 2, 150, StaggerConfig{} },
{ { 1800 }, 1800, Ratio{4, 4}, 5, 300, StaggerConfig{} },
{ { 3600 }, 3600, Ratio{2, 2}, 10, 600, StaggerConfig{} },
{ { 7200 }, 7200, Ratio{1, 1}, 20, 1200, StaggerConfig{0, 4} },
{ { 7200 }, 7200, Ratio{1, 1}, 20, 1200, StaggerConfig{4, 0} },
};
for (const CustomSensorSettings& setting : custom_settings) {
@ -3321,7 +3321,7 @@ void genesys_init_sensor_tables()
{ { 1200 }, 200, 20, StaggerConfig{} },
{ { 2400 }, 400, 40, StaggerConfig{} },
{ { 3600 }, 600, 60, StaggerConfig{} },
{ { 7200 }, 1200, 120, StaggerConfig{0, 4} },
{ { 7200 }, 1200, 120, StaggerConfig{4, 0} },
};
for (const CustomSensorSettings& setting : custom_settings) {
@ -3395,7 +3395,7 @@ void genesys_init_sensor_tables()
{ { 3600 }, ScanMethod::TRANSPARENCY, 3600, Ratio{2, 2}, 10, 0x2f44, 600,
StaggerConfig{} },
{ { 7200 }, ScanMethod::TRANSPARENCY, 7200, Ratio{1, 1}, 20, 0x2f44, 1200,
StaggerConfig{0, 4} },
StaggerConfig{4, 0} },
{ { 900 }, ScanMethod::TRANSPARENCY_INFRARED, 900, Ratio{8, 8}, 2, 0x2af8, 150,
StaggerConfig{} },
{ { 1800 }, ScanMethod::TRANSPARENCY_INFRARED, 1800, Ratio{4, 4}, 5, 0x2af8, 300,
@ -3403,7 +3403,7 @@ void genesys_init_sensor_tables()
{ { 3600 }, ScanMethod::TRANSPARENCY_INFRARED, 3600, Ratio{2, 2}, 10, 0x2af8, 600,
StaggerConfig{} },
{ { 7200 }, ScanMethod::TRANSPARENCY_INFRARED, 7200, Ratio{1, 1}, 20, 0x2af8, 1200,
StaggerConfig{0, 4} },
StaggerConfig{4, 0} },
};
for (const CustomSensorSettings& setting : custom_settings) {
@ -3459,11 +3459,11 @@ void genesys_init_sensor_tables()
{ { 900 }, ScanMethod::TRANSPARENCY, 150, 15, StaggerConfig{} },
{ { 1800 }, ScanMethod::TRANSPARENCY, 300, 30, StaggerConfig{} },
{ { 3600 }, ScanMethod::TRANSPARENCY, 600, 60, StaggerConfig{} },
{ { 7200 }, ScanMethod::TRANSPARENCY, 1200, 120, StaggerConfig{0, 4} },
{ { 7200 }, ScanMethod::TRANSPARENCY, 1200, 120, StaggerConfig{4, 0} },
{ { 900 }, ScanMethod::TRANSPARENCY_INFRARED, 150, 15, StaggerConfig{} },
{ { 1800 }, ScanMethod::TRANSPARENCY_INFRARED, 300, 30, StaggerConfig{} },
{ { 3600 }, ScanMethod::TRANSPARENCY_INFRARED, 600, 60, StaggerConfig{} },
{ { 7200 }, ScanMethod::TRANSPARENCY_INFRARED, 1200, 120, StaggerConfig{0, 4} },
{ { 7200 }, ScanMethod::TRANSPARENCY_INFRARED, 1200, 120, StaggerConfig{4, 0} },
};
for (const CustomSensorSettings& setting : custom_settings) {