From 05ed63fa34edd1e3c842b996f85d554bee8d8df1 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Fri, 13 Sep 2019 11:36:54 +0300 Subject: [PATCH] genesys: Move setup of read buffer to a single function --- backend/genesys_gl124.cc | 4 +--- backend/genesys_gl843.cc | 3 +-- backend/genesys_gl846.cc | 4 +--- backend/genesys_gl847.cc | 4 +--- backend/genesys_low.cc | 27 +++++++++++++++++++++++++++ backend/genesys_low.h | 2 ++ 6 files changed, 33 insertions(+), 11 deletions(-) diff --git a/backend/genesys_gl124.cc b/backend/genesys_gl124.cc index 19312a463..6f6c6695d 100644 --- a/backend/genesys_gl124.cc +++ b/backend/genesys_gl124.cc @@ -951,9 +951,7 @@ static void gl124_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens DBG (DBG_io2, "%s: pixels =%d\n", __func__, session.optical_pixels); DBG (DBG_io2, "%s: depth =%d\n", __func__, session.params.depth); - // BUG: we shouldn't multiply by channels here - dev->oe_buffer.clear(); - dev->oe_buffer.alloc(session.output_line_bytes_raw * session.params.channels); + build_image_pipeline(dev, session); // MAXWD is expressed in 2 words unit diff --git a/backend/genesys_gl843.cc b/backend/genesys_gl843.cc index 576820753..50e3703f5 100644 --- a/backend/genesys_gl843.cc +++ b/backend/genesys_gl843.cc @@ -1301,8 +1301,7 @@ static void gl843_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens dev->out_buffer.clear(); dev->out_buffer.alloc(session.buffer_size_out); - dev->oe_buffer.clear(); - dev->oe_buffer.alloc(session.output_line_bytes_raw * 2); + build_image_pipeline(dev, session); dev->read_bytes_left_after_deseg = session.output_line_bytes * session.output_line_count; diff --git a/backend/genesys_gl846.cc b/backend/genesys_gl846.cc index 9258b9ba5..26d80d0b3 100644 --- a/backend/genesys_gl846.cc +++ b/backend/genesys_gl846.cc @@ -821,9 +821,7 @@ static void gl846_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens DBG (DBG_io2, "%s: pixels =%d\n", __func__, session.optical_pixels); DBG (DBG_io2, "%s: depth =%d\n", __func__, session.params.depth); - // BUG: we shouldn't multiply by channels here - dev->oe_buffer.clear(); - dev->oe_buffer.alloc(session.output_line_bytes_raw * session.params.channels); + build_image_pipeline(dev, session); /* MAXWD is expressed in 4 words unit */ // BUG: we shouldn't multiply by channels here diff --git a/backend/genesys_gl847.cc b/backend/genesys_gl847.cc index efb198500..ee23eb1ee 100644 --- a/backend/genesys_gl847.cc +++ b/backend/genesys_gl847.cc @@ -838,9 +838,7 @@ static void gl847_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens DBG (DBG_io2, "%s: pixels =%d\n", __func__, session.optical_pixels); DBG (DBG_io2, "%s: depth =%d\n", __func__, session.params.depth); - // BUG: we shouldn't multiply by channels here - dev->oe_buffer.clear(); - dev->oe_buffer.alloc(session.output_line_bytes_raw * session.params.channels); + build_image_pipeline(dev, session); /* MAXWD is expressed in 4 words unit */ // BUG: we shouldn't multiply by channels here diff --git a/backend/genesys_low.cc b/backend/genesys_low.cc index 765cc0884..4678038f5 100644 --- a/backend/genesys_low.cc +++ b/backend/genesys_low.cc @@ -1387,6 +1387,33 @@ void compute_session(Genesys_Device* dev, ScanSession& s, const Genesys_Sensor& compute_session_buffer_sizes(dev->model->asic_type, s); } +static std::size_t get_usb_buffer_read_size(AsicType asic, const ScanSession& session) +{ + switch (asic) { + case AsicType::GL646: + // buffer not used on this chip set + return 1; + + case AsicType::GL124: + case AsicType::GL846: + case AsicType::GL847: + // BUG: we shouldn't multiply by channels here + return session.output_line_bytes_raw * session.params.channels; + + case AsicType::GL843: + return session.output_line_bytes_raw * 2; + + default: + throw SaneException("Unknown asic type"); + } +} + +void build_image_pipeline(Genesys_Device* dev, const ScanSession& session) +{ + dev->oe_buffer.clear(); + dev->oe_buffer.alloc(get_usb_buffer_read_size(dev->model->asic_type, session)); +} + const SensorProfile& get_sensor_profile(AsicType asic_type, const Genesys_Sensor& sensor, unsigned dpi, unsigned ccd_size_divisor) { diff --git a/backend/genesys_low.h b/backend/genesys_low.h index f5d0047a4..ac83eb682 100644 --- a/backend/genesys_low.h +++ b/backend/genesys_low.h @@ -638,6 +638,8 @@ extern void sanei_genesys_generate_gamma_buffer(Genesys_Device* dev, void compute_session(Genesys_Device* dev, ScanSession& s, const Genesys_Sensor& sensor); +void build_image_pipeline(Genesys_Device* dev, const ScanSession& session); + void genesys_fill_segmented_buffer(Genesys_Device* dev, uint8_t* work_buffer_dst, size_t size); const SensorProfile& get_sensor_profile(AsicType asic_type, const Genesys_Sensor& sensor,