1// Copyright (C) 2021 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 QPLATFORMCAMERA_H
5#define QPLATFORMCAMERA_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "qplatformvideosource_p.h"
19
20#include <QtMultimedia/qcamera.h>
21
22QT_BEGIN_NAMESPACE
23
24class Q_MULTIMEDIA_EXPORT QPlatformCamera : public QPlatformVideoSource
25{
26 Q_OBJECT
27
28public:
29 virtual void setCamera(const QCameraDevice &camera) = 0;
30 virtual bool setCameraFormat(const QCameraFormat &/*format*/) { return false; }
31 QCameraFormat cameraFormat() const { return m_cameraFormat; }
32
33 virtual bool isFocusModeSupported(QCamera::FocusMode mode) const { return mode == QCamera::FocusModeAuto; }
34 virtual void setFocusMode(QCamera::FocusMode /*mode*/) {}
35
36 virtual void setCustomFocusPoint(const QPointF &/*point*/) {}
37
38 virtual void setFocusDistance(float) {}
39
40 // smaller 0: zoom instantly, rate in power-of-two/sec
41 virtual void zoomTo(float /*newZoomFactor*/, float /*rate*/ = -1.) {}
42
43 virtual void setFlashMode(QCamera::FlashMode /*mode*/) {}
44 virtual bool isFlashModeSupported(QCamera::FlashMode mode) const { return mode == QCamera::FlashOff; }
45 virtual bool isFlashReady() const { return false; }
46
47 virtual void setTorchMode(QCamera::TorchMode /*mode*/) {}
48 virtual bool isTorchModeSupported(QCamera::TorchMode mode) const { return mode == QCamera::TorchOff; }
49
50 virtual void setExposureMode(QCamera::ExposureMode) {}
51 virtual bool isExposureModeSupported(QCamera::ExposureMode mode) const { return mode == QCamera::ExposureAuto; }
52 virtual void setExposureCompensation(float) {}
53 virtual int isoSensitivity() const { return 100; }
54 virtual void setManualIsoSensitivity(int) {}
55 virtual void setManualExposureTime(float) {}
56 virtual float exposureTime() const { return -1.; }
57
58 virtual bool isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const { return mode == QCamera::WhiteBalanceAuto; }
59 virtual void setWhiteBalanceMode(QCamera::WhiteBalanceMode /*mode*/) {}
60 virtual void setColorTemperature(int /*temperature*/) {}
61
62 QVideoFrameFormat frameFormat() const override;
63
64 QCamera::Features supportedFeatures() const { return m_supportedFeatures; }
65
66 QCamera::FocusMode focusMode() const { return m_focusMode; }
67 QPointF focusPoint() const { return m_customFocusPoint; }
68
69 float minZoomFactor() const { return m_minZoom; }
70 float maxZoomFactor() const { return m_maxZoom; }
71 float zoomFactor() const { return m_zoomFactor; }
72 QPointF customFocusPoint() const { return m_customFocusPoint; }
73 float focusDistance() const { return m_focusDistance; }
74
75 QCamera::FlashMode flashMode() const { return m_flashMode; }
76 QCamera::TorchMode torchMode() const { return m_torchMode; }
77
78 QCamera::ExposureMode exposureMode() const { return m_exposureMode; }
79 float exposureCompensation() const { return m_exposureCompensation; }
80 int manualIsoSensitivity() const { return m_iso; }
81 int minIso() const { return m_minIso; }
82 int maxIso() const { return m_maxIso; }
83 float manualExposureTime() const { return m_exposureTime; }
84 float minExposureTime() const { return m_minExposureTime; }
85 float maxExposureTime() const { return m_maxExposureTime; }
86 QCamera::WhiteBalanceMode whiteBalanceMode() const { return m_whiteBalance; }
87 int colorTemperature() const { return m_colorTemperature; }
88
89 void supportedFeaturesChanged(QCamera::Features);
90 void minimumZoomFactorChanged(float factor);
91 void maximumZoomFactorChanged(float);
92 void focusModeChanged(QCamera::FocusMode mode);
93 void customFocusPointChanged(const QPointF &point);
94 void focusDistanceChanged(float d);
95 void zoomFactorChanged(float zoom);
96 void flashReadyChanged(bool);
97 void flashModeChanged(QCamera::FlashMode mode);
98 void torchModeChanged(QCamera::TorchMode mode);
99 void exposureModeChanged(QCamera::ExposureMode mode);
100 void exposureCompensationChanged(float compensation);
101 void exposureCompensationRangeChanged(float min, float max);
102 void isoSensitivityChanged(int iso);
103 void minIsoChanged(int iso) { m_minIso = iso; }
104 void maxIsoChanged(int iso) { m_maxIso = iso; }
105 void exposureTimeChanged(float speed);
106 void minExposureTimeChanged(float secs) { m_minExposureTime = secs; }
107 void maxExposureTimeChanged(float secs) { m_maxExposureTime = secs; }
108 void whiteBalanceModeChanged(QCamera::WhiteBalanceMode mode);
109 void colorTemperatureChanged(int temperature);
110
111 static int colorTemperatureForWhiteBalance(QCamera::WhiteBalanceMode mode);
112
113Q_SIGNALS:
114 void error(int error, const QString &errorString);
115
116protected:
117 explicit QPlatformCamera(QCamera *parent);
118
119 virtual int cameraPixelFormatScore(QVideoFrameFormat::PixelFormat /*format*/,
120 QVideoFrameFormat::ColorRange /*colorRange*/) const
121 {
122 return 0;
123 }
124
125 QCameraFormat findBestCameraFormat(const QCameraDevice &camera) const;
126 QCameraFormat m_cameraFormat;
127 QVideoFrameFormat::PixelFormat m_framePixelFormat = QVideoFrameFormat::Format_Invalid;
128
129private:
130 QCamera *m_camera = nullptr;
131 QCamera::Features m_supportedFeatures = {};
132 QCamera::FocusMode m_focusMode = QCamera::FocusModeAuto;
133 float m_minZoom = 1.;
134 float m_maxZoom = 1.;
135 float m_zoomFactor = 1.;
136 float m_focusDistance = 1.;
137 QPointF m_customFocusPoint{-1, -1};
138 bool m_flashReady = false;
139 QCamera::FlashMode m_flashMode = QCamera::FlashOff;
140 QCamera::TorchMode m_torchMode = QCamera::TorchOff;
141 QCamera::ExposureMode m_exposureMode = QCamera::ExposureAuto;
142 float m_exposureCompensation = 0.;
143 float m_minExposureCompensation = 0.;
144 float m_maxExposureCompensation = 0.;
145 int m_iso = -1;
146 int m_minIso = -1;
147 int m_maxIso = -1;
148 float m_exposureTime = -1.;
149 float m_minExposureTime = -1.;
150 float m_maxExposureTime = -1.;
151 QCamera::WhiteBalanceMode m_whiteBalance = QCamera::WhiteBalanceAuto;
152 int m_colorTemperature = 0;
153};
154
155QT_END_NAMESPACE
156
157
158#endif // QPLATFORMCAMERA_H
159
160

source code of qtmultimedia/src/multimedia/platform/qplatformcamera_p.h