| 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 | Q_PROPERTY(QList<FileFormat> supportedFormats READ supportedFormats CONSTANT REVISION(6, 10)) |
| 33 | public: |
| 34 | enum Error |
| 35 | { |
| 36 | NoError, |
| 37 | NotReadyError, |
| 38 | ResourceError, |
| 39 | OutOfSpaceError, |
| 40 | NotSupportedFeatureError, |
| 41 | FormatError |
| 42 | }; |
| 43 | Q_ENUM(Error) |
| 44 | |
| 45 | enum Quality |
| 46 | { |
| 47 | VeryLowQuality, |
| 48 | LowQuality, |
| 49 | NormalQuality, |
| 50 | HighQuality, |
| 51 | VeryHighQuality |
| 52 | }; |
| 53 | Q_ENUM(Quality) |
| 54 | |
| 55 | enum FileFormat { |
| 56 | UnspecifiedFormat, |
| 57 | JPEG, |
| 58 | PNG, |
| 59 | WebP, |
| 60 | Tiff, |
| 61 | LastFileFormat = Tiff |
| 62 | }; |
| 63 | Q_ENUM(FileFormat) |
| 64 | |
| 65 | explicit QImageCapture(QObject *parent = nullptr); |
| 66 | ~QImageCapture() override; |
| 67 | |
| 68 | bool isAvailable() const; |
| 69 | |
| 70 | QMediaCaptureSession *captureSession() const; |
| 71 | |
| 72 | Error error() const; |
| 73 | QString errorString() const; |
| 74 | |
| 75 | bool isReadyForCapture() const; |
| 76 | |
| 77 | FileFormat fileFormat() const; |
| 78 | void setFileFormat(FileFormat format); |
| 79 | |
| 80 | static QList<FileFormat> supportedFormats(); |
| 81 | static QString fileFormatName(FileFormat c); |
| 82 | static QString fileFormatDescription(FileFormat c); |
| 83 | |
| 84 | QSize resolution() const; |
| 85 | void setResolution(const QSize &); |
| 86 | void setResolution(int width, int height); |
| 87 | |
| 88 | Quality quality() const; |
| 89 | void setQuality(Quality quality); |
| 90 | |
| 91 | QMediaMetaData metaData() const; |
| 92 | void setMetaData(const QMediaMetaData &metaData); |
| 93 | void addMetaData(const QMediaMetaData &metaData); |
| 94 | |
| 95 | public Q_SLOTS: |
| 96 | int captureToFile(const QString &location = QString()); |
| 97 | int capture(); |
| 98 | |
| 99 | Q_SIGNALS: |
| 100 | void errorChanged(); |
| 101 | void errorOccurred(int id, QImageCapture::Error error, const QString &errorString); |
| 102 | |
| 103 | void readyForCaptureChanged(bool ready); |
| 104 | void metaDataChanged(); |
| 105 | |
| 106 | void fileFormatChanged(); |
| 107 | void qualityChanged(); |
| 108 | void resolutionChanged(); |
| 109 | |
| 110 | void imageExposed(int id); |
| 111 | void imageCaptured(int id, const QImage &preview); |
| 112 | void imageMetadataAvailable(int id, const QMediaMetaData &metaData); |
| 113 | void imageAvailable(int id, const QVideoFrame &frame); |
| 114 | void imageSaved(int id, const QString &fileName); |
| 115 | |
| 116 | private: |
| 117 | // This is here to flag an incompatibilities with Qt 5 |
| 118 | QImageCapture(QCamera *) = delete; |
| 119 | |
| 120 | friend class QMediaCaptureSession; |
| 121 | class QPlatformImageCapture *platformImageCapture(); |
| 122 | void setCaptureSession(QMediaCaptureSession *session); |
| 123 | QImageCapturePrivate *d_ptr; |
| 124 | Q_DISABLE_COPY(QImageCapture) |
| 125 | Q_DECLARE_PRIVATE(QImageCapture) |
| 126 | Q_PRIVATE_SLOT(d_func(), void _q_error(int, int, const QString &)) |
| 127 | }; |
| 128 | |
| 129 | QT_END_NAMESPACE |
| 130 | |
| 131 | #endif |
| 132 | |
| 133 | |