/**
* libdmtx - Data Matrix Encoding/Decoding Library
* Copyright 2008, 2009 Mike Laughton. All rights reserved.
*
* See LICENSE file in the main project directory for full
* terms of use and distribution.
*
* Contact: Mike Laughton <mike@dragonflylogic.com>
*
* \file dmtx.h
* \brief Main libdmtx header
*/
#ifndef __DMTX_H__
#define __DMTX_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Time headers required for DmtxTime struct below */
#include <time.h>
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#ifndef M_PI_2
#define M_PI_2 1.57079632679489661923
#endif
#define DmtxVersion "0.7.4"
#define DmtxUndefined -1
#define DmtxPassFail unsigned int
#define DmtxPass 1
#define DmtxFail 0
#define DmtxBoolean unsigned int
#define DmtxTrue 1
#define DmtxFalse 0
#define DmtxFormatMatrix 0
#define DmtxFormatMosaic 1
#define DmtxSymbolSquareCount 24
#define DmtxSymbolRectCount 6
#define DmtxModuleOff 0x00
#define DmtxModuleOnRed 0x01
#define DmtxModuleOnGreen 0x02
#define DmtxModuleOnBlue 0x04
#define DmtxModuleOnRGB 0x07 /* OnRed | OnGreen | OnBlue */
#define DmtxModuleOn 0x07
#define DmtxModuleUnsure 0x08
#define DmtxModuleAssigned 0x10
#define DmtxModuleVisited 0x20
#define DmtxModuleData 0x40
#define DMTX_CHECK_BOUNDS(l,i) (assert((i) >= 0 && (i) < (l)->length && (l)->length <= (l)->capacity))
typedef enum {
DmtxStatusEncoding, /* Encoding is currently underway */
DmtxStatusComplete, /* Encoding is done and everything went well */
DmtxStatusInvalid, /* Something bad happened that sometimes happens */
DmtxStatusFatal /* Something happened that should never happen */
} DmtxStatus;
typedef enum {
DmtxSchemeAutoFast = -2,
DmtxSchemeAutoBest = -1,
DmtxSchemeAscii = 0,
DmtxSchemeC40,
DmtxSchemeText,
DmtxSchemeX12,
DmtxSchemeEdifact,
DmtxSchemeBase256
} DmtxScheme;
typedef enum {
DmtxSymbolRectAuto = -3,
DmtxSymbolSquareAuto = -2,
DmtxSymbolShapeAuto = -1,
DmtxSymbol10x10 = 0,
DmtxSymbol12x12,
DmtxSymbol14x14,
DmtxSymbol16x16,
DmtxSymbol18x18,
DmtxSymbol20x20,
DmtxSymbol22x22,
DmtxSymbol24x24,
DmtxSymbol26x26,
DmtxSymbol32x32,
DmtxSymbol36x36,
DmtxSymbol40x40,
DmtxSymbol44x44,
DmtxSymbol48x48,
DmtxSymbol52x52,
DmtxSymbol64x64,
DmtxSymbol72x72,
DmtxSymbol80x80,
DmtxSymbol88x88,
DmtxSymbol96x96,
DmtxSymbol104x104,
DmtxSymbol120x120,
DmtxSymbol132x132,
DmtxSymbol144x144,
DmtxSymbol8x18,
DmtxSymbol8x32,
DmtxSymbol12x26,
DmtxSymbol12x36,
DmtxSymbol16x36,
DmtxSymbol16x48
} DmtxSymbolSize;
typedef enum {
DmtxDirNone = 0x00,
DmtxDirUp = 0x01 << 0,
DmtxDirLeft = 0x01 << 1,
DmtxDirDown = 0x01 << 2,
DmtxDirRight = 0x01 << 3,
DmtxDirHorizontal = DmtxDirLeft | DmtxDirRight,
DmtxDirVertical = DmtxDirUp | DmtxDirDown,
DmtxDirRightUp = DmtxDirRight | DmtxDirUp,
DmtxDirLeftDown = DmtxDirLeft | DmtxDirDown
} DmtxDirection;
typedef enum {
DmtxSymAttribSymbolRows,
DmtxSymAttribSymbolCols,
DmtxSymAttribDataRegionRows,
DmtxSymAttribDataRegionCols,
DmtxSymAttribHorizDataRegions,
DmtxSymAttribVertDataRegions,
DmtxSymAttribMappingMatrixRows,
DmtxSymAttribMappingMatrixCols,
DmtxSymAttribInterleavedBlocks,
DmtxSymAttribBlockErrorWords,
DmtxSymAttribBlockMaxCorrectable,
DmtxSymAttribSymbolDataWords,
DmtxSymAttribSymbolErrorWords,
DmtxSymAttribSymbolMaxCorrectable
} DmtxSymAttribute;
typedef enum {
DmtxCorner00 = 0x01 << 0,
DmtxCorner10 = 0x01 << 1,
DmtxCorner11 = 0x01 << 2,
DmtxCorner01 = 0x01 << 3
} DmtxCornerLoc;
typedef enum {
/* Encoding properties */
DmtxPropScheme = 100,
DmtxPropSizeRequest,
DmtxPropMarginSize,
DmtxPropModuleSize,
/* Decoding properties */
DmtxPropEdgeMin = 200,
DmtxPropEdgeMax,
DmtxPropScanGap,
DmtxPropSquareDevn,
DmtxPropSymbolSize,
DmtxPropEdgeThresh,
/* Image properties */
DmtxPropWidth = 300,
DmtxPropHeight,
DmtxPropPixelPacking,
DmtxPropBitsPerPixel,
DmtxPropBytesPerPixel,
DmtxPropRowPadBytes,
DmtxPropRowSizeBytes,
DmtxPropImageFlip,
DmtxPropChannelCount,
/* Image modifiers */
DmtxPropXmin = 400,
DmtxPropXmax,
DmtxPropYmin,
DmtxPropYmax,
DmtxPropScale
} DmtxProperty;
typedef enum {
/* Custom format */
DmtxPackCustom = 100,
/* 1 bpp */
DmtxPack1bppK = 200,
/* 8 bpp grayscale */
DmtxPack8bppK = 300,
/* 16 bpp formats */
DmtxPack16bppRGB = 400,
DmtxPack16bppRGBX,
DmtxPack16bppXRGB,
DmtxPack16bppBGR,
DmtxPack16bppBGRX,
DmtxPack16bppXBGR,
DmtxPack16bppYCbCr,
/* 24 bpp formats */
DmtxPack24bppRGB = 500,
DmtxPack24bppBGR,
DmtxPack24bppYCbCr,
/* 32 bpp formats */
DmtxPack32bppRGBX = 600,
DmtxPack32bppXRGB,
DmtxPack32bppBGRX,
DmtxPack32bppXBGR,
DmtxPack32bppCMYK
} DmtxPackOrder;
typedef enum {
DmtxFlipNone = 0x00,
DmtxFlipX = 0x01 << 0,
DmtxFlipY = 0x01 << 1
} DmtxFlip;
typedef double DmtxMatrix3[3][3];
/**
* @struct DmtxPixelLoc
* @brief DmtxPixelLoc
*/
typedef struct DmtxPixelLoc_struct {
int X;
int Y;
} DmtxPixelLoc;
/**
* @struct DmtxVector2
* @brief DmtxVector2
*/
typedef struct DmtxVector2_struct {
double X;
double Y;
} DmtxVector2;
/**
* @struct DmtxRay2
* @brief DmtxRay2
*/
typedef struct DmtxRay2_struct {
double tMin;
double tMax;
DmtxVector2 p;
DmtxVector2 v;
} DmtxRay2;
typedef unsigned char DmtxByte;
/**
* @struct DmtxByteList
* @brief DmtxByteList
* Use signed int for length fields instead of size_t to play nicely with RS
* arithmetic
*/
typedef struct DmtxByteList_struct DmtxByteList;
struct DmtxByteList_struct
{
int length;
int capacity;
DmtxByte *b;
};
typedef struct DmtxEncodeStream_struct DmtxEncodeStream;
struct DmtxEncodeStream_struct
{
int currentScheme; /* Current encodation scheme */
int inputNext; /* Index of next unprocessed input word in queue */
int outputChainValueCount; /* Count of output values pushed within current scheme chain */
int outputChainWordCount; /* Count of output words pushed within current scheme chain */
char *reason; /* Reason for status */
int sizeIdx; /* Symbol size of completed stream */
DmtxStatus status;
DmtxByteList *input;
DmtxByteList *output;
};
/**
* @struct DmtxImage
* @brief 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;
/**
* @struct DmtxPointFlow
* @brief DmtxPointFlow
*/
typedef struct DmtxPointFlow_struct {
int plane;
int arrive;
int depart;
int mag;
DmtxPixelLoc loc;
} DmtxPointFlow;
/**
* @struct DmtxBestLine
* @brief DmtxBestLine
*/
typedef struct DmtxBestLine_struct {
int angle;
int hOffset;
int mag;