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

source code of qtmultimedia/src/multimedia/camera/qcamera.cpp