even/odd pixels handling frist step

merge-requests/1/head
Stphane Voltz 2010-05-22 10:22:48 +02:00
rodzic 93163da8ce
commit 304d84d5e1
4 zmienionych plików z 142 dodań i 56 usunięć

Wyświetl plik

@ -4891,7 +4891,7 @@ static FILE *rawfile = NULL;
static SANE_Status
genesys_fill_read_buffer (Genesys_Device * dev)
{
size_t size;
size_t size, count;
size_t space;
SANE_Status status;
uint8_t *work_buffer_dst;
@ -4914,47 +4914,128 @@ genesys_fill_read_buffer (Genesys_Device * dev)
size = space;
/* never read an odd number. exception: last read
the chip internal counter does not count half words. */
/* never read an odd number. exception: last read
the chip internal counter does not count half words. */
size &= ~1;
/* Some setups need the reads to be multiples of 256 bytes */
/* Some setups need the reads to be multiples of 256 bytes */
size &= ~0xff;
if (dev->read_bytes_left < size)
{
size = dev->read_bytes_left;
/*round up to a multiple of 256 bytes*/
/*round up to a multiple of 256 bytes */
size += (size & 0xff) ? 0x100 : 0x00;
size &= ~0xff;
}
/*early out if our remaining buffer capacity is too low*/
/* early out if our remaining buffer capacity is too lo w */
if (size == 0)
return SANE_STATUS_GOOD;
DBG (DBG_error, "genesys_fill_read_buffer: reading %lu bytes\n",
DBG (DBG_io, "genesys_fill_read_buffer: reading %lu bytes\n",
(u_long) size);
/* size is already maxed to our needs. for most models bulk_read_data
will read as much data as requested. */
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;
}
/* we have main 2 cases, one for normal scan, and the one where must read
* complete lines to reorder raw data from sensor (ie gl847 odd even lines
* and duplex scanners with back to back sensors) */
#ifdef SANE_DEBUG_LOG_RAW_DATA
if (rawfile != NULL)
/* size is already maxed to our needs. for most models bulk_read_data
will read as much data as requested. */
if (!(dev->model->flags & GENESYS_FLAG_ODD_EVEN_CIS))
{
/*TODO: convert big/little endian if depth == 16.
note: xv got this wrong for P5/P6.*/
fwrite (work_buffer_dst, size, 1, rawfile);
}
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)
{
/*TODO: convert big/little endian if depth == 16.
note: xv got this wrong for P5/P6. */
fwrite (work_buffer_dst, size, 1, rawfile);
}
#endif
}
else /* we scan full lines and crop data while reordering odd/even pixels */
{
/* fill buffer if needed */
if (dev->oe_buffer.avail == 0)
{
status =
dev->model->cmd_set->bulk_read_data (dev, 0x45,
dev->oe_buffer.buffer,
dev->oe_buffer.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;
}
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.size, 1, rawfile);
}
#endif
}
/* copy size bytes of data, copying from a subwindow of each line
* when last line of buffer is exhausted, read another one */
count = 0;
while (count < size)
{
while (dev->cur < dev->len && count < size)
{
/* even pixel */
work_buffer_dst[count] =
dev->oe_buffer.buffer[dev->cur + dev->skip + dev->oe_buffer.pos];
/* odd pixel */
work_buffer_dst[count + 1] =
dev->oe_buffer.buffer[dev->cur + dev->skip + dev->dist +
dev->oe_buffer.pos];
count += 2;
dev->cur++;
}
/* go to next line if needed */
if (dev->cur == dev->len)
{
dev->oe_buffer.pos += dev->bpl;
dev->cur = 0;
}
/* read a new buffer if needed */
if (dev->oe_buffer.pos >= dev->oe_buffer.avail)
{
status =
dev->model->cmd_set->bulk_read_data (dev, 0x45,
dev->oe_buffer.buffer,
dev->oe_buffer.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;
}
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.size, 1, rawfile);
}
#endif
}
}
}
if (size > dev->read_bytes_left)
size = dev->read_bytes_left;

Wyświetl plik

@ -432,7 +432,7 @@ static Genesys_Sensor Sensor[] = {
87, /* black pixels */
16, /* dummy pixels */
0,
10272, /* 10272 + 320 start ->10848=4*2712 max */
10272,
210,
200,
{0x00, 0x00, 0x00, 0x00},
@ -930,14 +930,14 @@ static Genesys_Model canon_lide_100_model = {
GENESYS_GL847,
NULL,
{1200, 600, 300, 150, 100, 75, 50, 0}, /* possible x-resolutions */
{1200, 600, 300, 150, 100, 75, 50, 0}, /* possible y-resolutions */
{1200, 600, 300, 150, 75, 0}, /* possible x-resolutions */
{1200, 600, 300, 150, 75, 0}, /* possible y-resolutions */
{16, 8, 0}, /* possible depths in gray mode */
{16, 8, 0}, /* possible depths in color mode */
SANE_FIX (6.42), /* Start of scan area in mm (x) */
SANE_FIX (0.0), /* Start of scan area in mm (y) */
SANE_FIX (217.44), /* Size of scan area in mm (x) */
SANE_FIX (6.95), /* Start of scan area in mm (x) */
SANE_FIX (30.0), /* Start of scan area in mm (y) */
SANE_FIX (216.07), /* Size of scan area in mm (x) */
SANE_FIX (299.0), /* Size of scan area in mm (y) */
SANE_FIX (3.0), /* Start of white strip in mm (y) */
@ -964,9 +964,10 @@ static Genesys_Model canon_lide_100_model = {
CIS_CANONLIDE100,
DAC_CANONLIDE200,
GPO_CANONLIDE200,
MOTOR_CANONLIDE100,
GENESYS_FLAG_LAZY_INIT /* Which flags are needed for this scanner? */
| GENESYS_FLAG_SKIP_WARMUP
MOTOR_CANONLIDE100,
/* Which flags are needed for this scanner? */
GENESYS_FLAG_SKIP_WARMUP
| GENESYS_FLAG_ODD_EVEN_CIS
| GENESYS_FLAG_OFFSET_CALIBRATION
| GENESYS_FLAG_DARK_CALIBRATION
| GENESYS_FLAG_CUSTOM_GAMMA,
@ -1017,13 +1018,11 @@ static Genesys_Model canon_lide_200_model = {
DAC_CANONLIDE200,
GPO_CANONLIDE200,
MOTOR_CANONLIDE200,
GENESYS_FLAG_LAZY_INIT /* Which flags are needed for this scanner? */
| GENESYS_FLAG_NO_CALIBRATION
GENESYS_FLAG_ODD_EVEN_CIS /* Which flags are needed for this scanner? */
| GENESYS_FLAG_SKIP_WARMUP
| GENESYS_FLAG_OFFSET_CALIBRATION
| GENESYS_FLAG_DARK_WHITE_CALIBRATION
| GENESYS_FLAG_CUSTOM_GAMMA
| GENESYS_FLAG_HALF_CCD_MODE,
| GENESYS_FLAG_DARK_CALIBRATION
| GENESYS_FLAG_CUSTOM_GAMMA,
GENESYS_HAS_SCAN_SW | GENESYS_HAS_COPY_SW | GENESYS_HAS_EMAIL_SW | GENESYS_HAS_FILE_SW,
150,
400

Wyświetl plik

@ -1416,7 +1416,7 @@ gl847_init_optical_regs_scan (Genesys_Device * dev,
SANE_Bool half_ccd, int color_filter, int flags)
{
unsigned int words_per_line;
unsigned int end;
unsigned int end, used_pixels;
unsigned int dpiset;
unsigned int i;
Genesys_Register_Set *r;
@ -1428,7 +1428,8 @@ gl847_init_optical_regs_scan (Genesys_Device * dev,
exposure_time,
used_res, start, pixels, channels, depth, half_ccd, flags);
end = start + pixels;
used_pixels = dev->sensor.sensor_pixels;
end = start + used_pixels;
status = gl847_set_fe (dev, AFE_SET);
if (status != SANE_STATUS_GOOD)
@ -1441,18 +1442,7 @@ gl847_init_optical_regs_scan (Genesys_Device * dev,
/* adjust used_res for chosen dpihw */
used_res = used_res * gl847_get_dpihw (dev) / dev->sensor.optical_res;
/*
with half_ccd the optical resolution of the ccd is halved. We don't apply this
to dpihw, so we need to double dpiset.
For the scanner only the ratio of dpiset and dpihw is of relevance to scale
down properly.
*/
if (half_ccd)
dpiset = used_res * 2;
else
dpiset = used_res;
dpiset = used_res;
/* enable shading */
r = sanei_genesys_get_address (reg, REG01);
@ -1566,7 +1556,16 @@ gl847_init_optical_regs_scan (Genesys_Device * dev,
r->value = LOBYTE (end);
/* words(16bit) before gamma, conversion to 8 bit or lineart*/
words_per_line = (pixels * dpiset) / gl847_get_dpihw (dev);
words_per_line = (used_pixels * dpiset) / gl847_get_dpihw (dev);
dev->bpl = words_per_line;
dev->cur=0;
dev->len=pixels/2;
dev->dist=0;
dev->skip=0;
RIE (sanei_genesys_buffer_free (&(dev->oe_buffer)));
RIE (sanei_genesys_buffer_alloc (&(dev->oe_buffer), ((used_pixels*channels*10)/dev->bpl)*dev->bpl));
words_per_line *= channels;
@ -4092,6 +4091,7 @@ gl847_init_memory_layout (Genesys_Device * dev)
return status;
}
#if 0
/** @brief dummy scan to reset scanner
*
* */
@ -4156,6 +4156,7 @@ gl847_dummy_scan (Genesys_Device * dev)
DBGCOMPLETED;
return SANE_STATUS_GOOD;
}
#endif
#if 0
/**
@ -4491,9 +4492,6 @@ gl847_init (Genesys_Device * dev)
}
dev->already_initialized = SANE_TRUE;
/* dummy scan , don't care if it fails */
gl847_dummy_scan (dev);
/* Move home */
RIE (gl847_slow_back_home (dev, SANE_TRUE));
dev->scanhead_position_in_steps = 0;

Wyświetl plik

@ -99,6 +99,7 @@
#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 */
@ -629,6 +630,13 @@ struct Genesys_Device
Genesys_Calibration_Cache *calibration_cache;
struct Genesys_Device *next;
size_t bpl; /**> bytes per full scan widthline */
size_t skip; /**> bytes to skip from start of line to get first required pixel */
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 */
Genesys_Buffer oe_buffer; /**> buffer to handle even/odd data */
};
typedef struct Genesys_USB_Device_Entry