libdmtx 0.7.8.7
libdmtx is a software library that enables programs to read and write Data Matrix barcodes of the modern ECC200 variety.
Loading...
Searching...
No Matches
dmtxmessage.c
Go to the documentation of this file.
1
17#include <assert.h>
18#include <stdio.h>
19#include <stdlib.h>
20
21#include "dmtx.h"
22#include "dmtxstatic.h"
23
30extern DmtxMessage *dmtxMessageCreate(int sizeIdx, int symbolFormat)
31{
32 DmtxMessage *message;
33 int mappingRows, mappingCols;
34
35 DmtxAssert(symbolFormat == DmtxFormatMatrix || symbolFormat == DmtxFormatMosaic);
36
39
40 message = (DmtxMessage *)calloc(1, sizeof(DmtxMessage));
41 if (message == NULL) {
42 return NULL;
43 }
44
45 message->arraySize = sizeof(unsigned char) * mappingRows * mappingCols;
46
47 message->array = (unsigned char *)calloc(1, message->arraySize);
48 if (message->array == NULL) {
49 perror("Calloc failed");
50 dmtxMessageDestroy(&message);
51 return NULL;
52 }
53
54 message->codeSize = sizeof(unsigned char) * dmtxGetSymbolAttribute(DmtxSymAttribSymbolDataWords, sizeIdx) +
56
57 if (symbolFormat == DmtxFormatMosaic) {
58 message->codeSize *= 3;
59 }
60
61 message->code = (unsigned char *)calloc(message->codeSize, sizeof(unsigned char));
62 if (message->code == NULL) {
63 perror("Calloc failed");
64 dmtxMessageDestroy(&message);
65 return NULL;
66 }
67
68 /* XXX not sure if this is the right place or even the right approach.
69 Trying to allocate memory for the decoded data stream and will
70 initially assume that decoded data will not be larger than 2x encoded data */
71 message->outputSize = sizeof(unsigned char) * message->codeSize * 10;
72 message->output = (unsigned char *)calloc(message->outputSize, sizeof(unsigned char));
73 if (message->output == NULL) {
74 perror("Calloc failed");
75 dmtxMessageDestroy(&message);
76 return NULL;
77 }
78
79 return message;
80}
81
88{
89 if (msg == NULL || *msg == NULL) {
90 return DmtxFail;
91 }
92
93 if ((*msg)->array != NULL) {
94 free((*msg)->array);
95 }
96
97 if ((*msg)->code != NULL) {
98 free((*msg)->code);
99 }
100
101 if ((*msg)->output != NULL) {
102 free((*msg)->output);
103 }
104
105 free(*msg);
106
107 *msg = NULL;
108
109 return DmtxPass;
110}
libdmtx - Data Matrix Encoding/Decoding Library Copyright 2008, 2009 Mike Laughton.
#define DmtxPassFail
Definition dmtx.h:42
#define DmtxFormatMosaic
Definition dmtx.h:51
int dmtxGetSymbolAttribute(int attribute, int sizeIdx)
根据规格索引返回二维码规格各个参数
Definition dmtxsymbol.c:45
@ DmtxSymAttribSymbolErrorWords
Definition dmtx.h:166
@ DmtxSymAttribSymbolDataWords
Definition dmtx.h:165
@ DmtxSymAttribMappingMatrixRows
二维码数据区码元总行数(不包括L形框和点线)
Definition dmtx.h:160
@ DmtxSymAttribMappingMatrixCols
二维码数据区码元总列数(不包括L形框和点线)
Definition dmtx.h:161
#define DmtxPass
Definition dmtx.h:43
#define DmtxFormatMatrix
Definition dmtx.h:50
#define DmtxFail
Definition dmtx.h:44
DmtxPassFail dmtxMessageDestroy(DmtxMessage **msg)
Free memory previously allocated for message.
Definition dmtxmessage.c:87
DmtxMessage * dmtxMessageCreate(int sizeIdx, int symbolFormat)
Allocate memory for message.
Definition dmtxmessage.c:30
libdmtx - Data Matrix Encoding/Decoding Library Copyright 2008, 2009 Mike Laughton.
#define DmtxAssert(expr)
Definition dmtxstatic.h:96
DataMatrix编码内容
Definition dmtx.h:421
unsigned char * code
指向码字(数据字和纠错字)的指针
Definition dmtx.h:429
size_t outputSize
Size of buffer used to hold decoded data.
Definition dmtx.h:424
size_t codeSize
编码数据的总大小,包括数据字和纠错字
Definition dmtx.h:423
unsigned char * array
指向DataMatrix数据区二进制矩阵的指针
Definition dmtx.h:428
size_t arraySize
二维码数据区码元行数x列数(mappingRows * mappingCols)
Definition dmtx.h:422
unsigned char * output
指向二维码码值的指针
Definition dmtx.h:430