58 if(entry == NULL)
return NULL;
64 entry->
data = (
unsigned char *)malloc((
size_t)
size);
65 if(entry->
data == NULL) {
69 memcpy(entry->
data, data, (
size_t)
size);
91 if(n == NULL)
return NULL;
95 n->
data = (
unsigned char *)malloc((
size_t)n->
size);
126 if(input == NULL)
return NULL;
146 if(input == NULL)
return NULL;
213 if(input->
tail == NULL) {
251 unsigned char buf[3];
257 if(number <= 0 || number >
size) {
262 buf[0] = (
unsigned char)
size;
263 buf[1] = (
unsigned char)number;
278 unsigned char data[4];
280 if(ecinum > 999999) {
287 data[0] = ecinum & 0xff;
288 data[1] = (ecinum >> 8) & 0xff;
289 data[2] = (ecinum >> 16) & 0xff;
290 data[3] = (ecinum >> 24) & 0xff;
300 while(list != NULL) {
311 unsigned char parity = 0;
316 while(list != NULL) {
318 for(i = list->
size-1; i >= 0; i--) {
319 parity ^= list->
data[i];
338 if(n == NULL)
return NULL;
341 while(list != NULL) {
368 for(i = 0; i <
size; i++) {
369 if(data[i] <
'0' || data[i] >
'9')
388 switch(
size - w * 3) {
419 if(ret < 0)
return -1;
422 if(ret < 0)
return -1;
425 if(ret < 0)
return -1;
428 if(ret < 0)
return -1;
431 words = entry->
size / 3;
432 for(i = 0; i < words; i++) {
433 val = (
unsigned int)(entry->
data[i*3 ] -
'0') * 100;
434 val += (
unsigned int)(entry->
data[i*3+1] -
'0') * 10;
435 val += (
unsigned int)(entry->
data[i*3+2] -
'0');
438 if(ret < 0)
return -1;
441 if(entry->
size - words * 3 == 1) {
442 val = (
unsigned int)(entry->
data[words*3] -
'0');
444 if(ret < 0)
return -1;
445 }
else if(entry->
size - words * 3 == 2) {
446 val = (
unsigned int)(entry->
data[words*3 ] -
'0') * 10;
447 val += (
unsigned int)(entry->
data[words*3+1] -
'0');
449 if(ret < 0)
return -1;
460 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
461 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
462 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43,
463 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1,
464 -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
465 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1,
466 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
467 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
480 for(i = 0; i <
size; i++) {
528 if(ret < 0)
return -1;
530 if(ret < 0)
return -1;
533 if(ret < 0)
return -1;
535 if(ret < 0)
return -1;
538 words = entry->
size / 2;
539 for(i = 0; i < words; i++) {
544 if(ret < 0)
return -1;
547 if(entry->
size & 1) {
551 if(ret < 0)
return -1;
590 if(ret < 0)
return -1;
592 if(ret < 0)
return -1;
595 if(ret < 0)
return -1;
597 if(ret < 0)
return -1;
601 if(ret < 0)
return -1;
618 return (
size / 2) * 13;
635 for(i = 0; i <
size; i+=2) {
636 val = ((
unsigned int)data[i] << 8) | data[i+1];
637 if(val < 0x8140 || (val > 0x9ffc && val < 0xe040) || val > 0xebbf) {
666 if(ret < 0)
return -1;
668 if(ret < 0)
return -1;
671 if(ret < 0)
return -1;
673 if(ret < 0)
return -1;
676 for(i = 0; i < entry->
size; i+=2) {
677 val = ((
unsigned int)entry->
data[i] << 8) | entry->
data[i+1];
683 h = (val >> 8) * 0xc0;
684 val = (val & 0xff) + h;
687 if(ret < 0)
return -1;
717 if(ret < 0)
return -1;
719 if(ret < 0)
return -1;
721 if(ret < 0)
return -1;
723 if(ret < 0)
return -1;
734 if(
size != 1)
return -1;
746 if(ret < 0)
return -1;
749 if(ret < 0)
return -1;
763 for(i = 0; i < 4; i++) {
764 ecinum = ecinum << 8;
780 }
else if(ecinum < 16384) {
790 unsigned int ecinum, code;
798 }
else if(ecinum < 16384) {
800 code = 0x8000 + ecinum;
803 code = 0xc0000 + ecinum;
807 if(ret < 0)
return -1;
810 if(ret < 0)
return -1;
866 switch(entry->
mode) {
900 num = (entry->
size/2 + m - 1) / m;
902 num = (entry->
size + m - 1) / m;
923 while(list != NULL) {
963 int payload,
size, chunks, remain, maxsize;
968 chunks = payload / 10;
969 remain = payload - chunks * 10;
973 }
else if(remain >= 4) {
978 chunks = payload / 11;
979 remain = payload - chunks * 11;
981 if(remain >= 6)
size++;
987 size = (payload / 13) * 2;
998 if(maxsize > 0 &&
size > maxsize)
size = maxsize;
1026 if(words != 0 && entry->
size > words) {
1028 if(st1 == NULL)
goto ABORT;
1030 if(st2 == NULL)
goto ABORT;
1033 if(ret < 0)
goto ABORT;
1035 if(ret < 0)
goto ABORT;
1041 switch(entry->
mode) {
1066 if(ret < 0)
return -1;
1087 int bits, total = 0;
1090 while(list != NULL) {
1092 if(bits < 0)
return -1;
1125 if(bits < 0)
return -1;
1149 int bits, maxbits, words, maxwords, i, ret;
1154 maxbits = maxwords * 8;
1156 if(maxbits < bits) {
1160 if(maxbits == bits) {
1164 if(maxbits - bits <= 4) {
1168 words = (bits + 4 + 7) / 8;
1171 if(ret < 0)
return ret;
1173 padlen = maxwords - words;
1175 for(i = 0; i < padlen; i++) {
1198 int bits, maxbits, words, maxwords, i, ret, termbits;
1203 maxwords = maxbits / 8;
1205 if(maxbits < bits) {
1209 if(maxbits == bits) {
1213 termbits = input->
version * 2 + 1;
1215 if(maxbits - bits <= termbits) {
1221 words = (bits + 7) / 8;
1222 if(maxbits - words * 8 > 0) {
1223 termbits += words * 8 - bits;
1224 if(words == maxwords) termbits += maxbits - words * 8;
1226 termbits += words * 8 - bits;
1229 if(ret < 0)
return ret;
1231 padlen = maxwords - words;
1233 for(i = 0; i < padlen; i++) {
1235 if(ret < 0)
return ret;
1237 termbits = maxbits - maxwords * 8;
1240 if(ret < 0)
return ret;
1251 if(input->
fnc1 == 1) {
1253 }
else if(input->
fnc1 == 2) {
1262 input->
head = entry;
1308 if(ret < 0)
return -1;
1315 if(ret < 0)
return -1;
1329 unsigned char *array;
1333 if(bstream == NULL) {
1357 if(entry == NULL)
return NULL;
1359 entry->
input = input;
1378 if(s == NULL)
return NULL;
1403 if(e == NULL)
return -1;
1406 if(s->
tail == NULL) {
1423 while(list != NULL) {
1435 unsigned char parity = 0;
1438 while(list != NULL) {
1450 unsigned char *data;
1452 data = (
unsigned char *)malloc((
size_t)bytes);
1453 if(data == NULL)
return -1;
1455 memcpy(data, entry->
data, (
size_t)bytes);
1458 entry->
size = bytes;
1489 int bits, maxbits, nextbits, bytes, ret;
1499 if(s == NULL)
return NULL;
1510 if(maxbits <= 0)
goto ABORT;
1513 if(bstream == NULL)
goto ABORT;
1518 while(list != NULL) {
1520 if(bits + nextbits <= maxbits) {
1523 if(ret < 0)
goto ABORT;
1530 if(p == NULL)
goto ABORT;
1566 if(ret < 0)
goto ABORT;
1604 while(list != NULL) {
1636 input->
appid = appid;
void BitStream_free(BitStream *bstream)
BitStream * BitStream_new(void)
unsigned char * BitStream_toByte(BitStream *bstream)
int BitStream_appendNum(BitStream *bstream, size_t bits, unsigned int num)
int BitStream_appendBytes(BitStream *bstream, size_t size, unsigned char *data)
#define BitStream_reset(__bstream__)
#define BitStream_size(__bstream__)
int MQRspec_getECCLength(int version, QRecLevel level)
Return maximum error correction code length (bytes) for the version.
int MQRspec_maximumWords(QRencodeMode mode, int version)
Return the maximum length for the mode and version.
int MQRspec_lengthIndicator(QRencodeMode mode, int version)
Length indicator.
int MQRspec_getDataLengthBit(int version, QRecLevel level)
Return maximum data code length (bits) for the version.
#define MQRSPEC_MODEID_KANJI
#define MQRSPEC_MODEID_AN
#define MQRSPEC_MODEID_NUM
Mode indicator.
QRecLevel
Level of error correction.
QRencodeMode
Encoding mode.
@ QR_MODE_KANJI
Kanji (shift-jis) mode.
@ QR_MODE_STRUCTURE
Internal use only.
@ QR_MODE_FNC1FIRST
FNC1, first position.
@ QR_MODE_FNC1SECOND
FNC1, second position.
@ QR_MODE_AN
Alphabet-numeric mode.
@ QR_MODE_8
8-bit data mode
@ QR_MODE_NUL
Terminator (NUL character). Internal use only.
@ QR_MODE_NUM
Numeric mode.
#define MQRSPEC_VERSION_MAX
Maximum version (size) of QR-code symbol.
#define QRSPEC_VERSION_MAX
Maximum version (size) of QR-code symbol.
int QRspec_getMinimumVersion(int size, QRecLevel level)
Return a version number that satisfies the input code length.
int QRspec_maximumWords(QRencodeMode mode, int version)
Return the maximum length for the mode and version.
int QRspec_lengthIndicator(QRencodeMode mode, int version)
Length indicator.
int QRspec_getDataLength(int version, QRecLevel level)
Return maximum data code length (bytes) for the version.
#define QRSPEC_MODEID_NUM
#define QRSPEC_MODEID_ECI
Mode indicator.
#define QRSPEC_MODEID_STRUCTURE
#define QRSPEC_MODEID_FNC1SECOND
#define QRSPEC_MODEID_KANJI