kopia lustrzana https://gitlab.com/sane-project/backends
genesys: Extract multiplication by depth to a separate function
rodzic
37734c880d
commit
9915608309
|
@ -1185,14 +1185,10 @@ static void gl124_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens
|
|||
dev->current_setup.stagger = session.num_staggered_lines;
|
||||
dev->current_setup.max_shift = session.max_color_shift_lines + session.num_staggered_lines;
|
||||
|
||||
dev->total_bytes_read = 0;
|
||||
if (session.params.depth == 1) {
|
||||
dev->total_bytes_to_read = ((session.params.get_requested_pixels() * session.params.lines) / 8 +
|
||||
(((session.params.get_requested_pixels() * session.params.lines) % 8) ? 1 : 0)) * session.params.channels;
|
||||
} else {
|
||||
dev->total_bytes_to_read = session.params.get_requested_pixels() * session.params.lines *
|
||||
session.params.channels * (session.params.depth / 8);
|
||||
}
|
||||
dev->total_bytes_read = 0;
|
||||
dev->total_bytes_to_read =
|
||||
multiply_by_depth_ceil(session.params.get_requested_pixels() * session.params.lines,
|
||||
session.params.depth) * session.params.channels;
|
||||
|
||||
DBG(DBG_info, "%s: total bytes to send to frontend = %lu\n", __func__,
|
||||
(u_long) dev->total_bytes_to_read);
|
||||
|
|
|
@ -774,17 +774,10 @@ static void gl646_setup_registers(Genesys_Device* dev,
|
|||
dev->current_setup.stagger = session.num_staggered_lines;
|
||||
dev->current_setup.max_shift = session.max_color_shift_lines + session.num_staggered_lines;
|
||||
|
||||
/* total_bytes_to_read is the number of byte to send to frontend
|
||||
* total_bytes_read is the number of bytes sent to frontend
|
||||
* read_bytes_left is the number of bytes to read from the scanner
|
||||
*/
|
||||
dev->total_bytes_read = 0;
|
||||
if (session.params.depth == 1) {
|
||||
dev->total_bytes_to_read = ((session.params.requested_pixels * session.params.lines) / 8 +
|
||||
(((session.params.requested_pixels * session.params.lines) % 8) ? 1 : 0)) * session.params.channels;
|
||||
} else {
|
||||
dev->total_bytes_to_read = session.params.requested_pixels * session.params.lines * session.params.channels * bpp;
|
||||
}
|
||||
dev->total_bytes_to_read =
|
||||
multiply_by_depth_ceil(session.params.get_requested_pixels() * session.params.lines,
|
||||
session.params.depth) * session.params.channels;
|
||||
|
||||
/* select color filter based on settings */
|
||||
regs->find_reg(0x04).value &= ~REG04_FILTER;
|
||||
|
|
|
@ -1960,32 +1960,12 @@ dummy \ scanned lines
|
|||
dev->current_setup.stagger = session.num_staggered_lines;
|
||||
dev->current_setup.max_shift = session.max_color_shift_lines + session.num_staggered_lines;
|
||||
|
||||
/* TODO: should this be done elsewhere? */
|
||||
/* scan bytes to send to the frontend */
|
||||
/* theory :
|
||||
target_size =
|
||||
(dev->settings.pixels * dev->settings.lines * channels * depth) / 8;
|
||||
but it suffers from integer overflow so we do the following:
|
||||
|
||||
1 bit color images store color data byte-wise, eg byte 0 contains
|
||||
8 bits of red data, byte 1 contains 8 bits of green, byte 2 contains
|
||||
8 bits of blue.
|
||||
This does not fix the overflow, though.
|
||||
644mp*16 = 10gp, leading to an overflow
|
||||
-- pierre
|
||||
*/
|
||||
|
||||
dev->total_bytes_read = 0;
|
||||
if (session.params.depth == 1) {
|
||||
dev->total_bytes_to_read = ((session.params.get_requested_pixels() * session.params.lines) / 8 +
|
||||
(((session.params.get_requested_pixels() * session.params.lines)%8)?1:0)) * session.params.channels;
|
||||
} else {
|
||||
dev->total_bytes_to_read =
|
||||
session.params.get_requested_pixels() * session.params.lines * session.params.channels * (session.params.depth / 8);
|
||||
}
|
||||
dev->total_bytes_read = 0;
|
||||
dev->total_bytes_to_read =
|
||||
multiply_by_depth_ceil(session.params.get_requested_pixels() * session.params.lines,
|
||||
session.params.depth) * session.params.channels;
|
||||
|
||||
DBG(DBG_info, "%s: total bytes to send = %lu\n", __func__, (u_long) dev->total_bytes_to_read);
|
||||
/* END TODO */
|
||||
}
|
||||
|
||||
static void gl841_calculate_current_setup(Genesys_Device * dev, const Genesys_Sensor& sensor)
|
||||
|
|
|
@ -1346,14 +1346,9 @@ static void gl843_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens
|
|||
dev->current_setup.max_shift = session.max_color_shift_lines + session.num_staggered_lines;
|
||||
|
||||
dev->total_bytes_read = 0;
|
||||
if (session.params.depth == 1) {
|
||||
dev->total_bytes_to_read = ((session.params.get_requested_pixels() * session.params.lines) / 8 +
|
||||
(((session.params.get_requested_pixels() * session.params.lines) % 8) ? 1 : 0)) *
|
||||
session.params.channels;
|
||||
} else {
|
||||
dev->total_bytes_to_read = session.params.get_requested_pixels() * session.params.lines *
|
||||
session.params.channels * (session.params.depth / 8);
|
||||
}
|
||||
dev->total_bytes_to_read =
|
||||
multiply_by_depth_ceil(session.params.get_requested_pixels() * session.params.lines,
|
||||
session.params.depth) * session.params.channels;
|
||||
|
||||
DBG(DBG_info, "%s: total bytes to send = %lu\n", __func__, (u_long) dev->total_bytes_to_read);
|
||||
}
|
||||
|
|
|
@ -1063,32 +1063,12 @@ static void gl846_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens
|
|||
dev->current_setup.stagger = session.num_staggered_lines;
|
||||
dev->current_setup.max_shift = session.max_color_shift_lines + session.num_staggered_lines;
|
||||
|
||||
/* TODO: should this be done elsewhere? */
|
||||
/* scan bytes to send to the frontend */
|
||||
/* theory :
|
||||
target_size =
|
||||
(params.pixels * params.lines * channels * depth) / 8;
|
||||
but it suffers from integer overflow so we do the following:
|
||||
|
||||
1 bit color images store color data byte-wise, eg byte 0 contains
|
||||
8 bits of red data, byte 1 contains 8 bits of green, byte 2 contains
|
||||
8 bits of blue.
|
||||
This does not fix the overflow, though.
|
||||
644mp*16 = 10gp, leading to an overflow
|
||||
-- pierre
|
||||
*/
|
||||
|
||||
dev->total_bytes_read = 0;
|
||||
if (session.params.depth == 1) {
|
||||
dev->total_bytes_to_read = ((session.params.get_requested_pixels() * session.params.lines) / 8 +
|
||||
(((session.params.get_requested_pixels() * session.params.lines) % 8) ? 1 : 0)) *
|
||||
session.params.channels;
|
||||
} else {
|
||||
dev->total_bytes_to_read = session.params.get_requested_pixels() * session.params.lines * session.params.channels * (session.params.depth / 8);
|
||||
}
|
||||
dev->total_bytes_read = 0;
|
||||
dev->total_bytes_to_read =
|
||||
multiply_by_depth_ceil(session.params.get_requested_pixels() * session.params.lines,
|
||||
session.params.depth) * session.params.channels;
|
||||
|
||||
DBG(DBG_info, "%s: total bytes to send = %lu\n", __func__, (u_long) dev->total_bytes_to_read);
|
||||
/* END TODO */
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -1079,28 +1079,10 @@ static void gl847_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens
|
|||
dev->current_setup.stagger = session.num_staggered_lines;
|
||||
dev->current_setup.max_shift = session.max_color_shift_lines + session.num_staggered_lines;
|
||||
|
||||
/* TODO: should this be done elsewhere? */
|
||||
/* scan bytes to send to the frontend */
|
||||
/* theory :
|
||||
target_size =
|
||||
(session.params.pixels * session.params.lines * channels * depth) / 8;
|
||||
but it suffers from integer overflow so we do the following:
|
||||
|
||||
1 bit color images store color data byte-wise, eg byte 0 contains
|
||||
8 bits of red data, byte 1 contains 8 bits of green, byte 2 contains
|
||||
8 bits of blue.
|
||||
This does not fix the overflow, though.
|
||||
644mp*16 = 10gp, leading to an overflow
|
||||
-- pierre
|
||||
*/
|
||||
|
||||
dev->total_bytes_read = 0;
|
||||
if (session.params.depth == 1) {
|
||||
dev->total_bytes_to_read = ((session.params.get_requested_pixels() * session.params.lines) / 8 +
|
||||
(((session.params.get_requested_pixels() * session.params.lines) % 8) ? 1 : 0)) * session.params.channels;
|
||||
} else {
|
||||
dev->total_bytes_to_read = session.params.get_requested_pixels() * session.params.lines * session.params.channels * (session.params.depth / 8);
|
||||
}
|
||||
dev->total_bytes_to_read =
|
||||
multiply_by_depth_ceil(session.params.get_requested_pixels() * session.params.lines,
|
||||
session.params.depth) * session.params.channels;
|
||||
|
||||
DBG(DBG_info, "%s: total bytes to send = %lu\n", __func__, (u_long) dev->total_bytes_to_read);
|
||||
/* END TODO */
|
||||
|
|
|
@ -646,6 +646,15 @@ inline T abs_diff(T a, T b)
|
|||
}
|
||||
}
|
||||
|
||||
inline unsigned multiply_by_depth_ceil(unsigned pixels, unsigned depth)
|
||||
{
|
||||
if (depth == 1) {
|
||||
return (pixels / 8) + ((pixels % 8) ? 1 : 0);
|
||||
} else {
|
||||
return pixels * (depth / 8);
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* ASIC specific functions declarations */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
Ładowanie…
Reference in New Issue