From 4e9f46e063fbcd3dc41413346f96174bfe5ec2ef Mon Sep 17 00:00:00 2001 From: nick black Date: Fri, 22 May 2020 05:50:41 -0400 Subject: [PATCH] Correct scaling in qrcode_rows() --- src/demo/qrcode.c | 4 +++- src/lib/fill.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/demo/qrcode.c b/src/demo/qrcode.c index dc50f75db..86a1f59f5 100644 --- a/src/demo/qrcode.c +++ b/src/demo/qrcode.c @@ -7,7 +7,7 @@ #define PER_QR_VERSION 4 static inline int qrcode_rows(int version){ - return QR_BASE_SIZE + (version * PER_QR_VERSION / 2); + return (QR_BASE_SIZE + (version * PER_QR_VERSION)) / 2; } static inline int @@ -38,6 +38,8 @@ int qrcode_demo(struct notcurses* nc){ int qlen = ncplane_qrcode(n, 0, data, len); // can fail due to being too large for the terminal if(qlen > 0){ + ncplane_move_yx(n, dimy / 2 - qrcode_rows(qlen) / 2, + dimx / 2 - qrcode_cols(qlen) / 2); if(ncplane_cursor_move_yx(n, 0, 0)){ ncplane_destroy(n); return -1; diff --git a/src/lib/fill.c b/src/lib/fill.c index 01975fce1..004d99ee4 100644 --- a/src/lib/fill.c +++ b/src/lib/fill.c @@ -600,7 +600,7 @@ int ncplane_rotate_ccw(ncplane* n){ static inline int qrcode_rows(int version){ - return QR_BASE_SIZE + (version * PER_QR_VERSION / 2); + return (QR_BASE_SIZE + (version * PER_QR_VERSION)) / 2; } static inline int