libdatamatrix is an embeddable and highly extensible library made to separate datamatrix (ISO/IEC16022) functionality from image reading/writing since I needed to make a custom image scanner and couldn't find any libraries that did error correction (instead of just error checking) and had a modular interface allowing one to extend functionality easily.
Since it was just written for internal use, it's not very polished. I'm just releasing it in hopes that it helps anyone who is also in search of an embeddable datamatrix solution.
The project also comes with a tiff image reading and very simplistic image scanner that finds and reads matrices.
Requirements:
· libfec
How to use:
Bundled with this library is a command line utility for accessing it - it also
serves as a good example (src/cli.c).
At the top level, one would just need to use datamatrix_create() and dm_region_read(), however internal functions are exported to allow extending the whole read or write process, for example to use a proprietary encoding method.
Better docs may come with time.
Example of simple region decoding
##############################
dm_region_t *reg;
if(!(str = dm_region_read(NULL, reg)))
error("Failed to decode image: %s", strerror(errno));
printf("decoded to [%s]n", str);
###############################
Example of dm_config
###############################
dm_config_t conf;
# config struct contains:
# int w, h;
# dm_enc_t encoding;
# dm_errcb_t errmsg;
#hard set the datamatrix width and height
# if not set for creating, it uses the smallest size that will fit data
conf.w = 12;
conf.h = 12;
# sets the encoding method - currently unimplemented and only uses ASCII
conf.encoding = DM_AUTOENC;
void errcb(const char *fmt, va_list ap)
{
fprintf(stderr, "libdatamatrix: ");
vfprintf(stderr, fmt, ap);
fprintf(stderr, "n");
}
# sets a callback function for reporting errors
conf.errmsg = errcb;
##################################
Example of extending to use a custom encoder (in this case for higher density
data encoding).
##################################
#define TS_DM_W 12
#define TS_DM_H 12
# gets a datamatrix definition based on width and height of matrix
/* lookup region size definition */
if(!(def = dm_szdef_wh(TS_DM_W, TS_DM_H)))
errret(NULL, "Invalid datamatrix region size (%dx%d)", TS_DM_W, TS_DM_H);
/* create a buf for total size of data and RS codewords */
if(!(data = dm_buf_new(NULL, def->dcw + def->rscw)))
errret(NULL, "Failed to alloc for dm buf");
# this is the propietary encoding method
/* encode slot */
ts_dm_enc(slot, data);
# padding not needed since the encoding uses the full datacode codeword section
# adds the ECC information to the end of the data buf
/* append ecc blocks */
dm_eccenc(data, def->rscw);
# dm_region_new is what actually turns an arbitrary chunk of data into a
# datamatrix, size based on the definition
/* reset idx for write */
data->idx = 0;
return(dm_region_new(def->w, def->h, data));
Product's homepage