From 991eec63d57ef58a6c67af7e18f182edf13aaf7c Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Thu, 12 Sep 2019 19:34:43 +0300 Subject: [PATCH] genesys: Use common code path to compute session output_line_count --- backend/genesys_gl124.cc | 17 +++++------------ backend/genesys_gl646.cc | 19 +++++++------------ backend/genesys_gl841.cc | 20 +++++++------------- backend/genesys_gl843.cc | 7 +------ backend/genesys_gl846.cc | 15 +++++---------- backend/genesys_gl847.cc | 15 +++++---------- backend/genesys_low.cc | 2 ++ backend/genesys_settings.h | 1 - 8 files changed, 32 insertions(+), 64 deletions(-) diff --git a/backend/genesys_gl124.cc b/backend/genesys_gl124.cc index f6dcf7869..bb49451f9 100644 --- a/backend/genesys_gl124.cc +++ b/backend/genesys_gl124.cc @@ -1068,7 +1068,6 @@ static void gl124_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens int start; int bytes_per_line; int move; - unsigned int lincnt; unsigned int mflags; int exposure_time; @@ -1128,10 +1127,6 @@ static void gl124_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens session.params.depth, session.ccd_size_divisor, session.params.color_filter); - /*** motor parameters ***/ - - lincnt = session.params.lines + session.max_color_shift_lines + session.num_staggered_lines; - /* add tl_y to base movement */ move = session.params.starty; DBG(DBG_info, "%s: move=%d steps\n", __func__, move); @@ -1144,7 +1139,8 @@ static void gl124_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens mflags |= MOTOR_FLAG_FEED; } gl124_init_motor_regs_scan(dev, sensor, reg, exposure_time, slope_dpi, scan_step_type, - dev->model->is_cis ? lincnt * session.params.channels : lincnt, + dev->model->is_cis ? session.output_line_count * session.params.channels : + session.output_line_count, dummy, move, session.params.scan_mode, mflags); /*** prepares data reordering ***/ @@ -1174,7 +1170,7 @@ static void gl124_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens dev->out_buffer.clear(); dev->out_buffer.alloc((8 * dev->settings.pixels * session.params.channels * session.params.depth) / 8); - dev->read_bytes_left = bytes_per_line * lincnt; + dev->read_bytes_left = bytes_per_line * session.output_line_count; DBG(DBG_info, "%s: physical bytes to read = %lu\n", __func__, (u_long) dev->read_bytes_left); dev->read_active = SANE_TRUE; @@ -1182,7 +1178,7 @@ static void gl124_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens dev->session = session; dev->current_setup.pixels = session.output_pixels; DBG(DBG_info, "%s: current_setup.pixels=%d\n", __func__, dev->current_setup.pixels); - dev->current_setup.lines = lincnt; + dev->current_setup.lines = session.output_line_count; dev->current_setup.exposure_time = exposure_time; dev->current_setup.xres = session.params.xres; dev->current_setup.ccd_size_divisor = session.ccd_size_divisor; @@ -1207,7 +1203,6 @@ gl124_calculate_current_setup (Genesys_Device * dev, const Genesys_Sensor& senso { int start; - unsigned int lincnt; int exposure_time; int dpihw; @@ -1255,12 +1250,10 @@ gl124_calculate_current_setup (Genesys_Device * dev, const Genesys_Sensor& senso session.ccd_size_divisor); dev->segnb = sensor_profile.custom_regs.get_value(0x98) & 0x0f; - lincnt = session.params.lines + session.max_color_shift_lines + session.num_staggered_lines; - dev->session = session; dev->current_setup.pixels = session.output_pixels; DBG (DBG_info, "%s: current_setup.pixels=%d\n", __func__, dev->current_setup.pixels); - dev->current_setup.lines = lincnt; + dev->current_setup.lines = session.output_line_count; dev->current_setup.exposure_time = exposure_time; dev->current_setup.xres = session.params.xres; dev->current_setup.ccd_size_divisor = session.ccd_size_divisor; diff --git a/backend/genesys_gl646.cc b/backend/genesys_gl646.cc index 24e47fd12..54ffb0c10 100644 --- a/backend/genesys_gl646.cc +++ b/backend/genesys_gl646.cc @@ -328,7 +328,6 @@ static void gl646_setup_registers(Genesys_Device* dev, debug_dump(DBG_info, sensor); uint32_t move = session.params.starty; - uint32_t linecnt = session.params.lines; uint32_t startx = 0; /* pixels are allways given at full CCD optical resolution */ @@ -366,7 +365,7 @@ static void gl646_setup_registers(Genesys_Device* dev, size_t read_buffer_size; int feedl; - DBG(DBG_info, "%s: startx=%d, endx=%d, linecnt=%d\n", __func__, startx, endx, linecnt); + DBG(DBG_info, "%s: startx=%d, endx=%d\n", __func__, startx, endx); /* for the given resolution, search for master * motor mode setting */ @@ -548,22 +547,16 @@ static void gl646_setup_registers(Genesys_Device* dev, regs->find_reg(0x23).value = motor->fwdbwd; regs->find_reg(0x24).value = motor->steps1; - linecnt = linecnt + session.max_color_shift_lines; - - /* at QUATER_STEP lines are 'staggered' and need correction */ - linecnt += session.num_staggered_lines; - /* CIS scanners read one line per color channel * since gray mode use 'add' we also read 3 channels even not in * color mode */ if (dev->model->is_cis == SANE_TRUE) { - regs->set24(REG_LINCNT, linecnt * 3); - linecnt *= session.params.channels; + regs->set24(REG_LINCNT, session.output_line_count * 3); } else { - regs->set24(REG_LINCNT, linecnt); + regs->set24(REG_LINCNT, session.output_line_count); } /* scanner's x coordinates are expressed in physical DPI but they must be divided by cksel */ @@ -765,14 +758,16 @@ static void gl646_setup_registers(Genesys_Device* dev, dev->out_buffer.alloc(8 * session.params.pixels * session.params.channels * bpp); /* scan bytes to read */ - dev->read_bytes_left = words_per_line * linecnt; + unsigned cis_channel_multiplier = dev->model->is_cis ? session.params.channels : 1; + + dev->read_bytes_left = words_per_line * session.output_line_count * cis_channel_multiplier; DBG(DBG_info, "%s: physical bytes to read = %lu\n", __func__, (u_long) dev->read_bytes_left); dev->read_active = SANE_TRUE; dev->session = session; dev->current_setup.pixels = session.output_pixels; - dev->current_setup.lines = linecnt; + dev->current_setup.lines = session.output_line_count * cis_channel_multiplier; dev->current_setup.exposure_time = sensor.exposure_lperiod; dev->current_setup.xres = session.output_resolution; dev->current_setup.ccd_size_divisor = session.ccd_size_divisor; diff --git a/backend/genesys_gl841.cc b/backend/genesys_gl841.cc index 8f924c867..41f6633fa 100644 --- a/backend/genesys_gl841.cc +++ b/backend/genesys_gl841.cc @@ -1765,7 +1765,6 @@ static void gl841_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens int start; int bytes_per_line; int move; - unsigned int lincnt; int exposure_time; int avg; @@ -1890,10 +1889,6 @@ dummy \ scanned lines session.params.depth, session.ccd_size_divisor, session.params.color_filter); -/*** motor parameters ***/ - - lincnt = session.params.lines + session.max_color_shift_lines + session.num_staggered_lines; - move = session.params.starty; DBG(DBG_info, "%s: move=%d steps\n", __func__, move); @@ -1910,10 +1905,12 @@ dummy \ scanned lines DBG(DBG_info, "%s: move=%d steps\n", __func__, move);*/ if (session.params.flags & SCAN_FLAG_SINGLE_LINE) { - gl841_init_motor_regs_off(reg, dev->model->is_cis?lincnt* session.params.channels:lincnt); + gl841_init_motor_regs_off(reg, dev->model->is_cis ? session.output_line_count * session.params.channels + : session.output_line_count); } else { gl841_init_motor_regs_scan(dev, sensor, reg, exposure_time, slope_dpi, scan_step_type, - dev->model->is_cis ? lincnt * session.params.channels : lincnt, + dev->model->is_cis ? session.output_line_count * session.params.channels + : session.output_line_count, dummy, move, (session.params.flags & SCAN_FLAG_DISABLE_BUFFER_FULL_MOVE) ? MOTOR_FLAG_DISABLE_BUFFER_FULL_MOVE : 0); @@ -1949,14 +1946,14 @@ dummy \ scanned lines dev->out_buffer.clear(); dev->out_buffer.alloc((8 * dev->settings.pixels * session.params.channels * session.params.depth) / 8); - dev->read_bytes_left = bytes_per_line * lincnt; + dev->read_bytes_left = bytes_per_line * session.output_line_count; DBG(DBG_info, "%s: physical bytes to read = %lu\n", __func__, (u_long) dev->read_bytes_left); dev->read_active = SANE_TRUE; dev->session = session; dev->current_setup.pixels = session.output_pixels; - dev->current_setup.lines = lincnt; + dev->current_setup.lines = session.output_line_count; dev->current_setup.exposure_time = exposure_time; dev->current_setup.xres = session.params.xres; dev->current_setup.ccd_size_divisor = session.ccd_size_divisor; @@ -1995,7 +1992,6 @@ static void gl841_calculate_current_setup(Genesys_Device * dev, const Genesys_Se { int start; - unsigned int lincnt; int exposure_time; int slope_dpi = 0; @@ -2086,11 +2082,9 @@ dummy \ scanned lines session.optical_pixels); DBG(DBG_info, "%s : exposure_time=%d pixels\n", __func__, exposure_time); - lincnt = session.params.lines + session.max_color_shift_lines + session.num_staggered_lines; - dev->session = session; dev->current_setup.pixels = session.output_pixels; - dev->current_setup.lines = lincnt; + dev->current_setup.lines = session.output_line_count; dev->current_setup.exposure_time = exposure_time; dev->current_setup.xres = session.params.xres; dev->current_setup.ccd_size_divisor = session.ccd_size_divisor; diff --git a/backend/genesys_gl843.cc b/backend/genesys_gl843.cc index 3096a64e7..c2415adcc 100644 --- a/backend/genesys_gl843.cc +++ b/backend/genesys_gl843.cc @@ -1193,8 +1193,6 @@ static void gl843_compute_session(Genesys_Device* dev, ScanSession& s, // compute optical and output resolutions s.hwdpi_divisor = sensor.get_hwdpi_divisor_for_dpi(s.params.xres); - s.output_line_count = s.params.lines + s.max_color_shift_lines + s.num_staggered_lines; - s.optical_line_bytes = (s.optical_pixels * s.params.channels * s.params.depth) / 8; s.output_line_bytes = (s.output_pixels * s.params.channels * s.params.depth) / 8; @@ -1365,7 +1363,6 @@ gl843_calculate_current_setup(Genesys_Device * dev, const Genesys_Sensor& sensor { int start; - unsigned int lincnt; int exposure; DBG(DBG_info, "%s ", __func__); @@ -1431,12 +1428,10 @@ gl843_calculate_current_setup(Genesys_Device * dev, const Genesys_Sensor& sensor dev->ld_shift_b = dev->model->ld_shift_b; } - lincnt = session.params.lines + session.max_color_shift_lines + session.num_staggered_lines; - dev->session = session; dev->current_setup.pixels = session.output_pixels; DBG(DBG_info, "%s: current_setup.pixels=%d\n", __func__, dev->current_setup.pixels); - dev->current_setup.lines = lincnt; + dev->current_setup.lines = session.output_line_count; dev->current_setup.exposure_time = exposure; dev->current_setup.xres = session.params.xres; dev->current_setup.ccd_size_divisor = session.ccd_size_divisor; diff --git a/backend/genesys_gl846.cc b/backend/genesys_gl846.cc index 6e363ac17..6753e9e61 100644 --- a/backend/genesys_gl846.cc +++ b/backend/genesys_gl846.cc @@ -953,7 +953,6 @@ static void gl846_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens int start; int bytes_per_line; int move; - unsigned int lincnt; unsigned int mflags; /**> motor flags */ int exposure_time; @@ -1009,8 +1008,6 @@ static void gl846_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens /*** motor parameters ***/ - lincnt = session.params.lines + session.max_color_shift_lines + session.num_staggered_lines; - /* add tl_y to base movement */ move = session.params.starty; DBG(DBG_info, "%s: move=%d steps\n", __func__, move); @@ -1024,7 +1021,8 @@ static void gl846_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens } gl846_init_motor_regs_scan(dev, sensor, reg, exposure_time, slope_dpi, scan_step_type, - dev->model->is_cis ? lincnt * session.params.channels : lincnt, + dev->model->is_cis ? session.output_line_count * session.params.channels + : session.output_line_count, dummy, move, mflags); /*** prepares data reordering ***/ @@ -1051,14 +1049,14 @@ static void gl846_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens dev->out_buffer.clear(); dev->out_buffer.alloc((8 * session.params.pixels * session.params.channels * session.params.depth) / 8); - dev->read_bytes_left = bytes_per_line * lincnt; + dev->read_bytes_left = bytes_per_line * session.output_line_count; DBG(DBG_info, "%s: physical bytes to read = %lu\n", __func__, (u_long) dev->read_bytes_left); dev->read_active = SANE_TRUE; dev->session = session; dev->current_setup.pixels = session.output_pixels; - dev->current_setup.lines = lincnt; + dev->current_setup.lines = session.output_line_count; dev->current_setup.exposure_time = exposure_time; dev->current_setup.xres = session.params.xres; dev->current_setup.ccd_size_divisor = session.ccd_size_divisor; @@ -1098,7 +1096,6 @@ gl846_calculate_current_setup(Genesys_Device * dev, const Genesys_Sensor& sensor { int start; - unsigned int lincnt; int exposure_time; int slope_dpi; @@ -1149,11 +1146,9 @@ gl846_calculate_current_setup(Genesys_Device * dev, const Genesys_Sensor& sensor exposure_time = get_sensor_profile(sensor, session.params.xres).exposure_lperiod; DBG(DBG_info, "%s : exposure_time=%d pixels\n", __func__, exposure_time); - lincnt = session.params.lines + session.max_color_shift_lines + session.num_staggered_lines; - dev->session = session; dev->current_setup.pixels = session.output_pixels; - dev->current_setup.lines = lincnt; + dev->current_setup.lines = session.output_line_count; dev->current_setup.exposure_time = exposure_time; dev->current_setup.xres = session.params.xres; dev->current_setup.ccd_size_divisor = session.ccd_size_divisor; diff --git a/backend/genesys_gl847.cc b/backend/genesys_gl847.cc index 8db35e16b..6ff3622b6 100644 --- a/backend/genesys_gl847.cc +++ b/backend/genesys_gl847.cc @@ -972,7 +972,6 @@ static void gl847_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens int start; int bytes_per_line; int move; - unsigned int lincnt; unsigned int mflags; /**> motor flags */ int exposure_time; @@ -1026,8 +1025,6 @@ static void gl847_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens session.optical_pixels, session.params.channels, session.params.depth, session.params.color_filter); - lincnt = session.params.lines + session.max_color_shift_lines + session.num_staggered_lines; - move = session.params.starty; DBG(DBG_info, "%s: move=%d steps\n", __func__, move); @@ -1040,7 +1037,8 @@ static void gl847_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens } gl847_init_motor_regs_scan(dev, sensor, reg, exposure_time, slope_dpi, scan_step_type, - dev->model->is_cis ? lincnt * session.params.channels : lincnt, + dev->model->is_cis ? session.output_line_count * session.params.channels + : session.output_line_count, dummy, move, mflags); /*** prepares data reordering ***/ @@ -1067,14 +1065,14 @@ static void gl847_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens dev->out_buffer.clear(); dev->out_buffer.alloc((8 * session.params.pixels * session.params.channels * session.params.depth) / 8); - dev->read_bytes_left = bytes_per_line * lincnt; + dev->read_bytes_left = bytes_per_line * session.output_line_count; DBG(DBG_info, "%s: physical bytes to read = %lu\n", __func__, (u_long) dev->read_bytes_left); dev->read_active = SANE_TRUE; dev->session = session; dev->current_setup.pixels = session.output_pixels; - dev->current_setup.lines = lincnt; + dev->current_setup.lines = session.output_line_count; dev->current_setup.exposure_time = exposure_time; dev->current_setup.xres = session.params.xres; dev->current_setup.ccd_size_divisor = session.ccd_size_divisor; @@ -1113,7 +1111,6 @@ gl847_calculate_current_setup(Genesys_Device * dev, const Genesys_Sensor& sensor { int start; - unsigned int lincnt; int exposure_time; int slope_dpi = 0; @@ -1165,11 +1162,9 @@ gl847_calculate_current_setup(Genesys_Device * dev, const Genesys_Sensor& sensor exposure_time = get_sensor_profile(sensor, session.params.xres).exposure_lperiod; DBG(DBG_info, "%s : exposure_time=%d pixels\n", __func__, exposure_time); - lincnt = session.params.lines + session.max_color_shift_lines + session.num_staggered_lines; - dev->session = session; dev->current_setup.pixels = session.output_pixels; - dev->current_setup.lines = lincnt; + dev->current_setup.lines = session.output_line_count; dev->current_setup.exposure_time = exposure_time; dev->current_setup.xres = session.params.xres; dev->current_setup.ccd_size_divisor = session.ccd_size_divisor; diff --git a/backend/genesys_low.cc b/backend/genesys_low.cc index 0e20a25d5..0afe4f24a 100644 --- a/backend/genesys_low.cc +++ b/backend/genesys_low.cc @@ -1221,6 +1221,8 @@ void compute_session(Genesys_Device* dev, ScanSession& s, const Genesys_Sensor& s.max_color_shift_lines = sanei_genesys_compute_max_shift(dev, s.params.channels, s.params.yres, s.params.flags); + + s.output_line_count = s.params.lines + s.max_color_shift_lines + s.num_staggered_lines; } /** @brief initialize device diff --git a/backend/genesys_settings.h b/backend/genesys_settings.h index 2fc3844db..d5aa6b288 100644 --- a/backend/genesys_settings.h +++ b/backend/genesys_settings.h @@ -246,7 +246,6 @@ struct ScanSession { unsigned output_line_bytes = 0; // the number of lines in the output of the scanner. This must be larger than the user - // gl843-only // requested number due to line staggering and color channel shifting. unsigned output_line_count = 0;