26#define ISDIGIT(n) (n > 47 && n < 58)
72 if (enc == NULL || *enc == NULL) {
77 if ((*enc)->image != NULL && (*enc)->image->pxl != NULL) {
78 free((*enc)->image->pxl);
79 (*enc)->image->pxl = NULL;
110 enc->sizeIdxRequest = value;
118 enc->marginSize = value;
121 enc->moduleSize = value;
126 enc->pixelPacking = value;
129 enc->imageFlip = value;
132 enc->rowPadBytes = value;
150 return enc->marginSize;
152 return enc->moduleSize;
174 int width, height, bitsPerPixel;
180 input.length = inputSize;
186 sizeIdx =
encodeDataCodewords(&input, &output, enc->sizeIdxRequest, enc->scheme, enc->fnc1);
195 enc->region.sizeIdx = sizeIdx;
203 enc->message->padCount = 0;
204 memcpy(enc->message->code, output.b, output.length);
207 rsEncode(enc->message, enc->region.sizeIdx);
212 width = 2 * enc->marginSize + (enc->region.symbolCols * enc->moduleSize);
213 height = 2 * enc->marginSize + (enc->region.symbolRows * enc->moduleSize);
221 pxl = (
unsigned char *)malloc((width * bitsPerPixel / 8 + enc->rowPadBytes) * height);
223 perror(
"pixel malloc error");
228 if (enc->image == NULL) {
229 perror(
"image malloc error");
261 unsigned char *inputStringR, *inputStringG, *inputStringB;
263 int inputSizeR, inputSizeG, inputSizeB;
264 int sizeIdxAttempt, sizeIdxFirst, sizeIdxLast;
265 int row, col, mappingRows, mappingCols;
269 tmpInputSize = (inputSize + 2) / 3;
270 inputSizeR = tmpInputSize;
271 inputSizeG = tmpInputSize;
272 inputSizeB = inputSize - (inputSizeR + inputSizeG);
274 inputStringR = inputString;
275 inputStringG = inputStringR + inputSizeR;
276 inputStringB = inputStringG + inputSizeG;
290 sizeIdxLast = sizeIdxFirst;
293 encR = encG = encB = NULL;
296 for (sizeIdxAttempt = sizeIdxFirst; sizeIdxAttempt <= sizeIdxLast; sizeIdxAttempt++) {
307 *encR = *encG = *encB = *enc;
315 if (encR->region.sizeIdx != sizeIdxAttempt) {
321 if (encG->region.sizeIdx != sizeIdxAttempt) {
327 if (encB->region.sizeIdx != sizeIdxAttempt) {
335 if (encR == NULL || encG == NULL || encB == NULL) {
351 memset(enc->message->array, 0x00,
sizeof(
unsigned char) * enc->region.mappingRows * enc->region.mappingCols);
356 for (row = 0; row < mappingRows; row++) {
357 for (col = 0; col < mappingCols; col++) {
365 for (row = 0; row < mappingRows; row++) {
366 for (col = 0; col < mappingCols; col++) {
418 int symbolRow, symbolCol;
419 int pixelRow, pixelCol;
421 size_t rowSize, height;
427 txy = enc->marginSize;
428 sxy = 1.0 / enc->moduleSize;
441 memset(enc->image->pxl, 0xff, rowSize * height);
443 for (symbolRow = 0; symbolRow < enc->region.symbolRows; symbolRow++) {
444 for (symbolCol = 0; symbolCol < enc->region.symbolCols; symbolCol++) {
450 pixelCol = (int)(vOut.
x);
451 pixelRow = (int)(vOut.
y);
455 if (enc->image->bytesPerPixel == 1) {
456 for (i = pixelRow; i < pixelRow + enc->moduleSize; i++) {
457 for (j = pixelCol; j < pixelCol + enc->moduleSize; j++) {
463 for (i = pixelRow; i < pixelRow + enc->moduleSize; i++) {
464 for (j = pixelCol; j < pixelCol + enc->moduleSize; j++) {
libdmtx - Data Matrix Encoding/Decoding Library Copyright 2008, 2009 Mike Laughton.
DmtxPassFail dmtxMatrix3VMultiply(OUT DmtxVector2 *vOut, DmtxVector2 *vIn, DmtxMatrix3 m)
将向量与矩阵相乘
@ DmtxPropRowSizeBytes
每一行(包括填充)在内存中的总字节数
@ DmtxPropImageFlip
图像是否需要翻转,通常用于处理上下颠倒的图像 DmtxFlip
@ DmtxPropPixelPacking
图像格式类型,像素打包方式 DmtxPackOrder
@ DmtxPropRowPadBytes
每行像素在内存中的填充或对齐字节数
int dmtxGetSymbolAttribute(int attribute, int sizeIdx)
根据规格索引返回二维码规格各个参数
#define DmtxModuleAssigned
已分配
int dmtxSymbolModuleStatus(DmtxMessage *message, int sizeIdx, int symbolRow, int symbolCol)
receives symbol row and col and returns status DmtxModuleOn / !DmtxModuleOn (DmtxModuleOff) DmtxModul...
DmtxPassFail dmtxMessageDestroy(DmtxMessage **msg)
Free memory previously allocated for message.
DmtxPassFail dmtxImageSetProp(DmtxImage *img, int prop, int value)
设置图像属性
double DmtxMatrix3[3][3]
DmtxMatrix3 类型定义,表示一个3x3的双精度浮点数矩阵
void dmtxMatrix3Multiply(OUT DmtxMatrix3 mOut, DmtxMatrix3 m0, DmtxMatrix3 m1)
矩阵相乘
DmtxByteList dmtxByteListBuild(DmtxByte *storage, int capacity)
@ DmtxSymAttribSymbolRows
二维码码元总行数(包括L形框和点线)
@ DmtxSymAttribSymbolCols
二维码码元总列数(包括L形框和点线)
@ DmtxSymAttribMappingMatrixRows
二维码数据区码元总行数(不包括L形框和点线)
@ DmtxSymAttribMappingMatrixCols
二维码数据区码元总列数(不包括L形框和点线)
enum DmtxScheme_enum DmtxScheme
#define DmtxModuleOnBlue
蓝
DmtxPassFail dmtxImageDestroy(DmtxImage **img)
Free libdmtx image memory.
#define DmtxModuleOnRGB
OnRed | OnGreen | OnBlue.
void dmtxMatrix3Translate(OUT DmtxMatrix3 m, double tx, double ty)
生成平移变换矩阵
DmtxMessage * dmtxMessageCreate(int sizeIdx, int symbolFormat)
Allocate memory for message.
DmtxImage * dmtxImageCreate(unsigned char *pxl, int width, int height, int pack)
libdmtx stores image data as a large one-dimensional array of packed pixels, reading from the array w...
#define DmtxSymbolRectCount
长方形二维码种类个数
#define DmtxModuleVisited
已访问
void dmtxMatrix3Identity(OUT DmtxMatrix3 m)
生成单位变换矩阵
int dmtxImageGetProp(DmtxImage *img, int prop)
获取图像属性
#define DmtxSymbolSquareCount
正方形二维码种类个数
DmtxPassFail dmtxImageSetPixelValue(DmtxImage *img, int x, int y, int channel, int value)
设置指定坐标、通道的像素值
#define DmtxModuleOnGreen
绿
void dmtxMatrix3Scale(OUT DmtxMatrix3 m, double sx, double sy)
生成缩放变换矩阵
DmtxEncode * dmtxEncodeCreate(void)
Initialize encode struct with default values.
DmtxPassFail dmtxEncodeSetProp(DmtxEncode *enc, int prop, int value)
Set encoding behavior property.
DmtxPassFail dmtxEncodeDataMosaic(DmtxEncode *enc, int inputSize, unsigned char *inputString)
Convert message into Data Mosaic image.
static void printPattern(DmtxEncode *enc)
Write encoded message to image.
DmtxPassFail dmtxEncodeDestroy(DmtxEncode **enc)
Deinitialize encode struct.
static int encodeDataCodewords(DmtxByteList *input, DmtxByteList *output, int sizeIdxRequest, DmtxScheme scheme, int fnc1)
Convert input into message using specific encodation scheme.
int dmtxEncodeGetProp(DmtxEncode *enc, int prop)
Get encoding behavior property.
DmtxPassFail dmtxEncodeDataMatrix(DmtxEncode *enc, int inputSize, unsigned char *inputString)
Convert message into Data Matrix image.
static int modulePlacementEcc200(INOUT unsigned char *modules, OUT unsigned char *codewords, int sizeIdx, int moduleOnColor)
通过DataMatrix数据区的二进制矩阵,根据DataMatrix的排列规则,得到码字(codewords)
static DmtxPassFail rsEncode(DmtxMessage *message, int sizeIdx)
Encode xyz.
libdmtx - Data Matrix Encoding/Decoding Library Copyright 2008, 2009 Mike Laughton.
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 int getBitsPerPixel(int pack)
static int findSymbolSize(int dataWords, int sizeIdxRequest)
DmtxByteList Use signed int for length fields instead of size_t to play nicely with RS arithmetic.