kopia lustrzana https://gitlab.com/sane-project/backends
Merge branch 'genesys-desegmentation-refactor' into 'master'
genesys: Simplify desegmentation state (part 1) See merge request sane-project/backends!160merge-requests/161/merge
commit
ce2d9840a7
|
@ -3562,9 +3562,8 @@ static void genesys_fill_read_buffer(Genesys_Device* dev)
|
|||
/* Some setups need the reads to be multiples of 256 bytes */
|
||||
size &= ~0xff;
|
||||
|
||||
if (dev->read_bytes_left < size)
|
||||
{
|
||||
size = dev->read_bytes_left;
|
||||
if (dev->read_bytes_left_after_deseg < size) {
|
||||
size = dev->read_bytes_left_after_deseg;
|
||||
/*round up to a multiple of 256 bytes */
|
||||
size += (size & 0xff) ? 0x100 : 0x00;
|
||||
size &= ~0xff;
|
||||
|
@ -3604,10 +3603,11 @@ static void genesys_fill_read_buffer(Genesys_Device* dev)
|
|||
dev->cmd_set->bulk_read_data(dev, 0x45, work_buffer_dst, size);
|
||||
}
|
||||
|
||||
if (size > dev->read_bytes_left)
|
||||
size = dev->read_bytes_left;
|
||||
if (size > dev->read_bytes_left_after_deseg) {
|
||||
size = dev->read_bytes_left_after_deseg;
|
||||
}
|
||||
|
||||
dev->read_bytes_left -= size;
|
||||
dev->read_bytes_left_after_deseg -= size;
|
||||
|
||||
dev->read_buffer.produce(size);
|
||||
}
|
||||
|
@ -3695,9 +3695,9 @@ static void genesys_read_ordered_data(Genesys_Device* dev, SANE_Byte* destinatio
|
|||
DBG(DBG_info, "%s: %lu lines left by output\n", __func__,
|
||||
((dev->total_bytes_to_read - dev->total_bytes_read) * 8UL) /
|
||||
(dev->settings.requested_pixels * channels * depth));
|
||||
DBG(DBG_info, "%s: %lu lines left by input\n", __func__,
|
||||
((dev->read_bytes_left + dev->read_buffer.avail()) * 8UL) /
|
||||
(src_pixels * channels * depth));
|
||||
DBG(DBG_info, "%s: %lu lines left by input\n", __func__,
|
||||
((dev->read_bytes_left_after_deseg + dev->read_buffer.avail()) * 8UL) /
|
||||
(src_pixels * channels * depth));
|
||||
|
||||
if (channels == 1)
|
||||
{
|
||||
|
@ -6524,7 +6524,8 @@ sane_read_impl(SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, SANE_Int*
|
|||
DBG(DBG_proc, "%s: start, %d maximum bytes required\n", __func__, max_len);
|
||||
DBG(DBG_io2, "%s: bytes_to_read=%lu, total_bytes_read=%lu\n", __func__,
|
||||
(u_long) dev->total_bytes_to_read, (u_long) dev->total_bytes_read);
|
||||
DBG(DBG_io2, "%s: physical bytes to read = %lu\n", __func__, (u_long) dev->read_bytes_left);
|
||||
DBG(DBG_io2, "%s: desegmented bytes to read = %lu\n", __func__,
|
||||
(u_long) dev->read_bytes_left_after_deseg);
|
||||
|
||||
if(dev->total_bytes_read>=dev->total_bytes_to_read)
|
||||
{
|
||||
|
|
|
@ -282,8 +282,9 @@ struct Genesys_Device
|
|||
// local buffer for gray data during dynamix lineart
|
||||
Genesys_Buffer local_buffer;
|
||||
|
||||
// bytes to read from scanner
|
||||
size_t read_bytes_left = 0;
|
||||
// bytes to read from desegmentation step. This is not the same as physical bytes read from
|
||||
// scanners, see `wpl` which corresponds to this information on certain scanners.
|
||||
size_t read_bytes_left_after_deseg = 0;
|
||||
|
||||
// total bytes read sent to frontend
|
||||
size_t total_bytes_read = 0;
|
||||
|
|
|
@ -824,18 +824,13 @@ static void gl124_setup_sensor(Genesys_Device * dev,
|
|||
*/
|
||||
static void gl124_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sensor& sensor,
|
||||
Genesys_Register_Set* reg, unsigned int exposure_time,
|
||||
const ScanSession& session, int used_res,
|
||||
unsigned int start, unsigned int pixels,
|
||||
int channels, int depth, unsigned ccd_size_divisor,
|
||||
ColorFilter color_filter)
|
||||
const ScanSession& session, unsigned int start)
|
||||
{
|
||||
DBG_HELPER_ARGS(dbg, "exposure_time=%d, used_res=%d, start=%d, pixels=%d, channels=%d, depth=%d, "
|
||||
"ccd_size_divisor=%d\n",
|
||||
exposure_time, used_res, start, pixels, channels, depth, ccd_size_divisor);
|
||||
DBG_HELPER_ARGS(dbg, "exposure_time=%d, start=%d\n",
|
||||
exposure_time, start);
|
||||
unsigned int words_per_line, segcnt;
|
||||
unsigned int startx, endx, segnb;
|
||||
unsigned int dpiset, dpihw, factor;
|
||||
unsigned int bytes;
|
||||
unsigned int dpihw, factor;
|
||||
GenesysRegister *r;
|
||||
uint32_t expmax;
|
||||
|
||||
|
@ -845,23 +840,21 @@ static void gl124_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens
|
|||
|
||||
// to manage high resolution device while keeping good low resolution scanning speed, we
|
||||
// make hardware dpi vary
|
||||
dpihw = sensor.get_register_hwdpi(used_res * ccd_pixels_per_system_pixel);
|
||||
factor = sensor.get_hwdpi_divisor_for_dpi(used_res * ccd_pixels_per_system_pixel);
|
||||
dpihw = sensor.get_register_hwdpi(session.output_resolution * ccd_pixels_per_system_pixel);
|
||||
factor = sensor.get_hwdpi_divisor_for_dpi(session.output_resolution * ccd_pixels_per_system_pixel);
|
||||
DBG (DBG_io2, "%s: dpihw=%d (factor=%d)\n", __func__, dpihw, factor);
|
||||
|
||||
// sensor parameters
|
||||
gl124_setup_sensor(dev, sensor, reg, dpihw, ccd_size_divisor);
|
||||
dpiset = used_res * ccd_pixels_per_system_pixel;
|
||||
gl124_setup_sensor(dev, sensor, reg, dpihw, session.ccd_size_divisor);
|
||||
|
||||
/* start and end coordinate in optical dpi coordinates */
|
||||
/* startx = start / ccd_pixels_per_system_pixel + sensor.dummy_pixel; XXX STEF XXX */
|
||||
startx = start / ccd_pixels_per_system_pixel;
|
||||
endx = startx + pixels / ccd_pixels_per_system_pixel;
|
||||
endx = startx + session.optical_pixels / ccd_pixels_per_system_pixel;
|
||||
|
||||
/* pixel coordinate factor correction when used dpihw is not maximal one */
|
||||
startx/=factor;
|
||||
endx/=factor;
|
||||
unsigned used_pixels = endx - startx;
|
||||
|
||||
gl124_set_fe(dev, sensor, AFE_SET);
|
||||
|
||||
|
@ -880,7 +873,7 @@ static void gl124_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens
|
|||
r->value &= ~REG01_SCAN;
|
||||
|
||||
r = sanei_genesys_get_address (reg, REG03);
|
||||
if((dev->model->ccd_type!=CIS_CANONLIDE120)&&(used_res>=600))
|
||||
if((dev->model->ccd_type!=CIS_CANONLIDE120)&&(session.params.xres>=600))
|
||||
{
|
||||
r->value &= ~REG03_AVEENB;
|
||||
DBG (DBG_io, "%s: disabling AVEENB\n", __func__);
|
||||
|
@ -900,7 +893,7 @@ static void gl124_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens
|
|||
|
||||
/* monochrome / color scan */
|
||||
r = sanei_genesys_get_address (reg, REG04);
|
||||
switch (depth)
|
||||
switch (session.params.depth)
|
||||
{
|
||||
case 1:
|
||||
r->value &= ~REG04_BITSET;
|
||||
|
@ -916,9 +909,9 @@ static void gl124_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens
|
|||
}
|
||||
|
||||
r->value &= ~REG04_FILTER;
|
||||
if (channels == 1)
|
||||
if (session.params.channels == 1)
|
||||
{
|
||||
switch (color_filter)
|
||||
switch (session.params.color_filter)
|
||||
{
|
||||
case ColorFilter::RED:
|
||||
r->value |= 0x10;
|
||||
|
@ -944,7 +937,8 @@ static void gl124_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens
|
|||
r->value |= REG05_GMMENB;
|
||||
}
|
||||
|
||||
unsigned dpiset_reg = dpiset * ccd_size_divisor;
|
||||
unsigned dpiset_reg = session.output_resolution * ccd_pixels_per_system_pixel *
|
||||
session.ccd_size_divisor;
|
||||
if (sensor.dpiset_override != 0) {
|
||||
dpiset_reg = sensor.dpiset_override;
|
||||
}
|
||||
|
@ -996,17 +990,9 @@ static void gl124_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens
|
|||
reg->set24(REG_ENDPIXEL, endx / segnb);
|
||||
DBG (DBG_io2, "%s: endpixel used=%d\n", __func__, endx/segnb);
|
||||
|
||||
/* words(16bit) before gamma, conversion to 8 bit or lineart */
|
||||
words_per_line = (used_pixels * dpiset) / dpihw;
|
||||
bytes = depth / 8;
|
||||
if (depth == 1)
|
||||
{
|
||||
words_per_line = (words_per_line >> 3) + ((words_per_line & 7) ? 1 : 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
words_per_line *= bytes;
|
||||
}
|
||||
// words(16bit) before gamma, conversion to 8 bit or lineart
|
||||
words_per_line = multiply_by_depth_ceil(session.output_pixels / session.ccd_size_divisor,
|
||||
session.params.depth);
|
||||
|
||||
dev->bpl = words_per_line;
|
||||
dev->cur = 0;
|
||||
|
@ -1017,15 +1003,14 @@ static void gl124_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens
|
|||
dev->line_count = 0;
|
||||
dev->line_interp = 0;
|
||||
|
||||
DBG (DBG_io2, "%s: used_pixels =%d\n", __func__, used_pixels);
|
||||
DBG (DBG_io2, "%s: pixels =%d\n", __func__, pixels);
|
||||
DBG (DBG_io2, "%s: depth =%d\n", __func__, depth);
|
||||
DBG (DBG_io2, "%s: pixels =%d\n", __func__, session.optical_pixels);
|
||||
DBG (DBG_io2, "%s: depth =%d\n", __func__, session.params.depth);
|
||||
DBG (DBG_io2, "%s: dev->bpl =%lu\n", __func__, (unsigned long)dev->bpl);
|
||||
DBG (DBG_io2, "%s: dev->len =%lu\n", __func__, (unsigned long)dev->len);
|
||||
DBG (DBG_io2, "%s: dev->dist =%lu\n", __func__, (unsigned long)dev->dist);
|
||||
DBG (DBG_io2, "%s: dev->line_interp=%lu\n", __func__, (unsigned long)dev->line_interp);
|
||||
|
||||
words_per_line *= channels;
|
||||
words_per_line *= session.params.channels;
|
||||
dev->wpl = words_per_line;
|
||||
|
||||
/* allocate buffer for odd/even pixels handling */
|
||||
|
@ -1120,11 +1105,7 @@ static void gl124_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens
|
|||
*/
|
||||
|
||||
// now _LOGICAL_ optical values used are known, setup registers
|
||||
gl124_init_optical_regs_scan(dev, sensor, reg, exposure_time, session, session.params.xres,
|
||||
start,
|
||||
session.optical_pixels, session.params.channels,
|
||||
session.params.depth, session.ccd_size_divisor,
|
||||
session.params.color_filter);
|
||||
gl124_init_optical_regs_scan(dev, sensor, reg, exposure_time, session, start);
|
||||
|
||||
/* add tl_y to base movement */
|
||||
move = session.params.starty;
|
||||
|
@ -1164,9 +1145,10 @@ static void gl124_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens
|
|||
dev->out_buffer.clear();
|
||||
dev->out_buffer.alloc((8 * dev->settings.pixels * session.params.channels * session.params.depth) / 8);
|
||||
|
||||
dev->read_bytes_left = session.output_line_bytes * session.output_line_count;
|
||||
dev->read_bytes_left_after_deseg = session.output_line_bytes * session.output_line_count;
|
||||
|
||||
DBG(DBG_info, "%s: physical bytes to read = %lu\n", __func__, (u_long) dev->read_bytes_left);
|
||||
DBG(DBG_info, "%s: desegmented bytes to read = %lu\n", __func__,
|
||||
(u_long) dev->read_bytes_left_after_deseg);
|
||||
dev->read_active = SANE_TRUE;
|
||||
|
||||
dev->session = session;
|
||||
|
|
|
@ -742,9 +742,10 @@ static void gl646_setup_registers(Genesys_Device* dev,
|
|||
/* scan bytes to read */
|
||||
unsigned cis_channel_multiplier = dev->model->is_cis ? session.params.channels : 1;
|
||||
|
||||
dev->read_bytes_left = session.output_line_bytes * session.output_line_count * cis_channel_multiplier;
|
||||
dev->read_bytes_left_after_deseg = session.output_line_bytes * session.output_line_count * cis_channel_multiplier;
|
||||
|
||||
DBG(DBG_info, "%s: physical bytes to read = %lu\n", __func__, (u_long) dev->read_bytes_left);
|
||||
DBG(DBG_info, "%s: desegmented bytes to read = %lu\n", __func__,
|
||||
(u_long) dev->read_bytes_left_after_deseg);
|
||||
dev->read_active = SANE_TRUE;
|
||||
|
||||
dev->session = session;
|
||||
|
@ -1511,7 +1512,7 @@ static void gl646_detect_document_end(Genesys_Device* dev)
|
|||
*/
|
||||
DBG(DBG_io, "%s: total_bytes_to_read=%lu\n", __func__, (u_long) dev->total_bytes_to_read);
|
||||
DBG(DBG_io, "%s: total_bytes_read =%lu\n", __func__, (u_long) dev->total_bytes_read);
|
||||
DBG(DBG_io, "%s: read_bytes_left =%lu\n", __func__, (u_long) dev->read_bytes_left);
|
||||
DBG(DBG_io, "%s: read_bytes_left_after_deseg =%lu\n", __func__, (u_long) dev->read_bytes_left_after_deseg);
|
||||
|
||||
// amount of data available from scanner is what to scan
|
||||
sanei_genesys_read_valid_words(dev, &bytes_left);
|
||||
|
@ -1526,14 +1527,13 @@ static void gl646_detect_document_end(Genesys_Device* dev)
|
|||
if (dev->session.params.channels > 1) {
|
||||
bytes_left = 3 * bytes_left;
|
||||
}
|
||||
if (bytes_left < dev->read_bytes_left)
|
||||
{
|
||||
dev->total_bytes_to_read = dev->total_bytes_read + bytes_left;
|
||||
dev->read_bytes_left = bytes_left;
|
||||
}
|
||||
if (bytes_left < dev->read_bytes_left_after_deseg) {
|
||||
dev->total_bytes_to_read = dev->total_bytes_read + bytes_left;
|
||||
dev->read_bytes_left_after_deseg = bytes_left;
|
||||
}
|
||||
DBG(DBG_io, "%s: total_bytes_to_read=%lu\n", __func__, (u_long) dev->total_bytes_to_read);
|
||||
DBG(DBG_io, "%s: total_bytes_read =%lu\n", __func__, (u_long) dev->total_bytes_read);
|
||||
DBG(DBG_io, "%s: read_bytes_left =%lu\n", __func__, (u_long) dev->read_bytes_left);
|
||||
DBG(DBG_io, "%s: read_bytes_left =%lu\n", __func__, (u_long) dev->read_bytes_left_after_deseg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1453,42 +1453,22 @@ static void gl841_init_optical_regs_off(Genesys_Register_Set* reg)
|
|||
|
||||
static void gl841_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sensor& sensor,
|
||||
Genesys_Register_Set* reg, unsigned int exposure_time,
|
||||
const ScanSession& session, unsigned int used_res,
|
||||
unsigned int start,
|
||||
unsigned int pixels, int channels,
|
||||
int depth, unsigned ccd_size_divisor,
|
||||
ColorFilter color_filter)
|
||||
const ScanSession& session, unsigned int start)
|
||||
{
|
||||
DBG_HELPER_ARGS(dbg, "exposure_time=%d, used_res=%d, start=%d, pixels=%d, channels=%d, "
|
||||
"depth=%d, ccd_size_divisor=%d",
|
||||
exposure_time, used_res, start, pixels, channels, depth, ccd_size_divisor);
|
||||
unsigned int words_per_line;
|
||||
DBG_HELPER_ARGS(dbg, "exposure_time=%d, start=%d", exposure_time, start);
|
||||
unsigned int end;
|
||||
unsigned int dpiset;
|
||||
GenesysRegister* r;
|
||||
uint16_t expavg, expr, expb, expg;
|
||||
|
||||
end = start + pixels;
|
||||
end = start + session.optical_pixels;
|
||||
|
||||
gl841_set_fe(dev, sensor, AFE_SET);
|
||||
|
||||
/* adjust used_res for chosen dpihw */
|
||||
used_res = used_res * gl841_get_dpihw(dev) / sensor.optical_res;
|
||||
|
||||
/*
|
||||
with ccd_size_divisor==2 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.
|
||||
*/
|
||||
dpiset = used_res * ccd_size_divisor;
|
||||
|
||||
/* gpio part.*/
|
||||
if (dev->model->gpo_type == GPO_CANONLIDE35)
|
||||
{
|
||||
r = sanei_genesys_get_address (reg, REG6C);
|
||||
if (ccd_size_divisor > 1) {
|
||||
if (session.ccd_size_divisor > 1) {
|
||||
r->value &= ~0x80;
|
||||
} else {
|
||||
r->value |= 0x80;
|
||||
|
@ -1497,7 +1477,7 @@ static void gl841_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens
|
|||
if (dev->model->gpo_type == GPO_CANONLIDE80)
|
||||
{
|
||||
r = sanei_genesys_get_address (reg, REG6C);
|
||||
if (ccd_size_divisor > 1) {
|
||||
if (session.ccd_size_divisor > 1) {
|
||||
r->value &= ~0x40;
|
||||
r->value |= 0x20;
|
||||
} else {
|
||||
|
@ -1534,7 +1514,7 @@ static void gl841_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens
|
|||
|
||||
/* monochrome / color scan */
|
||||
r = sanei_genesys_get_address (reg, 0x04);
|
||||
switch (depth) {
|
||||
switch (session.params.depth) {
|
||||
case 1:
|
||||
r->value &= ~REG04_BITSET;
|
||||
r->value |= REG04_LINEART;
|
||||
|
@ -1554,9 +1534,9 @@ static void gl841_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens
|
|||
if (session.params.flags & SCAN_FLAG_ENABLE_LEDADD) {
|
||||
r->value |= 0x10; /* no filter */
|
||||
}
|
||||
else if (channels == 1)
|
||||
else if (session.params.channels == 1)
|
||||
{
|
||||
switch (color_filter)
|
||||
switch (session.params.color_filter)
|
||||
{
|
||||
case ColorFilter::RED:
|
||||
r->value |= 0x14;
|
||||
|
@ -1614,35 +1594,20 @@ static void gl841_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens
|
|||
}
|
||||
|
||||
/* sensor parameters */
|
||||
sanei_gl841_setup_sensor(dev, sensor, &dev->reg, 1, ccd_size_divisor);
|
||||
sanei_gl841_setup_sensor(dev, sensor, &dev->reg, 1, session.ccd_size_divisor);
|
||||
|
||||
r = sanei_genesys_get_address (reg, 0x29);
|
||||
r->value = 255; /*<<<"magic" number, only suitable for cis*/
|
||||
|
||||
reg->set16(REG_DPISET, dpiset);
|
||||
reg->set16(REG_DPISET, gl841_get_dpihw(dev) * session.output_resolution / session.optical_resolution);
|
||||
reg->set16(REG_STRPIXEL, start);
|
||||
reg->set16(REG_ENDPIXEL, end);
|
||||
DBG(DBG_io2, "%s: STRPIXEL=%d, ENDPIXEL=%d\n", __func__, start, end);
|
||||
|
||||
/* words(16bit) before gamma, conversion to 8 bit or lineart*/
|
||||
words_per_line = (pixels * dpiset) / gl841_get_dpihw(dev);
|
||||
dev->wpl = session.output_line_bytes;
|
||||
dev->bpl = session.output_line_bytes;
|
||||
|
||||
words_per_line *= channels;
|
||||
|
||||
if (depth == 1)
|
||||
words_per_line = (words_per_line >> 3) + ((words_per_line & 7)?1:0);
|
||||
else
|
||||
words_per_line *= depth / 8;
|
||||
|
||||
dev->wpl = words_per_line;
|
||||
dev->bpl = words_per_line;
|
||||
|
||||
r = sanei_genesys_get_address (reg, 0x35);
|
||||
r->value = LOBYTE (HIWORD (words_per_line));
|
||||
r = sanei_genesys_get_address (reg, 0x36);
|
||||
r->value = HIBYTE (LOWORD (words_per_line));
|
||||
r = sanei_genesys_get_address (reg, 0x37);
|
||||
r->value = LOBYTE (LOWORD (words_per_line));
|
||||
reg->set24(REG_MAXWD, session.output_line_bytes);
|
||||
|
||||
reg->set16(REG_LPERIOD, exposure_time);
|
||||
|
||||
|
@ -1883,10 +1848,7 @@ dummy \ scanned lines
|
|||
session.params.flags |= SCAN_FLAG_DISABLE_GAMMA;
|
||||
}
|
||||
|
||||
gl841_init_optical_regs_scan(dev, sensor, reg, exposure_time, session, session.params.xres, start,
|
||||
session.optical_pixels, session.params.channels,
|
||||
session.params.depth, session.ccd_size_divisor,
|
||||
session.params.color_filter);
|
||||
gl841_init_optical_regs_scan(dev, sensor, reg, exposure_time, session, start);
|
||||
|
||||
move = session.params.starty;
|
||||
DBG(DBG_info, "%s: move=%d steps\n", __func__, move);
|
||||
|
@ -1940,9 +1902,10 @@ dummy \ scanned lines
|
|||
dev->out_buffer.clear();
|
||||
dev->out_buffer.alloc((8 * dev->settings.pixels * session.params.channels * session.params.depth) / 8);
|
||||
|
||||
dev->read_bytes_left = session.output_line_bytes * session.output_line_count;
|
||||
dev->read_bytes_left_after_deseg = session.output_line_bytes * session.output_line_count;
|
||||
|
||||
DBG(DBG_info, "%s: physical bytes to read = %lu\n", __func__, (u_long) dev->read_bytes_left);
|
||||
DBG(DBG_info, "%s: desegmented bytes to read = %lu\n", __func__,
|
||||
(u_long) dev->read_bytes_left_after_deseg);
|
||||
dev->read_active = SANE_TRUE;
|
||||
|
||||
dev->session = session;
|
||||
|
@ -2471,7 +2434,7 @@ static void gl841_detect_document_end(Genesys_Device* dev)
|
|||
sanei_genesys_read_scancnt(dev, &scancnt);
|
||||
} catch (...) {
|
||||
dev->total_bytes_to_read = dev->total_bytes_read;
|
||||
dev->read_bytes_left = 0;
|
||||
dev->read_bytes_left_after_deseg = 0;
|
||||
throw;
|
||||
}
|
||||
|
||||
|
|
|
@ -174,6 +174,7 @@
|
|||
#define REG_DPISET 0x2c
|
||||
#define REG_STRPIXEL 0x30
|
||||
#define REG_ENDPIXEL 0x32
|
||||
#define REG_MAXWD 0x35
|
||||
#define REG_LPERIOD 0x38
|
||||
|
||||
#define REG40_HISPDFLG 0x04
|
||||
|
|
|
@ -1322,9 +1322,10 @@ static void gl843_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens
|
|||
dev->out_buffer.alloc((8 * session.params.pixels * session.params.channels *
|
||||
session.params.depth) / 8);
|
||||
|
||||
dev->read_bytes_left = session.output_line_bytes * session.output_line_count;
|
||||
dev->read_bytes_left_after_deseg = session.output_line_bytes * session.output_line_count;
|
||||
|
||||
DBG(DBG_info, "%s: physical bytes to read = %lu\n", __func__, (u_long) dev->read_bytes_left);
|
||||
DBG(DBG_info, "%s: physical bytes to read = %lu\n", __func__,
|
||||
(u_long) dev->read_bytes_left_after_deseg);
|
||||
dev->read_active = SANE_TRUE;
|
||||
|
||||
dev->session = session;
|
||||
|
@ -1569,7 +1570,7 @@ static void gl843_detect_document_end(Genesys_Device* dev)
|
|||
|
||||
unsigned channels = dev->session.params.channels;
|
||||
unsigned depth = dev->session.params.depth;
|
||||
read_bytes_left = (int) dev->read_bytes_left;
|
||||
read_bytes_left = (int) dev->read_bytes_left_after_deseg;
|
||||
DBG(DBG_io, "%s: read_bytes_left=%d\n", __func__, read_bytes_left);
|
||||
|
||||
// get lines read
|
||||
|
@ -1641,16 +1642,13 @@ static void gl843_detect_document_end(Genesys_Device* dev)
|
|||
|
||||
dev->total_bytes_to_read -= sub_bytes;
|
||||
|
||||
/* then adjust the physical bytes to read */
|
||||
if (read_bytes_left > sub_bytes)
|
||||
{
|
||||
dev->read_bytes_left -= sub_bytes;
|
||||
}
|
||||
else
|
||||
{
|
||||
dev->total_bytes_to_read = dev->total_bytes_read;
|
||||
dev->read_bytes_left = 0;
|
||||
}
|
||||
/* then adjust the desegmented bytes to read */
|
||||
if (read_bytes_left > sub_bytes) {
|
||||
dev->read_bytes_left_after_deseg -= sub_bytes;
|
||||
} else {
|
||||
dev->total_bytes_to_read = dev->total_bytes_read;
|
||||
dev->read_bytes_left_after_deseg = 0;
|
||||
}
|
||||
|
||||
DBG(DBG_io, "%s: sublines=%d\n", __func__, sublines);
|
||||
DBG(DBG_io, "%s: subbytes=%d\n", __func__, sub_bytes);
|
||||
|
@ -2154,7 +2152,7 @@ static void gl843_search_start_position(Genesys_Device* dev)
|
|||
// send to scanner
|
||||
dev->write_registers(local_reg);
|
||||
|
||||
size = dev->read_bytes_left;
|
||||
size = dev->read_bytes_left_after_deseg;
|
||||
|
||||
std::vector<uint8_t> data(size);
|
||||
|
||||
|
@ -2392,7 +2390,7 @@ static void gl843_init_regs_for_shading(Genesys_Device* dev, const Genesys_Senso
|
|||
// the pixel number may be updated to conform to scanner constraints
|
||||
dev->calib_pixels = dev->current_setup.pixels;
|
||||
|
||||
dev->calib_total_bytes_to_read = dev->read_bytes_left;
|
||||
dev->calib_total_bytes_to_read = dev->read_bytes_left_after_deseg;
|
||||
|
||||
dev->scanhead_position_in_steps += dev->calib_lines + move;
|
||||
|
||||
|
@ -2574,7 +2572,7 @@ static SensorExposure gl843_led_calibration(Genesys_Device* dev, const Genesys_S
|
|||
|
||||
dev->write_registers(regs);
|
||||
|
||||
total_size = dev->read_bytes_left;
|
||||
total_size = dev->read_bytes_left_after_deseg;
|
||||
|
||||
std::vector<uint8_t> line(total_size);
|
||||
|
||||
|
@ -2812,8 +2810,8 @@ static void gl843_offset_calibration(Genesys_Device* dev, const Genesys_Sensor&
|
|||
|
||||
sanei_genesys_set_motor_power(regs, false);
|
||||
|
||||
/* allocate memory for scans */
|
||||
total_size = dev->read_bytes_left;
|
||||
// allocate memory for scans
|
||||
total_size = dev->read_bytes_left_after_deseg;
|
||||
|
||||
std::vector<uint8_t> first_line(total_size);
|
||||
std::vector<uint8_t> second_line(total_size);
|
||||
|
@ -3042,7 +3040,7 @@ static void gl843_coarse_gain_calibration(Genesys_Device* dev, const Genesys_Sen
|
|||
|
||||
dev->write_registers(regs);
|
||||
|
||||
total_size = dev->read_bytes_left;
|
||||
total_size = dev->read_bytes_left_after_deseg;
|
||||
|
||||
std::vector<uint8_t> line(total_size);
|
||||
|
||||
|
@ -3417,7 +3415,7 @@ static void gl843_search_strip(Genesys_Device* dev, const Genesys_Sensor& sensor
|
|||
|
||||
gl843_init_scan_regs(dev, calib_sensor, &local_reg, session);
|
||||
|
||||
size = dev->read_bytes_left;
|
||||
size = dev->read_bytes_left_after_deseg;
|
||||
std::vector<uint8_t> data(size);
|
||||
|
||||
/* set up for reverse or forward */
|
||||
|
|
|
@ -722,15 +722,11 @@ static void gl846_init_motor_regs_scan(Genesys_Device* dev,
|
|||
*/
|
||||
static void gl846_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sensor& sensor,
|
||||
Genesys_Register_Set* reg, unsigned int exposure_time,
|
||||
const ScanSession& session, int used_res,
|
||||
unsigned int start, unsigned int pixels,
|
||||
int channels, int depth, ColorFilter color_filter)
|
||||
const ScanSession& session, unsigned int start)
|
||||
{
|
||||
DBG_HELPER_ARGS(dbg, "exposure_time=%d, used_res=%d, start=%d, pixels=%d, channels=%d, depth=%d",
|
||||
exposure_time, used_res, start, pixels, channels, depth);
|
||||
DBG_HELPER_ARGS(dbg, "exposure_time=%d, start=%d", exposure_time, start);
|
||||
unsigned int words_per_line;
|
||||
unsigned int dpiset, dpihw, segnb, factor;
|
||||
unsigned int bytes;
|
||||
unsigned int dpihw, segnb, factor;
|
||||
GenesysRegister *r;
|
||||
|
||||
// resolution is divided according to ccd_pixels_per_system_pixel()
|
||||
|
@ -739,18 +735,17 @@ static void gl846_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens
|
|||
|
||||
// to manage high resolution device while keeping good low resolution scanning speed,
|
||||
// we make hardware dpi vary
|
||||
dpihw = sensor.get_register_hwdpi(used_res * ccd_pixels_per_system_pixel);
|
||||
dpihw = sensor.get_register_hwdpi(session.params.xres * ccd_pixels_per_system_pixel);
|
||||
factor = sensor.optical_res/dpihw;
|
||||
DBG(DBG_io2, "%s: dpihw=%d (factor=%d)\n", __func__, dpihw, factor);
|
||||
|
||||
// sensor parameters
|
||||
const auto& sensor_profile = get_sensor_profile(sensor, dpihw);
|
||||
gl846_setup_sensor(dev, sensor, reg, dpihw);
|
||||
dpiset = used_res * ccd_pixels_per_system_pixel ;
|
||||
|
||||
// start and end coordinate in optical dpi coordinates
|
||||
unsigned startx = start / ccd_pixels_per_system_pixel + sensor.CCD_start_xoffset;
|
||||
unsigned endx = startx + pixels / ccd_pixels_per_system_pixel;
|
||||
unsigned endx = startx + session.optical_pixels / ccd_pixels_per_system_pixel;
|
||||
|
||||
/* sensors are built from 600 dpi segments for LiDE 100/200
|
||||
* and 1200 dpi for the 700F */
|
||||
|
@ -810,7 +805,7 @@ static void gl846_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens
|
|||
|
||||
/* monochrome / color scan */
|
||||
r = sanei_genesys_get_address (reg, REG04);
|
||||
switch (depth)
|
||||
switch (session.params.depth)
|
||||
{
|
||||
case 1:
|
||||
r->value &= ~REG04_BITSET;
|
||||
|
@ -826,9 +821,9 @@ static void gl846_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens
|
|||
}
|
||||
|
||||
r->value &= ~(REG04_FILTER | REG04_AFEMOD);
|
||||
if (channels == 1)
|
||||
if (session.params.channels == 1)
|
||||
{
|
||||
switch (color_filter)
|
||||
switch (session.params.color_filter)
|
||||
{
|
||||
case ColorFilter::RED:
|
||||
r->value |= 0x24;
|
||||
|
@ -875,28 +870,19 @@ static void gl846_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens
|
|||
}
|
||||
|
||||
/* words(16bit) before gamma, conversion to 8 bit or lineart*/
|
||||
words_per_line = (used_pixels * dpiset) / dpihw;
|
||||
bytes=depth/8;
|
||||
if (depth == 1)
|
||||
{
|
||||
words_per_line = (words_per_line+7)/8 ;
|
||||
dev->len = (dev->len >> 3) + ((dev->len & 7) ? 1 : 0);
|
||||
dev->dist = (dev->dist >> 3) + ((dev->dist & 7) ? 1 : 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
words_per_line *= bytes;
|
||||
dev->dist *= bytes;
|
||||
dev->len *= bytes;
|
||||
}
|
||||
words_per_line = (used_pixels * session.params.xres * ccd_pixels_per_system_pixel) / sensor.get_register_hwdpi(session.params.xres * ccd_pixels_per_system_pixel);
|
||||
words_per_line = multiply_by_depth_ceil(words_per_line, session.params.depth);
|
||||
dev->len = multiply_by_depth_ceil(dev->len, session.params.depth);
|
||||
dev->dist = multiply_by_depth_ceil(dev->dist, session.params.depth);
|
||||
|
||||
dev->bpl = words_per_line;
|
||||
dev->cur=0;
|
||||
dev->segnb=segnb;
|
||||
dev->line_interp = 0;
|
||||
|
||||
reg->set16(REG_DPISET,dpiset);
|
||||
DBG (DBG_io2, "%s: dpiset used=%d\n", __func__, dpiset);
|
||||
unsigned dpiset = session.params.xres * ccd_pixels_per_system_pixel;
|
||||
reg->set16(REG_DPISET, dpiset);
|
||||
DBG(DBG_io2, "%s: dpiset used=%d\n", __func__, dpiset);
|
||||
|
||||
reg->set16(REG_STRPIXEL,startx);
|
||||
reg->set16(REG_ENDPIXEL,endx);
|
||||
|
@ -904,14 +890,14 @@ static void gl846_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens
|
|||
DBG (DBG_io2, "%s: endx =%d\n", __func__, endx);
|
||||
|
||||
DBG (DBG_io2, "%s: used_pixels=%d\n", __func__, used_pixels);
|
||||
DBG (DBG_io2, "%s: pixels =%d\n", __func__, pixels);
|
||||
DBG (DBG_io2, "%s: depth =%d\n", __func__, depth);
|
||||
DBG (DBG_io2, "%s: pixels =%d\n", __func__, session.optical_pixels);
|
||||
DBG (DBG_io2, "%s: depth =%d\n", __func__, session.params.depth);
|
||||
DBG (DBG_io2, "%s: dev->bpl =%lu\n", __func__, (unsigned long)dev->bpl);
|
||||
DBG (DBG_io2, "%s: dev->len =%lu\n", __func__, (unsigned long)dev->len);
|
||||
DBG (DBG_io2, "%s: dev->dist =%lu\n", __func__, (unsigned long)dev->dist);
|
||||
DBG (DBG_io2, "%s: dev->segnb =%lu\n", __func__, (unsigned long)dev->segnb);
|
||||
|
||||
words_per_line *= channels;
|
||||
words_per_line *= session.params.channels;
|
||||
dev->wpl = words_per_line;
|
||||
|
||||
dev->oe_buffer.clear();
|
||||
|
@ -1001,9 +987,7 @@ static void gl846_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens
|
|||
/* we enable true gray for cis scanners only, and just when doing
|
||||
* scan since color calibration is OK for this mode
|
||||
*/
|
||||
gl846_init_optical_regs_scan(dev, sensor, reg, exposure_time, session, session.params.xres, start,
|
||||
session.optical_pixels, session.params.channels, session.params.depth,
|
||||
session.params.color_filter);
|
||||
gl846_init_optical_regs_scan(dev, sensor, reg, exposure_time, session, start);
|
||||
|
||||
/*** motor parameters ***/
|
||||
|
||||
|
@ -1043,9 +1027,10 @@ static void gl846_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens
|
|||
dev->out_buffer.clear();
|
||||
dev->out_buffer.alloc((8 * session.params.pixels * session.params.channels * session.params.depth) / 8);
|
||||
|
||||
dev->read_bytes_left = session.output_line_bytes * session.output_line_count;
|
||||
dev->read_bytes_left_after_deseg = session.output_line_bytes * session.output_line_count;
|
||||
|
||||
DBG(DBG_info, "%s: physical bytes to read = %lu\n", __func__, (u_long) dev->read_bytes_left);
|
||||
DBG(DBG_info, "%s: desegmented bytes to read = %lu\n", __func__,
|
||||
(u_long) dev->read_bytes_left_after_deseg);
|
||||
dev->read_active = SANE_TRUE;
|
||||
|
||||
dev->session = session;
|
||||
|
|
|
@ -741,17 +741,11 @@ static void gl847_init_motor_regs_scan(Genesys_Device* dev,
|
|||
*/
|
||||
static void gl847_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sensor& sensor,
|
||||
Genesys_Register_Set* reg, unsigned int exposure_time,
|
||||
const ScanSession& session, int used_res,
|
||||
unsigned int start, unsigned int pixels,
|
||||
int channels, int depth,
|
||||
ColorFilter color_filter)
|
||||
const ScanSession& session, unsigned int start)
|
||||
{
|
||||
DBG_HELPER_ARGS(dbg, "exposure_time=%d, used_res=%d, start=%d, pixels=%d, channels=%d, "
|
||||
"depth=%d",
|
||||
exposure_time, used_res, start, pixels, channels, depth);
|
||||
DBG_HELPER_ARGS(dbg, "exposure_time=%d, start=%d", exposure_time, start);
|
||||
unsigned int words_per_line;
|
||||
unsigned dpiset, dpihw, segnb, factor;
|
||||
unsigned int bytes;
|
||||
GenesysRegister *r;
|
||||
|
||||
// resolution is divided according to ccd_pixels_per_system_pixel()
|
||||
|
@ -760,18 +754,18 @@ static void gl847_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens
|
|||
|
||||
// to manage high resolution device while keeping good low resolution scanning speed, we make
|
||||
// hardware dpi vary
|
||||
dpihw = sensor.get_register_hwdpi(used_res * ccd_pixels_per_system_pixel);
|
||||
dpihw = sensor.get_register_hwdpi(session.params.xres * ccd_pixels_per_system_pixel);
|
||||
factor=sensor.optical_res/dpihw;
|
||||
DBG(DBG_io2, "%s: dpihw=%d (factor=%d)\n", __func__, dpihw, factor);
|
||||
|
||||
// sensor parameters
|
||||
const auto& sensor_profile = get_sensor_profile(sensor, dpihw);
|
||||
gl847_setup_sensor(dev, sensor, reg, dpihw);
|
||||
dpiset = used_res * ccd_pixels_per_system_pixel;
|
||||
dpiset = session.params.xres * ccd_pixels_per_system_pixel;
|
||||
|
||||
// start and end coordinate in optical dpi coordinates
|
||||
unsigned startx = start / ccd_pixels_per_system_pixel + sensor.CCD_start_xoffset;
|
||||
unsigned endx = startx + pixels / ccd_pixels_per_system_pixel;
|
||||
unsigned endx = startx + session.optical_pixels / ccd_pixels_per_system_pixel;
|
||||
|
||||
/* sensors are built from 600 dpi segments for LiDE 100/200
|
||||
* and 1200 dpi for the 700F */
|
||||
|
@ -831,7 +825,7 @@ static void gl847_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens
|
|||
|
||||
/* monochrome / color scan */
|
||||
r = sanei_genesys_get_address (reg, REG04);
|
||||
switch (depth)
|
||||
switch (session.params.depth)
|
||||
{
|
||||
case 1:
|
||||
r->value &= ~REG04_BITSET;
|
||||
|
@ -847,9 +841,9 @@ static void gl847_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens
|
|||
}
|
||||
|
||||
r->value &= ~(REG04_FILTER | REG04_AFEMOD);
|
||||
if (channels == 1)
|
||||
if (session.params.channels == 1)
|
||||
{
|
||||
switch (color_filter)
|
||||
switch (session.params.color_filter)
|
||||
{
|
||||
|
||||
case ColorFilter::RED:
|
||||
|
@ -897,19 +891,9 @@ static void gl847_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens
|
|||
|
||||
/* words(16bit) before gamma, conversion to 8 bit or lineart*/
|
||||
words_per_line = (used_pixels * dpiset) / dpihw;
|
||||
bytes=depth/8;
|
||||
if (depth == 1)
|
||||
{
|
||||
words_per_line = (words_per_line+7)/8 ;
|
||||
dev->len = (dev->len >> 3) + ((dev->len & 7) ? 1 : 0);
|
||||
dev->dist = (dev->dist >> 3) + ((dev->dist & 7) ? 1 : 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
words_per_line *= bytes;
|
||||
dev->dist *= bytes;
|
||||
dev->len *= bytes;
|
||||
}
|
||||
words_per_line = multiply_by_depth_ceil(words_per_line, session.params.depth);
|
||||
dev->len = multiply_by_depth_ceil(dev->len, session.params.depth);
|
||||
dev->dist = multiply_by_depth_ceil(dev->dist, session.params.depth);
|
||||
|
||||
dev->bpl = words_per_line;
|
||||
dev->cur=0;
|
||||
|
@ -925,14 +909,14 @@ static void gl847_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens
|
|||
DBG (DBG_io2, "%s: endx =%d\n", __func__, endx);
|
||||
|
||||
DBG (DBG_io2, "%s: used_pixels=%d\n", __func__, used_pixels);
|
||||
DBG (DBG_io2, "%s: pixels =%d\n", __func__, pixels);
|
||||
DBG (DBG_io2, "%s: depth =%d\n", __func__, depth);
|
||||
DBG (DBG_io2, "%s: pixels =%d\n", __func__, session.optical_pixels);
|
||||
DBG (DBG_io2, "%s: depth =%d\n", __func__, session.params.depth);
|
||||
DBG (DBG_io2, "%s: dev->bpl =%lu\n", __func__, (unsigned long)dev->bpl);
|
||||
DBG (DBG_io2, "%s: dev->len =%lu\n", __func__, (unsigned long)dev->len);
|
||||
DBG (DBG_io2, "%s: dev->dist =%lu\n", __func__, (unsigned long)dev->dist);
|
||||
DBG (DBG_io2, "%s: dev->segnb =%lu\n", __func__, (unsigned long)dev->segnb);
|
||||
|
||||
words_per_line *= channels;
|
||||
words_per_line *= session.params.channels;
|
||||
dev->wpl = words_per_line;
|
||||
|
||||
dev->oe_buffer.clear();
|
||||
|
@ -1020,9 +1004,7 @@ static void gl847_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens
|
|||
/* we enable true gray for cis scanners only, and just when doing
|
||||
* scan since color calibration is OK for this mode
|
||||
*/
|
||||
gl847_init_optical_regs_scan(dev, sensor, reg, exposure_time, session, session.params.xres, start,
|
||||
session.optical_pixels, session.params.channels,
|
||||
session.params.depth, session.params.color_filter);
|
||||
gl847_init_optical_regs_scan(dev, sensor, reg, exposure_time, session, start);
|
||||
|
||||
move = session.params.starty;
|
||||
DBG(DBG_info, "%s: move=%d steps\n", __func__, move);
|
||||
|
@ -1059,9 +1041,11 @@ static void gl847_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens
|
|||
dev->out_buffer.clear();
|
||||
dev->out_buffer.alloc((8 * session.params.pixels * session.params.channels * session.params.depth) / 8);
|
||||
|
||||
dev->read_bytes_left = session.output_line_bytes * session.output_line_count;
|
||||
dev->read_bytes_left_after_deseg = session.output_line_bytes * session.output_line_count;
|
||||
|
||||
DBG(DBG_info, "%s: desegment bytes to read = %lu\n", __func__,
|
||||
(u_long) dev->read_bytes_left_after_deseg);
|
||||
|
||||
DBG(DBG_info, "%s: physical bytes to read = %lu\n", __func__, (u_long) dev->read_bytes_left);
|
||||
dev->read_active = SANE_TRUE;
|
||||
|
||||
dev->session = session;
|
||||
|
|
Ładowanie…
Reference in New Issue