working SHDAREA

- offset in data reading remians to be fixed
- data is read line by line
merge-requests/1/head
Stphane Voltz 2010-05-25 22:01:55 +02:00
rodzic 7cd2ed8ac9
commit d6c2184999
3 zmienionych plików z 205 dodań i 78 usunięć

Wyświetl plik

@ -2414,6 +2414,7 @@ genesys_dark_shading_calibration (Genesys_Device * dev)
uint16_t pixels_per_line;
uint8_t channels;
uint8_t *calibration_data;
int i;
DBG (DBG_proc, "genesys_dark_shading_calibration\n");
/* end pixel - start pixel */
@ -2458,8 +2459,8 @@ genesys_dark_shading_calibration (Genesys_Device * dev)
status =
dev->model->cmd_set->bulk_write_register (dev, dev->calib_reg,
dev->model->
cmd_set->bulk_full_size ());
dev->model->cmd_set->
bulk_full_size ());
if (status != SANE_STATUS_GOOD)
{
free (calibration_data);
@ -2481,14 +2482,38 @@ genesys_dark_shading_calibration (Genesys_Device * dev)
return status;
}
status = sanei_genesys_read_data_from_scanner (dev, calibration_data, size);
if (status != SANE_STATUS_GOOD)
if (!(dev->model->flags & GENESYS_FLAG_ODD_EVEN_CIS))
{
free (calibration_data);
DBG (DBG_error,
"genesys_dark_shading_calibration: Failed to read data: %s\n",
sane_strstatus (status));
return status;
status =
sanei_genesys_read_data_from_scanner (dev, calibration_data, size);
if (status != SANE_STATUS_GOOD)
{
free (calibration_data);
DBG (DBG_error,
"genesys_dark_shading_calibration: Failed to read data: %s\n",
sane_strstatus (status));
return status;
}
}
else
{
/* we need to read full line by full line */
size = channels * 2 * pixels_per_line;
for (i = 0; i < dev->model->shading_lines; i++)
{
status =
sanei_genesys_read_data_from_scanner (dev,
calibration_data + i * size,
size);
if (status != SANE_STATUS_GOOD)
{
free (calibration_data);
DBG (DBG_error,
"genesys_white_shading_calibration: failed to read data: %s\n",
sane_strstatus (status));
return status;
}
}
}
status = dev->model->cmd_set->end_scan (dev, dev->calib_reg, SANE_TRUE);
@ -2631,6 +2656,7 @@ genesys_white_shading_calibration (Genesys_Device * dev)
uint16_t pixels_per_line;
uint8_t *calibration_data;
uint8_t channels;
int i;
DBG (DBG_proc, "genesys_white_shading_calibration (lines = %d)\n",
dev->model->shading_lines);
@ -2665,8 +2691,8 @@ genesys_white_shading_calibration (Genesys_Device * dev)
status =
dev->model->cmd_set->bulk_write_register (dev, dev->calib_reg,
dev->model->
cmd_set->bulk_full_size ());
dev->model->cmd_set->
bulk_full_size ());
if (status != SANE_STATUS_GOOD)
{
free (calibration_data);
@ -2689,14 +2715,38 @@ genesys_white_shading_calibration (Genesys_Device * dev)
return status;
}
status = sanei_genesys_read_data_from_scanner (dev, calibration_data, size);
if (status != SANE_STATUS_GOOD)
if (!(dev->model->flags & GENESYS_FLAG_ODD_EVEN_CIS))
{
free (calibration_data);
DBG (DBG_error,
"genesys_white_shading_calibration: Failed to read data: %s\n",
sane_strstatus (status));
return status;
status =
sanei_genesys_read_data_from_scanner (dev, calibration_data, size);
if (status != SANE_STATUS_GOOD)
{
free (calibration_data);
DBG (DBG_error,
"genesys_white_shading_calibration: failed to read data: %s\n",
sane_strstatus (status));
return status;
}
}
else
{
/* we need to read full line by full line */
size = channels * 2 * pixels_per_line;
for (i = 0; i < dev->model->shading_lines; i++)
{
status =
sanei_genesys_read_data_from_scanner (dev,
calibration_data + i * size,
size);
if (status != SANE_STATUS_GOOD)
{
free (calibration_data);
DBG (DBG_error,
"genesys_white_shading_calibration: failed to read data: %s\n",
sane_strstatus (status));
return status;
}
}
}
status = dev->model->cmd_set->end_scan (dev, dev->calib_reg, SANE_TRUE);
@ -2704,7 +2754,7 @@ genesys_white_shading_calibration (Genesys_Device * dev)
{
free (calibration_data);
DBG (DBG_error,
"genesys_white_shading_calibration: Failed to end scan: %s\n",
"genesys_white_shading_calibration: failed to end scan: %s\n",
sane_strstatus (status));
return status;
}
@ -3005,8 +3055,9 @@ compute_averaged_planar (Genesys_Device * dev,
{
unsigned int x, i, j, br, dk, res, avgpixels, val;
DBG (DBG_info, "%s: pixels=%d\n", __FUNCTION__, pixels_per_line);
/* initialize result */
/* memset (shading_data, 0xff, words_per_color * 3 * 2); */
memset (shading_data, 0xff, words_per_color * 3 * 2);
/* duplicate half-ccd logic */
res = dev->settings.xres;
@ -3036,8 +3087,7 @@ compute_averaged_planar (Genesys_Device * dev,
else
avgpixels = 15;
DBG (DBG_info, "compute_planar_averaged: averaging over %d pixels\n",
avgpixels);
DBG (DBG_info, "%s: averaging over %d pixels\n", __FUNCTION__, avgpixels);
for (x = 0; x <= pixels_per_line - avgpixels; x += avgpixels)
{
@ -3466,12 +3516,15 @@ genesys_send_shading_coefficient (Genesys_Device * dev)
break;
case CIS_CANONLIDE100:
case CIS_CANONLIDE200:
/* we are using SHDAREA */
words_per_color=pixels_per_line*2;
length = words_per_color * 3 * 2;
compute_averaged_planar(dev,
shading_data,
pixels_per_line,
words_per_color,
channels,
4,
3,
0,
coeff,
0xfa00,
0x0a00);
@ -4887,6 +4940,102 @@ sanei_genesys_buffer_consume (Genesys_Buffer * buf, size_t size)
static FILE *rawfile = NULL;
#endif
static SANE_Status accurate_line_read(Genesys_Device * dev,
SANE_Byte *buffer,
size_t size)
{
SANE_Status status;
status = dev->model->cmd_set->bulk_read_data (dev, 0x45, buffer, size);
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 reading */
dev->oe_buffer.avail = 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;
}
#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
static SANE_Status
genesys_fill_read_buffer (Genesys_Device * dev)
{
@ -4966,25 +5115,14 @@ genesys_fill_read_buffer (Genesys_Device * dev)
/* 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);
status = accurate_line_read(dev,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));
(u_long) dev->oe_buffer.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.avail, 1, rawfile);
}
#endif
}
/* copy size bytes of data, copying from a subwindow of each line
@ -5013,25 +5151,14 @@ genesys_fill_read_buffer (Genesys_Device * dev)
/* 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.avail, 1, rawfile);
}
#endif
status = accurate_line_read(dev,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) dev->oe_buffer.size, sane_strstatus (status));
return SANE_STATUS_IO_ERROR;
}
}
}
}

Wyświetl plik

@ -788,7 +788,7 @@ static Genesys_Motor Motor[] = {
{ /* power mode 0 */
{ 2343, 1017, 128, 0.80}, /* full step */
{ 4678, 2034, 64, 0.80}, /* half step */
{ 4*2034, 4*2034, 32, 0.80}, /* quarter step 0.75*2712 */
{ 3*2652, 3*2652, 16, 0.80}, /* quarter step 0.75*2712 */
/*{ 4*2034, 4*2034, 32, 0.80}, quarter step */
/* extra values kept for documentation
{ 2343, 864, 32, 0.80}, full step
@ -973,7 +973,7 @@ static Genesys_Model canon_lide_100_model = {
| GENESYS_FLAG_DARK_CALIBRATION
| GENESYS_FLAG_CUSTOM_GAMMA,
GENESYS_HAS_SCAN_SW | GENESYS_HAS_COPY_SW | GENESYS_HAS_EMAIL_SW | GENESYS_HAS_FILE_SW,
50,
150,
400
};

Wyświetl plik

@ -464,6 +464,7 @@ gl847_init_registers (Genesys_Device * dev)
SETREG (0x17, 0x08);
SETREG (0x18, 0x00);
SETREG (0x19, 0x50);
SETREG (0x19, 0x01); /* XXX STEF XXX */
SETREG (0x1a, 0x34);
SETREG (0x1b, 0x00);
SETREG (0x1c, 0x02);
@ -1173,9 +1174,12 @@ gl847_init_motor_regs_scan (Genesys_Device * dev, Genesys_Register_Set * reg, un
else
feedl = (feed_steps << scan_step_type) - slow_slope_steps;
/* XXX STEF XXX no 2 tables */
feedl=0;
use_fast_fed=0;
/* all needed slopes available. we did even decide which mode to use.
what next? */
r = sanei_genesys_get_address (reg, 0x3d);
r->value = (feedl >> 16) & 0xf;
r = sanei_genesys_get_address (reg, 0x3e);
@ -1428,7 +1432,7 @@ gl847_init_optical_regs_scan (Genesys_Device * dev,
exposure_time,
used_res, start, pixels, channels, depth, half_ccd, flags);
startx = dev->sensor.dummy_pixel + 1 + dev->sensor.CCD_start_xoffset - 32;
startx = dev->sensor.dummy_pixel + 1 + dev->sensor.CCD_start_xoffset;
if(pixels<dev->sensor.sensor_pixels)
{
used_pixels = dev->sensor.sensor_pixels;
@ -1454,7 +1458,8 @@ gl847_init_optical_regs_scan (Genesys_Device * dev,
/* enable shading */
r = sanei_genesys_get_address (reg, REG01);
r->value &= ~(REG01_SCAN | REG01_SHDAREA);
r->value &= ~REG01_SCAN;
r->value |= REG01_SHDAREA;
if ((flags & OPTICAL_FLAG_DISABLE_SHADING) ||
(dev->model->flags & GENESYS_FLAG_NO_CALIBRATION))
{
@ -1464,7 +1469,6 @@ gl847_init_optical_regs_scan (Genesys_Device * dev,
{
r->value |= REG01_DVDSET;
}
r->value &= ~REG01_DVDSET; /* XXX STEF XXX */
/* average looks better than deletion, and we are already set up to
use one of the average enabled resolutions */
@ -1486,8 +1490,7 @@ gl847_init_optical_regs_scan (Genesys_Device * dev,
}
r = sanei_genesys_get_address (reg, 0x19);
r->value = 0xff;
r->value = 0x50; /* XXX STEF XXX */
r->value = 0x50;
/* BW threshold */
r = sanei_genesys_get_address (reg, 0x2e);
@ -1574,8 +1577,7 @@ gl847_init_optical_regs_scan (Genesys_Device * dev,
dev->bpl = words_per_line;
dev->cur=0;
dev->len=pixels/2;
dev->dist=used_pixels/2;
dev->dist=10272/2; /* XXX STEF XXX */
dev->dist=dev->bpl/2;
dev->skip=0;
RIE (sanei_genesys_buffer_free (&(dev->oe_buffer)));
@ -1608,14 +1610,6 @@ gl847_init_optical_regs_scan (Genesys_Device * dev,
r = sanei_genesys_get_address (reg, 0x34);
r->value = dev->sensor.dummy_pixel;
/* XXX STEF XXX
r = sanei_genesys_get_address (reg, 0x1d);
i = 2*r->value;
r = sanei_genesys_get_address (reg, 0x17);
i += r->value;
r = sanei_genesys_get_address (reg, 0x34);
r->value = i; */
DBG (DBG_proc, "gl847_init_optical_regs_scan : completed. \n");
return SANE_STATUS_GOOD;
}
@ -2317,6 +2311,7 @@ gl847_set_lamp_power (Genesys_Device * dev,
}
r = sanei_genesys_get_address (regs, 0x19);
r->value = 0x50;
r->value = 0xff;
r->value = 0x50; /* XXX STEF XXX */
}
else
@ -2333,7 +2328,6 @@ gl847_set_lamp_power (Genesys_Device * dev,
}
r = sanei_genesys_get_address (regs, 0x19);
r->value = 0xff;
r->value = 0x50; /* XXX STEF XXX */
}
}
@ -3335,7 +3329,7 @@ gl847_init_regs_for_shading (Genesys_Device * dev)
sane_strstatus (status));
return status;
}
dev->scanhead_position_in_steps += dev->model->shading_lines;
status =
@ -3574,6 +3568,9 @@ gl847_send_shading_data (Genesys_Device * dev, uint8_t * data, int size)
uint32_t addr, length;
uint8_t val;
DBGSTART;
DBG( DBG_io2, "%s: writing %d bytes of shading data\n",__FUNCTION__,size);
/* shading data is plit in 3 (up to 5 with IR) areas
write(0x10014000,0x00000dd8)
URB 23429 bulk_out len 3544 wrote 0x33 0x10 0x....
@ -3581,6 +3578,7 @@ gl847_send_shading_data (Genesys_Device * dev, uint8_t * data, int size)
write(0x10068000,0x00000dd8)
*/
length = (uint32_t) (size / 3);
DBG( DBG_io2, "%s: using chunks of %d (0x%04x) bytes\n",__FUNCTION__,length,length);
/* base addr of data has been written in reg D0-D4 in 4K word, so AHB address
* is 8192*reg value */
@ -3618,6 +3616,8 @@ gl847_send_shading_data (Genesys_Device * dev, uint8_t * data, int size)
return status;
}
DBGCOMPLETED;
return status;
}
@ -4083,7 +4083,6 @@ gl847_init_memory_layout (Genesys_Device * dev)
return status;
}
#if 0
/** @brief dummy scan to reset scanner
*
* */
@ -4148,7 +4147,6 @@ gl847_dummy_scan (Genesys_Device * dev)
DBGCOMPLETED;
return SANE_STATUS_GOOD;
}
#endif
#if 0
/**
@ -4484,6 +4482,8 @@ gl847_init (Genesys_Device * dev)
}
dev->already_initialized = SANE_TRUE;
gl847_dummy_scan(dev);
/* Move home */
RIE (gl847_slow_back_home (dev, SANE_TRUE));
dev->scanhead_position_in_steps = 0;