summaryrefslogtreecommitdiffstats
path: root/pica-client/qrcode.h
diff options
context:
space:
mode:
authorAnton <anton@picapica.im>2026-12-02 03:52:50 +0400
committerAnton <anton@picapica.im>2026-12-02 03:52:50 +0400
commitc3298beb0779a8cc09b6d4ea0d2132c0612ea776 (patch)
tree910842506249d59a05cae4a72229b61049fcab19 /pica-client/qrcode.h
parent56863d74399c8d7354a00bc8ddc87b924ef870ab (diff)
downloadpica-pica-qr_codes.tar.gz
pica-pica-qr_codes.zip
pica-client: show and scan contact ID as a QR codeqr_codes
Diffstat (limited to 'pica-client/qrcode.h')
-rw-r--r--pica-client/qrcode.h67
1 files changed, 67 insertions, 0 deletions
diff --git a/pica-client/qrcode.h b/pica-client/qrcode.h
new file mode 100644
index 0000000..30b9564
--- /dev/null
+++ b/pica-client/qrcode.h
@@ -0,0 +1,67 @@
+/*
+ (c) Copyright 2012 - 2026 Anton Sviridenko
+ https://picapica.im
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, version 3.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+#ifndef QRCODE_H
+#define QRCODE_H
+
+// Pica Pica IDs as QR codes, through ZXing-C++. Only built with HAVE_QRCODE.
+//
+// What a code carries is the ID exactly as the "Show My Pica Pica ID" dialog
+// shows it and the "Add Contact" one takes it - its base64 text - so a code can
+// equally be read by any phone's scanner app and pasted by hand.
+
+#include <QObject>
+#include <QImage>
+#include <QString>
+#include <QByteArray>
+
+// The QR code for text: one pixel per module, dark modules black and light
+// ones white, with quietZone light modules all round - the QR specification
+// asks for 4, without which a scanner may not find where the code begins.
+// Meant to be scaled up by a whole factor with Qt::FastTransformation, which
+// keeps the modules sharp. A null image if the text could not be encoded.
+QImage picaQrCodeImage(const QString &text, int quietZone = 4);
+
+// The Pica Pica ID a scanned code's text is the base64 form of, or an empty
+// QByteArray if it is not one - the same rule the "Add Contact" dialog applies
+// to what is typed into it.
+QByteArray picaIdFromQrText(const QString &text);
+
+// Looks for a QR code in camera frames. Lives on a thread of its own: reading a
+// 720p frame takes a few tens of milliseconds, too long for the GUI thread at
+// the rate a camera delivers frames.
+//
+// The caller is meant to hand it a frame only when it has answered the previous
+// one, through frameRead(), and to drop the frames in between - a reader that
+// fell behind would only ever be looking at the past.
+class QrCodeReader : public QObject
+{
+ Q_OBJECT
+public:
+ explicit QrCodeReader(QObject *parent = nullptr);
+
+public slots:
+ // Reads one frame - any QImage format, Format_RGB32 being what the camera
+ // delivers and what is read without a conversion - and answers with
+ // frameRead().
+ void read(QImage frame);
+
+signals:
+ // The text of the QR code found in the frame, empty if none was found.
+ void frameRead(QString text);
+};
+
+#endif // QRCODE_H