| 1 | // Copyright (C) 2016 The Qt Company Ltd. | 
|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only | 
|---|
| 3 |  | 
|---|
| 4 | #ifndef QCAMERAIMAGECAPTURE_H | 
|---|
| 5 | #define QCAMERAIMAGECAPTURE_H | 
|---|
| 6 |  | 
|---|
| 7 | #include <QtCore/qobject.h> | 
|---|
| 8 | #include <QtMultimedia/qvideoframe.h> | 
|---|
| 9 |  | 
|---|
| 10 | QT_BEGIN_NAMESPACE | 
|---|
| 11 |  | 
|---|
| 12 | class QSize; | 
|---|
| 13 | class QMediaMetaData; | 
|---|
| 14 | QT_END_NAMESPACE | 
|---|
| 15 |  | 
|---|
| 16 | QT_BEGIN_NAMESPACE | 
|---|
| 17 |  | 
|---|
| 18 | class QImageEncoderSettings; | 
|---|
| 19 | class QCamera; | 
|---|
| 20 | class QMediaCaptureSession; | 
|---|
| 21 |  | 
|---|
| 22 | class QImageCapturePrivate; | 
|---|
| 23 | class Q_MULTIMEDIA_EXPORT QImageCapture : public QObject | 
|---|
| 24 | { | 
|---|
| 25 | Q_OBJECT | 
|---|
| 26 | Q_PROPERTY(bool readyForCapture READ isReadyForCapture NOTIFY readyForCaptureChanged) | 
|---|
| 27 | Q_PROPERTY(QMediaMetaData metaData READ metaData WRITE setMetaData NOTIFY metaDataChanged) | 
|---|
| 28 | Q_PROPERTY(Error error READ error NOTIFY errorChanged) | 
|---|
| 29 | Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged) | 
|---|
| 30 | Q_PROPERTY(FileFormat fileFormat READ fileFormat WRITE setFileFormat NOTIFY fileFormatChanged) | 
|---|
| 31 | Q_PROPERTY(Quality quality READ quality WRITE setQuality NOTIFY qualityChanged) | 
|---|
| 32 | public: | 
|---|
| 33 | enum Error | 
|---|
| 34 | { | 
|---|
| 35 | NoError, | 
|---|
| 36 | NotReadyError, | 
|---|
| 37 | ResourceError, | 
|---|
| 38 | OutOfSpaceError, | 
|---|
| 39 | NotSupportedFeatureError, | 
|---|
| 40 | FormatError | 
|---|
| 41 | }; | 
|---|
| 42 | Q_ENUM(Error) | 
|---|
| 43 |  | 
|---|
| 44 | enum Quality | 
|---|
| 45 | { | 
|---|
| 46 | VeryLowQuality, | 
|---|
| 47 | LowQuality, | 
|---|
| 48 | NormalQuality, | 
|---|
| 49 | HighQuality, | 
|---|
| 50 | VeryHighQuality | 
|---|
| 51 | }; | 
|---|
| 52 | Q_ENUM(Quality) | 
|---|
| 53 |  | 
|---|
| 54 | enum FileFormat { | 
|---|
| 55 | UnspecifiedFormat, | 
|---|
| 56 | JPEG, | 
|---|
| 57 | PNG, | 
|---|
| 58 | WebP, | 
|---|
| 59 | Tiff, | 
|---|
| 60 | LastFileFormat = Tiff | 
|---|
| 61 | }; | 
|---|
| 62 | Q_ENUM(FileFormat) | 
|---|
| 63 |  | 
|---|
| 64 | explicit QImageCapture(QObject *parent = nullptr); | 
|---|
| 65 | ~QImageCapture() override; | 
|---|
| 66 |  | 
|---|
| 67 | bool isAvailable() const; | 
|---|
| 68 |  | 
|---|
| 69 | QMediaCaptureSession *captureSession() const; | 
|---|
| 70 |  | 
|---|
| 71 | Error error() const; | 
|---|
| 72 | QString errorString() const; | 
|---|
| 73 |  | 
|---|
| 74 | bool isReadyForCapture() const; | 
|---|
| 75 |  | 
|---|
| 76 | FileFormat fileFormat() const; | 
|---|
| 77 | void setFileFormat(FileFormat format); | 
|---|
| 78 |  | 
|---|
| 79 | static QList<FileFormat> supportedFormats(); | 
|---|
| 80 | static QString fileFormatName(FileFormat c); | 
|---|
| 81 | static QString fileFormatDescription(FileFormat c); | 
|---|
| 82 |  | 
|---|
| 83 | QSize resolution() const; | 
|---|
| 84 | void setResolution(const QSize &); | 
|---|
| 85 | void setResolution(int width, int height); | 
|---|
| 86 |  | 
|---|
| 87 | Quality quality() const; | 
|---|
| 88 | void setQuality(Quality quality); | 
|---|
| 89 |  | 
|---|
| 90 | QMediaMetaData metaData() const; | 
|---|
| 91 | void setMetaData(const QMediaMetaData &metaData); | 
|---|
| 92 | void addMetaData(const QMediaMetaData &metaData); | 
|---|
| 93 |  | 
|---|
| 94 | public Q_SLOTS: | 
|---|
| 95 | int captureToFile(const QString &location = QString()); | 
|---|
| 96 | int capture(); | 
|---|
| 97 |  | 
|---|
| 98 | Q_SIGNALS: | 
|---|
| 99 | void errorChanged(); | 
|---|
| 100 | void errorOccurred(int id, QImageCapture::Error error, const QString &errorString); | 
|---|
| 101 |  | 
|---|
| 102 | void readyForCaptureChanged(bool ready); | 
|---|
| 103 | void metaDataChanged(); | 
|---|
| 104 |  | 
|---|
| 105 | void fileFormatChanged(); | 
|---|
| 106 | void qualityChanged(); | 
|---|
| 107 | void resolutionChanged(); | 
|---|
| 108 |  | 
|---|
| 109 | void imageExposed(int id); | 
|---|
| 110 | void imageCaptured(int id, const QImage &preview); | 
|---|
| 111 | void imageMetadataAvailable(int id, const QMediaMetaData &metaData); | 
|---|
| 112 | void imageAvailable(int id, const QVideoFrame &frame); | 
|---|
| 113 | void imageSaved(int id, const QString &fileName); | 
|---|
| 114 |  | 
|---|
| 115 | private: | 
|---|
| 116 | // This is here to flag an incompatibilities with Qt 5 | 
|---|
| 117 | QImageCapture(QCamera *) = delete; | 
|---|
| 118 |  | 
|---|
| 119 | friend class QMediaCaptureSession; | 
|---|
| 120 | class QPlatformImageCapture *platformImageCapture(); | 
|---|
| 121 | void setCaptureSession(QMediaCaptureSession *session); | 
|---|
| 122 | QImageCapturePrivate *d_ptr; | 
|---|
| 123 | Q_DISABLE_COPY(QImageCapture) | 
|---|
| 124 | Q_DECLARE_PRIVATE(QImageCapture) | 
|---|
| 125 | Q_PRIVATE_SLOT(d_func(), void _q_error(int, int, const QString &)) | 
|---|
| 126 | }; | 
|---|
| 127 |  | 
|---|
| 128 | QT_END_NAMESPACE | 
|---|
| 129 |  | 
|---|
| 130 | #endif | 
|---|
| 131 |  | 
|---|
| 132 |  | 
|---|