From 061a722257d1c07db568bdfc88069c74f471bf76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Voltz?= Date: Wed, 15 Sep 2010 06:11:10 +0200 Subject: [PATCH 1/7] shading data may be wrote in one round --- backend/genesys_gl843.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/backend/genesys_gl843.c b/backend/genesys_gl843.c index b95724022..1f7ca3e91 100644 --- a/backend/genesys_gl843.c +++ b/backend/genesys_gl843.c @@ -120,12 +120,10 @@ gl843_bulk_write_data (Genesys_Device * dev, uint8_t addr, return status; } + /* TODO check with G4050 that we shouldn't loop at all */ while (len) { - if (len > BULKOUT_MAXSIZE) - size = BULKOUT_MAXSIZE; - else - size = len; + size = len; outdata[0] = BULK_OUT; outdata[1] = BULK_RAM; @@ -148,8 +146,6 @@ gl843_bulk_write_data (Genesys_Device * dev, uint8_t addr, return status; } - /* recreate data buffer to take care of memory layout */ - status = sanei_usb_write_bulk (dev->dn, data, &size); if (status != SANE_STATUS_GOOD) { From 5a387c0619e0509c4ebf4b3fd4ffad2aaffbb202 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Voltz?= Date: Wed, 15 Sep 2010 06:12:44 +0200 Subject: [PATCH 2/7] KV-SS080 scanarea fine tuning --- backend/genesys_devices.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/genesys_devices.c b/backend/genesys_devices.c index 3168c3430..0cbfab711 100644 --- a/backend/genesys_devices.c +++ b/backend/genesys_devices.c @@ -1009,7 +1009,7 @@ static Genesys_Model panasonic_kvss080_model = { {16, 8, 0}, /* possible depths in color mode */ SANE_FIX (7.6), /* Start of scan area in mm (x) */ - SANE_FIX (12.5), /* Start of scan area in mm (y) */ + SANE_FIX (13.8), /* Start of scan area in mm (y) */ SANE_FIX (218.5), /* Size of scan area in mm (x) */ SANE_FIX (297.0), /* Size of scan area in mm (y) */ From f06e2b36015e343f44577003d75a7b516079c4ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Voltz?= Date: Wed, 15 Sep 2010 06:13:50 +0200 Subject: [PATCH 3/7] valgrind memory leaks/overwrite fixes --- backend/genesys.c | 19 +++++++++++-------- sanei/sanei_magic.c | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/backend/genesys.c b/backend/genesys.c index b5fcc7dd8..f01bb6bb6 100644 --- a/backend/genesys.c +++ b/backend/genesys.c @@ -3128,15 +3128,19 @@ compute_gl843_coefficients (Genesys_Device * dev, darkptr = (uint16_t *) dev->dark_average_data; whiteptr = (uint16_t *) dev->white_average_data; - size = pixels * 2 * 3 * 256 / 252 * 2 + 512; - free (buffer); - buffer = (unsigned short *) malloc (size); - if (buffer == NULL) + size = (pixels * 2 * 3 * 256) / 252 * 2 + 512; + DBG (DBG_io, "%s: final shading size=%04x\n", __FUNCTION__, size); + *shading_data = (unsigned short *) malloc (size); + if (*shading_data == NULL) return 0; + memset(*shading_data,0,size); + /* offset */ - buffer = buffer + 12; - count = 12; + buffer = *shading_data; + count = 0; + + /* loop over calibration data to build shading coefficients */ for (i = 0; i < pixels; i++) { /* red */ @@ -3529,9 +3533,8 @@ genesys_send_shading_coefficient (Genesys_Device * dev) target_code); break; case CCD_KVSS080: - words_per_color=pixels_per_line * 2; - length = words_per_color * 3 * 2; target_code = 0xe000; + free(shading_data); length=compute_gl843_coefficients (dev, &shading_data, pixels_per_line, diff --git a/sanei/sanei_magic.c b/sanei/sanei_magic.c index e8daf50e8..3ec174900 100644 --- a/sanei/sanei_magic.c +++ b/sanei/sanei_magic.c @@ -1020,7 +1020,7 @@ getLine (int height, int width, int * buff, /* dont forget to cleanup */ cleanup: - for(i=0;i<10;i++){ + for(i=0;i Date: Wed, 15 Sep 2010 06:11:10 +0200 Subject: [PATCH 4/7] shading data may be wrote in one round --- backend/genesys_gl843.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/backend/genesys_gl843.c b/backend/genesys_gl843.c index b95724022..1f7ca3e91 100644 --- a/backend/genesys_gl843.c +++ b/backend/genesys_gl843.c @@ -120,12 +120,10 @@ gl843_bulk_write_data (Genesys_Device * dev, uint8_t addr, return status; } + /* TODO check with G4050 that we shouldn't loop at all */ while (len) { - if (len > BULKOUT_MAXSIZE) - size = BULKOUT_MAXSIZE; - else - size = len; + size = len; outdata[0] = BULK_OUT; outdata[1] = BULK_RAM; @@ -148,8 +146,6 @@ gl843_bulk_write_data (Genesys_Device * dev, uint8_t addr, return status; } - /* recreate data buffer to take care of memory layout */ - status = sanei_usb_write_bulk (dev->dn, data, &size); if (status != SANE_STATUS_GOOD) { From 9734e8eb5a8bac4f591b61aa018054b91ab55101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Voltz?= Date: Wed, 15 Sep 2010 06:12:44 +0200 Subject: [PATCH 5/7] KV-SS080 scanarea fine tuning --- backend/genesys_devices.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/genesys_devices.c b/backend/genesys_devices.c index 3168c3430..0cbfab711 100644 --- a/backend/genesys_devices.c +++ b/backend/genesys_devices.c @@ -1009,7 +1009,7 @@ static Genesys_Model panasonic_kvss080_model = { {16, 8, 0}, /* possible depths in color mode */ SANE_FIX (7.6), /* Start of scan area in mm (x) */ - SANE_FIX (12.5), /* Start of scan area in mm (y) */ + SANE_FIX (13.8), /* Start of scan area in mm (y) */ SANE_FIX (218.5), /* Size of scan area in mm (x) */ SANE_FIX (297.0), /* Size of scan area in mm (y) */ From efd59b15356b1f161e0fc369c00b14ccfd4ced77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Voltz?= Date: Wed, 15 Sep 2010 06:13:50 +0200 Subject: [PATCH 6/7] valgrind memory leaks/overwrite fixes --- backend/genesys.c | 19 +++++++++++-------- sanei/sanei_magic.c | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/backend/genesys.c b/backend/genesys.c index b5fcc7dd8..f01bb6bb6 100644 --- a/backend/genesys.c +++ b/backend/genesys.c @@ -3128,15 +3128,19 @@ compute_gl843_coefficients (Genesys_Device * dev, darkptr = (uint16_t *) dev->dark_average_data; whiteptr = (uint16_t *) dev->white_average_data; - size = pixels * 2 * 3 * 256 / 252 * 2 + 512; - free (buffer); - buffer = (unsigned short *) malloc (size); - if (buffer == NULL) + size = (pixels * 2 * 3 * 256) / 252 * 2 + 512; + DBG (DBG_io, "%s: final shading size=%04x\n", __FUNCTION__, size); + *shading_data = (unsigned short *) malloc (size); + if (*shading_data == NULL) return 0; + memset(*shading_data,0,size); + /* offset */ - buffer = buffer + 12; - count = 12; + buffer = *shading_data; + count = 0; + + /* loop over calibration data to build shading coefficients */ for (i = 0; i < pixels; i++) { /* red */ @@ -3529,9 +3533,8 @@ genesys_send_shading_coefficient (Genesys_Device * dev) target_code); break; case CCD_KVSS080: - words_per_color=pixels_per_line * 2; - length = words_per_color * 3 * 2; target_code = 0xe000; + free(shading_data); length=compute_gl843_coefficients (dev, &shading_data, pixels_per_line, diff --git a/sanei/sanei_magic.c b/sanei/sanei_magic.c index e8daf50e8..3ec174900 100644 --- a/sanei/sanei_magic.c +++ b/sanei/sanei_magic.c @@ -1020,7 +1020,7 @@ getLine (int height, int width, int * buff, /* dont forget to cleanup */ cleanup: - for(i=0;i<10;i++){ + for(i=0;i Date: Fri, 17 Sep 2010 06:47:21 +0200 Subject: [PATCH 7/7] don't wait head to be parked at end of scan to improve scan speed - issue slow_back_home without wait flag at end of scan - ensure head is parked at scan start and at close - issue slow_back_home before doing digital processing --- backend/genesys.c | 22 ++++++++++++++---- backend/genesys_low.h | 54 ++++++++++++++++++++----------------------- 2 files changed, 43 insertions(+), 33 deletions(-) diff --git a/backend/genesys.c b/backend/genesys.c index f01bb6bb6..2d80bf025 100644 --- a/backend/genesys.c +++ b/backend/genesys.c @@ -4686,7 +4686,7 @@ genesys_start_scan (Genesys_Device * dev) return status; } - status = dev->model->cmd_set->slow_back_home (dev, 1); + status = dev->model->cmd_set->slow_back_home (dev, SANE_TRUE); if (status != SANE_STATUS_GOOD) { DBG (DBG_error, @@ -4701,7 +4701,7 @@ genesys_start_scan (Genesys_Device * dev) /* Go home */ /* TODO: check we can drop this since we cannot have the scanner's head wandering here */ - status = dev->model->cmd_set->slow_back_home (dev, 1); + status = dev->model->cmd_set->slow_back_home (dev, SANE_TRUE); if (status != SANE_STATUS_GOOD) { DBG (DBG_error, @@ -6973,6 +6973,15 @@ genesys_buffer_image(Genesys_Scanner *s) } } + /* since digital processing is going to take place, + * issue head parking command so that the head move while + * computing so we can save time + */ + if (dev->model->is_sheetfed == SANE_FALSE) + { + dev->model->cmd_set->slow_back_home (dev, dev->model->flags & GENESYS_FLAG_MUST_WAIT); + } + /* update counters */ dev->total_bytes_to_read = total; dev->total_bytes_read = 0; @@ -7260,11 +7269,16 @@ sane_close (SANE_Handle handle) return; /* oops, not a handle we know about */ } - /* eject document for shhetfed scanners */ + /* eject document for sheetfed scanners */ if (s->dev->model->is_sheetfed == SANE_TRUE) { s->dev->model->cmd_set->eject_document (s->dev); } + else + { + /* for flatbed scanners, get sure the head is parked before leaving */ + s->dev->model->cmd_set->slow_back_home (s->dev, SANE_TRUE); + } /* here is the place to store calibration cache */ write_calibration (s->dev); @@ -8029,7 +8043,7 @@ sane_cancel (SANE_Handle handle) /* park head if flatbed scanner */ if (s->dev->model->is_sheetfed == SANE_FALSE) { - status = s->dev->model->cmd_set->slow_back_home (s->dev, 1); + status = s->dev->model->cmd_set->slow_back_home (s->dev, s->dev->model->flags & GENESYS_FLAG_MUST_WAIT); if (status != SANE_STATUS_GOOD) { DBG (DBG_error, diff --git a/backend/genesys_low.h b/backend/genesys_low.h index feab4c619..776cb24e3 100644 --- a/backend/genesys_low.h +++ b/backend/genesys_low.h @@ -74,42 +74,38 @@ /* Flags */ -#define GENESYS_FLAG_UNTESTED (1 << 0) /* Print a warning for these scanners */ -#define GENESYS_FLAG_14BIT_GAMMA (1 << 1) /* use 14bit Gamma table instead of 12 */ -#define GENESYS_FLAG_LAZY_INIT (1 << 2) /* skip extensive ASIC test at init */ +#define GENESYS_FLAG_UNTESTED (1 << 0) /**> Print a warning for these scanners */ +#define GENESYS_FLAG_14BIT_GAMMA (1 << 1) /**> use 14bit Gamma table instead of 12 */ +#define GENESYS_FLAG_LAZY_INIT (1 << 2) /**> skip extensive ASIC test at init */ #define GENESYS_FLAG_XPA (1 << 3) -#define GENESYS_FLAG_SKIP_WARMUP (1 << 4) /* skip genesys_warmup() */ -#define GENESYS_FLAG_OFFSET_CALIBRATION (1 << 5) /* do offset calibration */ -#define GENESYS_FLAG_SEARCH_START (1 << 6) /* do start search beofre scanning */ -#define GENESYS_FLAG_REPARK (1 << 7) /* repark head (and check for lock) by +#define GENESYS_FLAG_SKIP_WARMUP (1 << 4) /**> skip genesys_warmup() */ +#define GENESYS_FLAG_OFFSET_CALIBRATION (1 << 5) /**> do offset calibration */ +#define GENESYS_FLAG_SEARCH_START (1 << 6) /**> do start search before scanning */ +#define GENESYS_FLAG_REPARK (1 << 7) /**> repark head (and check for lock) by moving without scanning */ -#define GENESYS_FLAG_DARK_CALIBRATION (1 << 8) /* do dark calibration */ -#define GENESYS_FLAG_STAGGERED_LINE (1 << 9) /* pixel columns are shifted vertically for hi-res modes */ +#define GENESYS_FLAG_DARK_CALIBRATION (1 << 8) /**> do dark calibration */ +#define GENESYS_FLAG_STAGGERED_LINE (1 << 9) /**> pixel columns are shifted vertically for hi-res modes */ -#define GENESYS_FLAG_MUST_WAIT (1 << 10) /* tells wether the scanner - should wait 1 minute after - init before doing anything - */ +#define GENESYS_FLAG_MUST_WAIT (1 << 10) /**> tells wether the scanner must wait for the head when parking */ -#define GENESYS_FLAG_ALT_SLOPE_CREATE (1 << 11) /* use alternative slope - creation function */ +#define GENESYS_FLAG_ALT_SLOPE_CREATE (1 << 11) /**> use alternative slope creation function */ -#define GENESYS_FLAG_DARK_WHITE_CALIBRATION (1 << 12) /* yet another calibration method. does white and dark shading in one run, depending on a black and a white strip*/ -#define GENESYS_FLAG_CUSTOM_GAMMA (1 << 13) /* allow custom gamma tables */ -#define GENESYS_FLAG_NO_CALIBRATION (1 << 14) /* allow scanners to use skip the calibration, needed for sheetfed scanners */ -#define GENESYS_FLAG_HALF_CCD_MODE (1 << 15) /* scanner has setting for half ccd mode */ -#define GENESYS_FLAG_ODD_EVEN_CIS (1 << 16) /* scan odd and even pixels come in separated lines */ +#define GENESYS_FLAG_DARK_WHITE_CALIBRATION (1 << 12) /**> yet another calibration method. does white and dark shading in one run, depending on a black and a white strip*/ +#define GENESYS_FLAG_CUSTOM_GAMMA (1 << 13) /**> allow custom gamma tables */ +#define GENESYS_FLAG_NO_CALIBRATION (1 << 14) /**> allow scanners to use skip the calibration, needed for sheetfed scanners */ +#define GENESYS_FLAG_HALF_CCD_MODE (1 << 15) /**> scanner has setting for half ccd mode */ +#define GENESYS_FLAG_ODD_EVEN_CIS (1 << 16) /**> scan odd and even pixels come in separated lines */ -#define GENESYS_HAS_NO_BUTTONS 0 /* scanner has no supported button */ -#define GENESYS_HAS_SCAN_SW (1 << 0) /* scanner has SCAN button */ -#define GENESYS_HAS_FILE_SW (1 << 1) /* scanner has FILE button */ -#define GENESYS_HAS_COPY_SW (1 << 2) /* scanner has COPY button */ -#define GENESYS_HAS_EMAIL_SW (1 << 3) /* scanner has EMAIL button */ -#define GENESYS_HAS_PAGE_LOADED_SW (1 << 4) /* scanner has paper in detection */ -#define GENESYS_HAS_OCR_SW (1 << 5) /* scanner has OCR button */ -#define GENESYS_HAS_POWER_SW (1 << 6) /* scanner has power button */ -#define GENESYS_HAS_CALIBRATE (1 << 7) /* scanner has 'calibrate' software button to start calibration */ +#define GENESYS_HAS_NO_BUTTONS 0 /**> scanner has no supported button */ +#define GENESYS_HAS_SCAN_SW (1 << 0) /**> scanner has SCAN button */ +#define GENESYS_HAS_FILE_SW (1 << 1) /**> scanner has FILE button */ +#define GENESYS_HAS_COPY_SW (1 << 2) /**> scanner has COPY button */ +#define GENESYS_HAS_EMAIL_SW (1 << 3) /**> scanner has EMAIL button */ +#define GENESYS_HAS_PAGE_LOADED_SW (1 << 4) /**> scanner has paper in detection */ +#define GENESYS_HAS_OCR_SW (1 << 5) /**> scanner has OCR button */ +#define GENESYS_HAS_POWER_SW (1 << 6) /**> scanner has power button */ +#define GENESYS_HAS_CALIBRATE (1 << 7) /**> scanner has 'calibrate' software button to start calibration */ /* USB control message values */ #define REQUEST_TYPE_IN (USB_TYPE_VENDOR | USB_DIR_IN)