EstervQrCode 2.0.0
Library for qr code manipulation
Loading...
Searching...
No Matches
qr_image_decoder.hpp
1#include <QBuffer>
2#include <QImage>
3#include <QObject>
4#include <QString>
5#include <QtQml/qqmlregistration.h>
6
7#include <qquickimageprovider.h>
8
9#ifndef USE_EMSCRIPTEN
10#include <QCamera>
11#include <QCameraDevice>
12#include <QMediaCaptureSession>
13#include <QMediaDevices>
14#include <QVideoSink>
15#include <condition_variable>
16#include <mutex>
17#endif
18
19#include <esterv/utils/qrcode_dec.hpp>
20
21#if defined(QTQRDEC_SHARED)
22#include <QtCore/QtGlobal>
23#ifdef WINDOWS_EXPORT
24#define DEC_EXPORT Q_DECL_EXPORT
25#else
26#define DEC_EXPORT Q_DECL_IMPORT
27#endif
28#else
29#define DEC_EXPORT
30#endif
31
32namespace Esterv::Utils::QrDec {
33class DEC_EXPORT QRImageDecoder : public QObject {
34 Q_OBJECT
35 Q_PROPERTY(QString source READ get_source NOTIFY sourceChanged)
36 Q_PROPERTY(bool useTorch MEMBER m_useTorch NOTIFY useTorchChanged)
37 Q_PROPERTY(bool hasTorch MEMBER m_hasTorch NOTIFY hasTorchChanged)
38 QML_ELEMENT
39 QML_SINGLETON
40
41 QRImageDecoder(QObject *parent = nullptr);
42
43public:
44 ~QRImageDecoder() override {
45 {
46 std::lock_guard lk(m_decoding_mutex);
47 m_decode_running = false;
48 }
49 m_decoding_variable.notify_one();
50 }
51 static QRImageDecoder *instance();
52 static QRImageDecoder *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine) {
53 return instance();
54 }
55 enum State { Decoding = 0, Ready };
56 Q_INVOKABLE void start();
57 Q_INVOKABLE void stop();
58 Q_INVOKABLE void clear();
59 QString get_source(void) const { return m_source; }
60
61 void reload(int offset, int width, int height);
62signals:
63 void decodedQR(QString);
64 void sourceChanged();
65 void hasTorchChanged();
66 void useTorchChanged();
67
68private:
69 State m_state{Ready};
70 std::mutex m_decoding_mutex;
71 std::condition_variable m_decoding_variable;
72 bool m_decode_running{true};
73#ifndef USE_EMSCRIPTEN
74 QCamera *m_camera{nullptr};
75 QMediaCaptureSession *captureSession;
76 QVideoSink *videoSink;
77 void getCamera(void);
78#endif
79 void setid();
80 void decodePicture();
81 QString m_source;
82 QRDecoder detector;
83 bool m_useTorch{false}, m_hasTorch{false};
84};
85
86class DEC_EXPORT WasmImageProvider : public QQuickImageProvider {
87public:
88 WasmImageProvider() : QQuickImageProvider(QQuickImageProvider::Image) {
89 restart();
90 }
91 QImage requestImage(const QString &id, QSize *size,
92 const QSize &requestedSize) override;
93 static void restart(void);
94 static QImage img;
95};
96} // namespace Esterv::Utils::QrDec
Definition qr_image_decoder.hpp:33
State
Definition qr_image_decoder.hpp:55
QString get_source(void) const
Definition qr_image_decoder.hpp:59
static QRImageDecoder * create(QQmlEngine *qmlEngine, QJSEngine *jsEngine)
Definition qr_image_decoder.hpp:52
Definition qr_image_decoder.hpp:86
WasmImageProvider()
Definition qr_image_decoder.hpp:88
static QImage img
Definition qr_image_decoder.hpp:94
double start
Definition core_c.h:1381
void * parent
Definition core_c.h:1913
CvSize size
Definition core_c.h:112
CvArr CvPoint offset
Definition imgproc_c.h:88
Definition qrcode_dec.hpp:5