Merge branch 'genesys-fix-warnings' into 'master'

genesys: Fix warnings not enabled in regular build

See merge request sane-project/backends!209
merge-requests/209/merge
Povilas Kanapickas 2019-10-12 15:43:04 +00:00
commit 9581f29f13
18 zmienionych plików z 162 dodań i 481 usunięć

Wyświetl plik

@ -74,14 +74,10 @@ public:
Genesys_Register_Set& regs) const = 0; Genesys_Register_Set& regs) const = 0;
virtual void init_regs_for_scan(Genesys_Device* dev, const Genesys_Sensor& sensor) const = 0; virtual void init_regs_for_scan(Genesys_Device* dev, const Genesys_Sensor& sensor) const = 0;
virtual bool get_filter_bit(Genesys_Register_Set * reg) const = 0;
virtual bool get_lineart_bit(Genesys_Register_Set * reg) const = 0;
virtual bool get_bitset_bit(Genesys_Register_Set * reg) const = 0; virtual bool get_bitset_bit(Genesys_Register_Set * reg) const = 0;
virtual bool get_gain4_bit(Genesys_Register_Set * reg) const = 0; virtual bool get_gain4_bit(Genesys_Register_Set * reg) const = 0;
virtual bool get_fast_feed_bit(Genesys_Register_Set * reg) const = 0;
virtual bool test_buffer_empty_bit(std::uint8_t val) const = 0; virtual bool test_buffer_empty_bit(std::uint8_t val) const = 0;
virtual bool test_motor_flag_bit(std::uint8_t val) const = 0;
virtual void set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t set) const = 0; virtual void set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t set) const = 0;
virtual void set_powersaving(Genesys_Device* dev, int delay) const = 0; virtual void set_powersaving(Genesys_Device* dev, int delay) const = 0;

Wyświetl plik

@ -81,11 +81,13 @@ struct SANE_Device_Data
std::string name; std::string name;
}; };
StaticInit<std::list<Genesys_Scanner>> s_scanners; namespace {
StaticInit<std::vector<SANE_Device>> s_sane_devices; StaticInit<std::list<Genesys_Scanner>> s_scanners;
StaticInit<std::vector<SANE_Device_Data>> s_sane_devices_data; StaticInit<std::vector<SANE_Device>> s_sane_devices;
StaticInit<std::vector<SANE_Device*>> s_sane_devices_ptrs; StaticInit<std::vector<SANE_Device_Data>> s_sane_devices_data;
StaticInit<std::list<Genesys_Device>> s_devices; StaticInit<std::vector<SANE_Device*>> s_sane_devices_ptrs;
StaticInit<std::list<Genesys_Device>> s_devices;
} // namespace
static SANE_String_Const mode_list[] = { static SANE_String_Const mode_list[] = {
SANE_VALUE_SCAN_MODE_COLOR, SANE_VALUE_SCAN_MODE_COLOR,
@ -368,7 +370,7 @@ SANE_Int sanei_genesys_generate_slope_table(std::vector<uint16_t>& slope_table,
t2 = vstart; t2 = vstart;
for (i = 0; i < steps && i < use_steps - 1 && i < max_steps; i++, c++) for (i = 0; i < steps && i < use_steps - 1 && i < max_steps; i++, c++)
{ {
t = pow (((double) i) / ((double) (steps - 1)), g); t = std::pow(static_cast<double>(i) / static_cast<double>(steps - 1), g);
t2 = vstart * (1 - t) + t * vend; t2 = vstart * (1 - t) + t * vend;
if (t2 < stop_at) { if (t2 < stop_at) {
break; break;
@ -580,7 +582,7 @@ SANE_Int genesys_create_slope_table2(Genesys_Device* dev, std::vector<uint16_t>&
{ {
for (i = 0; i < steps; i++) for (i = 0; i < steps; i++)
{ {
t = pow (((double) i) / ((double) (steps - 1)), g); t = std::pow(static_cast<double>(i) / static_cast<double>(steps - 1), g);
slope_table[i] = vstart * (1 - t) + t * vend; slope_table[i] = vstart * (1 - t) + t * vend;
DBG (DBG_io, "slope_table[%3d] = %5d\n", i, slope_table[i]); DBG (DBG_io, "slope_table[%3d] = %5d\n", i, slope_table[i]);
sum += slope_table[i]; sum += slope_table[i];
@ -629,8 +631,8 @@ SANE_Int sanei_genesys_create_slope_table(Genesys_Device * dev, std::vector<uint
same_step = 4; same_step = 4;
divider = 1 << step_type; divider = 1 << step_type;
time_period = time_period = static_cast<std::uint32_t>(yres * exposure_time /
(uint32_t) (yres * exposure_time / dev->motor.base_ydpi /*MOTOR_GEAR */ ); dev->motor.base_ydpi /*MOTOR_GEAR */ );
if ((time_period < 2000) && (same_speed)) if ((time_period < 2000) && (same_speed))
same_speed = false; same_speed = false;
@ -640,7 +642,7 @@ SANE_Int sanei_genesys_create_slope_table(Genesys_Device * dev, std::vector<uint
{ {
for (i = 0; i < steps; i++) for (i = 0; i < steps; i++)
{ {
slope_table[i] = (uint16_t) time_period; slope_table[i] = static_cast<std::uint16_t>(time_period);
sum_time += time_period; sum_time += time_period;
DBG (DBG_io, "slope_table[%d] = %d\n", i, time_period); DBG (DBG_io, "slope_table[%d] = %d\n", i, time_period);
@ -676,7 +678,7 @@ SANE_Int sanei_genesys_create_slope_table(Genesys_Device * dev, std::vector<uint
if (dev->model->motor_id == MotorId::ST24) { if (dev->model->motor_id == MotorId::ST24) {
steps = 255; steps = 255;
switch ((int) yres) switch (static_cast<int>(yres))
{ {
case 2400: case 2400:
g = 0.1672; g = 0.1672;
@ -711,9 +713,8 @@ SANE_Int sanei_genesys_create_slope_table(Genesys_Device * dev, std::vector<uint
if (steps <= same_step) if (steps <= same_step)
{ {
time_period = time_period = static_cast<std::uint32_t>(yres * exposure_time /
(uint32_t) (yres * exposure_time / dev->motor.base_ydpi /*MOTOR_GEAR */ );
dev->motor.base_ydpi /*MOTOR_GEAR */ );
time_period = time_period / divider; time_period = time_period / divider;
if (time_period > 65535) if (time_period > 65535)
@ -721,7 +722,7 @@ SANE_Int sanei_genesys_create_slope_table(Genesys_Device * dev, std::vector<uint
for (i = 0; i < same_step; i++) for (i = 0; i < same_step; i++)
{ {
slope_table[i] = (uint16_t) time_period; slope_table[i] = static_cast<std::uint16_t>(time_period);
sum_time += time_period; sum_time += time_period;
DBG (DBG_io, "slope_table[%d] = %d\n", i, time_period); DBG (DBG_io, "slope_table[%d] = %d\n", i, time_period);
@ -733,23 +734,25 @@ SANE_Int sanei_genesys_create_slope_table(Genesys_Device * dev, std::vector<uint
for (i = 0; i < steps; i++) for (i = 0; i < steps; i++)
{ {
double j = ((double) i) - same_step + 1; /* start from 1/16 speed */ double j = static_cast<double>(i) - same_step + 1; /* start from 1/16 speed */
if (j <= 0) if (j <= 0) {
t = 0; t = 0;
else } else {
t = pow (j / (steps - same_step), g); t = std::pow(j / (steps - same_step), g);
}
time_period = /* time required for full steps */ // time required for full steps
(uint32_t) (yres * exposure_time / time_period = static_cast<std::uint32_t>(yres * exposure_time /
dev->motor.base_ydpi /*MOTOR_GEAR */ * dev->motor.base_ydpi /*MOTOR_GEAR */ *
(start_speed + (1 - start_speed) * t)); (start_speed + (1 - start_speed) * t));
time_period = time_period / divider; time_period = time_period / divider;
if (time_period > 65535) if (time_period > 65535) {
time_period = 65535; time_period = 65535;
}
slope_table[i] = (uint16_t) time_period; slope_table[i] = static_cast<std::uint16_t>(time_period);
sum_time += time_period; sum_time += time_period;
DBG (DBG_io, "slope_table[%d] = %d\n", i, slope_table[i]); DBG (DBG_io, "slope_table[%d] = %d\n", i, slope_table[i]);
@ -838,113 +841,10 @@ sanei_genesys_exposure_time2 (Genesys_Device * dev, float ydpi,
exposure = exposure_by_led; exposure = exposure_by_led;
DBG(DBG_info, "%s: ydpi=%d, step=%d, endpixel=%d led=%d => exposure=%d\n", __func__, DBG(DBG_info, "%s: ydpi=%d, step=%d, endpixel=%d led=%d => exposure=%d\n", __func__,
(int)ydpi, step_type, endpixel, exposure_by_led, exposure); static_cast<int>(ydpi), step_type, endpixel, exposure_by_led, exposure);
return exposure; return exposure;
} }
/* computes the exposure_time on the basis of the given horizontal dpi */
/* we will clean/simplify it by using constants from a future motor struct */
SANE_Int
sanei_genesys_exposure_time (Genesys_Device * dev, Genesys_Register_Set * reg,
int xdpi)
{
if (dev->model->motor_id == MotorId::MD_5345) {
if (dev->cmd_set->get_filter_bit(reg)) {
/* monochrome */
switch (xdpi)
{
case 600:
return 8500;
case 500:
case 400:
case 300:
case 250:
case 200:
case 150:
return 5500;
case 100:
return 6500;
case 50:
return 12000;
default:
return 11000;
}
}
else
{
/* color scan */
switch (xdpi)
{
case 300:
case 250:
case 200:
return 5500;
case 50:
return 12000;
default:
return 11000;
}
}
} else if (dev->model->motor_id == MotorId::HP2400) {
if (dev->cmd_set->get_filter_bit(reg)) {
/* monochrome */
switch (xdpi)
{
case 200:
return 7210;
default:
return 11111;
}
}
else
{
/* color scan */
switch (xdpi)
{
case 600:
return 8751; /*11902; 19200 */
default:
return 11111;
}
}
} else if (dev->model->motor_id == MotorId::HP2300) {
if (dev->cmd_set->get_filter_bit(reg)) {
/* monochrome */
switch (xdpi)
{
case 600:
return 8699; /* 3200; */
case 300:
return 3200; /*10000;, 3200 -> too dark */
case 150:
return 4480; /* 3200 ???, warmup needs 4480 */
case 75:
return 5500;
default:
return 11111;
}
}
else
{
/* color scan */
switch (xdpi)
{
case 600:
return 8699;
case 300:
return 4349;
case 150:
case 75:
return 4480;
default:
return 11111;
}
}
}
return 11000;
}
/* Sends a block of shading information to the scanner. /* Sends a block of shading information to the scanner.
The data is placed at address 0x0000 for color mode, gray mode and The data is placed at address 0x0000 for color mode, gray mode and
@ -1285,7 +1185,7 @@ static uint8_t genesys_adjust_gain(double* applied_multi, double multi, uint8_t
voltage *= multi; voltage *= multi;
new_gain = (uint8_t) ((voltage - 0.5) * 4); new_gain = static_cast<std::uint8_t>((voltage - 0.5) * 4);
if (new_gain > 0x0e) if (new_gain > 0x0e)
new_gain = 0x0e; new_gain = 0x0e;
@ -1384,7 +1284,7 @@ genesys_average_black (Genesys_Device * dev, int channel,
DBG(DBG_proc, "%s = %d\n", __func__, sum / pixels); DBG(DBG_proc, "%s = %d\n", __func__, sum / pixels);
return (int) (sum / pixels); return sum / pixels;
} }
@ -1476,8 +1376,7 @@ static void genesys_coarse_calibration(Genesys_Device* dev, Genesys_Sensor& sens
for (j = 0; j < 3; j++) for (j = 0; j < 3; j++)
{ {
x = x = static_cast<double>(dark[(i - 2) * 3 + j] -
(double) (dark[(i - 2) * 3 + j] -
dark[(i - 1) * 3 + j]) * 254 / (offset[i - 1] / 2 - dark[(i - 1) * 3 + j]) * 254 / (offset[i - 1] / 2 -
offset[i - 2] / 2); offset[i - 2] / 2);
y = x - x * (offset[i - 1] / 2) / 254 - dark[(i - 1) * 3 + j]; y = x - x * (offset[i - 1] / 2) / 254 - dark[(i - 1) * 3 + j];
@ -1516,8 +1415,9 @@ static void genesys_coarse_calibration(Genesys_Device* dev, Genesys_Sensor& sens
std::vector<uint8_t> all_data_8(size * 4 / 2); std::vector<uint8_t> all_data_8(size * 4 / 2);
unsigned int count; unsigned int count;
for (count = 0; count < (unsigned int) (size * 4 / 2); count++) for (count = 0; count < static_cast<unsigned>(size * 4 / 2); count++) {
all_data_8[count] = all_data[count * 2 + 1]; all_data_8[count] = all_data[count * 2 + 1];
}
sanei_genesys_write_pnm_file("gl_coarse.pnm", all_data_8.data(), 8, channels, size / 6, 4); sanei_genesys_write_pnm_file("gl_coarse.pnm", all_data_8.data(), 8, channels, size / 6, 4);
} }
@ -1804,12 +1704,11 @@ static void genesys_white_shading_calibration(Genesys_Device* dev, const Genesys
static void genesys_dark_white_shading_calibration(Genesys_Device* dev, static void genesys_dark_white_shading_calibration(Genesys_Device* dev,
const Genesys_Sensor& sensor) const Genesys_Sensor& sensor)
{ {
DBG_HELPER_ARGS(dbg, "lines = %d", (unsigned int)dev->calib_lines); DBG_HELPER_ARGS(dbg, "lines = %zu", dev->calib_lines);
size_t size; size_t size;
uint32_t pixels_per_line; uint32_t pixels_per_line;
uint8_t channels; uint8_t channels;
unsigned int x; unsigned int x;
int y;
uint32_t dark, white, dark_sum, white_sum, dark_count, white_count, col, uint32_t dark, white, dark_sum, white_sum, dark_count, white_count, col,
dif; dif;
@ -1881,7 +1780,7 @@ static void genesys_dark_white_shading_calibration(Genesys_Device* dev,
dark = 0xffff; dark = 0xffff;
white = 0; white = 0;
for (y = 0; y < (int)dev->calib_lines; y++) for (std::size_t y = 0; y < dev->calib_lines; y++)
{ {
col = calibration_data[(x + y * pixels_per_line * channels) * 2]; col = calibration_data[(x + y * pixels_per_line * channels) * 2];
col |= col |=
@ -1905,7 +1804,7 @@ static void genesys_dark_white_shading_calibration(Genesys_Device* dev,
white_count = 0; white_count = 0;
white_sum = 0; white_sum = 0;
for (y = 0; y < (int)dev->calib_lines; y++) for (std::size_t y = 0; y < dev->calib_lines; y++)
{ {
col = calibration_data[(x + y * pixels_per_line * channels) * 2]; col = calibration_data[(x + y * pixels_per_line * channels) * 2];
col |= col |=
@ -3308,18 +3207,8 @@ static void genesys_start_scan(Genesys_Device* dev, bool lamp_off)
wait_until_buffer_non_empty(dev); wait_until_buffer_non_empty(dev);
/* when doing one or two-table movement, let the motor settle to scanning speed */ // we wait for at least one word of valid scan data
/* and scanning start before reading data */ // this is also done in sanei_genesys_read_data_from_scanner -- pierre
/* the valid data check already waits until the scanner delivers data. this here leads to unnecessary buffer full conditions in the scanner.
if (dev->cmd_set->get_fast_feed_bit (dev->reg)) {
sanei_genesys_sleep_ms(1000);
} else {
sanei_genesys_sleep_ms(500);
}
*/
/* then we wait for at least one word of valid scan data
this is also done in sanei_genesys_read_data_from_scanner -- pierre */
if (!dev->model->is_sheetfed) { if (!dev->model->is_sheetfed) {
do do
{ {
@ -3377,10 +3266,10 @@ static void genesys_read_ordered_data(Genesys_Device* dev, SANE_Byte* destinatio
debug_dump(DBG_info, dev->current_setup); debug_dump(DBG_info, dev->current_setup);
debug_dump(DBG_info, dev->session.params); debug_dump(DBG_info, dev->session.params);
DBG(DBG_info, "%s: frontend requested %lu bytes\n", __func__, (u_long) * len); DBG(DBG_info, "%s: frontend requested %zu bytes\n", __func__, *len);
DBG(DBG_info, "%s: bytes_to_read=%zu, total_bytes_read=%zu\n", __func__,
dev->total_bytes_to_read, dev->total_bytes_read);
DBG(DBG_info, "%s: bytes_to_read=%lu, total_bytes_read=%lu\n", __func__,
(u_long) dev->total_bytes_to_read, (u_long) dev->total_bytes_read);
/* is there data left to scan */ /* is there data left to scan */
if (dev->total_bytes_read >= dev->total_bytes_to_read) if (dev->total_bytes_read >= dev->total_bytes_to_read)
{ {
@ -3461,7 +3350,7 @@ Problems with the first approach:
} }
} }
DBG(DBG_proc, "%s: completed, %lu bytes read\n", __func__, (u_long) bytes); DBG(DBG_proc, "%s: completed, %zu bytes read\n", __func__, bytes);
} }
@ -3786,7 +3675,6 @@ static std::string calibration_filename(Genesys_Device *currdev)
std::string ret; std::string ret;
ret.resize(PATH_MAX); ret.resize(PATH_MAX);
char *ptr;
char filename[80]; char filename[80];
unsigned int count; unsigned int count;
unsigned int i; unsigned int i;
@ -3799,15 +3687,15 @@ static std::string calibration_filename(Genesys_Device *currdev)
* 5 - temp dir * 5 - temp dir
* 6 - then resort to current dir * 6 - then resort to current dir
*/ */
ptr = getenv ("HOME"); char* ptr = std::getenv("HOME");
if (ptr == nullptr) { if (ptr == nullptr) {
ptr = getenv ("USERPROFILE"); ptr = std::getenv("USERPROFILE");
} }
if (ptr == nullptr) { if (ptr == nullptr) {
ptr = getenv ("TMPDIR"); ptr = std::getenv("TMPDIR");
} }
if (ptr == nullptr) { if (ptr == nullptr) {
ptr = getenv ("TMP"); ptr = std::getenv("TMP");
} }
/* now choose filename: /* now choose filename:
@ -3955,7 +3843,7 @@ static void init_options(Genesys_Scanner* s)
unsigned min_dpi = *std::min_element(resolutions.begin(), resolutions.end()); unsigned min_dpi = *std::min_element(resolutions.begin(), resolutions.end());
dpi_list = (SANE_Word*) malloc((resolutions.size() + 1) * sizeof(SANE_Word)); dpi_list = reinterpret_cast<SANE_Word*>(std::malloc((resolutions.size() + 1) * sizeof(SANE_Word)));
if (!dpi_list) { if (!dpi_list) {
throw SaneException(SANE_STATUS_NO_MEM); throw SaneException(SANE_STATUS_NO_MEM);
} }
@ -4619,7 +4507,7 @@ probe_genesys_devices (void)
status = sanei_configure_attach (GENESYS_CONFIG_FILE, &config, status = sanei_configure_attach (GENESYS_CONFIG_FILE, &config,
config_attach_genesys); config_attach_genesys);
DBG(DBG_info, "%s: %d devices currently attached\n", __func__, (int) s_devices->size()); DBG(DBG_info, "%s: %zu devices currently attached\n", __func__, s_devices->size());
return status; return status;
} }
@ -4814,8 +4702,7 @@ sane_init_impl(SANE_Int * version_code, SANE_Auth_Callback authorize)
{ {
DBG_INIT (); DBG_INIT ();
DBG_HELPER_ARGS(dbg, "authorize %s null", authorize ? "!=" : "=="); DBG_HELPER_ARGS(dbg, "authorize %s null", authorize ? "!=" : "==");
DBG(DBG_init, "SANE Genesys backend version %d.%d from %s\n", DBG(DBG_init, "SANE Genesys backend from %s\n", PACKAGE_STRING);
SANE_CURRENT_MAJOR, V_MINOR, PACKAGE_STRING);
#ifdef HAVE_LIBUSB #ifdef HAVE_LIBUSB
DBG(DBG_init, "SANE Genesys backend built with libusb-1.0\n"); DBG(DBG_init, "SANE Genesys backend built with libusb-1.0\n");
#endif #endif
@ -4823,8 +4710,9 @@ sane_init_impl(SANE_Int * version_code, SANE_Auth_Callback authorize)
DBG(DBG_init, "SANE Genesys backend built with libusb\n"); DBG(DBG_init, "SANE Genesys backend built with libusb\n");
#endif #endif
if (version_code) if (version_code) {
*version_code = SANE_VERSION_CODE (SANE_CURRENT_MAJOR, V_MINOR, 0); *version_code = SANE_VERSION_CODE(SANE_CURRENT_MAJOR, SANE_CURRENT_MINOR, 0);
}
/* init usb use */ /* init usb use */
sanei_usb_init (); sanei_usb_init ();
@ -4917,7 +4805,7 @@ sane_get_devices_impl(const SANE_Device *** device_list, SANE_Bool local_only)
} }
s_sane_devices_ptrs->push_back(nullptr); s_sane_devices_ptrs->push_back(nullptr);
*((SANE_Device ***)device_list) = s_sane_devices_ptrs->data(); *const_cast<SANE_Device***>(device_list) = s_sane_devices_ptrs->data();
return SANE_STATUS_GOOD; return SANE_STATUS_GOOD;
} }
@ -5089,9 +4977,9 @@ sane_close_impl(SANE_Handle handle)
s->dev->already_initialized = false; s->dev->already_initialized = false;
/* for an handful of bytes .. */ /* for an handful of bytes .. */
free ((void *)(size_t)s->opt[OPT_RESOLUTION].constraint.word_list); std::free(reinterpret_cast<void*>(const_cast<SANE_Word*>(s->opt[OPT_RESOLUTION].constraint.word_list)));
free ((void *)(size_t)s->opt[OPT_TL_X].constraint.range); std::free(reinterpret_cast<void*>(const_cast<SANE_Range*>(s->opt[OPT_TL_X].constraint.range)));
free ((void *)(size_t)s->opt[OPT_TL_Y].constraint.range); std::free(reinterpret_cast<void*>(const_cast<SANE_Range*>(s->opt[OPT_TL_Y].constraint.range)));
s->dev->clear(); s->dev->clear();
@ -5120,10 +5008,12 @@ void sane_close(SANE_Handle handle)
const SANE_Option_Descriptor * const SANE_Option_Descriptor *
sane_get_option_descriptor_impl(SANE_Handle handle, SANE_Int option) sane_get_option_descriptor_impl(SANE_Handle handle, SANE_Int option)
{ {
Genesys_Scanner *s = (Genesys_Scanner*) handle; Genesys_Scanner* s = reinterpret_cast<Genesys_Scanner*>(handle);
if (static_cast<unsigned>(option) >= NUM_OPTIONS) {
return nullptr;
}
if ((unsigned) option >= NUM_OPTIONS)
return 0;
DBG(DBG_io2, "%s: option = %s (%d)\n", __func__, s->opt[option].name, option); DBG(DBG_io2, "%s: option = %s (%d)\n", __func__, s->opt[option].name, option);
return s->opt + option; return s->opt + option;
} }
@ -5256,7 +5146,7 @@ get_option_value (Genesys_Scanner * s, int option, void *val)
if (!sensor) if (!sensor)
throw SaneException("Unsupported scanner mode selected"); throw SaneException("Unsupported scanner mode selected");
table = (SANE_Word *) val; table = reinterpret_cast<SANE_Word*>(val);
if (s->color_filter == "Red") { if (s->color_filter == "Red") {
gamma_table = get_gamma_table(s->dev, *sensor, GENESYS_RED); gamma_table = get_gamma_table(s->dev, *sensor, GENESYS_RED);
} else if (s->color_filter == "Blue") { } else if (s->color_filter == "Blue") {
@ -5276,7 +5166,7 @@ get_option_value (Genesys_Scanner * s, int option, void *val)
if (!sensor) if (!sensor)
throw SaneException("Unsupported scanner mode selected"); throw SaneException("Unsupported scanner mode selected");
table = (SANE_Word *) val; table = reinterpret_cast<SANE_Word*>(val);
gamma_table = get_gamma_table(s->dev, *sensor, GENESYS_RED); gamma_table = get_gamma_table(s->dev, *sensor, GENESYS_RED);
option_size = s->opt[option].size / sizeof (SANE_Word); option_size = s->opt[option].size / sizeof (SANE_Word);
if (gamma_table.size() != option_size) { if (gamma_table.size() != option_size) {
@ -5290,7 +5180,7 @@ get_option_value (Genesys_Scanner * s, int option, void *val)
if (!sensor) if (!sensor)
throw SaneException("Unsupported scanner mode selected"); throw SaneException("Unsupported scanner mode selected");
table = (SANE_Word *) val; table = reinterpret_cast<SANE_Word*>(val);
gamma_table = get_gamma_table(s->dev, *sensor, GENESYS_GREEN); gamma_table = get_gamma_table(s->dev, *sensor, GENESYS_GREEN);
option_size = s->opt[option].size / sizeof (SANE_Word); option_size = s->opt[option].size / sizeof (SANE_Word);
if (gamma_table.size() != option_size) { if (gamma_table.size() != option_size) {
@ -5304,7 +5194,7 @@ get_option_value (Genesys_Scanner * s, int option, void *val)
if (!sensor) if (!sensor)
throw SaneException("Unsupported scanner mode selected"); throw SaneException("Unsupported scanner mode selected");
table = (SANE_Word *) val; table = reinterpret_cast<SANE_Word*>(val);
gamma_table = get_gamma_table(s->dev, *sensor, GENESYS_BLUE); gamma_table = get_gamma_table(s->dev, *sensor, GENESYS_BLUE);
option_size = s->opt[option].size / sizeof (SANE_Word); option_size = s->opt[option].size / sizeof (SANE_Word);
if (gamma_table.size() != option_size) { if (gamma_table.size() != option_size) {
@ -5324,7 +5214,7 @@ get_option_value (Genesys_Scanner * s, int option, void *val)
case OPT_POWER_SW: case OPT_POWER_SW:
case OPT_EXTRA_SW: case OPT_EXTRA_SW:
s->dev->cmd_set->update_hardware_sensors(s); s->dev->cmd_set->update_hardware_sensors(s);
*(SANE_Bool *) val = s->buttons[genesys_option_to_button(option)].read(); *reinterpret_cast<SANE_Bool*>(val) = s->buttons[genesys_option_to_button(option)].read();
break; break;
case OPT_NEED_CALIBRATION_SW: case OPT_NEED_CALIBRATION_SW:
if (!sensor) if (!sensor)
@ -5332,11 +5222,11 @@ get_option_value (Genesys_Scanner * s, int option, void *val)
/* scanner needs calibration for current mode unless a matching /* scanner needs calibration for current mode unless a matching
* calibration cache is found */ * calibration cache is found */
*(SANE_Bool *) val = SANE_TRUE; *reinterpret_cast<SANE_Bool*>(val) = SANE_TRUE;
for (auto& cache : s->dev->calibration_cache) for (auto& cache : s->dev->calibration_cache)
{ {
if (s->dev->cmd_set->is_compatible_calibration(s->dev, *sensor, &cache, false)) { if (s->dev->cmd_set->is_compatible_calibration(s->dev, *sensor, &cache, false)) {
*(SANE_Bool *) val = SANE_FALSE; *reinterpret_cast<SANE_Bool*>(val) = SANE_FALSE;
} }
} }
break; break;
@ -5534,8 +5424,8 @@ set_option_value (Genesys_Scanner * s, int option, void *val,
} }
/* assign new values */ /* assign new values */
free((void *)(size_t)s->opt[OPT_TL_X].constraint.range); std::free(reinterpret_cast<void*>(const_cast<SANE_Range*>(s->opt[OPT_TL_X].constraint.range)));
free((void *)(size_t)s->opt[OPT_TL_Y].constraint.range); std::free(reinterpret_cast<void*>(const_cast<SANE_Range*>(s->opt[OPT_TL_Y].constraint.range)));
s->opt[OPT_TL_X].constraint.range = x_range; s->opt[OPT_TL_X].constraint.range = x_range;
s->pos_top_left_x = 0; s->pos_top_left_x = 0;
s->opt[OPT_TL_Y].constraint.range = y_range; s->opt[OPT_TL_Y].constraint.range = y_range;
@ -5661,7 +5551,7 @@ set_option_value (Genesys_Scanner * s, int option, void *val,
break; break;
case OPT_GAMMA_VECTOR: case OPT_GAMMA_VECTOR:
table = (SANE_Word *) val; table = reinterpret_cast<SANE_Word*>(val);
option_size = s->opt[option].size / sizeof (SANE_Word); option_size = s->opt[option].size / sizeof (SANE_Word);
s->dev->gamma_override_tables[GENESYS_RED].resize(option_size); s->dev->gamma_override_tables[GENESYS_RED].resize(option_size);
@ -5674,7 +5564,7 @@ set_option_value (Genesys_Scanner * s, int option, void *val,
} }
break; break;
case OPT_GAMMA_VECTOR_R: case OPT_GAMMA_VECTOR_R:
table = (SANE_Word *) val; table = reinterpret_cast<SANE_Word*>(val);
option_size = s->opt[option].size / sizeof (SANE_Word); option_size = s->opt[option].size / sizeof (SANE_Word);
s->dev->gamma_override_tables[GENESYS_RED].resize(option_size); s->dev->gamma_override_tables[GENESYS_RED].resize(option_size);
for (i = 0; i < option_size; i++) { for (i = 0; i < option_size; i++) {
@ -5682,7 +5572,7 @@ set_option_value (Genesys_Scanner * s, int option, void *val,
} }
break; break;
case OPT_GAMMA_VECTOR_G: case OPT_GAMMA_VECTOR_G:
table = (SANE_Word *) val; table = reinterpret_cast<SANE_Word*>(val);
option_size = s->opt[option].size / sizeof (SANE_Word); option_size = s->opt[option].size / sizeof (SANE_Word);
s->dev->gamma_override_tables[GENESYS_GREEN].resize(option_size); s->dev->gamma_override_tables[GENESYS_GREEN].resize(option_size);
for (i = 0; i < option_size; i++) { for (i = 0; i < option_size; i++) {
@ -5690,7 +5580,7 @@ set_option_value (Genesys_Scanner * s, int option, void *val,
} }
break; break;
case OPT_GAMMA_VECTOR_B: case OPT_GAMMA_VECTOR_B:
table = (SANE_Word *) val; table = reinterpret_cast<SANE_Word*>(val);
option_size = s->opt[option].size / sizeof (SANE_Word); option_size = s->opt[option].size / sizeof (SANE_Word);
s->dev->gamma_override_tables[GENESYS_BLUE].resize(option_size); s->dev->gamma_override_tables[GENESYS_BLUE].resize(option_size);
for (i = 0; i < option_size; i++) { for (i = 0; i < option_size; i++) {
@ -5746,7 +5636,7 @@ SANE_Status
sane_control_option_impl(SANE_Handle handle, SANE_Int option, sane_control_option_impl(SANE_Handle handle, SANE_Int option,
SANE_Action action, void *val, SANE_Int * info) SANE_Action action, void *val, SANE_Int * info)
{ {
Genesys_Scanner *s = (Genesys_Scanner*) handle; Genesys_Scanner* s = reinterpret_cast<Genesys_Scanner*>(handle);
auto action_str = (action == SANE_ACTION_GET_VALUE) ? "get" : auto action_str = (action == SANE_ACTION_GET_VALUE) ? "get" :
(action == SANE_ACTION_SET_VALUE) ? "set" : (action == SANE_ACTION_SET_VALUE) ? "set" :
(action == SANE_ACTION_SET_AUTO) ? "set_auto" : "unknown"; (action == SANE_ACTION_SET_AUTO) ? "set_auto" : "unknown";
@ -5836,7 +5726,7 @@ SANE_Status sane_control_option(SANE_Handle handle, SANE_Int option,
SANE_Status sane_get_parameters_impl(SANE_Handle handle, SANE_Parameters* params) SANE_Status sane_get_parameters_impl(SANE_Handle handle, SANE_Parameters* params)
{ {
DBG_HELPER(dbg); DBG_HELPER(dbg);
Genesys_Scanner *s = (Genesys_Scanner*) handle; Genesys_Scanner* s = reinterpret_cast<Genesys_Scanner*>(handle);
/* don't recompute parameters once data reading is active, ie during scan */ /* don't recompute parameters once data reading is active, ie during scan */
if (!s->dev->read_active) { if (!s->dev->read_active) {
@ -5872,7 +5762,7 @@ SANE_Status sane_get_parameters(SANE_Handle handle, SANE_Parameters* params)
SANE_Status sane_start_impl(SANE_Handle handle) SANE_Status sane_start_impl(SANE_Handle handle)
{ {
DBG_HELPER(dbg); DBG_HELPER(dbg);
Genesys_Scanner *s = (Genesys_Scanner*) handle; Genesys_Scanner* s = reinterpret_cast<Genesys_Scanner*>(handle);
SANE_Status status=SANE_STATUS_GOOD; SANE_Status status=SANE_STATUS_GOOD;
if (s->pos_top_left_x >= s->pos_bottom_right_x) if (s->pos_top_left_x >= s->pos_bottom_right_x)
@ -5961,7 +5851,7 @@ SANE_Status
sane_read_impl(SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, SANE_Int* len) sane_read_impl(SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, SANE_Int* len)
{ {
DBG_HELPER(dbg); DBG_HELPER(dbg);
Genesys_Scanner *s = (Genesys_Scanner*) handle; Genesys_Scanner* s = reinterpret_cast<Genesys_Scanner*>(handle);
Genesys_Device *dev; Genesys_Device *dev;
size_t local_len; size_t local_len;
@ -5999,8 +5889,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_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__, DBG(DBG_io2, "%s: bytes_to_read=%zu, total_bytes_read=%zu\n", __func__,
(u_long) dev->total_bytes_to_read, (u_long) dev->total_bytes_read); dev->total_bytes_to_read, dev->total_bytes_read);
if(dev->total_bytes_read>=dev->total_bytes_to_read) if(dev->total_bytes_read>=dev->total_bytes_to_read)
{ {
@ -6047,7 +5937,7 @@ sane_read_impl(SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, SANE_Int*
/* return data from lineart buffer if any, up to the available amount */ /* return data from lineart buffer if any, up to the available amount */
local_len = max_len; local_len = max_len;
if((size_t)max_len>dev->binarize_buffer.avail()) if (static_cast<std::size_t>(max_len) > dev->binarize_buffer.avail())
{ {
local_len=dev->binarize_buffer.avail(); local_len=dev->binarize_buffer.avail();
} }
@ -6074,8 +5964,7 @@ sane_read_impl(SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, SANE_Int*
} }
*len = local_len; *len = local_len;
if(local_len>(size_t)max_len) if (local_len > static_cast<std::size_t>(max_len)) {
{
fprintf (stderr, "[genesys] sane_read: returning incorrect length!!\n"); fprintf (stderr, "[genesys] sane_read: returning incorrect length!!\n");
} }
DBG(DBG_proc, "%s: %d bytes returned\n", __func__, *len); DBG(DBG_proc, "%s: %d bytes returned\n", __func__, *len);
@ -6093,7 +5982,7 @@ SANE_Status sane_read(SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, SAN
void sane_cancel_impl(SANE_Handle handle) void sane_cancel_impl(SANE_Handle handle)
{ {
DBG_HELPER(dbg); DBG_HELPER(dbg);
Genesys_Scanner *s = (Genesys_Scanner*) handle; Genesys_Scanner* s = reinterpret_cast<Genesys_Scanner*>(handle);
// end binary logging if needed // end binary logging if needed
if (s->dev->binary != nullptr) { if (s->dev->binary != nullptr) {
@ -6142,7 +6031,7 @@ sane_set_io_mode_impl(SANE_Handle handle, SANE_Bool non_blocking)
{ {
DBG_HELPER_ARGS(dbg, "handle = %p, non_blocking = %s", handle, DBG_HELPER_ARGS(dbg, "handle = %p, non_blocking = %s", handle,
non_blocking == SANE_TRUE ? "true" : "false"); non_blocking == SANE_TRUE ? "true" : "false");
Genesys_Scanner *s = (Genesys_Scanner*) handle; Genesys_Scanner* s = reinterpret_cast<Genesys_Scanner*>(handle);
if (!s->scanning) if (!s->scanning)
{ {
@ -6166,7 +6055,7 @@ sane_set_io_mode(SANE_Handle handle, SANE_Bool non_blocking)
SANE_Status SANE_Status
sane_get_select_fd_impl(SANE_Handle handle, SANE_Int * fd) sane_get_select_fd_impl(SANE_Handle handle, SANE_Int * fd)
{ {
DBG_HELPER_ARGS(dbg, "handle = %p, fd = %p", handle, (void *) fd); DBG_HELPER_ARGS(dbg, "handle = %p, fd = %p", handle, reinterpret_cast<void*>(fd));
Genesys_Scanner *s = (Genesys_Scanner*) handle; Genesys_Scanner *s = (Genesys_Scanner*) handle;
if (!s->scanning) if (!s->scanning)

Wyświetl plik

@ -49,33 +49,14 @@
#include <vector> #include <vector>
/****************************************************************************
Mid level functions
****************************************************************************/
bool CommandSetGl124::get_fast_feed_bit(Genesys_Register_Set* regs) const
{
return (bool)(regs->get8(REG02) & REG02_FASTFED);
}
bool CommandSetGl124::get_filter_bit(Genesys_Register_Set* regs) const
{
return (bool)(regs->get8(REG04) & REG04_FILTER);
}
bool CommandSetGl124::get_lineart_bit(Genesys_Register_Set* regs) const
{
return (bool)(regs->get8(REG04) & REG04_LINEART);
}
bool CommandSetGl124::get_bitset_bit(Genesys_Register_Set* regs) const bool CommandSetGl124::get_bitset_bit(Genesys_Register_Set* regs) const
{ {
return (bool)(regs->get8(REG04) & REG04_BITSET); return static_cast<bool>(regs->get8(REG04) & REG04_BITSET);
} }
bool CommandSetGl124::get_gain4_bit(Genesys_Register_Set* regs) const bool CommandSetGl124::get_gain4_bit(Genesys_Register_Set* regs) const
{ {
return (bool)(regs->get8(REG06) & REG06_GAIN4); return static_cast<bool>(regs->get8(REG06) & REG06_GAIN4);
} }
bool CommandSetGl124::test_buffer_empty_bit(SANE_Byte val) const bool CommandSetGl124::test_buffer_empty_bit(SANE_Byte val) const
@ -83,11 +64,6 @@ bool CommandSetGl124::test_buffer_empty_bit(SANE_Byte val) const
return (val & BUFEMPTY); return (val & BUFEMPTY);
} }
bool CommandSetGl124::test_motor_flag_bit(SANE_Byte val) const
{
return (val & MOTORENB);
}
static void gl124_homsnr_gpio(Genesys_Device* dev) static void gl124_homsnr_gpio(Genesys_Device* dev)
{ {
DBG_HELPER(dbg); DBG_HELPER(dbg);
@ -1029,8 +1005,8 @@ static void gl124_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens
dev->total_bytes_read = 0; dev->total_bytes_read = 0;
dev->total_bytes_to_read = session.output_line_bytes_requested * session.params.lines; dev->total_bytes_to_read = session.output_line_bytes_requested * session.params.lines;
DBG(DBG_info, "%s: total bytes to send to frontend = %lu\n", __func__, DBG(DBG_info, "%s: total bytes to send to frontend = %zu\n", __func__,
(u_long) dev->total_bytes_to_read); dev->total_bytes_to_read);
} }
void CommandSetGl124::calculate_current_setup(Genesys_Device * dev, void CommandSetGl124::calculate_current_setup(Genesys_Device * dev,
@ -1777,7 +1753,7 @@ void CommandSetGl124::send_shading_data(Genesys_Device* dev, const Genesys_Senso
uint8_t *ptr, *src; uint8_t *ptr, *src;
/* logical size of a color as seen by generic code of the frontend */ /* logical size of a color as seen by generic code of the frontend */
length = (uint32_t) (size / 3); length = size / 3;
std::uint32_t strpixel = dev->session.pixel_startx; std::uint32_t strpixel = dev->session.pixel_startx;
std::uint32_t endpixel = dev->session.pixel_endx; std::uint32_t endpixel = dev->session.pixel_endx;
segcnt = dev->reg.get24(REG_SEGCNT); segcnt = dev->reg.get24(REG_SEGCNT);
@ -2362,7 +2338,7 @@ void CommandSetGl124::coarse_gain_calibration(Genesys_Device* dev, const Genesys
} }
max[j] = max[j] / (pixels/2); max[j] = max[j] / (pixels/2);
gain[j] = ((float) sensor.gain_white_ref*coeff) / max[j]; gain[j] = (static_cast<float>(sensor.gain_white_ref) * coeff) / max[j];
/* turn logical gain value into gain code, checking for overflow */ /* turn logical gain value into gain code, checking for overflow */
code = 283 - 208 / gain[j]; code = 283 - 208 / gain[j];

Wyświetl plik

@ -142,14 +142,10 @@ public:
void init_regs_for_scan(Genesys_Device* dev, const Genesys_Sensor& sensor) const override; void init_regs_for_scan(Genesys_Device* dev, const Genesys_Sensor& sensor) const override;
bool get_filter_bit(Genesys_Register_Set * reg) const override;
bool get_lineart_bit(Genesys_Register_Set * reg) const override;
bool get_bitset_bit(Genesys_Register_Set * reg) const override; bool get_bitset_bit(Genesys_Register_Set * reg) const override;
bool get_gain4_bit(Genesys_Register_Set * reg) const override; bool get_gain4_bit(Genesys_Register_Set * reg) const override;
bool get_fast_feed_bit(Genesys_Register_Set * reg) const override;
bool test_buffer_empty_bit(std::uint8_t val) const override; bool test_buffer_empty_bit(std::uint8_t val) const override;
bool test_motor_flag_bit(std::uint8_t val) const override;
void set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t set) const override; void set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t set) const override;
void set_powersaving(Genesys_Device* dev, int delay) const override; void set_powersaving(Genesys_Device* dev, int delay) const override;

Wyświetl plik

@ -93,24 +93,6 @@ void CommandSetGl646::bulk_read_data(Genesys_Device* dev, uint8_t addr, uint8_t*
} }
} }
bool CommandSetGl646::get_fast_feed_bit(Genesys_Register_Set* regs) const
{
GenesysRegister *r = sanei_genesys_get_address(regs, 0x02);
return (r && (r->value & REG02_FASTFED));
}
bool CommandSetGl646::get_filter_bit(Genesys_Register_Set* regs) const
{
GenesysRegister *r = sanei_genesys_get_address(regs, 0x04);
return (r && (r->value & REG04_FILTER));
}
bool CommandSetGl646::get_lineart_bit(Genesys_Register_Set* regs) const
{
GenesysRegister *r = sanei_genesys_get_address(regs, 0x04);
return (r && (r->value & REG04_LINEART));
}
bool CommandSetGl646::get_bitset_bit(Genesys_Register_Set* regs) const bool CommandSetGl646::get_bitset_bit(Genesys_Register_Set* regs) const
{ {
GenesysRegister *r = sanei_genesys_get_address(regs, 0x04); GenesysRegister *r = sanei_genesys_get_address(regs, 0x04);
@ -128,11 +110,6 @@ bool CommandSetGl646::test_buffer_empty_bit(SANE_Byte val) const
return (val & REG41_BUFEMPTY); return (val & REG41_BUFEMPTY);
} }
bool CommandSetGl646::test_motor_flag_bit(SANE_Byte val) const
{
return (val & REG41_MOTMFLG);
}
/** /**
* decodes and prints content of status (0x41) register * decodes and prints content of status (0x41) register
* @param val value read from reg41 * @param val value read from reg41
@ -1227,10 +1204,9 @@ void CommandSetGl646::set_powersaving(Genesys_Device* dev, int delay /* in minut
local_reg.find_reg(0x03).value = (local_reg.get8(0x03) & 0xf0) | 0x0f; /* enable lampdog and set lamptime = 7 */ local_reg.find_reg(0x03).value = (local_reg.get8(0x03) & 0xf0) | 0x0f; /* enable lampdog and set lamptime = 7 */
time = delay * 1000 * 60; /* -> msec */ time = delay * 1000 * 60; /* -> msec */
exposure_time = exposure_time = static_cast<std::uint32_t>((time * 32000.0 /
(uint32_t) (time * 32000.0 /
(24.0 * 64.0 * (local_reg.get8(0x03) & REG03_LAMPTIM) * (24.0 * 64.0 * (local_reg.get8(0x03) & REG03_LAMPTIM) *
1024.0) + 0.5); 1024.0) + 0.5));
/* 32000 = system clock, 24 = clocks per pixel */ /* 32000 = system clock, 24 = clocks per pixel */
rate = (exposure_time + 65536) / 65536; rate = (exposure_time + 65536) / 65536;
if (rate > 4) if (rate > 4)
@ -1415,8 +1391,8 @@ void CommandSetGl646::detect_document_end(Genesys_Device* dev) const
* total_bytes_read is the number of bytes sent 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 * read_bytes_left is the number of bytes to read from the scanner
*/ */
DBG(DBG_io, "%s: total_bytes_to_read=%lu\n", __func__, (u_long) dev->total_bytes_to_read); DBG(DBG_io, "%s: total_bytes_to_read=%zu\n", __func__, 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: total_bytes_read =%zu\n", __func__, dev->total_bytes_read);
// amount of data available from scanner is what to scan // amount of data available from scanner is what to scan
sanei_genesys_read_valid_words(dev, &bytes_left); sanei_genesys_read_valid_words(dev, &bytes_left);
@ -1435,8 +1411,8 @@ void CommandSetGl646::detect_document_end(Genesys_Device* dev) const
dev->get_pipeline_source().set_remaining_bytes(bytes_left); dev->get_pipeline_source().set_remaining_bytes(bytes_left);
dev->total_bytes_to_read = dev->total_bytes_read + bytes_left; dev->total_bytes_to_read = dev->total_bytes_read + 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_to_read=%zu\n", __func__, 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: total_bytes_read =%zu\n", __func__, dev->total_bytes_read);
} }
} }
@ -2386,7 +2362,7 @@ static void ad_fe_offset_calibration(Genesys_Device* dev, const Genesys_Sensor&
if (DBG_LEVEL >= DBG_data) if (DBG_LEVEL >= DBG_data)
{ {
char title[30]; char title[30];
snprintf(title, 30, "gl646_offset%03d.pnm", (int)bottom); std::snprintf(title, 30, "gl646_offset%03d.pnm", static_cast<int>(bottom));
sanei_genesys_write_pnm_file (title, line.data(), 8, channels, sanei_genesys_write_pnm_file (title, line.data(), 8, channels,
settings.pixels, settings.lines); settings.pixels, settings.lines);
} }
@ -2624,7 +2600,7 @@ static void ad_fe_coarse_gain_calibration(Genesys_Device* dev, const Genesys_Sen
/* log scanning data */ /* log scanning data */
if (DBG_LEVEL >= DBG_data) if (DBG_LEVEL >= DBG_data)
{ {
sprintf (title, "gl646_alternative_gain%02d.pnm", (int)pass); sprintf (title, "gl646_alternative_gain%02d.pnm", pass);
sanei_genesys_write_pnm_file(title, line.data(), 8, channels, settings.pixels, sanei_genesys_write_pnm_file(title, line.data(), 8, channels, settings.pixels,
settings.lines); settings.lines);
} }
@ -2757,7 +2733,7 @@ void CommandSetGl646::coarse_gain_calibration(Genesys_Device* dev, const Genesys
/* log scanning data */ /* log scanning data */
if (DBG_LEVEL >= DBG_data) if (DBG_LEVEL >= DBG_data)
{ {
sprintf (title, "gl646_gain%02d.pnm", (int)pass); std::sprintf(title, "gl646_gain%02d.pnm", pass);
sanei_genesys_write_pnm_file(title, line.data(), 8, channels, settings.pixels, sanei_genesys_write_pnm_file(title, line.data(), 8, channels, settings.pixels,
settings.lines); settings.lines);
} }
@ -3444,8 +3420,8 @@ static void write_control(Genesys_Device* dev, const Genesys_Sensor& sensor, int
{ {
case MotorId::XP200: case MotorId::XP200:
/* we put scan's dpi, not motor one */ /* we put scan's dpi, not motor one */
control[0] = LOBYTE (resolution); control[0] = resolution & 0xff;
control[1] = HIBYTE (resolution); control[1] = (resolution >> 8) & 0xff;
control[2] = dev->control[4]; control[2] = dev->control[4];
control[3] = dev->control[5]; control[3] = dev->control[5];
break; break;
@ -3503,7 +3479,8 @@ bool CommandSetGl646::is_compatible_calibration(Genesys_Device* dev, const Genes
* requested scan. In the case of CIS scanners, dpi isn't a criteria */ * requested scan. In the case of CIS scanners, dpi isn't a criteria */
if (!dev->model->is_cis) { if (!dev->model->is_cis) {
compatible = (dev->session.params.channels == cache->params.channels) && compatible = (dev->session.params.channels == cache->params.channels) &&
(((int) dev->current_setup.xres) == ((int) cache->used_setup.xres)); (static_cast<int>(dev->current_setup.xres) ==
static_cast<int>(cache->used_setup.xres));
} else { } else {
compatible = dev->session.params.channels == cache->params.channels; compatible = dev->session.params.channels == cache->params.channels;
} }
@ -3592,8 +3569,7 @@ void CommandSetGl646::search_strip(Genesys_Device* dev, const Genesys_Sensor& se
if (DBG_LEVEL >= DBG_data) if (DBG_LEVEL >= DBG_data)
{ {
sprintf (title, "gl646_search_strip_%s%02d.pnm", forward ? "fwd" : "bwd", std::sprintf(title, "gl646_search_strip_%s%02d.pnm", forward ? "fwd" : "bwd", pass);
(int)pass);
sanei_genesys_write_pnm_file (title, data.data(), settings.depth, 1, sanei_genesys_write_pnm_file (title, data.data(), settings.depth, 1,
settings.pixels, settings.lines); settings.pixels, settings.lines);
} }

Wyświetl plik

@ -252,14 +252,10 @@ public:
void init_regs_for_scan(Genesys_Device* dev, const Genesys_Sensor& sensor) const override; void init_regs_for_scan(Genesys_Device* dev, const Genesys_Sensor& sensor) const override;
bool get_filter_bit(Genesys_Register_Set * reg) const override;
bool get_lineart_bit(Genesys_Register_Set * reg) const override;
bool get_bitset_bit(Genesys_Register_Set * reg) const override; bool get_bitset_bit(Genesys_Register_Set * reg) const override;
bool get_gain4_bit(Genesys_Register_Set * reg) const override; bool get_gain4_bit(Genesys_Register_Set * reg) const override;
bool get_fast_feed_bit(Genesys_Register_Set * reg) const override;
bool test_buffer_empty_bit(std::uint8_t val) const override; bool test_buffer_empty_bit(std::uint8_t val) const override;
bool test_motor_flag_bit(std::uint8_t val) const override;
void set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t set) const override; void set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t set) const override;
void set_powersaving(Genesys_Device* dev, int delay) const override; void set_powersaving(Genesys_Device* dev, int delay) const override;

Wyświetl plik

@ -57,14 +57,6 @@
#include <vector> #include <vector>
/****************************************************************************
Low level function
****************************************************************************/
/* ------------------------------------------------------------------------ */
/* Read and write RAM, registers and AFE */
/* ------------------------------------------------------------------------ */
// Set address for writing data // Set address for writing data
static void gl841_set_buffer_address_gamma(Genesys_Device* dev, uint32_t addr) static void gl841_set_buffer_address_gamma(Genesys_Device* dev, uint32_t addr)
{ {
@ -78,28 +70,6 @@ static void gl841_set_buffer_address_gamma(Genesys_Device* dev, uint32_t addr)
dev->write_register(0x5b, (addr & 0xff)); dev->write_register(0x5b, (addr & 0xff));
} }
/****************************************************************************
Mid level functions
****************************************************************************/
bool CommandSetGl841::get_fast_feed_bit(Genesys_Register_Set* regs) const
{
GenesysRegister *r = sanei_genesys_get_address(regs, 0x02);
return (r && (r->value & REG02_FASTFED));
}
bool CommandSetGl841::get_filter_bit(Genesys_Register_Set* regs) const
{
GenesysRegister *r = sanei_genesys_get_address(regs, 0x04);
return (r && (r->value & REG04_FILTER));
}
bool CommandSetGl841::get_lineart_bit(Genesys_Register_Set* regs) const
{
GenesysRegister *r = sanei_genesys_get_address(regs, 0x04);
return (r && (r->value & REG04_LINEART));
}
bool CommandSetGl841::get_bitset_bit(Genesys_Register_Set* regs) const bool CommandSetGl841::get_bitset_bit(Genesys_Register_Set* regs) const
{ {
GenesysRegister *r = sanei_genesys_get_address(regs, 0x04); GenesysRegister *r = sanei_genesys_get_address(regs, 0x04);
@ -117,11 +87,6 @@ bool CommandSetGl841::test_buffer_empty_bit(SANE_Byte val) const
return (val & REG41_BUFEMPTY); return (val & REG41_BUFEMPTY);
} }
bool CommandSetGl841::test_motor_flag_bit(SANE_Byte val) const
{
return (val & REG41_MOTORENB);
}
/** copy sensor specific settings */ /** copy sensor specific settings */
/* *dev : device infos /* *dev : device infos
*regs : registers to be set *regs : registers to be set
@ -1825,7 +1790,7 @@ dummy \ scanned lines
dev->total_bytes_read = 0; dev->total_bytes_read = 0;
dev->total_bytes_to_read = session.output_line_bytes_requested * session.params.lines; dev->total_bytes_to_read = session.output_line_bytes_requested * session.params.lines;
DBG(DBG_info, "%s: total bytes to send = %lu\n", __func__, (u_long) dev->total_bytes_to_read); DBG(DBG_info, "%s: total bytes to send = %zu\n", __func__, dev->total_bytes_to_read);
} }
void CommandSetGl841::calculate_current_setup(Genesys_Device * dev, void CommandSetGl841::calculate_current_setup(Genesys_Device * dev,
@ -2045,8 +2010,7 @@ void CommandSetGl841::set_powersaving(Genesys_Device* dev, int delay /* in minut
} }
time = delay * 1000 * 60; /* -> msec */ time = delay * 1000 * 60; /* -> msec */
exposure_time = exposure_time = static_cast<std::uint32_t>(time * 32000.0 /
(uint32_t) (time * 32000.0 /
(24.0 * 64.0 * (local_reg.find_reg(0x03).value & REG03_LAMPTIM) * (24.0 * 64.0 * (local_reg.find_reg(0x03).value & REG03_LAMPTIM) *
1024.0) + 0.5); 1024.0) + 0.5);
/* 32000 = system clock, 24 = clocks per pixel */ /* 32000 = system clock, 24 = clocks per pixel */
@ -2678,7 +2642,7 @@ void CommandSetGl841::init_regs_for_coarse_calibration(Genesys_Device* dev,
void CommandSetGl841::init_regs_for_shading(Genesys_Device* dev, const Genesys_Sensor& sensor, void CommandSetGl841::init_regs_for_shading(Genesys_Device* dev, const Genesys_Sensor& sensor,
Genesys_Register_Set& regs) const Genesys_Register_Set& regs) const
{ {
DBG_HELPER_ARGS(dbg, "lines = %d", (int)(dev->calib_lines)); DBG_HELPER_ARGS(dbg, "lines = %zu", dev->calib_lines);
SANE_Int ydpi; SANE_Int ydpi;
float starty=0; float starty=0;
@ -3725,7 +3689,7 @@ void CommandSetGl841::init_regs_for_warmup(Genesys_Device* dev, const Genesys_Se
int* total_size) const int* total_size) const
{ {
DBG_HELPER(dbg); DBG_HELPER(dbg);
int num_pixels = (int) (4 * 300); int num_pixels = 4 * 300;
*local_reg = dev->reg; *local_reg = dev->reg;
/* okay.. these should be defaults stored somewhere */ /* okay.. these should be defaults stored somewhere */
@ -4210,7 +4174,7 @@ void CommandSetGl841::send_shading_data(Genesys_Device* dev, const Genesys_Senso
} }
/* data is whole line, we extract only the part for the scanned area */ /* data is whole line, we extract only the part for the scanned area */
length = (uint32_t) (size / 3); length = static_cast<std::uint32_t>(size / 3);
unsigned strpixel = dev->session.pixel_startx; unsigned strpixel = dev->session.pixel_startx;
unsigned endpixel = dev->session.pixel_endx; unsigned endpixel = dev->session.pixel_endx;
@ -4225,7 +4189,7 @@ void CommandSetGl841::send_shading_data(Genesys_Device* dev, const Genesys_Senso
/* binary data logging */ /* binary data logging */
if(DBG_LEVEL>=DBG_data) if(DBG_LEVEL>=DBG_data)
{ {
dev->binary=fopen("binary.pnm","wb"); dev->binary = std::fopen("binary.pnm","wb");
lines = dev->reg.get24(REG_LINCNT); lines = dev->reg.get24(REG_LINCNT);
channels = dev->session.params.channels; channels = dev->session.params.channels;
if (dev->binary != nullptr) { if (dev->binary != nullptr) {

Wyświetl plik

@ -81,14 +81,10 @@ public:
void init_regs_for_scan(Genesys_Device* dev, const Genesys_Sensor& sensor) const override; void init_regs_for_scan(Genesys_Device* dev, const Genesys_Sensor& sensor) const override;
bool get_filter_bit(Genesys_Register_Set* reg) const override;
bool get_lineart_bit(Genesys_Register_Set* reg) const override;
bool get_bitset_bit(Genesys_Register_Set* reg) const override; bool get_bitset_bit(Genesys_Register_Set* reg) const override;
bool get_gain4_bit(Genesys_Register_Set* reg) const override; bool get_gain4_bit(Genesys_Register_Set* reg) const override;
bool get_fast_feed_bit(Genesys_Register_Set* reg) const override;
bool test_buffer_empty_bit(std::uint8_t val) const override; bool test_buffer_empty_bit(std::uint8_t val) const override;
bool test_motor_flag_bit(std::uint8_t val) const override;
void set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t set) const override; void set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t set) const override;
void set_powersaving(Genesys_Device* dev, int delay) const override; void set_powersaving(Genesys_Device* dev, int delay) const override;

Wyświetl plik

@ -50,14 +50,6 @@
#include <string> #include <string>
#include <vector> #include <vector>
/****************************************************************************
Low level function
****************************************************************************/
/* ------------------------------------------------------------------------ */
/* Read and write RAM, registers and AFE */
/* ------------------------------------------------------------------------ */
// Set address for writing data // Set address for writing data
static void gl843_set_buffer_address(Genesys_Device* dev, uint32_t addr) static void gl843_set_buffer_address(Genesys_Device* dev, uint32_t addr)
{ {
@ -96,28 +88,6 @@ static void write_data(Genesys_Device* dev, uint32_t addr, uint32_t size, uint8_
gl843_set_buffer_address(dev, 0); gl843_set_buffer_address(dev, 0);
} }
/****************************************************************************
Mid level functions
****************************************************************************/
bool CommandSetGl843::get_fast_feed_bit(Genesys_Register_Set* regs) const
{
GenesysRegister *r = sanei_genesys_get_address (regs, REG02);
return (r && (r->value & REG02_FASTFED));
}
bool CommandSetGl843::get_filter_bit(Genesys_Register_Set* regs) const
{
GenesysRegister *r = sanei_genesys_get_address (regs, REG04);
return (r && (r->value & REG04_FILTER));
}
bool CommandSetGl843::get_lineart_bit(Genesys_Register_Set* regs) const
{
GenesysRegister *r = sanei_genesys_get_address (regs, REG04);
return (r && (r->value & REG04_LINEART));
}
bool CommandSetGl843::get_bitset_bit(Genesys_Register_Set* regs) const bool CommandSetGl843::get_bitset_bit(Genesys_Register_Set* regs) const
{ {
GenesysRegister *r = sanei_genesys_get_address (regs, REG04); GenesysRegister *r = sanei_genesys_get_address (regs, REG04);
@ -161,11 +131,6 @@ bool CommandSetGl843::test_buffer_empty_bit(SANE_Byte val) const
return (val & REG41_BUFEMPTY); return (val & REG41_BUFEMPTY);
} }
bool CommandSetGl843::test_motor_flag_bit(SANE_Byte val) const
{
return (val & REG41_MOTORENB);
}
/** copy sensor specific settings */ /** copy sensor specific settings */
static void gl843_setup_sensor(Genesys_Device* dev, const Genesys_Sensor& sensor, static void gl843_setup_sensor(Genesys_Device* dev, const Genesys_Sensor& sensor,
Genesys_Register_Set* regs) Genesys_Register_Set* regs)
@ -1356,7 +1321,7 @@ static void gl843_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens
dev->total_bytes_read = 0; dev->total_bytes_read = 0;
dev->total_bytes_to_read = session.output_line_bytes_requested * session.params.lines; dev->total_bytes_to_read = session.output_line_bytes_requested * session.params.lines;
DBG(DBG_info, "%s: total bytes to send = %lu\n", __func__, (u_long) dev->total_bytes_to_read); DBG(DBG_info, "%s: total bytes to send = %zu\n", __func__, dev->total_bytes_to_read);
} }
void CommandSetGl843::calculate_current_setup(Genesys_Device * dev, void CommandSetGl843::calculate_current_setup(Genesys_Device * dev,
@ -2864,7 +2829,8 @@ void CommandSetGl843::offset_calibration(Genesys_Device* dev, const Genesys_Sens
if (DBG_LEVEL >= DBG_data) if (DBG_LEVEL >= DBG_data)
{ {
sanei_genesys_write_file("gl843_offset_all_desc.txt", sanei_genesys_write_file("gl843_offset_all_desc.txt",
(uint8_t*) debug_image_info.data(), debug_image_info.size()); reinterpret_cast<const std::uint8_t*>(debug_image_info.data()),
debug_image_info.size());
sanei_genesys_write_pnm_file("gl843_offset_all.pnm", sanei_genesys_write_pnm_file("gl843_offset_all.pnm",
debug_image.data(), bpp, channels, pixels, debug_image_lines); debug_image.data(), bpp, channels, pixels, debug_image_lines);
} }
@ -2997,7 +2963,7 @@ void CommandSetGl843::coarse_gain_calibration(Genesys_Device* dev, const Genesys
dev->frontend.set_gain(ch, code); dev->frontend.set_gain(ch, code);
DBG(DBG_proc, "%s: channel %d, max=%d, target=%d, setting:%d\n", __func__, ch, curr_output, DBG(DBG_proc, "%s: channel %d, max=%d, target=%d, setting:%d\n", __func__, ch, curr_output,
(int) target_value, code); static_cast<int>(target_value), code);
} }
if (dev->model->is_cis) { if (dev->model->is_cis) {
@ -3334,7 +3300,7 @@ void CommandSetGl843::search_strip(Genesys_Device* dev, const Genesys_Sensor& se
{ {
char fn[40]; char fn[40];
snprintf(fn, 40, "gl843_search_strip_%s_%s%02d.pnm", snprintf(fn, 40, "gl843_search_strip_%s_%s%02d.pnm",
black ? "black" : "white", forward ? "fwd" : "bwd", (int)pass); black ? "black" : "white", forward ? "fwd" : "bwd", pass);
sanei_genesys_write_pnm_file(fn, data); sanei_genesys_write_pnm_file(fn, data);
} }
@ -3357,8 +3323,8 @@ void CommandSetGl843::search_strip(Genesys_Device* dev, const Genesys_Sensor& se
if (DBG_LEVEL >= DBG_data) if (DBG_LEVEL >= DBG_data)
{ {
char fn[40]; char fn[40];
snprintf(fn, 40, "gl843_search_strip_%s_%s%02d.pnm", std::snprintf(fn, 40, "gl843_search_strip_%s_%s%02d.pnm",
black ? "black" : "white", forward ? "fwd" : "bwd", (int)pass); black ? "black" : "white", forward ? "fwd" : "bwd", pass);
sanei_genesys_write_pnm_file(fn, data); sanei_genesys_write_pnm_file(fn, data);
} }

Wyświetl plik

@ -84,14 +84,10 @@ public:
void init_regs_for_scan(Genesys_Device* dev, const Genesys_Sensor& sensor) const override; void init_regs_for_scan(Genesys_Device* dev, const Genesys_Sensor& sensor) const override;
bool get_filter_bit(Genesys_Register_Set * reg) const override;
bool get_lineart_bit(Genesys_Register_Set * reg) const override;
bool get_bitset_bit(Genesys_Register_Set * reg) const override; bool get_bitset_bit(Genesys_Register_Set * reg) const override;
bool get_gain4_bit(Genesys_Register_Set * reg) const override; bool get_gain4_bit(Genesys_Register_Set * reg) const override;
bool get_fast_feed_bit(Genesys_Register_Set * reg) const override;
bool test_buffer_empty_bit(std::uint8_t val) const override; bool test_buffer_empty_bit(std::uint8_t val) const override;
bool test_motor_flag_bit(std::uint8_t val) const override;
void set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t set) const override; void set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t set) const override;
void set_powersaving(Genesys_Device* dev, int delay) const override; void set_powersaving(Genesys_Device* dev, int delay) const override;

Wyświetl plik

@ -54,28 +54,6 @@
#include <vector> #include <vector>
/****************************************************************************
Mid level functions
****************************************************************************/
bool CommandSetGl846::get_fast_feed_bit(Genesys_Register_Set* regs) const
{
GenesysRegister *r = sanei_genesys_get_address(regs, REG02);
return (r && (r->value & REG02_FASTFED));
}
bool CommandSetGl846::get_filter_bit(Genesys_Register_Set* regs) const
{
GenesysRegister *r = sanei_genesys_get_address(regs, REG04);
return (r && (r->value & REG04_FILTER));
}
bool CommandSetGl846::get_lineart_bit(Genesys_Register_Set* regs) const
{
GenesysRegister *r = sanei_genesys_get_address(regs, REG04);
return (r && (r->value & REG04_LINEART));
}
bool CommandSetGl846::get_bitset_bit(Genesys_Register_Set* regs) const bool CommandSetGl846::get_bitset_bit(Genesys_Register_Set* regs) const
{ {
GenesysRegister *r = sanei_genesys_get_address(regs, REG04); GenesysRegister *r = sanei_genesys_get_address(regs, REG04);
@ -93,11 +71,6 @@ bool CommandSetGl846::test_buffer_empty_bit(SANE_Byte val) const
return (val & REG41_BUFEMPTY); return (val & REG41_BUFEMPTY);
} }
bool CommandSetGl846::test_motor_flag_bit(SANE_Byte val) const
{
return (val & REG41_MOTORENB);
}
/** /**
* compute the step multiplier used * compute the step multiplier used
*/ */
@ -879,7 +852,7 @@ static void gl846_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens
dev->total_bytes_read = 0; dev->total_bytes_read = 0;
dev->total_bytes_to_read = session.output_line_bytes_requested * session.params.lines; dev->total_bytes_to_read = session.output_line_bytes_requested * session.params.lines;
DBG(DBG_info, "%s: total bytes to send = %lu\n", __func__, (u_long) dev->total_bytes_to_read); DBG(DBG_info, "%s: total bytes to send = %zu\n", __func__, dev->total_bytes_to_read);
} }
void CommandSetGl846::calculate_current_setup(Genesys_Device* dev, void CommandSetGl846::calculate_current_setup(Genesys_Device* dev,
@ -1391,8 +1364,8 @@ void CommandSetGl846::init_regs_for_shading(Genesys_Device* dev, const Genesys_S
if(dev->calib_resolution==4800) if(dev->calib_resolution==4800)
dev->calib_lines *= 2; dev->calib_lines *= 2;
dev->calib_pixels = (sensor.sensor_pixels*dev->calib_resolution)/sensor.optical_res; dev->calib_pixels = (sensor.sensor_pixels*dev->calib_resolution)/sensor.optical_res;
DBG(DBG_io, "%s: calib_lines = %d\n", __func__, (unsigned int)dev->calib_lines); DBG(DBG_io, "%s: calib_lines = %zu\n", __func__, dev->calib_lines);
DBG(DBG_io, "%s: calib_pixels = %d\n", __func__, (unsigned int)dev->calib_pixels); DBG(DBG_io, "%s: calib_pixels = %zu\n", __func__, dev->calib_pixels);
/* this is aworkaround insufficent distance for slope /* this is aworkaround insufficent distance for slope
* motor acceleration TODO special motor slope for shading */ * motor acceleration TODO special motor slope for shading */
@ -1537,7 +1510,7 @@ void CommandSetGl846::send_shading_data(Genesys_Device* dev, const Genesys_Senso
write(0x1003e000,0x00000dd8) write(0x1003e000,0x00000dd8)
write(0x10068000,0x00000dd8) write(0x10068000,0x00000dd8)
*/ */
length = (uint32_t) (size / 3); length = static_cast<uint32_t>(size / 3);
unsigned strpixel = dev->session.pixel_startx; unsigned strpixel = dev->session.pixel_startx;
unsigned endpixel = dev->session.pixel_endx; unsigned endpixel = dev->session.pixel_endx;
@ -1549,7 +1522,7 @@ void CommandSetGl846::send_shading_data(Genesys_Device* dev, const Genesys_Senso
if(DBG_LEVEL>=DBG_data) if(DBG_LEVEL>=DBG_data)
{ {
dev->binary=fopen("binary.pnm","wb"); dev->binary = std::fopen("binary.pnm", "wb");
lines = dev->reg.get24(REG_LINCNT); lines = dev->reg.get24(REG_LINCNT);
unsigned channels = dev->session.params.channels; unsigned channels = dev->session.params.channels;
if (dev->binary != nullptr) { if (dev->binary != nullptr) {
@ -2008,8 +1981,8 @@ void CommandSetGl846::search_strip(Genesys_Device* dev, const Genesys_Sensor& se
pass = 0; pass = 0;
if (DBG_LEVEL >= DBG_data) if (DBG_LEVEL >= DBG_data)
{ {
sprintf(title, "gl846_search_strip_%s_%s%02d.pnm", std::sprintf(title, "gl846_search_strip_%s_%s%02d.pnm",
black ? "black" : "white", forward ? "fwd" : "bwd", (int)pass); black ? "black" : "white", forward ? "fwd" : "bwd", pass);
sanei_genesys_write_pnm_file(title, data.data(), depth, channels, pixels, lines); sanei_genesys_write_pnm_file(title, data.data(), depth, channels, pixels, lines);
} }
@ -2031,8 +2004,8 @@ void CommandSetGl846::search_strip(Genesys_Device* dev, const Genesys_Sensor& se
if (DBG_LEVEL >= DBG_data) if (DBG_LEVEL >= DBG_data)
{ {
sprintf(title, "gl846_search_strip_%s_%s%02d.pnm", std::sprintf(title, "gl846_search_strip_%s_%s%02d.pnm",
black ? "black" : "white", forward ? "fwd" : "bwd", (int)pass); black ? "black" : "white", forward ? "fwd" : "bwd", pass);
sanei_genesys_write_pnm_file(title, data.data(), depth, channels, pixels, lines); sanei_genesys_write_pnm_file(title, data.data(), depth, channels, pixels, lines);
} }
@ -2391,7 +2364,7 @@ void CommandSetGl846::coarse_gain_calibration(Genesys_Device* dev, const Genesys
} }
max[j] = max[j] / (pixels/2); max[j] = max[j] / (pixels/2);
gain[j] = ((float) sensor.gain_white_ref*coeff) / max[j]; gain[j] = (static_cast<float>(sensor.gain_white_ref) * coeff) / max[j];
/* turn logical gain value into gain code, checking for overflow */ /* turn logical gain value into gain code, checking for overflow */
code = 283 - 208 / gain[j]; code = 283 - 208 / gain[j];

Wyświetl plik

@ -153,14 +153,10 @@ public:
void init_regs_for_scan(Genesys_Device* dev, const Genesys_Sensor& sensor) const override; void init_regs_for_scan(Genesys_Device* dev, const Genesys_Sensor& sensor) const override;
bool get_filter_bit(Genesys_Register_Set * reg) const override;
bool get_lineart_bit(Genesys_Register_Set * reg) const override;
bool get_bitset_bit(Genesys_Register_Set * reg) const override; bool get_bitset_bit(Genesys_Register_Set * reg) const override;
bool get_gain4_bit(Genesys_Register_Set * reg) const override; bool get_gain4_bit(Genesys_Register_Set * reg) const override;
bool get_fast_feed_bit(Genesys_Register_Set * reg) const override;
bool test_buffer_empty_bit(std::uint8_t val) const override; bool test_buffer_empty_bit(std::uint8_t val) const override;
bool test_motor_flag_bit(std::uint8_t val) const override;
void set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t set) const override; void set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t set) const override;
void set_powersaving(Genesys_Device* dev, int delay) const override; void set_powersaving(Genesys_Device* dev, int delay) const override;

Wyświetl plik

@ -49,28 +49,6 @@
#include <vector> #include <vector>
/****************************************************************************
Mid level functions
****************************************************************************/
bool CommandSetGl847::get_fast_feed_bit(Genesys_Register_Set* regs) const
{
GenesysRegister *r = sanei_genesys_get_address(regs, REG02);
return (r && (r->value & REG02_FASTFED));
}
bool CommandSetGl847::get_filter_bit(Genesys_Register_Set* regs) const
{
GenesysRegister *r = sanei_genesys_get_address(regs, REG04);
return (r && (r->value & REG04_FILTER));
}
bool CommandSetGl847::get_lineart_bit(Genesys_Register_Set* regs) const
{
GenesysRegister *r = sanei_genesys_get_address(regs, REG04);
return (r && (r->value & REG04_LINEART));
}
bool CommandSetGl847::get_bitset_bit(Genesys_Register_Set* regs) const bool CommandSetGl847::get_bitset_bit(Genesys_Register_Set* regs) const
{ {
GenesysRegister *r = sanei_genesys_get_address(regs, REG04); GenesysRegister *r = sanei_genesys_get_address(regs, REG04);
@ -88,11 +66,6 @@ bool CommandSetGl847::test_buffer_empty_bit(SANE_Byte val) const
return (val & REG41_BUFEMPTY); return (val & REG41_BUFEMPTY);
} }
bool CommandSetGl847::test_motor_flag_bit(SANE_Byte val) const
{
return (val & REG41_MOTORENB);
}
/** /**
* compute the step multiplier used * compute the step multiplier used
*/ */
@ -881,8 +854,7 @@ static void gl847_init_scan_regs(Genesys_Device* dev, const Genesys_Sensor& sens
dev->total_bytes_read = 0; dev->total_bytes_read = 0;
dev->total_bytes_to_read = session.output_line_bytes_requested * session.params.lines; dev->total_bytes_to_read = session.output_line_bytes_requested * session.params.lines;
DBG(DBG_info, "%s: total bytes to send = %lu\n", __func__, (u_long) dev->total_bytes_to_read); DBG(DBG_info, "%s: total bytes to send = %zu\n", __func__, dev->total_bytes_to_read);
/* END TODO */
} }
void CommandSetGl847::calculate_current_setup(Genesys_Device * dev, void CommandSetGl847::calculate_current_setup(Genesys_Device * dev,
@ -1432,8 +1404,8 @@ void CommandSetGl847::init_regs_for_shading(Genesys_Device* dev, const Genesys_S
if(dev->calib_resolution==4800) if(dev->calib_resolution==4800)
dev->calib_lines *= 2; dev->calib_lines *= 2;
dev->calib_pixels = (sensor.sensor_pixels*dev->calib_resolution)/sensor.optical_res; dev->calib_pixels = (sensor.sensor_pixels*dev->calib_resolution)/sensor.optical_res;
DBG(DBG_io, "%s: calib_lines = %d\n", __func__, (int)dev->calib_lines); DBG(DBG_io, "%s: calib_lines = %zu\n", __func__, dev->calib_lines);
DBG(DBG_io, "%s: calib_pixels = %d\n", __func__, (int)dev->calib_pixels); DBG(DBG_io, "%s: calib_pixels = %zu\n", __func__, dev->calib_pixels);
/* this is aworkaround insufficent distance for slope /* this is aworkaround insufficent distance for slope
* motor acceleration TODO special motor slope for shading */ * motor acceleration TODO special motor slope for shading */
@ -1577,7 +1549,7 @@ void CommandSetGl847::send_shading_data(Genesys_Device* dev, const Genesys_Senso
write(0x1003e000,0x00000dd8) write(0x1003e000,0x00000dd8)
write(0x10068000,0x00000dd8) write(0x10068000,0x00000dd8)
*/ */
length = (uint32_t) (size / 3); length = static_cast<std::uint32_t>(size / 3);
std::uint32_t strpixel = dev->session.pixel_startx; std::uint32_t strpixel = dev->session.pixel_startx;
std::uint32_t endpixel = dev->session.pixel_endx; std::uint32_t endpixel = dev->session.pixel_endx;
@ -1589,7 +1561,7 @@ void CommandSetGl847::send_shading_data(Genesys_Device* dev, const Genesys_Senso
if(DBG_LEVEL>=DBG_data) if(DBG_LEVEL>=DBG_data)
{ {
dev->binary=fopen("binary.pnm","wb"); dev->binary = std::fopen("binary.pnm", "wb");
lines = dev->reg.get24(REG_LINCNT); lines = dev->reg.get24(REG_LINCNT);
unsigned channels = dev->session.params.channels; unsigned channels = dev->session.params.channels;
if (dev->binary != nullptr) { if (dev->binary != nullptr) {
@ -2084,8 +2056,8 @@ void CommandSetGl847::search_strip(Genesys_Device* dev, const Genesys_Sensor& se
pass = 0; pass = 0;
if (DBG_LEVEL >= DBG_data) if (DBG_LEVEL >= DBG_data)
{ {
sprintf(title, "gl847_search_strip_%s_%s%02d.pnm", std::sprintf(title, "gl847_search_strip_%s_%s%02d.pnm",
black ? "black" : "white", forward ? "fwd" : "bwd", (int)pass); black ? "black" : "white", forward ? "fwd" : "bwd", pass);
sanei_genesys_write_pnm_file(title, data.data(), depth, channels, pixels, lines); sanei_genesys_write_pnm_file(title, data.data(), depth, channels, pixels, lines);
} }
@ -2479,7 +2451,7 @@ void CommandSetGl847::coarse_gain_calibration(Genesys_Device* dev, const Genesys
} }
max[j] = max[j] / (pixels/2); max[j] = max[j] / (pixels/2);
gain[j] = ((float) sensor.gain_white_ref*coeff) / max[j]; gain[j] = (static_cast<float>(sensor.gain_white_ref) * coeff) / max[j];
/* turn logical gain value into gain code, checking for overflow */ /* turn logical gain value into gain code, checking for overflow */
code = 283 - 208 / gain[j]; code = 283 - 208 / gain[j];

Wyświetl plik

@ -137,14 +137,10 @@ public:
void init_regs_for_scan(Genesys_Device* dev, const Genesys_Sensor& sensor) const override; void init_regs_for_scan(Genesys_Device* dev, const Genesys_Sensor& sensor) const override;
bool get_filter_bit(Genesys_Register_Set * reg) const override;
bool get_lineart_bit(Genesys_Register_Set * reg) const override;
bool get_bitset_bit(Genesys_Register_Set * reg) const override; bool get_bitset_bit(Genesys_Register_Set * reg) const override;
bool get_gain4_bit(Genesys_Register_Set * reg) const override; bool get_gain4_bit(Genesys_Register_Set * reg) const override;
bool get_fast_feed_bit(Genesys_Register_Set * reg) const override;
bool test_buffer_empty_bit(std::uint8_t val) const override; bool test_buffer_empty_bit(std::uint8_t val) const override;
bool test_motor_flag_bit(std::uint8_t val) const override;
void set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t set) const override; void set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t set) const override;
void set_powersaving(Genesys_Device* dev, int delay) const override; void set_powersaving(Genesys_Device* dev, int delay) const override;

Wyświetl plik

@ -450,7 +450,7 @@ private:
std::size_t height_ = 0; std::size_t height_ = 0;
std::size_t current_line_ = 0; std::size_t current_line_ = 0;
std::vector<uint8_t> cached_line_; std::vector<std::uint8_t> cached_line_;
}; };
// A pipeline node that scales rows to the specified width by using a point filter // A pipeline node that scales rows to the specified width by using a point filter
@ -471,7 +471,7 @@ private:
ImagePipelineNode& source_; ImagePipelineNode& source_;
std::size_t width_ = 0; std::size_t width_ = 0;
std::vector<uint8_t> cached_line_; std::vector<std::uint8_t> cached_line_;
}; };
// A pipeline node that mimics the calibration behavior on Genesys chips // A pipeline node that mimics the calibration behavior on Genesys chips

Wyświetl plik

@ -205,7 +205,7 @@ void set_pixel_to_row(std::uint8_t* data, std::size_t x, Pixel pixel, PixelForma
float val = (pixel.r >> 8) * 0.3f; float val = (pixel.r >> 8) * 0.3f;
val += (pixel.g >> 8) * 0.59; val += (pixel.g >> 8) * 0.59;
val += (pixel.b >> 8) * 0.11; val += (pixel.b >> 8) * 0.11;
data[x] = static_cast<uint16_t>(val); data[x] = static_cast<std::uint16_t>(val);
return; return;
} }
case PixelFormat::I16: { case PixelFormat::I16: {

Wyświetl plik

@ -84,7 +84,7 @@ void sanei_genesys_init_cmd_set(Genesys_Device* dev)
/* General IO and debugging functions */ /* General IO and debugging functions */
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */
void sanei_genesys_write_file(const char* filename, uint8_t* data, size_t length) void sanei_genesys_write_file(const char* filename, const std::uint8_t* data, size_t length)
{ {
DBG_HELPER(dbg); DBG_HELPER(dbg);
FILE *out; FILE *out;
@ -286,9 +286,9 @@ void sanei_genesys_bulk_read_data(Genesys_Device * dev, uint8_t addr, uint8_t* d
} }
if (is_addr_used) { if (is_addr_used) {
DBG(DBG_io, "%s: requesting %lu bytes from 0x%02x addr\n", __func__, (u_long) len, addr); DBG(DBG_io, "%s: requesting %zu bytes from 0x%02x addr\n", __func__, len, addr);
} else { } else {
DBG(DBG_io, "%s: requesting %lu bytes\n", __func__, (u_long) len); DBG(DBG_io, "%s: requesting %zu bytes\n", __func__, len);
} }
if (len == 0) if (len == 0)
@ -320,12 +320,11 @@ void sanei_genesys_bulk_read_data(Genesys_Device * dev, uint8_t addr, uint8_t* d
sanei_genesys_bulk_read_data_send_header(dev, size); sanei_genesys_bulk_read_data_send_header(dev, size);
} }
DBG(DBG_io2, "%s: trying to read %lu bytes of data\n", __func__, (u_long) size); DBG(DBG_io2, "%s: trying to read %zu bytes of data\n", __func__, size);
dev->usb_dev.bulk_read(data, &size); dev->usb_dev.bulk_read(data, &size);
DBG(DBG_io2, "%s: read %lu bytes, %lu remaining\n", __func__, DBG(DBG_io2, "%s: read %zu bytes, %zu remaining\n", __func__, size, target - size);
(u_long) size, (u_long) (target - size));
target -= size; target -= size;
data += size; data += size;
@ -338,7 +337,7 @@ void sanei_genesys_bulk_read_data(Genesys_Device * dev, uint8_t addr, uint8_t* d
void sanei_genesys_bulk_write_data(Genesys_Device* dev, uint8_t addr, uint8_t* data, size_t len) void sanei_genesys_bulk_write_data(Genesys_Device* dev, uint8_t addr, uint8_t* data, size_t len)
{ {
DBG_HELPER_ARGS(dbg, "writing %lu bytes", (u_long) len); DBG_HELPER_ARGS(dbg, "writing %zu bytes", len);
// supported: GL646, GL841, GL843 // supported: GL646, GL841, GL843
size_t size; size_t size;
@ -379,8 +378,7 @@ void sanei_genesys_bulk_write_data(Genesys_Device* dev, uint8_t addr, uint8_t* d
dev->usb_dev.bulk_write(data, &size); dev->usb_dev.bulk_write(data, &size);
DBG(DBG_io2, "%s: wrote %lu bytes, %lu remaining\n", __func__, (u_long) size, DBG(DBG_io2, "%s: wrote %zu bytes, %zu remaining\n", __func__, size, len - size);
(u_long) (len - size));
len -= size; len -= size;
data += size; data += size;
@ -550,7 +548,7 @@ void sanei_genesys_read_register(Genesys_Device* dev, uint16_t reg, uint8_t* val
} }
/* 8 bit register address space */ /* 8 bit register address space */
reg8=(SANE_Byte)(reg& 0Xff); reg8 = reg & 0Xff;
dev->usb_dev.control_msg(REQUEST_TYPE_OUT, REQUEST_REGISTER, VALUE_SET_REGISTER, INDEX, dev->usb_dev.control_msg(REQUEST_TYPE_OUT, REQUEST_REGISTER, VALUE_SET_REGISTER, INDEX,
1, &reg8); 1, &reg8);
@ -831,7 +829,7 @@ void wait_until_has_valid_words(Genesys_Device* dev)
// Read data (e.g scanned image) from scan buffer // Read data (e.g scanned image) from scan buffer
void sanei_genesys_read_data_from_scanner(Genesys_Device* dev, uint8_t* data, size_t size) void sanei_genesys_read_data_from_scanner(Genesys_Device* dev, uint8_t* data, size_t size)
{ {
DBG_HELPER_ARGS(dbg, "size = %lu bytes", (u_long) size); DBG_HELPER_ARGS(dbg, "size = %zu bytes", size);
if (size & 1) if (size & 1)
DBG(DBG_info, "WARNING %s: odd number of bytes\n", __func__); DBG(DBG_info, "WARNING %s: odd number of bytes\n", __func__);
@ -1003,8 +1001,7 @@ void sanei_genesys_bulk_write_register(Genesys_Device* dev, const Genesys_Regist
buffer.push_back(r.value); buffer.push_back(r.value);
} }
DBG(DBG_io, "%s (elems= %lu, size = %lu)\n", __func__, (u_long) reg.size(), DBG(DBG_io, "%s (elems= %zu, size = %zu)\n", __func__, reg.size(), buffer.size());
(u_long) buffer.size());
if (dev->model->asic_type == AsicType::GL646) { if (dev->model->asic_type == AsicType::GL646) {
outdata[0] = BULK_OUT; outdata[0] = BULK_OUT;
@ -1040,7 +1037,7 @@ void sanei_genesys_bulk_write_register(Genesys_Device* dev, const Genesys_Regist
} }
} }
DBG (DBG_io, "%s: wrote %lu registers\n", __func__, (u_long) reg.size()); DBG (DBG_io, "%s: wrote %zu registers\n", __func__, reg.size());
} }
@ -1142,7 +1139,7 @@ void sanei_genesys_generate_gamma_buffer(Genesys_Device* dev,
if(dev->settings.contrast!=0 || dev->settings.brightness!=0) if(dev->settings.contrast!=0 || dev->settings.brightness!=0)
{ {
std::vector<uint16_t> lut(65536); std::vector<uint16_t> lut(65536);
sanei_genesys_load_lut((unsigned char *)lut.data(), sanei_genesys_load_lut(reinterpret_cast<unsigned char *>(lut.data()),
bits, bits,
bits, bits,
0, 0,
@ -1525,7 +1522,7 @@ void compute_session(Genesys_Device* dev, ScanSession& s, const Genesys_Sensor&
// for HP3670, stagger happens only at >=1200 dpi // for HP3670, stagger happens only at >=1200 dpi
if ((dev->model->motor_id != MotorId::HP3670 && if ((dev->model->motor_id != MotorId::HP3670 &&
dev->model->motor_id != MotorId::HP2400) || dev->model->motor_id != MotorId::HP2400) ||
s.params.yres >= (unsigned) sensor.optical_res) s.params.yres >= static_cast<unsigned>(sensor.optical_res))
{ {
s.num_staggered_lines = (4 * s.params.yres) / dev->motor.base_ydpi; s.num_staggered_lines = (4 * s.params.yres) / dev->motor.base_ydpi;
} }
@ -2287,7 +2284,7 @@ bool sanei_genesys_is_compatible_calibration(Genesys_Device * dev, const Genesys
/* a calibration cache is compatible if color mode and x dpi match the user /* a calibration cache is compatible if color mode and x dpi match the user
* requested scan. In the case of CIS scanners, dpi isn't a criteria */ * requested scan. In the case of CIS scanners, dpi isn't a criteria */
if (!dev->model->is_cis) { if (!dev->model->is_cis) {
compatible = (dev->settings.xres == ((int) cache->used_setup.xres)); compatible = (dev->settings.xres == static_cast<int>(cache->used_setup.xres));
} }
else else
{ {
@ -2417,7 +2414,7 @@ void sanei_genesys_load_lut(unsigned char* lut,
int max_in_val = (1 << in_bits) - 1; int max_in_val = (1 << in_bits) - 1;
int max_out_val = (1 << out_bits) - 1; int max_out_val = (1 << out_bits) - 1;
uint8_t *lut_p8 = lut; uint8_t *lut_p8 = lut;
uint16_t *lut_p16 = (uint16_t *) lut; uint16_t* lut_p16 = reinterpret_cast<std::uint16_t*>(lut);
/* slope is converted to rise per unit run: /* slope is converted to rise per unit run:
* first [-127,127] to [-.999,.999] * first [-127,127] to [-.999,.999]
@ -2425,16 +2422,16 @@ void sanei_genesys_load_lut(unsigned char* lut,
* then take the tangent (T.O.A) * then take the tangent (T.O.A)
* then multiply by the normal linear slope * then multiply by the normal linear slope
* because the table may not be square, i.e. 1024x256*/ * because the table may not be square, i.e. 1024x256*/
rise = tan ((double) slope / 128 * M_PI_4 + M_PI_4) * max_out_val / max_in_val; rise = std::tan(static_cast<double>(slope) / 128 * M_PI_4 + M_PI_4) * max_out_val / max_in_val;
/* line must stay vertically centered, so figure /* line must stay vertically centered, so figure
* out vertical offset at central input value */ * out vertical offset at central input value */
shift = (double) max_out_val / 2 - (rise * max_in_val / 2); shift = static_cast<double>(max_out_val) / 2 - (rise * max_in_val / 2);
/* convert the user offset setting to scale of output /* convert the user offset setting to scale of output
* first [-127,127] to [-1,1] * first [-127,127] to [-1,1]
* then to [-max_out_val/2,max_out_val/2]*/ * then to [-max_out_val/2,max_out_val/2]*/
shift += (double) offset / 127 * max_out_val / 2; shift += static_cast<double>(offset) / 127 * max_out_val / 2;
for (i = 0; i <= max_in_val; i++) for (i = 0; i <= max_in_val; i++)
{ {

Wyświetl plik

@ -372,10 +372,6 @@ extern void sanei_genesys_fe_write_data(Genesys_Device* dev, uint8_t addr, uint1
SANE_Int sanei_genesys_exposure_time2(Genesys_Device * dev, float ydpi, int step_type, SANE_Int sanei_genesys_exposure_time2(Genesys_Device * dev, float ydpi, int step_type,
int endpixel, int led_exposure); int endpixel, int led_exposure);
extern SANE_Int
sanei_genesys_exposure_time (Genesys_Device * dev, Genesys_Register_Set * reg,
int xdpi);
SANE_Int sanei_genesys_generate_slope_table(std::vector<uint16_t>& slope_table, unsigned int max_steps, SANE_Int sanei_genesys_generate_slope_table(std::vector<uint16_t>& slope_table, unsigned int max_steps,
unsigned int use_steps, uint16_t stop_at, unsigned int use_steps, uint16_t stop_at,
uint16_t vstart, uint16_t vend, uint16_t vstart, uint16_t vend,
@ -408,7 +404,7 @@ extern void sanei_genesys_search_reference_point(Genesys_Device* dev, Genesys_Se
const uint8_t* src_data, int start_pixel, int dpi, const uint8_t* src_data, int start_pixel, int dpi,
int width, int height); int width, int height);
extern void sanei_genesys_write_file(const char* filename, uint8_t* data, size_t length); extern void sanei_genesys_write_file(const char* filename, const std::uint8_t* data, size_t length);
extern void sanei_genesys_write_pnm_file(const char* filename, const std::uint8_t* data, int depth, extern void sanei_genesys_write_pnm_file(const char* filename, const std::uint8_t* data, int depth,
int channels, int pixels_per_line, int lines); int channels, int pixels_per_line, int lines);