Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#55 Can't decode matrix which was created by marginsize = 0

open
Mike Laughton
decoding (11)
5
2012-08-03
2012-08-03
clemens
No

Dear all,
I am not able to decode a string which was encoded by

dmtxEncodeSetProp(enc,DmtxPropMarginSize,0);

Here's the example, it's just the test file with a little enhancement. Check the comment right at the ENCODE stage. Uncomment it, and everything works... So, how can I use dmtxEncodeSetProp(enc,DmtxPropMarginSize,0); and be able to decode my message afterwards?? Thanks for any hints! I'm using 0.7.4.

Clemens

#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;

fprintf(stdout, "input: \"%s\"\n", str);

/* 1) ENCODE a new Data Matrix barcode image (in memory only) */

DmtxEncode *enc = dmtxEncodeCreate();
//dmtxEncodeSetProp(enc,DmtxPropMarginSize,0); //<------- check this!
dmtxEncodeSetProp(enc,DmtxPropModuleSize,2);

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 */

DmtxImage *img = dmtxImageCreate(pxl, width, height, DmtxPack24bppRGB);
assert(img != NULL);

DmtxDecode *dec = dmtxDecodeCreate(img, 1);

assert(dec != NULL);

DmtxMessage *msg;

DmtxRegion *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(&reg);
}

dmtxDecodeDestroy(&dec);
dmtxImageDestroy(&img);
free(pxl);

exit(0);
}

Discussion