From f5410b7738e46689a64e95279ea17b5178356785 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Sat, 2 Nov 2019 17:13:14 +0200 Subject: [PATCH 1/7] genesys: Add an easy way to override SANE API linkage --- backend/genesys/genesys.cpp | 44 +++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/backend/genesys/genesys.cpp b/backend/genesys/genesys.cpp index df6cca0f7..f0d5a230a 100644 --- a/backend/genesys/genesys.cpp +++ b/backend/genesys/genesys.cpp @@ -77,6 +77,10 @@ #include #include +#ifndef SANE_GENESYS_API_LINKAGE +#define SANE_GENESYS_API_LINKAGE extern "C" +#endif + namespace genesys { // Data that we allocate to back SANE_Device objects in s_sane_devices @@ -4706,7 +4710,8 @@ void sane_init_impl(SANE_Int * version_code, SANE_Auth_Callback authorize) } -extern "C" SANE_Status sane_init(SANE_Int * version_code, SANE_Auth_Callback authorize) +SANE_GENESYS_API_LINKAGE +SANE_Status sane_init(SANE_Int * version_code, SANE_Auth_Callback authorize) { return wrap_exceptions_to_status_code(__func__, [=]() { @@ -4724,7 +4729,8 @@ sane_exit_impl(void) run_functions_at_backend_exit(); } -extern "C" void sane_exit() +SANE_GENESYS_API_LINKAGE +void sane_exit() { catch_all_exceptions(__func__, [](){ sane_exit_impl(); }); } @@ -4768,7 +4774,8 @@ void sane_get_devices_impl(const SANE_Device *** device_list, SANE_Bool local_on *const_cast(device_list) = s_sane_devices_ptrs->data(); } -extern "C" SANE_Status sane_get_devices(const SANE_Device *** device_list, SANE_Bool local_only) +SANE_GENESYS_API_LINKAGE +SANE_Status sane_get_devices(const SANE_Device *** device_list, SANE_Bool local_only) { return wrap_exceptions_to_status_code(__func__, [=]() { @@ -4873,7 +4880,8 @@ static void sane_open_impl(SANE_String_Const devicename, SANE_Handle * handle) } } -extern "C" SANE_Status sane_open(SANE_String_Const devicename, SANE_Handle* handle) +SANE_GENESYS_API_LINKAGE +SANE_Status sane_open(SANE_String_Const devicename, SANE_Handle* handle) { return wrap_exceptions_to_status_code(__func__, [=]() { @@ -4943,7 +4951,8 @@ sane_close_impl(SANE_Handle handle) s_scanners->erase(it); } -extern "C" void sane_close(SANE_Handle handle) +SANE_GENESYS_API_LINKAGE +void sane_close(SANE_Handle handle) { catch_all_exceptions(__func__, [=]() { @@ -4966,8 +4975,8 @@ sane_get_option_descriptor_impl(SANE_Handle handle, SANE_Int option) } -extern "C" const SANE_Option_Descriptor* -sane_get_option_descriptor(SANE_Handle handle, SANE_Int option) +SANE_GENESYS_API_LINKAGE +const SANE_Option_Descriptor* sane_get_option_descriptor(SANE_Handle handle, SANE_Int option) { const SANE_Option_Descriptor* ret = nullptr; catch_all_exceptions(__func__, [&]() @@ -5630,7 +5639,8 @@ void sane_control_option_impl(SANE_Handle handle, SANE_Int option, *info = myinfo; } -extern "C" SANE_Status sane_control_option(SANE_Handle handle, SANE_Int option, +SANE_GENESYS_API_LINKAGE +SANE_Status sane_control_option(SANE_Handle handle, SANE_Int option, SANE_Action action, void *val, SANE_Int * info) { return wrap_exceptions_to_status_code(__func__, [=]() @@ -5666,7 +5676,8 @@ void sane_get_parameters_impl(SANE_Handle handle, SANE_Parameters* params) debug_dump(DBG_proc, *params); } -extern "C" SANE_Status sane_get_parameters(SANE_Handle handle, SANE_Parameters* params) +SANE_GENESYS_API_LINKAGE +SANE_Status sane_get_parameters(SANE_Handle handle, SANE_Parameters* params) { return wrap_exceptions_to_status_code(__func__, [=]() { @@ -5749,7 +5760,8 @@ void sane_start_impl(SANE_Handle handle) } } -extern "C" SANE_Status sane_start(SANE_Handle handle) +SANE_GENESYS_API_LINKAGE +SANE_Status sane_start(SANE_Handle handle) { return wrap_exceptions_to_status_code(__func__, [=]() { @@ -5870,7 +5882,8 @@ void sane_read_impl(SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, SANE_ DBG(DBG_proc, "%s: %d bytes returned\n", __func__, *len); } -extern "C" SANE_Status sane_read(SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, SANE_Int* len) +SANE_GENESYS_API_LINKAGE +SANE_Status sane_read(SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, SANE_Int* len) { return wrap_exceptions_to_status_code(__func__, [=]() { @@ -5914,7 +5927,8 @@ void sane_cancel_impl(SANE_Handle handle) return; } -extern "C" void sane_cancel(SANE_Handle handle) +SANE_GENESYS_API_LINKAGE +void sane_cancel(SANE_Handle handle) { catch_all_exceptions(__func__, [=]() { sane_cancel_impl(handle); }); } @@ -5933,7 +5947,8 @@ void sane_set_io_mode_impl(SANE_Handle handle, SANE_Bool non_blocking) } } -extern "C" SANE_Status sane_set_io_mode(SANE_Handle handle, SANE_Bool non_blocking) +SANE_GENESYS_API_LINKAGE +SANE_Status sane_set_io_mode(SANE_Handle handle, SANE_Bool non_blocking) { return wrap_exceptions_to_status_code(__func__, [=]() { @@ -5952,7 +5967,8 @@ void sane_get_select_fd_impl(SANE_Handle handle, SANE_Int* fd) throw SaneException(SANE_STATUS_UNSUPPORTED); } -extern "C" SANE_Status sane_get_select_fd(SANE_Handle handle, SANE_Int* fd) +SANE_GENESYS_API_LINKAGE +SANE_Status sane_get_select_fd(SANE_Handle handle, SANE_Int* fd) { return wrap_exceptions_to_status_code(__func__, [=]() { From a7ca16a415e526bae47d9e98eae282408875c001 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Sat, 2 Nov 2019 17:13:15 +0200 Subject: [PATCH 2/7] genesys: Add file with class forward declarations --- backend/Makefile.am | 1 + backend/genesys/command_set.h | 2 +- backend/genesys/fwd.h | 129 ++++++++++++++++++++++++++++++++++ backend/genesys/low.h | 5 +- 4 files changed, 132 insertions(+), 5 deletions(-) create mode 100644 backend/genesys/fwd.h diff --git a/backend/Makefile.am b/backend/Makefile.am index 95714080c..be35cd265 100644 --- a/backend/Makefile.am +++ b/backend/Makefile.am @@ -493,6 +493,7 @@ libgenesys_la_SOURCES = genesys/genesys.cpp genesys/genesys.h \ genesys/device.h genesys/device.cpp \ genesys/enums.h \ genesys/error.h genesys/error.cpp \ + genesys/fwd.h \ genesys/gl646.cpp genesys/gl646.h genesys/gl646_registers.h \ genesys/gl124.cpp genesys/gl124.h genesys/gl124_registers.h \ genesys/gl841.cpp genesys/gl841.h genesys/gl841_registers.h \ diff --git a/backend/genesys/command_set.h b/backend/genesys/command_set.h index f350bbdb4..3df60a482 100644 --- a/backend/genesys/command_set.h +++ b/backend/genesys/command_set.h @@ -45,11 +45,11 @@ #define BACKEND_GENESYS_COMMAND_SET_H #include "device.h" +#include "fwd.h" #include namespace genesys { -class Genesys_Device; /** Scanner command set description. diff --git a/backend/genesys/fwd.h b/backend/genesys/fwd.h new file mode 100644 index 000000000..8b5df9e02 --- /dev/null +++ b/backend/genesys/fwd.h @@ -0,0 +1,129 @@ +/* sane - Scanner Access Now Easy. + + Copyright (C) 2019 Povilas Kanapickas + + This file is part of the SANE package. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA. + + As a special exception, the authors of SANE give permission for + additional uses of the libraries contained in this release of SANE. + + The exception is that, if you link a SANE library with other files + to produce an executable, this does not by itself cause the + resulting executable to be covered by the GNU General Public + License. Your use of that executable is in no way restricted on + account of linking the SANE library code into it. + + This exception does not, however, invalidate any other reasons why + the executable file might be covered by the GNU General Public + License. + + If you submit changes to SANE to the maintainers to be included in + a subsequent release, you agree by submitting the changes that + those changes may be distributed with this exception intact. + + If you write modifications of your own for SANE, it is your choice + whether to permit this exception to apply to your modifications. + If you do not wish that, delete this exception notice. +*/ + +#ifndef BACKEND_GENESYS_FWD_H +#define BACKEND_GENESYS_FWD_H + +namespace genesys { + +// buffer.h +struct Genesys_Buffer; + +// calibration.h +struct Genesys_Calibration_Cache; + +// command_set.h +class CommandSet; + +// device.h +class FixedFloat; +struct Genesys_Gpo; +struct MethodResolutions; +struct Genesys_Model; +struct Genesys_Device; + +// error.h +class DebugMessageHelper; +class SaneException; + +// genesys.h +class GenesysButton; +struct Genesys_Scanner; + +// image.h +class Image; + +// image_buffer.h +class ImageBuffer; +class FakeBufferModel; +class ImageBufferGenesysUsb; + +// image_pipeline.h +class ImagePipelineNode; +// ImagePipelineNode* skipped +class ImagePipelineStack; + +// image_pixel.h +struct Pixel; +struct RawPixel; + +// low.h +struct Genesys_USB_Device_Entry; +struct Motor_Profile; + +// motor.h +struct Genesys_Motor; +struct Genesys_Motor_Slope; + +// register.h +class Genesys_Register_Set; +struct GenesysRegister; +struct GenesysRegisterSetState; + +// row_buffer.h +class RowBuffer; + +// sanei.h +class UsbDevice; + +// scanner_interface.h +class ScannerInterface; +class ScannerInterfaceUsb; +class TestScannerInterface; + +// sensor.h +class ResolutionFilter; +struct GenesysFrontendLayout; +struct Genesys_Frontend; +struct SensorExposure; +struct SensorProfile; +struct Genesys_Sensor; + +// settings.h +struct Genesys_Settings; +struct SetupParams; +struct ScanSession; + +} // namespace genesys + +#endif diff --git a/backend/genesys/low.h b/backend/genesys/low.h index 36a5589c5..e9bfccee9 100644 --- a/backend/genesys/low.h +++ b/backend/genesys/low.h @@ -84,6 +84,7 @@ #include "device.h" #include "enums.h" #include "error.h" +#include "fwd.h" #include "sanei.h" #include "sensor.h" #include "serialize.h" @@ -209,10 +210,6 @@ namespace genesys { -/* Forward typedefs */ -struct Genesys_Scanner; -typedef struct Genesys_Calibration_Cache Genesys_Calibration_Cache; - struct Genesys_USB_Device_Entry { Genesys_USB_Device_Entry(unsigned v, unsigned p, const Genesys_Model& m) : From 429d8e4d5b811fa70383ab5d3f8d414733181158 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Sat, 2 Nov 2019 17:13:16 +0200 Subject: [PATCH 3/7] genesys: Remove unused code --- backend/genesys/gl646.cpp | 64 -------------------------------- backend/genesys/gl841.cpp | 78 --------------------------------------- backend/genesys/low.h | 1 - 3 files changed, 143 deletions(-) diff --git a/backend/genesys/gl646.cpp b/backend/genesys/gl646.cpp index 01b87f965..c8e6cfedb 100644 --- a/backend/genesys/gl646.cpp +++ b/backend/genesys/gl646.cpp @@ -631,66 +631,6 @@ gl646_setup_sensor (Genesys_Device * dev, const Genesys_Sensor& sensor, Genesys_ DBG(DBG_proc, "%s: end\n", __func__); } -/** Test if the ASIC works - */ -static void gl646_asic_test(Genesys_Device* dev) -{ - DBG_HELPER(dbg); - size_t size, verify_size; - unsigned int i; - - // set and read exposure time, compare if it's the same - dev->write_register(0x38, 0xde); - - dev->write_register(0x39, 0xad); - - uint8_t val = dev->read_register(0x4e); - - if (val != 0xde) /* value of register 0x38 */ - { - throw SaneException("register contains invalid value"); - } - - val = dev->read_register(0x4f); - - if (val != 0xad) /* value of register 0x39 */ - { - throw SaneException("register contains invalid value"); - } - - /* ram test: */ - size = 0x40000; - verify_size = size + 0x80; - /* todo: looks like the read size must be a multiple of 128? - otherwise the read doesn't succeed the second time after the scanner has - been plugged in. Very strange. */ - - std::vector data(size); - std::vector verify_data(verify_size); - - for (i = 0; i < (size - 1); i += 2) - { - data[i] = i / 512; - data[i + 1] = (i / 2) % 256; - } - - sanei_genesys_set_buffer_address(dev, 0x0000); - sanei_genesys_bulk_write_data(dev, 0x3c, data.data(), size); - sanei_genesys_set_buffer_address(dev, 0x0000); - - dev->cmd_set->bulk_read_data(dev, 0x45, verify_data.data(), verify_size); - - /* i + 2 is needed as the changed address goes into effect only after one - data word is sent. */ - for (i = 0; i < size; i++) - { - if (verify_data[i + 2] != data[i]) - { - throw SaneException("data verification error"); - } - } -} - /** * Set all registers to default values after init * @param dev scannerr's device to set @@ -2901,10 +2841,6 @@ void CommandSetGl646::init(Genesys_Device* dev) const // Write initial registers dev->write_registers(dev->reg); - if (dev->model->flags & GENESYS_FLAG_TEST_ON_INIT) { - gl646_asic_test(dev); - } - // send gamma tables if needed dev->cmd_set->send_gamma_table(dev, sensor); diff --git a/backend/genesys/gl841.cpp b/backend/genesys/gl841.cpp index 443774584..c1f9e2c5a 100644 --- a/backend/genesys/gl841.cpp +++ b/backend/genesys/gl841.cpp @@ -212,80 +212,6 @@ static void sanei_gl841_setup_sensor(Genesys_Device * dev, const Genesys_Sensor& } } -/** Test if the ASIC works - */ -// TODO: make this functional -static void sanei_gl841_asic_test(Genesys_Device* dev) -{ - DBG_HELPER(dbg); - - size_t size, verify_size; - unsigned int i; - - throw SaneException("not implemented"); - - // set and read exposure time, compare if it's the same - dev->write_register(0x38, 0xde); - dev->write_register(0x39, 0xad); - - uint8_t val = dev->read_register(0x38); - - if (val != 0xde) /* value of register 0x38 */ - { - throw SaneException("register contains invalid value"); - } - - val = dev->read_register(0x39); - - if (val != 0xad) /* value of register 0x39 */ - { - throw SaneException("register contains invalid value"); - } - - /* ram test: */ - size = 0x40000; - verify_size = size + 0x80; - /* todo: looks like the read size must be a multiple of 128? - otherwise the read doesn't succeed the second time after the scanner has - been plugged in. Very strange. */ - - std::vector data(size); - std::vector verify_data(verify_size); - - for (i = 0; i < (size - 1); i += 2) - { - data[i] = i / 512; - data[i + 1] = (i / 2) % 256; - } - - sanei_genesys_set_buffer_address(dev, 0x0000); - - // sanei_genesys_bulk_write_data(dev, 0x3c, data, size); - - sanei_genesys_set_buffer_address(dev, 0x0000); - - sanei_genesys_bulk_read_data(dev, 0x45, verify_data.data(), verify_size); - - /* todo: why i + 2 ? */ - for (i = 0; i < size; i++) - { - if (verify_data[i] != data[i]) - { - DBG(DBG_info, "0x%.8x: got %.2x %.2x %.2x %.2x, expected %.2x %.2x %.2x %.2x\n", - i, - verify_data[i], - verify_data[i+1], - verify_data[i+2], - verify_data[i+3], - data[i], - data[i+1], - data[i+2], - data[i+3]); - throw SaneException("data verification error"); - } - } -} - /* * Set all registers LiDE 80 to default values * (function called only once at the beginning) @@ -3661,10 +3587,6 @@ void CommandSetGl841::init(Genesys_Device* dev) const // Write initial registers dev->write_registers(dev->reg); - if (dev->model->flags & GENESYS_FLAG_TEST_ON_INIT) { - sanei_gl841_asic_test(dev); - } - const auto& sensor = sanei_genesys_find_sensor_any(dev); // Set analog frontend diff --git a/backend/genesys/low.h b/backend/genesys/low.h index e9bfccee9..9746c524f 100644 --- a/backend/genesys/low.h +++ b/backend/genesys/low.h @@ -109,7 +109,6 @@ /* Flags */ #define GENESYS_FLAG_UNTESTED (1 << 0) /**< Print a warning for these scanners */ #define GENESYS_FLAG_14BIT_GAMMA (1 << 1) /**< use 14bit Gamma table instead of 12 */ -#define GENESYS_FLAG_TEST_ON_INIT (1 << 2) // perform ASIC test on initialization #define GENESYS_FLAG_XPA (1 << 3) #define GENESYS_FLAG_SKIP_WARMUP (1 << 4) /**< skip genesys_warmup() */ /** @brief offset calibration flag From 6fe1db1c734b9df8afe3c7a5c46203a7c858ece4 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Sat, 2 Nov 2019 17:13:17 +0200 Subject: [PATCH 4/7] genesys: Use std where needed --- backend/genesys/gl124.cpp | 15 +++++++-------- backend/genesys/gl646.cpp | 28 ++++++++++++++-------------- backend/genesys/gl841.cpp | 23 +++++++++++------------ backend/genesys/gl843.cpp | 27 +++++++++++++-------------- backend/genesys/gl846.cpp | 10 +++++----- backend/genesys/gl847.cpp | 10 +++++----- backend/genesys/low.cpp | 8 +++----- 7 files changed, 58 insertions(+), 63 deletions(-) diff --git a/backend/genesys/gl124.cpp b/backend/genesys/gl124.cpp index 1a3fdd8df..f1d555030 100644 --- a/backend/genesys/gl124.cpp +++ b/backend/genesys/gl124.cpp @@ -385,11 +385,10 @@ static void gl124_send_slope_table(Genesys_Device* dev, int table_nr, if (DBG_LEVEL >= DBG_io) { - sprintf (msg, "write slope %d (%d)=", table_nr, steps); - for (i = 0; i < steps; i++) - { - sprintf (msg+strlen(msg), ",%d", slope_table[i]); - } + std::sprintf(msg, "write slope %d (%d)=", table_nr, steps); + for (i = 0; i < steps; i++) { + std::sprintf(msg + std::strlen(msg), ",%d", slope_table[i]); + } DBG (DBG_io, "%s: %s\n", __func__, msg); } @@ -1907,7 +1906,7 @@ SensorExposure CommandSetGl124::led_calibration(Genesys_Device* dev, const Genes if (DBG_LEVEL >= DBG_data) { char fn[30]; - snprintf(fn, 30, "gl124_led_%02d.pnm", turn); + std::snprintf(fn, 30, "gl124_led_%02d.pnm", turn); sanei_genesys_write_pnm_file(fn, line.data(), session.params.depth, channels, num_pixels, 1); } @@ -2068,7 +2067,7 @@ void CommandSetGl124::offset_calibration(Genesys_Device* dev, const Genesys_Sens if (DBG_LEVEL >= DBG_data) { char title[30]; - snprintf(title, 30, "gl124_offset%03d.pnm", bottom); + std::snprintf(title, 30, "gl124_offset%03d.pnm", bottom); sanei_genesys_write_pnm_file(title, first_line.data(), session.params.depth, channels, pixels, lines); } @@ -2110,7 +2109,7 @@ void CommandSetGl124::offset_calibration(Genesys_Device* dev, const Genesys_Sens if (DBG_LEVEL >= DBG_data) { char title[30]; - snprintf(title, 30, "gl124_offset%03d.pnm", dev->frontend.get_offset(1)); + std::snprintf(title, 30, "gl124_offset%03d.pnm", dev->frontend.get_offset(1)); sanei_genesys_write_pnm_file(title, second_line.data(), session.params.depth, channels, pixels, lines); } diff --git a/backend/genesys/gl646.cpp b/backend/genesys/gl646.cpp index c8e6cfedb..c8de2ee3d 100644 --- a/backend/genesys/gl646.cpp +++ b/backend/genesys/gl646.cpp @@ -112,15 +112,15 @@ print_status (uint8_t val) { char msg[80]; - sprintf (msg, "%s%s%s%s%s%s%s%s", - val & REG_0x41_PWRBIT ? "PWRBIT " : "", - val & REG_0x41_BUFEMPTY ? "BUFEMPTY " : "", - val & REG_0x41_FEEDFSH ? "FEEDFSH " : "", - val & REG_0x41_SCANFSH ? "SCANFSH " : "", - val & REG_0x41_HOMESNR ? "HOMESNR " : "", - val & REG_0x41_LAMPSTS ? "LAMPSTS " : "", - val & REG_0x41_FEBUSY ? "FEBUSY " : "", - val & REG_0x41_MOTMFLG ? "MOTMFLG" : ""); + std::sprintf(msg, "%s%s%s%s%s%s%s%s", + val & REG_0x41_PWRBIT ? "PWRBIT " : "", + val & REG_0x41_BUFEMPTY ? "BUFEMPTY " : "", + val & REG_0x41_FEEDFSH ? "FEEDFSH " : "", + val & REG_0x41_SCANFSH ? "SCANFSH " : "", + val & REG_0x41_HOMESNR ? "HOMESNR " : "", + val & REG_0x41_LAMPSTS ? "LAMPSTS " : "", + val & REG_0x41_FEBUSY ? "FEBUSY " : "", + val & REG_0x41_MOTMFLG ? "MOTMFLG" : ""); DBG(DBG_info, "status=%s\n", msg); } @@ -2074,7 +2074,7 @@ SensorExposure CommandSetGl646::led_calibration(Genesys_Device* dev, const Genes if (DBG_LEVEL >= DBG_data) { char fn[30]; - snprintf(fn, 30, "gl646_led_%02d.pnm", turn); + std::snprintf(fn, 30, "gl646_led_%02d.pnm", turn); sanei_genesys_write_pnm_file(fn, line.data(), 16, channels, settings.pixels, 1); } @@ -2337,7 +2337,7 @@ void CommandSetGl646::offset_calibration(Genesys_Device* dev, const Genesys_Sens if (DBG_LEVEL >= DBG_data) { char title[30]; - snprintf(title, 30, "gl646_offset%03d.pnm", bottom); + std::snprintf(title, 30, "gl646_offset%03d.pnm", bottom); sanei_genesys_write_pnm_file(title, first_line.data(), 8, channels, settings.pixels, settings.lines); } @@ -2355,7 +2355,7 @@ void CommandSetGl646::offset_calibration(Genesys_Device* dev, const Genesys_Sens if (DBG_LEVEL >= DBG_data) { char title[30]; - snprintf(title, 30, "gl646_offset%03d.pnm", top); + std::snprintf(title, 30, "gl646_offset%03d.pnm", top); sanei_genesys_write_pnm_file (title, second_line.data(), 8, channels, settings.pixels, settings.lines); } @@ -2379,7 +2379,7 @@ void CommandSetGl646::offset_calibration(Genesys_Device* dev, const Genesys_Sens if (DBG_LEVEL >= DBG_data) { char title[30]; - snprintf(title, 30, "gl646_offset%03d.pnm", dev->frontend.get_offset(1)); + std::snprintf(title, 30, "gl646_offset%03d.pnm", dev->frontend.get_offset(1)); sanei_genesys_write_pnm_file (title, second_line.data(), 8, channels, settings.pixels, settings.lines); } @@ -2467,7 +2467,7 @@ static void ad_fe_coarse_gain_calibration(Genesys_Device* dev, const Genesys_Sen /* log scanning data */ if (DBG_LEVEL >= DBG_data) { - sprintf (title, "gl646_alternative_gain%02d.pnm", pass); + std::sprintf(title, "gl646_alternative_gain%02d.pnm", pass); sanei_genesys_write_pnm_file(title, line.data(), 8, channels, settings.pixels, settings.lines); } diff --git a/backend/genesys/gl841.cpp b/backend/genesys/gl841.cpp index c1f9e2c5a..792d2414c 100644 --- a/backend/genesys/gl841.cpp +++ b/backend/genesys/gl841.cpp @@ -564,10 +564,9 @@ static void gl841_send_slope_table(Genesys_Device* dev, int table_nr, if (DBG_LEVEL >= DBG_io) { - sprintf (msg, "write slope %d (%d)=", table_nr, steps); - for (i = 0; i < steps; i++) - { - sprintf (msg+strlen(msg), ",%d", slope_table[i]); + std::sprintf(msg, "write slope %d (%d)=", table_nr, steps); + for (i = 0; i < steps; i++) { + std::sprintf (msg+strlen(msg), ",%d", slope_table[i]); } DBG(DBG_io, "%s: %s\n", __func__, msg); } @@ -2737,7 +2736,7 @@ SensorExposure CommandSetGl841::led_calibration(Genesys_Device* dev, const Genes if (DBG_LEVEL >= DBG_data) { char fn[30]; - snprintf(fn, 30, "gl841_led_%d.pnm", turn); + std::snprintf(fn, 30, "gl841_led_%d.pnm", turn); sanei_genesys_write_pnm_file(fn, line.data(), 16, channels, num_pixels, 1); } @@ -2920,7 +2919,7 @@ static void ad_fe_offset_calibration(Genesys_Device* dev, const Genesys_Sensor& gl841_stop_action (dev); if (DBG_LEVEL >= DBG_data) { char fn[30]; - snprintf(fn, 30, "gl841_offset_%02d.pnm", turn); + std::snprintf(fn, 30, "gl841_offset_%02d.pnm", turn); sanei_genesys_write_pnm_file(fn, line.data(), 8, 3, num_pixels, 1); } @@ -3069,7 +3068,7 @@ void CommandSetGl841::offset_calibration(Genesys_Device* dev, const Genesys_Sens if (DBG_LEVEL >= DBG_data) { char fn[30]; - snprintf(fn, 30, "gl841_offset1_%02d.pnm", turn); + std::snprintf(fn, 30, "gl841_offset1_%02d.pnm", turn); sanei_genesys_write_pnm_file(fn, first_line.data(), 16, channels, num_pixels, 1); } @@ -3176,7 +3175,7 @@ void CommandSetGl841::offset_calibration(Genesys_Device* dev, const Genesys_Sens if (DBG_LEVEL >= DBG_data) { char fn[30]; - snprintf(fn, 30, "gl841_offset2_%02d.pnm", turn); + std::snprintf(fn, 30, "gl841_offset2_%02d.pnm", turn); sanei_genesys_write_pnm_file(fn, second_line.data(), 16, channels, num_pixels, 1); } @@ -3792,8 +3791,8 @@ void CommandSetGl841::search_strip(Genesys_Device* dev, const Genesys_Sensor& se pass = 0; if (DBG_LEVEL >= DBG_data) { - sprintf(title, "gl841_search_strip_%s_%s%02u.pnm", black ? "black" : "white", - forward ? "fwd" : "bwd", pass); + std::sprintf(title, "gl841_search_strip_%s_%s%02u.pnm", black ? "black" : "white", + forward ? "fwd" : "bwd", pass); sanei_genesys_write_pnm_file(title, data.data(), session.params.depth, channels, pixels, lines); } @@ -3817,8 +3816,8 @@ void CommandSetGl841::search_strip(Genesys_Device* dev, const Genesys_Sensor& se if (DBG_LEVEL >= DBG_data) { - sprintf(title, "gl841_search_strip_%s_%s%02u.pnm", - black ? "black" : "white", forward ? "fwd" : "bwd", pass); + std::sprintf(title, "gl841_search_strip_%s_%s%02u.pnm", + black ? "black" : "white", forward ? "fwd" : "bwd", pass); sanei_genesys_write_pnm_file(title, data.data(), session.params.depth, channels, pixels, lines); } diff --git a/backend/genesys/gl843.cpp b/backend/genesys/gl843.cpp index 12cc42109..c04c2bd50 100644 --- a/backend/genesys/gl843.cpp +++ b/backend/genesys/gl843.cpp @@ -737,10 +737,9 @@ static void gl843_send_slope_table(Genesys_Device* dev, int table_nr, if (DBG_LEVEL >= DBG_io) { - sprintf (msg, "write slope %d (%d)=", table_nr, steps); - for (i = 0; i < steps; i++) - { - sprintf (msg+strlen(msg), "%d", slope_table[i]); + std::sprintf(msg, "write slope %d (%d)=", table_nr, steps); + for (i = 0; i < steps; i++) { + std::sprintf (msg+strlen(msg), "%d", slope_table[i]); } DBG(DBG_io, "%s: %s\n", __func__, msg); } @@ -2425,7 +2424,7 @@ SensorExposure CommandSetGl843::led_calibration(Genesys_Device* dev, const Genes if (DBG_LEVEL >= DBG_data) { char fn[30]; - snprintf(fn, 30, "gl843_led_%02d.pnm", turn); + std::snprintf(fn, 30, "gl843_led_%02d.pnm", turn); sanei_genesys_write_pnm_file(fn, image); } @@ -2630,8 +2629,8 @@ void CommandSetGl843::offset_calibration(Genesys_Device* dev, const Genesys_Sens if (DBG_LEVEL >= DBG_data) { char fn[40]; - snprintf(fn, 40, "gl843_bottom_offset_%03d_%03d_%03d.pnm", - bottom[0], bottom[1], bottom[2]); + std::snprintf(fn, 40, "gl843_bottom_offset_%03d_%03d_%03d.pnm", + bottom[0], bottom[1], bottom[2]); sanei_genesys_write_pnm_file(fn, first_line); } @@ -2693,11 +2692,11 @@ void CommandSetGl843::offset_calibration(Genesys_Device* dev, const Genesys_Sens if (DBG_LEVEL >= DBG_data) { char title[100]; - snprintf(title, 100, "lines: %d pixels_per_line: %d offsets[0..2]: %d %d %d\n", - lines, pixels, - dev->frontend.get_offset(0), - dev->frontend.get_offset(1), - dev->frontend.get_offset(2)); + std::snprintf(title, 100, "lines: %d pixels_per_line: %d offsets[0..2]: %d %d %d\n", + lines, pixels, + dev->frontend.get_offset(0), + dev->frontend.get_offset(1), + dev->frontend.get_offset(2)); debug_image_info += title; std::copy(second_line.get_row_ptr(0), second_line.get_row_ptr(0) + second_line.get_row_bytes() * second_line.get_height(), @@ -3196,8 +3195,8 @@ void CommandSetGl843::search_strip(Genesys_Device* dev, const Genesys_Sensor& se if (DBG_LEVEL >= DBG_data) { char fn[40]; - snprintf(fn, 40, "gl843_search_strip_%s_%s%02d.pnm", - black ? "black" : "white", forward ? "fwd" : "bwd", pass); + std::snprintf(fn, 40, "gl843_search_strip_%s_%s%02d.pnm", + black ? "black" : "white", forward ? "fwd" : "bwd", pass); sanei_genesys_write_pnm_file(fn, data); } diff --git a/backend/genesys/gl846.cpp b/backend/genesys/gl846.cpp index becd75405..9994cb2b4 100644 --- a/backend/genesys/gl846.cpp +++ b/backend/genesys/gl846.cpp @@ -286,10 +286,10 @@ static void gl846_send_slope_table(Genesys_Device* dev, int table_nr, if (DBG_LEVEL >= DBG_io) { - sprintf (msg, "write slope %d (%d)=", table_nr, steps); + std::sprintf(msg, "write slope %d (%d)=", table_nr, steps); for (i = 0; i < steps; i++) { - sprintf (msg+strlen(msg), "%d", slope_table[i]); + std::sprintf(msg+strlen(msg), "%d", slope_table[i]); } DBG (DBG_io, "%s: %s\n", __func__, msg); } @@ -1577,7 +1577,7 @@ SensorExposure CommandSetGl846::led_calibration(Genesys_Device* dev, const Genes if (DBG_LEVEL >= DBG_data) { char fn[30]; - snprintf(fn, 30, "gl846_led_%02d.pnm", turn); + std::snprintf(fn, 30, "gl846_led_%02d.pnm", turn); sanei_genesys_write_pnm_file(fn, line.data(), session.params.depth, channels, num_pixels, 1); } @@ -2108,7 +2108,7 @@ void CommandSetGl846::offset_calibration(Genesys_Device* dev, const Genesys_Sens if (DBG_LEVEL >= DBG_data) { char fn[30]; - snprintf(fn, 30, "gl846_offset%03d.pnm", bottom); + std::snprintf(fn, 30, "gl846_offset%03d.pnm", bottom); sanei_genesys_write_pnm_file(fn, first_line.data(), session.params.depth, channels, pixels, lines); } @@ -2150,7 +2150,7 @@ void CommandSetGl846::offset_calibration(Genesys_Device* dev, const Genesys_Sens if (DBG_LEVEL >= DBG_data) { char fn[30]; - snprintf(fn, 30, "gl846_offset%03d.pnm", dev->frontend.get_offset(1)); + std::snprintf(fn, 30, "gl846_offset%03d.pnm", dev->frontend.get_offset(1)); sanei_genesys_write_pnm_file(fn, second_line.data(), session.params.depth, channels, pixels, lines); } diff --git a/backend/genesys/gl847.cpp b/backend/genesys/gl847.cpp index 6f23bdb2b..52fda7895 100644 --- a/backend/genesys/gl847.cpp +++ b/backend/genesys/gl847.cpp @@ -308,10 +308,10 @@ static void gl847_send_slope_table(Genesys_Device* dev, int table_nr, if (DBG_LEVEL >= DBG_io) { - sprintf (msg, "write slope %d (%d)=", table_nr, steps); + std::sprintf(msg, "write slope %d (%d)=", table_nr, steps); for (i = 0; i < steps; i++) { - sprintf (msg+strlen(msg), "%d", slope_table[i]); + std::sprintf(msg + std::strlen(msg), "%d", slope_table[i]); } DBG (DBG_io, "%s: %s\n", __func__, msg); } @@ -1610,7 +1610,7 @@ SensorExposure CommandSetGl847::led_calibration(Genesys_Device* dev, const Genes if (DBG_LEVEL >= DBG_data) { char fn[30]; - snprintf(fn, 30, "gl847_led_%02d.pnm", turn); + std::snprintf(fn, 30, "gl847_led_%02d.pnm", turn); sanei_genesys_write_pnm_file(fn, line.data(), session.params.depth, channels, num_pixels, 1); } @@ -2174,7 +2174,7 @@ void CommandSetGl847::offset_calibration(Genesys_Device* dev, const Genesys_Sens if (DBG_LEVEL >= DBG_data) { char fn[30]; - snprintf(fn, 30, "gl847_offset%03d.pnm", bottom); + std::snprintf(fn, 30, "gl847_offset%03d.pnm", bottom); sanei_genesys_write_pnm_file(fn, first_line.data(), session.params.depth, channels, pixels, lines); } @@ -2216,7 +2216,7 @@ void CommandSetGl847::offset_calibration(Genesys_Device* dev, const Genesys_Sens if (DBG_LEVEL >= DBG_data) { char fn[30]; - snprintf(fn, 30, "gl847_offset%03d.pnm", dev->frontend.get_offset(1)); + std::snprintf(fn, 30, "gl847_offset%03d.pnm", dev->frontend.get_offset(1)); sanei_genesys_write_pnm_file(fn, second_line.data(), session.params.depth, channels, pixels, lines); } diff --git a/backend/genesys/low.cpp b/backend/genesys/low.cpp index a7ee5caf3..bffec37fc 100644 --- a/backend/genesys/low.cpp +++ b/backend/genesys/low.cpp @@ -91,14 +91,12 @@ void sanei_genesys_init_cmd_set(Genesys_Device* dev) void sanei_genesys_write_file(const char* filename, const std::uint8_t* data, std::size_t length) { DBG_HELPER(dbg); - FILE *out; - - out = fopen (filename, "w"); + std::FILE* out = std::fopen(filename, "w"); if (!out) { throw SaneException("could not open %s for writing: %s", filename, strerror(errno)); } - fwrite(data, 1, length, out); - fclose(out); + std::fwrite(data, 1, length, out); + std::fclose(out); } // Write data to a pnm file (e.g. calibration). For debugging only From 3ad5a9241486b8fa785d37c92892919d1cda8ec0 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Sat, 2 Nov 2019 17:13:18 +0200 Subject: [PATCH 5/7] genesys: Move conversion of ScanMethod to option strings to enums.cpp --- backend/Makefile.am | 2 +- backend/genesys/enums.cpp | 73 +++++++++++++++++++++++++++++++++++++ backend/genesys/enums.h | 3 ++ backend/genesys/genesys.cpp | 26 ------------- backend/genesys/genesys.h | 4 ++ 5 files changed, 81 insertions(+), 27 deletions(-) create mode 100644 backend/genesys/enums.cpp diff --git a/backend/Makefile.am b/backend/Makefile.am index be35cd265..be56c5515 100644 --- a/backend/Makefile.am +++ b/backend/Makefile.am @@ -491,7 +491,7 @@ libgenesys_la_SOURCES = genesys/genesys.cpp genesys/genesys.h \ genesys/command_set.h \ genesys/conv.h genesys/conv.cpp \ genesys/device.h genesys/device.cpp \ - genesys/enums.h \ + genesys/enums.h genesys/enums.cpp \ genesys/error.h genesys/error.cpp \ genesys/fwd.h \ genesys/gl646.cpp genesys/gl646.h genesys/gl646_registers.h \ diff --git a/backend/genesys/enums.cpp b/backend/genesys/enums.cpp new file mode 100644 index 000000000..6869d78b6 --- /dev/null +++ b/backend/genesys/enums.cpp @@ -0,0 +1,73 @@ +/* sane - Scanner Access Now Easy. + + Copyright (C) 2019 Povilas Kanapickas + + This file is part of the SANE package. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA. + + As a special exception, the authors of SANE give permission for + additional uses of the libraries contained in this release of SANE. + + The exception is that, if you link a SANE library with other files + to produce an executable, this does not by itself cause the + resulting executable to be covered by the GNU General Public + License. Your use of that executable is in no way restricted on + account of linking the SANE library code into it. + + This exception does not, however, invalidate any other reasons why + the executable file might be covered by the GNU General Public + License. + + If you submit changes to SANE to the maintainers to be included in + a subsequent release, you agree by submitting the changes that + those changes may be distributed with this exception intact. + + If you write modifications of your own for SANE, it is your choice + whether to permit this exception to apply to your modifications. + If you do not wish that, delete this exception notice. +*/ + +#define DEBUG_DECLARE_ONLY + +#include "enums.h" +#include "genesys.h" + +namespace genesys { + +const char* scan_method_to_option_string(ScanMethod method) +{ + switch (method) { + case ScanMethod::FLATBED: return STR_FLATBED; + case ScanMethod::TRANSPARENCY: return STR_TRANSPARENCY_ADAPTER; + case ScanMethod::TRANSPARENCY_INFRARED: return STR_TRANSPARENCY_ADAPTER_INFRARED; + } + throw SaneException("Unknown scan method %d", static_cast(method)); +} + +ScanMethod option_string_to_scan_method(const std::string& str) +{ + if (str == STR_FLATBED) { + return ScanMethod::FLATBED; + } else if (str == STR_TRANSPARENCY_ADAPTER) { + return ScanMethod::TRANSPARENCY; + } else if (str == STR_TRANSPARENCY_ADAPTER_INFRARED) { + return ScanMethod::TRANSPARENCY_INFRARED; + } + throw SaneException("Unknown scan method option %s", str.c_str()); +} + +} // namespace genesys diff --git a/backend/genesys/enums.h b/backend/genesys/enums.h index 60aff1cf0..f1d322194 100644 --- a/backend/genesys/enums.h +++ b/backend/genesys/enums.h @@ -71,6 +71,9 @@ inline void serialize(std::ostream& str, ScanMethod& x) serialize(str, value); } +const char* scan_method_to_option_string(ScanMethod method); +ScanMethod option_string_to_scan_method(const std::string& str); + enum class ScanColorMode : unsigned { LINEART = 0, HALFTONE, diff --git a/backend/genesys/genesys.cpp b/backend/genesys/genesys.cpp index f0d5a230a..528772ac8 100644 --- a/backend/genesys/genesys.cpp +++ b/backend/genesys/genesys.cpp @@ -97,10 +97,6 @@ namespace { StaticInit> s_devices; } // namespace -#define STR_FLATBED SANE_I18N("Flatbed") -#define STR_TRANSPARENCY_ADAPTER SANE_I18N("Transparency Adapter") -#define STR_TRANSPARENCY_ADAPTER_INFRARED SANE_I18N("Transparency Adapter Infrared") - static SANE_String_Const mode_list[] = { SANE_VALUE_SCAN_MODE_COLOR, SANE_VALUE_SCAN_MODE_GRAY, @@ -3404,28 +3400,6 @@ static unsigned pick_resolution(const std::vector& resolutions, unsign return best_res; } -static const char* scan_method_to_option_string(ScanMethod method) -{ - switch (method) { - case ScanMethod::FLATBED: return STR_FLATBED; - case ScanMethod::TRANSPARENCY: return STR_TRANSPARENCY_ADAPTER; - case ScanMethod::TRANSPARENCY_INFRARED: return STR_TRANSPARENCY_ADAPTER_INFRARED; - } - throw SaneException("Unknown scan method %d", static_cast(method)); -} - -static ScanMethod option_string_to_scan_method(const std::string& str) -{ - if (str == STR_FLATBED) { - return ScanMethod::FLATBED; - } else if (str == STR_TRANSPARENCY_ADAPTER) { - return ScanMethod::TRANSPARENCY; - } else if (str == STR_TRANSPARENCY_ADAPTER_INFRARED) { - return ScanMethod::TRANSPARENCY_INFRARED; - } - throw SaneException("Unknown scan method option %s", str.c_str()); -} - static void calc_parameters(Genesys_Scanner* s) { DBG_HELPER(dbg); diff --git a/backend/genesys/genesys.h b/backend/genesys/genesys.h index 7e2569bb8..890984fdc 100644 --- a/backend/genesys/genesys.h +++ b/backend/genesys/genesys.h @@ -78,6 +78,10 @@ #define SANE_I18N(text) text #endif +#define STR_FLATBED SANE_I18N("Flatbed") +#define STR_TRANSPARENCY_ADAPTER SANE_I18N("Transparency Adapter") +#define STR_TRANSPARENCY_ADAPTER_INFRARED SANE_I18N("Transparency Adapter Infrared") + namespace genesys { /** List of SANE options From 42a58387b6847ab820dbd80ab1a54597eb04db96 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Sat, 2 Nov 2019 17:13:19 +0200 Subject: [PATCH 6/7] genesys: Extract conversion of ScanColorMode to separate functions --- backend/genesys/enums.cpp | 25 +++++++++++++++++++++++++ backend/genesys/enums.h | 2 ++ backend/genesys/genesys.cpp | 10 +--------- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/backend/genesys/enums.cpp b/backend/genesys/enums.cpp index 6869d78b6..155c87b80 100644 --- a/backend/genesys/enums.cpp +++ b/backend/genesys/enums.cpp @@ -70,4 +70,29 @@ ScanMethod option_string_to_scan_method(const std::string& str) throw SaneException("Unknown scan method option %s", str.c_str()); } +const char* scan_color_mode_to_option_string(ScanColorMode mode) +{ + switch (mode) { + case ScanColorMode::COLOR_SINGLE_PASS: return SANE_VALUE_SCAN_MODE_COLOR; + case ScanColorMode::GRAY: return SANE_VALUE_SCAN_MODE_GRAY; + case ScanColorMode::HALFTONE: return SANE_VALUE_SCAN_MODE_HALFTONE; + case ScanColorMode::LINEART: return SANE_VALUE_SCAN_MODE_LINEART; + } + throw SaneException("Unknown scan mode %d", static_cast(mode)); +} + +ScanColorMode option_string_to_scan_color_mode(const std::string& str) +{ + if (str == SANE_VALUE_SCAN_MODE_COLOR) { + return ScanColorMode::COLOR_SINGLE_PASS; + } else if (str == SANE_VALUE_SCAN_MODE_GRAY) { + return ScanColorMode::GRAY; + } else if (str == SANE_VALUE_SCAN_MODE_HALFTONE) { + return ScanColorMode::HALFTONE; + } else if (str == SANE_VALUE_SCAN_MODE_LINEART) { + return ScanColorMode::LINEART; + } + throw SaneException("Unknown scan color mode %s", str.c_str()); +} + } // namespace genesys diff --git a/backend/genesys/enums.h b/backend/genesys/enums.h index f1d322194..f825e31c5 100644 --- a/backend/genesys/enums.h +++ b/backend/genesys/enums.h @@ -94,6 +94,8 @@ inline void serialize(std::ostream& str, ScanColorMode& x) serialize(str, value); } +const char* scan_color_mode_to_option_string(ScanColorMode mode); +ScanColorMode option_string_to_scan_color_mode(const std::string& str); enum class ColorFilter : unsigned { RED = 0, diff --git a/backend/genesys/genesys.cpp b/backend/genesys/genesys.cpp index 528772ac8..799391a30 100644 --- a/backend/genesys/genesys.cpp +++ b/backend/genesys/genesys.cpp @@ -3511,15 +3511,7 @@ static void calc_parameters(Genesys_Scanner* s) bytes_per_line *= 3; } - if (s->mode == SANE_VALUE_SCAN_MODE_COLOR) { - s->dev->settings.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; - } else if (s->mode == SANE_VALUE_SCAN_MODE_GRAY) { - s->dev->settings.scan_mode = ScanColorMode::GRAY; - } else if (s->mode == SANE_TITLE_HALFTONE) { - s->dev->settings.scan_mode = ScanColorMode::HALFTONE; - } else { /* Lineart */ - s->dev->settings.scan_mode = ScanColorMode::LINEART; - } + s->dev->settings.scan_mode = option_string_to_scan_color_mode(s->mode); s->dev->settings.lines = s->params.lines; s->dev->settings.pixels = pixels_per_line; From 9d9552575d6c578cda0a3892403158db33d0e00e Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Sat, 2 Nov 2019 17:13:20 +0200 Subject: [PATCH 7/7] genesys: Extract MethodResolutions::get_resolutions() --- backend/genesys/device.cpp | 23 +++++++++++++---------- backend/genesys/device.h | 2 ++ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/backend/genesys/device.cpp b/backend/genesys/device.cpp index a113045a7..2d9dda218 100644 --- a/backend/genesys/device.cpp +++ b/backend/genesys/device.cpp @@ -49,6 +49,18 @@ namespace genesys { +std::vector MethodResolutions::get_resolutions() const +{ + std::vector ret; + std::copy(resolutions_x.begin(), resolutions_x.end(), std::back_inserter(ret)); + std::copy(resolutions_y.begin(), resolutions_y.end(), std::back_inserter(ret)); + // sort in decreasing order + + std::sort(ret.begin(), ret.end(), std::greater()); + ret.erase(std::unique(ret.begin(), ret.end()), ret.end()); + return ret; +} + const MethodResolutions& Genesys_Model::get_resolution_settings(ScanMethod method) const { for (const auto& res_for_method : resolutions) { @@ -64,16 +76,7 @@ const MethodResolutions& Genesys_Model::get_resolution_settings(ScanMethod metho std::vector Genesys_Model::get_resolutions(ScanMethod method) const { - auto settings = get_resolution_settings(method); - - std::vector ret; - std::copy(settings.resolutions_x.begin(), settings.resolutions_x.end(), std::back_inserter(ret)); - std::copy(settings.resolutions_y.begin(), settings.resolutions_y.end(), std::back_inserter(ret)); - // sort in decreasing order - - std::sort(ret.begin(), ret.end(), std::greater()); - ret.erase(std::unique(ret.begin(), ret.end()), ret.end()); - return ret; + return get_resolution_settings(method).get_resolutions(); } Genesys_Device::~Genesys_Device() diff --git a/backend/genesys/device.h b/backend/genesys/device.h index b5877a7fa..e73fb14ff 100644 --- a/backend/genesys/device.h +++ b/backend/genesys/device.h @@ -109,6 +109,8 @@ struct MethodResolutions { return *std::min_element(resolutions_y.begin(), resolutions_y.end()); } + + std::vector get_resolutions() const; }; /** @brief structure to describe a scanner model