• Home
  • Raw
  • Download

Lines Matching +full:cap +full:- +full:std

1 /* sane - Scanner Access Now Easy.
3 Copyright (C) 2003, 2004 Henning Meier-Geinitz <henning@meier-geinitz.de>
5 Copyright (C) 2004-2016 Stéphane Voltz <stef.dev@free.fr>
6 Copyright (C) 2005-2009 Pierre Willenbrock <pierre@pirsoft.dnsalias.org>
73 std::string name;
77 StaticInit<std::list<Genesys_Scanner>> s_scanners;
78 StaticInit<std::vector<SANE_Device>> s_sane_devices;
79 StaticInit<std::vector<SANE_Device_Data>> s_sane_devices_data;
80 StaticInit<std::vector<SANE_Device*>> s_sane_devices_ptrs;
81 StaticInit<std::list<Genesys_Device>> s_devices;
83 // Maximum time for lamp warm-up
144 -100, /* minimum */
153 -1, /* minimum */
162 if (dev->model->sensor_id == sensor.sensor_id) { in sanei_genesys_find_sensor_any()
166 throw std::runtime_error("Given device does not have sensor defined"); in sanei_genesys_find_sensor_any()
175 if (dev->model->sensor_id == sensor.sensor_id && sensor.resolutions.matches(dpi) && in find_sensor_impl()
200 throw std::runtime_error("Given device does not have sensor defined"); in sanei_genesys_find_sensor()
212 throw std::runtime_error("Given device does not have sensor defined"); in sanei_genesys_find_sensor_for_write()
216 std::vector<std::reference_wrapper<const Genesys_Sensor>>
220 std::vector<std::reference_wrapper<const Genesys_Sensor>> ret; in sanei_genesys_find_sensors_all()
222 if (dev->model->sensor_id == sensor.sensor_id && sensor.method == scan_method) { in sanei_genesys_find_sensors_all()
229 std::vector<std::reference_wrapper<Genesys_Sensor>>
233 std::vector<std::reference_wrapper<Genesys_Sensor>> ret; in sanei_genesys_find_sensors_all_for_write()
235 if (dev->model->sensor_id == sensor.sensor_id && sensor.method == scan_method) { in sanei_genesys_find_sensors_all_for_write()
252 if (dev->model->gpio_id == gpo.id) { in sanei_genesys_init_structs()
253 dev->gpo = gpo; in sanei_genesys_init_structs()
261 if (dev->model->motor_id == motor.id) { in sanei_genesys_init_structs()
262 dev->motor = motor; in sanei_genesys_init_structs()
269 if (dev->model->adc_id == frontend.id) { in sanei_genesys_init_structs()
270 dev->frontend_initial = frontend; in sanei_genesys_init_structs()
271 dev->frontend = frontend; in sanei_genesys_init_structs()
277 if (dev->model->asic_type == AsicType::GL845 || in sanei_genesys_init_structs()
278 dev->model->asic_type == AsicType::GL846 || in sanei_genesys_init_structs()
279 dev->model->asic_type == AsicType::GL847 || in sanei_genesys_init_structs()
280 dev->model->asic_type == AsicType::GL124) in sanei_genesys_init_structs()
284 if (memory_layout.models.matches(dev->model->model_id)) { in sanei_genesys_init_structs()
285 dev->memory_layout = memory_layout; in sanei_genesys_init_structs()
297 static_cast<unsigned>(dev->model->sensor_id), in sanei_genesys_init_structs()
298 static_cast<unsigned>(dev->model->gpio_id), in sanei_genesys_init_structs()
299 static_cast<unsigned>(dev->model->motor_id)); in sanei_genesys_init_structs()
313 void sanei_genesys_create_gamma_table(std::vector<std::uint16_t>& gamma_table, int size, in sanei_genesys_create_gamma_table()
326 … value = static_cast<float>(gamma_max * std::pow(static_cast<double>(i) / size, 1.0 / gamma)); in sanei_genesys_create_gamma_table()
330 gamma_table[i] = static_cast<std::uint16_t>(value); in sanei_genesys_create_gamma_table()
336 std::vector<std::uint16_t>& gamma_table, float gamma) in sanei_genesys_create_default_gamma_table()
340 if (dev->model->asic_type == AsicType::GL646) { in sanei_genesys_create_default_gamma_table()
341 if (has_flag(dev->model->flags, ModelFlag::GAMMA_14BIT)) { in sanei_genesys_create_default_gamma_table()
346 max = size - 1; in sanei_genesys_create_default_gamma_table()
347 } else if (dev->model->asic_type == AsicType::GL124 || in sanei_genesys_create_default_gamma_table()
348 dev->model->asic_type == AsicType::GL845 || in sanei_genesys_create_default_gamma_table()
349 dev->model->asic_type == AsicType::GL846 || in sanei_genesys_create_default_gamma_table()
350 dev->model->asic_type == AsicType::GL847) { in sanei_genesys_create_default_gamma_table()
376 int exposure_by_motor = static_cast<int>((max_speed_motor_w * dev->motor.base_ydpi) / ydpi); in sanei_genesys_exposure_time2()
384 if (exposure < exposure_by_led && dev->model->is_cis) { in sanei_genesys_exposure_time2()
399 std::uint8_t* data, int size) in genesys_send_offset_and_shading()
407 if (dev->cmd_set->has_send_shading_data()) { in genesys_send_offset_and_shading()
408 dev->cmd_set->send_shading_data(dev, sensor, data, size); in genesys_send_offset_and_shading()
414 dev->interface->write_buffer(0x3c, start_address, data, size); in genesys_send_offset_and_shading()
422 if (dev->cmd_set->has_send_shading_data()) { in sanei_genesys_init_shading_data()
428 unsigned channels = dev->settings.get_channels(); in sanei_genesys_init_shading_data()
431 std::vector<std::uint8_t> shading_data(pixels_per_line * 4 * channels, 0); in sanei_genesys_init_shading_data()
433 std::uint8_t* shading_data_ptr = shading_data.data(); in sanei_genesys_init_shading_data()
439 *shading_data_ptr++ = 0x40; /* white hi -> 0x4000 */ in sanei_genesys_init_shading_data()
452 switch (dev.model->asic_type) { in scanner_clear_scan_and_feed_counts()
454 dev.interface->write_register(gl841::REG_0x0D, in scanner_clear_scan_and_feed_counts()
459 dev.interface->write_register(gl842::REG_0x0D, in scanner_clear_scan_and_feed_counts()
464 dev.interface->write_register(gl843::REG_0x0D, in scanner_clear_scan_and_feed_counts()
470 dev.interface->write_register(gl846::REG_0x0D, in scanner_clear_scan_and_feed_counts()
475 dev.interface->write_register(gl847::REG_0x0D, in scanner_clear_scan_and_feed_counts()
480 dev.interface->write_register(gl124::REG_0x0D, in scanner_clear_scan_and_feed_counts()
490 const std::vector<std::uint16_t>& slope_table) in scanner_send_slope_table()
495 switch (dev->model->asic_type) { in scanner_send_slope_table()
518 std::vector<std::uint8_t> table; in scanner_send_slope_table()
520 for (std::size_t i = 0; i < slope_table.size(); i++) { in scanner_send_slope_table()
524 if (dev->model->asic_type == AsicType::GL841 || in scanner_send_slope_table()
525 dev->model->model_id == ModelId::CANON_LIDE_90) in scanner_send_slope_table()
528 auto max_table_size = get_slope_table_max_size(dev->model->asic_type); in scanner_send_slope_table()
536 if (dev->interface->is_mock()) { in scanner_send_slope_table()
537 dev->interface->record_slope_table(table_nr, slope_table); in scanner_send_slope_table()
540 switch (dev->model->asic_type) { in scanner_send_slope_table()
542 unsigned dpihw = dev->reg.find_reg(0x05).value >> 6; in scanner_send_slope_table()
553 dev->interface->write_buffer(0x3c, start_address + table_nr * 0x100, table.data(), in scanner_send_slope_table()
566 dev->interface->write_buffer(0x3c, start_address + table_nr * 0x200, table.data(), in scanner_send_slope_table()
573 dev->interface->write_gamma(0x28, 0x40000 + 0x8000 * table_nr, table.data(), in scanner_send_slope_table()
582 dev->interface->write_ahb(0x10000000 + 0x4000 * table_nr, table.size(), in scanner_send_slope_table()
594 switch (dev.model->asic_type) { in scanner_is_motor_stopped()
601 auto reg = dev.interface->read_register(gl841::REG_0x40); in scanner_is_motor_stopped()
608 auto reg = dev.interface->read_register(gl842::REG_0x40); in scanner_is_motor_stopped()
615 auto reg = dev.interface->read_register(gl843::REG_0x40); in scanner_is_motor_stopped()
623 auto reg = dev.interface->read_register(gl846::REG_0x40); in scanner_is_motor_stopped()
630 auto reg = dev.interface->read_register(gl847::REG_0x40); in scanner_is_motor_stopped()
637 auto reg = dev.interface->read_register(gl124::REG_0x100); in scanner_is_motor_stopped()
656 if (dev.model->asic_type != AsicType::GL843) in scanner_setup_sensor()
659 regs_set_exposure(dev.model->asic_type, regs, sensor.exposure); in scanner_setup_sensor()
669 switch (dev.model->asic_type) { in scanner_stop_action()
682 dev.cmd_set->update_home_sensor_gpio(dev); in scanner_stop_action()
700 dev.interface->sleep_ms(100); in scanner_stop_action()
708 switch (dev.model->asic_type) { in scanner_stop_action_no_move()
722 regs_set_optical_off(dev.model->asic_type, regs); in scanner_stop_action_no_move()
724 dev.interface->write_register(0x01, regs.get8(0x01)); in scanner_stop_action_no_move()
728 dev.interface->sleep_ms(100); in scanner_stop_action_no_move()
737 unsigned resolution = dev.model->get_resolution_settings(scan_method).get_min_resolution_y(); in scanner_move()
743 (!has_flag(dev.model->flags, ModelFlag::UTA_NO_SECONDARY_MOTOR)); in scanner_move()
746 dev.model->default_method == ScanMethod::FLATBED; in scanner_move()
786 if (dev.model->asic_type == AsicType::GL124) { in scanner_move()
796 dev.cmd_set->init_regs_for_scan_session(&dev, sensor, &local_reg, session); in scanner_move()
798 if (dev.model->asic_type != AsicType::GL843) { in scanner_move()
799 regs_set_exposure(dev.model->asic_type, local_reg, in scanner_move()
804 dev.interface->write_registers(local_reg); in scanner_move()
806 dev.cmd_set->set_motor_mode(dev, local_reg, MotorMode::PRIMARY_AND_SECONDARY); in scanner_move()
813 dev.cmd_set->set_motor_mode(dev, local_reg, MotorMode::PRIMARY); in scanner_move()
817 catch_all_exceptions(__func__, [&]() { dev.interface->write_registers(dev.reg); }); in scanner_move()
822 dev.interface->test_checkpoint("feed"); in scanner_move()
831 dev.cmd_set->set_motor_mode(dev, local_reg, MotorMode::PRIMARY); in scanner_move()
837 if (dev.model->model_id == ModelId::CANON_LIDE_700F) { in scanner_move()
838 dev.cmd_set->update_home_sensor_gpio(dev); in scanner_move()
850 dev.interface->sleep_ms(10); in scanner_move()
855 dev.cmd_set->set_motor_mode(dev, local_reg, MotorMode::PRIMARY); in scanner_move()
864 dev.interface->sleep_ms(100); in scanner_move()
871 unsigned feed = static_cast<unsigned>((dev.model->y_offset_sensor_to_ta * dev.motor.base_ydpi) / in scanner_move_to_ta()
873 scanner_move(dev, dev.model->default_method, feed, Direction::FORWARD); in scanner_move_to_ta()
880 switch (dev.model->asic_type) { in scanner_move_back_home()
893 if (dev.model->is_sheetfed) { in scanner_move_back_home()
903 (!has_flag(dev.model->flags, ModelFlag::UTA_NO_SECONDARY_MOTOR))) in scanner_move_back_home()
912 scanner_move(dev, dev.model->default_method, dev.head_pos(ScanHeadId::PRIMARY) - 500, in scanner_move_back_home()
916 dev.cmd_set->update_home_sensor_gpio(dev); in scanner_move_back_home()
929 const auto& sensor = sanei_genesys_find_sensor(&dev, resolution, 1, dev.model->default_method); in scanner_move_back_home()
952 if (dev.model->asic_type == AsicType::GL843) { in scanner_move_back_home()
958 dev.cmd_set->init_regs_for_scan_session(&dev, sensor, &local_reg, session); in scanner_move_back_home()
962 dev.interface->write_registers(local_reg); in scanner_move_back_home()
964 if (dev.model->asic_type == AsicType::GL124) { in scanner_move_back_home()
975 dev.interface->write_registers(dev.reg); in scanner_move_back_home()
980 dev.cmd_set->update_home_sensor_gpio(dev); in scanner_move_back_home()
983 dev.interface->test_checkpoint("move_back_home"); in scanner_move_back_home()
994 if (dev.model->asic_type == AsicType::GL846 || in scanner_move_back_home()
995 dev.model->asic_type == AsicType::GL847) in scanner_move_back_home()
1003 dev.interface->sleep_ms(100); in scanner_move_back_home()
1021 bool supports = dev.model->model_id == ModelId::CANON_8600F; in should_use_secondary_motor_mode()
1048 switch (dev.model->asic_type) { in scanner_move_back_home_ta()
1060 unsigned resolution = dev.model->get_resolution_settings(scan_method).get_min_resolution_y(); in scanner_move_back_home_ta()
1070 scanner_move(dev, scan_method, dev.head_pos(ScanHeadId::SECONDARY) - 500, in scanner_move_back_home_ta()
1097 dev.cmd_set->init_regs_for_scan_session(&dev, sensor, &local_reg, session); in scanner_move_back_home_ta()
1101 dev.interface->write_registers(local_reg); in scanner_move_back_home_ta()
1106 dev.cmd_set->set_motor_mode(dev, local_reg, motor_mode); in scanner_move_back_home_ta()
1113 catch_all_exceptions(__func__, [&]() { dev.interface->write_registers(dev.reg); }); in scanner_move_back_home_ta()
1118 dev.interface->test_checkpoint("move_back_home_ta"); in scanner_move_back_home_ta()
1123 dev.cmd_set->set_motor_mode(dev, local_reg, MotorMode::PRIMARY); in scanner_move_back_home_ta()
1137 dev.cmd_set->set_motor_mode(dev, local_reg, MotorMode::PRIMARY); in scanner_move_back_home_ta()
1141 dev.interface->sleep_ms(100); in scanner_move_back_home_ta()
1151 if (dev.model->asic_type == AsicType::GL841 && !black && forward) { in scanner_search_strip()
1158 const auto& resolution_settings = dev.model->get_resolution_settings(dev.settings.scan_method); in scanner_search_strip()
1163 dev.cmd_set->set_fe(&dev, sensor, AFE_SET); in scanner_search_strip()
1168 unsigned lines = static_cast<unsigned>(dev.model->y_size_calib_mm * dpi / MM_PER_INCH); in scanner_search_strip()
1169 if (dev.model->asic_type == AsicType::GL841) { in scanner_search_strip()
1170 lines = 10; // TODO: use dev.model->search_lines in scanner_search_strip()
1174 unsigned pixels = dev.model->x_size_calib_mm * dpi / MM_PER_INCH; in scanner_search_strip()
1179 if (dev.model->asic_type == AsicType::GL841) { in scanner_search_strip()
1202 if (dev.model->asic_type != AsicType::GL841 && !forward) { in scanner_search_strip()
1207 dev.cmd_set->init_regs_for_scan_session(&dev, sensor, &local_reg, session); in scanner_search_strip()
1209 dev.interface->write_registers(local_reg); in scanner_search_strip()
1211 dev.cmd_set->begin_scan(&dev, sensor, &local_reg, true); in scanner_search_strip()
1214 dev.interface->test_checkpoint("search_strip"); in scanner_search_strip()
1229 std::sprintf(title, "gl_search_strip_%s_%s%02d.tiff", in scanner_search_strip()
1237 dev.interface->write_registers(local_reg); in scanner_search_strip()
1240 dev.cmd_set->begin_scan(&dev, sensor, &local_reg, true); in scanner_search_strip()
1251 std::sprintf(title, "gl_search_strip_%s_%s%02d.tiff", in scanner_search_strip()
1260 std::size_t count = 0; in scanner_search_strip()
1266 for (std::size_t y = 0; y < image.get_height() && !found; y++) { in scanner_search_strip()
1270 for (std::size_t x = 0; x < image.get_width(); x++) { in scanner_search_strip()
1302 for (std::size_t y = 0; y < image.get_height(); y++) { in scanner_search_strip()
1304 for (std::size_t x = 0; x < image.get_width(); x++) { in scanner_search_strip()
1350 for (std::size_t y = 1; y < image.get_height(); y++) { in dark_average_channel()
1371 if (dev.model->model_id == ModelId::CANON_4400F && settings.xres >= 4800) { in should_calibrate_only_active_area()
1374 if (dev.model->model_id == ModelId::CANON_8600F && settings.xres == 4800) { in should_calibrate_only_active_area()
1386 if (dev.model->asic_type == AsicType::GL842 && in scanner_offset_calibration()
1392 if (dev.model->asic_type == AsicType::GL843 && in scanner_offset_calibration()
1398 if (dev.model->asic_type == AsicType::GL845 || in scanner_offset_calibration()
1399 dev.model->asic_type == AsicType::GL846) in scanner_offset_calibration()
1402 std::uint8_t reg04 = dev.interface->read_register(gl846::REG_0x04); in scanner_offset_calibration()
1407 if (dev.model->asic_type == AsicType::GL847) { in scanner_offset_calibration()
1409 std::uint8_t reg04 = dev.interface->read_register(gl847::REG_0x04); in scanner_offset_calibration()
1415 if (dev.model->asic_type == AsicType::GL124) { in scanner_offset_calibration()
1416 std::uint8_t reg0a = dev.interface->read_register(gl124::REG_0x0A); in scanner_offset_calibration()
1422 unsigned target_pixels = dev.model->x_size_calib_mm * sensor.full_resolution / MM_PER_INCH; in scanner_offset_calibration()
1431 if (dev.model->asic_type == AsicType::GL843) { in scanner_offset_calibration()
1443 target_pixels = dev.model->x_size_calib_mm * resolution / MM_PER_INCH; in scanner_offset_calibration()
1444 black_pixels = calib_sensor->black_pixels / factor; in scanner_offset_calibration()
1447 float offset = dev.model->x_offset_ta; in scanner_offset_calibration()
1448 … start_pixel = static_cast<int>((offset * calib_sensor->get_optical_resolution()) / MM_PER_INCH); in scanner_offset_calibration()
1450 float size = dev.model->x_size_ta; in scanner_offset_calibration()
1451 … target_pixels = static_cast<int>((size * calib_sensor->get_optical_resolution()) / MM_PER_INCH); in scanner_offset_calibration()
1454 if (dev.model->model_id == ModelId::CANON_4400F && in scanner_offset_calibration()
1461 if (dev.model->model_id == ModelId::CANON_5600F) { in scanner_offset_calibration()
1466 if (dev.model->asic_type == AsicType::GL847) { in scanner_offset_calibration()
1494 session.params.color_filter = dev.model->asic_type == AsicType::GL843 ? ColorFilter::RED in scanner_offset_calibration()
1501 dev.cmd_set->init_regs_for_scan_session(&dev, *calib_sensor, &regs, session); in scanner_offset_calibration()
1517 dev.cmd_set->set_fe(&dev, *calib_sensor, AFE_SET); in scanner_offset_calibration()
1520 dev.interface->write_registers(regs); in scanner_offset_calibration()
1523 dev.cmd_set->begin_scan(&dev, *calib_sensor, &regs, true); in scanner_offset_calibration()
1526 dev.interface->test_checkpoint("offset_calibration"); in scanner_offset_calibration()
1527 if (dev.model->asic_type == AsicType::GL842 || in scanner_offset_calibration()
1528 dev.model->asic_type == AsicType::GL843) in scanner_offset_calibration()
1536 if (dev.model->asic_type == AsicType::GL842 || in scanner_offset_calibration()
1537 dev.model->asic_type == AsicType::GL843) in scanner_offset_calibration()
1545 if (dev.model->model_id == ModelId::CANON_5600F) { in scanner_offset_calibration()
1552 std::snprintf(fn, 40, "gl843_bottom_offset_%03d_%03d_%03d.tiff", in scanner_offset_calibration()
1567 dev.cmd_set->set_fe(&dev, *calib_sensor, AFE_SET); in scanner_offset_calibration()
1570 dev.interface->write_registers(regs); in scanner_offset_calibration()
1573 dev.cmd_set->begin_scan(&dev, *calib_sensor, &regs, true); in scanner_offset_calibration()
1576 if (dev.model->asic_type == AsicType::GL842 || in scanner_offset_calibration()
1577 dev.model->asic_type == AsicType::GL843) in scanner_offset_calibration()
1585 if (dev.model->model_id == ModelId::CANON_5600F) { in scanner_offset_calibration()
1597 std::vector<std::uint8_t> debug_image; in scanner_offset_calibration()
1598 std::size_t debug_image_lines = 0; in scanner_offset_calibration()
1599 std::string debug_image_info; in scanner_offset_calibration()
1602 while ((pass < 32) && ((top[0] - bottom[0] > 1) || in scanner_offset_calibration()
1603 (top[1] - bottom[1] > 1) || in scanner_offset_calibration()
1604 (top[2] - bottom[2] > 1))) in scanner_offset_calibration()
1609 if (top[ch] - bottom[ch] > 1) { in scanner_offset_calibration()
1613 dev.cmd_set->set_fe(&dev, *calib_sensor, AFE_SET); in scanner_offset_calibration()
1616 dev.interface->write_registers(regs); in scanner_offset_calibration()
1618 dev.cmd_set->begin_scan(&dev, *calib_sensor, &regs, true); in scanner_offset_calibration()
1620 if (dev.model->asic_type == AsicType::GL842 || in scanner_offset_calibration()
1621 dev.model->asic_type == AsicType::GL843) in scanner_offset_calibration()
1629 if (dev.model->model_id == ModelId::CANON_5600F) { in scanner_offset_calibration()
1636 std::snprintf(title, 100, "lines: %d pixels_per_line: %d offsets[0..2]: %d %d %d\n", in scanner_offset_calibration()
1642 std::copy(second_line.get_row_ptr(0), in scanner_offset_calibration()
1644 std::back_inserter(debug_image)); in scanner_offset_calibration()
1668 reinterpret_cast<const std::uint8_t*>(debug_image_info.data()), in scanner_offset_calibration()
1689 if (dev.model->asic_type == AsicType::GL842 && in scanner_coarse_gain_calibration()
1695 if (dev.model->asic_type == AsicType::GL843 && in scanner_coarse_gain_calibration()
1701 if (dev.model->asic_type == AsicType::GL845 || in scanner_coarse_gain_calibration()
1702 dev.model->asic_type == AsicType::GL846) in scanner_coarse_gain_calibration()
1705 std::uint8_t reg04 = dev.interface->read_register(gl846::REG_0x04); in scanner_coarse_gain_calibration()
1711 if (dev.model->asic_type == AsicType::GL847) { in scanner_coarse_gain_calibration()
1713 std::uint8_t reg04 = dev.interface->read_register(gl847::REG_0x04); in scanner_coarse_gain_calibration()
1719 if (dev.model->asic_type == AsicType::GL124) { in scanner_coarse_gain_calibration()
1721 std::uint8_t reg0a = dev.interface->read_register(gl124::REG_0x0A); in scanner_coarse_gain_calibration()
1727 if (dev.model->asic_type == AsicType::GL841) { in scanner_coarse_gain_calibration()
1729 if (dev.model->y_offset_calib_white > 0) { in scanner_coarse_gain_calibration()
1731 (dev.model->y_offset_calib_white * (dev.motor.base_ydpi)) / MM_PER_INCH); in scanner_coarse_gain_calibration()
1732 scanner_move(dev, dev.model->default_method, move, Direction::FORWARD); in scanner_coarse_gain_calibration()
1740 if (dev.model->asic_type == AsicType::GL841) { in scanner_coarse_gain_calibration()
1746 if (dev.model->asic_type == AsicType::GL842 || in scanner_coarse_gain_calibration()
1747 dev.model->asic_type == AsicType::GL843) in scanner_coarse_gain_calibration()
1757 if (dev.model->sensor_id == SensorId::CCD_KVSS080 || in scanner_coarse_gain_calibration()
1758 dev.model->asic_type == AsicType::GL845 || in scanner_coarse_gain_calibration()
1759 dev.model->asic_type == AsicType::GL846 || in scanner_coarse_gain_calibration()
1760 dev.model->asic_type == AsicType::GL847 || in scanner_coarse_gain_calibration()
1761 dev.model->asic_type == AsicType::GL124) in scanner_coarse_gain_calibration()
1769 if (dev.model->asic_type == AsicType::GL841) { in scanner_coarse_gain_calibration()
1774 if (dev.model->asic_type == AsicType::GL841 || in scanner_coarse_gain_calibration()
1775 dev.model->asic_type == AsicType::GL842 || in scanner_coarse_gain_calibration()
1776 dev.model->asic_type == AsicType::GL843 || in scanner_coarse_gain_calibration()
1777 dev.model->asic_type == AsicType::GL847) in scanner_coarse_gain_calibration()
1797 session.params.yres = dev.model->asic_type == AsicType::GL841 ? dev.settings.yres : resolution; in scanner_coarse_gain_calibration()
1800 session.params.pixels = dev.model->x_size_calib_mm * resolution / MM_PER_INCH; in scanner_coarse_gain_calibration()
1802 session.params.depth = dev.model->asic_type == AsicType::GL841 ? 16 : 8; in scanner_coarse_gain_calibration()
1812 std::size_t pixels = session.output_pixels; in scanner_coarse_gain_calibration()
1815 dev.cmd_set->init_regs_for_scan_session(&dev, *calib_sensor, &regs, session); in scanner_coarse_gain_calibration()
1817 if (dev.model->asic_type != AsicType::GL841) { in scanner_coarse_gain_calibration()
1823 if (dev.model->asic_type != AsicType::GL841) { in scanner_coarse_gain_calibration()
1827 dev.interface->write_registers(regs); in scanner_coarse_gain_calibration()
1829 if (dev.model->asic_type != AsicType::GL841) { in scanner_coarse_gain_calibration()
1830 dev.cmd_set->set_fe(&dev, *calib_sensor, AFE_SET); in scanner_coarse_gain_calibration()
1832 dev.cmd_set->begin_scan(&dev, *calib_sensor, &regs, true); in scanner_coarse_gain_calibration()
1835 dev.interface->test_checkpoint("coarse_gain_calibration"); in scanner_coarse_gain_calibration()
1837 dev.cmd_set->move_back_home(&dev, true); in scanner_coarse_gain_calibration()
1842 if (dev.model->asic_type == AsicType::GL842 || in scanner_coarse_gain_calibration()
1843 dev.model->asic_type == AsicType::GL843) in scanner_coarse_gain_calibration()
1846 } else if (dev.model->asic_type == AsicType::GL124) { in scanner_coarse_gain_calibration()
1853 if (dev.model->asic_type == AsicType::GL842 || in scanner_coarse_gain_calibration()
1854 dev.model->asic_type == AsicType::GL843) in scanner_coarse_gain_calibration()
1867 if (dev.model->asic_type == AsicType::GL841 || in scanner_coarse_gain_calibration()
1868 dev.model->asic_type == AsicType::GL842 || in scanner_coarse_gain_calibration()
1869 dev.model->asic_type == AsicType::GL843) in scanner_coarse_gain_calibration()
1871 std::vector<std::uint16_t> values; in scanner_coarse_gain_calibration()
1874 for (std::size_t x = pixels / 4; x < (pixels * 3 / 4); x++) { in scanner_coarse_gain_calibration()
1880 std::sort(values.begin(), values.end()); in scanner_coarse_gain_calibration()
1881 curr_output = static_cast<float>(values[unsigned((values.size() - 1) * 0.95)]); in scanner_coarse_gain_calibration()
1882 target_value = calib_sensor->gain_white_ref * coeff; in scanner_coarse_gain_calibration()
1888 std::uint64_t total = 0; in scanner_coarse_gain_calibration()
1889 for (std::size_t x = width / 4; x < (width * 3 / 4); x++) { in scanner_coarse_gain_calibration()
1894 target_value = calib_sensor->gain_white_ref * coeff; in scanner_coarse_gain_calibration()
1897 std::uint8_t out_gain = compute_frontend_gain(curr_output, target_value, in scanner_coarse_gain_calibration()
1904 if (dev.model->asic_type == AsicType::GL841 && in scanner_coarse_gain_calibration()
1921 if (dev.model->is_cis) { in scanner_coarse_gain_calibration()
1922 std::uint8_t min_gain = std::min({dev.frontend.get_gain(0), in scanner_coarse_gain_calibration()
1936 dev.cmd_set->move_back_home(&dev, true); in scanner_coarse_gain_calibration()
1951 if (dev.model->asic_type == AsicType::GL841) { in scanner_led_calibration()
1952 if (dev.model->y_offset_calib_white > 0) { in scanner_led_calibration()
1953 move = (dev.model->y_offset_calib_white * (dev.motor.base_ydpi)) / MM_PER_INCH; in scanner_led_calibration()
1954 scanner_move(dev, dev.model->default_method, static_cast<unsigned>(move), in scanner_led_calibration()
1957 } else if (dev.model->asic_type == AsicType::GL842 || in scanner_led_calibration()
1958 dev.model->asic_type == AsicType::GL843) in scanner_led_calibration()
1961 } else if (dev.model->asic_type == AsicType::GL845 || in scanner_led_calibration()
1962 dev.model->asic_type == AsicType::GL846 || in scanner_led_calibration()
1963 dev.model->asic_type == AsicType::GL847) in scanner_led_calibration()
1965 move = dev.model->y_offset_calib_white; in scanner_led_calibration()
1968 scanner_move(dev, dev.model->default_method, static_cast<unsigned>(move), in scanner_led_calibration()
1971 } else if (dev.model->asic_type == AsicType::GL124) { in scanner_led_calibration()
1981 if (dev.model->asic_type == AsicType::GL841 || in scanner_led_calibration()
1982 dev.model->asic_type == AsicType::GL845 || in scanner_led_calibration()
1983 dev.model->asic_type == AsicType::GL846 || in scanner_led_calibration()
1984 dev.model->asic_type == AsicType::GL847 || in scanner_led_calibration()
1985 dev.model->asic_type == AsicType::GL124) in scanner_led_calibration()
1995 session.params.pixels = dev.model->x_size_calib_mm * resolution / MM_PER_INCH; in scanner_led_calibration()
2011 dev.cmd_set->init_regs_for_scan_session(&dev, calib_sensor, &regs, session); in scanner_led_calibration()
2013 std::uint16_t exp[3]; in scanner_led_calibration()
2019 std::uint16_t target = sensor.gain_white_ref * 256; in scanner_led_calibration()
2021 std::uint16_t top[3] = {}; in scanner_led_calibration()
2022 std::uint16_t bottom[3] = {}; in scanner_led_calibration()
2024 if (dev.model->asic_type == AsicType::GL845 || in scanner_led_calibration()
2025 dev.model->asic_type == AsicType::GL846) in scanner_led_calibration()
2034 } else if (dev.model->asic_type == AsicType::GL847) { in scanner_led_calibration()
2044 if (dev.model->asic_type == AsicType::GL845 || in scanner_led_calibration()
2045 dev.model->asic_type == AsicType::GL846 || in scanner_led_calibration()
2046 dev.model->asic_type == AsicType::GL847 || in scanner_led_calibration()
2047 dev.model->asic_type == AsicType::GL124) in scanner_led_calibration()
2054 regs_set_exposure(dev.model->asic_type, regs, { exp[0], exp[1], exp[2] }); in scanner_led_calibration()
2056 dev.interface->write_registers(regs); in scanner_led_calibration()
2059 dev.cmd_set->begin_scan(&dev, calib_sensor, &regs, true); in scanner_led_calibration()
2062 dev.interface->test_checkpoint("led_calibration"); in scanner_led_calibration()
2063 if (dev.model->asic_type == AsicType::GL841) { in scanner_led_calibration()
2065 dev.cmd_set->move_back_home(&dev, true); in scanner_led_calibration()
2066 } else if (dev.model->asic_type == AsicType::GL124) { in scanner_led_calibration()
2070 dev.cmd_set->move_back_home(&dev, true); in scanner_led_calibration()
2081 std::snprintf(fn, 30, "gl_led_%02d.tiff", i_test); in scanner_led_calibration()
2088 for (std::size_t x = 0; x < image.get_width(); x++) { in scanner_led_calibration()
2098 if (dev.model->asic_type == AsicType::GL845 || in scanner_led_calibration()
2099 dev.model->asic_type == AsicType::GL846) in scanner_led_calibration()
2119 } else if (dev.model->asic_type == AsicType::GL847) { in scanner_led_calibration()
2132 } else if (dev.model->asic_type == AsicType::GL841 || in scanner_led_calibration()
2133 dev.model->asic_type == AsicType::GL124) in scanner_led_calibration()
2136 // we accept +- 2% delta from target in scanner_led_calibration()
2137 if (std::abs(avg[i] - target) > target / 50) { in scanner_led_calibration()
2140 … exp[i] = exp[i] * prev_weight + ((exp[i] * target) / avg[i]) * (1 - prev_weight); in scanner_led_calibration()
2142 exp[i] = exp[i] * prev_weight + (exp[i] * 10) * (1 - prev_weight); in scanner_led_calibration()
2150 if (dev.model->asic_type == AsicType::GL845 || in scanner_led_calibration()
2151 dev.model->asic_type == AsicType::GL846 || in scanner_led_calibration()
2152 dev.model->asic_type == AsicType::GL847 || in scanner_led_calibration()
2153 dev.model->asic_type == AsicType::GL124) in scanner_led_calibration()
2156 regs_set_exposure(dev.model->asic_type, dev.reg, { exp[0], exp[1], exp[2] }); in scanner_led_calibration()
2159 if (dev.model->asic_type == AsicType::GL841 || in scanner_led_calibration()
2160 dev.model->asic_type == AsicType::GL842 || in scanner_led_calibration()
2161 dev.model->asic_type == AsicType::GL843) in scanner_led_calibration()
2163 dev.cmd_set->move_back_home(&dev, true); in scanner_led_calibration()
2166 if (dev.model->asic_type == AsicType::GL845 || in scanner_led_calibration()
2167 dev.model->asic_type == AsicType::GL846 || in scanner_led_calibration()
2168 dev.model->asic_type == AsicType::GL847) in scanner_led_calibration()
2171 dev.cmd_set->move_back_home(&dev, true); in scanner_led_calibration()
2181 std::uint32_t exposure_time, in sanei_genesys_calculate_zmod()
2182 const std::vector<std::uint16_t>& slope_table, in sanei_genesys_calculate_zmod()
2186 std::uint32_t* out_z1, std::uint32_t* out_z2) in sanei_genesys_calculate_zmod()
2189 unsigned sum = std::accumulate(slope_table.begin(), slope_table.begin() + acceleration_steps, in sanei_genesys_calculate_zmod()
2190 0, std::plus<unsigned>()); in sanei_genesys_calculate_zmod()
2197 … *out_z1 = (sum + buffer_acceleration_steps * slope_table[acceleration_steps - 1]) % exposure_time; in sanei_genesys_calculate_zmod()
2205 sum = sum + (move_steps * slope_table[acceleration_steps - 1]); in sanei_genesys_calculate_zmod()
2207 sum = sum + slope_table[acceleration_steps - 1]; in sanei_genesys_calculate_zmod()
2219 std::vector<std::uint16_t>& out_average_data, in genesys_shading_calibration_impl()
2220 bool is_dark, const std::string& log_filename_prefix) in genesys_shading_calibration_impl()
2224 if (dev->model->asic_type == AsicType::GL646) { in genesys_shading_calibration_impl()
2225 dev->cmd_set->init_regs_for_shading(dev, sensor, local_reg); in genesys_shading_calibration_impl()
2226 local_reg = dev->reg; in genesys_shading_calibration_impl()
2228 local_reg = dev->reg; in genesys_shading_calibration_impl()
2229 dev->cmd_set->init_regs_for_shading(dev, sensor, local_reg); in genesys_shading_calibration_impl()
2230 dev->interface->write_registers(local_reg); in genesys_shading_calibration_impl()
2233 debug_dump(DBG_info, dev->calib_session); in genesys_shading_calibration_impl()
2236 std::uint32_t pixels_per_line; in genesys_shading_calibration_impl()
2238 if (dev->model->asic_type == AsicType::GL842 || in genesys_shading_calibration_impl()
2239 dev->model->asic_type == AsicType::GL843 || in genesys_shading_calibration_impl()
2240 dev->model->model_id == ModelId::CANON_5600F) in genesys_shading_calibration_impl()
2242 pixels_per_line = dev->calib_session.output_pixels; in genesys_shading_calibration_impl()
2245 pixels_per_line = dev->calib_session.params.pixels; in genesys_shading_calibration_impl()
2247 unsigned channels = dev->calib_session.params.channels; in genesys_shading_calibration_impl()
2251 … dev->calib_session.params.startx * sensor.full_resolution / dev->calib_session.params.xres; in genesys_shading_calibration_impl()
2256 dev->average_size = channels * out_pixels_per_line; in genesys_shading_calibration_impl()
2259 out_average_data.resize(dev->average_size); in genesys_shading_calibration_impl()
2261 if (is_dark && dev->settings.scan_method == ScanMethod::TRANSPARENCY_INFRARED) { in genesys_shading_calibration_impl()
2266 // FIXME: the current calculation is likely incorrect on non-GL843 implementations, in genesys_shading_calibration_impl()
2268 if (dev->model->asic_type == AsicType::GL842 || in genesys_shading_calibration_impl()
2269 dev->model->asic_type == AsicType::GL843 || in genesys_shading_calibration_impl()
2270 dev->model->model_id == ModelId::CANON_5600F) in genesys_shading_calibration_impl()
2272 size = dev->calib_session.output_total_bytes_raw; in genesys_shading_calibration_impl()
2274 size = channels * 2 * pixels_per_line * (dev->calib_session.params.lines + 1); in genesys_shading_calibration_impl()
2277 std::vector<std::uint16_t> calibration_data(size / 2); in genesys_shading_calibration_impl()
2281 if (is_dark && !dev->model->is_sheetfed) { in genesys_shading_calibration_impl()
2288 dev->interface->write_registers(local_reg); in genesys_shading_calibration_impl()
2292 dev->interface->sleep_ms(200); in genesys_shading_calibration_impl()
2293 } else if (has_flag(dev->model->flags, ModelFlag::DARK_CALIBRATION)) { in genesys_shading_calibration_impl()
2296 dev->interface->sleep_ms(500); in genesys_shading_calibration_impl()
2300 dev->cmd_set->begin_scan(dev, sensor, &local_reg, start_motor); in genesys_shading_calibration_impl()
2304 dev->interface->test_checkpoint(is_dark ? "dark_shading_calibration" in genesys_shading_calibration_impl()
2306 dev->cmd_set->end_scan(dev, &local_reg, true); in genesys_shading_calibration_impl()
2310 …sanei_genesys_read_data_from_scanner(dev, reinterpret_cast<std::uint8_t*>(calibration_data.data()), in genesys_shading_calibration_impl()
2313 dev->cmd_set->end_scan(dev, &local_reg, true); in genesys_shading_calibration_impl()
2315 if (has_flag(dev->model->flags, ModelFlag::SWAP_16BIT_DATA)) { in genesys_shading_calibration_impl()
2316 for (std::size_t i = 0; i < size / 2; ++i) { in genesys_shading_calibration_impl()
2323 if (has_flag(dev->model->flags, ModelFlag::INVERT_PIXEL_DATA)) { in genesys_shading_calibration_impl()
2324 for (std::size_t i = 0; i < size / 2; ++i) { in genesys_shading_calibration_impl()
2325 calibration_data[i] = 0xffff - calibration_data[i]; in genesys_shading_calibration_impl()
2329 std::fill(out_average_data.begin(), in genesys_shading_calibration_impl()
2335 dev->calib_session.params.lines, pixels_per_line * channels, in genesys_shading_calibration_impl()
2340 channels, pixels_per_line, dev->calib_session.params.lines); in genesys_shading_calibration_impl()
2356 std::uint32_t pixels_per_line; in genesys_dark_shading_by_dummy_pixel()
2357 std::uint32_t skip, xend; in genesys_dark_shading_by_dummy_pixel()
2360 if (dev->model->asic_type == AsicType::GL842 || in genesys_dark_shading_by_dummy_pixel()
2361 dev->model->asic_type == AsicType::GL843) in genesys_dark_shading_by_dummy_pixel()
2363 pixels_per_line = dev->calib_session.output_pixels; in genesys_dark_shading_by_dummy_pixel()
2365 pixels_per_line = dev->calib_session.params.pixels; in genesys_dark_shading_by_dummy_pixel()
2368 unsigned channels = dev->calib_session.params.channels; in genesys_dark_shading_by_dummy_pixel()
2372 … dev->calib_session.params.startx * sensor.full_resolution / dev->calib_session.params.xres; in genesys_dark_shading_by_dummy_pixel()
2376 dev->average_size = channels * out_pixels_per_line; in genesys_dark_shading_by_dummy_pixel()
2377 dev->dark_average_data.clear(); in genesys_dark_shading_by_dummy_pixel()
2378 dev->dark_average_data.resize(dev->average_size, 0); in genesys_dark_shading_by_dummy_pixel()
2382 if (dev->settings.xres <= sensor.full_resolution / 2) { in genesys_dark_shading_by_dummy_pixel()
2391 if (dev->model->sensor_id==SensorId::CCD_G4050 || in genesys_dark_shading_by_dummy_pixel()
2392 dev->model->sensor_id==SensorId::CCD_HP_4850C in genesys_dark_shading_by_dummy_pixel()
2393 || dev->model->sensor_id==SensorId::CCD_CANON_4400F in genesys_dark_shading_by_dummy_pixel()
2394 || dev->model->sensor_id==SensorId::CCD_CANON_8400F in genesys_dark_shading_by_dummy_pixel()
2395 || dev->model->sensor_id==SensorId::CCD_KVSS080) in genesys_dark_shading_by_dummy_pixel()
2407 dummy1 += dev->white_average_data[channels * x]; in genesys_dark_shading_by_dummy_pixel()
2409 dummy2 += dev->white_average_data[channels * x + 1]; in genesys_dark_shading_by_dummy_pixel()
2410 dummy3 += dev->white_average_data[channels * x + 2]; in genesys_dark_shading_by_dummy_pixel()
2414 dummy1 /= (xend - skip); in genesys_dark_shading_by_dummy_pixel()
2417 dummy2 /= (xend - skip); in genesys_dark_shading_by_dummy_pixel()
2418 dummy3 /= (xend - skip); in genesys_dark_shading_by_dummy_pixel()
2424 dev->dark_average_data[channels * x] = dummy1; in genesys_dark_shading_by_dummy_pixel()
2426 dev->dark_average_data[channels * x + 1] = dummy2; in genesys_dark_shading_by_dummy_pixel()
2427 dev->dark_average_data[channels * x + 2] = dummy3; in genesys_dark_shading_by_dummy_pixel()
2441 if (has_flag(dev->model->flags, ModelFlag::SHADING_REPARK)) { in genesys_repark_sensor_before_shading()
2442 dev->cmd_set->move_back_home(dev, true); in genesys_repark_sensor_before_shading()
2444 if (dev->settings.scan_method == ScanMethod::TRANSPARENCY || in genesys_repark_sensor_before_shading()
2445 dev->settings.scan_method == ScanMethod::TRANSPARENCY_INFRARED) in genesys_repark_sensor_before_shading()
2455 if (has_flag(dev->model->flags, ModelFlag::SHADING_REPARK)) { in genesys_repark_sensor_after_white_shading()
2456 dev->cmd_set->move_back_home(dev, true); in genesys_repark_sensor_after_white_shading()
2461 std::vector<std::uint16_t>& out_average_data, in genesys_host_shading_calibration_impl()
2463 const std::string& log_filename_prefix) in genesys_host_shading_calibration_impl()
2473 dev.cmd_set->init_regs_for_shading(&dev, sensor, local_reg); in genesys_host_shading_calibration_impl()
2480 if (is_dark && !dev.model->is_sheetfed) { in genesys_host_shading_calibration_impl()
2487 dev.interface->write_registers(local_reg); in genesys_host_shading_calibration_impl()
2491 dev.interface->sleep_ms(200); in genesys_host_shading_calibration_impl()
2492 } else if (has_flag(dev.model->flags, ModelFlag::DARK_CALIBRATION)) { in genesys_host_shading_calibration_impl()
2495 dev.interface->sleep_ms(500); in genesys_host_shading_calibration_impl()
2499 dev.cmd_set->begin_scan(&dev, sensor, &local_reg, start_motor); in genesys_host_shading_calibration_impl()
2502 dev.interface->test_checkpoint(is_dark ? "host_dark_shading_calibration" in genesys_host_shading_calibration_impl()
2504 dev.cmd_set->end_scan(&dev, &local_reg, true); in genesys_host_shading_calibration_impl()
2521 std::fill(out_average_data.begin(), in genesys_host_shading_calibration_impl()
2526 reinterpret_cast<std::uint16_t*>(image.get_row_ptr(0)), in genesys_host_shading_calibration_impl()
2542 if (has_flag(dev->model->flags, ModelFlag::HOST_SIDE_CALIBRATION_COMPLETE_SCAN)) { in genesys_dark_shading_calibration()
2543 genesys_host_shading_calibration_impl(*dev, sensor, dev->dark_average_data, true, in genesys_dark_shading_calibration()
2546 genesys_shading_calibration_impl(dev, sensor, local_reg, dev->dark_average_data, true, in genesys_dark_shading_calibration()
2555 if (has_flag(dev->model->flags, ModelFlag::HOST_SIDE_CALIBRATION_COMPLETE_SCAN)) { in genesys_white_shading_calibration()
2556 genesys_host_shading_calibration_impl(*dev, sensor, dev->white_average_data, false, in genesys_white_shading_calibration()
2559 genesys_shading_calibration_impl(dev, sensor, local_reg, dev->white_average_data, false, in genesys_white_shading_calibration()
2572 if (dev->model->asic_type == AsicType::GL646) { in genesys_dark_white_shading_calibration()
2573 dev->cmd_set->init_regs_for_shading(dev, sensor, local_reg); in genesys_dark_white_shading_calibration()
2574 local_reg = dev->reg; in genesys_dark_white_shading_calibration()
2576 local_reg = dev->reg; in genesys_dark_white_shading_calibration()
2577 dev->cmd_set->init_regs_for_shading(dev, sensor, local_reg); in genesys_dark_white_shading_calibration()
2578 dev->interface->write_registers(local_reg); in genesys_dark_white_shading_calibration()
2581 std::size_t size; in genesys_dark_white_shading_calibration()
2582 std::uint32_t pixels_per_line; in genesys_dark_white_shading_calibration()
2585 if (dev->model->asic_type == AsicType::GL842 || in genesys_dark_white_shading_calibration()
2586 dev->model->asic_type == AsicType::GL843) in genesys_dark_white_shading_calibration()
2588 pixels_per_line = dev->calib_session.output_pixels; in genesys_dark_white_shading_calibration()
2590 pixels_per_line = dev->calib_session.params.pixels; in genesys_dark_white_shading_calibration()
2593 unsigned channels = dev->calib_session.params.channels; in genesys_dark_white_shading_calibration()
2597 … dev->calib_session.params.startx * sensor.full_resolution / dev->calib_session.params.xres; in genesys_dark_white_shading_calibration()
2601 dev->average_size = channels * out_pixels_per_line; in genesys_dark_white_shading_calibration()
2603 dev->white_average_data.clear(); in genesys_dark_white_shading_calibration()
2604 dev->white_average_data.resize(dev->average_size); in genesys_dark_white_shading_calibration()
2606 dev->dark_average_data.clear(); in genesys_dark_white_shading_calibration()
2607 dev->dark_average_data.resize(dev->average_size); in genesys_dark_white_shading_calibration()
2609 if (dev->model->asic_type == AsicType::GL842 || in genesys_dark_white_shading_calibration()
2610 dev->model->asic_type == AsicType::GL843) in genesys_dark_white_shading_calibration()
2612 size = dev->calib_session.output_total_bytes_raw; in genesys_dark_white_shading_calibration()
2614 // FIXME: on GL841 this is different than dev->calib_session.output_total_bytes_raw, in genesys_dark_white_shading_calibration()
2616 size = channels * 2 * pixels_per_line * dev->calib_session.params.lines; in genesys_dark_white_shading_calibration()
2619 std::vector<std::uint8_t> calibration_data(size); in genesys_dark_white_shading_calibration()
2625 dev->interface->write_registers(local_reg); in genesys_dark_white_shading_calibration()
2627 dev->cmd_set->begin_scan(dev, sensor, &local_reg, false); in genesys_dark_white_shading_calibration()
2630 dev->interface->test_checkpoint("dark_white_shading_calibration"); in genesys_dark_white_shading_calibration()
2631 dev->cmd_set->end_scan(dev, &local_reg, true); in genesys_dark_white_shading_calibration()
2637 dev->cmd_set->end_scan(dev, &local_reg, true); in genesys_dark_white_shading_calibration()
2640 if (dev->model->is_cis) { in genesys_dark_white_shading_calibration()
2643 dev->calib_session.params.lines); in genesys_dark_white_shading_calibration()
2647 dev->calib_session.params.lines); in genesys_dark_white_shading_calibration()
2652 std::fill(dev->dark_average_data.begin(), in genesys_dark_white_shading_calibration()
2653 dev->dark_average_data.begin() + start_offset * channels, 0); in genesys_dark_white_shading_calibration()
2654 std::fill(dev->white_average_data.begin(), in genesys_dark_white_shading_calibration()
2655 dev->white_average_data.begin() + start_offset * channels, 0); in genesys_dark_white_shading_calibration()
2657 std::uint16_t* average_white = dev->white_average_data.data() + start_offset * channels; in genesys_dark_white_shading_calibration()
2658 std::uint16_t* average_dark = dev->dark_average_data.data() + start_offset * channels; in genesys_dark_white_shading_calibration()
2662 std::uint32_t dark = 0xffff; in genesys_dark_white_shading_calibration()
2663 std::uint32_t white = 0; in genesys_dark_white_shading_calibration()
2665 for (std::size_t y = 0; y < dev->calib_session.params.lines; y++) in genesys_dark_white_shading_calibration()
2667 std::uint32_t col = calibration_data[(x + y * pixels_per_line * channels) * 2]; in genesys_dark_white_shading_calibration()
2678 std::uint32_t dif = white - dark; in genesys_dark_white_shading_calibration()
2681 white = white - dif / 8; in genesys_dark_white_shading_calibration()
2683 std::uint32_t dark_count = 0; in genesys_dark_white_shading_calibration()
2684 std::uint32_t dark_sum = 0; in genesys_dark_white_shading_calibration()
2686 std::uint32_t white_count = 0; in genesys_dark_white_shading_calibration()
2687 std::uint32_t white_sum = 0; in genesys_dark_white_shading_calibration()
2689 for (std::size_t y = 0; y < dev->calib_session.params.lines; y++) in genesys_dark_white_shading_calibration()
2691 std::uint32_t col = calibration_data[(x + y * pixels_per_line * channels) * 2]; in genesys_dark_white_shading_calibration()
2717 write_tiff_file("gl_white_average.tiff", dev->white_average_data.data(), 16, channels, in genesys_dark_white_shading_calibration()
2719 write_tiff_file("gl_dark_average.tiff", dev->dark_average_data.data(), 16, channels, in genesys_dark_white_shading_calibration()
2724 /* computes one coefficient given bright-dark value
2727 * @param value brght-dark value
2755 * o=(i-off)*(gain/coeff)
2759 * gain=coeff*bright_target/(bright_average-dark_average)
2763 * bright_target=(bright_average-off)*(gain/coeff)
2764 * dark_target=(dark_average-off)*(gain/coeff)
2766 * off = (dark_average*bright_target - bright_average*dark_target)/(bright_target - dark_target)
2767 * gain = (bright_target - dark_target)/(bright_average - dark_average)*coeff
2780 std::uint8_t* shading_data, in compute_averaged_planar()
2799 slope tables - which begin at address 0x10000(for 1200dpi hw mode): in compute_averaged_planar()
2810 o=(i-off)*(gain/coeff) in compute_averaged_planar()
2814 gain=coeff*bright_target/(bright_average-dark_average) in compute_averaged_planar()
2818 bright_target=(bright_average-off)*(gain/coeff) in compute_averaged_planar()
2819 dark_target=(dark_average-off)*(gain/coeff) in compute_averaged_planar()
2821 off = (dark_average*bright_target - bright_average*dark_target)/(bright_target - dark_target) in compute_averaged_planar()
2822 gain = (bright_target - dark_target)/(bright_average - dark_average)*coeff in compute_averaged_planar()
2824 res = dev->settings.xres; in compute_averaged_planar()
2850 if (dev->model->sensor_id != SensorId::CIS_CANON_LIDE_80) in compute_averaged_planar()
2865 for (x = 0; x <= pixels_per_line - avgpixels; x += avgpixels) in compute_averaged_planar()
2878 dk += dev->dark_average_data[(x + i + pixels_per_line * j)]; in compute_averaged_planar()
2880 br += dev->white_average_data[(x + i + pixels_per_line * j)]; in compute_averaged_planar()
2888 else if (dk * target_bright - br * target_dark > in compute_averaged_planar()
2889 65535 * (target_bright - target_dark)) in compute_averaged_planar()
2893 val = (dk * target_bright - br * target_dark) / (target_bright - target_dark); in compute_averaged_planar()
2903 val = br - dk; in compute_averaged_planar()
2905 if (65535 * val > (target_bright - target_dark) * coeff) in compute_averaged_planar()
2907 val = (coeff * (target_bright - target_dark)) / val; in compute_averaged_planar()
2936 static std::array<unsigned, 3> color_order_to_cmat(ColorOrder color_order) in color_order_to_cmat()
2942 throw std::logic_error("Unknown color order"); in color_order_to_cmat()
2960 std::uint8_t* shading_data, in compute_coefficients()
2979 start = -1 * offset; in compute_coefficients()
2985 end = pixels_per_line - offset; in compute_coefficients()
2994 std::uint8_t* ptr = shading_data + 4 * ((x + offset) * channels + cmat[c]); in compute_coefficients()
2997 dk = dev->dark_average_data[x * channels + c]; in compute_coefficients()
3000 br = dev->white_average_data[x * channels + c]; in compute_coefficients()
3003 val=compute_coefficient(coeff,target,br-dk); in compute_coefficients()
3032 std::uint8_t* shading_data, in compute_planar_coefficients()
3042 std::uint32_t i; in compute_planar_coefficients()
3043 std::uint32_t val, dk, br; in compute_planar_coefficients()
3055 std::uint8_t* ptr = shading_data + words_per_color * cmat[c] * 2 + (x + offset) * 4; in compute_planar_coefficients()
3063 dk += dev->dark_average_data[((x+i) + pixels_per_line * c)]; in compute_planar_coefficients()
3064 br += dev->white_average_data[((x+i) + pixels_per_line * c)]; in compute_planar_coefficients()
3069 val = compute_coefficient (coeff, target, br - dk); in compute_planar_coefficients()
3095 std::uint8_t* shading_data, in compute_shifted_coefficients()
3107 std::uint8_t* ptr = shading_data + offset * 3 * 4; // contain 16bit words in little endian in compute_shifted_coefficients()
3112 x = dev->settings.xres; in compute_shifted_coefficients()
3114 x *= 2; // scanner is using half-ccd mode in compute_shifted_coefficients()
3136 for (x = 0; x <= pixels_per_line - avgpixels; x += avgpixels) { in compute_shifted_coefficients()
3142 br_tmp[j] += dev->white_average_data[((x + i) * channels + j)]; in compute_shifted_coefficients()
3143 dk_tmp[i] += dev->dark_average_data[((x + i) * channels + j)]; in compute_shifted_coefficients()
3152 …else if (dk_tmp[j] * target_bright - br_tmp[j] * target_dark > 65535 * (target_bright - target_dar… in compute_shifted_coefficients()
3155 … val1 = (dk_tmp[j] * target_bright - br_tmp[j] * target_dark) / (target_bright - target_dark); in compute_shifted_coefficients()
3157 val2 = br_tmp[j] - dk_tmp[j]; in compute_shifted_coefficients()
3158 if (65535 * val2 > (target_bright - target_dark) * coeff) in compute_shifted_coefficients()
3159 val2 = (coeff * (target_bright - target_dark)) / val2; in compute_shifted_coefficients()
3193 std::uint32_t pixels_per_line; in genesys_send_shading_coefficient()
3202 … dev->calib_session.params.startx * sensor.full_resolution / dev->calib_session.params.xres; in genesys_send_shading_coefficient()
3204 if (dev->model->asic_type == AsicType::GL842 || in genesys_send_shading_coefficient()
3205 dev->model->asic_type == AsicType::GL843) in genesys_send_shading_coefficient()
3207 pixels_per_line = dev->calib_session.output_pixels + start_offset; in genesys_send_shading_coefficient()
3209 pixels_per_line = dev->calib_session.params.pixels + start_offset; in genesys_send_shading_coefficient()
3212 unsigned channels = dev->calib_session.params.channels; in genesys_send_shading_coefficient()
3219 switch (dev->reg.get8(0x05) >> 6) in genesys_send_shading_coefficient()
3242 if(dev->model->sensor_id==SensorId::CIS_CANON_LIDE_80) in genesys_send_shading_coefficient()
3251 std::vector<std::uint8_t> shading_data(length, 0); in genesys_send_shading_coefficient()
3253 if (!dev->calib_session.computed) { in genesys_send_shading_coefficient()
3258 /* TARGET/(Wn-Dn) = white gain -> ~1.xxx then it is multiplied by 0x2000 in genesys_send_shading_coefficient()
3263 if (get_registers_gain4_bit(dev->model->asic_type, dev->reg)) { in genesys_send_shading_coefficient()
3270 if (dev->settings.xres > sensor.full_resolution) { in genesys_send_shading_coefficient()
3273 factor = sensor.full_resolution / dev->settings.xres; in genesys_send_shading_coefficient()
3284 switch (dev->model->sensor_id) in genesys_send_shading_coefficient()
3322 if (dev->settings.xres <= sensor.full_resolution / 2) { in genesys_send_shading_coefficient()
3323 o = o - sensor.dummy_pixel / 2; in genesys_send_shading_coefficient()
3337 if(dev->settings.xres<=sensor.full_resolution/2) in genesys_send_shading_coefficient()
3339 o = o - sensor.dummy_pixel; in genesys_send_shading_coefficient()
3356 if(dev->settings.xres<=300) in genesys_send_shading_coefficient()
3358 o = -10; in genesys_send_shading_coefficient()
3360 else if(dev->settings.xres<=600) in genesys_send_shading_coefficient()
3362 o = -6; in genesys_send_shading_coefficient()
3411 switch(dev->model->sensor_id) in genesys_send_shading_coefficient()
3476 static_cast<unsigned>(dev->model->sensor_id)); in genesys_send_shading_coefficient()
3498 if (dev->calibration_cache.empty()) { in genesys_restore_calibration()
3502 auto session = dev->cmd_set->calculate_scan_session(dev, sensor, dev->settings); in genesys_restore_calibration()
3506 for (auto& cache : dev->calibration_cache) in genesys_restore_calibration()
3509 dev->frontend = cache.frontend; in genesys_restore_calibration()
3513 dev->calib_session = cache.session; in genesys_restore_calibration()
3514 dev->average_size = cache.average_size; in genesys_restore_calibration()
3516 dev->dark_average_data = cache.dark_average_data; in genesys_restore_calibration()
3517 dev->white_average_data = cache.white_average_data; in genesys_restore_calibration()
3519 if (!dev->cmd_set->has_send_shading_data()) { in genesys_restore_calibration()
3539 auto session = dev->cmd_set->calculate_scan_session(dev, sensor, dev->settings); in genesys_save_calibration()
3541 auto found_cache_it = dev->calibration_cache.end(); in genesys_save_calibration()
3542 for (auto cache_it = dev->calibration_cache.begin(); cache_it != dev->calibration_cache.end(); in genesys_save_calibration()
3552 if (found_cache_it == dev->calibration_cache.end()) in genesys_save_calibration()
3555 dev->calibration_cache.push_back(Genesys_Calibration_Cache()); in genesys_save_calibration()
3556 found_cache_it = std::prev(dev->calibration_cache.end()); in genesys_save_calibration()
3559 found_cache_it->average_size = dev->average_size; in genesys_save_calibration()
3561 found_cache_it->dark_average_data = dev->dark_average_data; in genesys_save_calibration()
3562 found_cache_it->white_average_data = dev->white_average_data; in genesys_save_calibration()
3564 found_cache_it->params = session.params; in genesys_save_calibration()
3565 found_cache_it->frontend = dev->frontend; in genesys_save_calibration()
3566 found_cache_it->sensor = sensor; in genesys_save_calibration()
3568 found_cache_it->session = dev->calib_session; in genesys_save_calibration()
3572 found_cache_it->last_calibration = time.tv_sec; in genesys_save_calibration()
3579 std::uint32_t pixels_per_line; in genesys_flatbed_calibration()
3582 if (dev->settings.yres <= sensor.full_resolution / 2) { in genesys_flatbed_calibration()
3586 if (dev->model->model_id == ModelId::CANON_8400F) { in genesys_flatbed_calibration()
3590 if (dev->model->model_id == ModelId::CANON_4400F || in genesys_flatbed_calibration()
3591 dev->model->model_id == ModelId::CANON_8600F) in genesys_flatbed_calibration()
3596 auto local_reg = dev->initial_regs; in genesys_flatbed_calibration()
3598 if (!has_flag(dev->model->flags, ModelFlag::DISABLE_ADC_CALIBRATION)) { in genesys_flatbed_calibration()
3600 dev->interface->record_progress_message("offset_calibration"); in genesys_flatbed_calibration()
3601 dev->cmd_set->offset_calibration(dev, sensor, local_reg); in genesys_flatbed_calibration()
3603 dev->interface->record_progress_message("coarse_gain_calibration"); in genesys_flatbed_calibration()
3604 dev->cmd_set->coarse_gain_calibration(dev, sensor, local_reg, coarse_res); in genesys_flatbed_calibration()
3607 if (dev->model->is_cis && in genesys_flatbed_calibration()
3608 !has_flag(dev->model->flags, ModelFlag::DISABLE_EXPOSURE_CALIBRATION)) in genesys_flatbed_calibration()
3611 dev->interface->record_progress_message("led_calibration"); in genesys_flatbed_calibration()
3612 switch (dev->model->asic_type) { in genesys_flatbed_calibration()
3618 auto calib_exposure = dev->cmd_set->led_calibration(dev, sensor, local_reg); in genesys_flatbed_calibration()
3627 sensor.exposure = dev->cmd_set->led_calibration(dev, sensor, local_reg); in genesys_flatbed_calibration()
3631 if (!has_flag(dev->model->flags, ModelFlag::DISABLE_ADC_CALIBRATION)) { in genesys_flatbed_calibration()
3633 dev->interface->record_progress_message("offset_calibration"); in genesys_flatbed_calibration()
3634 dev->cmd_set->offset_calibration(dev, sensor, local_reg); in genesys_flatbed_calibration()
3636 dev->interface->record_progress_message("coarse_gain_calibration"); in genesys_flatbed_calibration()
3637 dev->cmd_set->coarse_gain_calibration(dev, sensor, local_reg, coarse_res); in genesys_flatbed_calibration()
3641 /* we always use sensor pixel number when the ASIC can't handle multi-segments sensor */ in genesys_flatbed_calibration()
3642 if (!has_flag(dev->model->flags, ModelFlag::SIS_SENSOR)) { in genesys_flatbed_calibration()
3643 pixels_per_line = static_cast<std::uint32_t>((dev->model->x_size * dev->settings.xres) / in genesys_flatbed_calibration()
3646 … pixels_per_line = static_cast<std::uint32_t>((dev->model->x_size_calib_mm * dev->settings.xres) in genesys_flatbed_calibration()
3651 dev->interface->record_progress_message("sanei_genesys_init_shading_data"); in genesys_flatbed_calibration()
3654 if (dev->settings.scan_method == ScanMethod::TRANSPARENCY || in genesys_flatbed_calibration()
3655 dev->settings.scan_method == ScanMethod::TRANSPARENCY_INFRARED) in genesys_flatbed_calibration()
3661 if (!has_flag(dev->model->flags, ModelFlag::DISABLE_SHADING_CALIBRATION)) { in genesys_flatbed_calibration()
3662 if (has_flag(dev->model->flags, ModelFlag::DARK_WHITE_CALIBRATION)) { in genesys_flatbed_calibration()
3663 dev->interface->record_progress_message("genesys_dark_white_shading_calibration"); in genesys_flatbed_calibration()
3669 if (has_flag(dev->model->flags, ModelFlag::DARK_CALIBRATION)) { in genesys_flatbed_calibration()
3670 dev->interface->record_progress_message("genesys_dark_shading_calibration"); in genesys_flatbed_calibration()
3675 dev->interface->record_progress_message("genesys_white_shading_calibration"); in genesys_flatbed_calibration()
3680 if (!has_flag(dev->model->flags, ModelFlag::DARK_CALIBRATION)) { in genesys_flatbed_calibration()
3681 if (has_flag(dev->model->flags, ModelFlag::USE_CONSTANT_FOR_DARK_CALIBRATION)) { in genesys_flatbed_calibration()
3690 if (!dev->cmd_set->has_send_shading_data()) { in genesys_flatbed_calibration()
3691 dev->interface->record_progress_message("genesys_send_shading_coefficient"); in genesys_flatbed_calibration()
3698 * - offset calibration
3699 * - gain calibration
3700 * - shading calibration
3710 auto local_reg = dev->initial_regs; in genesys_sheetfed_calibration()
3713 dev->cmd_set->load_document(dev); in genesys_sheetfed_calibration()
3723 catch_all_exceptions(__func__, [&](){ dev->cmd_set->eject_document(dev); }); in genesys_sheetfed_calibration()
3727 if (!has_flag(dev->model->flags, ModelFlag::DISABLE_ADC_CALIBRATION)) { in genesys_sheetfed_calibration()
3729 dev->interface->record_progress_message("offset_calibration"); in genesys_sheetfed_calibration()
3730 dev->cmd_set->offset_calibration(dev, sensor, local_reg); in genesys_sheetfed_calibration()
3732 dev->interface->record_progress_message("coarse_gain_calibration"); in genesys_sheetfed_calibration()
3733 dev->cmd_set->coarse_gain_calibration(dev, sensor, local_reg, coarse_res); in genesys_sheetfed_calibration()
3736 if (dev->model->is_cis && in genesys_sheetfed_calibration()
3737 !has_flag(dev->model->flags, ModelFlag::DISABLE_EXPOSURE_CALIBRATION)) in genesys_sheetfed_calibration()
3740 dev->interface->record_progress_message("led_calibration"); in genesys_sheetfed_calibration()
3741 dev->cmd_set->led_calibration(dev, sensor, local_reg); in genesys_sheetfed_calibration()
3743 if (!has_flag(dev->model->flags, ModelFlag::DISABLE_ADC_CALIBRATION)) { in genesys_sheetfed_calibration()
3745 dev->interface->record_progress_message("offset_calibration"); in genesys_sheetfed_calibration()
3746 dev->cmd_set->offset_calibration(dev, sensor, local_reg); in genesys_sheetfed_calibration()
3748 dev->interface->record_progress_message("coarse_gain_calibration"); in genesys_sheetfed_calibration()
3749 dev->cmd_set->coarse_gain_calibration(dev, sensor, local_reg, coarse_res); in genesys_sheetfed_calibration()
3755 if (has_flag(dev->model->flags, ModelFlag::DARK_CALIBRATION)) { in genesys_sheetfed_calibration()
3760 catch_all_exceptions(__func__, [&](){ dev->cmd_set->eject_document(dev); }); in genesys_sheetfed_calibration()
3767 catch_all_exceptions(__func__, [&](){ dev->cmd_set->eject_document(dev); }); in genesys_sheetfed_calibration()
3778 catch_all_exceptions(__func__, [&](){ dev->cmd_set->eject_document(dev); }); in genesys_sheetfed_calibration()
3788 catch_all_exceptions(__func__, [&](){ dev->cmd_set->eject_document(dev); }); in genesys_sheetfed_calibration()
3794 if (!has_flag(dev->model->flags, ModelFlag::DARK_CALIBRATION)) { in genesys_sheetfed_calibration()
3800 if (!dev->cmd_set->has_send_shading_data()) { in genesys_sheetfed_calibration()
3808 dev->cmd_set->eject_document(dev); in genesys_sheetfed_calibration()
3811 dev->settings.xres = sensor.full_resolution; in genesys_sheetfed_calibration()
3821 if (!dev->model->is_sheetfed) { in genesys_scanner_calibration()
3829 /* ------------------------------------------------------------------------ */
3831 /* ------------------------------------------------------------------------ */
3844 dev->cmd_set->init_regs_for_warmup(dev, sensor, &dev->reg); in genesys_warmup_lamp()
3845 dev->interface->write_registers(dev->reg); in genesys_warmup_lamp()
3847 auto total_pixels = dev->session.output_pixels; in genesys_warmup_lamp()
3848 auto total_size = dev->session.output_line_bytes; in genesys_warmup_lamp()
3849 auto channels = dev->session.params.channels; in genesys_warmup_lamp()
3850 auto lines = dev->session.output_line_count; in genesys_warmup_lamp()
3852 std::vector<std::uint8_t> first_line(total_size); in genesys_warmup_lamp()
3853 std::vector<std::uint8_t> second_line(total_size); in genesys_warmup_lamp()
3858 dev->cmd_set->begin_scan(dev, sensor, &dev->reg, false); in genesys_warmup_lamp()
3861 dev->interface->test_checkpoint("warmup_lamp"); in genesys_warmup_lamp()
3862 dev->cmd_set->end_scan(dev, &dev->reg, true); in genesys_warmup_lamp()
3869 dev->cmd_set->end_scan(dev, &dev->reg, true); in genesys_warmup_lamp()
3876 if (dev->session.params.depth == 16) { in genesys_warmup_lamp()
3890 write_tiff_file("gl_warmup1.tiff", first_line.data(), dev->session.params.depth, in genesys_warmup_lamp()
3892 write_tiff_file("gl_warmup2.tiff", second_line.data(), dev->session.params.depth, in genesys_warmup_lamp()
3899 float average_difference = std::fabs(first_average - second_average) / second_average; in genesys_warmup_lamp()
3906 dev->interface->sleep_ms(1000); in genesys_warmup_lamp()
3927 auto session = dev.cmd_set->calculate_scan_session(&dev, sensor, dev.settings); in init_regs_for_scan()
3929 if (dev.model->asic_type == AsicType::GL124 || in init_regs_for_scan()
3930 dev.model->asic_type == AsicType::GL845 || in init_regs_for_scan()
3931 dev.model->asic_type == AsicType::GL846 || in init_regs_for_scan()
3932 dev.model->asic_type == AsicType::GL847) in init_regs_for_scan()
3942 scanner_move(dev, dev.model->default_method, in init_regs_for_scan()
3943 static_cast<unsigned>(session.params.starty - 500), in init_regs_for_scan()
3950 dev.cmd_set->init_regs_for_scan_session(&dev, sensor, &regs, session); in init_regs_for_scan()
3953 // High-level start of scanning
3962 if (dev->parking) { in genesys_start_scan()
3967 dev->cmd_set->save_power(dev, false); in genesys_start_scan()
3971 if (has_flag(dev->model->flags, ModelFlag::WARMUP) && in genesys_start_scan()
3972 (dev->settings.scan_method != ScanMethod::TRANSPARENCY_INFRARED)) in genesys_start_scan()
3974 if (dev->settings.scan_method == ScanMethod::TRANSPARENCY || in genesys_start_scan()
3975 dev->settings.scan_method == ScanMethod::TRANSPARENCY_INFRARED) in genesys_start_scan()
3984 if (!dev->model->is_sheetfed) { in genesys_start_scan()
3986 dev->parking = false; in genesys_start_scan()
3987 dev->cmd_set->move_back_home(dev, true); in genesys_start_scan()
3991 if (dev->settings.scan_method == ScanMethod::TRANSPARENCY || in genesys_start_scan()
3992 dev->settings.scan_method == ScanMethod::TRANSPARENCY_INFRARED) in genesys_start_scan()
3998 if (dev->model->is_sheetfed) { in genesys_start_scan()
3999 dev->cmd_set->load_document(dev); in genesys_start_scan()
4002 auto& sensor = sanei_genesys_find_sensor_for_write(dev, dev->settings.xres, in genesys_start_scan()
4003 dev->settings.get_channels(), in genesys_start_scan()
4004 dev->settings.scan_method); in genesys_start_scan()
4008 dev->cmd_set->send_gamma_table(dev, sensor); in genesys_start_scan()
4016 has_flag(dev->model->flags, ModelFlag::DISABLE_ADC_CALIBRATION) && in genesys_start_scan()
4017 has_flag(dev->model->flags, ModelFlag::DISABLE_EXPOSURE_CALIBRATION) && in genesys_start_scan()
4018 has_flag(dev->model->flags, ModelFlag::DISABLE_SHADING_CALIBRATION); in genesys_start_scan()
4019 if (!shading_disabled && !dev->model->is_sheetfed) { in genesys_start_scan()
4027 dev->cmd_set->wait_for_motor_stop(dev); in genesys_start_scan()
4029 if (dev->cmd_set->needs_home_before_init_regs_for_scan(dev)) { in genesys_start_scan()
4030 dev->cmd_set->move_back_home(dev, true); in genesys_start_scan()
4033 if (dev->settings.scan_method == ScanMethod::TRANSPARENCY || in genesys_start_scan()
4034 dev->settings.scan_method == ScanMethod::TRANSPARENCY_INFRARED) in genesys_start_scan()
4039 init_regs_for_scan(*dev, sensor, dev->reg); in genesys_start_scan()
4043 sanei_genesys_set_lamp_power(dev, sensor, dev->reg, false); in genesys_start_scan()
4048 if (dev->cmd_set->has_send_shading_data() && in genesys_start_scan()
4049 !has_flag(dev->model->flags, ModelFlag::DISABLE_SHADING_CALIBRATION)) in genesys_start_scan()
4055 dev->interface->write_registers(dev->reg); in genesys_start_scan()
4058 dev->cmd_set->begin_scan(dev, sensor, &dev->reg, true); in genesys_start_scan()
4061 dev->interface->test_checkpoint("start_scan"); in genesys_start_scan()
4065 /*do we really need this? the valid data check should be sufficient -- pierre*/ in genesys_start_scan()
4067 expected = dev->reg.get8(0x3d) * 65536 in genesys_start_scan()
4068 + dev->reg.get8(0x3e) * 256 in genesys_start_scan()
4069 + dev->reg.get8(0x3f); in genesys_start_scan()
4073 dev->interface->sleep_ms(100); in genesys_start_scan()
4081 // this is also done in sanei_genesys_read_data_from_scanner -- pierre in genesys_start_scan()
4082 if (!dev->model->is_sheetfed) { in genesys_start_scan()
4084 dev->interface->sleep_ms(100); in genesys_start_scan()
4094 Returns true on success, false on end-of-file.
4101 if (!dev->read_active) { in genesys_read_ordered_data()
4108 dev->total_bytes_to_read, dev->total_bytes_read); in genesys_read_ordered_data()
4111 if (dev->total_bytes_read >= dev->total_bytes_to_read) in genesys_read_ordered_data()
4115 if (!dev->model->is_sheetfed && !has_flag(dev->model->flags, ModelFlag::MUST_WAIT) && in genesys_read_ordered_data()
4116 !dev->parking) in genesys_read_ordered_data()
4118 dev->cmd_set->move_back_home(dev, false); in genesys_read_ordered_data()
4119 dev->parking = true; in genesys_read_ordered_data()
4125 if (dev->total_bytes_read + *len > dev->total_bytes_to_read) { in genesys_read_ordered_data()
4126 *len = dev->total_bytes_to_read - dev->total_bytes_read; in genesys_read_ordered_data()
4128 dev->total_bytes_read += *len; in genesys_read_ordered_data()
4130 if (dev->model->is_sheetfed) { in genesys_read_ordered_data()
4131 dev->cmd_set->detect_document_end(dev); in genesys_read_ordered_data()
4134 if (dev->total_bytes_read + *len > dev->total_bytes_to_read) { in genesys_read_ordered_data()
4135 *len = dev->total_bytes_to_read - dev->total_bytes_read; in genesys_read_ordered_data()
4138 dev->pipeline_buffer.get_data(*len, destination); in genesys_read_ordered_data()
4139 dev->total_bytes_read += *len; in genesys_read_ordered_data()
4143 if(dev->total_bytes_read >= dev->total_bytes_to_read) in genesys_read_ordered_data()
4145 dev->cmd_set->end_scan(dev, &dev->reg, true); in genesys_read_ordered_data()
4146 if (dev->model->is_sheetfed) { in genesys_read_ordered_data()
4147 dev->cmd_set->eject_document (dev); in genesys_read_ordered_data()
4156 /* ------------------------------------------------------------------------ */
4158 /* ------------------------------------------------------------------------ */
4175 static std::size_t max_string_size(const std::vector<const char*>& strings) in max_string_size()
4177 std::size_t max_size = 0; in max_string_size()
4182 max_size = std::max(max_size, std::strlen(s)); in max_string_size()
4187 static unsigned pick_resolution(const std::vector<unsigned>& resolutions, unsigned resolution, in pick_resolution()
4198 for (auto it = std::next(resolutions.begin()); it != resolutions.end(); ++it) { in pick_resolution()
4217 const auto* dev = s->dev; in calculate_scan_settings()
4219 settings.scan_method = s->scan_method; in calculate_scan_settings()
4220 settings.scan_mode = option_string_to_scan_color_mode(s->mode); in calculate_scan_settings()
4222 settings.depth = s->bit_depth; in calculate_scan_settings()
4230 const auto& resolutions = dev->model->get_resolution_settings(settings.scan_method); in calculate_scan_settings()
4232 settings.xres = pick_resolution(resolutions.resolutions_x, s->resolution, "X"); in calculate_scan_settings()
4233 settings.yres = pick_resolution(resolutions.resolutions_y, s->resolution, "Y"); in calculate_scan_settings()
4235 settings.tl_x = fixed_to_float(s->pos_top_left_x); in calculate_scan_settings()
4236 settings.tl_y = fixed_to_float(s->pos_top_left_y); in calculate_scan_settings()
4237 float br_x = fixed_to_float(s->pos_bottom_right_x); in calculate_scan_settings()
4238 float br_y = fixed_to_float(s->pos_bottom_right_y); in calculate_scan_settings()
4240 settings.lines = static_cast<unsigned>(((br_y - settings.tl_y) * settings.yres) / in calculate_scan_settings()
4244 unsigned pixels_per_line = static_cast<unsigned>(((br_x - settings.tl_x) * settings.xres) / in calculate_scan_settings()
4253 unsigned xres_factor = s->resolution / settings.xres; in calculate_scan_settings()
4257 if (s->color_filter == "Red") { in calculate_scan_settings()
4259 } else if (s->color_filter == "Green") { in calculate_scan_settings()
4261 } else if (s->color_filter == "Blue") { in calculate_scan_settings()
4268 if (s->bit_depth == 8) { in calculate_scan_settings()
4269 settings.contrast = (s->contrast * 127) / 100; in calculate_scan_settings()
4270 settings.brightness = (s->brightness * 127) / 100; in calculate_scan_settings()
4276 settings.expiration_time = s->expiration_time; in calculate_scan_settings()
4288 auto session = dev.cmd_set->calculate_scan_session(&dev, sensor, settings); in calculate_scan_parameters()
4297 // only single-pass scanning supported in calculate_scan_parameters()
4311 s->dev->settings = calculate_scan_settings(s); in calc_parameters()
4312 s->params = calculate_scan_parameters(*s->dev, s->dev->settings); in calc_parameters()
4315 static void create_bpp_list (Genesys_Scanner * s, const std::vector<unsigned>& bpp) in create_bpp_list()
4317 s->bpp_list[0] = bpp.size(); in create_bpp_list()
4318 std::reverse_copy(bpp.begin(), bpp.end(), s->bpp_list + 1); in create_bpp_list()
4334 scanner->opt[option].type = SANE_TYPE_INT; in init_gamma_vector_option()
4335 scanner->opt[option].cap |= SANE_CAP_INACTIVE | SANE_CAP_ADVANCED; in init_gamma_vector_option()
4336 scanner->opt[option].unit = SANE_UNIT_NONE; in init_gamma_vector_option()
4337 scanner->opt[option].constraint_type = SANE_CONSTRAINT_RANGE; in init_gamma_vector_option()
4338 if (scanner->dev->model->asic_type == AsicType::GL646) { in init_gamma_vector_option()
4339 if (has_flag(scanner->dev->model->flags, ModelFlag::GAMMA_14BIT)) { in init_gamma_vector_option()
4340 scanner->opt[option].size = 16384 * sizeof (SANE_Word); in init_gamma_vector_option()
4341 scanner->opt[option].constraint.range = &u14_range; in init_gamma_vector_option()
4345 scanner->opt[option].size = 4096 * sizeof (SANE_Word); in init_gamma_vector_option()
4346 scanner->opt[option].constraint.range = &u12_range; in init_gamma_vector_option()
4351 scanner->opt[option].size = 256 * sizeof (SANE_Word); in init_gamma_vector_option()
4352 scanner->opt[option].constraint.range = &u16_range; in init_gamma_vector_option()
4380 static std::string calibration_filename(Genesys_Device *currdev) in calibration_filename()
4382 std::string ret; in calibration_filename()
4390 * 1 - home dir in calibration_filename()
4391 * 2 - $TMPDIR in calibration_filename()
4392 * 3 - $TMP in calibration_filename()
4393 * 4 - tmp dir in calibration_filename()
4394 * 5 - temp dir in calibration_filename()
4395 * 6 - then resort to current dir in calibration_filename()
4397 char* ptr = std::getenv("HOME"); in calibration_filename()
4399 ptr = std::getenv("USERPROFILE"); in calibration_filename()
4402 ptr = std::getenv("TMPDIR"); in calibration_filename()
4405 ptr = std::getenv("TMP"); in calibration_filename()
4409 * 1 - if only one scanner, name of the model in calibration_filename()
4410 * 2 - if several scanners of the same model, use device name, in calibration_filename()
4415 if(s_devices->size() > 1) { in calibration_filename()
4417 if (dev.vendorId == currdev->vendorId && dev.productId == currdev->productId) { in calibration_filename()
4424 std::snprintf(filename, sizeof(filename), "%s.cal", currdev->file_name.c_str()); in calibration_filename()
4435 snprintf(filename,sizeof(filename),"%s.cal",currdev->model->name); in calibration_filename()
4440 int size = std::snprintf(&ret.front(), ret.size(), "%s", filename); in calibration_filename()
4448 size = std::snprintf(&ret.front(), ret.size(), "%s%c.sane", ptr, PATH_SEP); in calibration_filename()
4454 size = std::snprintf(&ret.front(), ret.size(), "%s%c.sane%c%s", in calibration_filename()
4466 auto resolutions = s.dev->model->get_resolutions(s.scan_method); in set_resolution_option_values()
4470 std::copy(resolutions.begin(), resolutions.end(), s.opt_resolution_values.begin() + 1); in set_resolution_option_values()
4475 s.resolution = *std::min_element(resolutions.begin(), resolutions.end()); in set_resolution_option_values()
4483 s.opt_x_range = create_range(s.dev->model->x_size); in set_xy_range_option_values()
4484 s.opt_y_range = create_range(s.dev->model->y_size); in set_xy_range_option_values()
4488 s.opt_x_range = create_range(s.dev->model->x_size_ta); in set_xy_range_option_values()
4489 s.opt_y_range = create_range(s.dev->model->y_size_ta); in set_xy_range_option_values()
4507 const Genesys_Model* model = s->dev->model; in init_options()
4509 memset (s->opt, 0, sizeof (s->opt)); in init_options()
4513 s->opt[option].size = sizeof (SANE_Word); in init_options()
4514 s->opt[option].cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT; in init_options()
4516 s->opt[OPT_NUM_OPTS].name = SANE_NAME_NUM_OPTIONS; in init_options()
4517 s->opt[OPT_NUM_OPTS].title = SANE_TITLE_NUM_OPTIONS; in init_options()
4518 s->opt[OPT_NUM_OPTS].desc = SANE_DESC_NUM_OPTIONS; in init_options()
4519 s->opt[OPT_NUM_OPTS].type = SANE_TYPE_INT; in init_options()
4520 s->opt[OPT_NUM_OPTS].cap = SANE_CAP_SOFT_DETECT; in init_options()
4523 s->opt[OPT_MODE_GROUP].name = "scanmode-group"; in init_options()
4524 s->opt[OPT_MODE_GROUP].title = SANE_I18N ("Scan Mode"); in init_options()
4525 s->opt[OPT_MODE_GROUP].desc = ""; in init_options()
4526 s->opt[OPT_MODE_GROUP].type = SANE_TYPE_GROUP; in init_options()
4527 s->opt[OPT_MODE_GROUP].size = 0; in init_options()
4528 s->opt[OPT_MODE_GROUP].cap = 0; in init_options()
4529 s->opt[OPT_MODE_GROUP].constraint_type = SANE_CONSTRAINT_NONE; in init_options()
4532 s->opt[OPT_MODE].name = SANE_NAME_SCAN_MODE; in init_options()
4533 s->opt[OPT_MODE].title = SANE_TITLE_SCAN_MODE; in init_options()
4534 s->opt[OPT_MODE].desc = SANE_DESC_SCAN_MODE; in init_options()
4535 s->opt[OPT_MODE].type = SANE_TYPE_STRING; in init_options()
4536 s->opt[OPT_MODE].constraint_type = SANE_CONSTRAINT_STRING_LIST; in init_options()
4537 s->opt[OPT_MODE].size = max_string_size (mode_list); in init_options()
4538 s->opt[OPT_MODE].constraint.string_list = mode_list; in init_options()
4539 s->mode = SANE_VALUE_SCAN_MODE_GRAY; in init_options()
4542 s->opt_source_values.clear(); in init_options()
4543 for (const auto& resolution_setting : model->resolutions) { in init_options()
4545 s->opt_source_values.push_back(scan_method_to_option_string(method)); in init_options()
4548 s->opt_source_values.push_back(nullptr); in init_options()
4550 s->opt[OPT_SOURCE].name = SANE_NAME_SCAN_SOURCE; in init_options()
4551 s->opt[OPT_SOURCE].title = SANE_TITLE_SCAN_SOURCE; in init_options()
4552 s->opt[OPT_SOURCE].desc = SANE_DESC_SCAN_SOURCE; in init_options()
4553 s->opt[OPT_SOURCE].type = SANE_TYPE_STRING; in init_options()
4554 s->opt[OPT_SOURCE].constraint_type = SANE_CONSTRAINT_STRING_LIST; in init_options()
4555 s->opt[OPT_SOURCE].size = max_string_size(s->opt_source_values); in init_options()
4556 s->opt[OPT_SOURCE].constraint.string_list = s->opt_source_values.data(); in init_options()
4557 if (s->opt_source_values.size() < 2) { in init_options()
4560 s->scan_method = model->default_method; in init_options()
4563 s->opt[OPT_PREVIEW].name = SANE_NAME_PREVIEW; in init_options()
4564 s->opt[OPT_PREVIEW].title = SANE_TITLE_PREVIEW; in init_options()
4565 s->opt[OPT_PREVIEW].desc = SANE_DESC_PREVIEW; in init_options()
4566 s->opt[OPT_PREVIEW].type = SANE_TYPE_BOOL; in init_options()
4567 s->opt[OPT_PREVIEW].unit = SANE_UNIT_NONE; in init_options()
4568 s->opt[OPT_PREVIEW].constraint_type = SANE_CONSTRAINT_NONE; in init_options()
4569 s->preview = false; in init_options()
4572 s->opt[OPT_BIT_DEPTH].name = SANE_NAME_BIT_DEPTH; in init_options()
4573 s->opt[OPT_BIT_DEPTH].title = SANE_TITLE_BIT_DEPTH; in init_options()
4574 s->opt[OPT_BIT_DEPTH].desc = SANE_DESC_BIT_DEPTH; in init_options()
4575 s->opt[OPT_BIT_DEPTH].type = SANE_TYPE_INT; in init_options()
4576 s->opt[OPT_BIT_DEPTH].constraint_type = SANE_CONSTRAINT_WORD_LIST; in init_options()
4577 s->opt[OPT_BIT_DEPTH].size = sizeof (SANE_Word); in init_options()
4578 s->opt[OPT_BIT_DEPTH].constraint.word_list = s->bpp_list; in init_options()
4579 create_bpp_list (s, model->bpp_gray_values); in init_options()
4580 s->bit_depth = model->bpp_gray_values[0]; in init_options()
4583 s->opt[OPT_RESOLUTION].name = SANE_NAME_SCAN_RESOLUTION; in init_options()
4584 s->opt[OPT_RESOLUTION].title = SANE_TITLE_SCAN_RESOLUTION; in init_options()
4585 s->opt[OPT_RESOLUTION].desc = SANE_DESC_SCAN_RESOLUTION; in init_options()
4586 s->opt[OPT_RESOLUTION].type = SANE_TYPE_INT; in init_options()
4587 s->opt[OPT_RESOLUTION].unit = SANE_UNIT_DPI; in init_options()
4588 s->opt[OPT_RESOLUTION].constraint_type = SANE_CONSTRAINT_WORD_LIST; in init_options()
4592 s->opt[OPT_GEOMETRY_GROUP].name = SANE_NAME_GEOMETRY; in init_options()
4593 s->opt[OPT_GEOMETRY_GROUP].title = SANE_I18N ("Geometry"); in init_options()
4594 s->opt[OPT_GEOMETRY_GROUP].desc = ""; in init_options()
4595 s->opt[OPT_GEOMETRY_GROUP].type = SANE_TYPE_GROUP; in init_options()
4596 s->opt[OPT_GEOMETRY_GROUP].cap = SANE_CAP_ADVANCED; in init_options()
4597 s->opt[OPT_GEOMETRY_GROUP].size = 0; in init_options()
4598 s->opt[OPT_GEOMETRY_GROUP].constraint_type = SANE_CONSTRAINT_NONE; in init_options()
4600 s->opt_x_range = create_range(model->x_size); in init_options()
4601 s->opt_y_range = create_range(model->y_size); in init_options()
4604 s->opt[OPT_TL_X].name = SANE_NAME_SCAN_TL_X; in init_options()
4605 s->opt[OPT_TL_X].title = SANE_TITLE_SCAN_TL_X; in init_options()
4606 s->opt[OPT_TL_X].desc = SANE_DESC_SCAN_TL_X; in init_options()
4607 s->opt[OPT_TL_X].type = SANE_TYPE_FIXED; in init_options()
4608 s->opt[OPT_TL_X].unit = SANE_UNIT_MM; in init_options()
4609 s->opt[OPT_TL_X].constraint_type = SANE_CONSTRAINT_RANGE; in init_options()
4611 s->opt[OPT_TL_Y].name = SANE_NAME_SCAN_TL_Y; in init_options()
4612 s->opt[OPT_TL_Y].title = SANE_TITLE_SCAN_TL_Y; in init_options()
4613 s->opt[OPT_TL_Y].desc = SANE_DESC_SCAN_TL_Y; in init_options()
4614 s->opt[OPT_TL_Y].type = SANE_TYPE_FIXED; in init_options()
4615 s->opt[OPT_TL_Y].unit = SANE_UNIT_MM; in init_options()
4616 s->opt[OPT_TL_Y].constraint_type = SANE_CONSTRAINT_RANGE; in init_options()
4618 s->opt[OPT_BR_X].name = SANE_NAME_SCAN_BR_X; in init_options()
4619 s->opt[OPT_BR_X].title = SANE_TITLE_SCAN_BR_X; in init_options()
4620 s->opt[OPT_BR_X].desc = SANE_DESC_SCAN_BR_X; in init_options()
4621 s->opt[OPT_BR_X].type = SANE_TYPE_FIXED; in init_options()
4622 s->opt[OPT_BR_X].unit = SANE_UNIT_MM; in init_options()
4623 s->opt[OPT_BR_X].constraint_type = SANE_CONSTRAINT_RANGE; in init_options()
4625 s->opt[OPT_BR_Y].name = SANE_NAME_SCAN_BR_Y; in init_options()
4626 s->opt[OPT_BR_Y].title = SANE_TITLE_SCAN_BR_Y; in init_options()
4627 s->opt[OPT_BR_Y].desc = SANE_DESC_SCAN_BR_Y; in init_options()
4628 s->opt[OPT_BR_Y].type = SANE_TYPE_FIXED; in init_options()
4629 s->opt[OPT_BR_Y].unit = SANE_UNIT_MM; in init_options()
4630 s->opt[OPT_BR_Y].constraint_type = SANE_CONSTRAINT_RANGE; in init_options()
4635 s->opt[OPT_ENHANCEMENT_GROUP].name = SANE_NAME_ENHANCEMENT; in init_options()
4636 s->opt[OPT_ENHANCEMENT_GROUP].title = SANE_I18N ("Enhancement"); in init_options()
4637 s->opt[OPT_ENHANCEMENT_GROUP].desc = ""; in init_options()
4638 s->opt[OPT_ENHANCEMENT_GROUP].type = SANE_TYPE_GROUP; in init_options()
4639 s->opt[OPT_ENHANCEMENT_GROUP].cap = SANE_CAP_ADVANCED; in init_options()
4640 s->opt[OPT_ENHANCEMENT_GROUP].size = 0; in init_options()
4641 s->opt[OPT_ENHANCEMENT_GROUP].constraint_type = SANE_CONSTRAINT_NONE; in init_options()
4643 /* custom-gamma table */ in init_options()
4644 s->opt[OPT_CUSTOM_GAMMA].name = SANE_NAME_CUSTOM_GAMMA; in init_options()
4645 s->opt[OPT_CUSTOM_GAMMA].title = SANE_TITLE_CUSTOM_GAMMA; in init_options()
4646 s->opt[OPT_CUSTOM_GAMMA].desc = SANE_DESC_CUSTOM_GAMMA; in init_options()
4647 s->opt[OPT_CUSTOM_GAMMA].type = SANE_TYPE_BOOL; in init_options()
4648 s->opt[OPT_CUSTOM_GAMMA].cap |= SANE_CAP_ADVANCED; in init_options()
4649 s->custom_gamma = false; in init_options()
4652 s->opt[OPT_GAMMA_VECTOR].name = SANE_NAME_GAMMA_VECTOR; in init_options()
4653 s->opt[OPT_GAMMA_VECTOR].title = SANE_TITLE_GAMMA_VECTOR; in init_options()
4654 s->opt[OPT_GAMMA_VECTOR].desc = SANE_DESC_GAMMA_VECTOR; in init_options()
4658 s->opt[OPT_GAMMA_VECTOR_R].name = SANE_NAME_GAMMA_VECTOR_R; in init_options()
4659 s->opt[OPT_GAMMA_VECTOR_R].title = SANE_TITLE_GAMMA_VECTOR_R; in init_options()
4660 s->opt[OPT_GAMMA_VECTOR_R].desc = SANE_DESC_GAMMA_VECTOR_R; in init_options()
4664 s->opt[OPT_GAMMA_VECTOR_G].name = SANE_NAME_GAMMA_VECTOR_G; in init_options()
4665 s->opt[OPT_GAMMA_VECTOR_G].title = SANE_TITLE_GAMMA_VECTOR_G; in init_options()
4666 s->opt[OPT_GAMMA_VECTOR_G].desc = SANE_DESC_GAMMA_VECTOR_G; in init_options()
4670 s->opt[OPT_GAMMA_VECTOR_B].name = SANE_NAME_GAMMA_VECTOR_B; in init_options()
4671 s->opt[OPT_GAMMA_VECTOR_B].title = SANE_TITLE_GAMMA_VECTOR_B; in init_options()
4672 s->opt[OPT_GAMMA_VECTOR_B].desc = SANE_DESC_GAMMA_VECTOR_B; in init_options()
4678 if (!has_flag(model->flags, ModelFlag::CUSTOM_GAMMA)) { in init_options()
4679 s->opt[OPT_ENHANCEMENT_GROUP].cap |= SANE_CAP_INACTIVE; in init_options()
4680 s->opt[OPT_CUSTOM_GAMMA].cap |= SANE_CAP_INACTIVE; in init_options()
4690 s->opt[OPT_BRIGHTNESS].name = SANE_NAME_BRIGHTNESS; in init_options()
4691 s->opt[OPT_BRIGHTNESS].title = SANE_TITLE_BRIGHTNESS; in init_options()
4692 s->opt[OPT_BRIGHTNESS].desc = SANE_DESC_BRIGHTNESS; in init_options()
4693 s->opt[OPT_BRIGHTNESS].type = SANE_TYPE_INT; in init_options()
4694 s->opt[OPT_BRIGHTNESS].unit = SANE_UNIT_NONE; in init_options()
4695 s->opt[OPT_BRIGHTNESS].constraint_type = SANE_CONSTRAINT_RANGE; in init_options()
4696 s->opt[OPT_BRIGHTNESS].constraint.range = &(enhance_range); in init_options()
4697 s->opt[OPT_BRIGHTNESS].cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT; in init_options()
4698 s->brightness = 0; // disable by default in init_options()
4701 s->opt[OPT_CONTRAST].name = SANE_NAME_CONTRAST; in init_options()
4702 s->opt[OPT_CONTRAST].title = SANE_TITLE_CONTRAST; in init_options()
4703 s->opt[OPT_CONTRAST].desc = SANE_DESC_CONTRAST; in init_options()
4704 s->opt[OPT_CONTRAST].type = SANE_TYPE_INT; in init_options()
4705 s->opt[OPT_CONTRAST].unit = SANE_UNIT_NONE; in init_options()
4706 s->opt[OPT_CONTRAST].constraint_type = SANE_CONSTRAINT_RANGE; in init_options()
4707 s->opt[OPT_CONTRAST].constraint.range = &(enhance_range); in init_options()
4708 s->opt[OPT_CONTRAST].cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT; in init_options()
4709 s->contrast = 0; // disable by default in init_options()
4712 s->opt[OPT_EXTRAS_GROUP].name = "extras-group"; in init_options()
4713 s->opt[OPT_EXTRAS_GROUP].title = SANE_I18N ("Extras"); in init_options()
4714 s->opt[OPT_EXTRAS_GROUP].desc = ""; in init_options()
4715 s->opt[OPT_EXTRAS_GROUP].type = SANE_TYPE_GROUP; in init_options()
4716 s->opt[OPT_EXTRAS_GROUP].cap = SANE_CAP_ADVANCED; in init_options()
4717 s->opt[OPT_EXTRAS_GROUP].size = 0; in init_options()
4718 s->opt[OPT_EXTRAS_GROUP].constraint_type = SANE_CONSTRAINT_NONE; in init_options()
4721 s->opt[OPT_COLOR_FILTER].name = "color-filter"; in init_options()
4722 s->opt[OPT_COLOR_FILTER].title = SANE_I18N ("Color filter"); in init_options()
4723 s->opt[OPT_COLOR_FILTER].desc = in init_options()
4726 s->opt[OPT_COLOR_FILTER].type = SANE_TYPE_STRING; in init_options()
4727 s->opt[OPT_COLOR_FILTER].constraint_type = SANE_CONSTRAINT_STRING_LIST; in init_options()
4729 if (!model->is_cis || model->asic_type==AsicType::GL847 || model->asic_type==AsicType::GL124) { in init_options()
4730 s->opt[OPT_COLOR_FILTER].size = max_string_size (color_filter_list); in init_options()
4731 s->opt[OPT_COLOR_FILTER].constraint.string_list = color_filter_list; in init_options()
4732 s->color_filter = s->opt[OPT_COLOR_FILTER].constraint.string_list[1]; in init_options()
4736 s->opt[OPT_COLOR_FILTER].size = max_string_size (cis_color_filter_list); in init_options()
4737 s->opt[OPT_COLOR_FILTER].constraint.string_list = cis_color_filter_list; in init_options()
4739 s->color_filter = s->opt[OPT_COLOR_FILTER].constraint.string_list[3]; in init_options()
4743 if (model->asic_type == AsicType::GL646 && model->is_cis) { in init_options()
4748 s->opt[OPT_CALIBRATION_FILE].name = "calibration-file"; in init_options()
4749 s->opt[OPT_CALIBRATION_FILE].title = SANE_I18N ("Calibration file"); in init_options()
4750 s->opt[OPT_CALIBRATION_FILE].desc = SANE_I18N ("Specify the calibration file to use"); in init_options()
4751 s->opt[OPT_CALIBRATION_FILE].type = SANE_TYPE_STRING; in init_options()
4752 s->opt[OPT_CALIBRATION_FILE].unit = SANE_UNIT_NONE; in init_options()
4753 s->opt[OPT_CALIBRATION_FILE].size = PATH_MAX; in init_options()
4754 …s->opt[OPT_CALIBRATION_FILE].cap = SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT | SANE_CAP_ADVANCED; in init_options()
4755 s->opt[OPT_CALIBRATION_FILE].constraint_type = SANE_CONSTRAINT_NONE; in init_options()
4756 s->calibration_file.clear(); in init_options()
4766 s->opt[OPT_EXPIRATION_TIME].name = "expiration-time"; in init_options()
4767 s->opt[OPT_EXPIRATION_TIME].title = SANE_I18N ("Calibration cache expiration time"); in init_options()
4768 …s->opt[OPT_EXPIRATION_TIME].desc = SANE_I18N ("Time (in minutes) before a cached calibration expir… in init_options()
4770 s->opt[OPT_EXPIRATION_TIME].type = SANE_TYPE_INT; in init_options()
4771 s->opt[OPT_EXPIRATION_TIME].unit = SANE_UNIT_NONE; in init_options()
4772 s->opt[OPT_EXPIRATION_TIME].constraint_type = SANE_CONSTRAINT_RANGE; in init_options()
4773 s->opt[OPT_EXPIRATION_TIME].constraint.range = &expiration_range; in init_options()
4774 s->expiration_time = 60; // 60 minutes by default in init_options()
4777 s->opt[OPT_LAMP_OFF_TIME].name = "lamp-off-time"; in init_options()
4778 s->opt[OPT_LAMP_OFF_TIME].title = SANE_I18N ("Lamp off time"); in init_options()
4779 s->opt[OPT_LAMP_OFF_TIME].desc = in init_options()
4783 s->opt[OPT_LAMP_OFF_TIME].type = SANE_TYPE_INT; in init_options()
4784 s->opt[OPT_LAMP_OFF_TIME].unit = SANE_UNIT_NONE; in init_options()
4785 s->opt[OPT_LAMP_OFF_TIME].constraint_type = SANE_CONSTRAINT_RANGE; in init_options()
4786 s->opt[OPT_LAMP_OFF_TIME].constraint.range = &time_range; in init_options()
4787 s->lamp_off_time = 15; // 15 minutes in init_options()
4790 s->opt[OPT_LAMP_OFF].name = "lamp-off-scan"; in init_options()
4791 s->opt[OPT_LAMP_OFF].title = SANE_I18N ("Lamp off during scan"); in init_options()
4792 s->opt[OPT_LAMP_OFF].desc = SANE_I18N ("The lamp will be turned off during scan. "); in init_options()
4793 s->opt[OPT_LAMP_OFF].type = SANE_TYPE_BOOL; in init_options()
4794 s->opt[OPT_LAMP_OFF].unit = SANE_UNIT_NONE; in init_options()
4795 s->opt[OPT_LAMP_OFF].constraint_type = SANE_CONSTRAINT_NONE; in init_options()
4796 s->lamp_off = false; in init_options()
4798 s->opt[OPT_SENSOR_GROUP].name = SANE_NAME_SENSORS; in init_options()
4799 s->opt[OPT_SENSOR_GROUP].title = SANE_TITLE_SENSORS; in init_options()
4800 s->opt[OPT_SENSOR_GROUP].desc = SANE_DESC_SENSORS; in init_options()
4801 s->opt[OPT_SENSOR_GROUP].type = SANE_TYPE_GROUP; in init_options()
4802 s->opt[OPT_SENSOR_GROUP].cap = SANE_CAP_ADVANCED; in init_options()
4803 s->opt[OPT_SENSOR_GROUP].size = 0; in init_options()
4804 s->opt[OPT_SENSOR_GROUP].constraint_type = SANE_CONSTRAINT_NONE; in init_options()
4806 s->opt[OPT_SCAN_SW].name = SANE_NAME_SCAN; in init_options()
4807 s->opt[OPT_SCAN_SW].title = SANE_TITLE_SCAN; in init_options()
4808 s->opt[OPT_SCAN_SW].desc = SANE_DESC_SCAN; in init_options()
4809 s->opt[OPT_SCAN_SW].type = SANE_TYPE_BOOL; in init_options()
4810 s->opt[OPT_SCAN_SW].unit = SANE_UNIT_NONE; in init_options()
4811 if (model->buttons & GENESYS_HAS_SCAN_SW) in init_options()
4812 s->opt[OPT_SCAN_SW].cap = in init_options()
4815 s->opt[OPT_SCAN_SW].cap = SANE_CAP_INACTIVE; in init_options()
4818 s->opt[OPT_FILE_SW].name = "file"; in init_options()
4819 s->opt[OPT_FILE_SW].title = SANE_I18N ("File button"); in init_options()
4820 s->opt[OPT_FILE_SW].desc = SANE_I18N ("File button"); in init_options()
4821 s->opt[OPT_FILE_SW].type = SANE_TYPE_BOOL; in init_options()
4822 s->opt[OPT_FILE_SW].unit = SANE_UNIT_NONE; in init_options()
4823 if (model->buttons & GENESYS_HAS_FILE_SW) in init_options()
4824 s->opt[OPT_FILE_SW].cap = in init_options()
4827 s->opt[OPT_FILE_SW].cap = SANE_CAP_INACTIVE; in init_options()
4829 s->opt[OPT_EMAIL_SW].name = SANE_NAME_EMAIL; in init_options()
4830 s->opt[OPT_EMAIL_SW].title = SANE_TITLE_EMAIL; in init_options()
4831 s->opt[OPT_EMAIL_SW].desc = SANE_DESC_EMAIL; in init_options()
4832 s->opt[OPT_EMAIL_SW].type = SANE_TYPE_BOOL; in init_options()
4833 s->opt[OPT_EMAIL_SW].unit = SANE_UNIT_NONE; in init_options()
4834 if (model->buttons & GENESYS_HAS_EMAIL_SW) in init_options()
4835 s->opt[OPT_EMAIL_SW].cap = in init_options()
4838 s->opt[OPT_EMAIL_SW].cap = SANE_CAP_INACTIVE; in init_options()
4840 s->opt[OPT_COPY_SW].name = SANE_NAME_COPY; in init_options()
4841 s->opt[OPT_COPY_SW].title = SANE_TITLE_COPY; in init_options()
4842 s->opt[OPT_COPY_SW].desc = SANE_DESC_COPY; in init_options()
4843 s->opt[OPT_COPY_SW].type = SANE_TYPE_BOOL; in init_options()
4844 s->opt[OPT_COPY_SW].unit = SANE_UNIT_NONE; in init_options()
4845 if (model->buttons & GENESYS_HAS_COPY_SW) in init_options()
4846 s->opt[OPT_COPY_SW].cap = in init_options()
4849 s->opt[OPT_COPY_SW].cap = SANE_CAP_INACTIVE; in init_options()
4851 s->opt[OPT_PAGE_LOADED_SW].name = SANE_NAME_PAGE_LOADED; in init_options()
4852 s->opt[OPT_PAGE_LOADED_SW].title = SANE_TITLE_PAGE_LOADED; in init_options()
4853 s->opt[OPT_PAGE_LOADED_SW].desc = SANE_DESC_PAGE_LOADED; in init_options()
4854 s->opt[OPT_PAGE_LOADED_SW].type = SANE_TYPE_BOOL; in init_options()
4855 s->opt[OPT_PAGE_LOADED_SW].unit = SANE_UNIT_NONE; in init_options()
4856 if (model->buttons & GENESYS_HAS_PAGE_LOADED_SW) in init_options()
4857 s->opt[OPT_PAGE_LOADED_SW].cap = in init_options()
4860 s->opt[OPT_PAGE_LOADED_SW].cap = SANE_CAP_INACTIVE; in init_options()
4863 s->opt[OPT_OCR_SW].name = "ocr"; in init_options()
4864 s->opt[OPT_OCR_SW].title = SANE_I18N ("OCR button"); in init_options()
4865 s->opt[OPT_OCR_SW].desc = SANE_I18N ("OCR button"); in init_options()
4866 s->opt[OPT_OCR_SW].type = SANE_TYPE_BOOL; in init_options()
4867 s->opt[OPT_OCR_SW].unit = SANE_UNIT_NONE; in init_options()
4868 if (model->buttons & GENESYS_HAS_OCR_SW) in init_options()
4869 s->opt[OPT_OCR_SW].cap = in init_options()
4872 s->opt[OPT_OCR_SW].cap = SANE_CAP_INACTIVE; in init_options()
4875 s->opt[OPT_POWER_SW].name = "power"; in init_options()
4876 s->opt[OPT_POWER_SW].title = SANE_I18N ("Power button"); in init_options()
4877 s->opt[OPT_POWER_SW].desc = SANE_I18N ("Power button"); in init_options()
4878 s->opt[OPT_POWER_SW].type = SANE_TYPE_BOOL; in init_options()
4879 s->opt[OPT_POWER_SW].unit = SANE_UNIT_NONE; in init_options()
4880 if (model->buttons & GENESYS_HAS_POWER_SW) in init_options()
4881 s->opt[OPT_POWER_SW].cap = in init_options()
4884 s->opt[OPT_POWER_SW].cap = SANE_CAP_INACTIVE; in init_options()
4887 s->opt[OPT_EXTRA_SW].name = "extra"; in init_options()
4888 s->opt[OPT_EXTRA_SW].title = SANE_I18N("Extra button"); in init_options()
4889 s->opt[OPT_EXTRA_SW].desc = SANE_I18N("Extra button"); in init_options()
4890 s->opt[OPT_EXTRA_SW].type = SANE_TYPE_BOOL; in init_options()
4891 s->opt[OPT_EXTRA_SW].unit = SANE_UNIT_NONE; in init_options()
4892 if (model->buttons & GENESYS_HAS_EXTRA_SW) in init_options()
4893 s->opt[OPT_EXTRA_SW].cap = in init_options()
4896 s->opt[OPT_EXTRA_SW].cap = SANE_CAP_INACTIVE; in init_options()
4899 s->opt[OPT_TRANSP_SW].name = "transparency"; in init_options()
4900 s->opt[OPT_TRANSP_SW].title = SANE_I18N ("Transparency button"); in init_options()
4901 s->opt[OPT_TRANSP_SW].desc = SANE_I18N ("Transparency button"); in init_options()
4902 s->opt[OPT_TRANSP_SW].type = SANE_TYPE_BOOL; in init_options()
4903 s->opt[OPT_TRANSP_SW].unit = SANE_UNIT_NONE; in init_options()
4904 if (model->buttons & GENESYS_HAS_TRANSP_SW) in init_options()
4905 s->opt[OPT_TRANSP_SW].cap = in init_options()
4908 s->opt[OPT_TRANSP_SW].cap = SANE_CAP_INACTIVE; in init_options()
4911 s->opt[OPT_PDF1_SW].name = "pdf1"; in init_options()
4912 s->opt[OPT_PDF1_SW].title = SANE_I18N ("PDF function button 1"); in init_options()
4913 s->opt[OPT_PDF1_SW].desc = SANE_I18N ("PDF function button 1"); in init_options()
4914 s->opt[OPT_PDF1_SW].type = SANE_TYPE_BOOL; in init_options()
4915 s->opt[OPT_PDF1_SW].unit = SANE_UNIT_NONE; in init_options()
4916 if (model->buttons & GENESYS_HAS_PDF1_SW) in init_options()
4917 s->opt[OPT_PDF1_SW].cap = in init_options()
4920 s->opt[OPT_PDF1_SW].cap = SANE_CAP_INACTIVE; in init_options()
4923 s->opt[OPT_PDF2_SW].name = "pdf2"; in init_options()
4924 s->opt[OPT_PDF2_SW].title = SANE_I18N ("PDF function button 2"); in init_options()
4925 s->opt[OPT_PDF2_SW].desc = SANE_I18N ("PDF function button 2"); in init_options()
4926 s->opt[OPT_PDF2_SW].type = SANE_TYPE_BOOL; in init_options()
4927 s->opt[OPT_PDF2_SW].unit = SANE_UNIT_NONE; in init_options()
4928 if (model->buttons & GENESYS_HAS_PDF2_SW) in init_options()
4929 s->opt[OPT_PDF2_SW].cap = in init_options()
4932 s->opt[OPT_PDF2_SW].cap = SANE_CAP_INACTIVE; in init_options()
4935 s->opt[OPT_PDF3_SW].name = "pdf3"; in init_options()
4936 s->opt[OPT_PDF3_SW].title = SANE_I18N ("PDF function button 3"); in init_options()
4937 s->opt[OPT_PDF3_SW].desc = SANE_I18N ("PDF function button 3"); in init_options()
4938 s->opt[OPT_PDF3_SW].type = SANE_TYPE_BOOL; in init_options()
4939 s->opt[OPT_PDF3_SW].unit = SANE_UNIT_NONE; in init_options()
4940 if (model->buttons & GENESYS_HAS_PDF3_SW) in init_options()
4941 s->opt[OPT_PDF3_SW].cap = in init_options()
4944 s->opt[OPT_PDF3_SW].cap = SANE_CAP_INACTIVE; in init_options()
4947 s->opt[OPT_PDF4_SW].name = "pdf4"; in init_options()
4948 s->opt[OPT_PDF4_SW].title = SANE_I18N ("PDF function button 4"); in init_options()
4949 s->opt[OPT_PDF4_SW].desc = SANE_I18N ("PDF function button 4"); in init_options()
4950 s->opt[OPT_PDF4_SW].type = SANE_TYPE_BOOL; in init_options()
4951 s->opt[OPT_PDF4_SW].unit = SANE_UNIT_NONE; in init_options()
4952 if (model->buttons & GENESYS_HAS_PDF4_SW) in init_options()
4953 s->opt[OPT_PDF4_SW].cap = in init_options()
4956 s->opt[OPT_PDF4_SW].cap = SANE_CAP_INACTIVE; in init_options()
4959 s->opt[OPT_NEED_CALIBRATION_SW].name = "need-calibration"; in init_options()
4960 s->opt[OPT_NEED_CALIBRATION_SW].title = SANE_I18N ("Needs calibration"); in init_options()
4961 …s->opt[OPT_NEED_CALIBRATION_SW].desc = SANE_I18N ("The scanner needs calibration for the current s… in init_options()
4962 s->opt[OPT_NEED_CALIBRATION_SW].type = SANE_TYPE_BOOL; in init_options()
4963 s->opt[OPT_NEED_CALIBRATION_SW].unit = SANE_UNIT_NONE; in init_options()
4964 if (model->buttons & GENESYS_HAS_CALIBRATE) in init_options()
4965 s->opt[OPT_NEED_CALIBRATION_SW].cap = in init_options()
4968 s->opt[OPT_NEED_CALIBRATION_SW].cap = SANE_CAP_INACTIVE; in init_options()
4971 s->opt[OPT_BUTTON_GROUP].name = "buttons"; in init_options()
4972 s->opt[OPT_BUTTON_GROUP].title = SANE_I18N ("Buttons"); in init_options()
4973 s->opt[OPT_BUTTON_GROUP].desc = ""; in init_options()
4974 s->opt[OPT_BUTTON_GROUP].type = SANE_TYPE_GROUP; in init_options()
4975 s->opt[OPT_BUTTON_GROUP].cap = SANE_CAP_ADVANCED; in init_options()
4976 s->opt[OPT_BUTTON_GROUP].size = 0; in init_options()
4977 s->opt[OPT_BUTTON_GROUP].constraint_type = SANE_CONSTRAINT_NONE; in init_options()
4980 s->opt[OPT_CALIBRATE].name = "calibrate"; in init_options()
4981 s->opt[OPT_CALIBRATE].title = SANE_I18N ("Calibrate"); in init_options()
4982 s->opt[OPT_CALIBRATE].desc = in init_options()
4984 s->opt[OPT_CALIBRATE].type = SANE_TYPE_BUTTON; in init_options()
4985 s->opt[OPT_CALIBRATE].unit = SANE_UNIT_NONE; in init_options()
4986 if (model->buttons & GENESYS_HAS_CALIBRATE) in init_options()
4987 s->opt[OPT_CALIBRATE].cap = in init_options()
4991 s->opt[OPT_CALIBRATE].cap = SANE_CAP_INACTIVE; in init_options()
4994 s->opt[OPT_CLEAR_CALIBRATION].name = "clear-calibration"; in init_options()
4995 s->opt[OPT_CLEAR_CALIBRATION].title = SANE_I18N ("Clear calibration"); in init_options()
4996 s->opt[OPT_CLEAR_CALIBRATION].desc = SANE_I18N ("Clear calibration cache"); in init_options()
4997 s->opt[OPT_CLEAR_CALIBRATION].type = SANE_TYPE_BUTTON; in init_options()
4998 s->opt[OPT_CLEAR_CALIBRATION].unit = SANE_UNIT_NONE; in init_options()
4999 s->opt[OPT_CLEAR_CALIBRATION].size = 0; in init_options()
5000 s->opt[OPT_CLEAR_CALIBRATION].constraint_type = SANE_CONSTRAINT_NONE; in init_options()
5001 s->opt[OPT_CLEAR_CALIBRATION].cap = in init_options()
5005 s->opt[OPT_FORCE_CALIBRATION].name = "force-calibration"; in init_options()
5006 s->opt[OPT_FORCE_CALIBRATION].title = SANE_I18N("Force calibration"); in init_options()
5007 …s->opt[OPT_FORCE_CALIBRATION].desc = SANE_I18N("Force calibration ignoring all and any calibration… in init_options()
5008 s->opt[OPT_FORCE_CALIBRATION].type = SANE_TYPE_BUTTON; in init_options()
5009 s->opt[OPT_FORCE_CALIBRATION].unit = SANE_UNIT_NONE; in init_options()
5010 s->opt[OPT_FORCE_CALIBRATION].size = 0; in init_options()
5011 s->opt[OPT_FORCE_CALIBRATION].constraint_type = SANE_CONSTRAINT_NONE; in init_options()
5012 s->opt[OPT_FORCE_CALIBRATION].cap = in init_options()
5016 s->opt[OPT_IGNORE_OFFSETS].name = "ignore-internal-offsets"; in init_options()
5017 s->opt[OPT_IGNORE_OFFSETS].title = SANE_I18N("Ignore internal offsets"); in init_options()
5018 s->opt[OPT_IGNORE_OFFSETS].desc = in init_options()
5020 s->opt[OPT_IGNORE_OFFSETS].type = SANE_TYPE_BUTTON; in init_options()
5021 s->opt[OPT_IGNORE_OFFSETS].unit = SANE_UNIT_NONE; in init_options()
5022 s->opt[OPT_IGNORE_OFFSETS].size = 0; in init_options()
5023 s->opt[OPT_IGNORE_OFFSETS].constraint_type = SANE_CONSTRAINT_NONE; in init_options()
5024 s->opt[OPT_IGNORE_OFFSETS].cap = SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT | in init_options()
5041 const UsbDeviceEntry& get_matching_usb_dev(std::uint16_t vendor_id, std::uint16_t product_id, in get_matching_usb_dev()
5042 std::uint16_t bcd_device) in get_matching_usb_dev()
5056 std::uint16_t vendor_id, std::uint16_t product_id, in attach_usb_device()
5057 std::uint16_t bcd_device) in attach_usb_device()
5061 s_devices->emplace_back(); in attach_usb_device()
5062 Genesys_Device* dev = &s_devices->back(); in attach_usb_device()
5063 dev->file_name = devname; in attach_usb_device()
5064 dev->vendorId = vendor_id; in attach_usb_device()
5065 dev->productId = product_id; in attach_usb_device()
5066 dev->model = &usb_dev.model(); in attach_usb_device()
5067 dev->usb_mode = 0; // i.e. unset in attach_usb_device()
5068 dev->already_initialized = false; in attach_usb_device()
5106 /* KV-SS080 is an auxiliary device which requires a master device to be here */ in attach_device_by_name()
5120 dev->file_name.c_str()); in attach_device_by_name()
5176 DBG(DBG_info, "%s: %zu devices currently attached\n", __func__, s_devices->size()); in probe_genesys_devices()
5182 changes that don't change size -- at least for now, as we store most
5188 bool read_calibration(std::istream& str, Genesys_Device::Calibration& calibration, in read_calibration()
5189 const std::string& path) in read_calibration()
5193 std::string ident; in read_calibration()
5216 * from file defined in dev->calib_file
5219 const std::string& path) in sanei_genesys_read_calibration()
5223 std::ifstream str; in sanei_genesys_read_calibration()
5233 void write_calibration(std::ostream& str, Genesys_Device::Calibration& calibration) in write_calibration()
5235 std::string ident = CALIBRATION_IDENT; in write_calibration()
5243 static void write_calibration(Genesys_Device::Calibration& calibration, const std::string& path) in write_calibration()
5247 std::ofstream str; in write_calibration()
5255 /* -------------------------- SANE API functions ------------------------- */
5265 DBG(DBG_init, "SANE Genesys backend built with libusb-1.0\n"); in sane_init_impl()
5301 // cold-plug case :detection of already connected scanners in sane_init_impl()
5339 // hot-plug case : detection of newly connected scanners */ in sane_get_devices_impl()
5345 s_sane_devices->clear(); in sane_get_devices_impl()
5346 s_sane_devices_data->clear(); in sane_get_devices_impl()
5347 s_sane_devices_ptrs->clear(); in sane_get_devices_impl()
5348 s_sane_devices->reserve(s_devices->size()); in sane_get_devices_impl()
5349 s_sane_devices_data->reserve(s_devices->size()); in sane_get_devices_impl()
5350 s_sane_devices_ptrs->reserve(s_devices->size() + 1); in sane_get_devices_impl()
5352 for (auto dev_it = s_devices->begin(); dev_it != s_devices->end();) { in sane_get_devices_impl()
5358 sanei_usb_find_devices(dev_it->vendorId, dev_it->productId, check_present); in sane_get_devices_impl()
5362 s_sane_devices->emplace_back(); in sane_get_devices_impl()
5363 s_sane_devices_data->emplace_back(); in sane_get_devices_impl()
5364 auto& sane_device = s_sane_devices->back(); in sane_get_devices_impl()
5365 auto& sane_device_data = s_sane_devices_data->back(); in sane_get_devices_impl()
5366 sane_device_data.name = dev_it->file_name; in sane_get_devices_impl()
5368 sane_device.vendor = dev_it->model->vendor; in sane_get_devices_impl()
5369 sane_device.model = dev_it->model->model; in sane_get_devices_impl()
5371 s_sane_devices_ptrs->push_back(&sane_device); in sane_get_devices_impl()
5374 dev_it = s_devices->erase(dev_it); in sane_get_devices_impl()
5377 s_sane_devices_ptrs->push_back(nullptr); in sane_get_devices_impl()
5379 *const_cast<SANE_Device***>(device_list) = s_sane_devices_ptrs->data(); in sane_get_devices_impl()
5409 DBG(DBG_info, "%s: found `%s' in devlist\n", __func__, dev->file_name.c_str()); in sane_open_impl()
5420 // empty devicename or "genesys" -> use first device in sane_open_impl()
5421 if (!s_devices->empty()) { in sane_open_impl()
5422 dev = &s_devices->front(); in sane_open_impl()
5423 DBG(DBG_info, "%s: empty devicename, trying `%s'\n", __func__, dev->file_name.c_str()); in sane_open_impl()
5432 // during testing we need to initialize dev->model before test scanner interface is created in sane_open_impl()
5438 dev->model = &get_matching_usb_dev(vendor_id, product_id, bcd_device).model(); in sane_open_impl()
5440 auto interface = std::unique_ptr<TestScannerInterface>{ in sane_open_impl()
5442 interface->set_checkpoint_callback(get_testing_checkpoint_callback()); in sane_open_impl()
5443 dev->interface = std::move(interface); in sane_open_impl()
5445 dev->interface->get_usb_device().open(dev->file_name.c_str()); in sane_open_impl()
5447 dev->interface = std::unique_ptr<ScannerInterfaceUsb>{new ScannerInterfaceUsb{dev}}; in sane_open_impl()
5449 dbg.vstatus("open device '%s'", dev->file_name.c_str()); in sane_open_impl()
5450 dev->interface->get_usb_device().open(dev->file_name.c_str()); in sane_open_impl()
5453 auto bcd_device = dev->interface->get_usb_device().get_bcd_device(); in sane_open_impl()
5455 dev->model = &get_matching_usb_dev(dev->vendorId, dev->productId, bcd_device).model(); in sane_open_impl()
5458 dbg.vlog(DBG_info, "Opened device %s", dev->model->name); in sane_open_impl()
5460 if (has_flag(dev->model->flags, ModelFlag::UNTESTED)) { in sane_open_impl()
5464 DBG(DBG_error0, " sane-devel@alioth-lists.debian.net. Please provide as many\n"); in sane_open_impl()
5469 s_scanners->push_back(Genesys_Scanner()); in sane_open_impl()
5470 auto* s = &s_scanners->back(); in sane_open_impl()
5472 s->dev = dev; in sane_open_impl()
5473 s->scanning = false; in sane_open_impl()
5474 dev->parking = false; in sane_open_impl()
5475 dev->read_active = false; in sane_open_impl()
5476 dev->force_calibration = 0; in sane_open_impl()
5477 dev->line_count = 0; in sane_open_impl()
5481 if (!dev->already_initialized) { in sane_open_impl()
5485 dev->cmd_set = create_cmd_set(dev->model->asic_type); in sane_open_impl()
5493 dev->cmd_set->init(dev); in sane_open_impl()
5496 dev->cmd_set->update_hardware_sensors (s); in sane_open_impl()
5514 auto it = s_scanners->end(); in sane_close_impl()
5515 for (auto it2 = s_scanners->begin(); it2 != s_scanners->end(); it2++) in sane_close_impl()
5522 if (it == s_scanners->end()) in sane_close_impl()
5528 auto* dev = it->dev; in sane_close_impl()
5531 if (dev->model->is_sheetfed) { in sane_close_impl()
5532 catch_all_exceptions(__func__, [&](){ dev->cmd_set->eject_document(dev); }); in sane_close_impl()
5535 if (dev->parking) { in sane_close_impl()
5541 dev->cmd_set->save_power(dev, true); in sane_close_impl()
5544 if (dev->force_calibration == 0 && !is_testing_mode()) { in sane_close_impl()
5545 catch_all_exceptions(__func__, [&](){ write_calibration(dev->calibration_cache, in sane_close_impl()
5546 dev->calib_file); }); in sane_close_impl()
5549 dev->already_initialized = false; in sane_close_impl()
5550 dev->clear(); in sane_close_impl()
5553 dev->interface->write_register(0x03, 0x00); in sane_close_impl()
5555 catch_all_exceptions(__func__, [&](){ dev->interface->get_usb_device().clear_halt(); }); in sane_close_impl()
5558 catch_all_exceptions(__func__, [&](){ dev->interface->get_usb_device().reset(); }); in sane_close_impl()
5561 catch_all_exceptions(__func__, [&](){ dev->interface->get_usb_device().close(); }); in sane_close_impl()
5563 s_scanners->erase(it); in sane_close_impl()
5585 DBG(DBG_io2, "%s: option = %s (%d)\n", __func__, s->opt[option].name, option); in sane_get_option_descriptor_impl()
5586 return s->opt + option; in sane_get_option_descriptor_impl()
5622 dbg.log(DBG_proc, "value: (non-printable)"); in print_option()
5627 DBG_HELPER_ARGS(dbg, "option: %s (%d)", s->opt[option].name, option); in get_option_value()
5628 auto* dev = s->dev; in get_option_value()
5631 std::vector<std::uint16_t> gamma_table; in get_option_value()
5635 if (sanei_genesys_has_sensor(dev, dev->settings.xres, dev->settings.get_channels(), in get_option_value()
5636 dev->settings.scan_method)) in get_option_value()
5638 sensor = &sanei_genesys_find_sensor(dev, dev->settings.xres, in get_option_value()
5639 dev->settings.get_channels(), in get_option_value()
5640 dev->settings.scan_method); in get_option_value()
5647 *reinterpret_cast<SANE_Word*>(val) = s->pos_top_left_x; in get_option_value()
5650 *reinterpret_cast<SANE_Word*>(val) = s->pos_top_left_y; in get_option_value()
5653 *reinterpret_cast<SANE_Word*>(val) = s->pos_bottom_right_x; in get_option_value()
5656 *reinterpret_cast<SANE_Word*>(val) = s->pos_bottom_right_y; in get_option_value()
5663 *reinterpret_cast<SANE_Word*>(val) = s->resolution; in get_option_value()
5666 *reinterpret_cast<SANE_Word*>(val) = s->bit_depth; in get_option_value()
5669 *reinterpret_cast<SANE_Word*>(val) = s->preview; in get_option_value()
5672 *reinterpret_cast<SANE_Word*>(val) = s->lamp_off; in get_option_value()
5675 *reinterpret_cast<SANE_Word*>(val) = s->lamp_off_time; in get_option_value()
5678 *reinterpret_cast<SANE_Word*>(val) = s->contrast; in get_option_value()
5681 *reinterpret_cast<SANE_Word*>(val) = s->brightness; in get_option_value()
5684 *reinterpret_cast<SANE_Word*>(val) = s->expiration_time; in get_option_value()
5687 *reinterpret_cast<SANE_Word*>(val) = s->custom_gamma; in get_option_value()
5692 std::strcpy(reinterpret_cast<char*>(val), s->mode.c_str()); in get_option_value()
5695 std::strcpy(reinterpret_cast<char*>(val), s->color_filter.c_str()); in get_option_value()
5698 std::strcpy(reinterpret_cast<char*>(val), s->calibration_file.c_str()); in get_option_value()
5701 std::strcpy(reinterpret_cast<char*>(val), scan_method_to_option_string(s->scan_method)); in get_option_value()
5710 if (s->color_filter == "Red") { in get_option_value()
5712 } else if (s->color_filter == "Blue") { in get_option_value()
5717 option_size = s->opt[option].size / sizeof (SANE_Word); in get_option_value()
5719 throw std::runtime_error("The size of the gamma tables does not match"); in get_option_value()
5731 option_size = s->opt[option].size / sizeof (SANE_Word); in get_option_value()
5733 throw std::runtime_error("The size of the gamma tables does not match"); in get_option_value()
5745 option_size = s->opt[option].size / sizeof (SANE_Word); in get_option_value()
5747 throw std::runtime_error("The size of the gamma tables does not match"); in get_option_value()
5759 option_size = s->opt[option].size / sizeof (SANE_Word); in get_option_value()
5761 throw std::runtime_error("The size of the gamma tables does not match"); in get_option_value()
5781 s->dev->cmd_set->update_hardware_sensors(s); in get_option_value()
5782 *reinterpret_cast<SANE_Bool*>(val) = s->buttons[genesys_option_to_button(option)].read(); in get_option_value()
5795 auto session = dev->cmd_set->calculate_scan_session(dev, *sensor, dev->settings); in get_option_value()
5797 for (auto& cache : dev->calibration_cache) { in get_option_value()
5817 auto dev = s->dev; in set_calibration_value()
5819 std::string new_calib_path = val; in set_calibration_value()
5832 dev->calibration_cache = std::move(new_calibration); in set_calibration_value()
5833 dev->calib_file = new_calib_path; in set_calibration_value()
5834 s->calibration_file = new_calib_path; in set_calibration_value()
5841 DBG_HELPER_ARGS(dbg, "option: %s (%d)", s->opt[option].name, option); in set_option_value()
5844 auto* dev = s->dev; in set_option_value()
5852 s->pos_top_left_x = *reinterpret_cast<SANE_Word*>(val); in set_option_value()
5857 s->pos_top_left_y = *reinterpret_cast<SANE_Word*>(val); in set_option_value()
5862 s->pos_bottom_right_x = *reinterpret_cast<SANE_Word*>(val); in set_option_value()
5867 s->pos_bottom_right_y = *reinterpret_cast<SANE_Word*>(val); in set_option_value()
5872 s->resolution = *reinterpret_cast<SANE_Word*>(val); in set_option_value()
5877 s->lamp_off = *reinterpret_cast<SANE_Word*>(val); in set_option_value()
5882 s->preview = *reinterpret_cast<SANE_Word*>(val); in set_option_value()
5887 s->brightness = *reinterpret_cast<SANE_Word*>(val); in set_option_value()
5892 s->contrast = *reinterpret_cast<SANE_Word*>(val); in set_option_value()
5898 s->bit_depth = *reinterpret_cast<SANE_Word*>(val); in set_option_value()
5899 if(s->bit_depth>8) in set_option_value()
5912 if (s->scan_method != scan_method) { in set_option_value()
5913 s->scan_method = scan_method; in set_option_value()
5923 s->mode = reinterpret_cast<const char*>(val); in set_option_value()
5925 if (s->mode == SANE_VALUE_SCAN_MODE_GRAY) { in set_option_value()
5926 if (dev->model->asic_type != AsicType::GL646 || !dev->model->is_cis) { in set_option_value()
5929 create_bpp_list(s, dev->model->bpp_gray_values); in set_option_value()
5930 s->bit_depth = dev->model->bpp_gray_values[0]; in set_option_value()
5933 create_bpp_list(s, dev->model->bpp_color_values); in set_option_value()
5934 s->bit_depth = dev->model->bpp_color_values[0]; in set_option_value()
5940 if (s->custom_gamma) in set_option_value()
5942 if (s->mode == SANE_VALUE_SCAN_MODE_COLOR) in set_option_value()
5962 s->color_filter = reinterpret_cast<const char*>(val); in set_option_value()
5966 if (dev->force_calibration == 0) { in set_option_value()
5972 if (*reinterpret_cast<SANE_Word*>(val) != s->lamp_off_time) { in set_option_value()
5973 s->lamp_off_time = *reinterpret_cast<SANE_Word*>(val); in set_option_value()
5974 dev->cmd_set->set_powersaving(dev, s->lamp_off_time); in set_option_value()
5979 if (*reinterpret_cast<SANE_Word*>(val) != s->expiration_time) { in set_option_value()
5980 s->expiration_time = *reinterpret_cast<SANE_Word*>(val); in set_option_value()
5986 s->custom_gamma = *reinterpret_cast<SANE_Bool*>(val); in set_option_value()
5988 if (s->custom_gamma) { in set_option_value()
5989 if (s->mode == SANE_VALUE_SCAN_MODE_COLOR) in set_option_value()
6010 for (auto& table : dev->gamma_override_tables) { in set_option_value()
6019 option_size = s->opt[option].size / sizeof (SANE_Word); in set_option_value()
6021 dev->gamma_override_tables[GENESYS_RED].resize(option_size); in set_option_value()
6022 dev->gamma_override_tables[GENESYS_GREEN].resize(option_size); in set_option_value()
6023 dev->gamma_override_tables[GENESYS_BLUE].resize(option_size); in set_option_value()
6025 dev->gamma_override_tables[GENESYS_RED][i] = table[i]; in set_option_value()
6026 dev->gamma_override_tables[GENESYS_GREEN][i] = table[i]; in set_option_value()
6027 dev->gamma_override_tables[GENESYS_BLUE][i] = table[i]; in set_option_value()
6033 option_size = s->opt[option].size / sizeof (SANE_Word); in set_option_value()
6034 dev->gamma_override_tables[GENESYS_RED].resize(option_size); in set_option_value()
6036 dev->gamma_override_tables[GENESYS_RED][i] = table[i]; in set_option_value()
6042 option_size = s->opt[option].size / sizeof (SANE_Word); in set_option_value()
6043 dev->gamma_override_tables[GENESYS_GREEN].resize(option_size); in set_option_value()
6045 dev->gamma_override_tables[GENESYS_GREEN][i] = table[i]; in set_option_value()
6051 option_size = s->opt[option].size / sizeof (SANE_Word); in set_option_value()
6052 dev->gamma_override_tables[GENESYS_BLUE].resize(option_size); in set_option_value()
6054 dev->gamma_override_tables[GENESYS_BLUE][i] = table[i]; in set_option_value()
6059 auto& sensor = sanei_genesys_find_sensor_for_write(dev, dev->settings.xres, in set_option_value()
6060 dev->settings.get_channels(), in set_option_value()
6061 dev->settings.scan_method); in set_option_value()
6064 dev->cmd_set->save_power(dev, false); in set_option_value()
6069 dev->cmd_set->save_power(dev, true); in set_option_value()
6075 dev->calibration_cache.clear(); in set_option_value()
6078 unlink(dev->calib_file.c_str()); in set_option_value()
6084 dev->force_calibration = 1; in set_option_value()
6085 dev->calibration_cache.clear(); in set_option_value()
6086 dev->calib_file.clear(); in set_option_value()
6094 dev->ignore_offsets = true; in set_option_value()
6113 s->opt[option].name, option); in sane_control_option_impl()
6115 SANE_Word cap; in sane_control_option_impl() local
6122 if (s->scanning) { in sane_control_option_impl()
6125 s->opt[option].name, option); in sane_control_option_impl()
6131 cap = s->opt[option].cap; in sane_control_option_impl()
6133 if (!SANE_OPTION_IS_ACTIVE (cap)) { in sane_control_option_impl()
6143 if (!SANE_OPTION_IS_SETTABLE (cap)) { in sane_control_option_impl()
6147 TIE(sanei_constrain_value(s->opt + option, val, &myinfo)); in sane_control_option_impl()
6177 auto* dev = s->dev; in sane_get_parameters_impl()
6180 if (!dev->read_active) { in sane_get_parameters_impl()
6184 *params = s->params; in sane_get_parameters_impl()
6187 * we override the computed line number with -1 to signal that we in sane_get_parameters_impl()
6191 if (dev->model->is_sheetfed && in sane_get_parameters_impl()
6192 s->pos_bottom_right_y == s->opt[OPT_BR_Y].constraint.range->max) in sane_get_parameters_impl()
6194 params->lines = -1; in sane_get_parameters_impl()
6213 auto* dev = s->dev; in sane_start_impl()
6215 if (s->pos_top_left_x >= s->pos_bottom_right_x) { in sane_start_impl()
6218 if (s->pos_top_left_y >= s->pos_bottom_right_y) { in sane_start_impl()
6223 if (dev->force_calibration == 0) { in sane_start_impl()
6225 s->calibration_file = path; in sane_start_impl()
6226 dev->calib_file = path; in sane_start_impl()
6228 DBG(DBG_info, "%s: >%s<\n", __func__, dev->calib_file.c_str()); in sane_start_impl()
6232 sanei_genesys_read_calibration(dev->calibration_cache, dev->calib_file); in sane_start_impl()
6240 genesys_start_scan(dev, s->lamp_off); in sane_start_impl()
6242 s->scanning = true; in sane_start_impl()
6265 auto* dev = s->dev; in sane_read_impl()
6280 if (!s->scanning) { in sane_read_impl()
6287 dev->total_bytes_to_read, dev->total_bytes_read); in sane_read_impl()
6289 if(dev->total_bytes_read>=dev->total_bytes_to_read) in sane_read_impl()
6295 if (!dev->model->is_sheetfed && !has_flag(dev->model->flags, ModelFlag::MUST_WAIT) && in sane_read_impl()
6296 !dev->parking) in sane_read_impl()
6298 dev->cmd_set->move_back_home(dev, false); in sane_read_impl()
6299 dev->parking = true; in sane_read_impl()
6309 if (local_len > static_cast<std::size_t>(max_len)) { in sane_read_impl()
6329 auto* dev = s->dev; in sane_cancel_impl()
6331 s->scanning = false; in sane_cancel_impl()
6332 dev->read_active = false; in sane_cancel_impl()
6335 if (!dev->parking) { in sane_cancel_impl()
6336 dev->cmd_set->end_scan(dev, &dev->reg, true); in sane_cancel_impl()
6340 if (!dev->model->is_sheetfed) { in sane_cancel_impl()
6341 if (!dev->parking) { in sane_cancel_impl()
6342 dev->cmd_set->move_back_home(dev, has_flag(dev->model->flags, ModelFlag::MUST_WAIT)); in sane_cancel_impl()
6343 dev->parking = !has_flag(dev->model->flags, ModelFlag::MUST_WAIT); in sane_cancel_impl()
6347 dev->cmd_set->eject_document(dev); in sane_cancel_impl()
6351 if (!dev->parking) { in sane_cancel_impl()
6352 dev->cmd_set->save_power(dev, true); in sane_cancel_impl()
6368 if (!s->scanning) { in sane_set_io_mode_impl()
6390 if (!s->scanning) { in sane_get_select_fd_impl()
6421 default: throw std::runtime_error("Unknown option to convert to button index"); in genesys_option_to_button()