style
This commit is contained in:
1 parent
0aac15cfd0
commit
c4de141d03
2 files changed
+52
-27
No files matched your search
+51
-26
@@ -63,11 +63,11 @@ static const uint8_t NUM_ERROR_CORRECTION_BLOCKS[4][40] = {
|
|||||||
|
|
||||||
static const uint16_t NUM_RAW_DATA_MODULES[40] = {
|
static const uint16_t NUM_RAW_DATA_MODULES[40] = {
|
||||||
// 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
|
// 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
|
||||||
208, 359, 567, 807, 1079, 1383, 1568, 1936, 2336, 2768, 3232, 3728, 4256, 4651, 5243, 5867, 6523,
|
208, 359, 567, 807, 1079, 1383, 1568, 1936, 2336, 2768, 3232, 3728, 4256, 4651, 5243, 5867, 6523,
|
||||||
// 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
|
// 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
|
||||||
7211, 7931, 8683, 9252, 10068, 10916, 11796, 12708, 13652, 14628, 15371, 16411, 17483, 18587,
|
7211, 7931, 8683, 9252, 10068, 10916, 11796, 12708, 13652, 14628, 15371, 16411, 17483, 18587,
|
||||||
// 32, 33, 34, 35, 36, 37, 38, 39, 40
|
// 32, 33, 34, 35, 36, 37, 38, 39, 40
|
||||||
19723, 20891, 22091, 23008, 24272, 25568, 26896, 28256, 29648
|
19723, 20891, 22091, 23008, 24272, 25568, 26896, 28256, 29648
|
||||||
};
|
};
|
||||||
|
|
||||||
// @TODO: Put other LOCK_VERSIONS here
|
// @TODO: Put other LOCK_VERSIONS here
|
||||||
@@ -103,15 +103,24 @@ static int8_t getAlphanumeric(char c) {
|
|||||||
if (c >= 'A' && c <= 'Z') { return (c - 'A' + 10); }
|
if (c >= 'A' && c <= 'Z') { return (c - 'A' + 10); }
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case ' ': return 36;
|
case ' ':
|
||||||
case '$': return 37;
|
return 36;
|
||||||
case '%': return 38;
|
case '$':
|
||||||
case '*': return 39;
|
return 37;
|
||||||
case '+': return 40;
|
case '%':
|
||||||
case '-': return 41;
|
return 38;
|
||||||
case '.': return 42;
|
case '*':
|
||||||
case '/': return 43;
|
return 39;
|
||||||
case ':': return 44;
|
case '+':
|
||||||
|
return 40;
|
||||||
|
case '-':
|
||||||
|
return 41;
|
||||||
|
case '.':
|
||||||
|
return 42;
|
||||||
|
case '/':
|
||||||
|
return 43;
|
||||||
|
case ':':
|
||||||
|
return 44;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
@@ -260,14 +269,30 @@ static void applyMask(BitBucket *modules, BitBucket *isFunction, uint8_t mask) {
|
|||||||
|
|
||||||
bool invert = 0;
|
bool invert = 0;
|
||||||
switch (mask) {
|
switch (mask) {
|
||||||
case 0: invert = (x + y) % 2 == 0; break;
|
case 0:
|
||||||
case 1: invert = y % 2 == 0; break;
|
invert = (x + y) % 2 == 0;
|
||||||
case 2: invert = x % 3 == 0; break;
|
break;
|
||||||
case 3: invert = (x + y) % 3 == 0; break;
|
case 1:
|
||||||
case 4: invert = (x / 3 + y / 2) % 2 == 0; break;
|
invert = y % 2 == 0;
|
||||||
case 5: invert = x * y % 2 + x * y % 3 == 0; break;
|
break;
|
||||||
case 6: invert = (x * y % 2 + x * y % 3) % 2 == 0; break;
|
case 2:
|
||||||
case 7: invert = ((x + y) % 2 + x * y % 3) % 2 == 0; break;
|
invert = x % 3 == 0;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
invert = (x + y) % 3 == 0;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
invert = (x / 3 + y / 2) % 2 == 0;
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
invert = x * y % 2 + x * y % 3 == 0;
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
invert = (x * y % 2 + x * y % 3) % 2 == 0;
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
invert = ((x + y) % 2 + x * y % 3) % 2 == 0;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
bb_invertBit(modules, x, y, invert);
|
bb_invertBit(modules, x, y, invert);
|
||||||
}
|
}
|
||||||
@@ -627,7 +652,7 @@ static void rs_getRemainder(uint8_t degree, uint8_t *coeff, uint8_t *data, uint8
|
|||||||
static int8_t encodeDataCodewords(BitBucket *dataCodewords, const uint8_t *text, uint16_t length, uint8_t version) {
|
static int8_t encodeDataCodewords(BitBucket *dataCodewords, const uint8_t *text, uint16_t length, uint8_t version) {
|
||||||
int8_t mode = MODE_BYTE;
|
int8_t mode = MODE_BYTE;
|
||||||
|
|
||||||
if (isNumeric((char*)text, length)) {
|
if (isNumeric((char *)text, length)) {
|
||||||
mode = MODE_NUMERIC;
|
mode = MODE_NUMERIC;
|
||||||
bb_appendBits(dataCodewords, 1 << MODE_NUMERIC, 4);
|
bb_appendBits(dataCodewords, 1 << MODE_NUMERIC, 4);
|
||||||
bb_appendBits(dataCodewords, length, getModeBits(version, MODE_NUMERIC));
|
bb_appendBits(dataCodewords, length, getModeBits(version, MODE_NUMERIC));
|
||||||
@@ -649,7 +674,7 @@ static int8_t encodeDataCodewords(BitBucket *dataCodewords, const uint8_t *text,
|
|||||||
bb_appendBits(dataCodewords, accumData, accumCount * 3 + 1);
|
bb_appendBits(dataCodewords, accumData, accumCount * 3 + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (isAlphanumeric((char*)text, length)) {
|
} else if (isAlphanumeric((char *)text, length)) {
|
||||||
mode = MODE_ALPHANUMERIC;
|
mode = MODE_ALPHANUMERIC;
|
||||||
bb_appendBits(dataCodewords, 1 << MODE_ALPHANUMERIC, 4);
|
bb_appendBits(dataCodewords, 1 << MODE_ALPHANUMERIC, 4);
|
||||||
bb_appendBits(dataCodewords, length, getModeBits(version, MODE_ALPHANUMERIC));
|
bb_appendBits(dataCodewords, length, getModeBits(version, MODE_ALPHANUMERIC));
|
||||||
@@ -848,7 +873,7 @@ int8_t qrcode_initBytes(QRCode *qrcode, uint8_t *modules, uint8_t version, uint8
|
|||||||
}
|
}
|
||||||
|
|
||||||
int8_t qrcode_initText(QRCode *qrcode, uint8_t *modules, uint8_t version, uint8_t ecc, const char *data) {
|
int8_t qrcode_initText(QRCode *qrcode, uint8_t *modules, uint8_t version, uint8_t ecc, const char *data) {
|
||||||
return qrcode_initBytes(qrcode, modules, version, ecc, (uint8_t*)data, strlen(data));
|
return qrcode_initBytes(qrcode, modules, version, ecc, (uint8_t *)data, strlen(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool qrcode_getModule(QRCode *qrcode, uint8_t x, uint8_t y) {
|
bool qrcode_getModule(QRCode *qrcode, uint8_t x, uint8_t y) {
|
||||||
@@ -897,7 +922,7 @@ void qrcode_print_matrix_utf8_2x2(QRCode *q) {
|
|||||||
// ab
|
// ab
|
||||||
// cd
|
// cd
|
||||||
// UTF-8 block elements for 2x2 pixel blocks
|
// UTF-8 block elements for 2x2 pixel blocks
|
||||||
static const char* block_chars[16] = {
|
static const char *block_chars[16] = {
|
||||||
" ", // 0000: 0
|
" ", // 0000: 0
|
||||||
"\xE2\x96\x97", // 0001: 1
|
"\xE2\x96\x97", // 0001: 1
|
||||||
"\xE2\x96\x96", // 0010: 2
|
"\xE2\x96\x96", // 0010: 2
|
||||||
@@ -909,7 +934,7 @@ void qrcode_print_matrix_utf8_2x2(QRCode *q) {
|
|||||||
"\xE2\x96\x98", // 1000: 8
|
"\xE2\x96\x98", // 1000: 8
|
||||||
"\xE2\x96\x9A", // 1001: 9
|
"\xE2\x96\x9A", // 1001: 9
|
||||||
"\xE2\x96\x8C", // 1010: a
|
"\xE2\x96\x8C", // 1010: a
|
||||||
"\xE2\x96\x99" , // 1011: b
|
"\xE2\x96\x99", // 1011: b
|
||||||
"\xE2\x96\x80", // 1100: c
|
"\xE2\x96\x80", // 1100: c
|
||||||
"\xE2\x96\x9C", // 1101: D
|
"\xE2\x96\x9C", // 1101: D
|
||||||
"\xE2\x96\x9B", // 1110: E
|
"\xE2\x96\x9B", // 1110: E
|
||||||
@@ -927,7 +952,7 @@ void qrcode_print_matrix_utf8_2x2(QRCode *q) {
|
|||||||
|
|
||||||
uint8_t c = qrcode_getModule(q, x, y + 1);
|
uint8_t c = qrcode_getModule(q, x, y + 1);
|
||||||
uint8_t d = 0;
|
uint8_t d = 0;
|
||||||
if ( ((x + 1) < q->size) && (y + 1) < q->size) {
|
if (((x + 1) < q->size) && (y + 1) < q->size) {
|
||||||
d = qrcode_getModule(q, x + 1, y + 1);
|
d = qrcode_getModule(q, x + 1, y + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ typedef struct QRCode {
|
|||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"{
|
extern "C" {
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user