Merge branch 'genesys-misc-cleanup' into 'master'

genesys: Miscellaneous cleanup

See merge request sane-project/backends!239
merge-requests/240/merge
Povilas Kanapickas 2019-11-10 14:56:00 +00:00
commit 8c4879c835
17 zmienionych plików z 344 dodań i 271 usunięć

Wyświetl plik

@ -491,8 +491,9 @@ 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 \
genesys/gl124.cpp genesys/gl124.h genesys/gl124_registers.h \
genesys/gl841.cpp genesys/gl841.h genesys/gl841_registers.h \

Wyświetl plik

@ -45,11 +45,11 @@
#define BACKEND_GENESYS_COMMAND_SET_H
#include "device.h"
#include "fwd.h"
#include <cstdint>
namespace genesys {
class Genesys_Device;
/** Scanner command set description.

Wyświetl plik

@ -49,6 +49,18 @@
namespace genesys {
std::vector<unsigned> MethodResolutions::get_resolutions() const
{
std::vector<unsigned> 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<unsigned>());
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<unsigned> Genesys_Model::get_resolutions(ScanMethod method) const
{
auto settings = get_resolution_settings(method);
std::vector<unsigned> 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<unsigned>());
ret.erase(std::unique(ret.begin(), ret.end()), ret.end());
return ret;
return get_resolution_settings(method).get_resolutions();
}
Genesys_Device::~Genesys_Device()

Wyświetl plik

@ -109,6 +109,8 @@ struct MethodResolutions
{
return *std::min_element(resolutions_y.begin(), resolutions_y.end());
}
std::vector<unsigned> get_resolutions() const;
};
/** @brief structure to describe a scanner model

Wyświetl plik

@ -0,0 +1,98 @@
/* sane - Scanner Access Now Easy.
Copyright (C) 2019 Povilas Kanapickas <povilas@radix.lt>
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<unsigned>(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());
}
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<unsigned>(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

Wyświetl plik

@ -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,
@ -91,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,

Wyświetl plik

@ -0,0 +1,129 @@
/* sane - Scanner Access Now Easy.
Copyright (C) 2019 Povilas Kanapickas <povilas@radix.lt>
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

Wyświetl plik

@ -77,6 +77,10 @@
#include <exception>
#include <vector>
#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
@ -93,10 +97,6 @@ namespace {
StaticInit<std::list<Genesys_Device>> 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,
@ -3400,28 +3400,6 @@ static unsigned pick_resolution(const std::vector<unsigned>& 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<unsigned>(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);
@ -3533,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;
@ -4706,7 +4676,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 +4695,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 +4740,8 @@ void sane_get_devices_impl(const SANE_Device *** device_list, SANE_Bool local_on
*const_cast<SANE_Device***>(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 +4846,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 +4917,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 +4941,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 +5605,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 +5642,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 +5726,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 +5848,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 +5893,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 +5913,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 +5933,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__, [=]()
{

Wyświetl plik

@ -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

Wyświetl plik

@ -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);
}

Wyświetl plik

@ -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);
}
@ -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<uint8_t> data(size);
std::vector<uint8_t> 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
@ -2134,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);
}
@ -2397,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);
}
@ -2415,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);
}
@ -2439,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);
}
@ -2527,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);
}
@ -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);

Wyświetl plik

@ -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<uint8_t> data(size);
std::vector<uint8_t> 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)
@ -638,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);
}
@ -2811,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);
}
@ -2994,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);
}
@ -3143,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);
}
@ -3250,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);
}
@ -3661,10 +3586,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
@ -3870,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);
}
@ -3895,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);
}

Wyświetl plik

@ -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);
}

Wyświetl plik

@ -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);
}

Wyświetl plik

@ -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);
}

Wyświetl plik

@ -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

Wyświetl plik

@ -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"
@ -108,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
@ -209,10 +209,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) :