From d64cb38240bd6db10135b6007f42dab6851ca559 Mon Sep 17 00:00:00 2001 From: swirl Date: Fri, 27 May 2022 15:45:38 -0400 Subject: [PATCH] Reverse QR code colors and add padding All QR scanners should be able to recognize this, as it is now the correct color with some padding to prevent blending. Signed-off-by: swirl --- src/command/cmd_funcs.c | 1 - src/ui/console.c | 26 +++++++++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 81293c15..1a4d4bf1 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -9778,4 +9778,3 @@ cmd_mood(ProfWin* window, const char* const command, gchar** args) } return TRUE; } - diff --git a/src/ui/console.c b/src/ui/console.c index e0b0fa4d..89c3cf29 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -871,24 +871,37 @@ cons_show_omemo_qrcode(const char* const text) { #ifdef HAVE_QRENCODE static const size_t ZOOM_SIZE = 10; - QRcode *qrcode = QRcode_encodeString(text, 0, QR_ECLEVEL_L, QR_MODE_8, 1); + QRcode* qrcode = QRcode_encodeString(text, 0, QR_ECLEVEL_L, QR_MODE_8, 1); int width = (qrcode->width * ZOOM_SIZE); - unsigned char *data = qrcode->data; + unsigned char* data = qrcode->data; ProfWin* console = wins_get_console(); char buf[(width * 4) + 1]; memset(buf, 0, sizeof buf); - for (size_t y = 0; y < width; y+=ZOOM_SIZE) { - for (size_t x = 0; x < width; x+=ZOOM_SIZE) { - strcat(buf, (*data & 1) ? "\u2588\u2588" : "\u2800\u2800"); + + char tmp[(width * 4) + 5]; + memset(tmp, 0, sizeof tmp); + + for (int i = 0; i < width + 2 * ZOOM_SIZE; i += ZOOM_SIZE) { + strcat(tmp, "\u2588\u2588"); + } + + win_println(console, THEME_DEFAULT, "", tmp); + for (size_t y = 0; y < width; y += ZOOM_SIZE) { + for (size_t x = 0; x < width; x += ZOOM_SIZE) { + strcat(buf, !(*data & 1) ? "\u2588\u2588" : "\u2800\u2800"); data++; } - win_println(console, THEME_DEFAULT, "", "%s", buf); + + // The extra squares are for padding, so that the QR code doesn't + // "blend in" with the rest of the terminal window. + win_println(console, THEME_DEFAULT, "", "\u2588\u2588%s\u2588\u2588", buf); memset(buf, 0, sizeof buf); } + win_println(console, THEME_DEFAULT, "", "%s", tmp); QRcode_free(qrcode); #endif @@ -2926,4 +2939,3 @@ cons_remove_alert(ProfWin* window) g_list_free_full(item, g_free); free(win_name); } -