summaryrefslogtreecommitdiffstats
path: root/src/multimedia/camera/qimagecapture.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/multimedia/camera/qimagecapture.cpp')
-rw-r--r--src/multimedia/camera/qimagecapture.cpp155
1 files changed, 77 insertions, 78 deletions
diff --git a/src/multimedia/camera/qimagecapture.cpp b/src/multimedia/camera/qimagecapture.cpp
index 41c3721f2..df3ddae3f 100644
--- a/src/multimedia/camera/qimagecapture.cpp
+++ b/src/multimedia/camera/qimagecapture.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2021 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <qimagecapture.h>
#include <private/qplatformimagecapture_p.h>
#include <qmediametadata.h>
@@ -118,25 +82,36 @@ QImageCapture::QImageCapture(QObject *parent)
{
Q_D(QImageCapture);
d->q_ptr = this;
- d->control = QPlatformMediaIntegration::instance()->createImageCapture(this);
-
- connect(d->control, SIGNAL(imageExposed(int)),
- this, SIGNAL(imageExposed(int)));
- connect(d->control, SIGNAL(imageCaptured(int,QImage)),
- this, SIGNAL(imageCaptured(int,QImage)));
- connect(d->control, SIGNAL(imageMetadataAvailable(int,const QMediaMetaData&)),
- this, SIGNAL(imageMetadataAvailable(int,const QMediaMetaData&)));
- connect(d->control, SIGNAL(imageAvailable(int,QVideoFrame)),
- this, SIGNAL(imageAvailable(int,QVideoFrame)));
- connect(d->control, SIGNAL(imageSaved(int,QString)),
- this, SIGNAL(imageSaved(int,QString)));
- connect(d->control, SIGNAL(readyForCaptureChanged(bool)),
- this, SIGNAL(readyForCaptureChanged(bool)));
+
+ auto maybeControl = QPlatformMediaIntegration::instance()->createImageCapture(this);
+ if (!maybeControl) {
+ qWarning() << "Failed to initialize QImageCapture" << maybeControl.error();
+ d->errorString = maybeControl.error();
+ d->error = NotReadyError;
+ return;
+ }
+
+ d->control = maybeControl.value();
+ connect(d->control, &QPlatformImageCapture::imageExposed, this, &QImageCapture::imageExposed);
+ connect(d->control, &QPlatformImageCapture::imageCaptured, this, &QImageCapture::imageCaptured);
+ connect(d->control, &QPlatformImageCapture::imageMetadataAvailable, this,
+ &QImageCapture::imageMetadataAvailable);
+ connect(d->control, &QPlatformImageCapture::imageAvailable, this,
+ &QImageCapture::imageAvailable);
+ connect(d->control, &QPlatformImageCapture::imageSaved, this, &QImageCapture::imageSaved);
+ connect(d->control, &QPlatformImageCapture::readyForCaptureChanged, this,
+ &QImageCapture::readyForCaptureChanged);
connect(d->control, SIGNAL(error(int,int,QString)),
this, SLOT(_q_error(int,int,QString)));
}
/*!
+ \fn void QImageCapture::imageMetadataAvailable(int id, const QMediaMetaData &metaData)
+
+ Signals that an image identified by \a id has \a metaData.
+*/
+
+/*!
\internal
*/
void QImageCapture::setCaptureSession(QMediaCaptureSession *session)
@@ -161,7 +136,7 @@ QImageCapture::~QImageCapture()
*/
bool QImageCapture::isAvailable() const
{
- return d_func()->captureSession && d_func()->captureSession->camera();
+ return d_func()->control && d_func()->captureSession && d_func()->captureSession->camera();
}
/*!
@@ -177,6 +152,8 @@ QMediaCaptureSession *QImageCapture::captureSession() const
}
/*!
+ \property QImageCapture::error
+
Returns the current error state.
\sa errorString()
@@ -188,6 +165,8 @@ QImageCapture::Error QImageCapture::error() const
}
/*!
+ \property QImageCapture::errorString
+
Returns a string describing the current error state.
\sa error()
@@ -219,7 +198,8 @@ void QImageCapture::setMetaData(const QMediaMetaData &metaData)
{
Q_D(QImageCapture);
d->metaData = metaData;
- d->control->setMetaData(d->metaData);
+ if (d->control)
+ d->control->setMetaData(d->metaData);
emit metaDataChanged();
}
@@ -285,14 +265,13 @@ bool QImageCapture::isReadyForCapture() const
int QImageCapture::captureToFile(const QString &file)
{
Q_D(QImageCapture);
-
- d->unsetError();
-
if (!d->control) {
- d->_q_error(-1, NotSupportedFeatureError, QPlatformImageCapture::msgCameraNotReady());
+ d->_q_error(-1, d->error, d->errorString);
return -1;
}
+ d->unsetError();
+
if (!isReadyForCapture()) {
d->_q_error(-1, NotReadyError, tr("Could not capture in stopped state"));
return -1;
@@ -316,18 +295,13 @@ int QImageCapture::captureToFile(const QString &file)
int QImageCapture::capture()
{
Q_D(QImageCapture);
-
- d->unsetError();
-
- if (d->control)
+ if (!d->control) {
+ d->_q_error(-1, d->error, d->errorString);
+ return -1;
+ } else {
+ d->unsetError();
return d->control->captureToBuffer();
-
- d->error = NotSupportedFeatureError;
- d->errorString = tr("Device does not support images capture.");
-
- d->_q_error(-1, d->error, d->errorString);
-
- return -1;
+ }
}
/*!
@@ -375,6 +349,20 @@ int QImageCapture::capture()
*/
/*!
+ \enum QImageCapture::FileFormat
+
+ Choose one of the following image formats:
+
+ \value UnspecifiedFormat No format specified
+ \value JPEG \c .jpg or \c .jpeg format
+ \value PNG \c .png format
+ \value WebP \c .webp format
+ \value Tiff \c .tiff format
+ \omitvalue LastFileFormat
+*/
+
+
+/*!
\property QImageCapture::fileFormat
\brief The image format.
*/
@@ -382,9 +370,7 @@ int QImageCapture::capture()
QImageCapture::FileFormat QImageCapture::fileFormat() const
{
Q_D(const QImageCapture);
- if (!d->control)
- return UnspecifiedFormat;
- return d->control->imageSettings().format();
+ return d->control ? d->control->imageSettings().format() : UnspecifiedFormat;
}
/*!
@@ -403,11 +389,19 @@ void QImageCapture::setFileFormat(QImageCapture::FileFormat format)
emit fileFormatChanged();
}
+/*!
+ Returns a list of supported file formats.
+
+ \sa {QImageCapture::}{FileFormat}
+*/
QList<QImageCapture::FileFormat> QImageCapture::supportedFormats()
{
return QPlatformMediaIntegration::instance()->formatInfo()->imageFormats;
}
+/*!
+ Returns the name of the given format, \a f.
+*/
QString QImageCapture::fileFormatName(QImageCapture::FileFormat f)
{
const char *name = nullptr;
@@ -431,6 +425,9 @@ QString QImageCapture::fileFormatName(QImageCapture::FileFormat f)
return QString::fromUtf8(name);
}
+/*!
+ Returns the description of the given file format, \a f.
+*/
QString QImageCapture::fileFormatDescription(QImageCapture::FileFormat f)
{
const char *name = nullptr;
@@ -461,12 +458,16 @@ QString QImageCapture::fileFormatDescription(QImageCapture::FileFormat f)
QSize QImageCapture::resolution() const
{
Q_D(const QImageCapture);
- if (!d->control)
- return QSize();
- return d->control->imageSettings().resolution();
+ return d->control ? d->control->imageSettings().resolution() : QSize{};
}
/*!
+ \fn void QImageCapture::resolutionChanged()
+
+ Signals when the image resolution changes.
+*/
+
+/*!
Sets the \a resolution of the encoded image.
An empty QSize indicates the encoder should make an optimal choice based on
@@ -514,9 +515,7 @@ void QImageCapture::setResolution(int width, int height)
QImageCapture::Quality QImageCapture::quality() const
{
Q_D(const QImageCapture);
- if (!d->control)
- return NormalQuality;
- return d->control->imageSettings().quality();
+ return d->control ? d->control->imageSettings().quality() : NormalQuality;
}
/*!