Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qcamera.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
5#include "qcamera_p.h"
6
7#include <qcameradevice.h>
8#include <private/qplatformcamera_p.h>
9#include <private/qplatformimagecapture_p.h>
10#include <private/qplatformmediaintegration_p.h>
11#include <private/qplatformmediacapture_p.h>
12#include <qmediadevices.h>
13#include <qmediacapturesession.h>
14
15#include <QDebug>
16
18
19/*!
20 \class QCamera
21
22
23 \brief The QCamera class provides interface for system camera devices.
24
25 \inmodule QtMultimedia
26 \ingroup multimedia
27 \ingroup multimedia_camera
28
29 QCamera can be used within a QMediaCaptureSession for video recording and image taking.
30
31 You can use QCameraDevice to list available cameras and choose which one to use.
32
33 \snippet multimedia-snippets/camera.cpp Camera selection
34
35 On hardware that supports it, \l QCamera lets you adjust the focus
36 and zoom. The \l minimumZoomFactor and \l maximumZoomFactor
37 properties provide the range of supported zoom factors. The
38 \l zoomFactor property allows changing the zoom factor.
39
40 \snippet multimedia-snippets/camera.cpp Camera zoom
41
42 After capturing the raw data for a camera frame, the camera hardware and
43 software performs various image processing tasks to produce the final
44 image. This includes compensating for ambient light color, reducing
45 noise, as well as making some other adjustments to the image.
46
47 You can control many of these processing steps through the Camera properties.
48 For example, you can set the white balance (or color temperature) used
49 for processing images:
50
51 \snippet multimedia-snippets/camera.cpp Camera image whitebalance
52
53 For more information on image processing of camera frames, see
54 \l {camera_image_processing}{Camera Image Processing}.
55
56 Most platforms require that the end-user grants permissions before a
57 camera can be activated. It is therefore strongly recommended that
58 application developers utilize the \l QCameraPermission class when
59 working with cameras. The following is a short example that requests
60 permissions from the end-user when the application starts, and then
61 activates the camera if permissions are granted.
62
63 \snippet multimedia-snippets/camera.cpp Camera permission
64
65 See the \l{Camera Overview}{camera overview} for more information.
66
67 \note On WebAssembly platform, due to its asynchronous nature,
68 QMediaDevices::videoInputsChanged() signal is emitted when the list of
69 video inputs is ready. User permissions are required. Works only on secure https contexts.
70*/
71
72/*!
73 \qmltype Camera
74 \nativetype QCamera
75 \inqmlmodule QtMultimedia
76 \brief An interface for camera settings related to focus and zoom.
77 \ingroup multimedia_qml
78 \ingroup camera_qml
79
80 The Camera element can be used within a \l CaptureSession for video recording
81 and image taking.
82
83 You can use \l MediaDevices to list available cameras and choose which one to use.
84
85 \qml
86 MediaDevices {
87 id: mediaDevices
88 }
89 CaptureSession {
90 camera: Camera {
91 cameraDevice: mediaDevices.defaultVideoInput
92 }
93 }
94 \endqml
95
96 On hardware that supports it, \l Camera lets you adjust the focus
97 and zoom. The \l minimumZoomFactor and \l maximumZoomFactor
98 properties provide the range of supported zoom factors. The
99 \l zoomFactor property allows changing the zoom factor.
100
101 \qml
102 Camera {
103 zoomFactor: maximumZoomFactor // zoom in as much as possible
104 }
105 \endqml
106
107 After capturing the raw data for a camera frame, the camera hardware and
108 software performs various image processing tasks to produce the final
109 image. This includes compensating for ambient light color, reducing
110 noise, as well as making some other adjustments to the image.
111
112 You can control many of these processing steps through the Camera properties.
113 For example, you can set the white balance (or color temperature) used
114 for processing images:
115
116 \qml
117 Camera {
118 whiteBalanceMode: Camera.WhiteBalanceManual
119 colorTemperature: 5600
120 }
121 \endqml
122
123 For more information on image processing of camera frames, see
124 \l {camera_image_processing}{Camera Image Processing}.
125
126 Most platforms require that the end-user grants permissions before a
127 camera can be activated. It is therefore strongly recommended that
128 application developers utilize the \l CameraPermission component when
129 working with cameras. The following is a short example that requests
130 permissions from the end-user when the application starts, and then
131 activates the camera if permissions are granted.
132
133 \qml
134 CameraPermission {
135 id: cameraPermission
136 }
137
138 Camera {
139 active: cameraPermission.status === Qt.PermissionStatus.Granted
140 }
141
142 Component.onCompleted: cameraPermission.request()
143 \endqml
144
145 See the \l{Camera Overview}{camera overview} for more information.
146*/
147
148void QCameraPrivate::init(const QCameraDevice &device)
149{
150 Q_Q(QCamera);
151
152 auto maybeControl = QPlatformMediaIntegration::instance()->createCamera(q);
153 if (!maybeControl) {
154 qWarning() << "Failed to initialize QCamera" << maybeControl.error();
155 return;
156 }
157 control = maybeControl.value();
158 cameraDevice = !device.isNull() ? device : QMediaDevices::defaultVideoInput();
159 if (cameraDevice.isNull())
160 control->updateError(QCamera::CameraError, QStringLiteral("No camera detected"));
161 control->setCamera(cameraDevice);
162 q->connect(control, &QPlatformVideoSource::activeChanged, q, &QCamera::activeChanged);
163 q->connect(control, &QPlatformCamera::errorChanged, q, &QCamera::errorChanged);
164 q->connect(control, &QPlatformCamera::errorOccurred, q, &QCamera::errorOccurred);
165}
166
167/*!
168 Construct a QCamera with a \a parent.
169
170 Selects the default camera on the system if more than one camera is available.
171*/
172
173QCamera::QCamera(QObject *parent)
174 : QCamera(QMediaDevices::defaultVideoInput(), parent)
175{
176}
177
178/*!
179 \since 5.3
180
181 Construct a QCamera from a camera description \a cameraDevice and \a parent.
182*/
183
184QCamera::QCamera(const QCameraDevice &cameraDevice, QObject *parent)
185 : QObject(*new QCameraPrivate, parent)
186{
187 Q_D(QCamera);
188 d->init(cameraDevice);
189}
190
191/*!
192 \since 5.3
193
194 Construct a QCamera which uses a hardware camera located a the specified \a position.
195
196 For example on a mobile phone it can be used to easily choose between front-facing and
197 back-facing cameras.
198
199 If no camera is available at the specified \a position or if \a position is
200 QCameraDevice::UnspecifiedPosition, the default camera is used.
201*/
202
203QCamera::QCamera(QCameraDevice::Position position, QObject *parent)
204 : QObject(*new QCameraPrivate, parent)
205{
206 Q_D(QCamera);
207
208 QCameraDevice device;
209 auto cameras = QMediaDevices::videoInputs();
210 for (const auto &c : std::as_const(cameras)) {
211 if (c.position() == position) {
212 device = c;
213 break;
214 }
215 }
216 d->init(device);
217}
218
219/*!
220 Destroys the camera object.
221*/
222
223QCamera::~QCamera()
224{
225 Q_D(QCamera);
226 if (d->captureSession)
227 d->captureSession->setCamera(nullptr);
228}
229
230/*!
231 Returns true if the camera can be used.
232*/
233bool QCamera::isAvailable() const
234{
235 Q_D(const QCamera);
236 return d->control && !d->cameraDevice.isNull();
237}
238
239/*! \qmlproperty bool QtMultimedia::Camera::active
240
241 Describes whether the camera is currently active.
242*/
243
244/*! \property QCamera::active
245
246 Describes whether the camera is currently active.
247*/
248
249/*!
250 Returns true if the camera is currently active.
251*/
252bool QCamera::isActive() const
253{
254 Q_D(const QCamera);
255 return d->control && d->control->isActive();
256}
257
258/*!
259 Turns the camera on if \a active is \c{true}, or off if it's \c{false}.
260*/
261void QCamera::setActive(bool active)
262{
263 Q_D(const QCamera);
264 if (d->control)
265 d->control->setActive(active);
266}
267
268/*!
269 \qmlproperty enumeration QtMultimedia::Camera::error
270
271 Returns the error state of the camera.
272
273 \qmlenumeratorsfrom QCamera::Error
274*/
275
276/*!
277 \property QCamera::error
278
279 Returns the error state of the camera.
280
281 \sa QCamera::Error
282*/
283
284QCamera::Error QCamera::error() const
285{
286 Q_D(const QCamera);
287
288 return d->control ? d->control->error() : QCamera::CameraError;
289}
290
291/*!
292 \qmlproperty string QtMultimedia::Camera::errorString
293
294 Returns a human readable string describing a camera's error state.
295*/
296
297/*!
298 \property QCamera::errorString
299
300 Returns a human readable string describing a camera's error state.
301*/
302QString QCamera::errorString() const
303{
304 Q_D(const QCamera);
305
306 return d->control ? d->control->errorString()
307 : QStringLiteral("Camera is not supported on the platform");
308}
309
310/*! \enum QCamera::Feature
311
312 Describes a set of features supported by the camera. The returned value can be a
313 combination of:
314
315 \value ColorTemperature
316 The Camera supports setting a custom \l{colorTemperature}.
317 \value ExposureCompensation
318 The Camera supports setting a custom \l{exposureCompensation}.
319 \value IsoSensitivity
320 The Camera supports setting a custom \l{isoSensitivity}.
321 \value ManualExposureTime
322 The Camera supports setting a \l{QCamera::manualExposureTime}{manual exposure Time}.
323 \value CustomFocusPoint
324 The Camera supports setting a \l{QCamera::customFocusPoint}{custom focus point}.
325 \value FocusDistance
326 The Camera supports setting the \l{focusDistance} property.
327*/
328
329/*!
330 \qmlproperty enumeration QtMultimedia::Camera::supportedFeatures
331
332 Returns the features supported by this camera. The value is bitmask
333 that may contain any of the following flags. It stores an OR
334 combination of Feature values.
335
336 \qmlenumeratorsfrom QCamera::Feature
337*/
338
339/*!
340 \property QCamera::supportedFeatures
341
342 Returns the features supported by this camera.
343
344 \sa QCamera::Feature
345*/
346QCamera::Features QCamera::supportedFeatures() const
347{
348 Q_D(const QCamera);
349 return d->control ? d->control->supportedFeatures() : QCamera::Features{};
350}
351
352/*! \qmlmethod void Camera::start()
353
354 Starts the camera.
355
356 Same as setting the active property to true.
357
358 If the camera can't be started for some reason, the errorOccurred() signal is emitted.
359*/
360
361/*! \fn void QCamera::start()
362
363 Starts the camera.
364
365 Same as setActive(true).
366
367 If the camera can't be started for some reason, the errorOccurred() signal is emitted.
368*/
369
370/*! \qmlmethod void Camera::stop()
371
372 Stops the camera.
373 Same as setting the active property to false.
374*/
375
376/*! \fn void QCamera::stop()
377
378 Stops the camera.
379 Same as setActive(false).
380*/
381
382/*!
383 Returns the capture session this camera is connected to, or
384 a nullptr if the camera is not connected to a capture session.
385
386 use QMediaCaptureSession::setCamera() to connect the camera to
387 a session.
388*/
389QMediaCaptureSession *QCamera::captureSession() const
390{
391 Q_D(const QCamera);
392 return d->captureSession;
393}
394
395/*!
396 \internal
397*/
398void QCamera::setCaptureSession(QMediaCaptureSession *session)
399{
400 Q_D(QCamera);
401 d->captureSession = session;
402}
403
404/*!
405 \internal
406*/
407QPlatformCamera *QCamera::platformCamera()
408{
409 Q_D(const QCamera);
410 return d->control;
411}
412
413/*! \qmlproperty cameraDevice QtMultimedia::Camera::cameraDevice
414
415 Gets or sets the currently active camera device.
416
417 When switching camera devices, the \l Camera's capabilities are updated.
418 Additionally, the \l Camera's control properties (such as \l focusMode,
419 \l flashMode, \l focusDistance, \l zoomFactor) are updated as follows:
420
421 \list
422 \li If a property is supported on the new device, the property value is applied to the
423 camera device.
424 \li If a property is supported but its range of valid values was changed, the property
425 is clamped to the new range and applied to the camera device.
426 \li If the new camera device does not support a property, the property value is reset
427 to default, and no changes are made to the camera device.
428 \endlist
429*/
430
431/*!
432 \property QCamera::cameraDevice
433
434 Returns the QCameraDevice object associated with this camera.
435
436 When switching camera devices, the \l QCamera's capabilities are updated.
437 Additionally, the \l QCamera's control properties (such as \l focusMode,
438 \l flashMode, \l focusDistance, \l zoomFactor) are updated as follows:
439
440 \list
441 \li If a property is supported on the new device, the property value is applied to the
442 camera device.
443 \li If a property is supported but its range of valid values was changed, the property
444 is clamped to the new range and applied to the camera device.
445 \li If the new camera device does not support a property, the property value is reset
446 to default, and no changes are made to the camera device.
447 \endlist
448 */
449QCameraDevice QCamera::cameraDevice() const
450{
451 Q_D(const QCamera);
452 return d->cameraDevice;
453}
454
455/*!
456 Connects the camera object to the physical camera device described by
457 \a cameraDevice. Using a default constructed QCameraDevice object as
458 \a cameraDevice will connect the camera to the system default camera device.
459
460 When switching camera devices, the QCamera's capabilities are updated.
461 Additionally, the QCamera's control properties (such as \l focusMode,
462 \l flashMode, \l focusDistance, \l zoomFactor) are updated as follows:
463
464 \list
465 \li If a property is supported on the new device, the property value is applied to the
466 camera device.
467 \li If a property is supported but its range of valid values was changed, the property
468 is clamped to the new range and applied to the camera device.
469 \li If the new camera device does not support a property, the property value is reset
470 to default, and no changes are made to the camera device.
471 \endlist
472*/
473void QCamera::setCameraDevice(const QCameraDevice &cameraDevice)
474{
475 Q_D(QCamera);
476 auto dev = cameraDevice;
477 if (dev.isNull())
478 dev = QMediaDevices::defaultVideoInput();
479 if (d->cameraDevice == dev)
480 return;
481 d->cameraDevice = dev;
482 if (d->control)
483 d->control->setCamera(d->cameraDevice);
484 emit cameraDeviceChanged();
485 setCameraFormat({});
486}
487
488/*! \qmlproperty cameraFormat QtMultimedia::Camera::cameraFormat
489
490 Gets or sets the currently active camera format.
491
492 \note When using the FFMPEG backend on an Android target device if you request
493 \b YUV420P format, you will receive either a fully planar 4:2:0 YUV420P or a
494 semi-planar NV12/NV21. This depends on the codec implemented by the device
495 OEM.
496
497 \note On macOS, camera-devices are shared across multiple
498 applications on the operating system. This means that another
499 application may override the format set by this property.
500 Application developers should account for receiving video frames
501 that have a different resolution, pixel format and framerate than
502 what is described by this property. This property does not change
503 when the device's format is modified by another application. The
504 format described by this property can be re-applied to the device
505 by re-activating the \l Camera.
506
507 \sa cameraDevice::videoFormats
508*/
509
510/*!
511 \property QCamera::cameraFormat
512
513 Returns the camera format currently used by the camera.
514
515 \note When using the FFMPEG backend on an Android target device if you request
516 \b YUV420P format, you will receive either a fully planar 4:2:0 YUV420P or a
517 semi-planar NV12/NV21. This depends on the codec implemented by the device
518 OEM.
519
520 \note On macOS, camera-devices are shared across multiple
521 applications on the operating system. This means that another
522 application may override the format set by this property.
523 Application developers should account for receiving video frames
524 that have a different resolution, pixel format and framerate than
525 what is described by this property. This property does not change
526 when the device's format is modified by another application. The
527 format described by this property can be re-applied to the device
528 by re-activating the \l QCamera.
529
530 \sa QCameraDevice::videoFormats
531*/
532QCameraFormat QCamera::cameraFormat() const
533{
534 Q_D(const QCamera);
535 return d->cameraFormat;
536}
537
538/*!
539 Tells the camera to use the format described by \a format. This can be used to define
540 a specific resolution and frame rate to be used for recording and image capture.
541
542 \note When using the FFMPEG backend on an Android target device if you request
543 \b YUV420P format, you will receive either a fully planar 4:2:0 YUV420P or a
544 semi-planar NV12/NV21. This depends on the codec implemented by the device
545 OEM.
546*/
547void QCamera::setCameraFormat(const QCameraFormat &format)
548{
549 Q_D(QCamera);
550 if (!d->control || !d->control->setCameraFormat(format))
551 return;
552
553 d->cameraFormat = format;
554 emit cameraFormatChanged();
555}
556
557/*!
558 \enum QCamera::Error
559
560 This enum holds the last error code.
561
562 \value NoError No errors have occurred.
563 \value CameraError An error has occurred.
564*/
565
566/*!
567 \qmlsignal void Camera::errorOccurred(Camera::Error error, string errorString)
568
569 This signal is emitted when error state changes to \a error. A description
570 of the error is provided as \a errorString.
571*/
572
573/*!
574 \fn void QCamera::errorOccurred(QCamera::Error error, const QString &errorString)
575
576 This signal is emitted when error state changes to \a error. A description
577 of the error is provided as \a errorString.
578*/
579
580/*!
581 \qmlproperty enumeration Camera::focusMode
582
583 This property holds the value that controls focus mode for the camera device.
584 In all autofocus modes, the camera device keeps focusing continuously.
585
586 \note In automatic focusing modes and where supported, the \l focusPoint property provides
587 information and control over the area of the image that is being focused.
588
589 \value Camera.FocusModeAuto Continuous auto focus mode.
590 \value Camera.FocusModeAutoNear Continuous auto focus, preferring objects near to
591 the camera.
592 \value Camera.FocusModeAutoFar Continuous auto focus, preferring objects far away
593 from the camera.
594 \value Camera.FocusModeHyperfocal Focus to hyperfocal distance, with the maximum
595 depth of field achieved. All objects at distances from half of this
596 distance out to infinity will be acceptably sharp.
597 \value Camera.FocusModeInfinity Focus strictly to infinity.
598 \value Camera.FocusModeManual The lens focus distance is set to a value specified by \l focusDistance.
599
600 To check whether the camera device supports a particular focus mode, pass the corresponding
601 \c focusMode value to the \l isFocusModeSupported() function as a parameter. The function
602 returns \c false if the focus mode value is not supported. Assigning an unsupported mode to
603 this property has no effect.
604
605 If you set the focusMode property to \c Camera.FocusModeManual, the lens
606 locks to the focus according to \l focusDistance.
607
608 \sa isFocusModeSupported()
609*/
610
611/*!
612 \property QCamera::focusMode
613 \brief the current camera focus mode.
614
615 This property holds the value that controls focus mode for the camera device.
616 In all autofocus modes, the camera device keeps focusing continuously.
617
618 To check whether the camera device supports a particular focus mode, pass the corresponding
619 \l FocusMode value to the \l isFocusModeSupported function as a parameter. The function
620 returns false if the focus mode value is not supported. Assigning an unsupported mode to
621 this property has no effect.
622
623 If you set the focusMode property to \l QCamera::FocusModeManual, the lens
624 locks to the focus according to \l focusDistance.
625
626 \sa isFocusModeSupported()
627*/
628QCamera::FocusMode QCamera::focusMode() const
629{
630 Q_D(const QCamera);
631 return d->control ? d->control->focusMode() : QCamera::FocusModeAuto;
632}
633
634/*!
635 \fn void QCamera::focusModeChanged()
636
637 Signals when the focusMode changes.
638*/
639void QCamera::setFocusMode(QCamera::FocusMode mode)
640{
641 Q_D(QCamera);
642 if (!d->control || d->control->focusMode() == mode)
643 return;
644 d->control->setFocusMode(mode);
645}
646
647/*!
648 \qmlmethod bool Camera::isFocusModeSupported(FocusMode mode)
649
650 Returns \c true if the focus \a mode is supported by the camera.
651
652 If \l {focusMode}{Camera.FocusModeManual} is reported as supported,
653 the feature \l {supportedFeatures}{Camera.FocusDistance} is implied
654 to be supported as well.
655*/
656
657/*!
658 Returns \c true if the focus \a mode is supported by the camera.
659
660 If \l FocusModeManual is reported as supported, the feature
661 \l Feature::FocusDistance is implied to be supported as well.
662*/
663bool QCamera::isFocusModeSupported(FocusMode mode) const
664{
665 Q_D(const QCamera);
666 return d->control ? d->control->isFocusModeSupported(mode) : false;
667}
668
669/*!
670 \qmlproperty point QtMultimedia::Camera::focusPoint
671 Returns the point currently used by the auto focus system to focus onto.
672*/
673
674/*!
675 \property QCamera::focusPoint
676
677 Returns the point currently used by the auto focus system to focus onto.
678 */
679QPointF QCamera::focusPoint() const
680{
681 Q_D(const QCamera);
682 return d->control ? d->control->focusPoint() : QPointF(-1., -1.);
683
684}
685
686/*!
687 \qmlproperty point QtMultimedia::Camera::customFocusPoint
688
689 This property holds the position of custom focus point, in relative frame
690 coordinates. This means that QPointF(0,0) points to the top-left corner
691 of the frame, and QPointF(0.5,0.5) points to the center of the frame.
692
693 You can check whether custom focus points are supported by querying
694 supportedFeatures() with the Feature.CustomFocusPoint flag.
695*/
696
697/*!
698 \property QCamera::customFocusPoint
699
700 This property represents the position of the custom focus point, in relative frame coordinates:
701 QPointF(0,0) points to the left top frame point, QPointF(0.5,0.5) points to the frame center.
702
703 You can check whether custom focus points are supported by querying
704 supportedFeatures() with the Feature.CustomFocusPoint flag.
705*/
706QPointF QCamera::customFocusPoint() const
707{
708 Q_D(const QCamera);
709 return d->control ? d->control->customFocusPoint() : QPointF{-1., -1.};
710}
711
712void QCamera::setCustomFocusPoint(const QPointF &point)
713{
714 Q_D(QCamera);
715 if (d->control)
716 d->control->setCustomFocusPoint(point);
717}
718
719/*!
720 \qmlproperty real QtMultimedia::Camera::focusDistance
721
722 This property defines the lens focus distance when the camera device works in
723 manual focus mode. Valid values range from 0 to 1, where 0 is the closest
724 possible focus distance, and 1 is the farthest. The farthest point is
725 typically at infinity, but this may not be the case for all devices.
726
727 This property is applied to the device only when \l focusMode is set to
728 \l {focusMode}{Camera.FocusModeManual}, and \l supportedFeatures includes the
729 \c Camera.FocusDistance flag.
730
731 If you assign a value to this property while \l focusMode is not
732 set to \c Camera.FocusModeManual, the property stores the value but does
733 not affect the device until \c Camera.FocusModeManual is active.
734
735 Assigning a value outside the valid range [0, 1] has no effect on this property.
736
737 If \l supportedFeatures does not include the \c Camera.FocusDistance flag,
738 any attempt to set this property is ignored.
739
740 This property will not be updated by the camera when it is in an automatic focus mode.
741
742 The default value is 1.
743*/
744
745/*!
746 \property QCamera::focusDistance
747
748 This property defines the lens focus distance when the camera device works in
749 manual focus mode. Valid values range from 0 to 1, where 0 is the closest
750 possible focus distance, and 1 is the farthest. The farthest point is
751 typically at infinity, but this may not be the case for all devices.
752
753 This property is applied to the device only when \l focusMode is set to
754 \l FocusModeManual, and \l supportedFeatures includes the
755 \l Feature::FocusDistance flag.
756
757 If you assign a value to this property while \l focusMode is not
758 set to \c QCamera::FocusModeManual, the property stores the value but does
759 not affect the device until \c QCamera::FocusModeManual is active.
760
761 Assigning a value outside the valid range [0, 1] has no effect on this property.
762
763 If \l supportedFeatures does not include the \l FocusDistance flag,
764 any attempt to set this property is ignored.
765
766 This property will not be updated by the camera when it is in an automatic focus mode.
767
768 The default value is 1.
769*/
770void QCamera::setFocusDistance(float distance)
771{
772 if (!d_func()->control)
773 return;
774 d_func()->control->setFocusDistance(distance);
775}
776
777float QCamera::focusDistance() const
778{
779 if (d_func()->control)
780 return d_func()->control->focusDistance();
781 return 0.f;
782}
783
784/*!
785 \qmlproperty real QtMultimedia::Camera::maximumZoomFactor
786
787 This property holds the maximum zoom factor supported.
788
789 This will be \c 1.0 on cameras that do not support zooming.
790*/
791
792
793/*!
794 \property QCamera::maximumZoomFactor
795
796 Returns the maximum zoom factor.
797
798 This will be \c 1.0 on cameras that do not support zooming.
799*/
800
801float QCamera::maximumZoomFactor() const
802{
803 Q_D(const QCamera);
804 return d->control ? d->control->maxZoomFactor() : 1.f;
805}
806
807/*!
808 \qmlproperty real QtMultimedia::Camera::minimumZoomFactor
809
810 This property holds the minimum zoom factor supported.
811
812 This will be \c 1.0 on cameras that do not support zooming.
813*/
814
815/*!
816 \property QCamera::minimumZoomFactor
817
818 Returns the minimum zoom factor.
819
820 This will be \c 1.0 on cameras that do not support zooming.
821*/
822
823float QCamera::minimumZoomFactor() const
824{
825 Q_D(const QCamera);
826 return d->control ? d->control->minZoomFactor() : 1.f;
827}
828
829/*!
830 \qmlproperty real QtMultimedia::Camera::zoomFactor
831
832 Gets or sets the current zoom factor. Values will be clamped between
833 \l minimumZoomFactor and \l maximumZoomFactor.
834*/
835
836/*!
837 \property QCamera::zoomFactor
838 \brief The current zoom factor.
839
840 Gets or sets the current zoom factor. Values will be clamped between
841 \l minimumZoomFactor and \l maximumZoomFactor.
842*/
843float QCamera::zoomFactor() const
844{
845 Q_D(const QCamera);
846 return d->control ? d->control->zoomFactor() : 1.f;
847}
848/*!
849 Zooms to a zoom factor \a factor at a rate of 1 factor per second.
850 */
851void QCamera::setZoomFactor(float factor)
852{
853 zoomTo(factor, 0.f);
854}
855
856/*!
857 \qmlmethod void QtMultimedia::Camera::zoomTo(factor, rate)
858
859 Zooms to a zoom factor \a factor using \a rate.
860
861 The \a rate is specified in powers of two per second. At a rate of 1
862 it would take 2 seconds to go from a zoom factor of 1 to 4.
863
864 \note Using a specific rate is not supported on all cameras. If not supported,
865 zooming will happen as fast as possible.
866*/
867
868/*!
869 Zooms to a zoom factor \a factor using \a rate.
870
871 The \a rate is specified in powers of two per second. At a rate of 1
872 it would take 2 seconds to go from a zoom factor of 1 to 4.
873
874 \note Using a specific rate is not supported on all cameras. If not supported,
875 zooming will happen as fast as possible.
876*/
877void QCamera::zoomTo(float factor, float rate)
878{
879 Q_ASSERT(rate >= 0.f);
880 if (rate < 0.f)
881 rate = 0.f;
882
883 Q_D(QCamera);
884 if (!d->control)
885 return;
886 factor = qBound(d->control->minZoomFactor(), factor, d->control->maxZoomFactor());
887 d->control->zoomTo(factor, rate);
888}
889
890/*!
891 \enum QCamera::FocusMode
892
893 \value FocusModeAuto Continuous auto focus mode.
894 \value FocusModeAutoNear Continuous auto focus mode on near objects.
895 \value FocusModeAutoFar Continuous auto focus mode on objects far away.
896 \value FocusModeHyperfocal Focus to hyperfocal distance, with the maximum depth of field achieved.
897 All objects at distances from half of this
898 distance out to infinity will be acceptably sharp.
899 \value FocusModeInfinity Focus strictly to infinity.
900 \value FocusModeManual Camera lens focus distance is locked according to \l focusDistance.
901*/
902
903/*!
904 \qmlproperty enumeration QtMultimedia::Camera::flashMode
905
906 Gets or sets a certain flash mode if the camera has a flash.
907
908 Assigning an unsupported mode to this property has no effect.
909
910 This property only has an effect when capturing images using
911 \l ImageCapture
912
913 \qmlenumeratorsfrom QCamera::FlashMode
914
915 \sa isFlashModeSupported(), isFlashReady(), flashReady
916*/
917
918/*!
919 \property QCamera::flashMode
920 \brief The flash mode being used.
921
922 Enables a certain flash mode if the camera has a flash.
923
924 Assigning an unsupported mode to this property has no effect.
925
926 This property only has an effect when capturing images using
927 \l QImageCapture
928
929 \sa QCamera::FlashMode, QCamera::isFlashModeSupported, QCamera::isFlashReady
930*/
931QCamera::FlashMode QCamera::flashMode() const
932{
933 Q_D(const QCamera);
934 return d->control ? d->control->flashMode() : QCamera::FlashOff;
935}
936
937void QCamera::setFlashMode(QCamera::FlashMode mode)
938{
939 Q_D(QCamera);
940 if (d->control)
941 d->control->setFlashMode(mode);
942}
943
944/*!
945 \qmlmethod bool QtMultimedia::Camera::isFlashModeSupported(FlashMode mode)
946
947 Returns true if the flash \a mode is supported.
948*/
949
950/*!
951 Returns true if the flash \a mode is supported.
952*/
953bool QCamera::isFlashModeSupported(QCamera::FlashMode mode) const
954{
955 Q_D(const QCamera);
956 return d->control ? d->control->isFlashModeSupported(mode) : (mode == FlashOff);
957}
958
959/*!
960 \qmlmethod bool QtMultimedia::Camera::isFlashReady()
961
962 Returns true if flash is charged.
963*/
964
965/*!
966 Returns true if flash is charged.
967*/
968bool QCamera::isFlashReady() const
969{
970 Q_D(const QCamera);
971 return d->control ? d->control->isFlashReady() : false;
972}
973
974/*!
975 \qmlproperty enumeration Camera::torchMode
976
977 Gets or sets the torch mode being used.
978
979 A torch is a continuous source of light. It can be used during video recording in
980 low light conditions. Enabling torch mode will usually override any currently set
981 flash mode.
982
983 \qmlenumeratorsfrom QCamera::TorchMode
984
985 \sa isTorchModeSupported(), flashMode
986*/
987
988/*!
989 \property QCamera::torchMode
990 \brief The torch mode being used.
991
992 A torch is a continuous source of light. It can be used during video recording in
993 low light conditions. Enabling torch mode will usually override any currently set
994 flash mode.
995
996 \sa QCamera::TorchMode, QCamera::isTorchModeSupported, QCamera::flashMode
997*/
998QCamera::TorchMode QCamera::torchMode() const
999{
1000 Q_D(const QCamera);
1001 return d->control ? d->control->torchMode() : TorchOff;
1002}
1003
1004void QCamera::setTorchMode(QCamera::TorchMode mode)
1005{
1006 Q_D(QCamera);
1007 if (d->control)
1008 d->control->setTorchMode(mode);
1009}
1010
1011/*!
1012 \qmlmethod bool QtMultimedia::Camera::isTorchModeSupported(TorchMode mode)
1013
1014 Returns true if the torch \a mode is supported.
1015*/
1016
1017/*!
1018 Returns true if the torch \a mode is supported.
1019*/
1020bool QCamera::isTorchModeSupported(QCamera::TorchMode mode) const
1021{
1022 Q_D(const QCamera);
1023 return d->control ? d->control->isTorchModeSupported(mode) : (mode == TorchOff);
1024}
1025
1026/*!
1027 \qmlproperty enumeration QtMultimedia::Camera::exposureMode
1028 \brief The exposure mode being used.
1029
1030 \qmlenumeratorsfrom QCamera::ExposureMode
1031
1032 \sa isExposureModeSupported()
1033*/
1034
1035/*!
1036 \property QCamera::exposureMode
1037 \brief The exposure mode being used.
1038
1039 \sa QCamera::isExposureModeSupported
1040*/
1041QCamera::ExposureMode QCamera::exposureMode() const
1042{
1043 Q_D(const QCamera);
1044 return d->control ? d->control->exposureMode() : QCamera::ExposureAuto;
1045}
1046
1047void QCamera::setExposureMode(QCamera::ExposureMode mode)
1048{
1049 Q_D(QCamera);
1050 if (d->control)
1051 d->control->setExposureMode(mode);
1052}
1053
1054/*!
1055 \qmlmethod bool QtMultimedia::Camera::isExposureModeSupported(ExposureMode mode)
1056
1057 Returns true if the exposure \a mode is supported.
1058*/
1059
1060/*!
1061 Returns true if the exposure \a mode is supported.
1062*/
1063bool QCamera::isExposureModeSupported(QCamera::ExposureMode mode) const
1064{
1065 Q_D(const QCamera);
1066 return d->control && d->control->isExposureModeSupported(mode);
1067}
1068
1069/*!
1070 \qmlproperty real QtMultimedia::Camera::exposureCompensation
1071
1072 Gets or sets the exposure compensation in EV units.
1073
1074 Exposure compensation property allows to adjust the automatically calculated
1075 exposure.
1076*/
1077
1078/*!
1079 \property QCamera::exposureCompensation
1080 \brief Exposure compensation in EV units.
1081
1082 Exposure compensation property allows to adjust the automatically calculated
1083 exposure.
1084*/
1085float QCamera::exposureCompensation() const
1086{
1087 Q_D(const QCamera);
1088 return d->control ? d->control->exposureCompensation() : 0.f;
1089}
1090
1091void QCamera::setExposureCompensation(float ev)
1092{
1093 Q_D(QCamera);
1094 if (d->control)
1095 d->control->setExposureCompensation(ev);
1096}
1097
1098/*!
1099 \qmlproperty int QtMultimedia::Camera::isoSensitivity
1100
1101 Describes the ISO sensitivity currently used by the camera.
1102
1103*/
1104
1105/*!
1106 \property QCamera::isoSensitivity
1107 \brief The sensor ISO sensitivity.
1108
1109 Describes the ISO sensitivity currently used by the camera.
1110
1111 \sa setAutoIsoSensitivity(), setManualIsoSensitivity()
1112*/
1113int QCamera::isoSensitivity() const
1114{
1115 Q_D(const QCamera);
1116 return d->control ? d->control->isoSensitivity() : -1;
1117}
1118
1119/*!
1120 \qmlproperty int QtMultimedia::Camera::manualIsoSensitivity
1121
1122 Describes a manually set ISO sensitivity
1123
1124 Setting this property to -1 (the default), implies that the camera
1125 automatically adjusts the ISO sensitivity.
1126*/
1127
1128/*!
1129 \property QCamera::manualIsoSensitivity
1130 \brief Describes a manually set ISO sensitivity
1131
1132 Setting this property to -1 (the default), implies that the camera
1133 automatically adjusts the ISO sensitivity.
1134*/
1135void QCamera::setManualIsoSensitivity(int iso)
1136{
1137 Q_D(QCamera);
1138 if (iso <= 0)
1139 iso = -1;
1140 if (d->control)
1141 d->control->setManualIsoSensitivity(iso);
1142}
1143
1144int QCamera::manualIsoSensitivity() const
1145{
1146 Q_D(const QCamera);
1147 return d->control ? d->control->manualIsoSensitivity() : 100;
1148}
1149
1150/*!
1151 \fn QCamera::setAutoIsoSensitivity()
1152 Turn on auto sensitivity
1153*/
1154
1155void QCamera::setAutoIsoSensitivity()
1156{
1157 Q_D(QCamera);
1158 if (d->control)
1159 d->control->setManualIsoSensitivity(-1);
1160}
1161
1162/*!
1163 Returns the minimum ISO sensitivity supported by the camera.
1164*/
1165int QCamera::minimumIsoSensitivity() const
1166{
1167 Q_D(const QCamera);
1168 return d->control ? d->control->minIso() : -1;
1169}
1170
1171/*!
1172 Returns the maximum ISO sensitivity supported by the camera.
1173*/
1174int QCamera::maximumIsoSensitivity() const
1175{
1176 Q_D(const QCamera);
1177 return d->control ? d->control->maxIso() : -1;
1178}
1179
1180/*!
1181 The minimal exposure time in seconds.
1182*/
1183float QCamera::minimumExposureTime() const
1184{
1185 Q_D(const QCamera);
1186 return d->control ? d->control->minExposureTime() : -1.f;
1187}
1188
1189/*!
1190 The maximal exposure time in seconds.
1191*/
1192float QCamera::maximumExposureTime() const
1193{
1194 Q_D(const QCamera);
1195 return d->control ? d->control->maxExposureTime() : -1.f;
1196}
1197
1198/*!
1199 \qmlproperty real QtMultimedia::Camera::exposureTime
1200 Returns the Camera's exposure time in seconds.
1201
1202 \sa manualExposureTime
1203*/
1204
1205/*!
1206 \property QCamera::exposureTime
1207 \brief Camera's exposure time in seconds.
1208
1209 \sa minimumExposureTime(), maximumExposureTime(), setManualExposureTime()
1210*/
1211
1212/*!
1213 \fn QCamera::exposureTimeChanged(float speed)
1214
1215 Signals that a camera's exposure \a speed has changed.
1216*/
1217
1218/*!
1219 Returns the current exposure time in seconds.
1220*/
1221
1222float QCamera::exposureTime() const
1223{
1224 Q_D(const QCamera);
1225 return d->control ? d->control->exposureTime() : -1;
1226}
1227
1228/*!
1229 \qmlproperty real QtMultimedia::Camera::manualExposureTime
1230
1231 Gets or sets a manual exposure time.
1232
1233 Setting this property to -1 (the default) means that the camera
1234 automatically determines the exposure time.
1235*/
1236
1237/*!
1238 \property QCamera::manualExposureTime
1239
1240 Set the manual exposure time to \a seconds
1241*/
1242
1243void QCamera::setManualExposureTime(float seconds)
1244{
1245 Q_D(QCamera);
1246 if (d->control)
1247 d->control->setManualExposureTime(seconds);
1248}
1249
1250/*!
1251 Returns the manual exposure time in seconds, or -1
1252 if the camera is using automatic exposure times.
1253*/
1254float QCamera::manualExposureTime() const
1255{
1256 Q_D(const QCamera);
1257 return d->control ? d->control->manualExposureTime() : -1;
1258}
1259
1260/*!
1261 Use automatically calculated exposure time
1262*/
1263void QCamera::setAutoExposureTime()
1264{
1265 Q_D(QCamera);
1266 if (d->control)
1267 d->control->setManualExposureTime(-1);
1268}
1269
1270
1271/*!
1272 \enum QCamera::FlashMode
1273
1274 \value FlashOff Flash is Off.
1275 \value FlashOn Flash is On.
1276 \value FlashAuto Automatic flash.
1277*/
1278
1279/*!
1280 \enum QCamera::TorchMode
1281
1282 \value TorchOff Torch is Off.
1283 \value TorchOn Torch is On.
1284 \value TorchAuto Automatic torch.
1285*/
1286
1287/*!
1288 \enum QCamera::ExposureMode
1289
1290 \value ExposureAuto Automatic mode.
1291 \value ExposureManual Manual mode.
1292 \value ExposurePortrait Portrait exposure mode.
1293 \value ExposureNight Night mode.
1294 \value ExposureSports Spots exposure mode.
1295 \value ExposureSnow Snow exposure mode.
1296 \value ExposureBeach Beach exposure mode.
1297 \value ExposureAction Action mode. Since 5.5
1298 \value ExposureLandscape Landscape mode. Since 5.5
1299 \value ExposureNightPortrait Night portrait mode. Since 5.5
1300 \value ExposureTheatre Theatre mode. Since 5.5
1301 \value ExposureSunset Sunset mode. Since 5.5
1302 \value ExposureSteadyPhoto Steady photo mode. Since 5.5
1303 \value ExposureFireworks Fireworks mode. Since 5.5
1304 \value ExposureParty Party mode. Since 5.5
1305 \value ExposureCandlelight Candlelight mode. Since 5.5
1306 \value ExposureBarcode Barcode mode. Since 5.5
1307*/
1308
1309/*!
1310 \qmlproperty bool QtMultimedia::Camera::flashReady
1311
1312 Indicates if the flash is charged and ready to use.
1313*/
1314
1315/*!
1316 \property QCamera::flashReady
1317 \brief Indicates if the flash is charged and ready to use.
1318*/
1319
1320/*!
1321 \fn void QCamera::flashReady(bool ready)
1322
1323 Signal the flash \a ready status has changed.
1324*/
1325
1326/*!
1327 \fn void QCamera::isoSensitivityChanged(int value)
1328
1329 Signal emitted when sensitivity changes to \a value.
1330*/
1331
1332/*!
1333 \fn void QCamera::exposureCompensationChanged(float value)
1334
1335 Signal emitted when the exposure compensation changes to \a value.
1336*/
1337
1338
1339/*!
1340 \qmlproperty enumeration QtMultimedia::Camera::whiteBalanceMode
1341
1342 Gets or sets the white balance mode being used.
1343
1344 \qmlenumeratorsfrom QCamera::WhiteBalanceMode
1345
1346 \sa isWhiteBalanceModeSupported()
1347*/
1348
1349/*!
1350 \property QCamera::whiteBalanceMode
1351
1352 Returns the white balance mode being used.
1353*/
1354QCamera::WhiteBalanceMode QCamera::whiteBalanceMode() const
1355{
1356 Q_D(const QCamera);
1357 return d->control ? d->control->whiteBalanceMode() : QCamera::WhiteBalanceAuto;
1358}
1359
1360/*!
1361 Sets the white balance to \a mode.
1362*/
1363void QCamera::setWhiteBalanceMode(QCamera::WhiteBalanceMode mode)
1364{
1365 Q_D(QCamera);
1366 if (!d->control)
1367 return;
1368 if (!d->control->isWhiteBalanceModeSupported(mode))
1369 return;
1370 d->control->setWhiteBalanceMode(mode);
1371 if (mode == QCamera::WhiteBalanceManual)
1372 d->control->setColorTemperature(5600);
1373}
1374
1375/*!
1376 \qmlmethod bool QtMultimedia::Camera::isWhiteBalanceModeSupported(WhiteBalanceMode mode)
1377
1378 Returns true if the white balance \a mode is supported.
1379*/
1380
1381/*!
1382 Returns true if the white balance \a mode is supported.
1383*/
1384bool QCamera::isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const
1385{
1386 Q_D(const QCamera);
1387 return d->control && d->control->isWhiteBalanceModeSupported(mode);
1388}
1389
1390/*!
1391 \qmlmethod QtMultimedia::Camera::colorTemperature
1392
1393 Gets or sets the current color temperature.
1394
1395 Setting a color temperature will only have an effect if WhiteBalanceManual is
1396 supported. In this case, setting a temperature greater 0 will automatically set the
1397 white balance mode to WhiteBalanceManual. Setting the temperature to 0 will reset
1398 the white balance mode to WhiteBalanceAuto.
1399*/
1400
1401/*!
1402 \property QCamera::colorTemperature
1403
1404 Returns the current color temperature if the
1405 current white balance mode is \c WhiteBalanceManual. For other modes the
1406 return value is undefined.
1407*/
1408int QCamera::colorTemperature() const
1409{
1410 Q_D(const QCamera);
1411 return d->control ? d->control->colorTemperature() : 0;
1412}
1413
1414/*!
1415 Sets manual white balance to \a colorTemperature. This is used
1416 when whiteBalanceMode() is set to \c WhiteBalanceManual. The units are Kelvin.
1417
1418 Setting a color temperature will only have an effect if WhiteBalanceManual is
1419 supported. In this case, setting a temperature greater 0 will automatically set the
1420 white balance mode to WhiteBalanceManual. Setting the temperature to 0 will reset
1421 the white balance mode to WhiteBalanceAuto.
1422*/
1423
1424void QCamera::setColorTemperature(int colorTemperature)
1425{
1426 Q_D(QCamera);
1427 if (!d->control)
1428 return;
1429 if (colorTemperature < 0)
1430 colorTemperature = 0;
1431 if (colorTemperature == 0) {
1432 d->control->setWhiteBalanceMode(WhiteBalanceAuto);
1433 } else if (!isWhiteBalanceModeSupported(WhiteBalanceManual)) {
1434 return;
1435 } else {
1436 d->control->setWhiteBalanceMode(WhiteBalanceManual);
1437 }
1438 d->control->setColorTemperature(colorTemperature);
1439}
1440
1441/*!
1442 \enum QCamera::WhiteBalanceMode
1443
1444 \value WhiteBalanceAuto Auto white balance mode.
1445 \value WhiteBalanceManual Manual white balance. In this mode the white
1446 balance should be set with setColorTemperature()
1447 \value WhiteBalanceSunlight Sunlight white balance mode.
1448 \value WhiteBalanceCloudy Cloudy white balance mode.
1449 \value WhiteBalanceShade Shade white balance mode.
1450 \value WhiteBalanceTungsten Tungsten (incandescent) white balance mode.
1451 \value WhiteBalanceFluorescent Fluorescent white balance mode.
1452 \value WhiteBalanceFlash Flash white balance mode.
1453 \value WhiteBalanceSunset Sunset white balance mode.
1454*/
1455
1456/*!
1457 \fn void QCamera::brightnessChanged()
1458 \internal
1459*/
1460/*!
1461 \fn void QCamera::contrastChanged()
1462 \internal
1463*/
1464/*!
1465 \fn void QCamera::hueChanged()
1466 \internal
1467*/
1468/*!
1469 \fn void QCamera::saturationChanged()
1470 \internal
1471*/
1472QT_END_NAMESPACE
1473
1474#include "moc_qcamera.cpp"
QPlatformCamera * control
Definition qcamera_p.h:34
Combined button and popup list for selecting options.