From 4f28093d2e3c1658f742b5eff678b9aa2662ca46 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Sat, 16 Feb 2019 17:36:08 +0100 Subject: [PATCH] vendor: replace vendor/trezor-qrenc with vendor/QR-Code-generator --- .gitmodules | 6 ++--- SConscript.bootloader | 3 +-- SConscript.firmware | 3 +-- SConscript.prodtest | 3 +-- SConscript.reflash | 3 +-- SConscript.unix | 3 +-- embed/extmod/modtrezorui/display.c | 26 +++++++++++++++++----- embed/extmod/modtrezorui/qr-code-generator | 1 + embed/extmod/modtrezorui/trezor-qrenc | 1 - vendor/QR-Code-generator | 1 + vendor/trezor-qrenc | 1 - 11 files changed, 31 insertions(+), 20 deletions(-) create mode 120000 embed/extmod/modtrezorui/qr-code-generator delete mode 120000 embed/extmod/modtrezorui/trezor-qrenc create mode 160000 vendor/QR-Code-generator delete mode 160000 vendor/trezor-qrenc diff --git a/.gitmodules b/.gitmodules index 61bd4d265a..aefae6c918 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,6 @@ [submodule "vendor/trezor-crypto"] path = vendor/trezor-crypto url = https://github.com/trezor/trezor-crypto.git -[submodule "vendor/trezor-qrenc"] - path = vendor/trezor-qrenc - url = https://github.com/trezor/trezor-qrenc.git [submodule "vendor/micropython"] path = vendor/micropython url = https://github.com/trezor/micropython.git @@ -16,3 +13,6 @@ [submodule "vendor/trezor-storage"] path = vendor/trezor-storage url = https://github.com/trezor/trezor-storage.git +[submodule "vendor/QR-Code-generator"] + path = vendor/QR-Code-generator + url = https://github.com/nayuki/QR-Code-generator.git diff --git a/SConscript.bootloader b/SConscript.bootloader index 5e7d554825..1d79537653 100644 --- a/SConscript.bootloader +++ b/SConscript.bootloader @@ -34,7 +34,6 @@ SOURCE_MOD += [ CPPDEFINES_MOD += [ 'TREZOR_FONT_NORMAL_ENABLE', 'TREZOR_FONT_MONO_ENABLE', - ('QR_MAX_VERSION', '0'), ] SOURCE_MOD += [ 'embed/extmod/modtrezorui/display.c', @@ -42,7 +41,7 @@ SOURCE_MOD += [ 'embed/extmod/modtrezorui/font_bitmap.c', 'embed/extmod/modtrezorui/font_roboto_regular_20.c', 'embed/extmod/modtrezorui/font_robotomono_regular_20.c', - 'embed/extmod/modtrezorui/trezor-qrenc/qr_encode.c', + 'embed/extmod/modtrezorui/qr-code-generator/qrcodegen.c', ] SOURCE_STMHAL = [ diff --git a/SConscript.firmware b/SConscript.firmware index 6c32f57715..9bcdcca8e8 100644 --- a/SConscript.firmware +++ b/SConscript.firmware @@ -97,7 +97,6 @@ CPPDEFINES_MOD += [ 'TREZOR_FONT_NORMAL_ENABLE', 'TREZOR_FONT_MONO_ENABLE', 'TREZOR_FONT_MONO_BOLD_ENABLE', - ('QR_MAX_VERSION', '0'), ] SOURCE_MOD += [ 'embed/extmod/modtrezorui/display.c', @@ -108,7 +107,7 @@ SOURCE_MOD += [ 'embed/extmod/modtrezorui/font_robotomono_bold_20.c', 'embed/extmod/modtrezorui/font_robotomono_regular_20.c', 'embed/extmod/modtrezorui/modtrezorui.c', - 'embed/extmod/modtrezorui/trezor-qrenc/qr_encode.c', + 'embed/extmod/modtrezorui/qr-code-generator/qrcodegen.c', ] # modtrezorutils diff --git a/SConscript.prodtest b/SConscript.prodtest index 136dcfe30a..d1be76d112 100644 --- a/SConscript.prodtest +++ b/SConscript.prodtest @@ -18,14 +18,13 @@ SOURCE_MOD += [ # modtrezorui CPPDEFINES_MOD += [ 'TREZOR_FONT_BOLD_ENABLE', - ('QR_MAX_VERSION', '0'), ] SOURCE_MOD += [ 'embed/extmod/modtrezorui/display.c', 'embed/extmod/modtrezorui/inflate.c', 'embed/extmod/modtrezorui/font_bitmap.c', 'embed/extmod/modtrezorui/font_roboto_bold_20.c', - 'embed/extmod/modtrezorui/trezor-qrenc/qr_encode.c', + 'embed/extmod/modtrezorui/qr-code-generator/qrcodegen.c', ] SOURCE_STMHAL = [ diff --git a/SConscript.reflash b/SConscript.reflash index 7334fa0813..b3c59f6508 100644 --- a/SConscript.reflash +++ b/SConscript.reflash @@ -18,14 +18,13 @@ SOURCE_MOD += [ # modtrezorui CPPDEFINES_MOD += [ 'TREZOR_FONT_BOLD_ENABLE', - ('QR_MAX_VERSION', '0'), ] SOURCE_MOD += [ 'embed/extmod/modtrezorui/display.c', 'embed/extmod/modtrezorui/inflate.c', 'embed/extmod/modtrezorui/font_bitmap.c', 'embed/extmod/modtrezorui/font_roboto_bold_20.c', - 'embed/extmod/modtrezorui/trezor-qrenc/qr_encode.c', + 'embed/extmod/modtrezorui/qr-code-generator/qrcodegen.c', ] SOURCE_STMHAL = [ diff --git a/SConscript.unix b/SConscript.unix index a09a961961..a6b23ea024 100644 --- a/SConscript.unix +++ b/SConscript.unix @@ -94,7 +94,6 @@ CPPDEFINES_MOD += [ 'TREZOR_FONT_NORMAL_ENABLE', 'TREZOR_FONT_MONO_ENABLE', 'TREZOR_FONT_MONO_BOLD_ENABLE', - ('QR_MAX_VERSION', '0'), ] SOURCE_MOD += [ 'embed/extmod/modtrezorui/display.c', @@ -105,7 +104,7 @@ SOURCE_MOD += [ 'embed/extmod/modtrezorui/font_robotomono_bold_20.c', 'embed/extmod/modtrezorui/font_robotomono_regular_20.c', 'embed/extmod/modtrezorui/modtrezorui.c', - 'embed/extmod/modtrezorui/trezor-qrenc/qr_encode.c', + 'embed/extmod/modtrezorui/qr-code-generator/qrcodegen.c', ] if ARGUMENTS.get('TREZOR_EMULATOR_NOUI', 0): CPPDEFINES_MOD += ['TREZOR_EMULATOR_NOUI'] diff --git a/embed/extmod/modtrezorui/display.c b/embed/extmod/modtrezorui/display.c index 124312f5a2..f04876b171 100644 --- a/embed/extmod/modtrezorui/display.c +++ b/embed/extmod/modtrezorui/display.c @@ -32,7 +32,7 @@ #include "font_robotomono_bold_20.h" #endif -#include "trezor-qrenc/qr_encode.h" +#include "qr-code-generator/qrcodegen.h" #include "common.h" #include "display.h" @@ -626,11 +626,28 @@ int display_text_width(const char *text, int textlen, int font) return width; } +#define QR_MAX_VERSION 9 + void display_qrcode(int x, int y, const char *data, int datalen, uint8_t scale) { if (scale < 1 || scale > 10) return; - uint8_t bitdata[QR_MAX_BITDATA]; - int side = qr_encode(QR_LEVEL_M, 0, data, datalen, bitdata); + + uint8_t codedata[qrcodegen_BUFFER_LEN_FOR_VERSION(QR_MAX_VERSION)]; + uint8_t tempdata[qrcodegen_BUFFER_LEN_FOR_VERSION(QR_MAX_VERSION)]; + + int side = 0; + if (qrcodegen_encodeText( + data, + tempdata, + codedata, + qrcodegen_Ecc_MEDIUM, + qrcodegen_VERSION_MIN, + QR_MAX_VERSION, + qrcodegen_Mask_AUTO, + true)) { + side = qrcodegen_getSize(codedata); + } + x += DISPLAY_OFFSET.x - (side + 2) * scale / 2; y += DISPLAY_OFFSET.y - (side + 2) * scale / 2; int x0, y0, x1, y1; @@ -645,8 +662,7 @@ void display_qrcode(int x, int y, const char *data, int datalen, uint8_t scale) PIXELDATA(0xFFFF); continue; } - int a = ry * side + rx; - if (bitdata[a / 8] & (1 << (7 - a % 8))) { + if (qrcodegen_getModule(codedata, rx, ry)) { PIXELDATA(0x0000); } else { PIXELDATA(0xFFFF); diff --git a/embed/extmod/modtrezorui/qr-code-generator b/embed/extmod/modtrezorui/qr-code-generator new file mode 120000 index 0000000000..3b20cb0109 --- /dev/null +++ b/embed/extmod/modtrezorui/qr-code-generator @@ -0,0 +1 @@ +../../../vendor/QR-Code-generator/c \ No newline at end of file diff --git a/embed/extmod/modtrezorui/trezor-qrenc b/embed/extmod/modtrezorui/trezor-qrenc deleted file mode 120000 index 965b822ffe..0000000000 --- a/embed/extmod/modtrezorui/trezor-qrenc +++ /dev/null @@ -1 +0,0 @@ -../../../vendor/trezor-qrenc \ No newline at end of file diff --git a/vendor/QR-Code-generator b/vendor/QR-Code-generator new file mode 160000 index 0000000000..40d24f38aa --- /dev/null +++ b/vendor/QR-Code-generator @@ -0,0 +1 @@ +Subproject commit 40d24f38aa0a8180b271b6c88be8633f842ed9d4 diff --git a/vendor/trezor-qrenc b/vendor/trezor-qrenc deleted file mode 160000 index 9344f23d86..0000000000 --- a/vendor/trezor-qrenc +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 9344f23d869030fbe7261d3361862eaba12b9975