diff options
author | Lars Knoll <lars.knoll@qt.io> | 2021-03-11 09:42:19 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2021-03-23 13:53:06 +0000 |
commit | e68cd5e48805110611b342ad6fd547b3e8dc4ff3 (patch) | |
tree | 868d079bca70c9b952262c0b8feb03a6b9ecf959 | |
parent | 487a3e5ed850484ae7f521313f578174cf92e8d5 (diff) |
Add support for Hue adjustment to QCameraImageProcessing
Change-Id: I99dda60c2118972efd6d703de57cb43d0a1f0be5
Reviewed-by: Doris Verria <doris.verria@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
7 files changed, 108 insertions, 42 deletions
diff --git a/examples/multimediawidgets/camera/camera.cpp b/examples/multimediawidgets/camera/camera.cpp index c77af6482..dcbb4d50e 100644 --- a/examples/multimediawidgets/camera/camera.cpp +++ b/examples/multimediawidgets/camera/camera.cpp @@ -139,6 +139,7 @@ void Camera::setCamera(const QCameraInfo &cameraInfo) ui->brightnessSlider->setEnabled(false); ui->contrastSlider->setEnabled(false); ui->saturationSlider->setEnabled(false); + ui->hueSlider->setEnabled(false); } else { connect(ui->brightnessSlider, &QSlider::valueChanged, [imageProcessing](int value) { imageProcessing->setBrightness(value/100.); @@ -149,6 +150,9 @@ void Camera::setCamera(const QCameraInfo &cameraInfo) connect(ui->saturationSlider, &QSlider::valueChanged, [imageProcessing](int value) { imageProcessing->setSaturation(value/100.); }); + connect(ui->hueSlider, &QSlider::valueChanged, [imageProcessing](int value) { + imageProcessing->setHue(value/100.); + }); } diff --git a/examples/multimediawidgets/camera/camera.ui b/examples/multimediawidgets/camera/camera.ui index ad14096ba..3fd944aed 100644 --- a/examples/multimediawidgets/camera/camera.ui +++ b/examples/multimediawidgets/camera/camera.ui @@ -25,21 +25,23 @@ <string>Image</string> </attribute> <layout class="QGridLayout" name="gridLayout"> - <item row="4" column="0"> - <widget class="QLabel" name="label_3"> - <property name="text"> - <string>Contrast</string> + <item row="8" column="0"> + <widget class="QSlider" name="saturationSlider"> + <property name="minimum"> + <number>-100</number> </property> - </widget> - </item> - <item row="10" column="0"> - <widget class="QLabel" name="label"> - <property name="text"> - <string>Exposure Compensation:</string> + <property name="maximum"> + <number>100</number> + </property> + <property name="value"> + <number>0</number> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> </property> </widget> </item> - <item row="9" column="0"> + <item row="11" column="0"> <spacer name="verticalSpacer_2"> <property name="orientation"> <enum>Qt::Vertical</enum> @@ -52,10 +54,16 @@ </property> </spacer> </item> - <item row="7" column="0"> - <widget class="QLabel" name="label_2"> - <property name="text"> - <string>Saturation</string> + <item row="6" column="0"> + <widget class="QSlider" name="contrastSlider"> + <property name="minimum"> + <number>-100</number> + </property> + <property name="maximum"> + <number>100</number> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> </property> </widget> </item> @@ -72,6 +80,34 @@ </property> </widget> </item> + <item row="2" column="0"> + <widget class="QLabel" name="label_4"> + <property name="text"> + <string>Brightness</string> + </property> + </widget> + </item> + <item row="7" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Saturation</string> + </property> + </widget> + </item> + <item row="4" column="0"> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Contrast</string> + </property> + </widget> + </item> + <item row="12" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Exposure Compensation:</string> + </property> + </widget> + </item> <item row="0" column="0"> <widget class="QPushButton" name="takeImageButton"> <property name="enabled"> @@ -86,7 +122,14 @@ </property> </widget> </item> - <item row="11" column="0"> + <item row="9" column="0"> + <widget class="QLabel" name="label_5"> + <property name="text"> + <string>Hue</string> + </property> + </widget> + </item> + <item row="13" column="0"> <widget class="QSlider" name="exposureCompensation"> <property name="minimum"> <number>-4</number> @@ -105,31 +148,8 @@ </property> </widget> </item> - <item row="8" column="0"> - <widget class="QSlider" name="saturationSlider"> - <property name="minimum"> - <number>-100</number> - </property> - <property name="maximum"> - <number>100</number> - </property> - <property name="value"> - <number>0</number> - </property> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - </widget> - </item> - <item row="2" column="0"> - <widget class="QLabel" name="label_4"> - <property name="text"> - <string>Brightness</string> - </property> - </widget> - </item> - <item row="6" column="0"> - <widget class="QSlider" name="contrastSlider"> + <item row="10" column="0"> + <widget class="QSlider" name="hueSlider"> <property name="minimum"> <number>-100</number> </property> diff --git a/src/multimedia/camera/qcameraimageprocessing.cpp b/src/multimedia/camera/qcameraimageprocessing.cpp index dff580274..9da9e6c88 100644 --- a/src/multimedia/camera/qcameraimageprocessing.cpp +++ b/src/multimedia/camera/qcameraimageprocessing.cpp @@ -261,7 +261,28 @@ void QCameraImageProcessing::setSaturation(qreal value) Q_D(QCameraImageProcessing); if (d->imageControl) d->imageControl->setParameter(QPlatformCameraImageProcessing::SaturationAdjustment, - QVariant(value)); + QVariant(value)); +} + +qreal QCameraImageProcessing::hue() const +{ + Q_D(const QCameraImageProcessing); + if (!d->imageControl) + return 0.; + return d->imageControl->parameter(QPlatformCameraImageProcessing::HueAdjustment).toReal(); +} + +/*! + Sets the hue adjustment value to \a value. + + Valid hue values range between -1.0 and 1.0, with a default of 0. +*/ +void QCameraImageProcessing::setHue(qreal value) +{ + Q_D(QCameraImageProcessing); + if (d->imageControl) + d->imageControl->setParameter(QPlatformCameraImageProcessing::HueAdjustment, + QVariant(value)); } /*! diff --git a/src/multimedia/camera/qcameraimageprocessing.h b/src/multimedia/camera/qcameraimageprocessing.h index 5ddd51f77..8370d9a3a 100644 --- a/src/multimedia/camera/qcameraimageprocessing.h +++ b/src/multimedia/camera/qcameraimageprocessing.h @@ -104,6 +104,9 @@ public: qreal saturation() const; void setSaturation(qreal value); + qreal hue() const; + void setHue(qreal value); + ColorFilter colorFilter() const; void setColorFilter(ColorFilter filter); bool isColorFilterSupported(ColorFilter filter) const; diff --git a/src/multimedia/platform/gstreamer/mediacapture/qgstreamercameraimageprocessing.cpp b/src/multimedia/platform/gstreamer/mediacapture/qgstreamercameraimageprocessing.cpp index 5e2f21b1a..03adf3e02 100644 --- a/src/multimedia/platform/gstreamer/mediacapture/qgstreamercameraimageprocessing.cpp +++ b/src/multimedia/platform/gstreamer/mediacapture/qgstreamercameraimageprocessing.cpp @@ -281,6 +281,8 @@ bool QGstreamerImageProcessing::isParameterSupported(QPlatformCameraImageProcess return v4l2Saturation.cid != 0; case BrightnessAdjustment: return v4l2Brightness.cid != 0; + case HueAdjustment: + return v4l2Hue.cid != 0; case ColorFilter: return false; } @@ -451,6 +453,13 @@ void QGstreamerImageProcessing::updateV4L2Controls() qDebug() << "V4L2: query saturation" << queryControl.minimum << queryControl.default_value << queryControl.maximum; } + ::memset(&queryControl, 0, sizeof(queryControl)); + queryControl.id = V4L2_CID_HUE; + if (::ioctl(fd, VIDIOC_QUERYCTRL, &queryControl) == 0) { + v4l2Hue = { queryControl.id, queryControl.default_value, queryControl.minimum, queryControl.maximum }; + qDebug() << "V4L2: query hue" << queryControl.minimum << queryControl.default_value << queryControl.maximum; + } + qt_safe_close(fd); } @@ -498,6 +507,9 @@ std::optional<float> QGstreamerImageProcessing::getV4L2Param(QGstreamerImageProc case BrightnessAdjustment: info = &v4l2Brightness; break; + case HueAdjustment: + info = &v4l2Hue; + break; case ColorTemperature: info = &v4l2ColorTemperature; break; @@ -565,6 +577,10 @@ bool QGstreamerImageProcessing::setV4L2Param(ProcessingParameter parameter, cons control.id = v4l2Brightness.cid; control.value = sourceImageProcessingParameterValue(value.toFloat(), v4l2Brightness); break; + case QPlatformCameraImageProcessing::HueAdjustment: // falling back + control.id = v4l2Hue.cid; + control.value = sourceImageProcessingParameterValue(value.toFloat(), v4l2Brightness); + break; default: return false; } diff --git a/src/multimedia/platform/gstreamer/mediacapture/qgstreamercameraimageprocessing_p.h b/src/multimedia/platform/gstreamer/mediacapture/qgstreamercameraimageprocessing_p.h index 93c27482b..2a9ff5783 100644 --- a/src/multimedia/platform/gstreamer/mediacapture/qgstreamercameraimageprocessing_p.h +++ b/src/multimedia/platform/gstreamer/mediacapture/qgstreamercameraimageprocessing_p.h @@ -122,6 +122,7 @@ private: SourceParameterValueInfo v4l2Brightness; SourceParameterValueInfo v4l2Contrast; SourceParameterValueInfo v4l2Saturation; + SourceParameterValueInfo v4l2Hue; #endif }; diff --git a/src/multimedia/platform/qplatformcameraimageprocessing_p.h b/src/multimedia/platform/qplatformcameraimageprocessing_p.h index 2d5d0d6f9..0989aa399 100644 --- a/src/multimedia/platform/qplatformcameraimageprocessing_p.h +++ b/src/multimedia/platform/qplatformcameraimageprocessing_p.h @@ -73,6 +73,7 @@ public: ColorTemperature, ContrastAdjustment, SaturationAdjustment, + HueAdjustment, BrightnessAdjustment, ColorFilter, }; |