7#include "datamatrixbarcode_p.h"
11DataMatrixBarcode::DataMatrixBarcode()
12 : AbstractBarcodePrivate(
Barcode::TwoDimensions)
15DataMatrixBarcode::~DataMatrixBarcode() =
default;
17QImage DataMatrixBarcode::paintImage()
19 const auto data = m_data.toString();
20 if (data.size() > 1200) {
24 DmtxEncode *enc = dmtxEncodeCreate();
25 dmtxEncodeSetProp(enc, DmtxPropPixelPacking, DmtxPack32bppRGBX);
26 dmtxEncodeSetProp(enc, DmtxPropModuleSize, 1);
27 dmtxEncodeSetProp(enc, DmtxPropMarginSize, 2);
29 QByteArray trimmedData(data.trimmed().toUtf8());
30 DmtxPassFail result = dmtxEncodeDataMatrix(enc, trimmedData.length(),
reinterpret_cast<unsigned char *
>(trimmedData.data()));
31 if (result == DmtxFail) {
32 dmtxEncodeDestroy(&enc);
35 Q_ASSERT(enc->image->width == enc->image->height);
45 if (enc->image->width > 0) {
46 int size = enc->image->width * enc->image->height * 4;
47 uchar *img =
new uchar[size];
49 background[3] = qAlpha(m_background.rgba());
50 background[2] = qRed(m_background.rgba());
51 background[1] = qGreen(m_background.rgba());
52 background[0] = qBlue(m_background.rgba());
54 foreground[3] = qAlpha(m_foreground.rgba());
55 foreground[2] = qRed(m_foreground.rgba());
56 foreground[1] = qGreen(m_foreground.rgba());
57 foreground[0] = qBlue(m_foreground.rgba());
58 for (
int i = 1; i < size; i += 4) {
60 if (enc->image->pxl[i] == 0x00) {
65 for (
int j = 0; j < 4; j++) {
66 img[i - 1 + j] = color[j];
76 dmtxEncodeDestroy(&enc);
A barcode generator for a fixed barcode format.
Provides classes and methods for generating barcodes.
QImage copy(const QRect &rectangle) const const