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
36enum class EanAddOnSymbol : unsigned char // see above
37{
41};
42
48enum class TextMode : unsigned char // see above
49{
56};
57
77{
78 struct Data;
79 std::unique_ptr<Data> d;
80
81public:
87 ReaderOptions& operator=(ReaderOptions&&) noexcept;
88
89#define ZX_PROPERTY(TYPE, NAME, SETTER, ...) \
90 TYPE NAME() const noexcept; \
91 __VA_ARGS__ ReaderOptions& NAME(TYPE v) &; \
92 __VA_ARGS__ ReaderOptions&& NAME(TYPE v) &&; \
93 __VA_ARGS__ inline ReaderOptions& SETTER(TYPE v) & { return NAME(v); } \
94 __VA_ARGS__ inline ReaderOptions&& SETTER(TYPE v) && { return std::move(*this).NAME(v); }
95
97 const BarcodeFormats& formats() const noexcept;
101 ReaderOptions&& formats(const BarcodeFormats& v) && { return std::move(*this).formats(BarcodeFormats(v)); }
102 inline ReaderOptions& setFormats(BarcodeFormats&& v) & { return formats(std::move(v)); }
103 inline ReaderOptions&& setFormats(BarcodeFormats&& v) && { return std::move(*this).formats(std::move(v)); }
105 inline ReaderOptions&& setFormats(const BarcodeFormats& v) && { return std::move(*this).formats(BarcodeFormats(v)); }
106
108 ZX_PROPERTY(bool, tryHarder, setTryHarder)
109
110
111 ZX_PROPERTY(bool, tryRotate, setTryRotate)
112
114 ZX_PROPERTY(bool, tryInvert, setTryInvert)
115
117 ZX_PROPERTY(bool, tryDownscale, setTryDownscale)
118
119#ifdef ZXING_EXPERIMENTAL_API
121 ZX_PROPERTY(bool, tryDenoise, setTryDenoise)
122#endif
123
126
127
128 ZX_PROPERTY(bool, isPure, setIsPure)
129
132
134 ZX_PROPERTY(uint8_t, downscaleFactor, setDownscaleFactor)
135
137 ZX_PROPERTY(uint8_t, minLineCount, setMinLineCount)
138
141
144
146 ZX_PROPERTY(bool, returnErrors, setReturnErrors)
147
150
153
156 ReaderOptions& characterSet(std::string_view v) &;
157 ReaderOptions&& characterSet(std::string_view v) &&;
158 inline ReaderOptions& setCharacterSet(std::string_view v) & { return characterSet(v); }
159 inline ReaderOptions&& setCharacterSet(std::string_view v) && { return std::move(*this).characterSet(v); }
160
161#undef ZX_PROPERTY
162
164
165 // Silence deprecated-declarations warnings, only happening here for deprecated inline functions
166#ifdef __GNUC__
167#pragma GCC diagnostic push
168#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
169#elif defined(_MSC_VER)
170#pragma warning(push)
171#pragma warning(disable : 4996)
172#endif
173
174#define ZX_DEPRECATED_PROPERTY(TYPE, NAME, SETTER, GET_IMPL, SET_IMPL) \
175 [[deprecated]] inline TYPE NAME() const noexcept { return GET_IMPL; } \
176 [[deprecated]] ReaderOptions& NAME(TYPE v) & { SET_IMPL; return *this; } \
177 [[deprecated]] ReaderOptions&& NAME(TYPE v) && { SET_IMPL; return std::move(*this); } \
178 [[deprecated]] inline ReaderOptions& SETTER(TYPE v) & { return NAME(v); } \
179 [[deprecated]] inline ReaderOptions&& SETTER(TYPE v) && { return std::move(*this).NAME(v); }
180
182 ZX_DEPRECATED_PROPERTY(bool, tryCode39ExtendedMode, setTryCode39ExtendedMode, true, (void)v)
183
184
185 ZX_DEPRECATED_PROPERTY(bool, validateCode39CheckSum, setValidateCode39CheckSum, validateOptionalChecksum(),
187
188
189 ZX_DEPRECATED_PROPERTY(bool, validateITFCheckSum, setValidateITFCheckSum, validateOptionalChecksum(), validateOptionalChecksum(v))
190
191#undef ZX_DEPRECATED_PROPERTY
192
193#ifdef __GNUC__
194#pragma GCC diagnostic pop
195#elif defined(_MSC_VER)
196#pragma warning(pop)
197#endif
198
200
201#ifdef ZXING_INTERNAL
203 bool hasFormat(const BarcodeFormats& formats) const noexcept;
204
206 bool hasAnyFormat(const BarcodeFormats& formats) const noexcept;
207#endif
208};
209
210} // 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:108
ReaderOptions & setCharacterSet(CharacterSet v) &
Definition ReaderOptions.h:155
ReaderOptions & setDownscaleFactor(uint8_t v) &
Definition ReaderOptions.h:134
uint8_t maxNumberOfSymbols() const noexcept
The maximum number of symbols (barcodes) to detect / look for with ReadBarcodes().
ReaderOptions & setMaxNumberOfSymbols(uint8_t v) &
Definition ReaderOptions.h:140
ReaderOptions & setTryDownscale(bool v) &
Definition ReaderOptions.h:117
ReaderOptions && setCharacterSet(std::string_view v) &&
Definition ReaderOptions.h:159
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:111
ReaderOptions && setFormats(const BarcodeFormats &v) &&
Definition ReaderOptions.h:105
ReaderOptions & setTextMode(TextMode v) &
Definition ReaderOptions.h:152
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:100
ReaderOptions & setReturnErrors(bool v) &
Definition ReaderOptions.h:146
ReaderOptions && formats(const BarcodeFormats &v) &&
Definition ReaderOptions.h:101
ReaderOptions & operator=(const ReaderOptions &)
ReaderOptions & setIsPure(bool v) &
Definition ReaderOptions.h:128
bool tryHarder() const noexcept
Spend more time to try to find a barcode; optimize for accuracy instead of not speed (default: true).
Binarizer binarizer() const noexcept
Binarizer to use for grayscale to binary transformation (default: Binarizer::LocalAverage).
ReaderOptions & setFormats(BarcodeFormats &&v) &
Definition ReaderOptions.h:102
ReaderOptions & setDownscaleThreshold(uint16_t v) &
Definition ReaderOptions.h:131
bool tryDownscale() const noexcept
Try detecting code in downscaled images (depending on image size) (default: true).
bool tryRotate() const noexcept
Try detecting codes in 90, 180 and 270 degree rotated images (default: true).
ReaderOptions & setBinarizer(Binarizer v) &
Definition ReaderOptions.h:125
ReaderOptions & setValidateOptionalChecksum(bool v) &
Definition ReaderOptions.h:143
TextMode textMode() const noexcept
Specifies the TextMode that controls the return of the Barcode::text() function (default: TextMode::H...
ReaderOptions & setEanAddOnSymbol(EanAddOnSymbol v) &
Definition ReaderOptions.h:149
bool validateOptionalChecksum() const noexcept
Validate optional checksums where applicable (e.g. Code39, ITF) (default: false).
ReaderOptions(const ReaderOptions &)
ReaderOptions & setTryInvert(bool v) &
Definition ReaderOptions.h:114
bool tryInvert() const noexcept
Try detecting inverted ("reversed reflectance") codes if the format allows for those (default: true).
bool returnErrors() const noexcept
If true, return the barcodes with errors as well (e.g. checksum errors, see Barcode::error()) (defaul...
ReaderOptions & setFormats(const BarcodeFormats &v) &
Definition ReaderOptions.h:104
CharacterSet characterSet() const noexcept
Specifies fallback character set to use instead of auto-detecting it (when applicable).
ReaderOptions && setFormats(BarcodeFormats &&v) &&
Definition ReaderOptions.h:103
uint8_t minLineCount() const noexcept
The number of scan lines in a linear barcode that have to be equal to accept the result (default: 2).
ReaderOptions & setMinLineCount(uint8_t v) &
Definition ReaderOptions.h:137
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
CharacterSet
Definition CharacterSet.h:14
TextMode
Specify how the decoded byte content of a barcode should be transcoded to text.
Definition ReaderOptions.h:49
@ HRI
Human Readable Interpretation (dependent on the ContentType).
Definition ReaderOptions.h:52
@ Plain
bytes() transcoded to unicode based on ECI info or guessed charset (the default mode prior to 2....
Definition ReaderOptions.h:50
@ ECI
standard content following the ECI protocol with every character set ECI segment transcoded to unicod...
Definition ReaderOptions.h:51
@ Hex
bytes() transcoded to ASCII string of HEX values
Definition ReaderOptions.h:54
@ Escaped
Use the EscapeNonGraphical() function (e.g. ASCII 29 will be transcoded to "<GS>").
Definition ReaderOptions.h:53
@ HexECI
bytesECI() transcoded to ASCII string of HEX values
Definition ReaderOptions.h:55
EanAddOnSymbol
Specify whether to ignore, read or require EAN-2/5 add-on symbols while scanning EAN/UPC codes.
Definition ReaderOptions.h:37
@ Read
Read EAN-2/EAN-5 Add-On symbol if found.
Definition ReaderOptions.h:39
@ Require
Require EAN-2/EAN-5 Add-On symbol to be present.
Definition ReaderOptions.h:40
@ Ignore
Ignore any Add-On symbol during read/scan.
Definition ReaderOptions.h:38