Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qplatformcamera.cpp
Go to the documentation of this file.
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#include "qplatformcamera_p.h"
5
7
9{
10 qRegisterMetaType<QVideoFrame>();
11}
12
14{
15 // check if fmt is better. We try to find the highest resolution that offers
16 // at least 30 FPS
17 // we use 29 FPS to compare against as some cameras report 29.97 FPS...
18
19 auto makeCriteria = [this](const QCameraFormat &fmt) {
20 constexpr float MinSufficientFrameRate = 29.f;
21
22 const auto isValid = fmt.pixelFormat() != QVideoFrameFormat::Format_Invalid;
23 const auto resolution = fmt.resolution();
24 const auto sufficientFrameRate = std::min(fmt.maxFrameRate(), MinSufficientFrameRate);
25
26 return std::make_tuple(
27 isValid, // 1st: ensure valid formats
28 sufficientFrameRate, // 2nd: ensure the highest frame rate in the range [0; 29]*/
29 resolution.width() * resolution.height(), // 3rd: ensure the highest resolution
30 cameraPixelFormatScore(fmt.pixelFormat()),
31 fmt.maxFrameRate()); // 4th: ensure the highest framerate in the whole range
32 };
33
34 const auto formats = camera.videoFormats();
35 const auto found =
36 std::max_element(formats.begin(), formats.end(),
37 [makeCriteria](const QCameraFormat &fmtA, const QCameraFormat &fmtB) {
38 return makeCriteria(fmtA) < makeCriteria(fmtB);
39 });
40
41 return found == formats.end() ? QCameraFormat{} : *found;
42}
43
45{
50 result.setFrameRate(m_cameraFormat.maxFrameRate());
51 return result;
52}
53
55{
56 if (m_supportedFeatures == f)
57 return;
58 m_supportedFeatures = f;
60}
61
63{
64 if (m_minZoom == factor)
65 return;
66 m_minZoom = factor;
67 emit m_camera->minimumZoomFactorChanged(factor);
68}
69
71{
72 if (m_maxZoom == factor)
73 return;
74 m_maxZoom = factor;
75 emit m_camera->maximumZoomFactorChanged(factor);
76}
77
79{
80 if (m_focusMode == mode)
81 return;
82 m_focusMode = mode;
83 emit m_camera->focusModeChanged();
84}
85
87{
88 if (m_customFocusPoint == point)
89 return;
90 m_customFocusPoint = point;
91 emit m_camera->customFocusPointChanged();
92}
93
94
96{
97 if (m_zoomFactor == zoom)
98 return;
99 m_zoomFactor = zoom;
100 emit m_camera->zoomFactorChanged(zoom);
101}
102
103
105{
106 if (m_focusDistance == d)
107 return;
108 m_focusDistance = d;
109 emit m_camera->focusDistanceChanged(m_focusDistance);
110}
111
112
114{
115 if (m_flashReady == ready)
116 return;
117 m_flashReady = ready;
118 emit m_camera->flashReady(m_flashReady);
119}
120
122{
123 if (m_flashMode == mode)
124 return;
125 m_flashMode = mode;
126 emit m_camera->flashModeChanged();
127}
128
130{
131 if (m_torchMode == mode)
132 return;
133 m_torchMode = mode;
134 emit m_camera->torchModeChanged();
135}
136
138{
139 if (m_exposureMode == mode)
140 return;
141 m_exposureMode = mode;
142 emit m_camera->exposureModeChanged();
143}
144
146{
147 if (m_exposureCompensation == compensation)
148 return;
149 m_exposureCompensation = compensation;
150 emit m_camera->exposureCompensationChanged(compensation);
151}
152
154{
155 if (m_minExposureCompensation == min && m_maxExposureCompensation == max)
156 return;
157 m_minExposureCompensation = min;
158 m_maxExposureCompensation = max;
159 // tell frontend
160}
161
163{
164 if (m_iso == iso)
165 return;
166 m_iso = iso;
167 emit m_camera->isoSensitivityChanged(iso);
168}
169
171{
172 if (m_exposureTime == speed)
173 return;
174 m_exposureTime = speed;
175 emit m_camera->exposureTimeChanged(speed);
176}
177
179{
180 if (m_whiteBalance == mode)
181 return;
182 m_whiteBalance = mode;
183 emit m_camera->whiteBalanceModeChanged();
184}
185
187{
188 Q_ASSERT(temperature >= 0);
189 Q_ASSERT((temperature > 0 && whiteBalanceMode() == QCamera::WhiteBalanceManual) ||
190 (temperature == 0 && whiteBalanceMode() == QCamera::WhiteBalanceAuto));
191 if (m_colorTemperature == temperature)
192 return;
193 m_colorTemperature = temperature;
194 emit m_camera->colorTemperatureChanged();
195}
196
198{
199 switch (mode) {
201 break;
204 return 5600;
206 return 6000;
208 return 7000;
210 return 3200;
212 return 4000;
214 return 5500;
216 return 3000;
217 }
218 return 0;
219}
220
222
223#include "moc_qplatformcamera_p.cpp"
The QCameraDevice class provides general information about camera devices.
The QCameraFormat class describes a video format supported by a camera device. \inmodule QtMultimedia...
QSize resolution
\qmlproperty size QtMultimedia::cameraFormat::resolution
QVideoFrameFormat::PixelFormat pixelFormat
\qmlproperty enumeration QtMultimedia::cameraFormat::pixelFormat
float maxFrameRate
\qmlproperty real QtMultimedia::cameraFormat::maxFrameRate
The QCamera class provides interface for system camera devices.
Definition qcamera.h:28
WhiteBalanceMode
\value WhiteBalanceAuto Auto white balance mode.
Definition qcamera.h:112
@ WhiteBalanceShade
Definition qcamera.h:117
@ WhiteBalanceCloudy
Definition qcamera.h:116
@ WhiteBalanceSunset
Definition qcamera.h:121
@ WhiteBalanceManual
Definition qcamera.h:114
@ WhiteBalanceSunlight
Definition qcamera.h:115
@ WhiteBalanceFlash
Definition qcamera.h:120
@ WhiteBalanceTungsten
Definition qcamera.h:118
@ WhiteBalanceFluorescent
Definition qcamera.h:119
@ WhiteBalanceAuto
Definition qcamera.h:113
TorchMode
\value TorchOff Torch is Off.
Definition qcamera.h:84
void exposureModeChanged()
void focusDistanceChanged(float)
FocusMode
\value FocusModeAuto Continuous auto focus mode.
Definition qcamera.h:67
void customFocusPointChanged()
void maximumZoomFactorChanged(float)
void flashModeChanged()
void exposureCompensationChanged(float)
Signal emitted when the exposure compensation changes to value.
void exposureTimeChanged(float speed)
Signals that a camera's exposure speed has changed.
void supportedFeaturesChanged()
void focusModeChanged()
Signals when the focusMode changes.
void colorTemperatureChanged() QT6_ONLY(const)
void whiteBalanceModeChanged() QT6_ONLY(const)
void minimumZoomFactorChanged(float)
FlashMode
\value FlashOff Flash is Off.
Definition qcamera.h:77
void torchModeChanged()
ExposureMode
\value ExposureAuto Automatic mode.
Definition qcamera.h:91
void zoomFactorChanged(float)
bool flashReady
\qmlproperty bool QtMultimedia::Camera::flashReady
Definition qcamera.h:51
void isoSensitivityChanged(int)
Signal emitted when sensitivity changes to value.
QVideoFrameFormat::PixelFormat m_framePixelFormat
QCameraFormat findBestCameraFormat(const QCameraDevice &camera) const
void isoSensitivityChanged(int iso)
void torchModeChanged(QCamera::TorchMode mode)
void flashReadyChanged(bool)
QCamera::WhiteBalanceMode whiteBalanceMode() const
void focusModeChanged(QCamera::FocusMode mode)
void exposureCompensationChanged(float compensation)
void whiteBalanceModeChanged(QCamera::WhiteBalanceMode mode)
void focusDistanceChanged(float d)
virtual int cameraPixelFormatScore(QVideoFrameFormat::PixelFormat) const
static int colorTemperatureForWhiteBalance(QCamera::WhiteBalanceMode mode)
void maximumZoomFactorChanged(float)
void customFocusPointChanged(const QPointF &point)
void flashModeChanged(QCamera::FlashMode mode)
void zoomFactorChanged(float zoom)
void colorTemperatureChanged(int temperature)
QVideoFrameFormat frameFormat() const override
QPlatformCamera(QCamera *parent)
void exposureModeChanged(QCamera::ExposureMode mode)
void supportedFeaturesChanged(QCamera::Features)
void minimumZoomFactorChanged(float factor)
void exposureCompensationRangeChanged(float min, float max)
QCameraFormat m_cameraFormat
void exposureTimeChanged(float speed)
\inmodule QtCore\reentrant
Definition qpoint.h:214
The QVideoFrameFormat class specifies the stream format of a video presentation surface.
QCamera * camera
Definition camera.cpp:19
EGLint EGLint * formats
Combined button and popup list for selecting options.
GLenum mode
GLfloat GLfloat f
GLuint64EXT * result
[6]
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define emit
QVideoFrameFormat::PixelFormat fmt
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent