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