comparison mupdf-source/thirdparty/zxing-cpp/core/src/Barcode.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 "ByteArray.h"
12 #include "Content.h"
13 #include "ReaderOptions.h"
14 #include "Error.h"
15 #include "ImageView.h"
16 #include "Quadrilateral.h"
17 #include "StructuredAppend.h"
18
19 #ifdef ZXING_EXPERIMENTAL_API
20 #include <memory>
21 namespace ZXing {
22 class BitMatrix;
23 }
24
25 extern "C" struct zint_symbol;
26 struct zint_symbol_deleter
27 {
28 void operator()(zint_symbol* p) const noexcept;
29 };
30 using unique_zint_symbol = std::unique_ptr<zint_symbol, zint_symbol_deleter>;
31 #endif
32
33 #include <string>
34 #include <vector>
35
36 namespace ZXing {
37
38 class DecoderResult;
39 class DetectorResult;
40 class WriterOptions;
41 class Result; // TODO: 3.0 replace deprected symbol name
42
43 using Position = QuadrilateralI;
44 using Barcode = Result;
45 using Barcodes = std::vector<Barcode>;
46 using Results = std::vector<Result>;
47
48 /**
49 * @brief The Barcode class encapsulates the result of decoding a barcode within an image.
50 */
51 class Result
52 {
53 void setIsInverted(bool v) { _isInverted = v; }
54 Result& setReaderOptions(const ReaderOptions& opts);
55
56 friend Barcode MergeStructuredAppendSequence(const Barcodes&);
57 friend Barcodes ReadBarcodes(const ImageView&, const ReaderOptions&);
58 friend Image WriteBarcodeToImage(const Barcode&, const WriterOptions&);
59 friend void IncrementLineCount(Barcode&);
60
61 public:
62 Result() = default;
63
64 // linear symbology convenience constructor
65 Result(const std::string& text, int y, int xStart, int xStop, BarcodeFormat format, SymbologyIdentifier si, Error error = {},
66 bool readerInit = false);
67
68 Result(DecoderResult&& decodeResult, DetectorResult&& detectorResult, BarcodeFormat format);
69
70 [[deprecated]] Result(DecoderResult&& decodeResult, Position&& position, BarcodeFormat format);
71
72 bool isValid() const;
73
74 const Error& error() const { return _error; }
75
76 BarcodeFormat format() const { return _format; }
77
78 /**
79 * @brief bytes is the raw / standard content without any modifications like character set conversions
80 */
81 const ByteArray& bytes() const;
82
83 /**
84 * @brief bytesECI is the raw / standard content following the ECI protocol
85 */
86 ByteArray bytesECI() const;
87
88 /**
89 * @brief text returns the bytes() content rendered to unicode/utf8 text accoring to specified TextMode
90 */
91 std::string text(TextMode mode) const;
92
93 /**
94 * @brief text returns the bytes() content rendered to unicode/utf8 text accoring to the TextMode set in the ReaderOptions
95 */
96 std::string text() const;
97
98 /**
99 * @brief ecLevel returns the error correction level of the symbol (empty string if not applicable)
100 */
101 std::string ecLevel() const;
102
103 /**
104 * @brief contentType gives a hint to the type of content found (Text/Binary/GS1/etc.)
105 */
106 ContentType contentType() const;
107
108 /**
109 * @brief hasECI specifies wheter or not an ECI tag was found
110 */
111 bool hasECI() const;
112
113 const Position& position() const { return _position; }
114 void setPosition(Position pos) { _position = pos; }
115
116 /**
117 * @brief orientation of barcode in degree, see also Position::orientation()
118 */
119 int orientation() const;
120
121 /**
122 * @brief isMirrored is the symbol mirrored (currently only supported by QRCode and DataMatrix)
123 */
124 bool isMirrored() const { return _isMirrored; }
125
126 /**
127 * @brief isInverted is the symbol inverted / has reveresed reflectance (see ReaderOptions::tryInvert)
128 */
129 bool isInverted() const { return _isInverted; }
130
131 /**
132 * @brief symbologyIdentifier Symbology identifier "]cm" where "c" is symbology code character, "m" the modifier.
133 */
134 std::string symbologyIdentifier() const;
135
136 /**
137 * @brief sequenceSize number of symbols in a structured append sequence.
138 *
139 * If this is not part of a structured append sequence, the returned value is -1.
140 * If it is a structured append symbol but the total number of symbols is unknown, the
141 * returned value is 0 (see PDF417 if optional "Segment Count" not given).
142 */
143 int sequenceSize() const;
144
145 /**
146 * @brief sequenceIndex the 0-based index of this symbol in a structured append sequence.
147 */
148 int sequenceIndex() const;
149
150 /**
151 * @brief sequenceId id to check if a set of symbols belongs to the same structured append sequence.
152 *
153 * If the symbology does not support this feature, the returned value is empty (see MaxiCode).
154 * For QR Code, this is the parity integer converted to a string.
155 * For PDF417 and DataMatrix, this is the "fileId".
156 */
157 std::string sequenceId() const;
158
159 bool isLastInSequence() const { return sequenceSize() == sequenceIndex() + 1; }
160 bool isPartOfSequence() const { return sequenceSize() > -1 && sequenceIndex() > -1; }
161
162 /**
163 * @brief readerInit Set if Reader Initialisation/Programming symbol.
164 */
165 bool readerInit() const { return _readerInit; }
166
167 /**
168 * @brief lineCount How many lines have been detected with this code (applies only to linear symbologies)
169 */
170 int lineCount() const { return _lineCount; }
171
172 /**
173 * @brief version QRCode / DataMatrix / Aztec version or size.
174 */
175 std::string version() const;
176
177 #ifdef ZXING_EXPERIMENTAL_API
178 void symbol(BitMatrix&& bits);
179 ImageView symbol() const;
180 void zint(unique_zint_symbol&& z);
181 zint_symbol* zint() const { return _zint.get(); }
182 #endif
183
184 bool operator==(const Result& o) const;
185
186 private:
187 Content _content;
188 Error _error;
189 Position _position;
190 ReaderOptions _readerOpts; // TODO: 3.0 switch order to prevent 4 padding bytes
191 StructuredAppendInfo _sai;
192 BarcodeFormat _format = BarcodeFormat::None;
193 char _ecLevel[4] = {};
194 char _version[4] = {};
195 int _lineCount = 0;
196 bool _isMirrored = false;
197 bool _isInverted = false;
198 bool _readerInit = false;
199 #ifdef ZXING_EXPERIMENTAL_API
200 std::shared_ptr<BitMatrix> _symbol;
201 std::shared_ptr<zint_symbol> _zint;
202 #endif
203 };
204
205 /**
206 * @brief Merge a list of Barcodes from one Structured Append sequence to a single barcode
207 */
208 Barcode MergeStructuredAppendSequence(const Barcodes& results);
209
210 /**
211 * @brief Automatically merge all Structured Append sequences found in the given list of barcodes
212 */
213 Barcodes MergeStructuredAppendSequences(const Barcodes& barcodes);
214
215 } // ZXing