56 if(entry == NULL)
return NULL;
63 if(entry->
data == NULL) {
67 memcpy(entry->
data, data, (
size_t)size);
89 if(n == NULL)
return NULL;
124 if(input == NULL)
return NULL;
129 input->
level = level;
144 if(input == NULL)
return NULL;
184 input->
level = level;
200 input->
level = level;
211 if(input->
tail == NULL) {
249 unsigned char buf[3];
255 if(number <= 0 || number > size) {
260 buf[0] = (
unsigned char)size;
261 buf[1] = (
unsigned char)number;
276 unsigned char data[4];
278 if(ecinum > 999999) {
285 data[0] = ecinum & 0xff;
286 data[1] = (ecinum >> 8) & 0xff;
287 data[2] = (ecinum >> 16) & 0xff;
288 data[3] = (ecinum >> 24) & 0xff;
298 while(list != NULL) {
309 unsigned char parity = 0;
314 while(list != NULL) {
316 for(i = list->
size-1; i >= 0; i--) {
317 parity ^= list->
data[i];
336 if(n == NULL)
return NULL;
339 while(list != NULL) {
366 for(i = 0; i <
size; i++) {
367 if(data[i] <
'0' || data[i] >
'9')
386 switch(size - w * 3) {
417 if(ret < 0)
return -1;
420 if(ret < 0)
return -1;
423 if(ret < 0)
return -1;
426 if(ret < 0)
return -1;
429 words = entry->
size / 3;
430 for(i = 0; i < words; i++) {
431 val = (
unsigned int)(entry->
data[i*3 ] -
'0') * 100;
432 val += (
unsigned int)(entry->
data[i*3+1] -
'0') * 10;
433 val += (
unsigned int)(entry->
data[i*3+2] -
'0');
436 if(ret < 0)
return -1;
439 if(entry->
size - words * 3 == 1) {
440 val = (
unsigned int)(entry->
data[words*3] -
'0');
442 if(ret < 0)
return -1;
443 }
else if(entry->
size - words * 3 == 2) {
444 val = (
unsigned int)(entry->
data[words*3 ] -
'0') * 10;
445 val += (
unsigned int)(entry->
data[words*3+1] -
'0');
447 if(ret < 0)
return -1;
458 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
459 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
460 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43,
461 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1,
462 -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
463 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1,
464 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
465 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
478 for(i = 0; i <
size; i++) {
526 if(ret < 0)
return -1;
528 if(ret < 0)
return -1;
531 if(ret < 0)
return -1;
533 if(ret < 0)
return -1;
536 words = entry->
size / 2;
537 for(i = 0; i < words; i++) {
542 if(ret < 0)
return -1;
545 if(entry->
size & 1) {
549 if(ret < 0)
return -1;
588 if(ret < 0)
return -1;
590 if(ret < 0)
return -1;
593 if(ret < 0)
return -1;
595 if(ret < 0)
return -1;
599 if(ret < 0)
return -1;
616 return (size / 2) * 13;
633 for(i = 0; i <
size; i+=2) {
634 val = ((
unsigned int)data[i] << 8) | data[i+1];
635 if(val < 0x8140 || (val > 0x9ffc && val < 0xe040) || val > 0xebbf) {
664 if(ret < 0)
return -1;
666 if(ret < 0)
return -1;
669 if(ret < 0)
return -1;
671 if(ret < 0)
return -1;
674 for(i = 0; i < entry->
size; i+=2) {
675 val = ((
unsigned int)entry->
data[i] << 8) | entry->
data[i+1];
681 h = (val >> 8) * 0xc0;
682 val = (val & 0xff) + h;
685 if(ret < 0)
return -1;
715 if(ret < 0)
return -1;
717 if(ret < 0)
return -1;
719 if(ret < 0)
return -1;
721 if(ret < 0)
return -1;
732 if(size != 1)
return -1;
744 if(ret < 0)
return -1;
747 if(ret < 0)
return -1;
761 for(i = 0; i < 4; i++) {
762 ecinum = ecinum << 8;
778 }
else if(ecinum < 16384) {
788 unsigned int ecinum,
code;
796 }
else if(ecinum < 16384) {
798 code = 0x8000 + ecinum;
801 code = 0xc0000 + ecinum;
805 if(ret < 0)
return -1;
808 if(ret < 0)
return -1;
862 if(version == 0) version = 1;
864 switch(entry->
mode) {
898 num = (entry->
size/2 + m - 1) / m;
900 num = (entry->
size + m - 1) / m;
921 while(list != NULL) {
944 if(prev == 0 && version > 1) {
947 }
while (version > prev);
961 int payload,
size, chunks, remain, maxsize;
966 chunks = payload / 10;
967 remain = payload - chunks * 10;
971 }
else if(remain >= 4) {
976 chunks = payload / 11;
977 remain = payload - chunks * 11;
979 if(remain >= 6) size++;
985 size = (payload / 13) * 2;
995 if(size < 0) size = 0;
996 if(maxsize > 0 && size > maxsize) size = maxsize;
1024 if(words != 0 && entry->
size > words) {
1026 if(st1 == NULL)
goto ABORT;
1028 if(st2 == NULL)
goto ABORT;
1031 if(ret < 0)
goto ABORT;
1033 if(ret < 0)
goto ABORT;
1039 switch(entry->
mode) {
1064 if(ret < 0)
return -1;
1085 int bits, total = 0;
1088 while(list != NULL) {
1090 if(bits < 0)
return -1;
1123 if(bits < 0)
return -1;
1147 int bits, maxbits, words, maxwords, i, ret;
1152 maxbits = maxwords * 8;
1154 if(maxbits < bits) {
1158 if(maxbits == bits) {
1162 if(maxbits - bits <= 4) {
1166 words = (bits + 4 + 7) / 8;
1169 if(ret < 0)
return ret;
1171 padlen = maxwords - words;
1173 for(i = 0; i < padlen; i++) {
1196 int bits, maxbits, words, maxwords, i, ret, termbits;
1201 maxwords = maxbits / 8;
1203 if(maxbits < bits) {
1207 if(maxbits == bits) {
1211 termbits = input->
version * 2 + 1;
1213 if(maxbits - bits <= termbits) {
1219 words = (bits + 7) / 8;
1220 if(maxbits - words * 8 > 0) {
1221 termbits += words * 8 - bits;
1222 if(words == maxwords) termbits += maxbits - words * 8;
1224 termbits += words * 8 - bits;
1227 if(ret < 0)
return ret;
1229 padlen = maxwords - words;
1231 for(i = 0; i < padlen; i++) {
1233 if(ret < 0)
return ret;
1235 termbits = maxbits - maxwords * 8;
1238 if(ret < 0)
return ret;
1249 if(input->
fnc1 == 1) {
1251 }
else if(input->
fnc1 == 2) {
1260 input->
head = entry;
1306 if(ret < 0)
return -1;
1313 if(ret < 0)
return -1;
1327 unsigned char *array;
1331 if(bstream == NULL) {
1355 if(entry == NULL)
return NULL;
1357 entry->
input = input;
1376 if(s == NULL)
return NULL;
1401 if(e == NULL)
return -1;
1404 if(s->
tail == NULL) {
1421 while(list != NULL) {
1433 unsigned char parity = 0;
1436 while(list != NULL) {
1448 unsigned char *data;
1450 data = (
unsigned char *)
malloc((
size_t)bytes);
1451 if(data == NULL)
return -1;
1453 memcpy(data, entry->
data, (
size_t)bytes);
1456 entry->
size = bytes;
1487 int bits, maxbits, nextbits, bytes, ret;
1497 if(s == NULL)
return NULL;
1508 if(maxbits <= 0)
goto ABORT;
1511 if(bstream == NULL)
goto ABORT;
1516 while(list != NULL) {
1518 if(bits + nextbits <= maxbits) {
1521 if(ret < 0)
goto ABORT;
1528 if(p == NULL)
goto ABORT;
1564 if(ret < 0)
goto ABORT;
1602 while(list != NULL) {
1634 input->
appid = appid;
#define QRSPEC_MODEID_KANJI
#define BitStream_reset(__bstream__)
int QRspec_getDataLength(int version, QRecLevel level)
Return maximum data code length (bytes) for the version.
#define QRSPEC_VERSION_MAX
Maximum version (size) of QR-code symbol.
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
#define STATIC_IN_RELEASE
QRecLevel
Level of error correction.
int MQRspec_lengthIndicator(QRencodeMode mode, int version)
Return the size of length indicator for the mode and version.
#define MQRSPEC_VERSION_MAX
Maximum version (size) of QR-code symbol.
#define MQRSPEC_MODEID_AN
QRencodeMode
Encoding mode.
int QRspec_maximumWords(QRencodeMode mode, int version)
Return the maximum length for the mode and version.
int BitStream_appendBytes(BitStream *bstream, size_t size, unsigned char *data)
int QRspec_lengthIndicator(QRencodeMode mode, int version)
Return the size of length indicator for the mode and version.
#define MQRSPEC_MODEID_KANJI
#define QRSPEC_MODEID_ECI
Mode indicator.
unsigned char * BitStream_toByte(BitStream *bstream)
void BitStream_free(BitStream *bstream)
#define MQRSPEC_MODEID_NUM
Mode indicator.
#define BitStream_size(__bstream__)
#define QRSPEC_MODEID_STRUCTURE
int MQRspec_getDataLengthBit(int version, QRecLevel level)
Return maximum data code length (bits) for the version.
int MQRspec_maximumWords(QRencodeMode mode, int version)
Return the maximum length for the mode and version.
int QRspec_getMinimumVersion(int size, QRecLevel level)
Return a version number that satisfies the input code length.
#define QRSPEC_MODEID_FNC1SECOND
int MQRspec_getECCLength(int version, QRecLevel level)
Return maximum error correction code length (bytes) for the version.
BitStream * BitStream_new(void)
Terminator (NUL character). Internal use only.
int BitStream_appendNum(BitStream *bstream, size_t bits, unsigned int num)
#define QRSPEC_MODEID_NUM