gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-taler-mdb] 61/93: qr gen


From: gnunet
Subject: [taler-taler-mdb] 61/93: qr gen
Date: Mon, 18 Nov 2019 21:13:24 +0100

This is an automated email from the git hooks/post-receive script.

marco-boss pushed a commit to branch master
in repository taler-mdb.

commit 80b7386ae8e7ccd3334e465afc617a17d8936a53
Author: Christian Grothoff <address@hidden>
AuthorDate: Sat Nov 16 10:22:07 2019 +0100

    qr gen
---
 src/main.c | 38 +++++++++++++++++++++-----------------
 1 file changed, 21 insertions(+), 17 deletions(-)

diff --git a/src/main.c b/src/main.c
index 5c8965d..e3b7f77 100644
--- a/src/main.c
+++ b/src/main.c
@@ -201,13 +201,6 @@ show_qrcode (const char *uri)
   size_t height;
   unsigned int scale;
 
-  if (0 < qrDisplay.devicefd)
-    scale = 8;
-  else
-    scale = 2;
-
-  const unsigned int n_channels = 3;
-
   qri = QRinput_new2 (0, QR_ECLEVEL_M);
   if (NULL == qri)
   {
@@ -246,22 +239,33 @@ show_qrcode (const char *uri)
     QRinput_free (qri);
     return;
   }
-  size = qrc->width * scale;
-  size += 8 - (size % 8);
+
+  /* +8 for 4-pixels border */
+  size = GNUNET_MIN (qrDisplay.var_info.xres,
+                     qrDisplay.var_info.yres);
+  scale = size / (qrc->width + 8);
+#if LEGACY
   pixels = GNUNET_malloc (size * size * n_channels);
-  for (unsigned int x = 0; x < size; x++)
-    for (unsigned int y = 0; y < size; y++)
+#endif
+  xOff = 4 * scale;
+  yOff = 4 * scale;
+  if (qrDisplay.var_info.xres < qrDisplay.var_info.yres)
+    yOff += (qrDisplay.var_info.yres - qrDisplay.var_info.xres) / 2;
+  else
+    xOff += (qrDisplay.var_info.xres - qrDisplay.var_info.yres) / 2;
+  for (unsigned int x = xOff; x < size - xOff; x++)
+    for (unsigned int y = yOff; y < size - yOff; y++)
     {
       unsigned int off =
-        (x * qrc->width / size) + (y * qrc->width / size) * qrc->width;
-      for (unsigned int c = 0; c < n_channels; c++)
-        pixels[(y * size + x) * n_channels + c] =
-          (0 == (qrc->data[off] & 1)) ? 0xFF : 0x00;
+        ((x - xOff) * qrc->width / size) + ((y - yOff) * qrc->width / size)
+        * qrc->width;
+      qrDisplay.memory[y * size + x] =
+        (0 == (qrc->data[off] & 1)) ? 0xFF : 0x00;
     }
 
   QRcode_free (qrc);
   QRinput_free (qri);
-
+#if LEGACY
   if (0 < qrDisplay.devicefd)
   {
     width = qrDisplay.var_info.xres;
@@ -297,8 +301,8 @@ show_qrcode (const char *uri)
       printf ("\n");
     }
   }
-
   GNUNET_free (pixels);
+#endif
 }
 
 

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]