Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

更新官方提交的pr #5

Merged
merged 2 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ qrcode_initText(&qrcode, qrcodeBytes, DEFAULT_QR_VERSION, ECC_LOW, "HELLO WORLD"
The generated two-dimensional code is dot matrix data, 8 dots constitute a Byte. The following codes can be used to display the QR code

```c
for (uint8 y = 0; y <qrcode.size; y++) {
for (uint8 x = 0; x <qrcode.size; x++) {
if (qrcode_getModule(&qrcode, x, y) {
for (uint8_t y = 0; y <qrcode.size; y++) {
for (uint8_t x = 0; x <qrcode.size; x++) {
if (qrcode_getModule(&qrcode, x, y)) {
rt_kprintf("**");
} else {
rt_kprintf(" ");
Expand Down
6 changes: 3 additions & 3 deletions README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ qrcode_initText(&qrcode, qrcodeBytes, DEFAULT_QR_VERSION, ECC_LOW, "HELLO WORLD"
生成的二维码是点阵数据,8个点构成一个 Byte。显示二维码可以使用以下代码

```c
for (uint8 y = 0; y < qrcode.size; y++) {
for (uint8 x = 0; x < qrcode.size; x++) {
if (qrcode_getModule(&qrcode, x, y) {
for (uint8_t y = 0; y < qrcode.size; y++) {
for (uint8_t x = 0; x < qrcode.size; x++) {
if (qrcode_getModule(&qrcode, x, y)) {
rt_kprintf("**");
} else {
rt_kprintf(" ");
Expand Down
2 changes: 1 addition & 1 deletion samples/qrcode_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ static void qrcode(uint8_t argc, char **argv)
}
}
MSH_CMD_EXPORT(qrcode, qrcode generator: qrcode [string]);
#endif /* defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) */
#endif /* defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) */
8 changes: 5 additions & 3 deletions src/qrcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ static void bb_initGrid(BitBucket *bitGrid, uint8_t *data, uint8_t size) {
static void bb_appendBits(BitBucket *bitBuffer, uint32_t val, uint8_t length) {
uint32_t offset = bitBuffer->bitOffsetOrWidth;
for (int8_t i = length - 1; i >= 0; i--, offset++) {
bitBuffer->data[offset >> 3] |= ((val >> i) & 1) << (7 - (offset & 7));
if (bitBuffer->capacityBytes > offset >> 3) {
bitBuffer->data[offset >> 3] |= ((val >> i) & 1) << (7 - (offset & 7));
}
}
bitBuffer->bitOffsetOrWidth = offset;
}
Expand Down Expand Up @@ -739,7 +741,6 @@ uint16_t qrcode_getBufferSize(uint8_t version) {
return bb_getGridSizeBytes(4 * version + 17);
}

// @TODO: Return error if data is too big.
int8_t qrcode_initBytes(QRCode *qrcode, uint8_t *modules, uint8_t version, uint8_t ecc, uint8_t *data, uint16_t length) {
uint8_t size = version * 4 + 17;
qrcode->version = version;
Expand Down Expand Up @@ -773,7 +774,8 @@ int8_t qrcode_initBytes(QRCode *qrcode, uint8_t *modules, uint8_t version, uint8
qrcode->mode = mode;

// Add terminator and pad up to a byte if applicable
uint32_t padding = (dataCapacity * 8) - codewords.bitOffsetOrWidth;
int32_t padding = (dataCapacity * 8) - codewords.bitOffsetOrWidth;
if (padding < 0) { return -1; }
if (padding > 4) { padding = 4; }
bb_appendBits(&codewords, 0, padding);
bb_appendBits(&codewords, 0, (8 - codewords.bitOffsetOrWidth % 8) % 8);
Expand Down