kopia lustrzana https://gitlab.com/sane-project/backends
genesys: Add generic value filter class for resolutions filtering
rodzic
ee2e026f2a
commit
c234ce6b77
|
@ -554,6 +554,7 @@ libgenesys_la_SOURCES = genesys/genesys.cpp genesys/genesys.h \
|
|||
genesys/test_usb_device.h genesys/test_usb_device.cpp \
|
||||
genesys/usb_device.h genesys/usb_device.cpp \
|
||||
genesys/low.cpp genesys/low.h \
|
||||
genesys/value_filter.h \
|
||||
genesys/utilities.h
|
||||
|
||||
libgenesys_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=genesys
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
#include "command_set_common.h"
|
||||
#include "low.h"
|
||||
#include "value_filter.h"
|
||||
|
||||
namespace genesys {
|
||||
|
||||
|
@ -150,7 +151,7 @@ void CommandSetCommon::set_motor_mode(Genesys_Device& dev, Genesys_Register_Set&
|
|||
|
||||
struct MotorSettings {
|
||||
ModelId model_id;
|
||||
ResolutionFilter resolutions;
|
||||
ValueFilterAny<unsigned> resolutions;
|
||||
GenesysRegisterSettingSet regs_primary_and_secondary;
|
||||
GenesysRegisterSettingSet regs_primary;
|
||||
GenesysRegisterSettingSet regs_secondary;
|
||||
|
@ -187,7 +188,7 @@ void CommandSetCommon::set_motor_mode(Genesys_Device& dev, Genesys_Register_Set&
|
|||
{ 0xa6, 0x01, 0x41 },
|
||||
}
|
||||
},
|
||||
{ ModelId::HP_SCANJET_G4050, ResolutionFilter::ANY, {
|
||||
{ ModelId::HP_SCANJET_G4050, VALUE_FILTER_ANY, {
|
||||
{ 0x6b, 0x81, 0x81 }, // set MULTFILM and GPOADF
|
||||
{ 0x6c, 0x00, 0x40 }, // note that reverse change is not applied on off
|
||||
// 0xa6 register 0x08 bit likely sets motor power. No move at all without that one
|
||||
|
@ -200,9 +201,9 @@ void CommandSetCommon::set_motor_mode(Genesys_Device& dev, Genesys_Register_Set&
|
|||
{ 0xa9, 0x00, 0x10 }, // note that 0x20 bit is not reset
|
||||
}, {}
|
||||
},
|
||||
{ ModelId::PLUSTEK_OPTICFILM_7200I, ResolutionFilter::ANY, {}, {}, {} },
|
||||
{ ModelId::PLUSTEK_OPTICFILM_7300, ResolutionFilter::ANY, {}, {}, {} },
|
||||
{ ModelId::PLUSTEK_OPTICFILM_7500I, ResolutionFilter::ANY, {}, {}, {} },
|
||||
{ ModelId::PLUSTEK_OPTICFILM_7200I, VALUE_FILTER_ANY, {}, {}, {} },
|
||||
{ ModelId::PLUSTEK_OPTICFILM_7300, VALUE_FILTER_ANY, {}, {}, {} },
|
||||
{ ModelId::PLUSTEK_OPTICFILM_7500I, VALUE_FILTER_ANY, {}, {}, {} },
|
||||
};
|
||||
|
||||
for (const auto& setting : settings) {
|
||||
|
|
|
@ -112,7 +112,6 @@ class TestScannerInterface;
|
|||
|
||||
// sensor.h
|
||||
class ScanMethodFilter;
|
||||
class ResolutionFilter;
|
||||
struct GenesysFrontendLayout;
|
||||
struct Genesys_Frontend;
|
||||
struct SensorExposure;
|
||||
|
@ -123,6 +122,10 @@ struct Genesys_Settings;
|
|||
struct SetupParams;
|
||||
struct ScanSession;
|
||||
|
||||
// value_filter.h
|
||||
template<class T> class ValueFilter;
|
||||
template<class T> class ValueFilterAny;
|
||||
|
||||
// test_usb_device.h
|
||||
class TestUsbDevice;
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@
|
|||
#include <vector>
|
||||
#include "enums.h"
|
||||
#include "sensor.h"
|
||||
#include "value_filter.h"
|
||||
|
||||
namespace genesys {
|
||||
|
||||
|
@ -151,7 +152,7 @@ struct MotorProfile
|
|||
int motor_vref = -1;
|
||||
|
||||
// the resolutions this profile is good for
|
||||
ResolutionFilter resolutions = ResolutionFilter::ANY;
|
||||
ValueFilterAny<unsigned> resolutions = VALUE_FILTER_ANY;
|
||||
// the scan method this profile is good for. If the list is empty, good for any method.
|
||||
ScanMethodFilter scan_methods = ScanMethodFilter::ANY;
|
||||
|
||||
|
|
|
@ -117,16 +117,6 @@ std::ostream& operator<<(std::ostream& out, const SensorExposure& exposure)
|
|||
return out;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, const ResolutionFilter& resolutions)
|
||||
{
|
||||
if (resolutions.matches_any()) {
|
||||
out << "ANY";
|
||||
return out;
|
||||
}
|
||||
out << format_vector_unsigned(4, resolutions.resolutions());
|
||||
return out;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, const ScanMethodFilter& methods)
|
||||
{
|
||||
if (methods.matches_any()) {
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
#include "enums.h"
|
||||
#include "register.h"
|
||||
#include "serialize.h"
|
||||
#include "value_filter.h"
|
||||
#include <array>
|
||||
#include <functional>
|
||||
|
||||
|
@ -247,54 +248,6 @@ struct SensorExposure {
|
|||
std::ostream& operator<<(std::ostream& out, const SensorExposure& exposure);
|
||||
|
||||
|
||||
class ResolutionFilter
|
||||
{
|
||||
public:
|
||||
struct Any {};
|
||||
static constexpr Any ANY{};
|
||||
|
||||
ResolutionFilter() : matches_any_{false} {}
|
||||
ResolutionFilter(Any) : matches_any_{true} {}
|
||||
ResolutionFilter(std::initializer_list<unsigned> resolutions) :
|
||||
matches_any_{false},
|
||||
resolutions_{resolutions}
|
||||
{}
|
||||
|
||||
bool matches(unsigned resolution) const
|
||||
{
|
||||
if (matches_any_)
|
||||
return true;
|
||||
auto it = std::find(resolutions_.begin(), resolutions_.end(), resolution);
|
||||
return it != resolutions_.end();
|
||||
}
|
||||
|
||||
bool operator==(const ResolutionFilter& other) const
|
||||
{
|
||||
return matches_any_ == other.matches_any_ && resolutions_ == other.resolutions_;
|
||||
}
|
||||
|
||||
bool matches_any() const { return matches_any_; }
|
||||
const std::vector<unsigned>& resolutions() const { return resolutions_; }
|
||||
|
||||
private:
|
||||
bool matches_any_ = false;
|
||||
std::vector<unsigned> resolutions_;
|
||||
|
||||
template<class Stream>
|
||||
friend void serialize(Stream& str, ResolutionFilter& x);
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, const ResolutionFilter& resolutions);
|
||||
|
||||
template<class Stream>
|
||||
void serialize(Stream& str, ResolutionFilter& x)
|
||||
{
|
||||
serialize(str, x.matches_any_);
|
||||
serialize_newline(str);
|
||||
serialize(str, x.resolutions_);
|
||||
}
|
||||
|
||||
|
||||
class ScanMethodFilter
|
||||
{
|
||||
public:
|
||||
|
@ -329,7 +282,7 @@ private:
|
|||
std::vector<ScanMethod> methods_;
|
||||
|
||||
template<class Stream>
|
||||
friend void serialize(Stream& str, ResolutionFilter& x);
|
||||
friend void serialize(Stream& str, ScanMethodFilter& x);
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, const ScanMethodFilter& methods);
|
||||
|
@ -348,7 +301,7 @@ struct Genesys_Sensor {
|
|||
unsigned optical_res = 0;
|
||||
|
||||
// the resolution list that the sensor is usable at.
|
||||
ResolutionFilter resolutions = ResolutionFilter::ANY;
|
||||
ValueFilterAny<unsigned> resolutions = VALUE_FILTER_ANY;
|
||||
|
||||
// the channel list that the sensor is usable at
|
||||
std::vector<unsigned> channels = { 1, 3 };
|
||||
|
|
|
@ -270,7 +270,7 @@ void genesys_init_motor_tables()
|
|||
profile.slope = MotorSlope::create_from_steps(20202 * 4, 333 * 4, 100);
|
||||
profile.step_type = StepType::QUARTER;
|
||||
profile.motor_vref = 0;
|
||||
profile.resolutions = ResolutionFilter::ANY;
|
||||
profile.resolutions = VALUE_FILTER_ANY;
|
||||
profile.scan_methods = { ScanMethod::FLATBED };
|
||||
motor.profiles.push_back(std::move(profile));
|
||||
|
||||
|
@ -278,7 +278,7 @@ void genesys_init_motor_tables()
|
|||
profile.slope = MotorSlope::create_from_steps(65535 * 4, 333 * 4, 100);
|
||||
profile.step_type = StepType::QUARTER;
|
||||
profile.motor_vref = 2;
|
||||
profile.resolutions = ResolutionFilter::ANY;
|
||||
profile.resolutions = VALUE_FILTER_ANY;
|
||||
profile.scan_methods = { ScanMethod::TRANSPARENCY, ScanMethod::TRANSPARENCY_INFRARED };
|
||||
motor.profiles.push_back(std::move(profile));
|
||||
|
||||
|
@ -286,7 +286,7 @@ void genesys_init_motor_tables()
|
|||
profile.slope = MotorSlope::create_from_steps(65535 * 4, 333 * 4, 200);
|
||||
profile.step_type = StepType::QUARTER;
|
||||
profile.motor_vref = 2;
|
||||
profile.resolutions = ResolutionFilter::ANY;
|
||||
profile.resolutions = VALUE_FILTER_ANY;
|
||||
profile.scan_methods = ScanMethodFilter::ANY;
|
||||
motor.fast_profiles.push_back(std::move(profile));
|
||||
|
||||
|
|
|
@ -215,7 +215,7 @@ void genesys_init_sensor_tables()
|
|||
|
||||
{
|
||||
struct CustomSensorSettings {
|
||||
ResolutionFilter resolutions;
|
||||
ValueFilterAny<unsigned> resolutions;
|
||||
unsigned exposure_lperiod;
|
||||
unsigned ccd_size_divisor;
|
||||
GenesysRegisterSettingSet custom_regs;
|
||||
|
@ -341,7 +341,7 @@ void genesys_init_sensor_tables()
|
|||
|
||||
{
|
||||
struct CustomSensorSettings {
|
||||
ResolutionFilter resolutions;
|
||||
ValueFilterAny<unsigned> resolutions;
|
||||
unsigned exposure_lperiod;
|
||||
GenesysRegisterSettingSet custom_regs;
|
||||
};
|
||||
|
@ -438,7 +438,7 @@ void genesys_init_sensor_tables()
|
|||
|
||||
{
|
||||
struct CustomSensorSettings {
|
||||
ResolutionFilter resolutions;
|
||||
ValueFilterAny<unsigned> resolutions;
|
||||
unsigned exposure_lperiod;
|
||||
unsigned ccd_size_divisor;
|
||||
GenesysRegisterSettingSet custom_regs;
|
||||
|
@ -570,7 +570,7 @@ void genesys_init_sensor_tables()
|
|||
|
||||
{
|
||||
struct CustomSensorSettings {
|
||||
ResolutionFilter resolutions;
|
||||
ValueFilterAny<unsigned> resolutions;
|
||||
std::vector<unsigned> channels;
|
||||
unsigned exposure_lperiod;
|
||||
SensorExposure exposure;
|
||||
|
@ -625,7 +625,7 @@ void genesys_init_sensor_tables()
|
|||
|
||||
{
|
||||
struct CustomSensorSettings {
|
||||
ResolutionFilter resolutions;
|
||||
ValueFilterAny<unsigned> resolutions;
|
||||
unsigned exposure_lperiod;
|
||||
GenesysRegisterSettingSet custom_regs;
|
||||
};
|
||||
|
@ -937,7 +937,7 @@ void genesys_init_sensor_tables()
|
|||
|
||||
{
|
||||
struct CustomSensorSettings {
|
||||
ResolutionFilter resolutions;
|
||||
ValueFilterAny<unsigned> resolutions;
|
||||
int exposure_lperiod;
|
||||
SensorExposure exposure;
|
||||
unsigned segment_size;
|
||||
|
@ -1038,7 +1038,7 @@ void genesys_init_sensor_tables()
|
|||
|
||||
{
|
||||
struct CustomSensorSettings {
|
||||
ResolutionFilter resolutions;
|
||||
ValueFilterAny<unsigned> resolutions;
|
||||
int exposure_lperiod;
|
||||
SensorExposure exposure;
|
||||
unsigned segment_size;
|
||||
|
@ -1137,7 +1137,7 @@ void genesys_init_sensor_tables()
|
|||
|
||||
{
|
||||
struct CustomSensorSettings {
|
||||
ResolutionFilter resolutions;
|
||||
ValueFilterAny<unsigned> resolutions;
|
||||
int exposure_lperiod;
|
||||
SensorExposure exposure;
|
||||
unsigned segment_size;
|
||||
|
@ -1272,7 +1272,7 @@ void genesys_init_sensor_tables()
|
|||
|
||||
{
|
||||
struct CustomSensorSettings {
|
||||
ResolutionFilter resolutions;
|
||||
ValueFilterAny<unsigned> resolutions;
|
||||
int exposure_lperiod;
|
||||
ScanMethod method;
|
||||
GenesysRegisterSettingSet extra_custom_regs;
|
||||
|
@ -1391,7 +1391,7 @@ void genesys_init_sensor_tables()
|
|||
{ 0x5a, 0x40 },
|
||||
}
|
||||
},
|
||||
{ ResolutionFilter::ANY, 15624, ScanMethod::TRANSPARENCY, {
|
||||
{ VALUE_FILTER_ANY, 15624, ScanMethod::TRANSPARENCY, {
|
||||
{ 0x74, 0x00 }, { 0x75, 0x1c }, { 0x76, 0x7f },
|
||||
{ 0x77, 0x03 }, { 0x78, 0xff }, { 0x79, 0xff },
|
||||
{ 0x7a, 0x03 }, { 0x7b, 0xff }, { 0x7c, 0xff },
|
||||
|
@ -1451,7 +1451,7 @@ void genesys_init_sensor_tables()
|
|||
|
||||
{
|
||||
struct CustomSensorSettings {
|
||||
ResolutionFilter resolutions;
|
||||
ValueFilterAny<unsigned> resolutions;
|
||||
int exposure_lperiod;
|
||||
ScanMethod method;
|
||||
GenesysRegisterSettingSet extra_custom_regs;
|
||||
|
@ -1514,7 +1514,7 @@ void genesys_init_sensor_tables()
|
|||
{ 0xaa, 0x07 },
|
||||
}
|
||||
},
|
||||
{ ResolutionFilter::ANY, 15624, ScanMethod::TRANSPARENCY, {
|
||||
{ VALUE_FILTER_ANY, 15624, ScanMethod::TRANSPARENCY, {
|
||||
{ 0x0c, 0x00 },
|
||||
{ 0x16, 0x33 }, { 0x17, 0x4c }, { 0x18, 0x01 }, { 0x19, 0x2a },
|
||||
{ 0x1a, 0x30 }, { 0x1b, 0x00 }, { 0x1c, 0x00 }, { 0x1d, 0x08 },
|
||||
|
@ -1562,7 +1562,7 @@ void genesys_init_sensor_tables()
|
|||
|
||||
{
|
||||
struct CustomSensorSettings {
|
||||
ResolutionFilter resolutions;
|
||||
ValueFilterAny<unsigned> resolutions;
|
||||
int exposure_lperiod;
|
||||
bool use_host_side_calib;
|
||||
std::vector<ScanMethod> methods;
|
||||
|
@ -1659,7 +1659,7 @@ void genesys_init_sensor_tables()
|
|||
|
||||
{
|
||||
struct CustomSensorSettings {
|
||||
ResolutionFilter resolutions;
|
||||
ValueFilterAny<unsigned> resolutions;
|
||||
unsigned dpiset_override;
|
||||
unsigned pixel_count_multiplier;
|
||||
int exposure_lperiod;
|
||||
|
@ -1815,7 +1815,7 @@ void genesys_init_sensor_tables()
|
|||
|
||||
{
|
||||
struct CustomSensorSettings {
|
||||
ResolutionFilter resolutions;
|
||||
ValueFilterAny<unsigned> resolutions;
|
||||
int exposure_lperiod;
|
||||
std::vector<ScanMethod> methods;
|
||||
GenesysRegisterSettingSet extra_custom_regs;
|
||||
|
@ -1955,7 +1955,7 @@ void genesys_init_sensor_tables()
|
|||
|
||||
{
|
||||
struct CustomSensorSettings {
|
||||
ResolutionFilter resolutions;
|
||||
ValueFilterAny<unsigned> resolutions;
|
||||
int exposure_lperiod;
|
||||
SensorExposure exposure;
|
||||
std::vector<unsigned> segment_order;
|
||||
|
@ -2077,7 +2077,7 @@ void genesys_init_sensor_tables()
|
|||
|
||||
{
|
||||
struct CustomSensorSettings {
|
||||
ResolutionFilter resolutions;
|
||||
ValueFilterAny<unsigned> resolutions;
|
||||
int exposure_lperiod;
|
||||
SensorExposure exposure;
|
||||
std::vector<unsigned> segment_order;
|
||||
|
@ -2182,7 +2182,7 @@ void genesys_init_sensor_tables()
|
|||
|
||||
{
|
||||
struct CustomSensorSettings {
|
||||
ResolutionFilter resolutions;
|
||||
ValueFilterAny<unsigned> resolutions;
|
||||
int exposure_lperiod;
|
||||
SensorExposure exposure;
|
||||
std::vector<unsigned> segment_order;
|
||||
|
@ -2291,7 +2291,7 @@ void genesys_init_sensor_tables()
|
|||
|
||||
{
|
||||
struct CustomSensorSettings {
|
||||
ResolutionFilter resolutions;
|
||||
ValueFilterAny<unsigned> resolutions;
|
||||
int exposure_lperiod;
|
||||
SensorExposure exposure;
|
||||
std::vector<unsigned> segment_order;
|
||||
|
@ -2475,7 +2475,7 @@ void genesys_init_sensor_tables()
|
|||
{
|
||||
struct CustomSensorSettings
|
||||
{
|
||||
ResolutionFilter resolutions;
|
||||
ValueFilterAny<unsigned> resolutions;
|
||||
ScanMethod method;
|
||||
unsigned ccd_size_divisor;
|
||||
unsigned logical_dpihw_override;
|
||||
|
@ -2565,7 +2565,7 @@ void genesys_init_sensor_tables()
|
|||
{
|
||||
struct CustomSensorSettings
|
||||
{
|
||||
ResolutionFilter resolutions;
|
||||
ValueFilterAny<unsigned> resolutions;
|
||||
unsigned ccd_size_divisor;
|
||||
unsigned logical_dpihw_override;
|
||||
unsigned pixel_count_multiplier;
|
||||
|
@ -2638,7 +2638,7 @@ void genesys_init_sensor_tables()
|
|||
{
|
||||
struct CustomSensorSettings
|
||||
{
|
||||
ResolutionFilter resolutions;
|
||||
ValueFilterAny<unsigned> resolutions;
|
||||
ScanMethod method;
|
||||
unsigned ccd_size_divisor;
|
||||
unsigned logical_dpihw_override;
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
/* sane - Scanner Access Now Easy.
|
||||
|
||||
Copyright (C) 2020 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.
|
||||
*/
|
||||
|
||||
#ifndef BACKEND_GENESYS_VALUE_FILTER_H
|
||||
#define BACKEND_GENESYS_VALUE_FILTER_H
|
||||
|
||||
#include <algorithm>
|
||||
#include <initializer_list>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
namespace genesys {
|
||||
|
||||
struct AnyTag {};
|
||||
constexpr AnyTag VALUE_FILTER_ANY{};
|
||||
|
||||
template<class T>
|
||||
class ValueFilterAny
|
||||
{
|
||||
public:
|
||||
ValueFilterAny() : matches_any_{false} {}
|
||||
ValueFilterAny(AnyTag) : matches_any_{true} {}
|
||||
ValueFilterAny(std::initializer_list<T> values) :
|
||||
matches_any_{false},
|
||||
values_{values}
|
||||
{}
|
||||
|
||||
bool matches(T value) const
|
||||
{
|
||||
if (matches_any_)
|
||||
return true;
|
||||
auto it = std::find(values_.begin(), values_.end(), value);
|
||||
return it != values_.end();
|
||||
}
|
||||
|
||||
bool operator==(const ValueFilterAny& other) const
|
||||
{
|
||||
return matches_any_ == other.matches_any_ && values_ == other.values_;
|
||||
}
|
||||
|
||||
bool matches_any() const { return matches_any_; }
|
||||
const std::vector<T>& values() const { return values_; }
|
||||
|
||||
private:
|
||||
bool matches_any_ = false;
|
||||
std::vector<T> values_;
|
||||
|
||||
template<class Stream, class U>
|
||||
friend void serialize(Stream& str, ValueFilterAny<U>& x);
|
||||
};
|
||||
|
||||
template<class T>
|
||||
std::ostream& operator<<(std::ostream& out, const ValueFilterAny<T>& values)
|
||||
{
|
||||
if (values.matches_any()) {
|
||||
out << "ANY";
|
||||
return out;
|
||||
}
|
||||
out << format_vector_indent_braced(4, "", values.values());
|
||||
return out;
|
||||
}
|
||||
|
||||
template<class Stream, class T>
|
||||
void serialize(Stream& str, ValueFilterAny<T>& x)
|
||||
{
|
||||
serialize(str, x.matches_any_);
|
||||
serialize_newline(str);
|
||||
serialize(str, x.values_);
|
||||
}
|
||||
|
||||
|
||||
} // namespace genesys
|
||||
|
||||
#endif // BACKEND_GENESYS_VALUE_FILTER_H
|
Ładowanie…
Reference in New Issue