Merge branch 'gl847'

merge-requests/1/head
Stphane Voltz 2011-07-05 14:29:12 +02:00
commit 1581bd3865
4 zmienionych plików z 148 dodań i 264 usunięć

Wyświetl plik

@ -1806,10 +1806,11 @@ static
#endif #endif
void void
genesys_average_data (uint8_t * average_data, genesys_average_data (uint8_t * average_data,
uint8_t * calibration_data, uint16_t lines, uint8_t * calibration_data,
uint16_t pixel_components_per_line) uint32_t lines,
uint32_t pixel_components_per_line)
{ {
int x, y; uint32_t x, y;
uint32_t sum; uint32_t sum;
for (x = 0; x < pixel_components_per_line; x++) for (x = 0; x < pixel_components_per_line; x++)
@ -1839,7 +1840,7 @@ genesys_dark_shading_calibration (Genesys_Device * dev)
{ {
SANE_Status status; SANE_Status status;
size_t size; size_t size;
uint16_t pixels_per_line; uint32_t pixels_per_line;
uint8_t channels; uint8_t channels;
uint8_t *calibration_data; uint8_t *calibration_data;
@ -1960,9 +1961,9 @@ genesys_dark_shading_calibration (Genesys_Device * dev)
static SANE_Status static SANE_Status
genesys_dummy_dark_shading (Genesys_Device * dev) genesys_dummy_dark_shading (Genesys_Device * dev)
{ {
uint16_t pixels_per_line; uint32_t pixels_per_line;
uint8_t channels; uint8_t channels;
int x, skip, xend; uint32_t x, skip, xend;
int dummy1, dummy2, dummy3; /* dummy black average per channel */ int dummy1, dummy2, dummy3; /* dummy black average per channel */
DBG (DBG_proc, "genesys_dummy_dark_shading \n"); DBG (DBG_proc, "genesys_dummy_dark_shading \n");
@ -2055,7 +2056,7 @@ genesys_white_shading_calibration (Genesys_Device * dev)
{ {
SANE_Status status; SANE_Status status;
size_t size; size_t size;
uint16_t pixels_per_line; uint32_t pixels_per_line;
uint8_t *calibration_data; uint8_t *calibration_data;
uint8_t channels; uint8_t channels;
@ -2178,7 +2179,7 @@ genesys_dark_white_shading_calibration (Genesys_Device * dev)
{ {
SANE_Status status; SANE_Status status;
size_t size; size_t size;
uint16_t pixels_per_line; uint32_t pixels_per_line;
uint8_t *calibration_data, *average_white, *average_dark; uint8_t *calibration_data, *average_white, *average_dark;
uint8_t channels; uint8_t channels;
unsigned int x; unsigned int x;
@ -2610,7 +2611,7 @@ compute_coefficients (Genesys_Device * dev,
uint8_t * shading_data, uint8_t * shading_data,
unsigned int pixels_per_line, unsigned int pixels_per_line,
unsigned int channels, unsigned int channels,
int cmat[3], unsigned int cmat[3],
int offset, int offset,
unsigned int coeff, unsigned int coeff,
unsigned int target) unsigned int target)
@ -2688,14 +2689,14 @@ compute_planar_coefficients (Genesys_Device * dev,
unsigned int pixels_per_line, unsigned int pixels_per_line,
unsigned int words_per_color, unsigned int words_per_color,
unsigned int channels, unsigned int channels,
int cmat[3], unsigned int cmat[3],
unsigned int offset, unsigned int offset,
unsigned int coeff, unsigned int coeff,
unsigned int target) unsigned int target)
{ {
uint8_t *ptr; /* contains 16bit words in little endian */ uint8_t *ptr; /* contains 16bit words in little endian */
unsigned int x, c, i; uint32_t x, c, i;
unsigned int val, dk, br; uint32_t val, dk, br;
DBG (DBG_io, DBG (DBG_io,
"compute_planar_coefficients: factor=%d, pixels_per_line=%d, words=0x%X, coeff=0x%04x\n", factor, "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 /* x2 because of 16 bit values, and x2 since one coeff for dark
* and another for white */ * and another for white */
ptr = ptr = shading_data + words_per_color * cmat[c] * 2 + (x + offset) * 4;
shading_data + words_per_color * cmat[c] * 2 + (x + offset) * 4; if(ptr-shading_data==0x385fc)
{
dk = 0;
}
dk = 0; dk = 0;
br = 0; br = 0;
@ -2759,7 +2763,7 @@ compute_shifted_coefficients (Genesys_Device * dev,
uint8_t * shading_data, uint8_t * shading_data,
unsigned int pixels_per_line, unsigned int pixels_per_line,
unsigned int channels, unsigned int channels,
int cmat[3], unsigned int cmat[3],
int offset, int offset,
unsigned int coeff, unsigned int coeff,
unsigned int target_dark, unsigned int target_dark,
@ -2849,13 +2853,13 @@ static SANE_Status
genesys_send_shading_coefficient (Genesys_Device * dev) genesys_send_shading_coefficient (Genesys_Device * dev)
{ {
SANE_Status status; 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 *shading_data; /**> contains 16bit words in little endian */
uint8_t channels; uint8_t channels;
int o; int o;
unsigned int length; /**> number of shading calibration data words */ unsigned int length; /**> number of shading calibration data words */
unsigned int x, j, i, res, factor; 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 coeff, target_code, val, avgpixels, dk, words_per_color = 0;
unsigned int target_dark, target_bright, br; unsigned int target_dark, target_bright, br;
@ -3038,31 +3042,9 @@ genesys_send_shading_coefficient (Genesys_Device * dev)
break; break;
case CIS_CANONLIDE100: case CIS_CANONLIDE100:
case CIS_CANONLIDE200: case CIS_CANONLIDE200:
words_per_color=pixels_per_line*2;
length = words_per_color * 3 * 2;
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;
}
compute_planar_coefficients (dev,
shading_data,
1,
pixels_per_line,
words_per_color,
channels,
cmat,
0,
coeff,
0xdc00);
break;
case CIS_CANONLIDE110: case CIS_CANONLIDE110:
words_per_color=pixels_per_line*2; words_per_color=pixels_per_line*2;
length = words_per_color * 3 * 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); free(shading_data);
shading_data = malloc (length); shading_data = malloc (length);
if (!shading_data) if (!shading_data)
@ -3071,6 +3053,7 @@ genesys_send_shading_coefficient (Genesys_Device * dev)
"genesys_send_shading_coefficient: failed to allocate memory\n"); "genesys_send_shading_coefficient: failed to allocate memory\n");
return SANE_STATUS_NO_MEM; return SANE_STATUS_NO_MEM;
} }
memset (shading_data, 0, length);
compute_planar_coefficients (dev, compute_planar_coefficients (dev,
shading_data, shading_data,
1, 1,
@ -3374,7 +3357,6 @@ genesys_save_calibration (Genesys_Device * dev)
{ {
SANE_Status status = SANE_STATUS_UNSUPPORTED; SANE_Status status = SANE_STATUS_UNSUPPORTED;
Genesys_Calibration_Cache *cache = NULL; Genesys_Calibration_Cache *cache = NULL;
uint8_t *tmp;
#ifdef HAVE_SYS_TIME_H #ifdef HAVE_SYS_TIME_H
struct timeval time; struct timeval time;
#endif #endif
@ -3388,8 +3370,7 @@ genesys_save_calibration (Genesys_Device * dev)
{ {
for (cache = dev->calibration_cache; cache; cache = cache->next) for (cache = dev->calibration_cache; cache; cache = cache->next)
{ {
status = dev->model->cmd_set->is_compatible_calibration (dev, cache, status = dev->model->cmd_set->is_compatible_calibration (dev, cache, SANE_TRUE);
SANE_TRUE);
if (status == SANE_STATUS_UNSUPPORTED) if (status == SANE_STATUS_UNSUPPORTED)
{ {
continue; continue;
@ -3405,27 +3386,15 @@ genesys_save_calibration (Genesys_Device * dev)
} }
} }
/* if we found on overridable cache, we reuse it */
if (cache) if (cache)
{ {
if (dev->average_size > cache->average_size) free(cache->dark_average_data);
{ free(cache->white_average_data);
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;
}
} }
else else
{ {
/* create a new cache entry and insert it in the linked list */
cache = malloc (sizeof (Genesys_Calibration_Cache)); cache = malloc (sizeof (Genesys_Calibration_Cache));
if (!cache) if (!cache)
return SANE_STATUS_NO_MEM; return SANE_STATUS_NO_MEM;
@ -3434,6 +3403,7 @@ genesys_save_calibration (Genesys_Device * dev)
cache->next = dev->calibration_cache; cache->next = dev->calibration_cache;
dev->calibration_cache = cache; dev->calibration_cache = cache;
}
cache->average_size = dev->average_size; cache->average_size = dev->average_size;
@ -3444,19 +3414,14 @@ genesys_save_calibration (Genesys_Device * dev)
if (!cache->white_average_data) if (!cache->white_average_data)
return SANE_STATUS_NO_MEM; return SANE_STATUS_NO_MEM;
memcpy (&cache->used_setup, &dev->current_setup, memcpy (&cache->used_setup, &dev->current_setup, sizeof (cache->used_setup));
sizeof (cache->used_setup));
}
memcpy (&cache->frontend, &dev->frontend, sizeof (cache->frontend)); memcpy (&cache->frontend, &dev->frontend, sizeof (cache->frontend));
memcpy (&cache->sensor, &dev->sensor, sizeof (cache->sensor)); memcpy (&cache->sensor, &dev->sensor, sizeof (cache->sensor));
cache->calib_pixels = dev->calib_pixels; cache->calib_pixels = dev->calib_pixels;
cache->calib_channels = dev->calib_channels; cache->calib_channels = dev->calib_channels;
memcpy (cache->dark_average_data, dev->dark_average_data, memcpy (cache->dark_average_data, dev->dark_average_data, cache->average_size);
cache->average_size); memcpy (cache->white_average_data, dev->white_average_data, cache->average_size);
memcpy (cache->white_average_data, dev->white_average_data,
cache->average_size);
#ifdef HAVE_SYS_TIME_H #ifdef HAVE_SYS_TIME_H
gettimeofday(&time,NULL); gettimeofday(&time,NULL);
cache->last_calibration = time.tv_sec; cache->last_calibration = time.tv_sec;
@ -3478,7 +3443,7 @@ static SANE_Status
genesys_flatbed_calibration (Genesys_Device * dev) genesys_flatbed_calibration (Genesys_Device * dev)
{ {
SANE_Status status; SANE_Status status;
uint16_t pixels_per_line; uint32_t pixels_per_line;
int yres; int yres;
DBG (DBG_info, "genesys_flatbed_calibration\n"); DBG (DBG_info, "genesys_flatbed_calibration\n");
@ -4548,12 +4513,6 @@ sanei_genesys_buffer_consume (Genesys_Buffer * buf, size_t size)
#include "genesys_conv.c" #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, static SANE_Status accurate_line_read(Genesys_Device * dev,
SANE_Byte *buffer, SANE_Byte *buffer,
size_t size) size_t size)
@ -4571,84 +4530,8 @@ static SANE_Status accurate_line_read(Genesys_Device * dev,
/* done reading */ /* done reading */
dev->oe_buffer.avail = size; dev->oe_buffer.avail = size;
dev->oe_buffer.pos = 0; dev->oe_buffer.pos = 0;
#ifdef SANE_DEBUG_LOG_RAW_DATA
if (rawfile != NULL)
{
fwrite (buffer, size, 1, rawfile);
}
#endif
return status; 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;
#ifdef SANE_DEBUG_LOG_RAW_DATA
if (rawfile != NULL)
{
fwrite (dev->oe_buffer.buffer, dev->oe_buffer.avail, 1, rawfile);
}
#endif
return status;
}
#endif
/** @brief fill buffer while reducing vertical resolution /** @brief fill buffer while reducing vertical resolution
* This function fills a read buffer with scanned data from a sensor * This function fills a read buffer with scanned data from a sensor
@ -4909,14 +4792,14 @@ genesys_fill_segmented_buffer (Genesys_Device * dev, uint8_t *work_buffer_dst, s
{ {
while (dev->cur < dev->len && count < size) 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 + 0] = dev->oe_buffer.buffer[dev->cur + dev->skip + 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 + 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 + 4*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 + 6*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 + 1*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 + 3*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 + 5*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 + 7*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 */ /* update counter and pointer */
count += 8; count += 8;
dev->cur+=1; dev->cur+=1;
@ -4926,22 +4809,22 @@ genesys_fill_segmented_buffer (Genesys_Device * dev, uint8_t *work_buffer_dst, s
{ {
while (dev->cur < dev->len && count < size) 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 + 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->oe_buffer.pos+1]; 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 + 2*dev->dist + dev->oe_buffer.pos]; 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 + 2*dev->dist + dev->oe_buffer.pos+1]; 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 + 4*dev->dist + dev->oe_buffer.pos]; 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 + 4*dev->dist + dev->oe_buffer.pos+1]; 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 + 6*dev->dist + dev->oe_buffer.pos]; 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 + 6*dev->dist + dev->oe_buffer.pos+1]; 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 + 1*dev->dist + dev->oe_buffer.pos]; 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 + 1*dev->dist + dev->oe_buffer.pos+1]; 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 + 3*dev->dist + dev->oe_buffer.pos]; 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 + 3*dev->dist + dev->oe_buffer.pos+1]; 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 + 5*dev->dist + dev->oe_buffer.pos]; 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 + 5*dev->dist + dev->oe_buffer.pos+1]; 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 + 7*dev->dist + dev->oe_buffer.pos]; 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 + 7*dev->dist + dev->oe_buffer.pos+1]; 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 */ /* update counter and pointer */
count += 16; count += 16;
@ -5091,14 +4974,6 @@ genesys_fill_read_buffer (Genesys_Device * dev)
else /* regular case with no extra copy */ else /* regular case with no extra copy */
{ {
status = dev->model->cmd_set->bulk_read_data (dev, 0x45, work_buffer_dst, size); 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) if (status != SANE_STATUS_GOOD)
{ {
@ -5221,40 +5096,8 @@ genesys_read_ordered_data (Genesys_Device * dev, SANE_Byte * destination,
DBG (DBG_proc, DBG (DBG_proc,
"genesys_read_ordered_data: nothing more to scan: EOF\n"); "genesys_read_ordered_data: nothing more to scan: EOF\n");
*len = 0; *len = 0;
#ifdef SANE_DEBUG_LOG_RAW_DATA
if (rawfile != NULL)
{
fclose (rawfile);
rawfile = NULL;
}
#endif
return SANE_STATUS_EOF; 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", DBG (DBG_info, "genesys_read_ordered_data: %lu lines left by output\n",
((dev->total_bytes_to_read - dev->total_bytes_read) * 8UL) / ((dev->total_bytes_to_read - dev->total_bytes_read) * 8UL) /
@ -8028,6 +7871,13 @@ sane_cancel (SANE_Handle handle)
DBG (DBG_proc, "sane_cancel: start\n"); 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->scanning = SANE_FALSE;
s->dev->read_active = SANE_FALSE; s->dev->read_active = SANE_FALSE;
if(s->dev->img_buffer!=NULL) if(s->dev->img_buffer!=NULL)

Wyświetl plik

@ -3,7 +3,7 @@
Copyright (C) 2003 Oliver Rauch Copyright (C) 2003 Oliver Rauch
Copyright (C) 2003-2005 Henning Meier-Geinitz <henning@meier-geinitz.de> Copyright (C) 2003-2005 Henning Meier-Geinitz <henning@meier-geinitz.de>
Copyright (C) 2004, 2005 Gerhard Jaeger <gerhard@gjaeger.de> Copyright (C) 2004, 2005 Gerhard Jaeger <gerhard@gjaeger.de>
Copyright (C) 2004-2010 Stéphane Voltz <stef.dev@free.fr> Copyright (C) 2004-2011 Stéphane Voltz <stef.dev@free.fr>
Copyright (C) 2005-2009 Pierre Willenbrock <pierre@pirsoft.dnsalias.org> Copyright (C) 2005-2009 Pierre Willenbrock <pierre@pirsoft.dnsalias.org>
Copyright (C) 2007 Luke <iceyfor@gmail.com> Copyright (C) 2007 Luke <iceyfor@gmail.com>
Copyright (C) 2010 Jack McGill <jmcgill85258@yahoo.com> Copyright (C) 2010 Jack McGill <jmcgill85258@yahoo.com>
@ -441,7 +441,7 @@ static Genesys_Sensor Sensor[] = {
4800, /* optical resolution */ 4800, /* optical resolution */
87*4, /* black pixels */ 87*4, /* black pixels */
16*4, /* dummy pixels */ 16*4, /* dummy pixels */
323*8, /* CCD_startx_offset */ 320*8, /* CCD_startx_offset 323 */
5136*8, 5136*8,
210, 210,
200, 200,
@ -466,7 +466,7 @@ static Genesys_Sensor Sensor[] = {
2400, /* optical resolution */ 2400, /* optical resolution */
87*4, /* black pixels */ 87*4, /* black pixels */
16*4, /* dummy pixels 16 */ 16*4, /* dummy pixels 16 */
323*4, /* 303 */ 320*4, /* 323 */
5136*4, /* 10272 */ 5136*4, /* 10272 */
210, 210,
200, 200,

Wyświetl plik

@ -1,6 +1,6 @@
/* sane - Scanner Access Now Easy. /* sane - Scanner Access Now Easy.
Copyright (C) 2010 Stéphane Voltz <stef.dev@free.fr> Copyright (C) 2010-2011 Stéphane Voltz <stef.dev@free.fr>
This file is part of the SANE package. This file is part of the SANE package.
@ -121,6 +121,7 @@ gl847_bulk_read_data (Genesys_Device * dev, uint8_t addr,
SANE_Status status; SANE_Status status;
size_t size, target, read, done; size_t size, target, read, done;
uint8_t outdata[8]; 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); 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; return SANE_STATUS_GOOD;
target = len; target = len;
buffer = data;
/* loop until computed data size is read */ /* loop until computed data size is read */
while (target) while (target)
@ -175,7 +177,7 @@ gl847_bulk_read_data (Genesys_Device * dev, uint8_t addr,
DBG (DBG_io2, DBG (DBG_io2,
"gl847_bulk_read_data: trying to read %lu bytes of data\n", "gl847_bulk_read_data: trying to read %lu bytes of data\n",
(u_long) read); (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) if (status != SANE_STATUS_GOOD)
{ {
DBG (DBG_error, DBG (DBG_error,
@ -193,7 +195,7 @@ gl847_bulk_read_data (Genesys_Device * dev, uint8_t addr,
DBG (DBG_io2, DBG (DBG_io2,
"gl847_bulk_read_data: trying to read %lu bytes of data\n", "gl847_bulk_read_data: trying to read %lu bytes of data\n",
(u_long) read); (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) if (status != SANE_STATUS_GOOD)
{ {
DBG (DBG_error, DBG (DBG_error,
@ -209,7 +211,12 @@ gl847_bulk_read_data (Genesys_Device * dev, uint8_t addr,
(u_long) size, (u_long) (target - size)); (u_long) size, (u_long) (target - size));
target -= size; target -= size;
data += size; buffer += size;
}
if (DBG_LEVEL >= DBG_data && dev->binary!=NULL)
{
fwrite(data, len, 1, dev->binary);
} }
DBGCOMPLETED; DBGCOMPLETED;
@ -465,7 +472,6 @@ gl847_init_registers (Genesys_Device * dev)
SETREG (0x01, 0x82); SETREG (0x01, 0x82);
SETREG (0x02, 0x18); SETREG (0x02, 0x18);
SETREG (0x03, 0x50); SETREG (0x03, 0x50);
SETREG (0x03, 0x10); /* XXX STEF XXX */
SETREG (0x04, 0x12); SETREG (0x04, 0x12);
SETREG (0x05, 0x80); SETREG (0x05, 0x80);
SETREG (0x06, 0x50); /* FASTMODE + POWERBIT */ SETREG (0x06, 0x50); /* FASTMODE + POWERBIT */
@ -1147,6 +1153,8 @@ gl847_init_optical_regs_scan (Genesys_Device * dev,
/* start and end coordinate in optical dpi coordinates */ /* start and end coordinate in optical dpi coordinates */
startx = start/cksel+dev->sensor.CCD_start_xoffset; startx = start/cksel+dev->sensor.CCD_start_xoffset;
used_pixels=pixels/cksel; used_pixels=pixels/cksel;
/* end of sensor window */
endx = startx + used_pixels; endx = startx + used_pixels;
/* sensors are built from 600 dpi segments */ /* sensors are built from 600 dpi segments */
@ -1158,6 +1166,18 @@ gl847_init_optical_regs_scan (Genesys_Device * dev,
endx/=factor*segnb; endx/=factor*segnb;
dev->len=endx-startx; dev->len=endx-startx;
dev->dist=0; 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 /* in cas of multi-segments sensor, we have to add the witdh
* of the sensor crossed by the scan area */ * of the sensor crossed by the scan area */
@ -1397,23 +1417,6 @@ gl847_init_scan_regs (Genesys_Device * dev,
"Flags : %x\n\n", "Flags : %x\n\n",
xres, yres, lines, pixels, startx, starty, depth, channels, flags); 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 */ /* we may have 2 domains for ccd: xres below or above half ccd max dpi */
if (dev->sensor.optical_res < 2 * xres || if (dev->sensor.optical_res < 2 * xres ||
!(dev->model->flags & GENESYS_FLAG_HALF_CCD_MODE)) !(dev->model->flags & GENESYS_FLAG_HALF_CCD_MODE))
@ -2744,6 +2747,7 @@ gl847_send_shading_data (Genesys_Device * dev, uint8_t * data, int size)
uint32_t addr, length, i, x, factor, pixels; uint32_t addr, length, i, x, factor, pixels;
uint32_t dpiset, dpihw, strpixel, endpixel; uint32_t dpiset, dpihw, strpixel, endpixel;
uint16_t tempo; uint16_t tempo;
uint32_t lines, channels;
uint8_t val,*buffer,*ptr,*src; uint8_t val,*buffer,*ptr,*src;
DBGSTART; DBGSTART;
@ -2769,14 +2773,34 @@ gl847_send_shading_data (Genesys_Device * dev, uint8_t * data, int size)
factor=dpihw/dpiset; factor=dpihw/dpiset;
DBG( DBG_io2, "%s: factor=%d\n",__FUNCTION__,factor); DBG( DBG_io2, "%s: factor=%d\n",__FUNCTION__,factor);
/* since we're using SHDAREA, substract startx coordinate from shading */ if(DBG_LEVEL>=DBG_data)
{
dev->binary=fopen("binary.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/channels,255);
}
}
pixels=endpixel-strpixel;
/* 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); strpixel-=((dev->sensor.CCD_start_xoffset*600)/dev->sensor.optical_res);
}
else
{
strpixel=0;
}
/* turn pixel value into bytes 2x16 bits words */ /* turn pixel value into bytes 2x16 bits words */
strpixel*=2*2; /* 2 words of 2 bytes */ strpixel*=2*2;
endpixel*=2*2; endpixel*=2*2;
/* byte size of coefficients */ pixels*=2*2;
pixels=endpixel-strpixel;
/* allocate temporary buffer */ /* allocate temporary buffer */
buffer=(uint8_t *)malloc(pixels); buffer=(uint8_t *)malloc(pixels);
@ -3084,7 +3108,7 @@ gl847_is_compatible_calibration (Genesys_Device * dev,
DBGSTART; DBGSTART;
if (cache == NULL || for_overwrite) if (cache == NULL)
return SANE_STATUS_UNSUPPORTED; return SANE_STATUS_UNSUPPORTED;
status = gl847_calculate_current_setup (dev); status = gl847_calculate_current_setup (dev);
@ -3118,7 +3142,10 @@ gl847_is_compatible_calibration (Genesys_Device * dev,
} }
/* a cache entry expires after 60 minutes for non sheetfed scanners */ /* 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 #ifdef HAVE_SYS_TIME_H
if(for_overwrite == SANE_FALSE)
{
gettimeofday (&time, NULL); gettimeofday (&time, NULL);
if ((time.tv_sec - cache->last_calibration > 60 * 60) if ((time.tv_sec - cache->last_calibration > 60 * 60)
&& (dev->model->is_sheetfed == SANE_FALSE) && (dev->model->is_sheetfed == SANE_FALSE)
@ -3128,6 +3155,7 @@ gl847_is_compatible_calibration (Genesys_Device * dev,
"gl847_is_compatible_calibration: expired entry, non compatible cache\n"); "gl847_is_compatible_calibration: expired entry, non compatible cache\n");
return SANE_STATUS_UNSUPPORTED; return SANE_STATUS_UNSUPPORTED;
} }
}
#endif #endif
DBGCOMPLETED; DBGCOMPLETED;
@ -3439,6 +3467,9 @@ gl847_init (Genesys_Device * dev)
/* set up hardware and registers */ /* set up hardware and registers */
RIE (gl847_cold_boot (dev)); RIE (gl847_cold_boot (dev));
/* move head away from park position */
gl847_feed (dev, 300);
/* now hardware part is OK, set up device struct */ /* now hardware part is OK, set up device struct */
FREE_IFNOT_NULL (dev->white_average_data); FREE_IFNOT_NULL (dev->white_average_data);
FREE_IFNOT_NULL (dev->dark_average_data); FREE_IFNOT_NULL (dev->dark_average_data);

Wyświetl plik

@ -665,11 +665,14 @@ struct Genesys_Device
size_t dist; /**> bytes distance between an odd and an even pixel */ size_t dist; /**> bytes distance between an odd and an even pixel */
size_t len; /**> number of even pixels */ size_t len; /**> number of even pixels */
size_t cur; /**> current pixel position within sub window */ 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 */ Genesys_Buffer oe_buffer; /**> buffer to handle even/odd data */
SANE_Bool buffer_image; /**> when true the scanned picture is first buffered SANE_Bool buffer_image; /**> when true the scanned picture is first buffered
* to allow software image enhancements */ * to allow software image enhancements */
SANE_Byte *img_buffer; /**> image buffer where the scanned picture is stored */ SANE_Byte *img_buffer; /**> image buffer where the scanned picture is stored */
FILE *binary; /**> binary logger file */
}; };
typedef struct Genesys_USB_Device_Entry typedef struct Genesys_USB_Device_Entry