17#ifndef __DMTXSTATIC_H__
18#define __DMTXSTATIC_H__
25#define DmtxAlmostZero 0.000001
26#define DmtxAlmostInfinity -1
28#define DmtxValueC40Latch 230
29#define DmtxValueTextLatch 239
30#define DmtxValueX12Latch 238
31#define DmtxValueEdifactLatch 240
32#define DmtxValueBase256Latch 231
34#define DmtxValueCTXUnlatch 254
35#define DmtxValueEdifactUnlatch 31
37#define DmtxValueAsciiPad 129
38#define DmtxValueAsciiUpperShift 235
39#define DmtxValueCTXShift1 0
40#define DmtxValueCTXShift2 1
41#define DmtxValueCTXShift3 2
42#define DmtxValueFNC1 232
43#define DmtxValueStructuredAppend 233
44#define DmtxValueReaderProgramming 234
45#define DmtxValue05Macro 236
46#define DmtxValue06Macro 237
47#define DmtxValueECI 241
49#define DmtxC40TextBasicSet 0
50#define DmtxC40TextShift1 1
51#define DmtxC40TextShift2 2
52#define DmtxC40TextShift3 3
54#define DmtxUnlatchExplicit 0
55#define DmtxUnlatchImplicit 1
57#define DmtxChannelValid 0x00
58#define DmtxChannelUnsupportedChar 0x01 << 0
59#define DmtxChannelCannotUnlatch 0x01 << 1
62#define min(X, Y) (((X) < (Y)) ? (X) : (Y))
65#define max(X, Y) (((X) > (Y)) ? (X) : (Y))
68#define ISDIGIT(n) (n > 47 && n < 58)
73 if (stream->currentScheme != (s)) { \
74 streamMarkFatal(stream, DmtxErrorUnexpectedScheme); \
82 if (stream->status != DmtxStatusEncoding) { \
90 if (sizeIdx == DmtxUndefined) { \
91 streamMarkInvalid(stream, DmtxErrorUnknown); \
96#define DmtxAssert(expr) \
101 dmtxLogError("%s\n", #expr); \
248 unsigned char *codeword,
int moduleOnColor);
249static void patternShapeSpecial1(
unsigned char *modules,
int mappingRows,
int mappingCols,
unsigned char *codeword,
251static void patternShapeSpecial2(
unsigned char *modules,
int mappingRows,
int mappingCols,
unsigned char *codeword,
253static void patternShapeSpecial3(
unsigned char *modules,
int mappingRows,
int mappingCols,
unsigned char *codeword,
255static void patternShapeSpecial4(
unsigned char *modules,
int mappingRows,
int mappingCols,
unsigned char *codeword,
257static void placeModule(
unsigned char *modules,
int mappingRows,
int mappingCols,
int row,
int col,
258 unsigned char *codeword,
int mask,
int moduleOnColor);
311 int ctxValueCount,
int sizeIdxRequest);
369 256, 256, 256, 256, 255, 255, 255, 254, 254, 253, 252, 251, 250, 249, 248, 247, 246, 245,
370 243, 242, 241, 239, 237, 236, 234, 232, 230, 228, 226, 224, 222, 219, 217, 215, 212, 210,
371 207, 204, 202, 199, 196, 193, 190, 187, 184, 181, 178, 175, 171, 168, 165, 161, 158, 154,
372 150, 147, 143, 139, 136, 132, 128, 124, 120, 116, 112, 108, 104, 100, 96, 92, 88, 83,
373 79, 75, 71, 66, 62, 58, 53, 49, 44, 40, 36, 31, 27, 22, 18, 13, 9, 4,
374 0, -4, -9, -13, -18, -22, -27, -31, -36, -40, -44, -49, -53, -58, -62, -66, -71, -75,
375 -79, -83, -88, -92, -96, -100, -104, -108, -112, -116, -120, -124, -128, -132, -136, -139, -143, -147,
376 -150, -154, -158, -161, -165, -168, -171, -175, -178, -181, -184, -187, -190, -193, -196, -199, -202, -204,
377 -207, -210, -212, -215, -217, -219, -222, -224, -226, -228, -230, -232, -234, -236, -237, -239, -241, -242,
378 -243, -245, -246, -247, -248, -249, -250, -251, -252, -253, -254, -254, -255, -255, -255, -256, -256, -256};
380static int rHvY[] = {0, 4, 9, 13, 18, 22, 27, 31, 36, 40, 44, 49, 53, 58, 62, 66, 71, 75, 79, 83,
381 88, 92, 96, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 139, 143, 147, 150, 154, 158, 161,
382 165, 168, 171, 175, 178, 181, 184, 187, 190, 193, 196, 199, 202, 204, 207, 210, 212, 215, 217, 219,
383 222, 224, 226, 228, 230, 232, 234, 236, 237, 239, 241, 242, 243, 245, 246, 247, 248, 249, 250, 251,
384 252, 253, 254, 254, 255, 255, 255, 256, 256, 256, 256, 256, 256, 256, 255, 255, 255, 254, 254, 253,
385 252, 251, 250, 249, 248, 247, 246, 245, 243, 242, 241, 239, 237, 236, 234, 232, 230, 228, 226, 224,
386 222, 219, 217, 215, 212, 210, 207, 204, 202, 199, 196, 193, 190, 187, 184, 181, 178, 175, 171, 168,
387 165, 161, 158, 154, 150, 147, 143, 139, 136, 132, 128, 124, 120, 116, 112, 108, 104, 100, 96, 92,
388 88, 83, 79, 75, 71, 66, 62, 58, 53, 49, 44, 40, 36, 31, 27, 22, 18, 13, 9, 4};
407 "Unsupported character",
408 "Not on byte boundary",
409 "Illegal parameter value",
410 "Encountered empty list",
413 "Can't compact non-digits",
414 "Encountered unexpected scheme",
415 "Encountered incomplete value list"};
libdmtx - Data Matrix Encoding/Decoding Library Copyright 2008, 2009 Mike Laughton.
void(* DmtxCallbackBuildMatrixRegion)(DmtxRegion *region)
enum DmtxDirection_enum DmtxDirection
enum DmtxScheme_enum DmtxScheme
void(* DmtxCallbackBuildMatrix)(DmtxMatrix3 matrix)
void(* DmtxCallbackXfrmPlotPoint)(DmtxVector2 point, DmtxMatrix3 xfrm, int paneNbr, int dispType)
void(* DmtxCallbackFinal)(DmtxDecode *decode, DmtxRegion *region)
void(* DmtxCallbackPlotModule)(DmtxDecode *info, DmtxRegion *region, int row, int col, float colorHue)
void(* DmtxCallbackPlotPoint)(DmtxPixelLoc loc, float colorHue, int paneNbr, int dispType)
static int encodeSingleScheme(DmtxByteList *input, DmtxByteList *output, int sizeIdxRequest, DmtxScheme scheme, int fnc1)
static int encodeOptimizeBest(DmtxByteList *input, DmtxByteList *output, int sizeIdxRequest, int fnc1)
static DmtxBoolean validStateSwitch(int fromState, int targetState)
static DmtxScanGrid initScanGrid(DmtxDecode *dec)
static DmtxByte streamInputAdvanceNext(DmtxEncodeStream *stream)
static void encodeNextChunk(DmtxEncodeStream *stream, int scheme, int subScheme, int sizeIdxRequest)
static unsigned char * decodeSchemeC40Text(DmtxMessage *msg, unsigned char *ptr, unsigned char *dataEnd, DmtxScheme encScheme)
static void completeIfDoneAscii(DmtxEncodeStream *stream, int sizeIdxRequest)
static void shiftValueListBy3(DmtxByteList *list, DmtxPassFail *passFail)
static DmtxPassFail matrixRegionOrientation(DmtxDecode *dec, DmtxRegion *reg, DmtxPointFlow flowBegin)
static void encodeNextChunkBase256(DmtxEncodeStream *stream)
static void appendValueBase256(DmtxEncodeStream *stream, DmtxByte value)
static void streamOutputChainAppend(DmtxEncodeStream *stream, DmtxByte value)
static unsigned char * decodeSchemeAscii(DmtxMessage *msg, unsigned char *ptr, unsigned char *dataEnd)
static void updateBase256ChainHeader(DmtxEncodeStream *stream, int perfectSizeIdx)
static DmtxPassFail rsDecode(unsigned char *code, int sizeIdx, int fix)
struct DmtxLogEvent_struct DmtxLogEvent
static void completePartialX12(DmtxEncodeStream *stream, DmtxByteList *valueList, int sizeIdxRequest)
static DmtxPointFlow findStrongestNeighbor(DmtxDecode *dec, DmtxPointFlow center, int sign)
static void advanceEdifact(DmtxEncodeStream *streamNext, DmtxEncodeStream *streamList, int state, int inputNext, int sizeIdxRequest)
static void completeIfDoneCTX(DmtxEncodeStream *stream, int sizeIdxRequest)
static void streamOutputSet(DmtxEncodeStream *stream, int index, DmtxByte value)
static DmtxCallbackXfrmPlotPoint cbXfrmPlotPoint
@ DmtxErrorUnsupportedCharacter
@ DmtxErrorCantCompactNonDigits
@ DmtxErrorIncompleteValueList
@ DmtxErrorNotOnByteBoundary
@ DmtxErrorIllegalParameterValue
@ DmtxErrorMessageTooLarge
@ DmtxErrorUnexpectedScheme
static DmtxByte randomize253State(DmtxByte cwValue, int cwPosition)
static void completeIfDoneEdifact(DmtxEncodeStream *stream, int sizeIdxRequest)
static void padRemainingInAscii(DmtxEncodeStream *stream, int sizeIdx)
static DmtxEncodeStream streamInit(DmtxByteList *input, DmtxByteList *output)
static DmtxPassFail matrixRegionAlignCalibEdge(DmtxDecode *dec, DmtxRegion *reg, int edgeLoc)
static DmtxBoolean rsFindErrorLocatorPoly(DmtxByteList *elp, const DmtxByteList *syn, int errorWordCount, int maxCorrectable)
static DmtxPassFail matrixRegionFindSize(DmtxDecode *dec, DmtxRegion *reg)
static double rightAngleTrueness(DmtxVector2 c0, DmtxVector2 c1, DmtxVector2 c2, double angle)
static const DmtxPointFlow dmtxBlankEdge
static DmtxPointFlow matrixRegionSeekEdge(DmtxDecode *dec, DmtxPixelLoc loc0)
static void patternShapeStandard(unsigned char *modules, int mappingRows, int mappingCols, int row, int col, unsigned char *codeword, int moduleOnColor)
static int getBitsPerPixel(int pack)
static void printPattern(DmtxEncode *encode)
static const int dmtxPatternX[]
static DmtxBestLine findBestSolidLine2(DmtxDecode *dec, DmtxPixelLoc loc0, int tripSteps, int sign, int houghAvoid)
static void tallyModuleJumps(DmtxDecode *dec, DmtxRegion *reg, INOUT int tally[][24], int xOrigin, int yOrigin, int mapWidth, int mapHeight, DmtxDirection dir)
enum DmtxRange_enum DmtxRange
static void streamCopy(DmtxEncodeStream *dst, DmtxEncodeStream *src)
static void advanceAsciiCompact(DmtxEncodeStream *streamNext, DmtxEncodeStream *streamList, int state, int inputNext, int sizeIdxRequest)
enum DmtxEdge_enum DmtxEdge
static void base256OutputChainRemoveFirst(DmtxEncodeStream *stream)
static DmtxBestLine findBestSolidLine(DmtxDecode *dec, DmtxRegion *reg, int step0, int step1, int streamDir, int houghAvoid)
static int getEncodationScheme(unsigned char cw)
static DmtxPointFlow getPointFlow(DmtxDecode *dec, int colorPlane, DmtxPixelLoc loc, int arrive)
static DmtxPassFail bresLineStep(DmtxBresLine *line, int travel, int outward)
static void base256OutputChainInsertFirst(DmtxEncodeStream *stream)
static DmtxPassFail decodeDataStream(DmtxMessage *msg, int sizeIdx, unsigned char *outputStart)
Translate encoded data stream into final output.
static DmtxPassFail populateArrayFromMatrix(DmtxDecode *dec, DmtxRegion *reg, OUT DmtxMessage *msg)
static DmtxPassFail rsRepairErrors(DmtxByteList *rec, const DmtxByteList *loc, const DmtxByteList *elp, const DmtxByteList *syn)
static DmtxFollow followSeek(DmtxDecode *dec, DmtxRegion *reg, int seek)
static void streamMarkInvalid(DmtxEncodeStream *stream, int reasonIdx)
void(* DmtxLogFn)(DmtxLogEvent *ev)
static int popGridLocation(DmtxScanGrid *grid, OUT DmtxPixelLoc *locPtr)
static void appendUnlatchCTX(DmtxEncodeStream *stream)
static void advanceCTX(DmtxEncodeStream *streamNext, DmtxEncodeStream *streamList, int state, int inputNext, int ctxValueCount, int sizeIdxRequest)
static void placeModule(unsigned char *modules, int mappingRows, int mappingCols, int row, int col, unsigned char *codeword, int mask, int moduleOnColor)
static DmtxByte streamInputPeekNext(DmtxEncodeStream *stream)
static char * dmtxErrorMessage[]
static void patternShapeSpecial3(unsigned char *modules, int mappingRows, int mappingCols, unsigned char *codeword, int moduleOnColor)
static DmtxBoolean rsComputeSyndromes(DmtxByteList *syn, const DmtxByteList *rec, int blockErrorWords)
static void encodeNextChunkAscii(DmtxEncodeStream *stream, int option)
static unsigned char * decodeSchemeX12(DmtxMessage *msg, unsigned char *ptr, unsigned char *dataEnd)
static DmtxBoolean partialX12ChunkRemains(DmtxEncodeStream *stream)
static void pushOutputWord(DmtxMessage *msg, int value)
static void streamInputAdvancePrev(DmtxEncodeStream *stream)
struct C40TextState_struct C40TextState
static DmtxPassFail trailBlazeContinuous(DmtxDecode *dec, DmtxRegion *reg, DmtxPointFlow flowBegin, int maxDiagonal)
static DmtxPassFail findTravelLimits(DmtxDecode *dec, DmtxRegion *reg, DmtxBestLine *line)
static DmtxFollow followStep2(DmtxDecode *dec, DmtxFollow followBeg, int sign)
static const int dmtxPatternY[]
static void appendValuesCTX(DmtxEncodeStream *stream, DmtxByteList *valueList)
static DmtxByte streamOutputChainRemoveLast(DmtxEncodeStream *stream)
static void encodeNextChunkCTX(DmtxEncodeStream *stream, int sizeIdxRequest)
static int findSymbolSize(int dataWords, int sizeIdxRequest)
static void setDerivedFields(DmtxScanGrid *grid)
static DmtxByteList encodeTmpRemainingInAscii(DmtxEncodeStream *stream, DmtxByte *storage, int capacity, DmtxPassFail *passFail)
static void completeIfDoneBase256(DmtxEncodeStream *stream, int sizeIdxRequest)
static void pushOutputMacroHeader(DmtxMessage *msg, int macroType)
static const int dmtxNeighborNone
enum DmtxEncodeOption_enum DmtxEncodeOption
static int getGridCoordinates(DmtxScanGrid *grid, OUT DmtxPixelLoc *locPtr)
static void pushCTXValues(DmtxByteList *valueList, DmtxByte inputValue, int targetScheme, DmtxPassFail *passFail, int fnc1)
static DmtxBoolean rsFindErrorLocations(DmtxByteList *loc, const DmtxByteList *elp)
struct DmtxBresLine_struct DmtxBresLine
static void streamMarkComplete(DmtxEncodeStream *stream, int sizeIdx)
static DmtxPassFail rsGenPoly(DmtxByteList *gen, int errorWordCount)
static void encodeChangeScheme(DmtxEncodeStream *stream, DmtxScheme targetScheme, int unlatchType)
static void patternShapeSpecial4(unsigned char *modules, int mappingRows, int mappingCols, unsigned char *codeword, int moduleOnColor)
static int getRemainingSymbolCapacity(int outputLength, int sizeIdx)
struct DmtxFollow_struct DmtxFollow
static void streamAdvanceFromBest(DmtxEncodeStream *streamNext, DmtxEncodeStream *streamList, int targeteState, int sizeIdxRequest)
static DmtxCallbackPlotModule cbPlotModule
static void encodeNextChunkEdifact(DmtxEncodeStream *stream)
static unsigned char unRandomize255State(unsigned char value, int idx)
static long distanceSquared(DmtxPixelLoc a, DmtxPixelLoc b)
static void completePartialC40Text(DmtxEncodeStream *stream, DmtxByteList *valueList, int sizeIdxRequest)
static void appendValueAscii(DmtxEncodeStream *stream, DmtxByte value)
static DmtxByte randomize255State(DmtxByte cwValue, int cwPosition)
static int readModuleColor(DmtxDecode *dec, DmtxRegion *reg, int symbolRow, int symbolCol, int sizeIdx, int colorPlane)
static DmtxFollow followSeekLoc(DmtxDecode *dec, DmtxPixelLoc loc)
static DmtxCallbackPlotPoint cbPlotPoint
static int trailClear(DmtxDecode *dec, DmtxRegion *reg, int clearMask)
static DmtxBresLine bresLineInit(DmtxPixelLoc loc0, DmtxPixelLoc loc1, DmtxPixelLoc locInside)
void(* DmtxLogLockFn)(DmtxBoolean lock, void *udata)
static DmtxCallbackBuildMatrix cbBuildMatrix
static void patternShapeSpecial2(unsigned char *modules, int mappingRows, int mappingCols, unsigned char *codeword, int moduleOnColor)
static int getScheme(int state)
static DmtxCallbackBuildMatrixRegion cbBuildMatrixRegion
static unsigned char * decodeSchemeEdifact(DmtxMessage *msg, unsigned char *ptr, unsigned char *dataEnd)
static DmtxBoolean isCTX(int scheme)
enum DmtxMaskBit_enum DmtxMaskBit
static int modulePlacementEcc200(INOUT unsigned char *modules, OUT unsigned char *codewords, int sizeIdx, int moduleOnColor)
static void streamMarkFatal(DmtxEncodeStream *stream, int reasonIdx)
static int countJumpTally(DmtxDecode *dec, DmtxRegion *reg, int xStart, int yStart, DmtxDirection dir)
static int encodeDataCodewords(DmtxByteList *input, DmtxByteList *output, int sizeIdxRequest, DmtxScheme scheme, int fnc1)
static DmtxCallbackFinal cbFinal
static int trailBlazeGapped(DmtxDecode *dec, DmtxRegion *reg, DmtxBresLine line, int streamDir)
static DmtxPassFail bresLineGetStep(DmtxBresLine line, DmtxPixelLoc target, int *travel, int *outward)
static DmtxPassFail rsEncode(DmtxMessage *message, int sizeIdx)
static void pushOutputMacroTrailer(DmtxMessage *msg)
static void appendValueEdifact(DmtxEncodeStream *stream, DmtxByte value)
static DmtxBoolean streamInputHasNext(DmtxEncodeStream *stream)
static DmtxFollow followStep(DmtxDecode *dec, DmtxRegion *reg, DmtxFollow followBeg, int sign)
static void patternShapeSpecial1(unsigned char *modules, int mappingRows, int mappingCols, unsigned char *codeword, int moduleOnColor)
static unsigned char * decodeSchemeBase256(DmtxMessage *msg, unsigned char *ptr, unsigned char *dataEnd)
static void pushOutputC40TextWord(DmtxMessage *msg, C40TextState *state, int value)
DmtxByteList Use signed int for length fields instead of size_t to play nicely with RS arithmetic.