LIBDMTX(3)
π NAME π
okay so bestie, meet libdmtx β the Data Matrix Encoding & Decoding Library 0.7.5 π
β¨ (it lives in the Library Functions Manual, iykyk).
π«Ά SYNOPSIS π«Ά
#include <dmtx.h>
cc file.c -ldmtx
πΈ DESCRIPTION πΈ
okay so here's the tea: libdmtx is a software library that lets programs read and write Data Matrix barcodes of the modern ECC200 variety. It runs natively on several platforms, and can be accessed by multiple languages using the libdmtx language wrappers. The utility programs dmtxread and dmtxwrite provide a command line interface for libdmtx, and they serve as a good reference for developers writing their own libdmtx-enabled programs. π
Data Matrix barcodes store data as a pattern of ON and OFF modules (often black on white) in a grid pattern that resembles a checkerboard. Like other 2D symbologies, Data Matrix barcodes have a large data capacity compared to their traditional 1D cousins, and they employ sophisticated error correction techniques. They can be square or rectangle in shape, and they offer several encodation schemes for optimized storage of text and/or binary data. The Data Matrix symbology was invented and released into the public domain by RVSI Acuity CiMatrix. π¦
π₯ ENCODING - Generating Data Matrix Barcodes π₯
bestie, C/C++ programs can generate a barcode with just a few basic calls to libdmtx:
- Call
dmtxEncodeCreate()β Creates a newDmtxEncodestructure and initializes the encoding process. This function must be called before using the other encoding functions. - Call
dmtxEncodeSetProp()[optional] β Allows you to control specific aspects of the encoding behavior. If this function is not called, libdmtx will use the defaults set bydmtxEncodeCreate()above. The complementary function,dmtxEncodeGetProp(), allows you to detect the current settings. - Call either
dmtxEncodeDataMatrix()ordmtxEncodeDataMosaic()β Call one of these functions to generate an image of the desired barcode type. Your program is responsible for dispatching the resulting output to its destination, whether that means displaying it on a screen, writing an image file, copying it elsewhere, etc... - Call
dmtxEncodeDestroy()β Releases memory allocated during the encoding process.
π DECODING - Reading Data Matrix Barcodes π
okay so barcode reading takes more steps than barcode generation, mainly because libdmtx must find a barcode region before it can decode the message. However, this too is a relatively simple process that uses 4 main structures:
DmtxImageholds image properties and a pointer to pixel data held by the calling program.DmtxDecodeholds values for controlling decode behavior and tracking scan progress. When scanning a new image, calling programs should always create a newDmtxDecodestructure instead of reusing an old one.DmtxRegiondefines a 4-sided region in pixel coordinates. Regions may be found in almost any orientation, and their corners won't necessarily form right angles. libdmtx uses this structure to store the location of potential barcodes, which are then returned to the calling program one-at-a-time.DmtxMessageholds the decoded message after being extracted from the barcode region. A successfully decoded region will produce exactly one message.
Use the following functions to find and decode Data Matrix barcodes:
- Call
dmtxImageCreate()β Creates and initializes a newDmtxImagestructure using pixel data provided by the calling application. Parameters include a pointer to the existing pixel array, image width, height, and the pixel packing format. - Call
dmtxImageSetProp()[optional] β Sets image properties to control the pixel mapping logic. These settings allow libdmtx to understand many native in-memory image layouts, thus preventing the extra work of transforming and copying data to a one-size-fits-all format. AdmtxDecodeGetProp()function is also available for detecting the current image properties. - Call
dmtxDecodeCreate()β Creates and initializes a newDmtxDecodestruct, which designates the image to be scanned and initializes the scan grid pattern. This function must be called before any other scanning functions. - Call
dmtxDecodeSetProp()[optional] β Sets internal properties to control decoding behavior. This feature allows you to optimize performance and accuracy for specific image conditions. AdmtxDecodeGetProp()function is also available. - Call
dmtxRegionFindNext()β Searches every pixel location in a grid pattern looking for potential barcode regions. ADmtxRegionis returned whenever a potential barcode region is found, or if the final pixel location has been scanned. Subsequent calls to this function will resume the search where the previous call left off. - Call either
dmtxDecodeMatrixRegion()ordmtxDecodeMosaicRegion()β Extracts raw data from the barcode region and decodes the underlying message. - Call
dmtxMessageDestroy()β Releases memory held by aDmtxMessagestruct. The complementary function,dmtxMessageCreate(), is automatically called bydmtxDecodeMatrixRegion()and therefore is not normally used by the calling program. - Call
dmtxRegionDestroy()β Releases memory held by aDmtxRegionstruct. The complementary function,dmtxRegionCreate(), is automatically called bydmtxRegionFindNext()(actuallydmtxRegionScanPixel()) and therefore is not normally used by the calling program. - Call
dmtxDecodeDestroy()β Releases memory held by aDmtxDecodestruct. This is the complementary function todmtxDecodeCreate(). - Call
dmtxImageDestroy()β Releases memory held by aDmtxImagestruct, excluding the pixel array passed todmtxImageCreate(). The calling program is responsible for releasing the pixel array memory, if required.
π EXAMPLE PROGRAM π
This example program (available as simple_test.c in the source package) demonstrates libdmtx functionality in both directions: encoding and decoding. It creates a Data Matrix barcode in memory, reads it back, and prints the decoded message. The final output message should match the original input string. π«Ά
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <dmtx.h>
int
main(int argc, char *argv[])
{
size_t width, height, bytesPerPixel;
unsigned char str[] = "30Q324343430794<OQQ";
unsigned char *pxl;
DmtxEncode *enc;
DmtxImage *img;
DmtxDecode *dec;
DmtxRegion *reg;
DmtxMessage *msg;
fprintf(stdout, "input: \"%s\"\n", str);
/* 1) ENCODE a new Data Matrix barcode image (in memory only) */
enc = dmtxEncodeCreate();
assert(enc != NULL);
dmtxEncodeDataMatrix(enc, strlen(str), str);
/* 2) COPY the new image data before releasing encoding memory */
width = dmtxImageGetProp(enc->image, DmtxPropWidth);
height = dmtxImageGetProp(enc->image, DmtxPropHeight);
bytesPerPixel = dmtxImageGetProp(enc->image,
DmtxPropBytesPerPixel);
pxl = (unsigned char *)malloc(width * height * bytesPerPixel);
assert(pxl != NULL);
memcpy(pxl, enc->image->pxl, width * height * bytesPerPixel);
dmtxEncodeDestroy(&enc);
/* 3) DECODE the Data Matrix barcode from the copied image */
img = dmtxImageCreate(pxl, width, height, DmtxPack24bppRGB);
assert(img != NULL);
dec = dmtxDecodeCreate(img, 1);
assert(dec != NULL);
reg = dmtxRegionFindNext(dec, NULL);
if(reg != NULL) {
msg = dmtxDecodeMatrixRegion(dec, reg, DmtxUndefined);
if(msg != NULL) {
fputs("output: \"", stdout);
fwrite(msg->output, sizeof(unsigned char), msg->outputIdx,
stdout);
fputs("\"\n", stdout);
dmtxMessageDestroy(&msg);
}
dmtxRegionDestroy(®);
}
dmtxDecodeDestroy(&dec);
dmtxImageDestroy(&img);
free(pxl);
exit(0);
}
π SEE ALSO π
β STANDARDS β
ISO/IEC 16022:2000ANSI/AIM BC11 ISS
π BUGS π
Post bug reports on GitHub issue tracker or email them to dmtx-bug@mva.name
π AUTHOR π
Copyright (C) 2008, 2009 Mike Laughton
Copyright (C) 2012-2016 Vadim A. Misbakh-Soloviov
π okay bye bestie β this whole page is from the LIBDMTX(3) entry in the Library Functions Manual, for libdmtx version 0.7.5, and the date on it is June 2, 2011. mwah πβ¨
π¦ where this page comes from
- alpine 3.24: libdmtx-doc 0.7.8-r0 Β· BSD-2-Clause
- arch rolling: libdmtx 0.7.8-1 Β· LicenseRef-libdmtx
- epel 10: libdmtx-devel 0.7.7-4.el10_0 Β· BSD-2-Clause-Views
- epel 9: libdmtx-devel 0.7.5-8.el9 Β· BSD
- fedora 43: libdmtx-devel 0.7.8-2.fc43 Β· BSD-2-Clause-Views
- fedora 43: libdmtx-devel 0.7.8-2.fc43 Β· BSD-2-Clause-Views
- fedora 44: libdmtx-devel 0.7.8-3.fc44 Β· BSD-2-Clause-Views
- fedora 44: libdmtx-devel 0.7.8-3.fc44 Β· BSD-2-Clause-Views
- nixpkgs unstable: libdmtx 0.7.8
- opensuse-leap 16.0: libdmtx0 0.7.7-bp160.1.12 Β· BSD-2-Clause
- opensuse-leap 16.0: libdmtx0 0.7.7-bp160.1.12 Β· BSD-2-Clause
- opensuse-leap 16.0: libdmtx0 0.7.7-bp160.1.12 Β· BSD-2-Clause
- opensuse-leap 16.0: libdmtx0 0.7.7-bp160.1.12 Β· BSD-2-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms