comparison mupdf-source/thirdparty/zxing-cpp/example/ZXingQtWriter.cpp @ 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 2023 Axel Waggershauser
3 */
4 // SPDX-License-Identifier: Apache-2.0
5
6 #include "BarcodeFormat.h"
7 #ifdef ZXING_EXPERIMENTAL_API
8 #include "WriteBarcode.h"
9 #else
10 #include "BitMatrix.h"
11 #include "MultiFormatWriter.h"
12 #endif
13
14 #include <QDebug>
15 #include <QImage>
16
17 namespace ZXingQt {
18
19 QImage WriteBarcode(QStringView text, ZXing::BarcodeFormat format)
20 {
21 using namespace ZXing;
22
23 #ifdef ZXING_EXPERIMENTAL_API
24 auto barcode = CreateBarcodeFromText(text.toString().toStdString(), format);
25 auto bitmap = WriteBarcodeToImage(barcode);
26 #else
27 auto writer = MultiFormatWriter(format);
28 auto matrix = writer.encode(text.toString().toStdString(), 0, 0);
29 auto bitmap = ToMatrix<uint8_t>(matrix);
30 #endif
31 return QImage(bitmap.data(), bitmap.width(), bitmap.height(), bitmap.width(), QImage::Format::Format_Grayscale8).copy();
32 }
33
34 } // namespace ZXingQt
35
36 int main(int argc, char* argv[])
37 {
38 if (argc != 4) {
39 qDebug() << "usage: ZXingQtWriter <format> <text> <filename>";
40 return 1;
41 }
42
43 auto format = ZXing::BarcodeFormatFromString(argv[1]);
44 auto text = QString(argv[2]);
45 auto filename = QString(argv[3]);
46
47 auto result = ZXingQt::WriteBarcode(text, format);
48
49 result.save(filename);
50
51 return 0;
52 }