From ab403bc9aedd7090ce773961f808959ea856b1af Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Sat, 7 Nov 2015 22:13:20 +0300 Subject: GStreamer: Adjust the camera's manual color temperature through V4L2 GStreamer does not support setup of manual color temperature for the camera. Now it is implemented through the V4L2 interface, where it is works together with the GStreamer and covers the GStreamer's holes. Change-Id: Icaeadeb4e21ec7865bcfa908bead318d4ead8ba5 Reviewed-by: Yoann Lopes --- src/plugins/gstreamer/camerabin/camerabin.pro | 11 +- .../camerabin/camerabinimageprocessing.cpp | 99 +++++++-- .../gstreamer/camerabin/camerabinimageprocessing.h | 10 +- src/plugins/gstreamer/camerabin/camerabinsession.h | 2 + .../camerabin/camerabinv4limageprocessing.cpp | 242 +++++++++++++++++++++ .../camerabin/camerabinv4limageprocessing.h | 80 +++++++ 6 files changed, 428 insertions(+), 16 deletions(-) create mode 100644 src/plugins/gstreamer/camerabin/camerabinv4limageprocessing.cpp create mode 100644 src/plugins/gstreamer/camerabin/camerabinv4limageprocessing.h (limited to 'src/plugins/gstreamer/camerabin') diff --git a/src/plugins/gstreamer/camerabin/camerabin.pro b/src/plugins/gstreamer/camerabin/camerabin.pro index 80d992960..b807071f2 100644 --- a/src/plugins/gstreamer/camerabin/camerabin.pro +++ b/src/plugins/gstreamer/camerabin/camerabin.pro @@ -89,6 +89,15 @@ config_gstreamer_encodingprofiles { DEFINES += HAVE_GST_ENCODING_PROFILES } +config_linux_v4l: { + DEFINES += USE_V4L + + HEADERS += \ + $$PWD/camerabinv4limageprocessing.h + + SOURCES += \ + $$PWD/camerabinv4limageprocessing.cpp +} + OTHER_FILES += \ camerabin.json - diff --git a/src/plugins/gstreamer/camerabin/camerabinimageprocessing.cpp b/src/plugins/gstreamer/camerabin/camerabinimageprocessing.cpp index 633662c70..d2ff89af0 100644 --- a/src/plugins/gstreamer/camerabin/camerabinimageprocessing.cpp +++ b/src/plugins/gstreamer/camerabin/camerabinimageprocessing.cpp @@ -34,6 +34,10 @@ #include "camerabinimageprocessing.h" #include "camerabinsession.h" +#ifdef USE_V4L +#include "camerabinv4limageprocessing.h" +#endif + #if GST_CHECK_VERSION(1,0,0) # include #else @@ -43,9 +47,12 @@ QT_BEGIN_NAMESPACE CameraBinImageProcessing::CameraBinImageProcessing(CameraBinSession *session) - :QCameraImageProcessingControl(session), - m_session(session), - m_whiteBalanceMode(QCameraImageProcessing::WhiteBalanceAuto) + : QCameraImageProcessingControl(session) + , m_session(session) + , m_whiteBalanceMode(QCameraImageProcessing::WhiteBalanceAuto) +#ifdef USE_V4L + , m_v4lImageControl(Q_NULLPTR) +#endif { #ifdef HAVE_GST_PHOTOGRAPHY if (m_session->photography()) { @@ -83,6 +90,12 @@ CameraBinImageProcessing::CameraBinImageProcessing(CameraBinSession *session) #endif #endif +#ifdef USE_V4L + m_v4lImageControl = new CameraBinV4LImageProcessing(m_session); + connect(m_session, &CameraBinSession::statusChanged, + m_v4lImageControl, &CameraBinV4LImageProcessing::updateParametersInfo); +#endif + updateColorBalanceValues(); } @@ -160,7 +173,7 @@ QCameraImageProcessing::WhiteBalanceMode CameraBinImageProcessing::whiteBalanceM return m_whiteBalanceMode; } -void CameraBinImageProcessing::setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceMode mode) +bool CameraBinImageProcessing::setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceMode mode) { #ifdef HAVE_GST_PHOTOGRAPHY if (isWhiteBalanceModeSupported(mode)) { @@ -172,11 +185,13 @@ void CameraBinImageProcessing::setWhiteBalanceMode(QCameraImageProcessing::White #endif { unlockWhiteBalance(); + return true; } } #else Q_UNUSED(mode); #endif + return false; } bool CameraBinImageProcessing::isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceMode mode) const @@ -184,7 +199,8 @@ bool CameraBinImageProcessing::isWhiteBalanceModeSupported(QCameraImageProcessin #ifdef HAVE_GST_PHOTOGRAPHY return m_mappedWbValues.values().contains(mode); #else - return mode == QCameraImageProcessing::WhiteBalanceAuto; + Q_UNUSED(mode); + return false; #endif } @@ -192,16 +208,24 @@ bool CameraBinImageProcessing::isParameterSupported(QCameraImageProcessingContro { #ifdef HAVE_GST_PHOTOGRAPHY if (parameter == QCameraImageProcessingControl::WhiteBalancePreset - || parameter == QCameraImageProcessingControl::ColorFilter) - return m_session->photography(); + || parameter == QCameraImageProcessingControl::ColorFilter) { + if (m_session->photography()) + return true; + } #endif if (parameter == QCameraImageProcessingControl::Contrast || parameter == QCameraImageProcessingControl::Brightness || parameter == QCameraImageProcessingControl::Saturation) { - return GST_IS_COLOR_BALANCE(m_session->cameraBin()); + if (GST_IS_COLOR_BALANCE(m_session->cameraBin())) + return true; } +#ifdef USE_V4L + if (m_v4lImageControl->isParameterSupported(parameter)) + return true; +#endif + return false; } @@ -212,8 +236,23 @@ bool CameraBinImageProcessing::isParameterValueSupported(QCameraImageProcessingC case BrightnessAdjustment: case SaturationAdjustment: return GST_IS_COLOR_BALANCE(m_session->cameraBin()) && qAbs(value.toReal()) <= 1.0; - case WhiteBalancePreset: - return isWhiteBalanceModeSupported(value.value()); + case WhiteBalancePreset: { + const QCameraImageProcessing::WhiteBalanceMode mode = + value.value(); + const bool isPhotographyWhiteBalanceSupported = isWhiteBalanceModeSupported(mode); +#ifdef USE_V4L + if (!isPhotographyWhiteBalanceSupported) + return m_v4lImageControl->isParameterValueSupported(parameter, value); +#endif + return isPhotographyWhiteBalanceSupported; + } + case ColorTemperature: { +#ifdef USE_V4L + return m_v4lImageControl->isParameterValueSupported(parameter, value); +#else + return false; +#endif + } case ColorFilter: { const QCameraImageProcessing::ColorFilter filter = value.value(); #ifdef HAVE_GST_PHOTOGRAPHY @@ -233,8 +272,23 @@ QVariant CameraBinImageProcessing::parameter( QCameraImageProcessingControl::ProcessingParameter parameter) const { switch (parameter) { - case QCameraImageProcessingControl::WhiteBalancePreset: - return QVariant::fromValue(whiteBalanceMode()); + case QCameraImageProcessingControl::WhiteBalancePreset: { + const QCameraImageProcessing::WhiteBalanceMode mode = whiteBalanceMode(); +#ifdef USE_V4L + if (mode == QCameraImageProcessing::WhiteBalanceAuto + || mode == QCameraImageProcessing::WhiteBalanceManual) { + return m_v4lImageControl->parameter(parameter); + } +#endif + return QVariant::fromValue(mode); + } + case QCameraImageProcessingControl::ColorTemperature: { +#ifdef USE_V4L + return m_v4lImageControl->parameter(parameter); +#else + return QVariant(); +#endif + } case QCameraImageProcessingControl::ColorFilter: #ifdef HAVE_GST_PHOTOGRAPHY if (GstPhotography *photography = m_session->photography()) { @@ -269,9 +323,26 @@ void CameraBinImageProcessing::setParameter(QCameraImageProcessingControl::Proce case SaturationAdjustment: setColorBalanceValue("saturation", value.toReal()); break; - case WhiteBalancePreset: - setWhiteBalanceMode(value.value()); + case WhiteBalancePreset: { + if (!setWhiteBalanceMode(value.value())) { +#ifdef USE_V4L + const QCameraImageProcessing::WhiteBalanceMode mode = + value.value(); + if (mode == QCameraImageProcessing::WhiteBalanceAuto + || mode == QCameraImageProcessing::WhiteBalanceManual) { + m_v4lImageControl->setParameter(parameter, value); + return; + } +#endif + } + } + break; + case QCameraImageProcessingControl::ColorTemperature: { +#ifdef USE_V4L + m_v4lImageControl->setParameter(parameter, value); +#endif break; + } case QCameraImageProcessingControl::ColorFilter: #ifdef HAVE_GST_PHOTOGRAPHY if (GstPhotography *photography = m_session->photography()) { diff --git a/src/plugins/gstreamer/camerabin/camerabinimageprocessing.h b/src/plugins/gstreamer/camerabin/camerabinimageprocessing.h index 9f280c485..6b2a114ec 100644 --- a/src/plugins/gstreamer/camerabin/camerabinimageprocessing.h +++ b/src/plugins/gstreamer/camerabin/camerabinimageprocessing.h @@ -50,6 +50,10 @@ typedef GstColourToneMode GstPhotographyColorToneMode; QT_BEGIN_NAMESPACE +#ifdef USE_V4L +class CameraBinV4LImageProcessing; +#endif + class CameraBinSession; class CameraBinImageProcessing : public QCameraImageProcessingControl @@ -61,7 +65,7 @@ public: virtual ~CameraBinImageProcessing(); QCameraImageProcessing::WhiteBalanceMode whiteBalanceMode() const; - void setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceMode mode); + bool setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceMode mode); bool isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceMode mode) const; bool isParameterSupported(ProcessingParameter) const; @@ -86,6 +90,10 @@ private: QMap m_filterMap; #endif QCameraImageProcessing::WhiteBalanceMode m_whiteBalanceMode; + +#ifdef USE_V4L + CameraBinV4LImageProcessing *m_v4lImageControl; +#endif }; QT_END_NAMESPACE diff --git a/src/plugins/gstreamer/camerabin/camerabinsession.h b/src/plugins/gstreamer/camerabin/camerabinsession.h index 1c5c9899d..dda900a8b 100644 --- a/src/plugins/gstreamer/camerabin/camerabinsession.h +++ b/src/plugins/gstreamer/camerabin/camerabinsession.h @@ -153,6 +153,8 @@ public: bool isMuted() const; + QString device() const { return m_inputDevice; } + bool processSyncMessage(const QGstreamerMessage &message); bool processBusMessage(const QGstreamerMessage &message); diff --git a/src/plugins/gstreamer/camerabin/camerabinv4limageprocessing.cpp b/src/plugins/gstreamer/camerabin/camerabinv4limageprocessing.cpp new file mode 100644 index 000000000..47522565c --- /dev/null +++ b/src/plugins/gstreamer/camerabin/camerabinv4limageprocessing.cpp @@ -0,0 +1,242 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Denis Shienkov +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "camerabinv4limageprocessing.h" +#include "camerabinsession.h" + +#include + +#include +#include + +QT_BEGIN_NAMESPACE + +CameraBinV4LImageProcessing::CameraBinV4LImageProcessing(CameraBinSession *session) + : QCameraImageProcessingControl(session) + , m_session(session) +{ +} + +CameraBinV4LImageProcessing::~CameraBinV4LImageProcessing() +{ +} + +bool CameraBinV4LImageProcessing::isParameterSupported( + ProcessingParameter parameter) const +{ + return m_parametersInfo.contains(parameter); +} + +bool CameraBinV4LImageProcessing::isParameterValueSupported( + ProcessingParameter parameter, const QVariant &value) const +{ + QMap::const_iterator sourceValueInfo = + m_parametersInfo.constFind(parameter); + if (sourceValueInfo == m_parametersInfo.constEnd()) + return false; + + switch (parameter) { + + case QCameraImageProcessingControl::WhiteBalancePreset: { + const QCameraImageProcessing::WhiteBalanceMode checkedValue = + value.value(); + const QCameraImageProcessing::WhiteBalanceMode firstAllowedValue = + (*sourceValueInfo).minimumValue ? QCameraImageProcessing::WhiteBalanceAuto + : QCameraImageProcessing::WhiteBalanceManual; + const QCameraImageProcessing::WhiteBalanceMode secondAllowedValue = + (*sourceValueInfo).maximumValue ? QCameraImageProcessing::WhiteBalanceAuto + : QCameraImageProcessing::WhiteBalanceManual; + if (checkedValue != firstAllowedValue + && checkedValue != secondAllowedValue) { + return false; + } + } + break; + + case QCameraImageProcessingControl::ColorTemperature: { + const qint32 checkedValue = value.toInt(); + if (checkedValue < (*sourceValueInfo).minimumValue + || checkedValue > (*sourceValueInfo).maximumValue) { + return false; + } + } + break; + + default: + return false; + } + + return true; +} + +QVariant CameraBinV4LImageProcessing::parameter( + ProcessingParameter parameter) const +{ + QMap::const_iterator sourceValueInfo = + m_parametersInfo.constFind(parameter); + if (sourceValueInfo == m_parametersInfo.constEnd()) { + qWarning() << "Unable to get the parameter value: the parameter is not supported."; + return QVariant(); + } + + const QString deviceName = m_session->device(); + const int fd = qt_safe_open(deviceName.toLocal8Bit().constData(), O_RDONLY); + if (fd == -1) { + qWarning() << "Unable to open the camera" << deviceName + << "for read to get the parameter value:" << qt_error_string(errno); + return QVariant(); + } + + struct v4l2_control control; + ::memset(&control, 0, sizeof(control)); + control.id = (*sourceValueInfo).cid; + + const bool ret = (::ioctl(fd, VIDIOC_G_CTRL, &control) == 0); + + qt_safe_close(fd); + + if (!ret) { + qWarning() << "Unable to get the parameter value:" << qt_error_string(errno); + return QVariant(); + } + + switch (parameter) { + + case QCameraImageProcessingControl::WhiteBalancePreset: + return QVariant::fromValue( + control.value ? QCameraImageProcessing::WhiteBalanceAuto + : QCameraImageProcessing::WhiteBalanceManual); + + case QCameraImageProcessingControl::ColorTemperature: + return QVariant::fromValue(control.value); + + default: + return QVariant(); + } +} + +void CameraBinV4LImageProcessing::setParameter( + ProcessingParameter parameter, const QVariant &value) +{ + QMap::const_iterator sourceValueInfo = + m_parametersInfo.constFind(parameter); + if (sourceValueInfo == m_parametersInfo.constEnd()) { + qWarning() << "Unable to set the parameter value: the parameter is not supported."; + return; + } + + const QString deviceName = m_session->device(); + const int fd = qt_safe_open(deviceName.toLocal8Bit().constData(), O_WRONLY); + if (fd == -1) { + qWarning() << "Unable to open the camera" << deviceName + << "for write to set the parameter value:" << qt_error_string(errno); + return; + } + + struct v4l2_control control; + ::memset(&control, 0, sizeof(control)); + control.id = (*sourceValueInfo).cid; + + switch (parameter) { + + case QCameraImageProcessingControl::WhiteBalancePreset: { + const QCameraImageProcessing::WhiteBalanceMode m = + value.value(); + if (m != QCameraImageProcessing::WhiteBalanceAuto + && m != QCameraImageProcessing::WhiteBalanceManual) + return; + + control.value = (m == QCameraImageProcessing::WhiteBalanceAuto) ? true : false; + } + break; + + case QCameraImageProcessingControl::ColorTemperature: + control.value = value.toInt(); + break; + + default: + return; + } + + if (::ioctl(fd, VIDIOC_S_CTRL, &control) != 0) + qWarning() << "Unable to set the parameter value:" << qt_error_string(errno); + + qt_safe_close(fd); +} + +void CameraBinV4LImageProcessing::updateParametersInfo( + QCamera::Status cameraStatus) +{ + if (cameraStatus == QCamera::UnloadedStatus) + m_parametersInfo.clear(); + else if (cameraStatus == QCamera::LoadedStatus) { + const QString deviceName = m_session->device(); + const int fd = qt_safe_open(deviceName.toLocal8Bit().constData(), O_RDONLY); + if (fd == -1) { + qWarning() << "Unable to open the camera" << deviceName + << "for read to query the parameter info:" << qt_error_string(errno); + return; + } + + static const struct SupportedParameterEntry { + quint32 cid; + QCameraImageProcessingControl::ProcessingParameter parameter; + } supportedParametersEntries[] = { + { V4L2_CID_AUTO_WHITE_BALANCE, QCameraImageProcessingControl::WhiteBalancePreset }, + { V4L2_CID_WHITE_BALANCE_TEMPERATURE, QCameraImageProcessingControl::ColorTemperature } + }; + + for (int i = 0; i < int(sizeof(supportedParametersEntries) / sizeof(SupportedParameterEntry)); ++i) { + struct v4l2_queryctrl queryControl; + ::memset(&queryControl, 0, sizeof(queryControl)); + queryControl.id = supportedParametersEntries[i].cid; + + if (::ioctl(fd, VIDIOC_QUERYCTRL, &queryControl) != 0) { + qWarning() << "Unable to query the parameter info:" << qt_error_string(errno); + continue; + } + + SourceParameterValueInfo sourceValueInfo; + sourceValueInfo.cid = queryControl.id; + sourceValueInfo.defaultValue = queryControl.default_value; + sourceValueInfo.maximumValue = queryControl.maximum; + sourceValueInfo.minimumValue = queryControl.minimum; + + m_parametersInfo.insert(supportedParametersEntries[i].parameter, sourceValueInfo); + } + + qt_safe_close(fd); + } +} + +QT_END_NAMESPACE diff --git a/src/plugins/gstreamer/camerabin/camerabinv4limageprocessing.h b/src/plugins/gstreamer/camerabin/camerabinv4limageprocessing.h new file mode 100644 index 000000000..03b3917ed --- /dev/null +++ b/src/plugins/gstreamer/camerabin/camerabinv4limageprocessing.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Denis Shienkov +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef CAMERABINV4LIMAGEPROCESSINGCONTROL_H +#define CAMERABINV4LIMAGEPROCESSINGCONTROL_H + +#include +#include + +QT_BEGIN_NAMESPACE + +class CameraBinSession; + +class CameraBinV4LImageProcessing : public QCameraImageProcessingControl +{ + Q_OBJECT + +public: + CameraBinV4LImageProcessing(CameraBinSession *session); + virtual ~CameraBinV4LImageProcessing(); + + bool isParameterSupported(ProcessingParameter) const; + bool isParameterValueSupported(ProcessingParameter parameter, const QVariant &value) const; + QVariant parameter(ProcessingParameter parameter) const; + void setParameter(ProcessingParameter parameter, const QVariant &value); + +public slots: + void updateParametersInfo(QCamera::Status cameraStatus); + +private: + struct SourceParameterValueInfo { + SourceParameterValueInfo() + : cid(0) + { + } + + qint32 defaultValue; + qint32 minimumValue; + qint32 maximumValue; + quint32 cid; // V4L control id + }; + +private: + CameraBinSession *m_session; + QMap m_parametersInfo; +}; + +QT_END_NAMESPACE + +#endif // CAMERABINV4LIMAGEPROCESSINGCONTROL_H -- cgit v1.2.3 From dd2b63498a4dd3b064dc4e4acc770e4124ead937 Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Thu, 10 Dec 2015 16:35:30 +0300 Subject: GStreamer: Add color balance and sharpening adjustments using V4L2 GStreamer's backend does not implements this features, therefore now is used the V4L2 interface for the contrast, saturation, brightness and the sharpening adjustments. The V4l2 interface works together with the GStreamer and covers the features which are not supported by the GStreamer. Change-Id: I995ed6cb096a29543fb80206384a92c13a1d1af2 Reviewed-by: Yoann Lopes --- .../camerabin/camerabinimageprocessing.cpp | 67 ++++++++++++++++++---- .../camerabin/camerabinv4limageprocessing.cpp | 64 ++++++++++++++++++++- .../camerabin/camerabinv4limageprocessing.h | 4 ++ 3 files changed, 124 insertions(+), 11 deletions(-) (limited to 'src/plugins/gstreamer/camerabin') diff --git a/src/plugins/gstreamer/camerabin/camerabinimageprocessing.cpp b/src/plugins/gstreamer/camerabin/camerabinimageprocessing.cpp index d2ff89af0..2d1659900 100644 --- a/src/plugins/gstreamer/camerabin/camerabinimageprocessing.cpp +++ b/src/plugins/gstreamer/camerabin/camerabinimageprocessing.cpp @@ -234,8 +234,22 @@ bool CameraBinImageProcessing::isParameterValueSupported(QCameraImageProcessingC switch (parameter) { case ContrastAdjustment: case BrightnessAdjustment: - case SaturationAdjustment: - return GST_IS_COLOR_BALANCE(m_session->cameraBin()) && qAbs(value.toReal()) <= 1.0; + case SaturationAdjustment: { + const bool isGstColorBalanceValueSupported = GST_IS_COLOR_BALANCE(m_session->cameraBin()) + && qAbs(value.toReal()) <= 1.0; +#ifdef USE_V4L + if (!isGstColorBalanceValueSupported) + return m_v4lImageControl->isParameterValueSupported(parameter, value); +#endif + return isGstColorBalanceValueSupported; + } + case SharpeningAdjustment: { +#ifdef USE_V4L + return m_v4lImageControl->isParameterValueSupported(parameter, value); +#else + return false; +#endif + } case WhiteBalancePreset: { const QCameraImageProcessing::WhiteBalanceMode mode = value.value(); @@ -303,25 +317,58 @@ QVariant CameraBinImageProcessing::parameter( } #endif return QVariant::fromValue(QCameraImageProcessing::ColorFilterNone); - default: - return m_values.contains(parameter) + default: { + const bool isGstParameterSupported = m_values.contains(parameter); +#ifdef USE_V4L + if (!isGstParameterSupported) { + if (parameter == QCameraImageProcessingControl::BrightnessAdjustment + || parameter == QCameraImageProcessingControl::ContrastAdjustment + || parameter == QCameraImageProcessingControl::SaturationAdjustment + || parameter == QCameraImageProcessingControl::SharpeningAdjustment) { + return m_v4lImageControl->parameter(parameter); + } + } +#endif + return isGstParameterSupported ? QVariant(m_values.value(parameter)) : QVariant(); } + } } void CameraBinImageProcessing::setParameter(QCameraImageProcessingControl::ProcessingParameter parameter, const QVariant &value) { switch (parameter) { - case ContrastAdjustment: - setColorBalanceValue("contrast", value.toReal()); + case ContrastAdjustment: { + if (!setColorBalanceValue("contrast", value.toReal())) { +#ifdef USE_V4L + m_v4lImageControl->setParameter(parameter, value); +#endif + } + } break; - case BrightnessAdjustment: - setColorBalanceValue("brightness", value.toReal()); + case BrightnessAdjustment: { + if (!setColorBalanceValue("brightness", value.toReal())) { +#ifdef USE_V4L + m_v4lImageControl->setParameter(parameter, value); +#endif + } + } break; - case SaturationAdjustment: - setColorBalanceValue("saturation", value.toReal()); + case SaturationAdjustment: { + if (!setColorBalanceValue("saturation", value.toReal())) { +#ifdef USE_V4L + m_v4lImageControl->setParameter(parameter, value); +#endif + } + } + break; + case SharpeningAdjustment: { +#ifdef USE_V4L + m_v4lImageControl->setParameter(parameter, value); +#endif + } break; case WhiteBalancePreset: { if (!setWhiteBalanceMode(value.value())) { diff --git a/src/plugins/gstreamer/camerabin/camerabinv4limageprocessing.cpp b/src/plugins/gstreamer/camerabin/camerabinv4limageprocessing.cpp index 47522565c..bf51cbfd0 100644 --- a/src/plugins/gstreamer/camerabin/camerabinv4limageprocessing.cpp +++ b/src/plugins/gstreamer/camerabin/camerabinv4limageprocessing.cpp @@ -92,6 +92,19 @@ bool CameraBinV4LImageProcessing::isParameterValueSupported( } break; + case QCameraImageProcessingControl::ContrastAdjustment: // falling back + case QCameraImageProcessingControl::SaturationAdjustment: // falling back + case QCameraImageProcessingControl::BrightnessAdjustment: // falling back + case QCameraImageProcessingControl::SharpeningAdjustment: { + const qint32 sourceValue = sourceImageProcessingParameterValue( + value.toReal(), (*sourceValueInfo)); + if (sourceValue < (*sourceValueInfo).minimumValue + || sourceValue > (*sourceValueInfo).maximumValue) { + return false; + } + } + break; + default: return false; } @@ -140,6 +153,14 @@ QVariant CameraBinV4LImageProcessing::parameter( case QCameraImageProcessingControl::ColorTemperature: return QVariant::fromValue(control.value); + case QCameraImageProcessingControl::ContrastAdjustment: // falling back + case QCameraImageProcessingControl::SaturationAdjustment: // falling back + case QCameraImageProcessingControl::BrightnessAdjustment: // falling back + case QCameraImageProcessingControl::SharpeningAdjustment: { + return scaledImageProcessingParameterValue( + control.value, (*sourceValueInfo)); + } + default: return QVariant(); } @@ -184,6 +205,14 @@ void CameraBinV4LImageProcessing::setParameter( control.value = value.toInt(); break; + case QCameraImageProcessingControl::ContrastAdjustment: // falling back + case QCameraImageProcessingControl::SaturationAdjustment: // falling back + case QCameraImageProcessingControl::BrightnessAdjustment: // falling back + case QCameraImageProcessingControl::SharpeningAdjustment: + control.value = sourceImageProcessingParameterValue( + value.toReal(), (*sourceValueInfo)); + break; + default: return; } @@ -213,7 +242,11 @@ void CameraBinV4LImageProcessing::updateParametersInfo( QCameraImageProcessingControl::ProcessingParameter parameter; } supportedParametersEntries[] = { { V4L2_CID_AUTO_WHITE_BALANCE, QCameraImageProcessingControl::WhiteBalancePreset }, - { V4L2_CID_WHITE_BALANCE_TEMPERATURE, QCameraImageProcessingControl::ColorTemperature } + { V4L2_CID_WHITE_BALANCE_TEMPERATURE, QCameraImageProcessingControl::ColorTemperature }, + { V4L2_CID_CONTRAST, QCameraImageProcessingControl::ContrastAdjustment }, + { V4L2_CID_SATURATION, QCameraImageProcessingControl::SaturationAdjustment }, + { V4L2_CID_BRIGHTNESS, QCameraImageProcessingControl::BrightnessAdjustment }, + { V4L2_CID_SHARPNESS, QCameraImageProcessingControl::SharpeningAdjustment } }; for (int i = 0; i < int(sizeof(supportedParametersEntries) / sizeof(SupportedParameterEntry)); ++i) { @@ -239,4 +272,33 @@ void CameraBinV4LImageProcessing::updateParametersInfo( } } +qreal CameraBinV4LImageProcessing::scaledImageProcessingParameterValue( + qint32 sourceValue, const SourceParameterValueInfo &sourceValueInfo) +{ + if (sourceValue == sourceValueInfo.defaultValue) { + return 0.0f; + } else if (sourceValue < sourceValueInfo.defaultValue) { + return ((sourceValue - sourceValueInfo.minimumValue) + / qreal(sourceValueInfo.defaultValue - sourceValueInfo.minimumValue)) + + (-1.0f); + } else { + return ((sourceValue - sourceValueInfo.defaultValue) + / qreal(sourceValueInfo.maximumValue - sourceValueInfo.defaultValue)); + } +} + +qint32 CameraBinV4LImageProcessing::sourceImageProcessingParameterValue( + qreal scaledValue, const SourceParameterValueInfo &valueRange) +{ + if (qFuzzyIsNull(scaledValue)) { + return valueRange.defaultValue; + } else if (scaledValue < 0.0f) { + return ((scaledValue - (-1.0f)) * (valueRange.defaultValue - valueRange.minimumValue)) + + valueRange.minimumValue; + } else { + return (scaledValue * (valueRange.maximumValue - valueRange.defaultValue)) + + valueRange.defaultValue; + } +} + QT_END_NAMESPACE diff --git a/src/plugins/gstreamer/camerabin/camerabinv4limageprocessing.h b/src/plugins/gstreamer/camerabin/camerabinv4limageprocessing.h index 03b3917ed..7961d6c0d 100644 --- a/src/plugins/gstreamer/camerabin/camerabinv4limageprocessing.h +++ b/src/plugins/gstreamer/camerabin/camerabinv4limageprocessing.h @@ -70,6 +70,10 @@ private: quint32 cid; // V4L control id }; + static qreal scaledImageProcessingParameterValue( + qint32 sourceValue, const SourceParameterValueInfo &sourceValueInfo); + static qint32 sourceImageProcessingParameterValue( + qreal scaledValue, const SourceParameterValueInfo &valueRange); private: CameraBinSession *m_session; QMap m_parametersInfo; -- cgit v1.2.3