Data Structures

DmtxDecode

typedef struct DmtxDecode_struct {
   /* Options */
   int             edgeMin;
   int             edgeMax;
   int             scanGap;
   double          squareDevn;
   int             sizeIdxExpected;
   int             edgeThresh;

   /* Image modifiers */
   int             xMin;
   int             xMax;
   int             yMin;
   int             yMax;
   int             scale;

   /* Internals */
   unsigned char  *cache;
   DmtxImage      *image;
   DmtxScanGrid    grid;
} DmtxDecode;

DmtxEncode

typedef struct DmtxEncode_struct {
   int             method;
   int             scheme;
   int             sizeIdxRequest;
   int             marginSize;
   int             moduleSize;
   int             pixelPacking;
   int             imageFlip;
   int             rowPadBytes;
   DmtxMessage    *message;
   DmtxImage      *image;
   DmtxRegion      region;
} DmtxEncode;

DmtxImage

typedef struct DmtxImage_struct {
   int             width;
   int             height;
   int             pixelPacking;
   int             bitsPerPixel;
   int             bytesPerPixel;
   int             rowPadBytes;
   int             rowSizeBytes;
   int             imageFlip;
   int             channelCount;
   int             channelStart[4];
   int             bitsPerChannel[4];
   unsigned char  *pxl;
} DmtxImage;

libdmtx treats image data as a single 1D array of packed pixels. When reading and writing barcodes, this array provides the sole mechanism for pixel storage and libdmtx relies on the calling program to transfer images to/from the outside world (e.g., saving to disk, acquiring camera input, etc…).

By default, libdmtx treats the first pixel of an array as the top-left location of an image, with horizontal rows working downward to the final pixel at the bottom-right corner. If mapping a pixel buffer this way produces an inverted image, then specify DmtxFlipY at image creation time to remove the inversion. Note that DmtxFlipY has no significant affect on performance since it only modifies the pixel mapping math and does not alter any pixel data. If the image appears correctly without any flips then specify DmtxFlipNone.

Regardless of how an image is stored internally, all libdmtx functions consider coordinate (x=0,y=0) to represent the bottom-left pixel location of an image.

(0,HEIGHT-1)        (WIDTH-1,HEIGHT-1)
array pos = 0,1,2,3,...-----------+
            |                     |
            |                     |
            |       libdmtx       |
            |        image        |
            |     coordinates     |
            |                     |
            |                     |
            +---------...,N-2,N-1,N = array pos
          (0,0)              (WIDTH-1,0)

Notes:

  • OpenGL pixel arrays obtained with glReadPixels() are stored bottom-to-top; use DmtxFlipY
  • Many popular image formats (e.g., PNG, GIF) store rows top-to-bottom; use DmtxFlipNone

DmtxMessage

typedef struct DmtxMessage_struct {
   size_t          arraySize;     /* mappingRows * mappingCols */
   size_t          codeSize;      /* Size of encoded data (data words + error words) */
   size_t          outputSize;    /* Size of buffer used to hold decoded data */
   int             outputIdx;     /* Internal index used to store output progress */
   int             padCount;
   unsigned char  *array;         /* Pointer to internal representation of Data Matrix modules */
   unsigned char  *code;          /* Pointer to internal storage of code words (data and error) */
   unsigned char  *output;        /* Pointer to internal storage of decoded output */
} DmtxMessage;

DmtxRegion

(content required)

DmtxMatrix3

The DmtxMatrix3 struct holds a 3x3 matrix of double precision floats. These are used extensively within libdmtx to identify and refine rectangular regions (potential barcodes) within an image.

typedef double DmtxMatrix3[3][3];

The use of DmtxMatrix is best described using standard transformations as examples:

DmtxMatrix3 m;

Elements are addressed as:
   m[0][0] m[0][1] m[0][2]
   m[1][0] m[1][1] m[1][2]
   m[2][0] m[2][1] m[2][2]

Translate           Rotate
    | 1  0  0 |         |  cos(a)  sin(a)  0 |
m = | 0  1  0 |     m = | -sin(a)  cos(a)  0 |
    | tx ty 1 |         |  0       0       1 |

Scale               Shear
    | sx 0  0 |         |  0       shy     0 |
m = | 0  sy 0 |     m = |  shx     0       0 |
    | 0  0  1 |         |  0       0       1 |

These and other transformations are implemented in dmtxmatrix3.c.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License