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