Skip to content

Commit b31f804

Browse files
committed
Barcode: add experimental BitMatrix Barcode::symbol() property
Add `-symbol` cli argument to `ZXingReader` to print the detected symbol as (nicely rendered unicode) text. This feature is a precursor to the new writer API. Need to compile with `BUILD_EXPERIMENTAL_API=ON` cmake setting to see this.
1 parent 873d015 commit b31f804

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

core/src/Barcode.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ Result::Result(DecoderResult&& decodeResult, DetectorResult&& detectorResult, Ba
3434
_lineCount(decodeResult.lineCount()),
3535
_isMirrored(decodeResult.isMirrored()),
3636
_readerInit(decodeResult.readerInit())
37+
#ifdef ZXING_BUILD_EXPERIMENTAL_API
38+
, _symbol(std::make_shared<BitMatrix>(std::move(detectorResult).bits()))
39+
#endif
3740
{
3841
if (decodeResult.versionNumber())
3942
snprintf(_version, 4, "%d", decodeResult.versionNumber());

core/src/Barcode.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
#include "Quadrilateral.h"
1616
#include "StructuredAppend.h"
1717

18+
#ifdef ZXING_BUILD_EXPERIMENTAL_API
19+
#include "BitMatrix.h"
20+
#include <memory>
21+
#endif
22+
1823
#include <string>
1924
#include <vector>
2025

@@ -158,6 +163,10 @@ class Result
158163
*/
159164
std::string version() const;
160165

166+
#ifdef ZXING_BUILD_EXPERIMENTAL_API
167+
const BitMatrix& symbol() const { return *_symbol; }
168+
#endif
169+
161170
bool operator==(const Result& o) const;
162171

163172
private:
@@ -173,6 +182,9 @@ class Result
173182
bool _isMirrored = false;
174183
bool _isInverted = false;
175184
bool _readerInit = false;
185+
#ifdef ZXING_BUILD_EXPERIMENTAL_API
186+
std::shared_ptr<BitMatrix> _symbol;
187+
#endif
176188
};
177189

178190
/**

example/ZXingReader.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
*/
55
// SPDX-License-Identifier: Apache-2.0
66

7-
#include "ReadBarcode.h"
7+
#include "BitMatrixIO.h"
88
#include "GTIN.h"
9+
#include "ReadBarcode.h"
910
#include "ZXVersion.h"
1011

1112
#include <cctype>
@@ -52,6 +53,9 @@ static void PrintUsage(const char* exePath)
5253
<< " -mode <plain|eci|hri|escaped>\n"
5354
<< " Text mode used to render the raw byte content into text\n"
5455
<< " -1 Print only file name, content/error on one line per file/barcode (implies '-mode Escaped')\n"
56+
#ifdef ZXING_BUILD_EXPERIMENTAL_API
57+
<< " -symbol Print the detected symbol (if available)\n"
58+
#endif
5559
<< " -bytes Write (only) the bytes content of the symbol(s) to stdout\n"
5660
<< " -pngout <file name>\n"
5761
<< " Write a copy of the input image with barcodes outlined by a green line\n"
@@ -128,6 +132,8 @@ static bool ParseOptions(int argc, char* argv[], ReaderOptions& options, CLI& cl
128132
cli.oneLine = true;
129133
} else if (is("-bytes")) {
130134
cli.bytesOnly = true;
135+
} else if (is("-symbol")) {
136+
cli.showSymbol = true;
131137
} else if (is("-pngout")) {
132138
if (++i == argc)
133139
return false;
@@ -296,6 +302,11 @@ int main(int argc, char* argv[])
296302

297303
if (barcode.readerInit())
298304
std::cout << "Reader Initialisation/Programming\n";
305+
306+
#ifdef ZXING_BUILD_EXPERIMENTAL_API
307+
if (auto& symbol = barcode.symbol(); cli.showSymbol && !symbol.empty())
308+
std::cout << "Symbol:\n" << ToString(symbol);
309+
#endif
299310
}
300311

301312
if (Size(cli.filePaths) == 1 && !cli.outPath.empty())

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy