From a3274977cbf579ebee6614d858e903af4457535d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Voltz?= Date: Mon, 27 Jun 2011 06:29:05 +0200 Subject: [PATCH 1/6] add little move at probe time --- backend/genesys_gl847.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/genesys_gl847.c b/backend/genesys_gl847.c index c676b7eb2..b4e574c85 100644 --- a/backend/genesys_gl847.c +++ b/backend/genesys_gl847.c @@ -1,6 +1,6 @@ /* sane - Scanner Access Now Easy. - Copyright (C) 2010 Stéphane Voltz + Copyright (C) 2010-2011 Stéphane Voltz This file is part of the SANE package. @@ -3439,6 +3439,9 @@ gl847_init (Genesys_Device * dev) /* set up hardware and registers */ RIE (gl847_cold_boot (dev)); + /* move head away from park position */ + gl847_feed (dev, 300); + /* now hardware part is OK, set up device struct */ FREE_IFNOT_NULL (dev->white_average_data); FREE_IFNOT_NULL (dev->dark_average_data); From e827077bf349dc3bf7fdf565c11a94bfed1d55ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Voltz?= Date: Tue, 28 Jun 2011 22:13:41 +0200 Subject: [PATCH 2/6] binary logging change - removed old raw data logging - added new binary data logging (gl847 only for now) --- backend/genesys.c | 65 +++++---------------------------------- backend/genesys_devices.c | 10 +++--- backend/genesys_gl847.c | 42 +++++++++++++------------ backend/genesys_low.h | 2 ++ 4 files changed, 36 insertions(+), 83 deletions(-) diff --git a/backend/genesys.c b/backend/genesys.c index 970bf7907..9fdd484a0 100644 --- a/backend/genesys.c +++ b/backend/genesys.c @@ -4548,12 +4548,6 @@ sanei_genesys_buffer_consume (Genesys_Buffer * buf, size_t size) #include "genesys_conv.c" -#define SANE_DEBUG_LOG_RAW_DATA 1 - -#ifdef SANE_DEBUG_LOG_RAW_DATA -static FILE *rawfile = NULL; -#endif - static SANE_Status accurate_line_read(Genesys_Device * dev, SANE_Byte *buffer, size_t size) @@ -4571,12 +4565,6 @@ static SANE_Status accurate_line_read(Genesys_Device * dev, /* done reading */ dev->oe_buffer.avail = size; dev->oe_buffer.pos = 0; -#ifdef SANE_DEBUG_LOG_RAW_DATA - if (rawfile != NULL) - { - fwrite (buffer, size, 1, rawfile); - } -#endif return status; } #if 0 @@ -4639,12 +4627,6 @@ static SANE_Status accurate_line_read(Genesys_Device * dev, /* done reading */ dev->oe_buffer.avail = dev->oe_buffer.size; dev->oe_buffer.pos = 0; -#ifdef SANE_DEBUG_LOG_RAW_DATA - if (rawfile != NULL) - { - fwrite (dev->oe_buffer.buffer, dev->oe_buffer.avail, 1, rawfile); - } -#endif return status; } #endif @@ -5091,14 +5073,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); -#ifdef SANE_DEBUG_LOG_RAW_DATA - if (rawfile != NULL && DBG_LEVEL >= DBG_data) - { - /*TODO: convert big/little endian if depth == 16. - note: xv got this wrong for P5/P6. */ - fwrite (work_buffer_dst, size, 1, rawfile); - } -#endif } if (status != SANE_STATUS_GOOD) { @@ -5221,40 +5195,8 @@ genesys_read_ordered_data (Genesys_Device * dev, SANE_Byte * destination, DBG (DBG_proc, "genesys_read_ordered_data: nothing more to scan: EOF\n"); *len = 0; -#ifdef SANE_DEBUG_LOG_RAW_DATA - if (rawfile != NULL) - { - fclose (rawfile); - rawfile = NULL; - } -#endif return SANE_STATUS_EOF; } -#ifdef SANE_DEBUG_LOG_RAW_DATA - if (rawfile == NULL && DBG_LEVEL >= DBG_data) - { - rawfile = fopen ("raw.pnm", "wb"); - if (rawfile != NULL) - { - if (!(dev->model->flags & GENESYS_FLAG_SIS_SENSOR)) - fprintf (rawfile, - "P%c\n%05d %05d\n%d\n", - dev->current_setup.channels == 1 ? - (dev->current_setup.depth == 1 ? '4' : '5') : '6', - dev->current_setup.pixels, - dev->current_setup.lines, - (1 << dev->current_setup.depth) - 1); - else - { - fprintf (rawfile, - "P5\n%05d %05d\n%d\n", - (dev->sensor.sensor_pixels*3*dev->settings.xres)/dev->sensor.optical_res, - dev->current_setup.lines, - (1 << dev->current_setup.depth) - 1); - } - } - } -#endif DBG (DBG_info, "genesys_read_ordered_data: %lu lines left by output\n", ((dev->total_bytes_to_read - dev->total_bytes_read) * 8UL) / @@ -8028,6 +7970,13 @@ sane_cancel (SANE_Handle handle) DBG (DBG_proc, "sane_cancel: start\n"); + /* end binary logging if needed */ + if (s->dev->binary!=NULL) + { + fclose(s->dev->binary); + s->dev->binary=NULL; + } + s->scanning = SANE_FALSE; s->dev->read_active = SANE_FALSE; if(s->dev->img_buffer!=NULL) diff --git a/backend/genesys_devices.c b/backend/genesys_devices.c index 19300d3bc..552c40bd1 100644 --- a/backend/genesys_devices.c +++ b/backend/genesys_devices.c @@ -3,7 +3,7 @@ Copyright (C) 2003 Oliver Rauch Copyright (C) 2003-2005 Henning Meier-Geinitz Copyright (C) 2004, 2005 Gerhard Jaeger - Copyright (C) 2004-2010 Stéphane Voltz + Copyright (C) 2004-2011 Stéphane Voltz Copyright (C) 2005-2009 Pierre Willenbrock Copyright (C) 2007 Luke Copyright (C) 2010 Jack McGill @@ -439,9 +439,9 @@ static Genesys_Sensor Sensor[] = { /* CANONLIDE200 */ {CIS_CANONLIDE200, 4800, /* optical resolution */ - 87*4, /* black pixels */ - 16*4, /* dummy pixels */ - 323*8, /* CCD_startx_offset */ + 87*4, /* black pixels */ + 16*4, /* dummy pixels */ + 320*8, /* CCD_startx_offset 323 */ 5136*8, 210, 200, @@ -466,7 +466,7 @@ static Genesys_Sensor Sensor[] = { 2400, /* optical resolution */ 87*4, /* black pixels */ 16*4, /* dummy pixels 16 */ - 323*4, /* 303 */ + 320*4, /* 323 */ 5136*4, /* 10272 */ 210, 200, diff --git a/backend/genesys_gl847.c b/backend/genesys_gl847.c index b4e574c85..09efe519e 100644 --- a/backend/genesys_gl847.c +++ b/backend/genesys_gl847.c @@ -121,6 +121,7 @@ gl847_bulk_read_data (Genesys_Device * dev, uint8_t addr, SANE_Status status; size_t size, target, read, done; uint8_t outdata[8]; + uint8_t *buffer; DBG (DBG_io, "gl847_bulk_read_data: requesting %lu bytes at addr=0x%02x\n", (u_long) len, addr); @@ -128,6 +129,7 @@ gl847_bulk_read_data (Genesys_Device * dev, uint8_t addr, return SANE_STATUS_GOOD; target = len; + buffer = data; /* loop until computed data size is read */ while (target) @@ -175,7 +177,7 @@ gl847_bulk_read_data (Genesys_Device * dev, uint8_t addr, DBG (DBG_io2, "gl847_bulk_read_data: trying to read %lu bytes of data\n", (u_long) read); - status = sanei_usb_read_bulk (dev->dn, data, &read); + status = sanei_usb_read_bulk (dev->dn, buffer, &read); if (status != SANE_STATUS_GOOD) { DBG (DBG_error, @@ -193,7 +195,7 @@ gl847_bulk_read_data (Genesys_Device * dev, uint8_t addr, DBG (DBG_io2, "gl847_bulk_read_data: trying to read %lu bytes of data\n", (u_long) read); - status = sanei_usb_read_bulk (dev->dn, data+done, &read); + status = sanei_usb_read_bulk (dev->dn, buffer+done, &read); if (status != SANE_STATUS_GOOD) { DBG (DBG_error, @@ -209,7 +211,12 @@ gl847_bulk_read_data (Genesys_Device * dev, uint8_t addr, (u_long) size, (u_long) (target - size)); target -= size; - data += size; + buffer += size; + } + + if (DBG_LEVEL >= DBG_data && dev->binary!=NULL) + { + fwrite(data, len, 1, dev->binary); } DBGCOMPLETED; @@ -1397,23 +1404,6 @@ gl847_init_scan_regs (Genesys_Device * dev, "Flags : %x\n\n", xres, yres, lines, pixels, startx, starty, depth, channels, flags); -#ifdef SANE_DEBUG_LOG_RAW_DATA - /* for raw data debug, we know here the exact raw image - * attributes */ - if (rawfile == NULL && DBG_LEVEL >= DBG_data) - { - if (rawfile != NULL) - { - rewind(rawfile); - fprintf (rawfile, - "P5\n%05d %05d\n%d\n", - pixels*channel, - lines, - (1 << depth) - 1); - } - } -#endif - /* we may have 2 domains for ccd: xres below or above half ccd max dpi */ if (dev->sensor.optical_res < 2 * xres || !(dev->model->flags & GENESYS_FLAG_HALF_CCD_MODE)) @@ -2744,6 +2734,7 @@ gl847_send_shading_data (Genesys_Device * dev, uint8_t * data, int size) uint32_t addr, length, i, x, factor, pixels; uint32_t dpiset, dpihw, strpixel, endpixel; uint16_t tempo; + uint32_t lines; uint8_t val,*buffer,*ptr,*src; DBGSTART; @@ -2769,6 +2760,17 @@ gl847_send_shading_data (Genesys_Device * dev, uint8_t * data, int size) factor=dpihw/dpiset; DBG( DBG_io2, "%s: factor=%d\n",__FUNCTION__,factor); + if(DBG_LEVEL>=DBG_data) + { + dev->binary=fopen("raw.pnm","wb"); + sanei_genesys_get_triple(dev->reg, REG_LINCNT, &lines); + channels=3; + if(dev->binary!=NULL) + { + fprintf(dev->binary,"P5\n%d %d\n%d\n",(endpixel-strpixel)/factor*channels,lines,255); + } + } + /* since we're using SHDAREA, substract startx coordinate from shading */ strpixel-=((dev->sensor.CCD_start_xoffset*600)/dev->sensor.optical_res); diff --git a/backend/genesys_low.h b/backend/genesys_low.h index bca40f0c0..16734c632 100644 --- a/backend/genesys_low.h +++ b/backend/genesys_low.h @@ -670,6 +670,8 @@ struct Genesys_Device SANE_Bool buffer_image; /**> when true the scanned picture is first buffered * to allow software image enhancements */ SANE_Byte *img_buffer; /**> image buffer where the scanned picture is stored */ + + FILE *binary; /**> binary logger file */ }; typedef struct Genesys_USB_Device_Entry From 69b17b34f210fb7608081e5e53d3bd36eb29b930 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Voltz?= Date: Wed, 29 Jun 2011 06:55:26 +0200 Subject: [PATCH 3/6] binary logging fixes --- backend/genesys_gl847.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/genesys_gl847.c b/backend/genesys_gl847.c index 09efe519e..4378753e1 100644 --- a/backend/genesys_gl847.c +++ b/backend/genesys_gl847.c @@ -2734,7 +2734,7 @@ gl847_send_shading_data (Genesys_Device * dev, uint8_t * data, int size) uint32_t addr, length, i, x, factor, pixels; uint32_t dpiset, dpihw, strpixel, endpixel; uint16_t tempo; - uint32_t lines; + uint32_t lines, channels; uint8_t val,*buffer,*ptr,*src; DBGSTART; @@ -2767,7 +2767,7 @@ gl847_send_shading_data (Genesys_Device * dev, uint8_t * data, int size) channels=3; if(dev->binary!=NULL) { - fprintf(dev->binary,"P5\n%d %d\n%d\n",(endpixel-strpixel)/factor*channels,lines,255); + fprintf(dev->binary,"P5\n%d %d\n%d\n",(endpixel-strpixel)/factor*channels,lines/channels,255); } } From 197d5ce95476206045310a199544131fdee07cb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Voltz?= Date: Tue, 5 Jul 2011 13:53:44 +0200 Subject: [PATCH 4/6] high resolution fixes - use 32 bit number for pixel number so we can handle high resolution - simplify cache reuse - code cleanups --- backend/genesys.c | 229 +++++++++++++--------------------------------- 1 file changed, 65 insertions(+), 164 deletions(-) diff --git a/backend/genesys.c b/backend/genesys.c index 9fdd484a0..87ec5a63f 100644 --- a/backend/genesys.c +++ b/backend/genesys.c @@ -1806,10 +1806,11 @@ static #endif void genesys_average_data (uint8_t * average_data, - uint8_t * calibration_data, uint16_t lines, - uint16_t pixel_components_per_line) + uint8_t * calibration_data, + uint32_t lines, + uint32_t pixel_components_per_line) { - int x, y; + uint32_t x, y; uint32_t sum; for (x = 0; x < pixel_components_per_line; x++) @@ -1839,7 +1840,7 @@ genesys_dark_shading_calibration (Genesys_Device * dev) { SANE_Status status; size_t size; - uint16_t pixels_per_line; + uint32_t pixels_per_line; uint8_t channels; uint8_t *calibration_data; @@ -1960,9 +1961,9 @@ genesys_dark_shading_calibration (Genesys_Device * dev) static SANE_Status genesys_dummy_dark_shading (Genesys_Device * dev) { - uint16_t pixels_per_line; + uint32_t pixels_per_line; uint8_t channels; - int x, skip, xend; + uint32_t x, skip, xend; int dummy1, dummy2, dummy3; /* dummy black average per channel */ DBG (DBG_proc, "genesys_dummy_dark_shading \n"); @@ -2055,7 +2056,7 @@ genesys_white_shading_calibration (Genesys_Device * dev) { SANE_Status status; size_t size; - uint16_t pixels_per_line; + uint32_t pixels_per_line; uint8_t *calibration_data; uint8_t channels; @@ -2178,7 +2179,7 @@ genesys_dark_white_shading_calibration (Genesys_Device * dev) { SANE_Status status; size_t size; - uint16_t pixels_per_line; + uint32_t pixels_per_line; uint8_t *calibration_data, *average_white, *average_dark; uint8_t channels; unsigned int x; @@ -2610,7 +2611,7 @@ compute_coefficients (Genesys_Device * dev, uint8_t * shading_data, unsigned int pixels_per_line, unsigned int channels, - int cmat[3], + unsigned int cmat[3], int offset, unsigned int coeff, unsigned int target) @@ -2688,14 +2689,14 @@ compute_planar_coefficients (Genesys_Device * dev, unsigned int pixels_per_line, unsigned int words_per_color, unsigned int channels, - int cmat[3], + unsigned int cmat[3], unsigned int offset, unsigned int coeff, unsigned int target) { uint8_t *ptr; /* contains 16bit words in little endian */ - unsigned int x, c, i; - unsigned int val, dk, br; + uint32_t x, c, i; + uint32_t val, dk, br; DBG (DBG_io, "compute_planar_coefficients: factor=%d, pixels_per_line=%d, words=0x%X, coeff=0x%04x\n", factor, @@ -2707,8 +2708,11 @@ compute_planar_coefficients (Genesys_Device * dev, { /* x2 because of 16 bit values, and x2 since one coeff for dark * and another for white */ - ptr = - shading_data + words_per_color * cmat[c] * 2 + (x + offset) * 4; + ptr = shading_data + words_per_color * cmat[c] * 2 + (x + offset) * 4; + if(ptr-shading_data==0x385fc) + { + dk = 0; + } dk = 0; br = 0; @@ -2759,7 +2763,7 @@ compute_shifted_coefficients (Genesys_Device * dev, uint8_t * shading_data, unsigned int pixels_per_line, unsigned int channels, - int cmat[3], + unsigned int cmat[3], int offset, unsigned int coeff, unsigned int target_dark, @@ -2849,13 +2853,13 @@ static SANE_Status genesys_send_shading_coefficient (Genesys_Device * dev) { SANE_Status status; - uint16_t pixels_per_line; + uint32_t pixels_per_line; uint8_t *shading_data; /**> contains 16bit words in little endian */ uint8_t channels; int o; unsigned int length; /**> number of shading calibration data words */ unsigned int x, j, i, res, factor; - int cmat[3]; /**> matrix of color channels */ + unsigned int cmat[3]; /**> matrix of color channels */ unsigned int coeff, target_code, val, avgpixels, dk, words_per_color = 0; unsigned int target_dark, target_bright, br; @@ -3038,6 +3042,7 @@ genesys_send_shading_coefficient (Genesys_Device * dev) break; case CIS_CANONLIDE100: case CIS_CANONLIDE200: + case CIS_CANONLIDE110: words_per_color=pixels_per_line*2; length = words_per_color * 3 * 2; free(shading_data); @@ -3048,29 +3053,7 @@ genesys_send_shading_coefficient (Genesys_Device * dev) "genesys_send_shading_coefficient: failed to allocate memory\n"); return SANE_STATUS_NO_MEM; } - compute_planar_coefficients (dev, - shading_data, - 1, - pixels_per_line, - words_per_color, - channels, - cmat, - 0, - coeff, - 0xdc00); - break; - case CIS_CANONLIDE110: - words_per_color=pixels_per_line*2; - length = words_per_color * 3 * 2; - /* XXX STEF XXX re do it better, words per color is wrong since our dpihw vary */ - free(shading_data); - shading_data = malloc (length); - if (!shading_data) - { - DBG (DBG_error, - "genesys_send_shading_coefficient: failed to allocate memory\n"); - return SANE_STATUS_NO_MEM; - } + memset (shading_data, 0, length); compute_planar_coefficients (dev, shading_data, 1, @@ -3374,7 +3357,6 @@ genesys_save_calibration (Genesys_Device * dev) { SANE_Status status = SANE_STATUS_UNSUPPORTED; Genesys_Calibration_Cache *cache = NULL; - uint8_t *tmp; #ifdef HAVE_SYS_TIME_H struct timeval time; #endif @@ -3388,8 +3370,7 @@ genesys_save_calibration (Genesys_Device * dev) { for (cache = dev->calibration_cache; cache; cache = cache->next) { - status = dev->model->cmd_set->is_compatible_calibration (dev, cache, - SANE_TRUE); + status = dev->model->cmd_set->is_compatible_calibration (dev, cache, SANE_TRUE); if (status == SANE_STATUS_UNSUPPORTED) { continue; @@ -3405,27 +3386,15 @@ genesys_save_calibration (Genesys_Device * dev) } } + /* if we found on overridable cache, we reuse it */ if (cache) { - if (dev->average_size > cache->average_size) - { - cache->average_size = dev->average_size; - - tmp = (uint8_t *) realloc (cache->dark_average_data, - cache->average_size); - if (!tmp) - return SANE_STATUS_NO_MEM; - cache->dark_average_data = tmp; - - tmp = (uint8_t *) realloc (cache->white_average_data, - cache->average_size); - if (!tmp) - return SANE_STATUS_NO_MEM; - cache->white_average_data = tmp; - } + free(cache->dark_average_data); + free(cache->white_average_data); } else { + /* create a new cache entry and insert it in the linked list */ cache = malloc (sizeof (Genesys_Calibration_Cache)); if (!cache) return SANE_STATUS_NO_MEM; @@ -3434,29 +3403,25 @@ genesys_save_calibration (Genesys_Device * dev) cache->next = dev->calibration_cache; dev->calibration_cache = cache; - - cache->average_size = dev->average_size; - - cache->dark_average_data = (uint8_t *) malloc (cache->average_size); - if (!cache->dark_average_data) - return SANE_STATUS_NO_MEM; - cache->white_average_data = (uint8_t *) malloc (cache->average_size); - if (!cache->white_average_data) - return SANE_STATUS_NO_MEM; - - memcpy (&cache->used_setup, &dev->current_setup, - sizeof (cache->used_setup)); } + cache->average_size = dev->average_size; + + cache->dark_average_data = (uint8_t *) malloc (cache->average_size); + if (!cache->dark_average_data) + return SANE_STATUS_NO_MEM; + cache->white_average_data = (uint8_t *) malloc (cache->average_size); + if (!cache->white_average_data) + return SANE_STATUS_NO_MEM; + + memcpy (&cache->used_setup, &dev->current_setup, sizeof (cache->used_setup)); memcpy (&cache->frontend, &dev->frontend, sizeof (cache->frontend)); memcpy (&cache->sensor, &dev->sensor, sizeof (cache->sensor)); cache->calib_pixels = dev->calib_pixels; cache->calib_channels = dev->calib_channels; - memcpy (cache->dark_average_data, dev->dark_average_data, - cache->average_size); - memcpy (cache->white_average_data, dev->white_average_data, - cache->average_size); + memcpy (cache->dark_average_data, dev->dark_average_data, cache->average_size); + memcpy (cache->white_average_data, dev->white_average_data, cache->average_size); #ifdef HAVE_SYS_TIME_H gettimeofday(&time,NULL); cache->last_calibration = time.tv_sec; @@ -3478,7 +3443,7 @@ static SANE_Status genesys_flatbed_calibration (Genesys_Device * dev) { SANE_Status status; - uint16_t pixels_per_line; + uint32_t pixels_per_line; int yres; DBG (DBG_info, "genesys_flatbed_calibration\n"); @@ -4567,70 +4532,6 @@ static SANE_Status accurate_line_read(Genesys_Device * dev, dev->oe_buffer.pos = 0; return status; } -#if 0 -static SANE_Status accurate_line_read(Genesys_Device * dev, - SANE_Byte *buffer, - size_t size) -{ - SANE_Status status; - unsigned int words; - size_t done, count; - - done = 0; - while (done < size) - { - /* wait for data */ - words = 0; - count = 0; - while (words == 0) - { - status = sanei_genesys_read_valid_words (dev, &words); - if (status != SANE_STATUS_GOOD) - { - DBG (DBG_error, - "accurate_line_read: failed to read words (%s)\n", - sane_strstatus (status)); - return SANE_STATUS_IO_ERROR; - } - if (words == 0) - { - count++; - /* couldn't read a line in 10s */ - if (count > 1000) - { - DBG (DBG_error, "accurate_line_read: failed while waiting for data \n"); - return SANE_STATUS_IO_ERROR; - } - usleep (10000); - } - } - - /* change to bytes */ - words *= 2; - - /* compute read size */ - if(words>size-done) - words=size-done; - if(words>0xeff0) - words=0xeff0; - status = dev->model->cmd_set->bulk_read_data (dev, 0x45, buffer, words); - if (status != SANE_STATUS_GOOD) - { - DBG (DBG_error, - "accurate_line_read: failed to read %lu bytes (%s)\n", - (u_long) size, sane_strstatus (status)); - return SANE_STATUS_IO_ERROR; - } - done += words; - } - - /* done reading */ - dev->oe_buffer.avail = dev->oe_buffer.size; - dev->oe_buffer.pos = 0; - return status; -} -#endif - /** @brief fill buffer while reducing vertical resolution * This function fills a read buffer with scanned data from a sensor @@ -4891,14 +4792,14 @@ genesys_fill_segmented_buffer (Genesys_Device * dev, uint8_t *work_buffer_dst, s { while (dev->cur < dev->len && count < size) { - work_buffer_dst[count + 0] = dev->oe_buffer.buffer[dev->cur + dev->oe_buffer.pos]; - work_buffer_dst[count + 1] = dev->oe_buffer.buffer[dev->cur + 2*dev->dist + dev->oe_buffer.pos]; - work_buffer_dst[count + 2] = dev->oe_buffer.buffer[dev->cur + 4*dev->dist + dev->oe_buffer.pos]; - work_buffer_dst[count + 3] = dev->oe_buffer.buffer[dev->cur + 6*dev->dist + dev->oe_buffer.pos]; - work_buffer_dst[count + 4] = dev->oe_buffer.buffer[dev->cur + 1*dev->dist + dev->oe_buffer.pos]; - work_buffer_dst[count + 5] = dev->oe_buffer.buffer[dev->cur + 3*dev->dist + dev->oe_buffer.pos]; - work_buffer_dst[count + 6] = dev->oe_buffer.buffer[dev->cur + 5*dev->dist + dev->oe_buffer.pos]; - work_buffer_dst[count + 7] = dev->oe_buffer.buffer[dev->cur + 7*dev->dist + dev->oe_buffer.pos]; + work_buffer_dst[count + 0] = 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 + 2*dev->dist + dev->oe_buffer.pos]; + work_buffer_dst[count + 2] = dev->oe_buffer.buffer[dev->cur + dev->skip + 4*dev->dist + dev->oe_buffer.pos]; + work_buffer_dst[count + 3] = dev->oe_buffer.buffer[dev->cur + dev->skip + 6*dev->dist + dev->oe_buffer.pos]; + work_buffer_dst[count + 4] = dev->oe_buffer.buffer[dev->cur + dev->skip + 1*dev->dist + dev->oe_buffer.pos]; + work_buffer_dst[count + 5] = dev->oe_buffer.buffer[dev->cur + dev->skip + 3*dev->dist + dev->oe_buffer.pos]; + work_buffer_dst[count + 6] = dev->oe_buffer.buffer[dev->cur + dev->skip + 5*dev->dist + dev->oe_buffer.pos]; + work_buffer_dst[count + 7] = dev->oe_buffer.buffer[dev->cur + dev->skip + 7*dev->dist + dev->oe_buffer.pos]; /* update counter and pointer */ count += 8; dev->cur+=1; @@ -4908,22 +4809,22 @@ genesys_fill_segmented_buffer (Genesys_Device * dev, uint8_t *work_buffer_dst, s { while (dev->cur < dev->len && count < size) { - work_buffer_dst[count + 0] = dev->oe_buffer.buffer[dev->cur + dev->oe_buffer.pos]; - work_buffer_dst[count + 1] = dev->oe_buffer.buffer[dev->cur + dev->oe_buffer.pos+1]; - work_buffer_dst[count + 2] = dev->oe_buffer.buffer[dev->cur + 2*dev->dist + dev->oe_buffer.pos]; - work_buffer_dst[count + 3] = dev->oe_buffer.buffer[dev->cur + 2*dev->dist + dev->oe_buffer.pos+1]; - work_buffer_dst[count + 4] = dev->oe_buffer.buffer[dev->cur + 4*dev->dist + dev->oe_buffer.pos]; - work_buffer_dst[count + 5] = dev->oe_buffer.buffer[dev->cur + 4*dev->dist + dev->oe_buffer.pos+1]; - work_buffer_dst[count + 6] = dev->oe_buffer.buffer[dev->cur + 6*dev->dist + dev->oe_buffer.pos]; - work_buffer_dst[count + 7] = dev->oe_buffer.buffer[dev->cur + 6*dev->dist + dev->oe_buffer.pos+1]; - work_buffer_dst[count + 8] = dev->oe_buffer.buffer[dev->cur + 1*dev->dist + dev->oe_buffer.pos]; - work_buffer_dst[count + 9] = dev->oe_buffer.buffer[dev->cur + 1*dev->dist + dev->oe_buffer.pos+1]; - work_buffer_dst[count + 10] = dev->oe_buffer.buffer[dev->cur + 3*dev->dist + dev->oe_buffer.pos]; - work_buffer_dst[count + 11] = dev->oe_buffer.buffer[dev->cur + 3*dev->dist + dev->oe_buffer.pos+1]; - work_buffer_dst[count + 12] = dev->oe_buffer.buffer[dev->cur + 5*dev->dist + dev->oe_buffer.pos]; - work_buffer_dst[count + 13] = dev->oe_buffer.buffer[dev->cur + 5*dev->dist + dev->oe_buffer.pos+1]; - work_buffer_dst[count + 14] = dev->oe_buffer.buffer[dev->cur + 7*dev->dist + dev->oe_buffer.pos]; - work_buffer_dst[count + 15] = dev->oe_buffer.buffer[dev->cur + 7*dev->dist + dev->oe_buffer.pos+1]; + work_buffer_dst[count + 0] = 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]; + work_buffer_dst[count + 2] = dev->oe_buffer.buffer[dev->cur + dev->skip + 2*dev->dist + dev->oe_buffer.pos]; + work_buffer_dst[count + 3] = dev->oe_buffer.buffer[dev->cur + dev->skip + 2*dev->dist + dev->oe_buffer.pos+1]; + work_buffer_dst[count + 4] = dev->oe_buffer.buffer[dev->cur + dev->skip + 4*dev->dist + dev->oe_buffer.pos]; + work_buffer_dst[count + 5] = dev->oe_buffer.buffer[dev->cur + dev->skip + 4*dev->dist + dev->oe_buffer.pos+1]; + work_buffer_dst[count + 6] = dev->oe_buffer.buffer[dev->cur + dev->skip + 6*dev->dist + dev->oe_buffer.pos]; + work_buffer_dst[count + 7] = dev->oe_buffer.buffer[dev->cur + dev->skip + 6*dev->dist + dev->oe_buffer.pos+1]; + work_buffer_dst[count + 8] = dev->oe_buffer.buffer[dev->cur + dev->skip + 1*dev->dist + dev->oe_buffer.pos]; + work_buffer_dst[count + 9] = dev->oe_buffer.buffer[dev->cur + dev->skip + 1*dev->dist + dev->oe_buffer.pos+1]; + work_buffer_dst[count + 10] = dev->oe_buffer.buffer[dev->cur + dev->skip + 3*dev->dist + dev->oe_buffer.pos]; + work_buffer_dst[count + 11] = dev->oe_buffer.buffer[dev->cur + dev->skip + 3*dev->dist + dev->oe_buffer.pos+1]; + work_buffer_dst[count + 12] = dev->oe_buffer.buffer[dev->cur + dev->skip + 5*dev->dist + dev->oe_buffer.pos]; + work_buffer_dst[count + 13] = dev->oe_buffer.buffer[dev->cur + dev->skip + 5*dev->dist + dev->oe_buffer.pos+1]; + work_buffer_dst[count + 14] = dev->oe_buffer.buffer[dev->cur + dev->skip + 7*dev->dist + dev->oe_buffer.pos]; + work_buffer_dst[count + 15] = dev->oe_buffer.buffer[dev->cur + dev->skip + 7*dev->dist + dev->oe_buffer.pos+1]; /* update counter and pointer */ count += 16; From b8ea43fd399f5da49e896bb3d6150bb80b5d7f2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Voltz?= Date: Tue, 5 Jul 2011 13:55:13 +0200 Subject: [PATCH 5/6] added bytes to skip from scan line --- backend/genesys_low.h | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/genesys_low.h b/backend/genesys_low.h index 16734c632..6555d8657 100644 --- a/backend/genesys_low.h +++ b/backend/genesys_low.h @@ -665,6 +665,7 @@ struct Genesys_Device size_t dist; /**> bytes distance between an odd and an even pixel */ size_t len; /**> number of even pixels */ size_t cur; /**> current pixel position within sub window */ + size_t skip; /**> number of bytes to skip at start of line */ Genesys_Buffer oe_buffer; /**> buffer to handle even/odd data */ SANE_Bool buffer_image; /**> when true the scanned picture is first buffered From abcc5104dd94510b09a9d043709a095669bb3ff2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Voltz?= Date: Tue, 5 Jul 2011 14:27:56 +0200 Subject: [PATCH 6/6] 4800 dpi now fully working --- backend/genesys_gl847.c | 60 +++++++++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 17 deletions(-) diff --git a/backend/genesys_gl847.c b/backend/genesys_gl847.c index 4378753e1..d30a487ca 100644 --- a/backend/genesys_gl847.c +++ b/backend/genesys_gl847.c @@ -472,7 +472,6 @@ gl847_init_registers (Genesys_Device * dev) SETREG (0x01, 0x82); SETREG (0x02, 0x18); SETREG (0x03, 0x50); - SETREG (0x03, 0x10); /* XXX STEF XXX */ SETREG (0x04, 0x12); SETREG (0x05, 0x80); SETREG (0x06, 0x50); /* FASTMODE + POWERBIT */ @@ -1154,8 +1153,10 @@ gl847_init_optical_regs_scan (Genesys_Device * dev, /* start and end coordinate in optical dpi coordinates */ startx = start/cksel+dev->sensor.CCD_start_xoffset; used_pixels=pixels/cksel; + + /* end of sensor window */ endx = startx + used_pixels; - + /* sensors are built from 600 dpi segments */ segnb=dpihw/600; @@ -1165,6 +1166,18 @@ gl847_init_optical_regs_scan (Genesys_Device * dev, endx/=factor*segnb; dev->len=endx-startx; dev->dist=0; + dev->skip=0; + + /* in case of 4800 dpi, we must match full sensor width */ + if(dpihw==4800) + { + dev->skip=startx-dev->sensor.CCD_start_xoffset/segnb; + if(depth==16) + dev->skip*=2; + startx = dev->sensor.CCD_start_xoffset/segnb; + used_pixels = sensor->segcnt; + endx = startx + used_pixels; + } /* in cas of multi-segments sensor, we have to add the witdh * of the sensor crossed by the scan area */ @@ -2762,7 +2775,7 @@ gl847_send_shading_data (Genesys_Device * dev, uint8_t * data, int size) if(DBG_LEVEL>=DBG_data) { - dev->binary=fopen("raw.pnm","wb"); + dev->binary=fopen("binary.pnm","wb"); sanei_genesys_get_triple(dev->reg, REG_LINCNT, &lines); channels=3; if(dev->binary!=NULL) @@ -2770,15 +2783,24 @@ gl847_send_shading_data (Genesys_Device * dev, uint8_t * data, int size) fprintf(dev->binary,"P5\n%d %d\n%d\n",(endpixel-strpixel)/factor*channels,lines/channels,255); } } + + pixels=endpixel-strpixel; - /* since we're using SHDAREA, substract startx coordinate from shading */ - strpixel-=((dev->sensor.CCD_start_xoffset*600)/dev->sensor.optical_res); + /* since we're using SHDAREA, substract startx coordinate from shading, + * but not a 4800 dpi where hardware coordinates are fixed */ + if(dpihw!=4800) + { + strpixel-=((dev->sensor.CCD_start_xoffset*600)/dev->sensor.optical_res); + } + else + { + strpixel=0; + } /* turn pixel value into bytes 2x16 bits words */ - strpixel*=2*2; /* 2 words of 2 bytes */ + strpixel*=2*2; endpixel*=2*2; - /* byte size of coefficients */ - pixels=endpixel-strpixel; + pixels*=2*2; /* allocate temporary buffer */ buffer=(uint8_t *)malloc(pixels); @@ -2806,7 +2828,7 @@ gl847_send_shading_data (Genesys_Device * dev, uint8_t * data, int size) ptr[1]=src[1]; ptr[2]=src[2]; ptr[3]=src[3]; - + /* next shading coefficient */ ptr+=4; } @@ -3086,7 +3108,7 @@ gl847_is_compatible_calibration (Genesys_Device * dev, DBGSTART; - if (cache == NULL || for_overwrite) + if (cache == NULL) return SANE_STATUS_UNSUPPORTED; status = gl847_calculate_current_setup (dev); @@ -3120,15 +3142,19 @@ gl847_is_compatible_calibration (Genesys_Device * dev, } /* a cache entry expires after 60 minutes for non sheetfed scanners */ + /* this is not taken into account when overwriting cache entries */ #ifdef HAVE_SYS_TIME_H - gettimeofday (&time, NULL); - if ((time.tv_sec - cache->last_calibration > 60 * 60) - && (dev->model->is_sheetfed == SANE_FALSE) - && (dev->settings.scan_method == SCAN_METHOD_FLATBED)) + if(for_overwrite == SANE_FALSE) { - DBG (DBG_proc, - "gl847_is_compatible_calibration: expired entry, non compatible cache\n"); - return SANE_STATUS_UNSUPPORTED; + gettimeofday (&time, NULL); + if ((time.tv_sec - cache->last_calibration > 60 * 60) + && (dev->model->is_sheetfed == SANE_FALSE) + && (dev->settings.scan_method == SCAN_METHOD_FLATBED)) + { + DBG (DBG_proc, + "gl847_is_compatible_calibration: expired entry, non compatible cache\n"); + return SANE_STATUS_UNSUPPORTED; + } } #endif