1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
|
/* sane - Scanner Access Now Easy.
Copyright (C) 2003, 2004 Henning Meier-Geinitz <henning@meier-geinitz.de>
Copyright (C) 2005-2013 Stephane Voltz <stef.dev@free.fr>
Copyright (C) 2006 Laurent Charpentier <laurent_pubs@yahoo.com>
Copyright (C) 2009 Pierre Willenbrock <pierre@pirsoft.dnsalias.org>
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, see <https://www.gnu.org/licenses/>.
*/
#ifndef GENESYS_H
#define GENESYS_H
#ifndef BACKEND_NAME
# define BACKEND_NAME genesys
#endif
#include "low.h"
#include <queue>
#ifndef PATH_MAX
# define PATH_MAX 1024
#endif
#if defined(_WIN32) || defined(HAVE_OS2_H)
# define PATH_SEP '\\'
#else
# define PATH_SEP '/'
#endif
#define ENABLE(OPTION) s->opt[OPTION].cap &= ~SANE_CAP_INACTIVE
#define DISABLE(OPTION) s->opt[OPTION].cap |= SANE_CAP_INACTIVE
#define IS_ACTIVE(OPTION) (((s->opt[OPTION].cap) & SANE_CAP_INACTIVE) == 0)
#define GENESYS_CONFIG_FILE "genesys.conf"
#ifndef SANE_I18N
#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
*/
enum Genesys_Option
{
OPT_NUM_OPTS = 0,
OPT_MODE_GROUP,
OPT_MODE,
OPT_SOURCE,
OPT_PREVIEW,
OPT_BIT_DEPTH,
OPT_RESOLUTION,
OPT_GEOMETRY_GROUP,
OPT_TL_X, /* top-left x */
OPT_TL_Y, /* top-left y */
OPT_BR_X, /* bottom-right x */
OPT_BR_Y, /* bottom-right y */
/* advanced image enhancement options */
OPT_ENHANCEMENT_GROUP,
OPT_CUSTOM_GAMMA, /* toggle to enable custom gamma tables */
OPT_GAMMA_VECTOR,
OPT_GAMMA_VECTOR_R,
OPT_GAMMA_VECTOR_G,
OPT_GAMMA_VECTOR_B,
OPT_BRIGHTNESS,
OPT_CONTRAST,
OPT_EXTRAS_GROUP,
OPT_LAMP_OFF_TIME,
OPT_LAMP_OFF,
OPT_COLOR_FILTER,
OPT_CALIBRATION_FILE,
OPT_EXPIRATION_TIME,
OPT_SENSOR_GROUP,
OPT_SCAN_SW,
OPT_FILE_SW,
OPT_EMAIL_SW,
OPT_COPY_SW,
OPT_PAGE_LOADED_SW,
OPT_OCR_SW,
OPT_POWER_SW,
OPT_EXTRA_SW,
OPT_TRANSP_SW,
OPT_PDF1_SW,
OPT_PDF2_SW,
OPT_PDF3_SW,
OPT_PDF4_SW,
OPT_NEED_CALIBRATION_SW,
OPT_BUTTON_GROUP,
OPT_CALIBRATE,
OPT_CLEAR_CALIBRATION,
OPT_FORCE_CALIBRATION,
OPT_IGNORE_OFFSETS,
/* must come last: */
NUM_OPTIONS
};
enum GenesysButtonName : unsigned {
BUTTON_SCAN_SW = 0,
BUTTON_FILE_SW,
BUTTON_EMAIL_SW,
BUTTON_COPY_SW,
BUTTON_PAGE_LOADED_SW,
BUTTON_OCR_SW,
BUTTON_POWER_SW,
BUTTON_EXTRA_SW,
BUTTON_TRANSP_SW,
BUTTON_PDF1_SW,
BUTTON_PDF2_SW,
BUTTON_PDF3_SW,
BUTTON_PDF4_SW,
NUM_BUTTONS
};
GenesysButtonName genesys_option_to_button(int option);
class GenesysButton {
public:
void write(bool value)
{
if (value == value_) {
return;
}
values_to_read_.push(value);
value_ = value;
}
bool read()
{
if (values_to_read_.empty()) {
return value_;
}
bool ret = values_to_read_.front();
values_to_read_.pop();
return ret;
}
private:
bool value_ = false;
std::queue<bool> values_to_read_;
};
/** Scanner object. Should have better be called Session than Scanner
*/
struct Genesys_Scanner
{
Genesys_Scanner() = default;
~Genesys_Scanner() = default;
// Next scanner in list
struct Genesys_Scanner *next;
// Low-level device object
Genesys_Device* dev = nullptr;
// SANE data
// We are currently scanning
bool scanning;
// Option descriptors
SANE_Option_Descriptor opt[NUM_OPTIONS];
std::vector<SANE_Word> opt_resolution_values;
SANE_Range opt_x_range = {};
SANE_Range opt_y_range = {};
std::vector<const char*> opt_source_values;
// Option values
SANE_Word bit_depth = 0;
SANE_Word resolution = 0;
bool preview = false; // TODO: currently not used
bool lamp_off = false;
SANE_Word lamp_off_time = 0;
SANE_Word contrast = 0;
SANE_Word brightness = 0;
SANE_Word expiration_time = 0;
bool custom_gamma = false;
SANE_Word pos_top_left_y = 0;
SANE_Word pos_top_left_x = 0;
SANE_Word pos_bottom_right_y = 0;
SANE_Word pos_bottom_right_x = 0;
std::string mode, color_filter;
// the value of the source option
ScanMethod scan_method = ScanMethod::FLATBED;
std::string calibration_file;
// Button states
GenesysButton buttons[NUM_BUTTONS];
// SANE Parameters
SANE_Parameters params = {};
SANE_Int bpp_list[5] = {};
};
void write_calibration(std::ostream& str, Genesys_Device::Calibration& cache);
bool read_calibration(std::istream& str, Genesys_Device::Calibration& cache,
const std::string& path);
} // namespace genesys
#endif /* not GENESYS_H */
|