1 /* sane - Scanner Access Now Easy.
2 
3    Copyright (C) 2019 Povilas Kanapickas <povilas@radix.lt>
4 
5    This file is part of the SANE package.
6 
7    This program is free software; you can redistribute it and/or
8    modify it under the terms of the GNU General Public License as
9    published by the Free Software Foundation; either version 2 of the
10    License, or (at your option) any later version.
11 
12    This program is distributed in the hope that it will be useful, but
13    WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    General Public License for more details.
16 
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <https://www.gnu.org/licenses/>.
19 */
20 
21 #ifndef BACKEND_GENESYS_ENUMS_H
22 #define BACKEND_GENESYS_ENUMS_H
23 
24 #include <iostream>
25 #include "serialize.h"
26 
27 namespace genesys {
28 
29 enum class ScanMethod : unsigned {
30     // normal scan method
31     FLATBED = 0,
32     // scan using transparency adaptor
33     TRANSPARENCY = 1,
34     // scan using transparency adaptor via infrared channel
35     TRANSPARENCY_INFRARED = 2
36 };
37 
operator <<(std::ostream& out, ScanMethod mode)38 inline std::ostream& operator<<(std::ostream& out, ScanMethod mode)
39 {
40     switch (mode) {
41         case ScanMethod::FLATBED: out << "FLATBED"; return out;
42         case ScanMethod::TRANSPARENCY: out << "TRANSPARENCY"; return out;
43         case ScanMethod::TRANSPARENCY_INFRARED: out << "TRANSPARENCY_INFRARED"; return out;
44     }
45     return out;
46 }
47 
serialize(std::istream& str, ScanMethod& x)48 inline void serialize(std::istream& str, ScanMethod& x)
49 {
50     unsigned value;
51     serialize(str, value);
52     x = static_cast<ScanMethod>(value);
53 }
54 
serialize(std::ostream& str, ScanMethod& x)55 inline void serialize(std::ostream& str, ScanMethod& x)
56 {
57     unsigned value = static_cast<unsigned>(x);
58     serialize(str, value);
59 }
60 
61 const char* scan_method_to_option_string(ScanMethod method);
62 ScanMethod option_string_to_scan_method(const std::string& str);
63 
64 enum class ScanColorMode : unsigned {
65     LINEART = 0,
66     HALFTONE,
67     GRAY,
68     COLOR_SINGLE_PASS
69 };
70 
operator <<(std::ostream& out, ScanColorMode mode)71 inline std::ostream& operator<<(std::ostream& out, ScanColorMode mode)
72 {
73     switch (mode) {
74         case ScanColorMode::LINEART: out << "LINEART"; return out;
75         case ScanColorMode::HALFTONE: out << "HALFTONE"; return out;
76         case ScanColorMode::GRAY: out << "GRAY"; return out;
77         case ScanColorMode::COLOR_SINGLE_PASS: out << "COLOR_SINGLE_PASS"; return out;
78     }
79     return out;
80 }
81 
serialize(std::istream& str, ScanColorMode& x)82 inline void serialize(std::istream& str, ScanColorMode& x)
83 {
84     unsigned value;
85     serialize(str, value);
86     x = static_cast<ScanColorMode>(value);
87 }
88 
serialize(std::ostream& str, ScanColorMode& x)89 inline void serialize(std::ostream& str, ScanColorMode& x)
90 {
91     unsigned value = static_cast<unsigned>(x);
92     serialize(str, value);
93 }
94 
95 const char* scan_color_mode_to_option_string(ScanColorMode mode);
96 ScanColorMode option_string_to_scan_color_mode(const std::string& str);
97 
98 
99 enum class ScanHeadId : unsigned {
100     NONE = 0,
101     PRIMARY = 1 << 0,
102     SECONDARY = 1 << 1,
103     ALL = PRIMARY | SECONDARY,
104 };
105 
operator |(ScanHeadId left, ScanHeadId right)106 inline ScanHeadId operator|(ScanHeadId left, ScanHeadId right)
107 {
108     return static_cast<ScanHeadId>(static_cast<unsigned>(left) | static_cast<unsigned>(right));
109 }
110 
operator &(ScanHeadId left, ScanHeadId right)111 inline ScanHeadId operator&(ScanHeadId left, ScanHeadId right)
112 {
113     return static_cast<ScanHeadId>(static_cast<unsigned>(left) & static_cast<unsigned>(right));
114 }
115 
116 
117 enum class ColorFilter : unsigned {
118     RED = 0,
119     GREEN,
120     BLUE,
121     NONE
122 };
123 
124 std::ostream& operator<<(std::ostream& out, ColorFilter mode);
125 
serialize(std::istream& str, ColorFilter& x)126 inline void serialize(std::istream& str, ColorFilter& x)
127 {
128     unsigned value;
129     serialize(str, value);
130     x = static_cast<ColorFilter>(value);
131 }
132 
serialize(std::ostream& str, ColorFilter& x)133 inline void serialize(std::ostream& str, ColorFilter& x)
134 {
135     unsigned value = static_cast<unsigned>(x);
136     serialize(str, value);
137 }
138 
139 enum class ColorOrder
140 {
141     RGB,
142     GBR,
143     BGR,
144 };
145 
146 /*  Enum value naming conventions:
147     Full name must be included with the following exceptions:
148 
149     Canon scanners omit "Canoscan" if present
150 */
151 enum class ModelId : unsigned
152 {
153     UNKNOWN = 0,
154     CANON_4400F,
155     CANON_5600F,
156     CANON_8400F,
157     CANON_8600F,
158     CANON_IMAGE_FORMULA_101,
159     CANON_LIDE_50,
160     CANON_LIDE_60,
161     CANON_LIDE_80,
162     CANON_LIDE_90,
163     CANON_LIDE_100,
164     CANON_LIDE_110,
165     CANON_LIDE_120,
166     CANON_LIDE_200,
167     CANON_LIDE_210,
168     CANON_LIDE_220,
169     CANON_LIDE_700F,
170     DCT_DOCKETPORT_487,
171     HP_SCANJET_2300C,
172     HP_SCANJET_2400C,
173     HP_SCANJET_3670,
174     HP_SCANJET_4850C,
175     HP_SCANJET_G4010,
176     HP_SCANJET_G4050,
177     HP_SCANJET_N6310,
178     MEDION_MD5345,
179     PANASONIC_KV_SS080,
180     PENTAX_DSMOBILE_600,
181     PLUSTEK_OPTICBOOK_3800,
182     PLUSTEK_OPTICFILM_7200,
183     PLUSTEK_OPTICFILM_7200I,
184     PLUSTEK_OPTICFILM_7300,
185     PLUSTEK_OPTICFILM_7400,
186     PLUSTEK_OPTICFILM_7500I,
187     PLUSTEK_OPTICFILM_8200I,
188     PLUSTEK_OPTICPRO_3600,
189     PLUSTEK_OPTICPRO_ST12,
190     PLUSTEK_OPTICPRO_ST24,
191     SYSCAN_DOCKETPORT_465,
192     SYSCAN_DOCKETPORT_467,
193     SYSCAN_DOCKETPORT_485,
194     SYSCAN_DOCKETPORT_665,
195     SYSCAN_DOCKETPORT_685,
196     UMAX_ASTRA_4500,
197     VISIONEER_7100,
198     VISIONEER_ROADWARRIOR,
199     VISIONEER_STROBE_XP100_REVISION3,
200     VISIONEER_STROBE_XP200,
201     VISIONEER_STROBE_XP300,
202     XEROX_2400,
203     XEROX_TRAVELSCANNER_100,
204 };
205 
serialize(std::istream& str, ModelId& x)206 inline void serialize(std::istream& str, ModelId& x)
207 {
208     unsigned value;
209     serialize(str, value);
210     x = static_cast<ModelId>(value);
211 }
212 
serialize(std::ostream& str, ModelId& x)213 inline void serialize(std::ostream& str, ModelId& x)
214 {
215     unsigned value = static_cast<unsigned>(x);
216     serialize(str, value);
217 }
218 
219 std::ostream& operator<<(std::ostream& out, ModelId id);
220 
221 enum class SensorId : unsigned
222 {
223     UNKNOWN = 0,
224     CCD_5345,
225     CCD_CANON_4400F,
226     CCD_CANON_5600F,
227     CCD_CANON_8400F,
228     CCD_CANON_8600F,
229     CCD_DP665,
230     CCD_DP685,
231     CCD_DSMOBILE600,
232     CCD_DOCKETPORT_487,
233     CCD_G4050,
234     CCD_HP2300,
235     CCD_HP2400,
236     CCD_HP3670,
237     CCD_HP_N6310,
238     CCD_HP_4850C,
239     CCD_IMG101,
240     CCD_KVSS080,
241     CCD_PLUSTEK_OPTICBOOK_3800,
242     CCD_PLUSTEK_OPTICFILM_7200,
243     CCD_PLUSTEK_OPTICFILM_7200I,
244     CCD_PLUSTEK_OPTICFILM_7300,
245     CCD_PLUSTEK_OPTICFILM_7400,
246     CCD_PLUSTEK_OPTICFILM_7500I,
247     CCD_PLUSTEK_OPTICFILM_8200I,
248     CCD_PLUSTEK_OPTICPRO_3600,
249     CCD_ROADWARRIOR,
250     CCD_ST12,         // SONY ILX548: 5340 Pixel  ???
251     CCD_ST24,         // SONY ILX569: 10680 Pixel ???
252     CCD_UMAX,
253     CCD_XP300,
254     CIS_CANON_LIDE_35,
255     CIS_CANON_LIDE_60,
256     CIS_CANON_LIDE_80,
257     CIS_CANON_LIDE_90,
258     CIS_CANON_LIDE_100,
259     CIS_CANON_LIDE_110,
260     CIS_CANON_LIDE_120,
261     CIS_CANON_LIDE_200,
262     CIS_CANON_LIDE_210,
263     CIS_CANON_LIDE_220,
264     CIS_CANON_LIDE_700F,
265     CIS_XP200,
266 };
267 
serialize(std::istream& str, SensorId& x)268 inline void serialize(std::istream& str, SensorId& x)
269 {
270     unsigned value;
271     serialize(str, value);
272     x = static_cast<SensorId>(value);
273 }
274 
serialize(std::ostream& str, SensorId& x)275 inline void serialize(std::ostream& str, SensorId& x)
276 {
277     unsigned value = static_cast<unsigned>(x);
278     serialize(str, value);
279 }
280 
281 std::ostream& operator<<(std::ostream& out, SensorId id);
282 
283 
284 enum class AdcId : unsigned
285 {
286     UNKNOWN = 0,
287     AD_XP200,
288     CANON_LIDE_35,
289     CANON_LIDE_80,
290     CANON_LIDE_90,
291     CANON_LIDE_110,
292     CANON_LIDE_120,
293     CANON_LIDE_200,
294     CANON_LIDE_700F,
295     CANON_4400F,
296     CANON_5600F,
297     CANON_8400F,
298     CANON_8600F,
299     G4050,
300     IMG101,
301     KVSS080,
302     PLUSTEK_OPTICBOOK_3800,
303     PLUSTEK_OPTICFILM_7200,
304     PLUSTEK_OPTICFILM_7200I,
305     PLUSTEK_OPTICFILM_7300,
306     PLUSTEK_OPTICFILM_7400,
307     PLUSTEK_OPTICFILM_7500I,
308     PLUSTEK_OPTICFILM_8200I,
309     PLUSTEK_OPTICPRO_3600,
310     WOLFSON_5345,
311     WOLFSON_DSM600,
312     WOLFSON_HP2300,
313     WOLFSON_HP2400,
314     WOLFSON_HP3670,
315     WOLFSON_ST12,
316     WOLFSON_ST24,
317     WOLFSON_UMAX,
318     WOLFSON_XP300,
319 };
320 
serialize(std::istream& str, AdcId& x)321 inline void serialize(std::istream& str, AdcId& x)
322 {
323     unsigned value;
324     serialize(str, value);
325     x = static_cast<AdcId>(value);
326 }
327 
serialize(std::ostream& str, AdcId& x)328 inline void serialize(std::ostream& str, AdcId& x)
329 {
330     unsigned value = static_cast<unsigned>(x);
331     serialize(str, value);
332 }
333 
334 std::ostream& operator<<(std::ostream& out, AdcId id);
335 
336 enum class GpioId : unsigned
337 {
338     UNKNOWN = 0,
339     CANON_LIDE_35,
340     CANON_LIDE_80,
341     CANON_LIDE_90,
342     CANON_LIDE_110,
343     CANON_LIDE_120,
344     CANON_LIDE_200,
345     CANON_LIDE_210,
346     CANON_LIDE_700F,
347     CANON_4400F,
348     CANON_5600F,
349     CANON_8400F,
350     CANON_8600F,
351     DP665,
352     DP685,
353     G4050,
354     G4010,
355     HP2300,
356     HP2400,
357     HP3670,
358     HP_N6310,
359     IMG101,
360     KVSS080,
361     MD_5345,
362     PLUSTEK_OPTICBOOK_3800,
363     PLUSTEK_OPTICFILM_7200,
364     PLUSTEK_OPTICFILM_7200I,
365     PLUSTEK_OPTICFILM_7300,
366     PLUSTEK_OPTICFILM_7400,
367     PLUSTEK_OPTICFILM_7500I,
368     PLUSTEK_OPTICFILM_8200I,
369     PLUSTEK_OPTICPRO_3600,
370     ST12,
371     ST24,
372     UMAX,
373     XP200,
374     XP300,
375 };
376 
377 std::ostream& operator<<(std::ostream& out, GpioId id);
378 
379 enum class MotorId : unsigned
380 {
381     UNKNOWN = 0,
382     CANON_LIDE_100,
383     CANON_LIDE_110,
384     CANON_LIDE_120,
385     CANON_LIDE_200,
386     CANON_LIDE_210,
387     CANON_LIDE_35,
388     CANON_LIDE_60,
389     CANON_LIDE_700,
390     CANON_LIDE_80,
391     CANON_LIDE_90,
392     CANON_4400F,
393     CANON_5600F,
394     CANON_8400F,
395     CANON_8600F,
396     DP665,
397     DSMOBILE_600,
398     G4050,
399     HP2300,
400     HP2400,
401     HP3670,
402     IMG101,
403     KVSS080,
404     MD_5345,
405     PLUSTEK_OPTICBOOK_3800,
406     PLUSTEK_OPTICFILM_7200,
407     PLUSTEK_OPTICFILM_7200I,
408     PLUSTEK_OPTICFILM_7300,
409     PLUSTEK_OPTICFILM_7400,
410     PLUSTEK_OPTICFILM_7500I,
411     PLUSTEK_OPTICFILM_8200I,
412     PLUSTEK_OPTICPRO_3600,
413     ROADWARRIOR,
414     ST24,
415     UMAX,
416     XP200,
417     XP300,
418 };
419 
420 std::ostream& operator<<(std::ostream& out, MotorId id);
421 
422 enum class StepType : unsigned
423 {
424     FULL = 0,
425     HALF = 1,
426     QUARTER = 2,
427     EIGHTH = 3,
428 };
429 
430 std::ostream& operator<<(std::ostream& out, StepType type);
431 
operator <(StepType lhs, StepType rhs)432 inline bool operator<(StepType lhs, StepType rhs)
433 {
434     return static_cast<unsigned>(lhs) < static_cast<unsigned>(rhs);
435 }
operator <=(StepType lhs, StepType rhs)436 inline bool operator<=(StepType lhs, StepType rhs)
437 {
438     return static_cast<unsigned>(lhs) <= static_cast<unsigned>(rhs);
439 }
operator >(StepType lhs, StepType rhs)440 inline bool operator>(StepType lhs, StepType rhs)
441 {
442     return static_cast<unsigned>(lhs) > static_cast<unsigned>(rhs);
443 }
operator >=(StepType lhs, StepType rhs)444 inline bool operator>=(StepType lhs, StepType rhs)
445 {
446     return static_cast<unsigned>(lhs) >= static_cast<unsigned>(rhs);
447 }
448 
449 enum class AsicType : unsigned
450 {
451     UNKNOWN = 0,
452     GL646,
453     GL841,
454     GL842,
455     GL843,
456     GL845,
457     GL846,
458     GL847,
459     GL124,
460 };
461 
462 
463 enum class ModelFlag : unsigned
464 {
465     // no flags
466     NONE = 0,
467 
468     // scanner is not tested, print a warning as it's likely it won't work
469     UNTESTED = 1 << 0,
470 
471     // use 14-bit gamma table instead of 12-bit
472     GAMMA_14BIT = 1 << 1,
473 
474     // perform lamp warmup
475     WARMUP = 1 << 4,
476 
477     // whether to disable offset and gain calibration
478     DISABLE_ADC_CALIBRATION = 1 << 5,
479 
480     // whether to disable exposure calibration (this currently is only done on CIS
481     // scanners)
482     DISABLE_EXPOSURE_CALIBRATION = 1 << 6,
483 
484     // whether to disable shading calibration completely
485     DISABLE_SHADING_CALIBRATION = 1 << 7,
486 
487     // do dark calibration
488     DARK_CALIBRATION = 1 << 8,
489 
490     // host-side calibration uses a complete scan
491     HOST_SIDE_CALIBRATION_COMPLETE_SCAN = 1 << 9,
492 
493     // whether scanner must wait for the head while parking
494     MUST_WAIT = 1 << 10,
495 
496     // use zeroes for dark calibration
497     USE_CONSTANT_FOR_DARK_CALIBRATION = 1 << 11,
498 
499     // do dark and white calibration in one run
500     DARK_WHITE_CALIBRATION = 1 << 12,
501 
502     // allow custom gamma tables
503     CUSTOM_GAMMA = 1 << 13,
504 
505     // disable fast feeding mode on this scanner
506     DISABLE_FAST_FEEDING = 1 << 14,
507 
508     // scan gray scans as color and combine on host side
509     HOST_SIDE_GRAY = 1 << 15,
510 
511     // the scanner uses multi-segment sensors that must be handled during calibration
512     SIS_SENSOR = 1 << 16,
513 
514     // the head must be reparked between shading scans
515     SHADING_REPARK = 1 << 18,
516 
517     // the scanner outputs inverted pixel data
518     INVERT_PIXEL_DATA = 1 << 19,
519 
520     // the scanner outputs 16-bit data that is byte-inverted
521     SWAP_16BIT_DATA = 1 << 20,
522 
523     // the scanner has transparency, but it's implemented using only one motor
524     UTA_NO_SECONDARY_MOTOR = 1 << 21,
525 
526     // the scanner has transparency, but it's implemented using only one lamp
527     TA_NO_SECONDARY_LAMP = 1 << 22,
528 };
529 
operator |(ModelFlag left, ModelFlag right)530 inline ModelFlag operator|(ModelFlag left, ModelFlag right)
531 {
532     return static_cast<ModelFlag>(static_cast<unsigned>(left) | static_cast<unsigned>(right));
533 }
534 
operator |=(ModelFlag& left, ModelFlag right)535 inline ModelFlag& operator|=(ModelFlag& left, ModelFlag right)
536 {
537     left = left | right;
538     return left;
539 }
540 
operator &(ModelFlag left, ModelFlag right)541 inline ModelFlag operator&(ModelFlag left, ModelFlag right)
542 {
543     return static_cast<ModelFlag>(static_cast<unsigned>(left) & static_cast<unsigned>(right));
544 }
545 
has_flag(ModelFlag flags, ModelFlag which)546 inline bool has_flag(ModelFlag flags, ModelFlag which)
547 {
548     return (flags & which) == which;
549 }
550 
551 
552 enum class ScanFlag : unsigned
553 {
554     NONE = 0,
555     SINGLE_LINE = 1 << 0,
556     DISABLE_SHADING = 1 << 1,
557     DISABLE_GAMMA = 1 << 2,
558     DISABLE_BUFFER_FULL_MOVE = 1 << 3,
559 
560     // if this flag is set the sensor will always be handled ignoring staggering of multiple
561     // sensors to achieve high resolution.
562     IGNORE_STAGGER_OFFSET = 1 << 4,
563 
564     // if this flag is set the sensor will always be handled as if the components that scan
565     // different colors are at the same position.
566     IGNORE_COLOR_OFFSET = 1 << 5,
567 
568     DISABLE_LAMP = 1 << 6,
569     CALIBRATION = 1 << 7,
570     FEEDING = 1 << 8,
571     USE_XPA = 1 << 9,
572     ENABLE_LEDADD = 1 << 10,
573     REVERSE = 1 << 12,
574 
575     // the scanner should return head to home position automatically after scan.
576     AUTO_GO_HOME = 1 << 13,
577 };
578 
operator |(ScanFlag left, ScanFlag right)579 inline ScanFlag operator|(ScanFlag left, ScanFlag right)
580 {
581     return static_cast<ScanFlag>(static_cast<unsigned>(left) | static_cast<unsigned>(right));
582 }
583 
operator |=(ScanFlag& left, ScanFlag right)584 inline ScanFlag& operator|=(ScanFlag& left, ScanFlag right)
585 {
586     left = left | right;
587     return left;
588 }
589 
operator &(ScanFlag left, ScanFlag right)590 inline ScanFlag operator&(ScanFlag left, ScanFlag right)
591 {
592     return static_cast<ScanFlag>(static_cast<unsigned>(left) & static_cast<unsigned>(right));
593 }
594 
has_flag(ScanFlag flags, ScanFlag which)595 inline bool has_flag(ScanFlag flags, ScanFlag which)
596 {
597     return (flags & which) == which;
598 }
599 
serialize(std::istream& str, ScanFlag& x)600 inline void serialize(std::istream& str, ScanFlag& x)
601 {
602     unsigned value;
603     serialize(str, value);
604     x = static_cast<ScanFlag>(value);
605 }
606 
serialize(std::ostream& str, ScanFlag& x)607 inline void serialize(std::ostream& str, ScanFlag& x)
608 {
609     unsigned value = static_cast<unsigned>(x);
610     serialize(str, value);
611 }
612 
613 std::ostream& operator<<(std::ostream& out, ScanFlag flags);
614 
615 
616 enum class Direction : unsigned
617 {
618     FORWARD = 0,
619     BACKWARD = 1
620 };
621 
622 enum class MotorMode : unsigned
623 {
624     PRIMARY = 0,
625     PRIMARY_AND_SECONDARY,
626     SECONDARY,
627 };
628 
629 } // namespace genesys
630 
631 #endif // BACKEND_GENESYS_ENUMS_H
632