From 827c3a049db4391501dda81f2999df8e4d011403 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Thu, 12 Sep 2019 21:26:51 +0300 Subject: [PATCH 1/8] genesys: Rename ScanSession::output_{line_channel => channel}_bytes --- backend/genesys_gl646.cc | 2 +- backend/genesys_gl843.cc | 4 ++-- backend/genesys_low.cc | 4 ++-- backend/genesys_settings.h | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/genesys_gl646.cc b/backend/genesys_gl646.cc index 8cbb807c6..c8777db25 100644 --- a/backend/genesys_gl646.cc +++ b/backend/genesys_gl646.cc @@ -563,7 +563,7 @@ static void gl646_setup_registers(Genesys_Device* dev, DBG(DBG_info, "%s: startx=%d, endx=%d, ccd_size_divisor=%d\n", __func__, sx, ex, session.ccd_size_divisor); - dev->bpl = session.output_line_channel_bytes; + dev->bpl = session.output_channel_bytes; dev->wpl = session.output_line_bytes; regs->set24(REG_MAXWD, session.output_line_bytes); diff --git a/backend/genesys_gl843.cc b/backend/genesys_gl843.cc index c187356cb..b18009ab7 100644 --- a/backend/genesys_gl843.cc +++ b/backend/genesys_gl843.cc @@ -1157,8 +1157,8 @@ static void gl843_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens reg->set16(REG_STRPIXEL, session.pixel_startx); reg->set16(REG_ENDPIXEL, session.pixel_endx); - dev->wpl = session.output_line_channel_bytes; // FIXME: this is not currently used - dev->bpl = session.output_line_channel_bytes; // FIXME: this is not currently used + dev->wpl = session.output_channel_bytes; // FIXME: this is not currently used + dev->bpl = session.output_channel_bytes; // FIXME: this is not currently used DBG(DBG_io2, "%s: pixels =%d\n", __func__, session.optical_pixels); DBG(DBG_io2, "%s: depth =%d\n", __func__, session.params.depth); diff --git a/backend/genesys_low.cc b/backend/genesys_low.cc index aa3b70215..67c90cc11 100644 --- a/backend/genesys_low.cc +++ b/backend/genesys_low.cc @@ -1280,8 +1280,8 @@ void compute_session(Genesys_Device* dev, ScanSession& s, const Genesys_Sensor& s.output_line_count = s.params.lines + s.max_color_shift_lines + s.num_staggered_lines; - s.output_line_channel_bytes = multiply_by_depth_ceil(s.output_pixels, s.params.depth); - s.output_line_bytes = s.output_line_channel_bytes * s.params.channels; + s.output_channel_bytes = multiply_by_depth_ceil(s.output_pixels, s.params.depth); + s.output_line_bytes = s.output_channel_bytes * s.params.channels; compute_session_buffer_sizes(dev->model->asic_type, s); } diff --git a/backend/genesys_settings.h b/backend/genesys_settings.h index ca15d6d3c..e7bf55c2e 100644 --- a/backend/genesys_settings.h +++ b/backend/genesys_settings.h @@ -238,7 +238,7 @@ struct ScanSession { unsigned output_pixels = 0; // the number of bytes in the output of a channel of a single line - unsigned output_line_channel_bytes; + unsigned output_channel_bytes = 0; // the number of bytes in the output of a single line unsigned output_line_bytes = 0; From dd702968279b4328d0650853a15cc4bf96542494 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Thu, 12 Sep 2019 21:26:52 +0300 Subject: [PATCH 2/8] genesys: Move desegmentation line width data to a separate struct --- backend/genesys.cc | 4 ++-- backend/genesys_device.h | 18 +++++++++++++----- backend/genesys_gl124.cc | 25 ++++++++++++------------- backend/genesys_gl646.cc | 7 ++++--- backend/genesys_gl841.cc | 6 +++--- backend/genesys_gl843.cc | 12 ++++++------ backend/genesys_gl846.cc | 14 ++++++-------- backend/genesys_gl847.cc | 17 +++++++---------- 8 files changed, 53 insertions(+), 50 deletions(-) diff --git a/backend/genesys.cc b/backend/genesys.cc index 2814aa4bb..11fdce8e6 100644 --- a/backend/genesys.cc +++ b/backend/genesys.cc @@ -3434,7 +3434,7 @@ static void genesys_fill_line_interp_buffer(Genesys_Device* dev, uint8_t* work_b /* go to next line if needed */ if (dev->cur == dev->len) { - dev->oe_buffer.set_pos(dev->oe_buffer.pos() + dev->bpl); + dev->oe_buffer.set_pos(dev->oe_buffer.pos() + dev->deseg.raw_channel_bytes); dev->cur = 0; dev->line_count++; } @@ -3521,7 +3521,7 @@ static void genesys_fill_segmented_buffer(Genesys_Device* dev, uint8_t* work_buf /* go to next line if needed */ if (dev->cur == dev->len) { - dev->oe_buffer.set_pos(dev->oe_buffer.pos() + dev->bpl); + dev->oe_buffer.set_pos(dev->oe_buffer.pos() + dev->deseg.raw_channel_bytes); dev->cur = 0; } diff --git a/backend/genesys_device.h b/backend/genesys_device.h index 90e3676a5..8245bb24a 100644 --- a/backend/genesys_device.h +++ b/backend/genesys_device.h @@ -192,6 +192,15 @@ struct Genesys_Model } }; +// Describes the geometry of the raw data coming out of the scanner for desegmentation. +struct DesegmentationState +{ + // total bytes in a channel received from a scanner + unsigned raw_channel_bytes = 0; + // total bytes in a line received from a scanner + unsigned raw_line_bytes = 0; +}; + /** * Describes the current device status for the backend * session. This should be more accurately called @@ -283,15 +292,16 @@ struct Genesys_Device Genesys_Buffer local_buffer; // bytes to read from desegmentation step. This is not the same as physical bytes read from - // scanners, see `wpl` which corresponds to this information on certain scanners. + // scanners, see `deseg.raw_line_bytes` which corresponds to this information on certain + // scanners. size_t read_bytes_left_after_deseg = 0; // total bytes read sent to frontend size_t total_bytes_read = 0; // total bytes read to be sent to frontend size_t total_bytes_to_read = 0; - // asic's word per line - size_t wpl = 0; + + DesegmentationState deseg; // contains the real used values Genesys_Current_Setup current_setup; @@ -315,8 +325,6 @@ struct Genesys_Device int line_interp = 0; // number of scan lines used during scan int line_count = 0; - // bytes per full scan widthline - size_t bpl = 0; // bytes distance between an odd and an even pixel size_t dist = 0; // number of even pixels diff --git a/backend/genesys_gl124.cc b/backend/genesys_gl124.cc index 2f28a021f..a5ccf3e92 100644 --- a/backend/genesys_gl124.cc +++ b/backend/genesys_gl124.cc @@ -828,7 +828,7 @@ static void gl124_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens { DBG_HELPER_ARGS(dbg, "exposure_time=%d, start=%d\n", exposure_time, start); - unsigned int words_per_line, segcnt; + unsigned int segcnt; unsigned int startx, endx, segnb; unsigned int dpihw, factor; GenesysRegister *r; @@ -991,35 +991,34 @@ static void gl124_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens DBG (DBG_io2, "%s: endpixel used=%d\n", __func__, endx/segnb); // words(16bit) before gamma, conversion to 8 bit or lineart - words_per_line = multiply_by_depth_ceil(session.output_pixels / session.ccd_size_divisor, - session.params.depth); + dev->deseg.raw_channel_bytes = + multiply_by_depth_ceil(session.output_pixels / session.ccd_size_divisor, + session.params.depth); - dev->bpl = words_per_line; dev->cur = 0; dev->skip = 0; - dev->len = dev->bpl/segnb; - dev->dist = dev->bpl/segnb; + dev->len = dev->deseg.raw_channel_bytes / segnb; + dev->dist = dev->deseg.raw_channel_bytes / segnb; dev->segnb = segnb; dev->line_count = 0; dev->line_interp = 0; DBG (DBG_io2, "%s: pixels =%d\n", __func__, session.optical_pixels); DBG (DBG_io2, "%s: depth =%d\n", __func__, session.params.depth); - DBG (DBG_io2, "%s: dev->bpl =%lu\n", __func__, (unsigned long)dev->bpl); + DBG (DBG_io2, "%s: dev->bpl =%lu\n", __func__, (unsigned long) dev->deseg.raw_channel_bytes); DBG (DBG_io2, "%s: dev->len =%lu\n", __func__, (unsigned long)dev->len); DBG (DBG_io2, "%s: dev->dist =%lu\n", __func__, (unsigned long)dev->dist); DBG (DBG_io2, "%s: dev->line_interp=%lu\n", __func__, (unsigned long)dev->line_interp); - words_per_line *= session.params.channels; - dev->wpl = words_per_line; + dev->deseg.raw_line_bytes = dev->deseg.raw_channel_bytes * session.params.channels; /* allocate buffer for odd/even pixels handling */ dev->oe_buffer.clear(); - dev->oe_buffer.alloc(dev->wpl); + dev->oe_buffer.alloc(dev->deseg.raw_line_bytes); - /* MAXWD is expressed in 2 words unit */ - reg->set24(REG_MAXWD, words_per_line); - DBG (DBG_io2, "%s: words_per_line used=%d\n", __func__, words_per_line); + // MAXWD is expressed in 2 words unit + reg->set24(REG_MAXWD, dev->deseg.raw_line_bytes); + DBG (DBG_io2, "%s: words_per_line used=%d\n", __func__, dev->deseg.raw_line_bytes); reg->set24(REG_LPERIOD, exposure_time); DBG (DBG_io2, "%s: exposure_time used=%d\n", __func__, exposure_time); diff --git a/backend/genesys_gl646.cc b/backend/genesys_gl646.cc index c8777db25..0bf09a452 100644 --- a/backend/genesys_gl646.cc +++ b/backend/genesys_gl646.cc @@ -563,8 +563,8 @@ static void gl646_setup_registers(Genesys_Device* dev, DBG(DBG_info, "%s: startx=%d, endx=%d, ccd_size_divisor=%d\n", __func__, sx, ex, session.ccd_size_divisor); - dev->bpl = session.output_channel_bytes; - dev->wpl = session.output_line_bytes; + dev->deseg.raw_channel_bytes = session.output_channel_bytes; + dev->deseg.raw_line_bytes = session.output_line_bytes; regs->set24(REG_MAXWD, session.output_line_bytes); @@ -1511,7 +1511,8 @@ static void gl646_detect_document_end(Genesys_Device* dev) /* we add the number of lines needed to read the last part of the document in */ lines = (SANE_UNFIX(dev->model->y_offset) * dev->session.params.yres) / MM_PER_INCH; DBG(DBG_io, "%s: adding %d line to flush\n", __func__, lines); - bytes_left += lines * dev->wpl; + bytes_left += lines * dev->deseg.raw_line_bytes; + if (dev->session.params.depth > 8) { bytes_left = 2 * bytes_left; } diff --git a/backend/genesys_gl841.cc b/backend/genesys_gl841.cc index d9e59cc41..b2973f4be 100644 --- a/backend/genesys_gl841.cc +++ b/backend/genesys_gl841.cc @@ -1604,8 +1604,8 @@ static void gl841_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens reg->set16(REG_ENDPIXEL, end); DBG(DBG_io2, "%s: STRPIXEL=%d, ENDPIXEL=%d\n", __func__, start, end); - dev->wpl = session.output_line_bytes; - dev->bpl = session.output_line_bytes; + dev->deseg.raw_line_bytes = session.output_line_bytes; + dev->deseg.raw_channel_bytes = session.output_line_bytes; reg->set24(REG_MAXWD, session.output_line_bytes); @@ -2442,7 +2442,7 @@ static void gl841_detect_document_end(Genesys_Device* dev) /* the current scancnt is also the final one, so we use it to * compute total bytes to read. We also add the line count to eject document */ - total_bytes_to_read=(scancnt+postcnt)*dev->wpl; + total_bytes_to_read=(scancnt+postcnt) * dev->deseg.raw_line_bytes; DBG(DBG_io, "%s: old total_bytes_to_read=%u\n", __func__, (unsigned int)dev->total_bytes_to_read); diff --git a/backend/genesys_gl843.cc b/backend/genesys_gl843.cc index b18009ab7..c64b36310 100644 --- a/backend/genesys_gl843.cc +++ b/backend/genesys_gl843.cc @@ -1157,12 +1157,12 @@ static void gl843_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens reg->set16(REG_STRPIXEL, session.pixel_startx); reg->set16(REG_ENDPIXEL, session.pixel_endx); - dev->wpl = session.output_channel_bytes; // FIXME: this is not currently used - dev->bpl = session.output_channel_bytes; // FIXME: this is not currently used + dev->deseg.raw_line_bytes = session.output_channel_bytes; // FIXME: this is not currently used + dev->deseg.raw_channel_bytes = session.output_channel_bytes; // FIXME: this is not currently used DBG(DBG_io2, "%s: pixels =%d\n", __func__, session.optical_pixels); DBG(DBG_io2, "%s: depth =%d\n", __func__, session.params.depth); - DBG(DBG_io2, "%s: dev->bpl =%lu\n", __func__, (unsigned long) dev->bpl); + DBG(DBG_io2, "%s: dev->bpl =%lu\n", __func__, (unsigned long) dev->deseg.raw_channel_bytes); DBG(DBG_io2, "%s: dev->len =%lu\n", __func__, (unsigned long)dev->len); DBG(DBG_io2, "%s: dev->dist =%lu\n", __func__, (unsigned long)dev->dist); @@ -1588,9 +1588,9 @@ static void gl843_detect_document_end(Genesys_Device* dev) DBG(DBG_io, "%s: adding %d line to flush\n", __func__, lines); - /* number of bytes to read from scanner to get document out of it after - * end of document dectected by hardware sensor */ - bytes_to_flush = lines * dev->wpl; + // number of bytes to read from scanner to get document out of it after + // end of document dectected by hardware sensor */ + bytes_to_flush = lines * dev->deseg.raw_line_bytes; /* if we are already close to end of scan, flushing isn't needed */ if (bytes_to_flush < read_bytes_left) diff --git a/backend/genesys_gl846.cc b/backend/genesys_gl846.cc index bd4723c62..6bb66cb44 100644 --- a/backend/genesys_gl846.cc +++ b/backend/genesys_gl846.cc @@ -871,11 +871,10 @@ static void gl846_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens /* words(16bit) before gamma, conversion to 8 bit or lineart*/ words_per_line = (used_pixels * session.params.xres * ccd_pixels_per_system_pixel) / sensor.get_register_hwdpi(session.params.xres * ccd_pixels_per_system_pixel); - words_per_line = multiply_by_depth_ceil(words_per_line, session.params.depth); + dev->deseg.raw_channel_bytes = multiply_by_depth_ceil(words_per_line, session.params.depth); dev->len = multiply_by_depth_ceil(dev->len, session.params.depth); dev->dist = multiply_by_depth_ceil(dev->dist, session.params.depth); - dev->bpl = words_per_line; dev->cur=0; dev->segnb=segnb; dev->line_interp = 0; @@ -892,20 +891,19 @@ static void gl846_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens DBG (DBG_io2, "%s: used_pixels=%d\n", __func__, used_pixels); DBG (DBG_io2, "%s: pixels =%d\n", __func__, session.optical_pixels); DBG (DBG_io2, "%s: depth =%d\n", __func__, session.params.depth); - DBG (DBG_io2, "%s: dev->bpl =%lu\n", __func__, (unsigned long)dev->bpl); + DBG (DBG_io2, "%s: dev->bpl =%lu\n", __func__, (unsigned long) dev->deseg.raw_channel_bytes); DBG (DBG_io2, "%s: dev->len =%lu\n", __func__, (unsigned long)dev->len); DBG (DBG_io2, "%s: dev->dist =%lu\n", __func__, (unsigned long)dev->dist); DBG (DBG_io2, "%s: dev->segnb =%lu\n", __func__, (unsigned long)dev->segnb); - words_per_line *= session.params.channels; - dev->wpl = words_per_line; + dev->deseg.raw_line_bytes = dev->deseg.raw_channel_bytes * session.params.channels; dev->oe_buffer.clear(); - dev->oe_buffer.alloc(dev->wpl); + dev->oe_buffer.alloc(dev->deseg.raw_line_bytes); /* MAXWD is expressed in 4 words unit */ - reg->set24(REG_MAXWD, (words_per_line >> 2)); - DBG (DBG_io2, "%s: words_per_line used=%d\n", __func__, words_per_line); + reg->set24(REG_MAXWD, (dev->deseg.raw_line_bytes >> 2)); + DBG(DBG_io2, "%s: words_per_line used=%d\n", __func__, dev->deseg.raw_line_bytes); reg->set16(REG_LPERIOD, exposure_time); DBG (DBG_io2, "%s: exposure_time used=%d\n", __func__, exposure_time); diff --git a/backend/genesys_gl847.cc b/backend/genesys_gl847.cc index 3a45afa85..802afedb1 100644 --- a/backend/genesys_gl847.cc +++ b/backend/genesys_gl847.cc @@ -744,7 +744,6 @@ static void gl847_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens const ScanSession& session, unsigned int start) { DBG_HELPER_ARGS(dbg, "exposure_time=%d, start=%d", exposure_time, start); - unsigned int words_per_line; unsigned dpiset, dpihw, segnb, factor; GenesysRegister *r; @@ -890,12 +889,11 @@ static void gl847_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens } /* words(16bit) before gamma, conversion to 8 bit or lineart*/ - words_per_line = (used_pixels * dpiset) / dpihw; - words_per_line = multiply_by_depth_ceil(words_per_line, session.params.depth); + dev->deseg.raw_channel_bytes = multiply_by_depth_ceil((used_pixels * dpiset) / dpihw, + session.params.depth); dev->len = multiply_by_depth_ceil(dev->len, session.params.depth); dev->dist = multiply_by_depth_ceil(dev->dist, session.params.depth); - dev->bpl = words_per_line; dev->cur=0; dev->segnb=segnb; dev->line_interp = 0; @@ -911,20 +909,19 @@ static void gl847_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens DBG (DBG_io2, "%s: used_pixels=%d\n", __func__, used_pixels); DBG (DBG_io2, "%s: pixels =%d\n", __func__, session.optical_pixels); DBG (DBG_io2, "%s: depth =%d\n", __func__, session.params.depth); - DBG (DBG_io2, "%s: dev->bpl =%lu\n", __func__, (unsigned long)dev->bpl); + DBG (DBG_io2, "%s: dev->bpl =%lu\n", __func__, (unsigned long) dev->deseg.raw_channel_bytes); DBG (DBG_io2, "%s: dev->len =%lu\n", __func__, (unsigned long)dev->len); DBG (DBG_io2, "%s: dev->dist =%lu\n", __func__, (unsigned long)dev->dist); DBG (DBG_io2, "%s: dev->segnb =%lu\n", __func__, (unsigned long)dev->segnb); - words_per_line *= session.params.channels; - dev->wpl = words_per_line; + dev->deseg.raw_line_bytes = dev->deseg.raw_channel_bytes * session.params.channels; dev->oe_buffer.clear(); - dev->oe_buffer.alloc(dev->wpl); + dev->oe_buffer.alloc(dev->deseg.raw_line_bytes); /* MAXWD is expressed in 4 words unit */ - reg->set24(REG_MAXWD, (words_per_line >> 2)); - DBG(DBG_io2, "%s: words_per_line used=%d\n", __func__, words_per_line); + reg->set24(REG_MAXWD, (dev->deseg.raw_line_bytes >> 2)); + DBG(DBG_io2, "%s: words_per_line used=%d\n", __func__, dev->deseg.raw_line_bytes); reg->set16(REG_LPERIOD, exposure_time); DBG(DBG_io2, "%s: exposure_time used=%d\n", __func__, exposure_time); From 07d8db5423cae48cbe247f3a3b6f42a1c33aa6ca Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Thu, 12 Sep 2019 21:26:53 +0300 Subject: [PATCH 3/8] genesys: Move Genesys_Device::dist to DesegmentationState --- backend/genesys.cc | 8 ++++---- backend/genesys_device.h | 9 +++++---- backend/genesys_gl124.cc | 4 ++-- backend/genesys_gl843.cc | 2 +- backend/genesys_gl846.cc | 10 +++++----- backend/genesys_gl847.cc | 10 +++++----- 6 files changed, 22 insertions(+), 21 deletions(-) diff --git a/backend/genesys.cc b/backend/genesys.cc index 11fdce8e6..8bd147401 100644 --- a/backend/genesys.cc +++ b/backend/genesys.cc @@ -3485,7 +3485,7 @@ static void genesys_fill_segmented_buffer(Genesys_Device* dev, uint8_t* work_buf k=count+(i*dev->segnb)/8; for (n=0;nsegnb;n++) { work_buffer_dst[k] = work_buffer_dst[k] << 1; - if ((dev->oe_buffer.get_read_pos()[dev->cur + dev->skip + dev->dist*dev->segment_order[n]])&(128>>i)) { + if ((dev->oe_buffer.get_read_pos()[dev->cur + dev->skip + dev->deseg.conseq_pixel_dist_bytes * dev->segment_order[n]])&(128>>i)) { work_buffer_dst[k] |= 1; } } @@ -3499,7 +3499,7 @@ static void genesys_fill_segmented_buffer(Genesys_Device* dev, uint8_t* work_buf if (depth==8) { while (dev->cur < dev->len && count < size) { for (n=0;nsegnb;n++) { - work_buffer_dst[count+n] = dev->oe_buffer.get_read_pos()[dev->cur + dev->skip + dev->dist*dev->segment_order[n]]; + work_buffer_dst[count+n] = dev->oe_buffer.get_read_pos()[dev->cur + dev->skip + dev->deseg.conseq_pixel_dist_bytes *dev->segment_order[n]]; } /* update counter and pointer */ count += dev->segnb; @@ -3509,8 +3509,8 @@ static void genesys_fill_segmented_buffer(Genesys_Device* dev, uint8_t* work_buf if (depth==16) { while (dev->cur < dev->len && count < size) { for (n=0;nsegnb;n++) { - work_buffer_dst[count+n*2] = dev->oe_buffer.get_read_pos()[dev->cur + dev->skip + dev->dist*dev->segment_order[n]]; - work_buffer_dst[count+n*2+1] = dev->oe_buffer.get_read_pos()[dev->cur + dev->skip + dev->dist*dev->segment_order[n] + 1]; + work_buffer_dst[count+n*2] = dev->oe_buffer.get_read_pos()[dev->cur + dev->skip + dev->deseg.conseq_pixel_dist_bytes * dev->segment_order[n]]; + work_buffer_dst[count+n*2+1] = dev->oe_buffer.get_read_pos()[dev->cur + dev->skip + dev->deseg.conseq_pixel_dist_bytes * dev->segment_order[n] + 1]; } /* update counter and pointer */ count += dev->segnb*2; diff --git a/backend/genesys_device.h b/backend/genesys_device.h index 8245bb24a..378b857e4 100644 --- a/backend/genesys_device.h +++ b/backend/genesys_device.h @@ -195,9 +195,12 @@ struct Genesys_Model // Describes the geometry of the raw data coming out of the scanner for desegmentation. struct DesegmentationState { - // total bytes in a channel received from a scanner + // Distance in bytes between consecutive pixels, e.g. between odd and even pixels. Note that + // the number of segments can be large. + unsigned conseq_pixel_dist_bytes = 0; + // Total bytes in a channel received from a scanner unsigned raw_channel_bytes = 0; - // total bytes in a line received from a scanner + // Total bytes in a line received from a scanner unsigned raw_line_bytes = 0; }; @@ -325,8 +328,6 @@ struct Genesys_Device int line_interp = 0; // number of scan lines used during scan int line_count = 0; - // bytes distance between an odd and an even pixel - size_t dist = 0; // number of even pixels size_t len = 0; // current pixel position within sub window diff --git a/backend/genesys_gl124.cc b/backend/genesys_gl124.cc index a5ccf3e92..1f8cfaebe 100644 --- a/backend/genesys_gl124.cc +++ b/backend/genesys_gl124.cc @@ -998,7 +998,7 @@ static void gl124_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens dev->cur = 0; dev->skip = 0; dev->len = dev->deseg.raw_channel_bytes / segnb; - dev->dist = dev->deseg.raw_channel_bytes / segnb; + dev->deseg.conseq_pixel_dist_bytes = dev->deseg.raw_channel_bytes / segnb; dev->segnb = segnb; dev->line_count = 0; dev->line_interp = 0; @@ -1007,7 +1007,7 @@ static void gl124_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens DBG (DBG_io2, "%s: depth =%d\n", __func__, session.params.depth); DBG (DBG_io2, "%s: dev->bpl =%lu\n", __func__, (unsigned long) dev->deseg.raw_channel_bytes); DBG (DBG_io2, "%s: dev->len =%lu\n", __func__, (unsigned long)dev->len); - DBG (DBG_io2, "%s: dev->dist =%lu\n", __func__, (unsigned long)dev->dist); + DBG (DBG_io2, "%s: dev->dist =%lu\n", __func__, (unsigned long) dev->deseg.conseq_pixel_dist_bytes); DBG (DBG_io2, "%s: dev->line_interp=%lu\n", __func__, (unsigned long)dev->line_interp); dev->deseg.raw_line_bytes = dev->deseg.raw_channel_bytes * session.params.channels; diff --git a/backend/genesys_gl843.cc b/backend/genesys_gl843.cc index c64b36310..a5ef81688 100644 --- a/backend/genesys_gl843.cc +++ b/backend/genesys_gl843.cc @@ -1164,7 +1164,7 @@ static void gl843_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens DBG(DBG_io2, "%s: depth =%d\n", __func__, session.params.depth); DBG(DBG_io2, "%s: dev->bpl =%lu\n", __func__, (unsigned long) dev->deseg.raw_channel_bytes); DBG(DBG_io2, "%s: dev->len =%lu\n", __func__, (unsigned long)dev->len); - DBG(DBG_io2, "%s: dev->dist =%lu\n", __func__, (unsigned long)dev->dist); + DBG(DBG_io2, "%s: dev->dist =%lu\n", __func__, (unsigned long) dev->deseg.conseq_pixel_dist_bytes); /* MAXWD is expressed in 2 words unit */ /* nousedspace = (mem_bank_range * 1024 / 256 -1 ) * 4; */ diff --git a/backend/genesys_gl846.cc b/backend/genesys_gl846.cc index 6bb66cb44..055c67fe9 100644 --- a/backend/genesys_gl846.cc +++ b/backend/genesys_gl846.cc @@ -762,17 +762,17 @@ static void gl846_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens startx /= factor*segnb; endx /= factor*segnb; dev->len = endx - startx; - dev->dist=0; + dev->deseg.conseq_pixel_dist_bytes = 0; dev->skip=0; /* in cas of multi-segments sensor, we have to add the witdh * of the sensor crossed by the scan area */ if (dev->model->flags & GENESYS_FLAG_SIS_SENSOR && segnb > 1) { - dev->dist = sensor_profile.segment_count; + dev->deseg.conseq_pixel_dist_bytes = sensor_profile.segment_count; } /* use a segcnt rounded to next even number */ - endx += ((dev->dist+1)&0xfffe)*(segnb-1); + endx += ((dev->deseg.conseq_pixel_dist_bytes + 1) & 0xfffe) * (segnb - 1); unsigned used_pixels = endx - startx; gl846_set_fe(dev, sensor, AFE_SET); @@ -873,7 +873,7 @@ static void gl846_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens words_per_line = (used_pixels * session.params.xres * ccd_pixels_per_system_pixel) / sensor.get_register_hwdpi(session.params.xres * ccd_pixels_per_system_pixel); dev->deseg.raw_channel_bytes = multiply_by_depth_ceil(words_per_line, session.params.depth); dev->len = multiply_by_depth_ceil(dev->len, session.params.depth); - dev->dist = multiply_by_depth_ceil(dev->dist, session.params.depth); + dev->deseg.conseq_pixel_dist_bytes = multiply_by_depth_ceil(dev->deseg.conseq_pixel_dist_bytes, session.params.depth); dev->cur=0; dev->segnb=segnb; @@ -893,7 +893,7 @@ static void gl846_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens DBG (DBG_io2, "%s: depth =%d\n", __func__, session.params.depth); DBG (DBG_io2, "%s: dev->bpl =%lu\n", __func__, (unsigned long) dev->deseg.raw_channel_bytes); DBG (DBG_io2, "%s: dev->len =%lu\n", __func__, (unsigned long)dev->len); - DBG (DBG_io2, "%s: dev->dist =%lu\n", __func__, (unsigned long)dev->dist); + DBG (DBG_io2, "%s: dev->dist =%lu\n", __func__, (unsigned long) dev->deseg.conseq_pixel_dist_bytes); DBG (DBG_io2, "%s: dev->segnb =%lu\n", __func__, (unsigned long)dev->segnb); dev->deseg.raw_line_bytes = dev->deseg.raw_channel_bytes * session.params.channels; diff --git a/backend/genesys_gl847.cc b/backend/genesys_gl847.cc index 802afedb1..fd73c9726 100644 --- a/backend/genesys_gl847.cc +++ b/backend/genesys_gl847.cc @@ -781,17 +781,17 @@ static void gl847_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens startx /= factor*segnb; endx /= factor*segnb; dev->len=endx-startx; - dev->dist=0; + dev->deseg.conseq_pixel_dist_bytes = 0; dev->skip=0; /* in cas of multi-segments sensor, we have to add the witdh * of the sensor crossed by the scan area */ if (dev->model->flags & GENESYS_FLAG_SIS_SENSOR && segnb > 1) { - dev->dist = sensor_profile.segment_count; + dev->deseg.conseq_pixel_dist_bytes = sensor_profile.segment_count; } /* use a segcnt rounded to next even number */ - endx += ((dev->dist+1)&0xfffe)*(segnb-1); + endx += ((dev->deseg.conseq_pixel_dist_bytes + 1) & 0xfffe) * (segnb - 1); unsigned used_pixels = endx - startx; gl847_set_fe(dev, sensor, AFE_SET); @@ -892,7 +892,7 @@ static void gl847_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens dev->deseg.raw_channel_bytes = multiply_by_depth_ceil((used_pixels * dpiset) / dpihw, session.params.depth); dev->len = multiply_by_depth_ceil(dev->len, session.params.depth); - dev->dist = multiply_by_depth_ceil(dev->dist, session.params.depth); + dev->deseg.conseq_pixel_dist_bytes = multiply_by_depth_ceil(dev->deseg.conseq_pixel_dist_bytes, session.params.depth); dev->cur=0; dev->segnb=segnb; @@ -911,7 +911,7 @@ static void gl847_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens DBG (DBG_io2, "%s: depth =%d\n", __func__, session.params.depth); DBG (DBG_io2, "%s: dev->bpl =%lu\n", __func__, (unsigned long) dev->deseg.raw_channel_bytes); DBG (DBG_io2, "%s: dev->len =%lu\n", __func__, (unsigned long)dev->len); - DBG (DBG_io2, "%s: dev->dist =%lu\n", __func__, (unsigned long)dev->dist); + DBG (DBG_io2, "%s: dev->dist =%lu\n", __func__, (unsigned long) dev->deseg.conseq_pixel_dist_bytes); DBG (DBG_io2, "%s: dev->segnb =%lu\n", __func__, (unsigned long)dev->segnb); dev->deseg.raw_line_bytes = dev->deseg.raw_channel_bytes * session.params.channels; From 9bd14f535059e674016a96b1f04a38533bc15a4b Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Thu, 12 Sep 2019 21:26:54 +0300 Subject: [PATCH 4/8] genesys: Move Genesys_Device::len to DesegmentationState --- backend/genesys.cc | 12 +++++------- backend/genesys_device.h | 8 ++++++-- backend/genesys_gl124.cc | 4 ++-- backend/genesys_gl843.cc | 2 +- backend/genesys_gl846.cc | 6 +++--- backend/genesys_gl847.cc | 6 +++--- 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/backend/genesys.cc b/backend/genesys.cc index 8bd147401..4f8a1a06a 100644 --- a/backend/genesys.cc +++ b/backend/genesys.cc @@ -3432,8 +3432,7 @@ static void genesys_fill_line_interp_buffer(Genesys_Device* dev, uint8_t* work_b dev->cur++; /* go to next line if needed */ - if (dev->cur == dev->len) - { + if (dev->cur == dev->deseg.pixel_groups) { dev->oe_buffer.set_pos(dev->oe_buffer.pos() + dev->deseg.raw_channel_bytes); dev->cur = 0; dev->line_count++; @@ -3476,7 +3475,7 @@ static void genesys_fill_segmented_buffer(Genesys_Device* dev, uint8_t* work_buf while (count < size) { if (depth==1) { - while (dev->cur < dev->len && count < size) { + while (dev->cur < dev->deseg.pixel_groups && count < size) { for (n=0; nsegnb; n++) { work_buffer_dst[count+n] = 0; } @@ -3497,7 +3496,7 @@ static void genesys_fill_segmented_buffer(Genesys_Device* dev, uint8_t* work_buf } } if (depth==8) { - while (dev->cur < dev->len && count < size) { + while (dev->cur < dev->deseg.pixel_groups && count < size) { for (n=0;nsegnb;n++) { work_buffer_dst[count+n] = dev->oe_buffer.get_read_pos()[dev->cur + dev->skip + dev->deseg.conseq_pixel_dist_bytes *dev->segment_order[n]]; } @@ -3507,7 +3506,7 @@ static void genesys_fill_segmented_buffer(Genesys_Device* dev, uint8_t* work_buf } } if (depth==16) { - while (dev->cur < dev->len && count < size) { + while (dev->cur < dev->deseg.pixel_groups && count < size) { for (n=0;nsegnb;n++) { work_buffer_dst[count+n*2] = dev->oe_buffer.get_read_pos()[dev->cur + dev->skip + dev->deseg.conseq_pixel_dist_bytes * dev->segment_order[n]]; work_buffer_dst[count+n*2+1] = dev->oe_buffer.get_read_pos()[dev->cur + dev->skip + dev->deseg.conseq_pixel_dist_bytes * dev->segment_order[n] + 1]; @@ -3519,8 +3518,7 @@ static void genesys_fill_segmented_buffer(Genesys_Device* dev, uint8_t* work_buf } /* go to next line if needed */ - if (dev->cur == dev->len) - { + if (dev->cur == dev->deseg.pixel_groups) { dev->oe_buffer.set_pos(dev->oe_buffer.pos() + dev->deseg.raw_channel_bytes); dev->cur = 0; } diff --git a/backend/genesys_device.h b/backend/genesys_device.h index 378b857e4..7eb0eb890 100644 --- a/backend/genesys_device.h +++ b/backend/genesys_device.h @@ -195,11 +195,17 @@ struct Genesys_Model // Describes the geometry of the raw data coming out of the scanner for desegmentation. struct DesegmentationState { + // The number of "even" pixels to scan. This corresponds to the number of pixels that will be + // scanned from a single segment + unsigned pixel_groups = 0; + // Distance in bytes between consecutive pixels, e.g. between odd and even pixels. Note that // the number of segments can be large. unsigned conseq_pixel_dist_bytes = 0; + // Total bytes in a channel received from a scanner unsigned raw_channel_bytes = 0; + // Total bytes in a line received from a scanner unsigned raw_line_bytes = 0; }; @@ -328,8 +334,6 @@ struct Genesys_Device int line_interp = 0; // number of scan lines used during scan int line_count = 0; - // number of even pixels - size_t len = 0; // current pixel position within sub window size_t cur = 0; // number of bytes to skip at start of line diff --git a/backend/genesys_gl124.cc b/backend/genesys_gl124.cc index 1f8cfaebe..9ccf258d3 100644 --- a/backend/genesys_gl124.cc +++ b/backend/genesys_gl124.cc @@ -997,7 +997,7 @@ static void gl124_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens dev->cur = 0; dev->skip = 0; - dev->len = dev->deseg.raw_channel_bytes / segnb; + dev->deseg.pixel_groups = dev->deseg.raw_channel_bytes / segnb; dev->deseg.conseq_pixel_dist_bytes = dev->deseg.raw_channel_bytes / segnb; dev->segnb = segnb; dev->line_count = 0; @@ -1006,7 +1006,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); DBG (DBG_io2, "%s: dev->bpl =%lu\n", __func__, (unsigned long) dev->deseg.raw_channel_bytes); - DBG (DBG_io2, "%s: dev->len =%lu\n", __func__, (unsigned long)dev->len); + DBG (DBG_io2, "%s: dev->len =%lu\n", __func__, (unsigned long) dev->deseg.pixel_groups); DBG (DBG_io2, "%s: dev->dist =%lu\n", __func__, (unsigned long) dev->deseg.conseq_pixel_dist_bytes); DBG (DBG_io2, "%s: dev->line_interp=%lu\n", __func__, (unsigned long)dev->line_interp); diff --git a/backend/genesys_gl843.cc b/backend/genesys_gl843.cc index a5ef81688..f519c411a 100644 --- a/backend/genesys_gl843.cc +++ b/backend/genesys_gl843.cc @@ -1163,7 +1163,7 @@ static void gl843_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); DBG(DBG_io2, "%s: dev->bpl =%lu\n", __func__, (unsigned long) dev->deseg.raw_channel_bytes); - DBG(DBG_io2, "%s: dev->len =%lu\n", __func__, (unsigned long)dev->len); + DBG(DBG_io2, "%s: dev->len =%lu\n", __func__, (unsigned long) dev->deseg.pixel_groups); DBG(DBG_io2, "%s: dev->dist =%lu\n", __func__, (unsigned long) dev->deseg.conseq_pixel_dist_bytes); /* MAXWD is expressed in 2 words unit */ diff --git a/backend/genesys_gl846.cc b/backend/genesys_gl846.cc index 055c67fe9..dffc54474 100644 --- a/backend/genesys_gl846.cc +++ b/backend/genesys_gl846.cc @@ -761,7 +761,7 @@ static void gl846_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens // compute pixel coordinate in the given dpihw space, taking segments into account startx /= factor*segnb; endx /= factor*segnb; - dev->len = endx - startx; + dev->deseg.pixel_groups = endx - startx; dev->deseg.conseq_pixel_dist_bytes = 0; dev->skip=0; @@ -872,7 +872,7 @@ static void gl846_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens /* words(16bit) before gamma, conversion to 8 bit or lineart*/ words_per_line = (used_pixels * session.params.xres * ccd_pixels_per_system_pixel) / sensor.get_register_hwdpi(session.params.xres * ccd_pixels_per_system_pixel); dev->deseg.raw_channel_bytes = multiply_by_depth_ceil(words_per_line, session.params.depth); - dev->len = multiply_by_depth_ceil(dev->len, session.params.depth); + dev->deseg.pixel_groups = multiply_by_depth_ceil(dev->deseg.pixel_groups, session.params.depth); dev->deseg.conseq_pixel_dist_bytes = multiply_by_depth_ceil(dev->deseg.conseq_pixel_dist_bytes, session.params.depth); dev->cur=0; @@ -892,7 +892,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); DBG (DBG_io2, "%s: dev->bpl =%lu\n", __func__, (unsigned long) dev->deseg.raw_channel_bytes); - DBG (DBG_io2, "%s: dev->len =%lu\n", __func__, (unsigned long)dev->len); + DBG (DBG_io2, "%s: dev->len =%lu\n", __func__, (unsigned long) dev->deseg.pixel_groups); DBG (DBG_io2, "%s: dev->dist =%lu\n", __func__, (unsigned long) dev->deseg.conseq_pixel_dist_bytes); DBG (DBG_io2, "%s: dev->segnb =%lu\n", __func__, (unsigned long)dev->segnb); diff --git a/backend/genesys_gl847.cc b/backend/genesys_gl847.cc index fd73c9726..fa59359f1 100644 --- a/backend/genesys_gl847.cc +++ b/backend/genesys_gl847.cc @@ -780,7 +780,7 @@ static void gl847_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens // compute pixel coordinate in the given dpihw space, taking segments into account startx /= factor*segnb; endx /= factor*segnb; - dev->len=endx-startx; + dev->deseg.pixel_groups = endx-startx; dev->deseg.conseq_pixel_dist_bytes = 0; dev->skip=0; @@ -891,7 +891,7 @@ static void gl847_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens /* words(16bit) before gamma, conversion to 8 bit or lineart*/ dev->deseg.raw_channel_bytes = multiply_by_depth_ceil((used_pixels * dpiset) / dpihw, session.params.depth); - dev->len = multiply_by_depth_ceil(dev->len, session.params.depth); + dev->deseg.pixel_groups = multiply_by_depth_ceil(dev->deseg.pixel_groups, session.params.depth); dev->deseg.conseq_pixel_dist_bytes = multiply_by_depth_ceil(dev->deseg.conseq_pixel_dist_bytes, session.params.depth); dev->cur=0; @@ -910,7 +910,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); DBG (DBG_io2, "%s: dev->bpl =%lu\n", __func__, (unsigned long) dev->deseg.raw_channel_bytes); - DBG (DBG_io2, "%s: dev->len =%lu\n", __func__, (unsigned long)dev->len); + DBG (DBG_io2, "%s: dev->len =%lu\n", __func__, (unsigned long) dev->deseg.pixel_groups); DBG (DBG_io2, "%s: dev->dist =%lu\n", __func__, (unsigned long) dev->deseg.conseq_pixel_dist_bytes); DBG (DBG_io2, "%s: dev->segnb =%lu\n", __func__, (unsigned long)dev->segnb); From 31820384de76a71e83b6fa003b2d2c95d2a85272 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Thu, 12 Sep 2019 21:26:55 +0300 Subject: [PATCH 5/8] genesys: Move Genesys_Device::skip to DesegmentationState --- backend/genesys.cc | 8 ++++---- backend/genesys_device.h | 5 +++-- backend/genesys_gl124.cc | 2 +- backend/genesys_gl846.cc | 2 +- backend/genesys_gl847.cc | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/backend/genesys.cc b/backend/genesys.cc index 4f8a1a06a..4e713690d 100644 --- a/backend/genesys.cc +++ b/backend/genesys.cc @@ -3484,7 +3484,7 @@ static void genesys_fill_segmented_buffer(Genesys_Device* dev, uint8_t* work_buf k=count+(i*dev->segnb)/8; for (n=0;nsegnb;n++) { work_buffer_dst[k] = work_buffer_dst[k] << 1; - if ((dev->oe_buffer.get_read_pos()[dev->cur + dev->skip + dev->deseg.conseq_pixel_dist_bytes * dev->segment_order[n]])&(128>>i)) { + if ((dev->oe_buffer.get_read_pos()[dev->cur + dev->deseg.skip_bytes + dev->deseg.conseq_pixel_dist_bytes * dev->segment_order[n]])&(128>>i)) { work_buffer_dst[k] |= 1; } } @@ -3498,7 +3498,7 @@ static void genesys_fill_segmented_buffer(Genesys_Device* dev, uint8_t* work_buf if (depth==8) { while (dev->cur < dev->deseg.pixel_groups && count < size) { for (n=0;nsegnb;n++) { - work_buffer_dst[count+n] = dev->oe_buffer.get_read_pos()[dev->cur + dev->skip + dev->deseg.conseq_pixel_dist_bytes *dev->segment_order[n]]; + work_buffer_dst[count+n] = dev->oe_buffer.get_read_pos()[dev->cur + dev->deseg.skip_bytes + dev->deseg.conseq_pixel_dist_bytes *dev->segment_order[n]]; } /* update counter and pointer */ count += dev->segnb; @@ -3508,8 +3508,8 @@ static void genesys_fill_segmented_buffer(Genesys_Device* dev, uint8_t* work_buf if (depth==16) { while (dev->cur < dev->deseg.pixel_groups && count < size) { for (n=0;nsegnb;n++) { - work_buffer_dst[count+n*2] = dev->oe_buffer.get_read_pos()[dev->cur + dev->skip + dev->deseg.conseq_pixel_dist_bytes * dev->segment_order[n]]; - work_buffer_dst[count+n*2+1] = dev->oe_buffer.get_read_pos()[dev->cur + dev->skip + dev->deseg.conseq_pixel_dist_bytes * dev->segment_order[n] + 1]; + work_buffer_dst[count+n*2] = dev->oe_buffer.get_read_pos()[dev->cur + dev->deseg.skip_bytes + dev->deseg.conseq_pixel_dist_bytes * dev->segment_order[n]]; + work_buffer_dst[count+n*2+1] = dev->oe_buffer.get_read_pos()[dev->cur + dev->deseg.skip_bytes + dev->deseg.conseq_pixel_dist_bytes * dev->segment_order[n] + 1]; } /* update counter and pointer */ count += dev->segnb*2; diff --git a/backend/genesys_device.h b/backend/genesys_device.h index 7eb0eb890..46f72bab9 100644 --- a/backend/genesys_device.h +++ b/backend/genesys_device.h @@ -195,6 +195,9 @@ struct Genesys_Model // Describes the geometry of the raw data coming out of the scanner for desegmentation. struct DesegmentationState { + // The number of bytes to skip at start of line. Currently it's always zero. + unsigned skip_bytes = 0; + // The number of "even" pixels to scan. This corresponds to the number of pixels that will be // scanned from a single segment unsigned pixel_groups = 0; @@ -336,8 +339,6 @@ struct Genesys_Device int line_count = 0; // current pixel position within sub window size_t cur = 0; - // number of bytes to skip at start of line - size_t skip = 0; // array describing the order of the sub-segments of the sensor std::vector segment_order; diff --git a/backend/genesys_gl124.cc b/backend/genesys_gl124.cc index 9ccf258d3..74b79dda5 100644 --- a/backend/genesys_gl124.cc +++ b/backend/genesys_gl124.cc @@ -996,7 +996,7 @@ static void gl124_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens session.params.depth); dev->cur = 0; - dev->skip = 0; + dev->deseg.skip_bytes = 0; dev->deseg.pixel_groups = dev->deseg.raw_channel_bytes / segnb; dev->deseg.conseq_pixel_dist_bytes = dev->deseg.raw_channel_bytes / segnb; dev->segnb = segnb; diff --git a/backend/genesys_gl846.cc b/backend/genesys_gl846.cc index dffc54474..21670c118 100644 --- a/backend/genesys_gl846.cc +++ b/backend/genesys_gl846.cc @@ -763,7 +763,7 @@ static void gl846_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens endx /= factor*segnb; dev->deseg.pixel_groups = endx - startx; dev->deseg.conseq_pixel_dist_bytes = 0; - dev->skip=0; + dev->deseg.skip_bytes = 0; /* in cas of multi-segments sensor, we have to add the witdh * of the sensor crossed by the scan area */ diff --git a/backend/genesys_gl847.cc b/backend/genesys_gl847.cc index fa59359f1..e5609df0e 100644 --- a/backend/genesys_gl847.cc +++ b/backend/genesys_gl847.cc @@ -782,7 +782,7 @@ static void gl847_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens endx /= factor*segnb; dev->deseg.pixel_groups = endx-startx; dev->deseg.conseq_pixel_dist_bytes = 0; - dev->skip=0; + dev->deseg.skip_bytes = 0; /* in cas of multi-segments sensor, we have to add the witdh * of the sensor crossed by the scan area */ From 15996983ba34868927750665dd49b3d13b76a2c8 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Thu, 12 Sep 2019 21:26:56 +0300 Subject: [PATCH 6/8] genesys: Rename SensorProfile::segment_{count => size} --- backend/genesys_gl846.cc | 2 +- backend/genesys_gl847.cc | 2 +- backend/genesys_sensor.h | 2 +- backend/genesys_tables_sensor.cc | 38 ++++++++++++++++---------------- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/backend/genesys_gl846.cc b/backend/genesys_gl846.cc index 21670c118..61398717e 100644 --- a/backend/genesys_gl846.cc +++ b/backend/genesys_gl846.cc @@ -768,7 +768,7 @@ static void gl846_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens /* in cas of multi-segments sensor, we have to add the witdh * of the sensor crossed by the scan area */ if (dev->model->flags & GENESYS_FLAG_SIS_SENSOR && segnb > 1) { - dev->deseg.conseq_pixel_dist_bytes = sensor_profile.segment_count; + dev->deseg.conseq_pixel_dist_bytes = sensor_profile.segment_size; } /* use a segcnt rounded to next even number */ diff --git a/backend/genesys_gl847.cc b/backend/genesys_gl847.cc index e5609df0e..cf483b294 100644 --- a/backend/genesys_gl847.cc +++ b/backend/genesys_gl847.cc @@ -787,7 +787,7 @@ static void gl847_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens /* in cas of multi-segments sensor, we have to add the witdh * of the sensor crossed by the scan area */ if (dev->model->flags & GENESYS_FLAG_SIS_SENSOR && segnb > 1) { - dev->deseg.conseq_pixel_dist_bytes = sensor_profile.segment_count; + dev->deseg.conseq_pixel_dist_bytes = sensor_profile.segment_size; } /* use a segcnt rounded to next even number */ diff --git a/backend/genesys_sensor.h b/backend/genesys_sensor.h index 1033ec08d..0ee3ebde3 100644 --- a/backend/genesys_sensor.h +++ b/backend/genesys_sensor.h @@ -165,7 +165,7 @@ struct SensorProfile unsigned ccd_size_divisor = 1; unsigned exposure_lperiod = 0; SensorExposure exposure; - unsigned segment_count = 0; // only on GL846, GL847 + unsigned segment_size = 0; // only on GL846, GL847 std::vector segment_order; GenesysRegisterSettingSet custom_regs; diff --git a/backend/genesys_tables_sensor.cc b/backend/genesys_tables_sensor.cc index e4cc34af4..ae1e995df 100644 --- a/backend/genesys_tables_sensor.cc +++ b/backend/genesys_tables_sensor.cc @@ -1638,7 +1638,7 @@ void genesys_init_sensor_tables() profile.dpi = 200; profile.exposure_lperiod = 2848; profile.exposure = { 410, 275, 203 }; - profile.segment_count = 5136; + profile.segment_size = 5136; profile.segment_order = {}; profile.custom_regs = { { 0x17, 0x0a }, @@ -1653,7 +1653,7 @@ void genesys_init_sensor_tables() profile.dpi = 300; profile.exposure_lperiod = 1424; profile.exposure = { 410, 275, 203 }; - profile.segment_count = 5136; + profile.segment_size = 5136; profile.segment_order = {}; profile.custom_regs = { { 0x17, 0x0a }, @@ -1668,7 +1668,7 @@ void genesys_init_sensor_tables() profile.dpi = 600; profile.exposure_lperiod = 1432; profile.exposure = { 410, 275, 203 }; - profile.segment_count = 5136; + profile.segment_size = 5136; profile.segment_order = {}; profile.custom_regs = { { 0x17, 0x0a }, @@ -1683,7 +1683,7 @@ void genesys_init_sensor_tables() profile.dpi = 1200; profile.exposure_lperiod = 2712; profile.exposure = { 746, 478, 353 }; - profile.segment_count = 5136; + profile.segment_size = 5136; profile.segment_order = {0, 1}; profile.custom_regs = { { 0x17, 0x08 }, @@ -1698,7 +1698,7 @@ void genesys_init_sensor_tables() profile.dpi = 2400; profile.exposure_lperiod = 5280; profile.exposure = { 1417, 909, 643 }; - profile.segment_count = 5136; + profile.segment_size = 5136; profile.segment_order = {0, 2, 1, 3}; profile.custom_regs = { { 0x17, 0x06 }, @@ -1713,7 +1713,7 @@ void genesys_init_sensor_tables() profile.dpi = 4800; profile.exposure_lperiod = 10416; profile.exposure = { 2692, 1728, 1221 }; - profile.segment_count = 5136; + profile.segment_size = 5136; profile.segment_order = {0, 2, 4, 6, 1, 3, 5, 7}; profile.custom_regs = { { 0x17, 0x04 }, @@ -1776,7 +1776,7 @@ void genesys_init_sensor_tables() profile.dpi = 150; profile.exposure_lperiod = 2848; profile.exposure = { 465, 310, 239 }; - profile.segment_count = 5187; + profile.segment_size = 5187; profile.segment_order = {}; profile.custom_regs = { { 0x17, 0x0c }, @@ -1791,7 +1791,7 @@ void genesys_init_sensor_tables() profile.dpi = 300; profile.exposure_lperiod = 1424; profile.exposure = { 465, 310, 239 }; - profile.segment_count = 5187; + profile.segment_size = 5187; profile.segment_order = {}; profile.custom_regs = { { 0x17, 0x0c }, @@ -1806,7 +1806,7 @@ void genesys_init_sensor_tables() profile.dpi = 600; profile.exposure_lperiod = 1504; profile.exposure = { 465, 310, 239 }; - profile.segment_count = 5187; + profile.segment_size = 5187; profile.segment_order = {}; profile.custom_regs = { { 0x17, 0x0c }, @@ -1821,7 +1821,7 @@ void genesys_init_sensor_tables() profile.dpi = 1200; profile.exposure_lperiod = 2696; profile.exposure = { 1464, 844, 555 }; - profile.segment_count = 5187; + profile.segment_size = 5187; profile.segment_order = {0, 1}; profile.custom_regs = { { 0x17, 0x0a }, @@ -1836,7 +1836,7 @@ void genesys_init_sensor_tables() profile.dpi = 2400; profile.exposure_lperiod = 10576; profile.exposure = { 2798, 1558, 972 }; - profile.segment_count = 5187; + profile.segment_size = 5187; profile.segment_order = {0, 1, 2, 3}; profile.custom_regs = { { 0x17, 0x08 }, @@ -1851,7 +1851,7 @@ void genesys_init_sensor_tables() profile.dpi = 4800; profile.exposure_lperiod = 10576; profile.exposure = { 2798, 1558, 972 }; - profile.segment_count = 5187; + profile.segment_size = 5187; profile.segment_order = {0, 1, 4, 5, 2, 3, 6, 7}; profile.custom_regs = { { 0x17, 0x06 }, @@ -1912,7 +1912,7 @@ void genesys_init_sensor_tables() profile.dpi = 200; profile.exposure_lperiod = 2848; profile.exposure = { 410, 275, 203 }; - profile.segment_count = 5136; + profile.segment_size = 5136; profile.segment_order = {}; profile.custom_regs = { { 0x17, 0x0a }, @@ -1928,7 +1928,7 @@ void genesys_init_sensor_tables() profile.dpi = 300; profile.exposure_lperiod = 1424; profile.exposure = { 410, 275, 203 }; - profile.segment_count = 5136; + profile.segment_size = 5136; profile.segment_order = {}; profile.custom_regs = { { 0x17, 0x0a }, @@ -1943,7 +1943,7 @@ void genesys_init_sensor_tables() profile.dpi = 600; profile.exposure_lperiod = 1432; profile.exposure = { 410, 275, 203 }; - profile.segment_count = 5136; + profile.segment_size = 5136; profile.segment_order = {}; profile.custom_regs = { { 0x17, 0x0a }, @@ -1958,7 +1958,7 @@ void genesys_init_sensor_tables() profile.dpi = 1200; profile.exposure_lperiod = 2712; profile.exposure = { 746, 478, 353 }; - profile.segment_count = 5136; + profile.segment_size = 5136; profile.segment_order = {0, 1}; profile.custom_regs = { { 0x17, 0x08 }, @@ -1973,7 +1973,7 @@ void genesys_init_sensor_tables() profile.dpi = 2400; profile.exposure_lperiod = 5280; profile.exposure = { 1417, 909, 643 }; - profile.segment_count = 5136; + profile.segment_size = 5136; profile.segment_order = {0, 2, 1, 3}; profile.custom_regs = { { 0x17, 0x06 }, @@ -3354,7 +3354,7 @@ void genesys_init_sensor_tables() profile.dpi = 1200; profile.exposure_lperiod = 11000; profile.exposure = { 0, 0, 0 }; - profile.segment_count = 5136; + profile.segment_size = 5136; profile.segment_order = {0, 1}; profile.custom_regs = { { 0x17, 0x13 }, @@ -3416,7 +3416,7 @@ void genesys_init_sensor_tables() profile.dpi = 1200; profile.exposure_lperiod = 11000; profile.exposure = { 0, 0, 0 }; - profile.segment_count = 5136; + profile.segment_size = 5136; profile.segment_order = {0, 1}; profile.custom_regs = { { 0x17, 0x13 }, From f92253adc86b425abc228ddbed6de1dac67f40c3 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Thu, 12 Sep 2019 21:26:57 +0300 Subject: [PATCH 7/8] genesys: Move Genesys_Device::segnb to DesegmentationState --- backend/genesys.cc | 23 +++++++++++------------ backend/genesys_device.h | 5 +++-- backend/genesys_gl124.cc | 34 +++++++++++++++++----------------- backend/genesys_gl846.cc | 24 ++++++++++-------------- backend/genesys_gl847.cc | 24 ++++++++++-------------- 5 files changed, 51 insertions(+), 59 deletions(-) diff --git a/backend/genesys.cc b/backend/genesys.cc index 4e713690d..7781fda9f 100644 --- a/backend/genesys.cc +++ b/backend/genesys.cc @@ -3457,7 +3457,7 @@ static void genesys_fill_segmented_buffer(Genesys_Device* dev, uint8_t* work_buf { DBG_HELPER(dbg); size_t count; - int depth,i,n,k; + int depth, i, k; depth = dev->settings.depth; if (dev->settings.scan_mode == ScanColorMode::LINEART && dev->settings.dynamic_lineart==SANE_FALSE) @@ -3476,13 +3476,13 @@ static void genesys_fill_segmented_buffer(Genesys_Device* dev, uint8_t* work_buf { if (depth==1) { while (dev->cur < dev->deseg.pixel_groups && count < size) { - for (n=0; nsegnb; n++) { + for (unsigned n = 0; n < dev->deseg.segment_count; n++) { work_buffer_dst[count+n] = 0; } /* interleaving is at bit level */ for (i=0;i<8;i++) { - k=count+(i*dev->segnb)/8; - for (n=0;nsegnb;n++) { + k = count + (i * dev->deseg.segment_count) / 8; + for (unsigned n = 0; n < dev->deseg.segment_count; n++) { work_buffer_dst[k] = work_buffer_dst[k] << 1; if ((dev->oe_buffer.get_read_pos()[dev->cur + dev->deseg.skip_bytes + dev->deseg.conseq_pixel_dist_bytes * dev->segment_order[n]])&(128>>i)) { work_buffer_dst[k] |= 1; @@ -3491,28 +3491,28 @@ static void genesys_fill_segmented_buffer(Genesys_Device* dev, uint8_t* work_buf } /* update counter and pointer */ - count += dev->segnb; + count += dev->deseg.segment_count; dev->cur++; } } if (depth==8) { while (dev->cur < dev->deseg.pixel_groups && count < size) { - for (n=0;nsegnb;n++) { + for (unsigned n = 0; n < dev->deseg.segment_count; n++) { work_buffer_dst[count+n] = dev->oe_buffer.get_read_pos()[dev->cur + dev->deseg.skip_bytes + dev->deseg.conseq_pixel_dist_bytes *dev->segment_order[n]]; } /* update counter and pointer */ - count += dev->segnb; + count += dev->deseg.segment_count; dev->cur++; } } if (depth==16) { while (dev->cur < dev->deseg.pixel_groups && count < size) { - for (n=0;nsegnb;n++) { + for (unsigned n = 0; n < dev->deseg.segment_count; n++) { work_buffer_dst[count+n*2] = dev->oe_buffer.get_read_pos()[dev->cur + dev->deseg.skip_bytes + dev->deseg.conseq_pixel_dist_bytes * dev->segment_order[n]]; work_buffer_dst[count+n*2+1] = dev->oe_buffer.get_read_pos()[dev->cur + dev->deseg.skip_bytes + dev->deseg.conseq_pixel_dist_bytes * dev->segment_order[n] + 1]; } /* update counter and pointer */ - count += dev->segnb*2; + count += dev->deseg.segment_count * 2; dev->cur+=2; } } @@ -3591,8 +3591,7 @@ static void genesys_fill_read_buffer(Genesys_Device* dev) // line interpolation genesys_fill_line_interp_buffer(dev, work_buffer_dst, size); } - else if (dev->segnb>1) - { + else if (dev->deseg.segment_count > 1) { // multi-segment sensors processing genesys_fill_segmented_buffer(dev, work_buffer_dst, size); } @@ -5528,7 +5527,7 @@ sane_open_impl(SANE_String_Const devicename, SANE_Handle * handle) s->dev->force_calibration = 0; s->dev->line_interp = 0; s->dev->line_count = 0; - s->dev->segnb = 0; + s->dev->deseg.segment_count = 0; s->dev->binary=NULL; *handle = s; diff --git a/backend/genesys_device.h b/backend/genesys_device.h index 46f72bab9..c4dbb51d2 100644 --- a/backend/genesys_device.h +++ b/backend/genesys_device.h @@ -195,6 +195,9 @@ struct Genesys_Model // Describes the geometry of the raw data coming out of the scanner for desegmentation. struct DesegmentationState { + // The number of segments in the sensor + unsigned segment_count = 0; + // The number of bytes to skip at start of line. Currently it's always zero. unsigned skip_bytes = 0; @@ -331,8 +334,6 @@ struct Genesys_Device SANE_Int ld_shift_g = 0; // used blue line-distance shift SANE_Int ld_shift_b = 0; - // number of segments composing the sensor - int segnb = 0; // number of lines used in line interpolation int line_interp = 0; // number of scan lines used during scan diff --git a/backend/genesys_gl124.cc b/backend/genesys_gl124.cc index 74b79dda5..e8dd58ab4 100644 --- a/backend/genesys_gl124.cc +++ b/backend/genesys_gl124.cc @@ -829,7 +829,7 @@ static void gl124_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens DBG_HELPER_ARGS(dbg, "exposure_time=%d, start=%d\n", exposure_time, start); unsigned int segcnt; - unsigned int startx, endx, segnb; + unsigned int startx, endx; unsigned int dpihw, factor; GenesysRegister *r; uint32_t expmax; @@ -978,17 +978,16 @@ static void gl124_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens /* segment number */ r = sanei_genesys_get_address (reg, 0x98); - segnb = r->value & 0x0f; + unsigned segment_count = r->value & 0x0f; - reg->set24(REG_STRPIXEL, startx / segnb); - DBG (DBG_io2, "%s: strpixel used=%d\n", __func__, startx/segnb); + reg->set24(REG_STRPIXEL, startx / segment_count); + DBG (DBG_io2, "%s: strpixel used=%d\n", __func__, startx / segment_count); segcnt = reg->get24(REG_SEGCNT); - if(endx/segnb==segcnt) - { + if(endx / segment_count == segcnt) { endx=0; } - reg->set24(REG_ENDPIXEL, endx / segnb); - DBG (DBG_io2, "%s: endpixel used=%d\n", __func__, endx/segnb); + reg->set24(REG_ENDPIXEL, endx / segment_count); + DBG (DBG_io2, "%s: endpixel used=%d\n", __func__, endx / segment_count); // words(16bit) before gamma, conversion to 8 bit or lineart dev->deseg.raw_channel_bytes = @@ -997,9 +996,9 @@ static void gl124_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens dev->cur = 0; dev->deseg.skip_bytes = 0; - dev->deseg.pixel_groups = dev->deseg.raw_channel_bytes / segnb; - dev->deseg.conseq_pixel_dist_bytes = dev->deseg.raw_channel_bytes / segnb; - dev->segnb = segnb; + dev->deseg.pixel_groups = dev->deseg.raw_channel_bytes / segment_count; + dev->deseg.conseq_pixel_dist_bytes = dev->deseg.raw_channel_bytes / segment_count; + dev->deseg.segment_count = segment_count; dev->line_count = 0; dev->line_interp = 0; @@ -1210,7 +1209,7 @@ gl124_calculate_current_setup (Genesys_Device * dev, const Genesys_Sensor& senso const SensorProfile& sensor_profile = get_sensor_profile(sensor, dpihw, session.ccd_size_divisor); - dev->segnb = sensor_profile.custom_regs.get_value(0x98) & 0x0f; + dev->deseg.segment_count = sensor_profile.custom_regs.get_value(0x98) & 0x0f; dev->session = session; dev->current_setup.pixels = session.output_pixels; @@ -1943,7 +1942,9 @@ static void gl124_send_shading_data(Genesys_Device* dev, const Genesys_Sensor& s channels = dev->session.params.channels; if(dev->binary!=NULL) { - fprintf(dev->binary,"P5\n%d %d\n%d\n",(endpixel-strpixel)/factor*channels*dev->segnb,lines/channels,255); + std::fprintf(dev->binary,"P5\n%d %d\n%d\n", + (endpixel - strpixel) / factor * channels * dev->deseg.segment_count, + lines / channels, 255); } } @@ -1954,7 +1955,7 @@ static void gl124_send_shading_data(Genesys_Device* dev, const Genesys_Sensor& s pixels=endpixel-strpixel; DBG( DBG_io2, "%s: using chunks of %d bytes (%d shading data pixels)\n",__func__,length, length/4); - std::vector buffer(pixels * dev->segnb, 0); + std::vector buffer(pixels * dev->deseg.segment_count, 0); /* write actual red data */ for(i=0;i<3;i++) @@ -1970,8 +1971,7 @@ static void gl124_send_shading_data(Genesys_Device* dev, const Genesys_Sensor& s src=data+x+strpixel+i*length; /* iterate over all the segments */ - switch(dev->segnb) - { + switch (dev->deseg.segment_count) { case 1: ptr[0+pixels*0]=src[0+segcnt*0]; ptr[1+pixels*0]=src[1+segcnt*0]; @@ -2013,7 +2013,7 @@ static void gl124_send_shading_data(Genesys_Device* dev, const Genesys_Sensor& s } uint8_t val = dev->read_register(0xd0+i); addr = val * 8192 + 0x10000000; - sanei_genesys_write_ahb(dev, addr, pixels*dev->segnb, buffer.data()); + sanei_genesys_write_ahb(dev, addr, pixels * dev->deseg.segment_count, buffer.data()); } } diff --git a/backend/genesys_gl846.cc b/backend/genesys_gl846.cc index 61398717e..0d20d0903 100644 --- a/backend/genesys_gl846.cc +++ b/backend/genesys_gl846.cc @@ -726,7 +726,7 @@ static void gl846_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens { DBG_HELPER_ARGS(dbg, "exposure_time=%d, start=%d", exposure_time, start); unsigned int words_per_line; - unsigned int dpihw, segnb, factor; + unsigned int dpihw, factor; GenesysRegister *r; // resolution is divided according to ccd_pixels_per_system_pixel() @@ -749,30 +749,26 @@ static void gl846_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens /* sensors are built from 600 dpi segments for LiDE 100/200 * and 1200 dpi for the 700F */ - if (dev->model->flags & GENESYS_FLAG_SIS_SENSOR) - { - segnb=dpihw/600; - } - else - { - segnb=1; + unsigned segment_count = 1; + if (dev->model->flags & GENESYS_FLAG_SIS_SENSOR) { + segment_count = dpihw / 600; } // compute pixel coordinate in the given dpihw space, taking segments into account - startx /= factor*segnb; - endx /= factor*segnb; + startx /= factor * segment_count; + endx /= factor * segment_count; dev->deseg.pixel_groups = endx - startx; dev->deseg.conseq_pixel_dist_bytes = 0; dev->deseg.skip_bytes = 0; /* in cas of multi-segments sensor, we have to add the witdh * of the sensor crossed by the scan area */ - if (dev->model->flags & GENESYS_FLAG_SIS_SENSOR && segnb > 1) { + if (dev->model->flags & GENESYS_FLAG_SIS_SENSOR && segment_count > 1) { dev->deseg.conseq_pixel_dist_bytes = sensor_profile.segment_size; } /* use a segcnt rounded to next even number */ - endx += ((dev->deseg.conseq_pixel_dist_bytes + 1) & 0xfffe) * (segnb - 1); + endx += ((dev->deseg.conseq_pixel_dist_bytes + 1) & 0xfffe) * (segment_count - 1); unsigned used_pixels = endx - startx; gl846_set_fe(dev, sensor, AFE_SET); @@ -876,7 +872,7 @@ static void gl846_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens dev->deseg.conseq_pixel_dist_bytes = multiply_by_depth_ceil(dev->deseg.conseq_pixel_dist_bytes, session.params.depth); dev->cur=0; - dev->segnb=segnb; + dev->deseg.segment_count = segment_count; dev->line_interp = 0; unsigned dpiset = session.params.xres * ccd_pixels_per_system_pixel; @@ -894,7 +890,7 @@ static void gl846_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens DBG (DBG_io2, "%s: dev->bpl =%lu\n", __func__, (unsigned long) dev->deseg.raw_channel_bytes); DBG (DBG_io2, "%s: dev->len =%lu\n", __func__, (unsigned long) dev->deseg.pixel_groups); DBG (DBG_io2, "%s: dev->dist =%lu\n", __func__, (unsigned long) dev->deseg.conseq_pixel_dist_bytes); - DBG (DBG_io2, "%s: dev->segnb =%lu\n", __func__, (unsigned long)dev->segnb); + DBG (DBG_io2, "%s: dev->segnb =%lu\n", __func__, (unsigned long) dev->deseg.segment_count); dev->deseg.raw_line_bytes = dev->deseg.raw_channel_bytes * session.params.channels; diff --git a/backend/genesys_gl847.cc b/backend/genesys_gl847.cc index cf483b294..4b89424df 100644 --- a/backend/genesys_gl847.cc +++ b/backend/genesys_gl847.cc @@ -744,7 +744,7 @@ static void gl847_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens const ScanSession& session, unsigned int start) { DBG_HELPER_ARGS(dbg, "exposure_time=%d, start=%d", exposure_time, start); - unsigned dpiset, dpihw, segnb, factor; + unsigned dpiset, dpihw, factor; GenesysRegister *r; // resolution is divided according to ccd_pixels_per_system_pixel() @@ -768,30 +768,26 @@ static void gl847_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens /* sensors are built from 600 dpi segments for LiDE 100/200 * and 1200 dpi for the 700F */ - if (dev->model->flags & GENESYS_FLAG_SIS_SENSOR) - { - segnb=dpihw/600; - } - else - { - segnb=1; + unsigned segment_count = 1; + if (dev->model->flags & GENESYS_FLAG_SIS_SENSOR) { + segment_count = dpihw/600; } // compute pixel coordinate in the given dpihw space, taking segments into account - startx /= factor*segnb; - endx /= factor*segnb; + startx /= factor * segment_count; + endx /= factor * segment_count; dev->deseg.pixel_groups = endx-startx; dev->deseg.conseq_pixel_dist_bytes = 0; dev->deseg.skip_bytes = 0; /* in cas of multi-segments sensor, we have to add the witdh * of the sensor crossed by the scan area */ - if (dev->model->flags & GENESYS_FLAG_SIS_SENSOR && segnb > 1) { + if (dev->model->flags & GENESYS_FLAG_SIS_SENSOR && segment_count > 1) { dev->deseg.conseq_pixel_dist_bytes = sensor_profile.segment_size; } /* use a segcnt rounded to next even number */ - endx += ((dev->deseg.conseq_pixel_dist_bytes + 1) & 0xfffe) * (segnb - 1); + endx += ((dev->deseg.conseq_pixel_dist_bytes + 1) & 0xfffe) * (segment_count - 1); unsigned used_pixels = endx - startx; gl847_set_fe(dev, sensor, AFE_SET); @@ -895,7 +891,7 @@ static void gl847_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens dev->deseg.conseq_pixel_dist_bytes = multiply_by_depth_ceil(dev->deseg.conseq_pixel_dist_bytes, session.params.depth); dev->cur=0; - dev->segnb=segnb; + dev->deseg.segment_count = segment_count; dev->line_interp = 0; reg->set16(REG_DPISET,dpiset); @@ -912,7 +908,7 @@ static void gl847_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens DBG (DBG_io2, "%s: dev->bpl =%lu\n", __func__, (unsigned long) dev->deseg.raw_channel_bytes); DBG (DBG_io2, "%s: dev->len =%lu\n", __func__, (unsigned long) dev->deseg.pixel_groups); DBG (DBG_io2, "%s: dev->dist =%lu\n", __func__, (unsigned long) dev->deseg.conseq_pixel_dist_bytes); - DBG (DBG_io2, "%s: dev->segnb =%lu\n", __func__, (unsigned long)dev->segnb); + DBG (DBG_io2, "%s: dev->segnb =%lu\n", __func__, (unsigned long) dev->deseg.segment_count); dev->deseg.raw_line_bytes = dev->deseg.raw_channel_bytes * session.params.channels; From 676831dc7bf9cab36fe72786e8a89d935ea8da0b Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Thu, 12 Sep 2019 21:26:58 +0300 Subject: [PATCH 8/8] genesys: Move Genesys_Device::curr to DesegmentationState --- backend/genesys.cc | 34 +++++++++++++++++----------------- backend/genesys_device.h | 5 +++-- backend/genesys_gl124.cc | 2 +- backend/genesys_gl846.cc | 2 +- backend/genesys_gl847.cc | 2 +- 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/backend/genesys.cc b/backend/genesys.cc index 7781fda9f..029be9df7 100644 --- a/backend/genesys.cc +++ b/backend/genesys.cc @@ -3424,17 +3424,17 @@ static void genesys_fill_line_interp_buffer(Genesys_Device* dev, uint8_t* work_b // dev->line_interp holds the number of lines scanned for one line of data sent if (((dev->line_count / dev->session.params.channels) % dev->line_interp) == 0) { /* copy pixel when line matches */ - work_buffer_dst[count] = dev->oe_buffer.get_read_pos()[dev->cur]; + work_buffer_dst[count] = dev->oe_buffer.get_read_pos()[dev->deseg.curr_byte]; count++; } - /* always update pointer so we skip uncopied data */ - dev->cur++; + // always update pointer so we skip uncopied data + dev->deseg.curr_byte++; /* go to next line if needed */ - if (dev->cur == dev->deseg.pixel_groups) { + if (dev->deseg.curr_byte == dev->deseg.pixel_groups) { dev->oe_buffer.set_pos(dev->oe_buffer.pos() + dev->deseg.raw_channel_bytes); - dev->cur = 0; + dev->deseg.curr_byte = 0; dev->line_count++; } @@ -3475,7 +3475,7 @@ static void genesys_fill_segmented_buffer(Genesys_Device* dev, uint8_t* work_buf while (count < size) { if (depth==1) { - while (dev->cur < dev->deseg.pixel_groups && count < size) { + while (dev->deseg.curr_byte < dev->deseg.pixel_groups && count < size) { for (unsigned n = 0; n < dev->deseg.segment_count; n++) { work_buffer_dst[count+n] = 0; } @@ -3484,7 +3484,7 @@ static void genesys_fill_segmented_buffer(Genesys_Device* dev, uint8_t* work_buf k = count + (i * dev->deseg.segment_count) / 8; for (unsigned n = 0; n < dev->deseg.segment_count; n++) { work_buffer_dst[k] = work_buffer_dst[k] << 1; - if ((dev->oe_buffer.get_read_pos()[dev->cur + dev->deseg.skip_bytes + dev->deseg.conseq_pixel_dist_bytes * dev->segment_order[n]])&(128>>i)) { + if ((dev->oe_buffer.get_read_pos()[dev->deseg.curr_byte + dev->deseg.skip_bytes + dev->deseg.conseq_pixel_dist_bytes * dev->segment_order[n]])&(128>>i)) { work_buffer_dst[k] |= 1; } } @@ -3492,35 +3492,35 @@ static void genesys_fill_segmented_buffer(Genesys_Device* dev, uint8_t* work_buf /* update counter and pointer */ count += dev->deseg.segment_count; - dev->cur++; + dev->deseg.curr_byte++; } } if (depth==8) { - while (dev->cur < dev->deseg.pixel_groups && count < size) { + while (dev->deseg.curr_byte < dev->deseg.pixel_groups && count < size) { for (unsigned n = 0; n < dev->deseg.segment_count; n++) { - work_buffer_dst[count+n] = dev->oe_buffer.get_read_pos()[dev->cur + dev->deseg.skip_bytes + dev->deseg.conseq_pixel_dist_bytes *dev->segment_order[n]]; + work_buffer_dst[count+n] = dev->oe_buffer.get_read_pos()[dev->deseg.curr_byte + dev->deseg.skip_bytes + dev->deseg.conseq_pixel_dist_bytes *dev->segment_order[n]]; } /* update counter and pointer */ count += dev->deseg.segment_count; - dev->cur++; + dev->deseg.curr_byte++; } } if (depth==16) { - while (dev->cur < dev->deseg.pixel_groups && count < size) { + while (dev->deseg.curr_byte < dev->deseg.pixel_groups && count < size) { for (unsigned n = 0; n < dev->deseg.segment_count; n++) { - work_buffer_dst[count+n*2] = dev->oe_buffer.get_read_pos()[dev->cur + dev->deseg.skip_bytes + dev->deseg.conseq_pixel_dist_bytes * dev->segment_order[n]]; - work_buffer_dst[count+n*2+1] = dev->oe_buffer.get_read_pos()[dev->cur + dev->deseg.skip_bytes + dev->deseg.conseq_pixel_dist_bytes * dev->segment_order[n] + 1]; + work_buffer_dst[count+n*2] = dev->oe_buffer.get_read_pos()[dev->deseg.curr_byte + dev->deseg.skip_bytes + dev->deseg.conseq_pixel_dist_bytes * dev->segment_order[n]]; + work_buffer_dst[count+n*2+1] = dev->oe_buffer.get_read_pos()[dev->deseg.curr_byte + dev->deseg.skip_bytes + dev->deseg.conseq_pixel_dist_bytes * dev->segment_order[n] + 1]; } /* update counter and pointer */ count += dev->deseg.segment_count * 2; - dev->cur+=2; + dev->deseg.curr_byte += 2; } } /* go to next line if needed */ - if (dev->cur == dev->deseg.pixel_groups) { + if (dev->deseg.curr_byte == dev->deseg.pixel_groups) { dev->oe_buffer.set_pos(dev->oe_buffer.pos() + dev->deseg.raw_channel_bytes); - dev->cur = 0; + dev->deseg.curr_byte = 0; } /* read a new buffer if needed */ diff --git a/backend/genesys_device.h b/backend/genesys_device.h index c4dbb51d2..ba9edcd38 100644 --- a/backend/genesys_device.h +++ b/backend/genesys_device.h @@ -214,6 +214,9 @@ struct DesegmentationState // Total bytes in a line received from a scanner unsigned raw_line_bytes = 0; + + // The current byte during desegmentation process + unsigned curr_byte = 0; }; /** @@ -338,8 +341,6 @@ struct Genesys_Device int line_interp = 0; // number of scan lines used during scan int line_count = 0; - // current pixel position within sub window - size_t cur = 0; // array describing the order of the sub-segments of the sensor std::vector segment_order; diff --git a/backend/genesys_gl124.cc b/backend/genesys_gl124.cc index e8dd58ab4..8d0f7671f 100644 --- a/backend/genesys_gl124.cc +++ b/backend/genesys_gl124.cc @@ -994,7 +994,7 @@ static void gl124_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens multiply_by_depth_ceil(session.output_pixels / session.ccd_size_divisor, session.params.depth); - dev->cur = 0; + dev->deseg.curr_byte = 0; dev->deseg.skip_bytes = 0; dev->deseg.pixel_groups = dev->deseg.raw_channel_bytes / segment_count; dev->deseg.conseq_pixel_dist_bytes = dev->deseg.raw_channel_bytes / segment_count; diff --git a/backend/genesys_gl846.cc b/backend/genesys_gl846.cc index 0d20d0903..fbde72bc7 100644 --- a/backend/genesys_gl846.cc +++ b/backend/genesys_gl846.cc @@ -871,7 +871,7 @@ static void gl846_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens dev->deseg.pixel_groups = multiply_by_depth_ceil(dev->deseg.pixel_groups, session.params.depth); dev->deseg.conseq_pixel_dist_bytes = multiply_by_depth_ceil(dev->deseg.conseq_pixel_dist_bytes, session.params.depth); - dev->cur=0; + dev->deseg.curr_byte = 0; dev->deseg.segment_count = segment_count; dev->line_interp = 0; diff --git a/backend/genesys_gl847.cc b/backend/genesys_gl847.cc index 4b89424df..529217c7a 100644 --- a/backend/genesys_gl847.cc +++ b/backend/genesys_gl847.cc @@ -890,7 +890,7 @@ static void gl847_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens dev->deseg.pixel_groups = multiply_by_depth_ceil(dev->deseg.pixel_groups, session.params.depth); dev->deseg.conseq_pixel_dist_bytes = multiply_by_depth_ceil(dev->deseg.conseq_pixel_dist_bytes, session.params.depth); - dev->cur=0; + dev->deseg.curr_byte = 0; dev->deseg.segment_count = segment_count; dev->line_interp = 0;