| 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 QCAMERA_H | 
|---|
| 5 | #define QCAMERA_H | 
|---|
| 6 |  | 
|---|
| 7 | #include <QtCore/qstringlist.h> | 
|---|
| 8 | #include <QtCore/qpair.h> | 
|---|
| 9 | #include <QtCore/qsize.h> | 
|---|
| 10 | #include <QtCore/qpoint.h> | 
|---|
| 11 | #include <QtCore/qrect.h> | 
|---|
| 12 |  | 
|---|
| 13 | #include <QtCore/qobject.h> | 
|---|
| 14 |  | 
|---|
| 15 | #include <QtMultimedia/qcameradevice.h> | 
|---|
| 16 |  | 
|---|
| 17 | QT_BEGIN_NAMESPACE | 
|---|
| 18 |  | 
|---|
| 19 |  | 
|---|
| 20 | class QCameraDevice; | 
|---|
| 21 | class QPlatformMediaCaptureSession; | 
|---|
| 22 | class QMediaCaptureSession; | 
|---|
| 23 |  | 
|---|
| 24 | class QCameraPrivate; | 
|---|
| 25 | class Q_MULTIMEDIA_EXPORT QCamera : public QObject | 
|---|
| 26 | { | 
|---|
| 27 | Q_OBJECT | 
|---|
| 28 | Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged) | 
|---|
| 29 | // Qt 7: rename to device | 
|---|
| 30 | Q_PROPERTY(QCameraDevice cameraDevice READ cameraDevice WRITE setCameraDevice NOTIFY cameraDeviceChanged) | 
|---|
| 31 | Q_PROPERTY(Error error READ error NOTIFY errorChanged) | 
|---|
| 32 | Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged) | 
|---|
| 33 | Q_PROPERTY(QCameraFormat cameraFormat READ cameraFormat WRITE setCameraFormat NOTIFY cameraFormatChanged) | 
|---|
| 34 |  | 
|---|
| 35 | Q_PROPERTY(FocusMode focusMode READ focusMode WRITE setFocusMode NOTIFY focusModeChanged) | 
|---|
| 36 | Q_PROPERTY(QPointF focusPoint READ focusPoint NOTIFY focusPointChanged) | 
|---|
| 37 | Q_PROPERTY(QPointF customFocusPoint READ customFocusPoint WRITE setCustomFocusPoint NOTIFY customFocusPointChanged) | 
|---|
| 38 | Q_PROPERTY(float focusDistance READ focusDistance WRITE setFocusDistance NOTIFY focusDistanceChanged) | 
|---|
| 39 |  | 
|---|
| 40 | Q_PROPERTY(float minimumZoomFactor READ minimumZoomFactor NOTIFY minimumZoomFactorChanged) | 
|---|
| 41 | Q_PROPERTY(float maximumZoomFactor READ maximumZoomFactor NOTIFY maximumZoomFactorChanged) | 
|---|
| 42 | Q_PROPERTY(float zoomFactor READ zoomFactor WRITE setZoomFactor NOTIFY zoomFactorChanged) | 
|---|
| 43 | Q_PROPERTY(float exposureTime READ exposureTime NOTIFY exposureTimeChanged) | 
|---|
| 44 | Q_PROPERTY(float manualExposureTime READ manualExposureTime WRITE setManualExposureTime NOTIFY manualExposureTimeChanged) | 
|---|
| 45 | Q_PROPERTY(int isoSensitivity READ isoSensitivity NOTIFY isoSensitivityChanged) | 
|---|
| 46 | Q_PROPERTY(int manualIsoSensitivity READ manualIsoSensitivity WRITE setManualIsoSensitivity NOTIFY manualIsoSensitivityChanged) | 
|---|
| 47 | Q_PROPERTY(float exposureCompensation READ exposureCompensation WRITE setExposureCompensation NOTIFY exposureCompensationChanged) | 
|---|
| 48 | Q_PROPERTY(QCamera::ExposureMode exposureMode READ exposureMode WRITE setExposureMode NOTIFY exposureModeChanged) | 
|---|
| 49 | Q_PROPERTY(bool flashReady READ isFlashReady NOTIFY flashReady) | 
|---|
| 50 | Q_PROPERTY(QCamera::FlashMode flashMode READ flashMode WRITE setFlashMode NOTIFY flashModeChanged) | 
|---|
| 51 | Q_PROPERTY(QCamera::TorchMode torchMode READ torchMode WRITE setTorchMode NOTIFY torchModeChanged) | 
|---|
| 52 |  | 
|---|
| 53 | Q_PROPERTY(WhiteBalanceMode whiteBalanceMode READ whiteBalanceMode WRITE setWhiteBalanceMode NOTIFY whiteBalanceModeChanged) | 
|---|
| 54 | Q_PROPERTY(int colorTemperature READ colorTemperature WRITE setColorTemperature NOTIFY colorTemperatureChanged) | 
|---|
| 55 | Q_PROPERTY(Features supportedFeatures READ supportedFeatures NOTIFY supportedFeaturesChanged) | 
|---|
| 56 |  | 
|---|
| 57 | public: | 
|---|
| 58 | enum Error | 
|---|
| 59 | { | 
|---|
| 60 | NoError, | 
|---|
| 61 | CameraError | 
|---|
| 62 | }; | 
|---|
| 63 | Q_ENUM(Error) | 
|---|
| 64 |  | 
|---|
| 65 | enum FocusMode { | 
|---|
| 66 | FocusModeAuto, | 
|---|
| 67 | FocusModeAutoNear, | 
|---|
| 68 | FocusModeAutoFar, | 
|---|
| 69 | FocusModeHyperfocal, | 
|---|
| 70 | FocusModeInfinity, | 
|---|
| 71 | FocusModeManual | 
|---|
| 72 | }; | 
|---|
| 73 | Q_ENUM(FocusMode) | 
|---|
| 74 |  | 
|---|
| 75 | enum FlashMode { | 
|---|
| 76 | FlashOff, | 
|---|
| 77 | FlashOn, | 
|---|
| 78 | FlashAuto | 
|---|
| 79 | }; | 
|---|
| 80 | Q_ENUM(FlashMode) | 
|---|
| 81 |  | 
|---|
| 82 | enum TorchMode { | 
|---|
| 83 | TorchOff, | 
|---|
| 84 | TorchOn, | 
|---|
| 85 | TorchAuto | 
|---|
| 86 | }; | 
|---|
| 87 | Q_ENUM(TorchMode) | 
|---|
| 88 |  | 
|---|
| 89 | enum ExposureMode { | 
|---|
| 90 | ExposureAuto, | 
|---|
| 91 | ExposureManual, | 
|---|
| 92 | ExposurePortrait, | 
|---|
| 93 | ExposureNight, | 
|---|
| 94 | ExposureSports, | 
|---|
| 95 | ExposureSnow, | 
|---|
| 96 | ExposureBeach, | 
|---|
| 97 | ExposureAction, | 
|---|
| 98 | ExposureLandscape, | 
|---|
| 99 | ExposureNightPortrait, | 
|---|
| 100 | ExposureTheatre, | 
|---|
| 101 | ExposureSunset, | 
|---|
| 102 | ExposureSteadyPhoto, | 
|---|
| 103 | ExposureFireworks, | 
|---|
| 104 | ExposureParty, | 
|---|
| 105 | ExposureCandlelight, | 
|---|
| 106 | ExposureBarcode | 
|---|
| 107 | }; | 
|---|
| 108 | Q_ENUM(ExposureMode) | 
|---|
| 109 |  | 
|---|
| 110 | enum WhiteBalanceMode { | 
|---|
| 111 | WhiteBalanceAuto = 0, | 
|---|
| 112 | WhiteBalanceManual = 1, | 
|---|
| 113 | WhiteBalanceSunlight = 2, | 
|---|
| 114 | WhiteBalanceCloudy = 3, | 
|---|
| 115 | WhiteBalanceShade = 4, | 
|---|
| 116 | WhiteBalanceTungsten = 5, | 
|---|
| 117 | WhiteBalanceFluorescent = 6, | 
|---|
| 118 | WhiteBalanceFlash = 7, | 
|---|
| 119 | WhiteBalanceSunset = 8 | 
|---|
| 120 | }; | 
|---|
| 121 | Q_ENUM(WhiteBalanceMode) | 
|---|
| 122 |  | 
|---|
| 123 | enum class Feature { | 
|---|
| 124 | ColorTemperature = 0x1, | 
|---|
| 125 | ExposureCompensation = 0x2, | 
|---|
| 126 | IsoSensitivity = 0x4, | 
|---|
| 127 | ManualExposureTime = 0x8, | 
|---|
| 128 | CustomFocusPoint = 0x10, | 
|---|
| 129 | FocusDistance = 0x20 | 
|---|
| 130 | }; | 
|---|
| 131 | Q_DECLARE_FLAGS(Features, Feature) | 
|---|
| 132 | Q_FLAG(Features) | 
|---|
| 133 |  | 
|---|
| 134 | explicit QCamera(QObject *parent = nullptr); | 
|---|
| 135 | explicit QCamera(const QCameraDevice& cameraDevice, QObject *parent = nullptr); | 
|---|
| 136 | explicit QCamera(QCameraDevice::Position position, QObject *parent = nullptr); | 
|---|
| 137 | ~QCamera() override; | 
|---|
| 138 |  | 
|---|
| 139 | bool isAvailable() const; | 
|---|
| 140 | bool isActive() const; | 
|---|
| 141 |  | 
|---|
| 142 | QMediaCaptureSession *captureSession() const; | 
|---|
| 143 |  | 
|---|
| 144 | QCameraDevice cameraDevice() const; | 
|---|
| 145 | void setCameraDevice(const QCameraDevice &cameraDevice); | 
|---|
| 146 |  | 
|---|
| 147 | QCameraFormat cameraFormat() const; | 
|---|
| 148 | void setCameraFormat(const QCameraFormat &format); | 
|---|
| 149 |  | 
|---|
| 150 | Error error() const; | 
|---|
| 151 | QString errorString() const; | 
|---|
| 152 |  | 
|---|
| 153 | Features supportedFeatures() const; | 
|---|
| 154 |  | 
|---|
| 155 | FocusMode focusMode() const; | 
|---|
| 156 | void setFocusMode(FocusMode mode); | 
|---|
| 157 | Q_INVOKABLE bool isFocusModeSupported(FocusMode mode) const; | 
|---|
| 158 |  | 
|---|
| 159 | QPointF focusPoint() const; | 
|---|
| 160 |  | 
|---|
| 161 | QPointF customFocusPoint() const; | 
|---|
| 162 | void setCustomFocusPoint(const QPointF &point); | 
|---|
| 163 |  | 
|---|
| 164 | void setFocusDistance(float d); | 
|---|
| 165 | float focusDistance() const; | 
|---|
| 166 |  | 
|---|
| 167 | float minimumZoomFactor() const; | 
|---|
| 168 | float maximumZoomFactor() const; | 
|---|
| 169 | float zoomFactor() const; | 
|---|
| 170 | void setZoomFactor(float factor); | 
|---|
| 171 |  | 
|---|
| 172 | FlashMode flashMode() const; | 
|---|
| 173 | Q_INVOKABLE bool isFlashModeSupported(FlashMode mode) const; | 
|---|
| 174 | Q_INVOKABLE bool isFlashReady() const; | 
|---|
| 175 |  | 
|---|
| 176 | TorchMode torchMode() const; | 
|---|
| 177 | Q_INVOKABLE bool isTorchModeSupported(TorchMode mode) const; | 
|---|
| 178 |  | 
|---|
| 179 | ExposureMode exposureMode() const; | 
|---|
| 180 | Q_INVOKABLE bool isExposureModeSupported(ExposureMode mode) const; | 
|---|
| 181 |  | 
|---|
| 182 | float exposureCompensation() const; | 
|---|
| 183 |  | 
|---|
| 184 | int isoSensitivity() const; | 
|---|
| 185 | int manualIsoSensitivity() const; | 
|---|
| 186 |  | 
|---|
| 187 | float exposureTime() const; | 
|---|
| 188 | float manualExposureTime() const; | 
|---|
| 189 |  | 
|---|
| 190 | int minimumIsoSensitivity() const; | 
|---|
| 191 | int maximumIsoSensitivity() const; | 
|---|
| 192 |  | 
|---|
| 193 | float minimumExposureTime() const; | 
|---|
| 194 | float maximumExposureTime() const; | 
|---|
| 195 |  | 
|---|
| 196 | WhiteBalanceMode whiteBalanceMode() const; | 
|---|
| 197 | Q_INVOKABLE bool isWhiteBalanceModeSupported(WhiteBalanceMode mode) const; | 
|---|
| 198 |  | 
|---|
| 199 | int colorTemperature() const; | 
|---|
| 200 |  | 
|---|
| 201 | public Q_SLOTS: | 
|---|
| 202 | void setActive(bool active); | 
|---|
| 203 | void start() { setActive(true); } | 
|---|
| 204 | void stop() { setActive(false); } | 
|---|
| 205 |  | 
|---|
| 206 | void zoomTo(float zoom, float rate); | 
|---|
| 207 |  | 
|---|
| 208 | void setFlashMode(FlashMode mode); | 
|---|
| 209 | void setTorchMode(TorchMode mode); | 
|---|
| 210 | void setExposureMode(ExposureMode mode); | 
|---|
| 211 |  | 
|---|
| 212 | void setExposureCompensation(float ev); | 
|---|
| 213 |  | 
|---|
| 214 | void setManualIsoSensitivity(int iso); | 
|---|
| 215 | void setAutoIsoSensitivity(); | 
|---|
| 216 |  | 
|---|
| 217 | void setManualExposureTime(float seconds); | 
|---|
| 218 | void setAutoExposureTime(); | 
|---|
| 219 |  | 
|---|
| 220 | void setWhiteBalanceMode(WhiteBalanceMode mode); | 
|---|
| 221 | void setColorTemperature(int colorTemperature); | 
|---|
| 222 |  | 
|---|
| 223 | Q_SIGNALS: | 
|---|
| 224 | void activeChanged(bool); | 
|---|
| 225 | void errorChanged(); | 
|---|
| 226 | void errorOccurred(QCamera::Error error, const QString &errorString); | 
|---|
| 227 | void cameraDeviceChanged(); | 
|---|
| 228 | void cameraFormatChanged(); | 
|---|
| 229 | void supportedFeaturesChanged(); | 
|---|
| 230 |  | 
|---|
| 231 | void focusModeChanged(); | 
|---|
| 232 | void zoomFactorChanged(float); | 
|---|
| 233 | void minimumZoomFactorChanged(float); | 
|---|
| 234 | void maximumZoomFactorChanged(float); | 
|---|
| 235 | void focusDistanceChanged(float); | 
|---|
| 236 | void focusPointChanged(); | 
|---|
| 237 | void customFocusPointChanged(); | 
|---|
| 238 |  | 
|---|
| 239 | void flashReady(bool); | 
|---|
| 240 | void flashModeChanged(); | 
|---|
| 241 | void torchModeChanged(); | 
|---|
| 242 |  | 
|---|
| 243 | void exposureTimeChanged(float speed); | 
|---|
| 244 | void manualExposureTimeChanged(float speed); | 
|---|
| 245 | void isoSensitivityChanged(int); | 
|---|
| 246 | void manualIsoSensitivityChanged(int); | 
|---|
| 247 | void exposureCompensationChanged(float); | 
|---|
| 248 | void exposureModeChanged(); | 
|---|
| 249 |  | 
|---|
| 250 | void whiteBalanceModeChanged() QT6_ONLY(const); | 
|---|
| 251 | void colorTemperatureChanged() QT6_ONLY(const); | 
|---|
| 252 | void brightnessChanged(); | 
|---|
| 253 | void contrastChanged(); | 
|---|
| 254 | void saturationChanged(); | 
|---|
| 255 | void hueChanged(); | 
|---|
| 256 |  | 
|---|
| 257 | private: | 
|---|
| 258 | class QPlatformCamera *platformCamera(); | 
|---|
| 259 | void setCaptureSession(QMediaCaptureSession *session); | 
|---|
| 260 | friend class QMediaCaptureSession; | 
|---|
| 261 | Q_DISABLE_COPY(QCamera) | 
|---|
| 262 | Q_DECLARE_PRIVATE(QCamera) | 
|---|
| 263 | friend class QCameraDevice; | 
|---|
| 264 | }; | 
|---|
| 265 |  | 
|---|
| 266 | Q_DECLARE_OPERATORS_FOR_FLAGS(QCamera::Features) | 
|---|
| 267 |  | 
|---|
| 268 | QT_END_NAMESPACE | 
|---|
| 269 |  | 
|---|
| 270 | #endif  // QCAMERA_H | 
|---|
| 271 |  | 
|---|