diff options
Diffstat (limited to 'pica-client/qrcode.h')
| -rw-r--r-- | pica-client/qrcode.h | 67 |
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 |
