comparison mupdf-source/thirdparty/zxing-cpp/core/src/ReaderOptions.h @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
1 /*
2 * Copyright 2016 Nu-book Inc.
3 * Copyright 2016 ZXing authors
4 * Copyright 2020 Axel Waggershauser
5 */
6 // SPDX-License-Identifier: Apache-2.0
7
8 #pragma once
9
10 #include "BarcodeFormat.h"
11 #include "CharacterSet.h"
12
13 #include <string_view>
14 #include <utility>
15
16 namespace ZXing {
17
18 /**
19 * @brief The Binarizer enum
20 *
21 * Specify which algorithm to use for the grayscale to binary transformation.
22 * The difference is how to get to a threshold value T which results in a bit
23 * value R = L <= T.
24 */
25 enum class Binarizer : unsigned char // needs to be unsigned for the bitfield below to work, uint8_t fails as well
26 {
27 LocalAverage, ///< T = average of neighboring pixels for matrix and GlobalHistogram for linear (HybridBinarizer)
28 GlobalHistogram, ///< T = valley between the 2 largest peaks in the histogram (per line in linear case)
29 FixedThreshold, ///< T = 127
30 BoolCast, ///< T = 0, fastest possible
31 };
32
33 enum class EanAddOnSymbol : unsigned char // see above
34 {
35 Ignore, ///< Ignore any Add-On symbol during read/scan
36 Read, ///< Read EAN-2/EAN-5 Add-On symbol if found
37 Require, ///< Require EAN-2/EAN-5 Add-On symbol to be present
38 };
39
40 enum class TextMode : unsigned char // see above
41 {
42 Plain, ///< bytes() transcoded to unicode based on ECI info or guessed charset (the default mode prior to 2.0)
43 ECI, ///< standard content following the ECI protocol with every character set ECI segment transcoded to unicode
44 HRI, ///< Human Readable Interpretation (dependent on the ContentType)
45 Hex, ///< bytes() transcoded to ASCII string of HEX values
46 Escaped, ///< Use the EscapeNonGraphical() function (e.g. ASCII 29 will be transcoded to "<GS>")
47 };
48
49 class ReaderOptions
50 {
51 bool _tryHarder : 1;
52 bool _tryRotate : 1;
53 bool _tryInvert : 1;
54 bool _tryDownscale : 1;
55 bool _isPure : 1;
56 bool _tryCode39ExtendedMode : 1;
57 bool _validateCode39CheckSum : 1;
58 bool _validateITFCheckSum : 1;
59 bool _returnCodabarStartEnd : 1;
60 bool _returnErrors : 1;
61 uint8_t _downscaleFactor : 3;
62 EanAddOnSymbol _eanAddOnSymbol : 2;
63 Binarizer _binarizer : 2;
64 TextMode _textMode : 3;
65 CharacterSet _characterSet : 6;
66 #ifdef ZXING_EXPERIMENTAL_API
67 bool _tryDenoise : 1;
68 #endif
69
70 uint8_t _minLineCount = 2;
71 uint8_t _maxNumberOfSymbols = 0xff;
72 uint16_t _downscaleThreshold = 500;
73 BarcodeFormats _formats = BarcodeFormat::None;
74
75 public:
76 // bitfields don't get default initialized to 0 before c++20
77 ReaderOptions()
78 : _tryHarder(1),
79 _tryRotate(1),
80 _tryInvert(1),
81 _tryDownscale(1),
82 _isPure(0),
83 _tryCode39ExtendedMode(1),
84 _validateCode39CheckSum(0),
85 _validateITFCheckSum(0),
86 _returnCodabarStartEnd(1),
87 _returnErrors(0),
88 _downscaleFactor(3),
89 _eanAddOnSymbol(EanAddOnSymbol::Ignore),
90 _binarizer(Binarizer::LocalAverage),
91 _textMode(TextMode::HRI),
92 _characterSet(CharacterSet::Unknown)
93 #ifdef ZXING_EXPERIMENTAL_API
94 ,
95 _tryDenoise(0)
96 #endif
97 {}
98
99 #define ZX_PROPERTY(TYPE, GETTER, SETTER, ...) \
100 TYPE GETTER() const noexcept { return _##GETTER; } \
101 __VA_ARGS__ ReaderOptions& SETTER(TYPE v)& { return (void)(_##GETTER = std::move(v)), *this; } \
102 __VA_ARGS__ ReaderOptions&& SETTER(TYPE v)&& { return (void)(_##GETTER = std::move(v)), std::move(*this); }
103
104 /// Specify a set of BarcodeFormats that should be searched for, the default is all supported formats.
105 ZX_PROPERTY(BarcodeFormats, formats, setFormats)
106
107 /// Spend more time to try to find a barcode; optimize for accuracy, not speed.
108 ZX_PROPERTY(bool, tryHarder, setTryHarder)
109
110 /// Also try detecting code in 90, 180 and 270 degree rotated images.
111 ZX_PROPERTY(bool, tryRotate, setTryRotate)
112
113 /// Also try detecting inverted ("reversed reflectance") codes if the format allows for those.
114 ZX_PROPERTY(bool, tryInvert, setTryInvert)
115
116 /// Also try detecting code in downscaled images (depending on image size).
117 ZX_PROPERTY(bool, tryDownscale, setTryDownscale)
118
119 #ifdef ZXING_EXPERIMENTAL_API
120 /// Also try detecting code after denoising (currently morphological closing filter for 2D symbologies only).
121 ZX_PROPERTY(bool, tryDenoise, setTryDenoise)
122 #endif
123
124 /// Binarizer to use internally when using the ReadBarcode function
125 ZX_PROPERTY(Binarizer, binarizer, setBinarizer)
126
127 /// Set to true if the input contains nothing but a single perfectly aligned barcode (generated image)
128 ZX_PROPERTY(bool, isPure, setIsPure)
129
130 /// Image size ( min(width, height) ) threshold at which to start downscaled scanning
131 // WARNING: this API is experimental and may change/disappear
132 ZX_PROPERTY(uint16_t, downscaleThreshold, setDownscaleThreshold)
133
134 /// Scale factor used during downscaling, meaningful values are 2, 3 and 4
135 // WARNING: this API is experimental and may change/disappear
136 ZX_PROPERTY(uint8_t, downscaleFactor, setDownscaleFactor)
137
138 /// The number of scan lines in a linear barcode that have to be equal to accept the result, default is 2
139 ZX_PROPERTY(uint8_t, minLineCount, setMinLineCount)
140
141 /// The maximum number of symbols (barcodes) to detect / look for in the image with ReadBarcodes
142 ZX_PROPERTY(uint8_t, maxNumberOfSymbols, setMaxNumberOfSymbols)
143
144 /// Enable the heuristic to detect and decode "full ASCII"/extended Code39 symbols
145 ZX_PROPERTY(bool, tryCode39ExtendedMode, setTryCode39ExtendedMode)
146
147 /// Deprecated / does nothing. The Code39 symbol has a valid checksum iff symbologyIdentifier()[2] is an odd digit
148 ZX_PROPERTY(bool, validateCode39CheckSum, setValidateCode39CheckSum, [[deprecated]])
149
150 /// Deprecated / does nothing. The ITF symbol has a valid checksum iff symbologyIdentifier()[2] == '1'.
151 ZX_PROPERTY(bool, validateITFCheckSum, setValidateITFCheckSum, [[deprecated]])
152
153 /// Deprecated / does nothing. Codabar start/stop characters are always returned.
154 ZX_PROPERTY(bool, returnCodabarStartEnd, setReturnCodabarStartEnd, [[deprecated]])
155
156 /// If true, return the barcodes with errors as well (e.g. checksum errors, see @Barcode::error())
157 ZX_PROPERTY(bool, returnErrors, setReturnErrors)
158
159 /// Specify whether to ignore, read or require EAN-2/5 add-on symbols while scanning EAN/UPC codes
160 ZX_PROPERTY(EanAddOnSymbol, eanAddOnSymbol, setEanAddOnSymbol)
161
162 /// Specifies the TextMode that controls the return of the Barcode::text() function
163 ZX_PROPERTY(TextMode, textMode, setTextMode)
164
165 /// Specifies fallback character set to use instead of auto-detecting it (when applicable)
166 ZX_PROPERTY(CharacterSet, characterSet, setCharacterSet)
167 ReaderOptions& setCharacterSet(std::string_view v)& { return (void)(_characterSet = CharacterSetFromString(v)), *this; }
168 ReaderOptions&& setCharacterSet(std::string_view v) && { return (void)(_characterSet = CharacterSetFromString(v)), std::move(*this); }
169
170 #undef ZX_PROPERTY
171
172 bool hasFormat(BarcodeFormats f) const noexcept { return _formats.testFlags(f) || _formats.empty(); }
173 };
174
175 #ifndef HIDE_DECODE_HINTS_ALIAS
176 using DecodeHints [[deprecated]] = ReaderOptions;
177 #endif
178
179 } // ZXing