Skip to content

Commit

Permalink
WriteBarcode: use experimental API in example and test if available
Browse files Browse the repository at this point in the history
  • Loading branch information
axxel committed Mar 6, 2024
1 parent d5cf7d0 commit 29fb3cf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
10 changes: 9 additions & 1 deletion example/ZXingQtWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
// SPDX-License-Identifier: Apache-2.0

#include "BarcodeFormat.h"
#ifdef ZXING_BUILD_EXPERIMENTAL_API
#include "WriteBarcode.h"
#else
#include "BitMatrix.h"
#include "MultiFormatWriter.h"
#endif

#include <QDebug>
#include <QImage>
Expand All @@ -16,10 +20,14 @@ QImage WriteBarcode(QStringView text, ZXing::BarcodeFormat format)
{
using namespace ZXing;

#ifdef ZXING_BUILD_EXPERIMENTAL_API
auto barcode = CreateBarcodeFromText(text.toString().toStdString(), format);
auto bitmap = WriteBarcodeToImage(barcode);
#else
auto writer = MultiFormatWriter(format);
auto matrix = writer.encode(text.toString().toStdString(), 0, 0);
auto bitmap = ToMatrix<uint8_t>(matrix);

#endif
return QImage(bitmap.data(), bitmap.width(), bitmap.height(), bitmap.width(), QImage::Format::Format_Grayscale8).copy();
}

Expand Down
12 changes: 12 additions & 0 deletions test/blackbox/TestWriterMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
// SPDX-License-Identifier: Apache-2.0

#include "BitMatrix.h"
#ifdef ZXING_BUILD_EXPERIMENTAL_API
#include "WriteBarcode.h"
#else
#include "MultiFormatWriter.h"
#endif

#include <vector>

Expand All @@ -30,7 +34,11 @@ int main()
BarcodeFormat::PDF417,
BarcodeFormat::QRCode })
{
#ifdef ZXING_BUILD_EXPERIMENTAL_API
savePng(CreateBarcodeFromText(text, format).symbol(), format);
#else
savePng(MultiFormatWriter(format).encode(text, 200, 200), format);
#endif
}

text = "012345678901234567890123456789";
Expand All @@ -47,6 +55,10 @@ int main()
{BarcodeFormat::UPCE, 7} }))
{
auto input = length > 0 ? text.substr(0, length) : text;
#ifdef ZXING_BUILD_EXPERIMENTAL_API
savePng(CreateBarcodeFromText(input, format).symbol(), format);
#else
savePng(MultiFormatWriter(format).encode(input, 100, 100), format);
#endif
}
}

0 comments on commit 29fb3cf

Please sign in to comment.