From dd2a64e9a4824f8d80435a4115a3b1255dc3332d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Voltz?= Date: Wed, 29 Dec 2010 07:17:14 +0100 Subject: [PATCH 1/3] lide 110/210 scanarea fine tuning --- backend/genesys.c | 12 ++++++------ backend/genesys_devices.c | 8 ++++---- backend/genesys_gl124.c | 17 +++++++++-------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/backend/genesys.c b/backend/genesys.c index 76522b876..6c5d94225 100644 --- a/backend/genesys.c +++ b/backend/genesys.c @@ -5481,9 +5481,13 @@ Problems with the first approach: DBG (DBG_error, "Cannot convert from 16bit to lineart\n"); return SANE_STATUS_INVAL; } -/*lines in input*/ + /* lines in input to process */ dst_lines = bytes / (dev->settings.pixels * channels); - + if(dst_lines==0) + { + /* padd to at least line length */ + dst_lines=1; + } bytes = dst_lines * dev->settings.pixels * channels; status = genesys_gray_lineart (dev, @@ -6053,10 +6057,6 @@ init_options (Genesys_Scanner * s) { s->opt[OPT_DISABLE_DYNAMIC_LINEART].cap = SANE_CAP_INACTIVE; } - if (s->dev->model->asic_type == GENESYS_GL124) - { - s->val[OPT_DISABLE_DYNAMIC_LINEART].w = SANE_TRUE; - } /* disable_interpolation */ s->opt[OPT_DISABLE_INTERPOLATION].name = "disable-interpolation"; diff --git a/backend/genesys_devices.c b/backend/genesys_devices.c index c85d9aa1a..d8eefcf9b 100644 --- a/backend/genesys_devices.c +++ b/backend/genesys_devices.c @@ -1315,9 +1315,9 @@ static Genesys_Model canon_lide_110_model = { {16, 8, 0}, /* possible depths in color mode */ SANE_FIX (3.6), /* Start of scan area in mm (x) */ - SANE_FIX (8.2), /* Start of scan area in mm (y) */ + SANE_FIX (8.5), /* Start of scan area in mm (y) */ SANE_FIX (213.80), /* Size of scan area in mm (x) */ - SANE_FIX (297.0), /* Size of scan area in mm (y) */ + SANE_FIX (300.0), /* Size of scan area in mm (y) */ SANE_FIX (1.0), /* Start of white strip in mm (y) */ SANE_FIX (0.0), /* Start of black mark in mm (x) */ @@ -1367,9 +1367,9 @@ static Genesys_Model canon_lide_210_model = { {16, 8, 0}, /* possible depths in color mode */ SANE_FIX (3.6), /* Start of scan area in mm (x) */ - SANE_FIX (8.2), /* Start of scan area in mm (y) */ + SANE_FIX (8.5), /* Start of scan area in mm (y) */ SANE_FIX (213.80), /* Size of scan area in mm (x) */ - SANE_FIX (297.0), /* Size of scan area in mm (y) */ + SANE_FIX (300.0), /* Size of scan area in mm (y) */ SANE_FIX (0.0), /* Start of white strip in mm (y) */ SANE_FIX (0.0), /* Start of black mark in mm (x) */ diff --git a/backend/genesys_gl124.c b/backend/genesys_gl124.c index a92d36433..5f5894d7a 100644 --- a/backend/genesys_gl124.c +++ b/backend/genesys_gl124.c @@ -1071,11 +1071,12 @@ gl124_init_motor_regs_scan (Genesys_Device * dev, /* STEPNO */ sanei_genesys_set_double(reg,REG_STEPNO,scan_steps); - /* FASTNO */ - sanei_genesys_set_double(reg,REG_FASTNO,scan_steps); - /* fast table */ fast_dpi=yres; + if (scan_mode != SCAN_MODE_COLOR) + { + fast_dpi*=3; + } fast_time=gl124_slope_table(fast_table, &fast_steps, fast_dpi, @@ -1087,6 +1088,9 @@ gl124_init_motor_regs_scan (Genesys_Device * dev, RIE(gl124_send_slope_table (dev, STOP_TABLE, fast_table, fast_steps)); RIE(gl124_send_slope_table (dev, FAST_TABLE, fast_table, fast_steps)); + /* FASTNO */ + sanei_genesys_set_double(reg,REG_FASTNO,fast_steps); + /* FSHDEC */ sanei_genesys_set_double(reg,REG_FSHDEC,fast_steps); @@ -1611,9 +1615,6 @@ gl124_init_scan_regs (Genesys_Device * dev, { depth = 8; } - /* XXX STEF XXX - if (depth == 16) - flags |= SCAN_FLAG_DISABLE_GAMMA; */ /* we enable true gray for cis scanners only, and just when doing * scan since color calibration is OK for this mode @@ -2732,7 +2733,7 @@ gl124_init_regs_for_scan (Genesys_Device * dev) if(channels*dev->settings.yres>=1200 && move>3000) { - move-=190; + move -= 180; status = gl124_feed (dev, move); if (status != SANE_STATUS_GOOD) { @@ -2745,7 +2746,7 @@ gl124_init_regs_for_scan (Genesys_Device * dev) { if(channels==1) { - move-=25; + move-=0; } } DBG (DBG_info, "gl124_init_regs_for_scan: move=%f steps\n", move); From de2af06d35a84c3f54485b7919c42e1874b3996c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Voltz?= Date: Mon, 3 Jan 2011 21:35:44 +0100 Subject: [PATCH 2/3] make lineart work when number of segments is higher than 1 --- backend/genesys.c | 109 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 85 insertions(+), 24 deletions(-) diff --git a/backend/genesys.c b/backend/genesys.c index 6c5d94225..e476a2f09 100644 --- a/backend/genesys.c +++ b/backend/genesys.c @@ -4790,6 +4790,13 @@ genesys_fill_segmented_buffer (Genesys_Device * dev, uint8_t *work_buffer_dst, s { size_t count; SANE_Status status; + uint8_t odd,even,mask; + uint16_t merged; + int depth,i; + + depth = dev->settings.depth; + if (dev->settings.scan_mode == SCAN_MODE_LINEART) + depth = 1; /* fill buffer if needed */ if (dev->oe_buffer.avail == 0) @@ -4817,32 +4824,86 @@ genesys_fill_segmented_buffer (Genesys_Device * dev, uint8_t *work_buffer_dst, s count++; dev->cur++; } - else if(dev->settings.depth==8 && dev->settings.double_xres==SANE_FALSE) + else { - while (dev->cur < dev->len && count < size) - { - /* copy even pixel */ - work_buffer_dst[count] = dev->oe_buffer.buffer[dev->cur + dev->skip + dev->oe_buffer.pos]; - /* copy odd pixel */ - work_buffer_dst[count + 1] = dev->oe_buffer.buffer[dev->cur + dev->skip + dev->dist + dev->oe_buffer.pos]; - /* update counter and pointer */ - count += 2; - dev->cur++; + /* here we must handle the segments to copy data */ + if(dev->segnb==2) + { + if(depth==8) + { + while (dev->cur < dev->len && count < size) + { + /* copy even pixel */ + work_buffer_dst[count] = dev->oe_buffer.buffer[dev->cur + dev->skip + dev->oe_buffer.pos]; + /* copy odd pixel */ + work_buffer_dst[count + 1] = dev->oe_buffer.buffer[dev->cur + dev->skip + dev->dist + dev->oe_buffer.pos]; + /* update counter and pointer */ + count += 2; + dev->cur++; + } + } + else if(depth==16) + { + while (dev->cur < dev->len && count < size) + { + /* copy even pixel */ + work_buffer_dst[count] = dev->oe_buffer.buffer[dev->cur + dev->skip + dev->oe_buffer.pos]; + work_buffer_dst[count+1] = dev->oe_buffer.buffer[dev->cur + dev->skip + dev->oe_buffer.pos+1]; + /* copy odd pixel */ + work_buffer_dst[count + 2] = dev->oe_buffer.buffer[dev->cur + dev->skip + dev->dist + dev->oe_buffer.pos]; + work_buffer_dst[count + 3] = dev->oe_buffer.buffer[dev->cur + dev->skip + dev->dist + dev->oe_buffer.pos+1]; + /* update counter and pointer */ + count += 4; + dev->cur+=2; + } + } else { /* lineart case */ + while (dev->cur < dev->len && count < size) + { + /* get values to merge */ + odd = dev->oe_buffer.buffer[dev->cur + dev->skip + dev->oe_buffer.pos]; + even = dev->oe_buffer.buffer[dev->cur + dev->skip + dev->dist + dev->oe_buffer.pos]; + + /* interleave bits .... */ + merged=0; + for(i=7;i>=0;i--) + { + mask=1<0) + { + merged<<=1; + } + } + + /* store result */ + work_buffer_dst[count] = merged >> 8; + work_buffer_dst[count+1] = merged & 255; + + /* update counter and pointer */ + count += 2; + dev->cur++; + } + } } - } - else if(dev->settings.depth==16 && dev->settings.double_xres==SANE_FALSE) - { - while (dev->cur < dev->len && count < size) - { - /* copy even pixel */ - work_buffer_dst[count] = dev->oe_buffer.buffer[dev->cur + dev->skip + dev->oe_buffer.pos]; - work_buffer_dst[count+1] = dev->oe_buffer.buffer[dev->cur + dev->skip + dev->oe_buffer.pos+1]; - /* copy odd pixel */ - work_buffer_dst[count + 2] = dev->oe_buffer.buffer[dev->cur + dev->skip + dev->dist + dev->oe_buffer.pos]; - work_buffer_dst[count + 3] = dev->oe_buffer.buffer[dev->cur + dev->skip + dev->dist + dev->oe_buffer.pos+1]; - /* update counter and pointer */ - count += 4; - dev->cur+=2; + else if(dev->segnb==4) + { + DBG (DBG_error, "%s: %d is an unimplemented segment number ....\n",__FUNCTION__,dev->segnb); + return SANE_STATUS_INVAL; + } + else + { + DBG (DBG_error, "%s: %d is an unimplemented segment number ....\n",__FUNCTION__,dev->segnb); + return SANE_STATUS_INVAL; } } From 8fb58d5118241705a24a24ba1b618c310f1a34ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Voltz?= Date: Tue, 4 Jan 2011 21:37:41 +0100 Subject: [PATCH 3/3] fix lineart issue at 1200 dpi and clean up block read for gl124 --- backend/genesys.c | 30 ++++++++++++++++++------------ backend/genesys_gl124.c | 38 +++++++++++++++++++------------------- 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/backend/genesys.c b/backend/genesys.c index e476a2f09..d6f499052 100644 --- a/backend/genesys.c +++ b/backend/genesys.c @@ -4972,7 +4972,7 @@ genesys_fill_read_buffer (Genesys_Device * dev) size &= ~0xff; } - /* early out if our remaining buffer capacity is too lo w */ + /* early out if our remaining buffer capacity is too low */ if (size == 0) return SANE_STATUS_GOOD; @@ -5010,13 +5010,6 @@ genesys_fill_read_buffer (Genesys_Device * dev) else /* regular case with no extra copy */ { status = dev->model->cmd_set->bulk_read_data (dev, 0x45, work_buffer_dst, size); - if (status != SANE_STATUS_GOOD) - { - DBG (DBG_error, - "genesys_fill_read_buffer: failed to read %lu bytes (%s)\n", - (u_long) size, sane_strstatus (status)); - return SANE_STATUS_IO_ERROR; - } #ifdef SANE_DEBUG_LOG_RAW_DATA if (rawfile != NULL && DBG_LEVEL >= DBG_data) { @@ -5026,6 +5019,13 @@ genesys_fill_read_buffer (Genesys_Device * dev) } #endif } + if (status != SANE_STATUS_GOOD) + { + DBG (DBG_error, + "genesys_fill_read_buffer: failed to read %lu bytes (%s)\n", + (u_long) size, sane_strstatus (status)); + return SANE_STATUS_IO_ERROR; + } if (size > dev->read_bytes_left) size = dev->read_bytes_left; @@ -5658,7 +5658,7 @@ calc_parameters (Genesys_Scanner * s) s->dev->settings.double_xres = SANE_FALSE; if ((s->dev->model->flags & GENESYS_FLAG_ODD_EVEN_CIS) && s->dev->settings.xres <= s->dev->sensor.optical_res / 2 - && s->dev->settings.xres != 400) + && s->dev->settings.xres != 400) { s->dev->settings.double_xres = SANE_TRUE; } @@ -5675,6 +5675,13 @@ calc_parameters (Genesys_Scanner * s) s->params.pixels_per_line = (s->params.pixels_per_line/4)*4; } + /* corner case for true lineart for sensor with several segments */ + if (s->dev->settings.xres >= 1200 + && s->dev->model->asic_type == GENESYS_GL124 ) + { + s->params.pixels_per_line = (s->params.pixels_per_line/16)*16; + } + s->params.bytes_per_line = s->params.pixels_per_line; if (s->params.depth > 8) { @@ -7300,8 +7307,6 @@ set_option_value (Genesys_Scanner * s, int option, void *val, SANE_Status status = SANE_STATUS_GOOD; SANE_Word *table; unsigned int i; - int min, count; - SANE_Word *dpi_list; SANE_Range *x_range, *y_range; Genesys_Calibration_Cache *cache, *next_cache; @@ -7388,6 +7393,7 @@ set_option_value (Genesys_Scanner * s, int option, void *val, /* due to low resolution emulation ,we can't mix lineart * with dpi lower than 300 for GL124 */ + /* XXX STEF XXX if(s->dev->model->asic_type == GENESYS_GL124) { free(s->opt[OPT_RESOLUTION].constraint.word_list); @@ -7405,7 +7411,7 @@ set_option_value (Genesys_Scanner * s, int option, void *val, s->opt[OPT_RESOLUTION].constraint.word_list = dpi_list; if(s->val[OPT_RESOLUTION].wval[OPT_RESOLUTION].w=min; - } + } */ if (strcmp (s->val[option].s, SANE_VALUE_SCAN_MODE_LINEART) == 0) { diff --git a/backend/genesys_gl124.c b/backend/genesys_gl124.c index 5f5894d7a..fa66b370f 100644 --- a/backend/genesys_gl124.c +++ b/backend/genesys_gl124.c @@ -145,31 +145,31 @@ gl124_bulk_read_data (Genesys_Device * dev, uint8_t addr, /* blocks must be multiple of 512 but not last block */ read = size; - if (read >= 512) - { - read /= 512; - read *= 512; - } - - DBG (DBG_io2, - "gl124_bulk_read_data: trying to read %lu bytes of data\n", - (u_long) read); - status = sanei_usb_read_bulk (dev->dn, data, &read); - if (status != SANE_STATUS_GOOD) - { - DBG (DBG_error, - "gl124_bulk_read_data failed while reading bulk data: %s\n", - sane_strstatus (status)); - return status; - } + read /= 512; + read *= 512; + + if(read>0) + { + DBG (DBG_io2, + "gl124_bulk_read_data: trying to read %lu bytes of data\n", + (u_long) read); + status = sanei_usb_read_bulk (dev->dn, data, &read); + if (status != SANE_STATUS_GOOD) + { + DBG (DBG_error, + "gl124_bulk_read_data failed while reading bulk data: %s\n", + sane_strstatus (status)); + return status; + } + } /* read less than 512 bytes remainder */ if (read < size) { - done=read; + done = read; read = size - read; DBG (DBG_io2, - "gl124_bulk_read_data: trying to read %lu bytes of data\n", + "gl124_bulk_read_data: trying to read remaining %lu bytes of data\n", (u_long) read); status = sanei_usb_read_bulk (dev->dn, data+done, &read); if (status != SANE_STATUS_GOOD)