dmtx.h | dmtx.h | |||
---|---|---|---|---|
/* | /* | |||
libdmtx - Data Matrix Encoding/Decoding Library | libdmtx - Data Matrix Encoding/Decoding Library | |||
Copyright (C) 2005 Mike Laughton | Copyright (C) 2006 Mike Laughton | |||
This library is free software; you can redistribute it and/or | This library is free software; you can redistribute it and/or | |||
modify it under the terms of the GNU Lesser General Public | modify it under the terms of the GNU Lesser General Public | |||
License as published by the Free Software Foundation; either | License as published by the Free Software Foundation; either | |||
version 2.1 of the License, or (at your option) any later version. | version 2.1 of the License, or (at your option) any later version. | |||
This library is distributed in the hope that it will be useful, | This library is distributed in the hope that it will be useful, | |||
but WITHOUT ANY WARRANTY; without even the implied warranty of | but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
Lesser General Public License for more details. | Lesser General Public License for more details. | |||
skipping to change at line 30 | skipping to change at line 30 | |||
*/ | */ | |||
#include <stdlib.h> | #include <stdlib.h> | |||
#include <stdio.h> | #include <stdio.h> | |||
#include <string.h> | #include <string.h> | |||
#include <math.h> | #include <math.h> | |||
#ifndef __DMTX_H__ | #ifndef __DMTX_H__ | |||
#define __DMTX_H__ | #define __DMTX_H__ | |||
#define DMTX_ALMOST_ZERO 0.000001 | #define DMTX_ALMOST_ZERO 0.000001 | |||
#define DMTX_FALSE 0 | #define DMTX_FALSE 0 | |||
#define DMTX_TRUE 1 | #define DMTX_TRUE 1 | |||
#define DMTX_FAILURE 0 | #define DMTX_FAILURE 0 | |||
#define DMTX_SUCCESS 1 | #define DMTX_SUCCESS 1 | |||
#define DMTX_DISPLAY_SQUARE 1 | #define DMTX_DISPLAY_SQUARE 1 | |||
#define DMTX_DISPLAY_POINT 2 | #define DMTX_DISPLAY_POINT 2 | |||
#define DMTX_DISPLAY_CIRCLE 3 | #define DMTX_DISPLAY_CIRCLE 3 | |||
#define DEBUGLINE printf("made it here\n"); fflush(NULL); | ||||
#define DMTX_MIN_JUMP_COUNT 2 | #define DMTX_MIN_JUMP_COUNT 2 | |||
#define DMTX_MIN_STEP_RANGE 10 | #define DMTX_MIN_STEP_RANGE 10 | |||
#define DMTX_MIN_JUMP_DISTANCE 10.0 // Minimum color difference for step r egion | #define DMTX_MIN_JUMP_DISTANCE 10.0 // Minimum color difference for step r egion | |||
#define DMTX_MAX_COLOR_DEVN 20.0 // Maximum deviation from color gradie nt | #define DMTX_MAX_COLOR_DEVN 20.0 // Maximum deviation from color gradie nt | |||
#define DMTX_FOLLOW_STEPS 5 | #define DMTX_FOLLOW_STEPS 5 | |||
#define DMTX_ENCODING_AUTO 1 | ||||
#define DMTX_ENCODING_ASCII 2 | ||||
#define DMTX_ENCODING_C40 3 | ||||
#define DMTX_ENCODING_TEXT 4 | ||||
#define DMTX_ENCODING_BASE256 5 | ||||
#define DMTX_MODULE_OFF 0x00 | ||||
#define DMTX_MODULE_ON 0x01 | ||||
#define DMTX_MODULE_ASSIGNED 0x02 | ||||
#define DMTX_MODULE_VISITED 0x04 | ||||
/* IMPORTANT: The DmtxDirection enum defines values in a way that facilitat es | /* IMPORTANT: The DmtxDirection enum defines values in a way that facilitat es | |||
turning left or right (x<<1 x>>1). Do not alter this enum unless you | turning left or right (x<<1 x>>1). Do not alter this enum unless you | |||
understand the full implications of doing so. */ | understand the full implications of doing so. */ | |||
typedef enum { | typedef enum { | |||
DmtxDirNone = 0x00, | DmtxDirNone = 0x00, | |||
DmtxDirUp = 0x01 << 0, | DmtxDirUp = 0x01 << 0, | |||
DmtxDirLeft = 0x01 << 1, | DmtxDirLeft = 0x01 << 1, | |||
DmtxDirDown = 0x01 << 2, | DmtxDirDown = 0x01 << 2, | |||
DmtxDirRight = 0x01 << 3, | DmtxDirRight = 0x01 << 3, | |||
DmtxDirHorizontal = DmtxDirLeft | DmtxDirRight, | DmtxDirHorizontal = DmtxDirLeft | DmtxDirRight, | |||
DmtxDirVertical = DmtxDirUp | DmtxDirDown, | DmtxDirVertical = DmtxDirUp | DmtxDirDown, | |||
DmtxDirRightUp = DmtxDirRight | DmtxDirUp, | DmtxDirRightUp = DmtxDirRight | DmtxDirUp, | |||
DmtxDirLeftDown = DmtxDirLeft | DmtxDirDown | DmtxDirLeftDown = DmtxDirLeft | DmtxDirDown | |||
} DmtxDirection; | } DmtxDirection; | |||
typedef enum { | ||||
DmtxSingleScanOnly = 0x00 | ||||
} DmtxOptions; | ||||
typedef float DmtxMatrix3[3][3]; | typedef float DmtxMatrix3[3][3]; | |||
typedef struct { | typedef struct { | |||
DmtxMatrix3 m; | DmtxMatrix3 m; | |||
} DmtxMatrix3Struct; | } DmtxMatrix3Struct; | |||
typedef struct { | typedef struct { | |||
float X; | float X; | |||
float Y; | float Y; | |||
float Z; | float Z; | |||
skipping to change at line 98 | skipping to change at line 111 | |||
char isDefined; | char isDefined; | |||
float tMin, tMax; | float tMin, tMax; | |||
DmtxVector2 p; | DmtxVector2 p; | |||
DmtxVector2 v; | DmtxVector2 v; | |||
} DmtxRay2; | } DmtxRay2; | |||
typedef struct { | typedef struct { | |||
char isDefined; | char isDefined; | |||
float tMin, tMax, tMid; | float tMin, tMax, tMid; | |||
DmtxRay3 ray; | DmtxRay3 ray; | |||
DmtxVector3 color, colorPrev; | DmtxVector3 color, colorPrev; // XXX maybe these aren't appropriate vari ables for a gradient? | |||
} DmtxGradient; | } DmtxGradient; | |||
typedef struct { | typedef struct { | |||
unsigned char R; | unsigned char R; | |||
unsigned char G; | unsigned char G; | |||
unsigned char B; | unsigned char B; | |||
} DmtxPixel; | } DmtxPixel; | |||
typedef struct { | typedef struct { | |||
unsigned int width; | unsigned int width; | |||
unsigned int height; | unsigned int height; | |||
DmtxPixel *pxl; | DmtxPixel *pxl; | |||
} DmtxImage; | } DmtxImage; | |||
typedef struct { | typedef struct { | |||
char *array; | DmtxDirection dir; | |||
int dataRows, dataCols; | int lineNbr; | |||
} DmtxPattern; | int firstPos; | |||
int lastPos; | ||||
typedef struct { | ||||
int line; | ||||
int start; | ||||
int distance; | ||||
DmtxDirection direction; | ||||
DmtxImage *image; | ||||
} DmtxScanRange; | } DmtxScanRange; | |||
typedef struct { | typedef struct { | |||
int jumpCount; | DmtxScanRange range; | |||
int anchor1, anchor2, lastJump; | ||||
DmtxGradient gradient; | DmtxGradient gradient; | |||
} DmtxStepScan; | int jumpCount; | |||
int anchor1; | ||||
int anchor2; | ||||
int lastJump; | ||||
} DmtxJumpRegion; | ||||
typedef struct { | ||||
DmtxScanRange range; | ||||
DmtxJumpRegion region; | ||||
} DmtxJumpScan; | ||||
typedef struct { | typedef struct { | |||
int offset; | int offset; | |||
float t; | float t; | |||
DmtxVector3 color; | DmtxVector3 color; | |||
} DmtxCrossPoint; | } DmtxEdge; | |||
typedef struct { | typedef struct { | |||
DmtxCrossPoint point, pointNext; | DmtxScanRange range; | |||
float subPixelOffset; | DmtxEdge edge; | |||
} DmtxCrossScan; | DmtxEdge edgeNext; | |||
float subPixelOffset; // XXX implement it this way first, then | ||||
refactor to offsetFloat (offset + subP..) | ||||
} DmtxEdgeScan; | ||||
typedef struct { | ||||
float tx, ty; | ||||
float shx, shy; | ||||
float scx, scy; | ||||
float bx0, bx1; | ||||
float by0, by1; | ||||
} DmtxChain; | ||||
typedef struct { | ||||
DmtxGradient gradient; | ||||
DmtxChain chain; | ||||
DmtxMatrix3 raw2fit; | ||||
DmtxMatrix3 fit2raw; | ||||
DmtxVector2 calibTopP0; | ||||
DmtxVector2 calibTopP1; | ||||
int sizeIdx; | ||||
int dataRows; | ||||
int dataCols; | ||||
int arraySize; | ||||
int codeSize; | ||||
int dataSize; | ||||
int padSize; | ||||
int outputSize; | ||||
int outputIdx; | ||||
unsigned char *array; | ||||
unsigned char *code; | ||||
unsigned char *error; | ||||
unsigned char *output; | ||||
} DmtxMatrixRegion; | ||||
typedef struct { | typedef struct { | |||
int slope; | int slope; | |||
int turnCount; | int turnCount; | |||
int paraOffset; | int paraOffset; | |||
float perpOffset; | float perpOffset; | |||
float tMin, tMid, tMax; | float tMin, tMid, tMax; | |||
DmtxRay3 ray; | DmtxRay3 ray; | |||
DmtxRay2 line0, line1; | DmtxRay2 line0, line1; | |||
DmtxDirection direction; | DmtxDirection dir; | |||
} DmtxFollower; | } DmtxEdgeFollower; | |||
typedef struct { | typedef struct { | |||
DmtxVector2 p0, p1, p2; | DmtxVector2 p0, p1, p2; | |||
DmtxMatrix3 m, mInv; | ||||
} DmtxFinderBar; | } DmtxFinderBar; | |||
typedef struct { | ||||
float tx, ty; | ||||
float shx, shy; | ||||
float scx, scy; | ||||
float bx0, bx1; | ||||
float by0, by1; | ||||
} DmtxChain; | ||||
typedef struct _DmtxInfo DmtxInfo; | typedef struct _DmtxInfo DmtxInfo; | |||
struct _DmtxInfo { | struct _DmtxInfo { | |||
DmtxMatrix3 m; | int option; | |||
DmtxMatrix3 mInv; | int matrixCount; | |||
DmtxMatrixRegion matrix[16]; | ||||
DmtxImage image; | DmtxImage image; | |||
DmtxGradient gradient; | void (* stepScanCallback)(DmtxInfo *, DmtxScanRange *, DmtxJumpScan *); | |||
DmtxVector2 calibTopP0; | void (* crossScanCallback)(DmtxScanRange *, DmtxGradient *, DmtxEdgeScan | |||
DmtxVector2 calibTopP1; | *); | |||
int matrixSize; | void (* followScanCallback)(DmtxEdgeFollower *); | |||
int sizeIdx; | ||||
void (* stepScanCallback)(DmtxScanRange *, DmtxStepScan *); | ||||
void (* crossScanCallback)(DmtxScanRange *, DmtxGradient *, DmtxCrossSca | ||||
n *); | ||||
void (* followScanCallback)(DmtxFollower *); | ||||
void (* finderBarCallback)(DmtxRay2 *); | void (* finderBarCallback)(DmtxRay2 *); | |||
void (* buildMatrixCallback2)(DmtxFinderBar *); | void (* buildMatrixCallback2)(DmtxFinderBar *, DmtxMatrixRegion *); | |||
void (* buildMatrixCallback3)(DmtxMatrix3); | void (* buildMatrixCallback3)(DmtxMatrix3); | |||
void (* buildMatrixCallback4)(DmtxMatrix3); | void (* buildMatrixCallback4)(DmtxMatrix3); | |||
void (* plotPointCallback)(DmtxVector2, int, int, int); | void (* plotPointCallback)(DmtxVector2, int, int, int); | |||
void (* xfrmPlotPointCallback)(DmtxVector2, DmtxMatrix3, int, int); | void (* xfrmPlotPointCallback)(DmtxVector2, DmtxMatrix3, int, int); | |||
void (* finalCallback)(DmtxMatrix3, DmtxMatrix3); | void (* finalCallback)(DmtxMatrixRegion *); | |||
void (* plotModuleCallback)(DmtxInfo *, int, int, DmtxVector3); | void (* plotModuleCallback)(DmtxInfo *, DmtxMatrixRegion *, int, int, Dm | |||
txVector3); | ||||
}; | }; | |||
/* encoding structs ******************************************************* | ||||
**/ | ||||
typedef struct { | ||||
int option; | ||||
int scheme; | ||||
int moduleSize; | ||||
int marginSize; | ||||
DmtxImage image; | ||||
DmtxMatrix3 xfrm; | ||||
DmtxMatrixRegion matrix; | ||||
} DmtxEncode; | ||||
/************************************************************************** | ||||
**/ | ||||
DmtxVector3 *dmtxVector3AddTo(DmtxVector3 *v1, DmtxVector3 *v2); | DmtxVector3 *dmtxVector3AddTo(DmtxVector3 *v1, DmtxVector3 *v2); | |||
DmtxVector3 *dmtxVector3Add(DmtxVector3 *vOut, DmtxVector3 *v1, DmtxVector3 *v2); | DmtxVector3 *dmtxVector3Add(DmtxVector3 *vOut, DmtxVector3 *v1, DmtxVector3 *v2); | |||
DmtxVector3 *dmtxVector3SubFrom(DmtxVector3 *v1, DmtxVector3 *v2); | DmtxVector3 *dmtxVector3SubFrom(DmtxVector3 *v1, DmtxVector3 *v2); | |||
DmtxVector3 *dmtxVector3Sub(DmtxVector3 *vOut, DmtxVector3 *v1, DmtxVector3 *v2); | DmtxVector3 *dmtxVector3Sub(DmtxVector3 *vOut, DmtxVector3 *v1, DmtxVector3 *v2); | |||
DmtxVector3 *dmtxVector3ScaleBy(DmtxVector3 *v, float s); | DmtxVector3 *dmtxVector3ScaleBy(DmtxVector3 *v, float s); | |||
DmtxVector3 *dmtxVector3Scale(DmtxVector3 *vOut, DmtxVector3 *v, float s); | DmtxVector3 *dmtxVector3Scale(DmtxVector3 *vOut, DmtxVector3 *v, float s); | |||
DmtxVector3 *dmtxVector3Cross(DmtxVector3 *vOut, DmtxVector3 *v1, DmtxVecto r3 *v2); | DmtxVector3 *dmtxVector3Cross(DmtxVector3 *vOut, DmtxVector3 *v1, DmtxVecto r3 *v2); | |||
float dmtxVector3Norm(DmtxVector3 *v); | float dmtxVector3Norm(DmtxVector3 *v); | |||
float dmtxVector3Dot(DmtxVector3 *v1, DmtxVector3 *v2); | float dmtxVector3Dot(DmtxVector3 *v1, DmtxVector3 *v2); | |||
float dmtxVector3Mag(DmtxVector3 *v); | float dmtxVector3Mag(DmtxVector3 *v); | |||
skipping to change at line 235 | skipping to change at line 283 | |||
void dmtxMatrix3Rotate(DmtxMatrix3 m, float angle); | void dmtxMatrix3Rotate(DmtxMatrix3 m, float angle); | |||
void dmtxMatrix3Scale(DmtxMatrix3 m, float sx, float sy); | void dmtxMatrix3Scale(DmtxMatrix3 m, float sx, float sy); | |||
void dmtxMatrix3Shear(DmtxMatrix3 m, float shx, float shy); | void dmtxMatrix3Shear(DmtxMatrix3 m, float shx, float shy); | |||
DmtxVector2 *dmtxMatrix3VMultiplyBy(DmtxVector2 *v, DmtxMatrix3 m); | DmtxVector2 *dmtxMatrix3VMultiplyBy(DmtxVector2 *v, DmtxMatrix3 m); | |||
DmtxVector2 *dmtxMatrix3VMultiply(DmtxVector2 *vOut, DmtxVector2 *vIn, Dmtx Matrix3 m); | DmtxVector2 *dmtxMatrix3VMultiply(DmtxVector2 *vOut, DmtxVector2 *vIn, Dmtx Matrix3 m); | |||
void dmtxMatrix3Multiply(DmtxMatrix3 mOut, DmtxMatrix3 m0, DmtxMatrix3 m1); | void dmtxMatrix3Multiply(DmtxMatrix3 mOut, DmtxMatrix3 m0, DmtxMatrix3 m1); | |||
void dmtxMatrix3MultiplyBy(DmtxMatrix3 m0, DmtxMatrix3 m1); | void dmtxMatrix3MultiplyBy(DmtxMatrix3 m0, DmtxMatrix3 m1); | |||
void dmtxMatrix3LineSkewTop(DmtxMatrix3 m, float b0, float b1, float sz); | void dmtxMatrix3LineSkewTop(DmtxMatrix3 m, float b0, float b1, float sz); | |||
void dmtxMatrix3LineSkewSide(DmtxMatrix3 m, float b0, float b1, float sz); | void dmtxMatrix3LineSkewSide(DmtxMatrix3 m, float b0, float b1, float sz); | |||
void dmtxMatrix3Print(DmtxMatrix3 m); | void dmtxMatrix3Print(DmtxMatrix3 m); | |||
void dmtxMatrix3ChainXfrm(DmtxMatrix3 m, DmtxChain *chain); | ||||
void dmtxMatrix3ChainInvXfrm(DmtxMatrix3 m, DmtxChain *chain); | ||||
void dmtxColorFromImage(DmtxVector3 *color, DmtxImage *image, int x, int y) ; | void dmtxColorFromImage(DmtxVector3 *color, DmtxImage *image, int x, int y) ; | |||
void dmtxColorFromImage2(DmtxVector3 *color, DmtxImage *image, DmtxVector2 p); | void dmtxColorFromImage2(DmtxVector3 *color, DmtxImage *image, DmtxVector2 p); | |||
void dmtxColorFromPixel(DmtxVector3 *color, DmtxPixel *pxl); | void dmtxColorFromPixel(DmtxVector3 *color, DmtxPixel *pxl); | |||
void dmtxPixelFromColor(DmtxPixel *pxl, DmtxVector3 *color); | void dmtxPixelFromColor(DmtxPixel *pxl, DmtxVector3 *color); | |||
DmtxVector3 dmtxColorAlongRay3(DmtxRay3 *ray, float dist); | DmtxVector3 dmtxColorAlongRay3(DmtxRay3 *ray, float dist); | |||
int dmtxImageInit(DmtxImage *image); | int dmtxImageInit(DmtxImage *image); | |||
int dmtxImageDeInit(DmtxImage *image); | int dmtxImageDeInit(DmtxImage *image); | |||
int dmtxImageGetWidth(DmtxImage *image); | int dmtxImageGetWidth(DmtxImage *image); | |||
int dmtxImageGetHeight(DmtxImage *image); | int dmtxImageGetHeight(DmtxImage *image); | |||
int dmtxImageGetOffset(DmtxImage *image, DmtxDirection dir, int lineNbr, in | ||||
t offset); | ||||
int dmtxImageLoadPng(DmtxImage *image, char *filename); | ||||
void dmtxScanLine(DmtxInfo *info, int line, DmtxDirection direction); | int dmtxScanLine(DmtxInfo *info, DmtxDirection dir, int lineNbr); | |||
void dmtxMatrixRegionDeInit(DmtxMatrixRegion *matrixRegion); | ||||
DmtxInfo *dmtxCreateInfoStruct(void); | int dmtxPatternReadEcc200Modules(DmtxMatrixRegion *matrixRegion); | |||
void dmtxDestroyInfoStruct(DmtxInfo **info); | int dmtxGfSum(int a, int b); | |||
void dmtxSetStepScanCallback(DmtxInfo *info, void (* func)(DmtxScanRange *, | int dmtxGfProduct(int a, int b); | |||
DmtxStepScan *)); | ||||
void dmtxSetCrossScanCallback(DmtxInfo *info, void (* func)(DmtxScanRange * | DmtxInfo *dmtxInfoStructCreate(void); | |||
, DmtxGradient *, DmtxCrossScan *)); | void dmtxInfoStructDestroy(DmtxInfo **info); | |||
void dmtxSetFollowScanCallback(DmtxInfo *info, void (* func)(DmtxFollower * | DmtxMatrixRegion *dmtxInfoGetMatrix(DmtxInfo *info, int index); | |||
)); | int dmtxInfoGetMatrixCount(DmtxInfo *info); | |||
void dmtxScanStartNew(DmtxInfo *info); | ||||
void dmtxSetStepScanCallback(DmtxInfo *info, void (* func)(DmtxInfo *, Dmtx | ||||
ScanRange *, DmtxJumpScan *)); | ||||
void dmtxSetCrossScanCallback(DmtxInfo *info, void (* func)(DmtxScanRange * | ||||
, DmtxGradient *, DmtxEdgeScan *)); | ||||
void dmtxSetFollowScanCallback(DmtxInfo *info, void (* func)(DmtxEdgeFollow | ||||
er *)); | ||||
void dmtxSetFinderBarCallback(DmtxInfo *info, void (* func)(DmtxRay2 *)); | void dmtxSetFinderBarCallback(DmtxInfo *info, void (* func)(DmtxRay2 *)); | |||
void dmtxSetBuildMatrixCallback2(DmtxInfo *info, void (* func)(DmtxFinderBa r *)); | void dmtxSetBuildMatrixCallback2(DmtxInfo *info, void (* func)(DmtxFinderBa r *, DmtxMatrixRegion *)); | |||
void dmtxSetBuildMatrixCallback3(DmtxInfo *info, void (* func)(DmtxMatrix3) ); | void dmtxSetBuildMatrixCallback3(DmtxInfo *info, void (* func)(DmtxMatrix3) ); | |||
void dmtxSetBuildMatrixCallback4(DmtxInfo *info, void (* func)(DmtxMatrix3) ); | void dmtxSetBuildMatrixCallback4(DmtxInfo *info, void (* func)(DmtxMatrix3) ); | |||
void dmtxSetPlotPointCallback(DmtxInfo *info, void (* func)(DmtxVector2, in t, int, int)); | void dmtxSetPlotPointCallback(DmtxInfo *info, void (* func)(DmtxVector2, in t, int, int)); | |||
void dmtxSetXfrmPlotPointCallback(DmtxInfo *info, void (* func)(DmtxVector2 , DmtxMatrix3, int, int)); | void dmtxSetXfrmPlotPointCallback(DmtxInfo *info, void (* func)(DmtxVector2 , DmtxMatrix3, int, int)); | |||
void dmtxSetFinalCallback(DmtxInfo *info, void (* func)(DmtxMatrix3, DmtxMa | void dmtxSetFinalCallback(DmtxInfo *info, void (* func)(DmtxMatrixRegion *) | |||
trix3)); | ); | |||
void dmtxSetPlotModuleCallback(DmtxInfo *info, void (* func)(DmtxInfo *, in | void dmtxSetPlotModuleCallback(DmtxInfo *info, void (* func)(DmtxInfo *, Dm | |||
t, int, DmtxVector3)); | txMatrixRegion *, int, int, DmtxVector3)); | |||
/* encoding functions ***************************************************** | ||||
**/ | ||||
DmtxEncode *dmtxEncodeCreate(void); | ||||
void dmtxEncodeDestroy(DmtxEncode **encode); | ||||
int dmtxEncodeData(DmtxEncode *encode, unsigned char *inputString); | ||||
/************************************************************************** | ||||
**/ | ||||
#endif | #endif | |||
End of changes. 26 change blocks. | ||||
68 lines changed or deleted | 138 lines changed or added | |||