EstervQrCode 1.1.1
Library for qr code manipulation
qr_image_decoder.hpp
1 #include<QObject>
2 #include<QString>
3 #include <QtQml/qqmlregistration.h>
4 #include<QImage>
5 #include<QBuffer>
6 #include <qquickimageprovider.h>
7 
8 #ifndef USE_EMSCRIPTEN
9 #include <QMediaDevices>
10 #include <QCameraDevice>
11 #include <QCamera>
12 #include <QMediaCaptureSession>
13 #include <QVideoSink>
14 #endif
15 
16 #include <esterv/utils/qrcode_dec.hpp>
17 
18 
19 #if defined(QTQRDEC_SHARED)
20 #include <QtCore/QtGlobal>
21  #ifdef WINDOWS_EXPORT
22  #define DEC_EXPORT Q_DECL_EXPORT
23  #else
24  #define DEC_EXPORT Q_DECL_IMPORT
25  #endif
26 #else
27  #define DEC_EXPORT
28 #endif
29 
30 namespace Esterv::Utils::QrDec
31 {
32 class DEC_EXPORT QRImageDecoder : public QObject
33 {
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 public:
43  static QRImageDecoder* instance();
44  static QRImageDecoder *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine)
45  {
46  return instance();
47  }
48  enum State {
49  Decoding = 0,
50  Ready
51  };
52  Q_INVOKABLE void start();
53  Q_INVOKABLE void stop();
54  Q_INVOKABLE void clear();
55  QString get_source(void)const{return m_source;}
56 
57 
58  void reload(int offset, int width, int height);
59 signals:
60  void decodedQR(QString);
61  void sourceChanged();
62  void hasTorchChanged();
63  void useTorchChanged();
64 private:
65  State m_state;
66 #ifndef USE_EMSCRIPTEN
67  QCamera* m_camera;
68  QMediaCaptureSession* captureSession;
69  QVideoSink* videoSink;
70  void getCamera(void);
71 #endif
72  void setid();
73  void decodePicture(QImage picture);
74  QString m_source;
75  QRDecoder detector;
76  bool m_useTorch,m_hasTorch;
77  static QRImageDecoder* m_instance;
78 };
79 
80 
81 class DEC_EXPORT WasmImageProvider : public QQuickImageProvider
82 {
83 public:
84  WasmImageProvider():QQuickImageProvider(QQuickImageProvider::Image)
85  {
86  restart();
87  }
88  QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize) override;
89  static void restart(void);
90  static QImage img;
91 };
92 }
Definition: qrcode_dec.hpp:8
Definition: qr_image_decoder.hpp:33
State
Definition: qr_image_decoder.hpp:48
static QRImageDecoder * create(QQmlEngine *qmlEngine, QJSEngine *jsEngine)
Definition: qr_image_decoder.hpp:44
QString get_source(void) const
Definition: qr_image_decoder.hpp:55
Definition: qr_image_decoder.hpp:82
WasmImageProvider()
Definition: qr_image_decoder.hpp:84
static QImage img
Definition: qr_image_decoder.hpp:90
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:6