zxing-cpp v3.0
Loading...
Searching...
No Matches
ReaderOptions.h
Go to the documentation of this file.
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#include "Version.h"
13
14#include <string_view>
15#include <utility>
16#include <memory>
17
18namespace ZXing {
19
25enum class Binarizer : unsigned char // needs to be unsigned for the bitfield below to work, uint8_t fails as well
26{
31};
32
33enum class EanAddOnSymbol : unsigned char // see above
34{
38};
39
45enum class TextMode : unsigned char // see above
46{
53};
54
74{
75 struct Data;
76 std::unique_ptr<Data> d;
77
78public:
84 ReaderOptions& operator=(ReaderOptions&&) noexcept;
85
86#define ZX_PROPERTY(TYPE, NAME, SETTER, ...) \
87 TYPE NAME() const noexcept; \
88 __VA_ARGS__ ReaderOptions& NAME(TYPE v) &; \
89 __VA_ARGS__ ReaderOptions&& NAME(TYPE v) &&; \
90 __VA_ARGS__ inline ReaderOptions& SETTER(TYPE v) & { return NAME(v); } \
91 __VA_ARGS__ inline ReaderOptions&& SETTER(TYPE v) && { return std::move(*this).NAME(v); }
92
94 const BarcodeFormats& formats() const noexcept;
98 ReaderOptions&& formats(const BarcodeFormats& v) && { return std::move(*this).formats(BarcodeFormats(v)); }
99 inline ReaderOptions& setFormats(BarcodeFormats&& v) & { return formats(std::move(v)); }
100 inline ReaderOptions&& setFormats(BarcodeFormats&& v) && { return std::move(*this).formats(std::move(v)); }
102 inline ReaderOptions&& setFormats(const BarcodeFormats& v) && { return std::move(*this).formats(BarcodeFormats(v)); }
103
105 ZX_PROPERTY(bool, tryHarder, setTryHarder)
106
107
108 ZX_PROPERTY(bool, tryRotate, setTryRotate)
109
111 ZX_PROPERTY(bool, tryInvert, setTryInvert)
112
114 ZX_PROPERTY(bool, tryDownscale, setTryDownscale)
115
116#ifdef ZXING_EXPERIMENTAL_API
118 ZX_PROPERTY(bool, tryDenoise, setTryDenoise)
119#endif
120
123
124
125 ZX_PROPERTY(bool, isPure, setIsPure)
126
129
131 ZX_PROPERTY(uint8_t, downscaleFactor, setDownscaleFactor)
132
134 ZX_PROPERTY(uint8_t, minLineCount, setMinLineCount)
135
138
141
143 ZX_PROPERTY(bool, returnErrors, setReturnErrors)
144
147
150
152 ZX_PROPERTY(CharacterSet, characterSet, setCharacterSet)
153 ReaderOptions& characterSet(std::string_view v) &;
154 ReaderOptions&& characterSet(std::string_view v) &&;
155 inline ReaderOptions& setCharacterSet(std::string_view v) & { return characterSet(v); }
156 inline ReaderOptions&& setCharacterSet(std::string_view v) && { return std::move(*this).characterSet(v); }
157
158#undef ZX_PROPERTY
159
161
162 // Silence deprecated-declarations warnings, only happening here for deprecated inline functions
163#ifdef __GNUC__
164#pragma GCC diagnostic push
165#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
166#elif defined(_MSC_VER)
167#pragma warning(push)
168#pragma warning(disable : 4996)
169#endif
170
171#define ZX_DEPRECATED_PROPERTY(TYPE, NAME, SETTER, GET_IMPL, SET_IMPL) \
172 [[deprecated]] inline TYPE NAME() const noexcept { return GET_IMPL; } \
173 [[deprecated]] ReaderOptions& NAME(TYPE v) & { SET_IMPL; return *this; } \
174 [[deprecated]] ReaderOptions&& NAME(TYPE v) && { SET_IMPL; return std::move(*this); } \
175 [[deprecated]] inline ReaderOptions& SETTER(TYPE v) & { return NAME(v); } \
176 [[deprecated]] inline ReaderOptions&& SETTER(TYPE v) && { return std::move(*this).NAME(v); }
177
179 ZX_DEPRECATED_PROPERTY(bool, tryCode39ExtendedMode, setTryCode39ExtendedMode, true, (void)v)
180
181
182 ZX_DEPRECATED_PROPERTY(bool, validateCode39CheckSum, setValidateCode39CheckSum, validateOptionalChecksum(),
184
185
186 ZX_DEPRECATED_PROPERTY(bool, validateITFCheckSum, setValidateITFCheckSum, validateOptionalChecksum(), validateOptionalChecksum(v))
187
188#undef ZX_DEPRECATED_PROPERTY
189
190#ifdef __GNUC__
191#pragma GCC diagnostic pop
192#elif defined(_MSC_VER)
193#pragma warning(pop)
194#endif
195
197
198#ifdef ZXING_INTERNAL
200 bool hasFormat(const BarcodeFormats& formats) const noexcept;
201
203 bool hasAnyFormat(const BarcodeFormats& formats) const noexcept;
204#endif
205};
206
207} // ZXing
A small container representing a collection of BarcodeFormat values.
Definition BarcodeFormat.h:182
bool isPure() const noexcept
Set to true if the input contains nothing but a single perfectly aligned barcode (generated image).
EanAddOnSymbol eanAddOnSymbol() const noexcept
Specify whether to ignore, read or require EAN-2/5 add-on symbols while scanning EAN/UPC codes.
ReaderOptions(ReaderOptions &&) noexcept
ReaderOptions & setTryHarder(bool v) &
Definition ReaderOptions.h:105
ReaderOptions & setCharacterSet(CharacterSet v) &
Definition ReaderOptions.h:152
ReaderOptions & setDownscaleFactor(uint8_t v) &
Definition ReaderOptions.h:131
uint8_t maxNumberOfSymbols() const noexcept
The maximum number of symbols (barcodes) to detect / look for in the image with ReadBarcodes.
ReaderOptions & setMaxNumberOfSymbols(uint8_t v) &
Definition ReaderOptions.h:137
ReaderOptions & setTryDownscale(bool v) &
Definition ReaderOptions.h:114
ReaderOptions && setCharacterSet(std::string_view v) &&
Definition ReaderOptions.h:156
uint8_t downscaleFactor() const noexcept
Scale factor used during downscaling, meaningful values are 2, 3 and 4.
uint16_t downscaleThreshold() const noexcept
Image size ( min(width, height) ) threshold at which to start downscaled scanning.
ReaderOptions & setTryRotate(bool v) &
Definition ReaderOptions.h:108
ReaderOptions && setFormats(const BarcodeFormats &v) &&
Definition ReaderOptions.h:102
ReaderOptions & setTextMode(TextMode v) &
Definition ReaderOptions.h:149
const BarcodeFormats & formats() const noexcept
Specify a set of BarcodeFormats that should be searched for, the default is all supported formats.
ReaderOptions & formats(const BarcodeFormats &v) &
Definition ReaderOptions.h:97
ReaderOptions & setReturnErrors(bool v) &
Definition ReaderOptions.h:143
ReaderOptions && formats(const BarcodeFormats &v) &&
Definition ReaderOptions.h:98
ReaderOptions & operator=(const ReaderOptions &)
ReaderOptions & setIsPure(bool v) &
Definition ReaderOptions.h:125
bool tryHarder() const noexcept
Spend more time to try to find a barcode; optimize for accuracy, not speed.
Binarizer binarizer() const noexcept
Binarizer to use internally when using the ReadBarcode function.
ReaderOptions & setFormats(BarcodeFormats &&v) &
Definition ReaderOptions.h:99
ReaderOptions & setDownscaleThreshold(uint16_t v) &
Definition ReaderOptions.h:128
bool tryDownscale() const noexcept
Also try detecting code in downscaled images (depending on image size).
bool tryRotate() const noexcept
Also try detecting code in 90, 180 and 270 degree rotated images.
ReaderOptions & setBinarizer(Binarizer v) &
Definition ReaderOptions.h:122
ReaderOptions & setValidateOptionalChecksum(bool v) &
Definition ReaderOptions.h:140
TextMode textMode() const noexcept
Specifies the TextMode that controls the return of the Barcode::text() function.
ReaderOptions & setEanAddOnSymbol(EanAddOnSymbol v) &
Definition ReaderOptions.h:146
bool validateOptionalChecksum() const noexcept
Validate optional checksums where applicable (e.g. Code39, ITF).
ReaderOptions(const ReaderOptions &)
ReaderOptions & setTryInvert(bool v) &
Definition ReaderOptions.h:111
bool tryInvert() const noexcept
Also try detecting inverted ("reversed reflectance") codes if the format allows for those.
bool returnErrors() const noexcept
If true, return the barcodes with errors as well (e.g. checksum errors, see Barcode::error()).
ReaderOptions & setFormats(const BarcodeFormats &v) &
Definition ReaderOptions.h:101
CharacterSet characterSet() const noexcept
Specifies fallback character set to use instead of auto-detecting it (when applicable).
ReaderOptions && setFormats(BarcodeFormats &&v) &&
Definition ReaderOptions.h:100
uint8_t minLineCount() const noexcept
The number of scan lines in a linear barcode that have to be equal to accept the result,...
ReaderOptions & setMinLineCount(uint8_t v) &
Definition ReaderOptions.h:134
Definition Barcode.h:26
Binarizer
Specify which algorithm to use for the grayscale to binary transformation.
Definition ReaderOptions.h:26
@ LocalAverage
T = average of neighboring pixels for matrix and GlobalHistogram for linear (HybridBinarizer).
Definition ReaderOptions.h:27
@ FixedThreshold
T = 127.
Definition ReaderOptions.h:29
@ BoolCast
T = 0, fastest possible.
Definition ReaderOptions.h:30
@ GlobalHistogram
T = valley between the 2 largest peaks in the histogram (per line in linear case).
Definition ReaderOptions.h:28
TextMode
Specify how the decoded byte content of a barcode should be transcoded to text.
Definition ReaderOptions.h:46
@ HRI
Human Readable Interpretation (dependent on the ContentType).
Definition ReaderOptions.h:49
@ Plain
bytes() transcoded to unicode based on ECI info or guessed charset (the default mode prior to 2....
Definition ReaderOptions.h:47
@ ECI
standard content following the ECI protocol with every character set ECI segment transcoded to unicod...
Definition ReaderOptions.h:48
@ Hex
bytes() transcoded to ASCII string of HEX values
Definition ReaderOptions.h:51
@ Escaped
Use the EscapeNonGraphical() function (e.g. ASCII 29 will be transcoded to "<GS>").
Definition ReaderOptions.h:50
@ HexECI
bytesECI() transcoded to ASCII string of HEX values
Definition ReaderOptions.h:52
EanAddOnSymbol
Definition ReaderOptions.h:34
@ Read
Read EAN-2/EAN-5 Add-On symbol if found.
Definition ReaderOptions.h:36
@ Require
Require EAN-2/EAN-5 Add-On symbol to be present.
Definition ReaderOptions.h:37
@ Ignore
Ignore any Add-On symbol during read/scan.
Definition ReaderOptions.h:35