Add a color filter property to QCameraImageProcessing.

[ChangeLog] New color filter property for QCameraImageProcessing.

Change-Id: I999e349e3e4f284b533fa62ba50903fbd21cb400
Reviewed-by: Yoann Lopes <yoann.lopes@theqtcompany.com>
This commit is contained in:
Andrew den Exter
2014-07-09 13:38:25 +10:00
committed by Andrew den Exter
parent be7fef656a
commit 25ad679c25
9 changed files with 212 additions and 7 deletions

View File

@@ -103,6 +103,9 @@ public:
qmlRegisterUncreatableType<QDeclarativeCameraViewfinder>(uri, 5, 4, "CameraViewfinder",
trUtf8("CameraViewfinder is provided by Camera"));
// 5.5 types
qmlRegisterUncreatableType<QDeclarativeCameraImageProcessing, 1>(uri, 5, 5, "CameraImageProcessing", trUtf8("CameraImageProcessing is provided by Camera"));
qmlRegisterType<QDeclarativeMediaMetaData>();
}

View File

@@ -219,6 +219,42 @@ void QDeclarativeCameraImageProcessing::setDenoisingLevel(qreal value)
}
}
/*!
\qmlproperty QtMultimedia::CameraImageProcessing::colorFilter
This property holds which color filter if any will be applied to image data captured by the camera.
It can be one of:
\table
\row \li CameraImageProcessing.ColorFilterNone \li No filter is applied to images.
\row \li CameraImageProcessing.ColorFilterGrayscale \li A grayscale filter.
\row \li CameraImageProcessing.ColorFilterNegative \li A negative filter.
\row \li CameraImageProcessing.ColorFilterSolarize \li A solarize filter.
\row \li CameraImageProcessing.ColorFilterSepia \li A sepia filter.
\row \li CameraImageProcessing.ColorFilterPosterize \li A posterize filter.
\row \li CameraImageProcessing.ColorFilterWhiteboard \li A whiteboard filter.
\row \li CameraImageProcessing.ColorFilterBlackboard \li A blackboard filter.
\row \li CameraImageProcessing.ColorFilterAqua \li An aqua filter.
\row \li CameraImageProcessing.ColorFilterVendor \li The base value for vendor defined filters.
\endtable
\since 5.5
*/
QDeclarativeCameraImageProcessing::ColorFilter QDeclarativeCameraImageProcessing::colorFilter() const
{
return ColorFilter(m_imageProcessing->colorFilter());
}
void QDeclarativeCameraImageProcessing::setColorFilter(ColorFilter filter)
{
if (this->colorFilter() != filter) {
m_imageProcessing->setColorFilter(QCameraImageProcessing::ColorFilter(filter));
emit colorFilterChanged();
}
}
/*!
\qmlsignal QtMultimedia::Camera::whiteBalanceModeChanged(Camera::WhiteBalanceMode)
This signal is emitted when the \c whiteBalanceMode property is changed.

View File

@@ -56,6 +56,7 @@ class QDeclarativeCameraImageProcessing : public QObject
{
Q_OBJECT
Q_ENUMS(WhiteBalanceMode)
Q_ENUMS(ColorFilter)
Q_PROPERTY(WhiteBalanceMode whiteBalanceMode READ whiteBalanceMode WRITE setWhiteBalanceMode NOTIFY whiteBalanceModeChanged)
Q_PROPERTY(qreal manualWhiteBalance READ manualWhiteBalance WRITE setManualWhiteBalance NOTIFY manualWhiteBalanceChanged)
@@ -63,7 +64,7 @@ class QDeclarativeCameraImageProcessing : public QObject
Q_PROPERTY(qreal saturation READ saturation WRITE setSaturation NOTIFY saturationChanged)
Q_PROPERTY(qreal sharpeningLevel READ sharpeningLevel WRITE setSharpeningLevel NOTIFY sharpeningLevelChanged)
Q_PROPERTY(qreal denoisingLevel READ denoisingLevel WRITE setDenoisingLevel NOTIFY denoisingLevelChanged)
Q_PROPERTY(ColorFilter colorFilter READ colorFilter WRITE setColorFilter NOTIFY colorFilterChanged REVISION 1)
public:
enum WhiteBalanceMode {
WhiteBalanceAuto = QCameraImageProcessing::WhiteBalanceAuto,
@@ -78,6 +79,19 @@ public:
WhiteBalanceVendor = QCameraImageProcessing::WhiteBalanceVendor
};
enum ColorFilter {
ColorFilterNone = QCameraImageProcessing::ColorFilterNone,
ColorFilterGrayscale = QCameraImageProcessing::ColorFilterGrayscale,
ColorFilterNegative = QCameraImageProcessing::ColorFilterNegative,
ColorFilterSolarize = QCameraImageProcessing::ColorFilterSolarize,
ColorFilterSepia = QCameraImageProcessing::ColorFilterSepia,
ColorFilterPosterize = QCameraImageProcessing::ColorFilterPosterize,
ColorFilterWhiteboard = QCameraImageProcessing::ColorFilterWhiteboard,
ColorFilterBlackboard = QCameraImageProcessing::ColorFilterBlackboard,
ColorFilterAqua = QCameraImageProcessing::ColorFilterAqua,
ColorFilterVendor = QCameraImageProcessing::ColorFilterVendor
};
~QDeclarativeCameraImageProcessing();
WhiteBalanceMode whiteBalanceMode() const;
@@ -88,6 +102,8 @@ public:
qreal sharpeningLevel() const;
qreal denoisingLevel() const;
ColorFilter colorFilter() const;
public Q_SLOTS:
void setWhiteBalanceMode(QDeclarativeCameraImageProcessing::WhiteBalanceMode mode) const;
void setManualWhiteBalance(qreal colorTemp) const;
@@ -97,6 +113,8 @@ public Q_SLOTS:
void setSharpeningLevel(qreal value);
void setDenoisingLevel(qreal value);
void setColorFilter(ColorFilter colorFilter);
Q_SIGNALS:
void whiteBalanceModeChanged(QDeclarativeCameraImageProcessing::WhiteBalanceMode) const;
void manualWhiteBalanceChanged(qreal) const;
@@ -106,6 +124,8 @@ Q_SIGNALS:
void sharpeningLevelChanged(qreal);
void denoisingLevelChanged(qreal);
void colorFilterChanged();
private:
friend class QDeclarativeCamera;
QDeclarativeCameraImageProcessing(QCamera *camera, QObject *parent = 0);

View File

@@ -49,6 +49,7 @@ QT_BEGIN_NAMESPACE
static void qRegisterCameraImageProcessingMetaTypes()
{
qRegisterMetaType<QCameraImageProcessing::WhiteBalanceMode>();
qRegisterMetaType<QCameraImageProcessing::ColorFilter>();
}
Q_CONSTRUCTOR_FUNCTION(qRegisterCameraImageProcessingMetaTypes)
@@ -317,5 +318,63 @@ void QCameraImageProcessing::setDenoisingLevel(qreal level)
\value WhiteBalanceVendor Base value for vendor defined white balance modes.
*/
/*!
\enum QCameraImageProcessing::Filter
\value ColorFilterNone No filter is applied to images.
\value ColorFilterGrayscale A grayscale filter.
\value ColorFilterNegative A negative filter.
\value ColorFilterSolarize A solarize filter.
\value ColorFilterSepia A sepia filter.
\value ColorFilterPosterize A posterize filter.
\value ColorFilterWhiteboard A whiteboard filter.
\value ColorFilterBlackboard A blackboard filter.
\value ColorFilterAqua An aqua filter.
\value ColorFilterVendor The base value for vendor defined filters.
\since 5.5
*/
/*!
Returns the color filter which will be applied to image data captured by the camera.
\since 5.5
*/
QCameraImageProcessing::ColorFilter QCameraImageProcessing::colorFilter() const
{
return d_func()->imageControl->parameter(QCameraImageProcessingControl::ColorFilter)
.value<QCameraImageProcessing::ColorFilter>();
}
/*!
Sets the color \a filter which will be applied to image data captured by the camera.
\since 5.5
*/
void QCameraImageProcessing::setColorFilter(QCameraImageProcessing::ColorFilter filter)
{
d_func()->imageControl->setParameter(
QCameraImageProcessingControl::ColorFilter,
QVariant::fromValue<QCameraImageProcessing::ColorFilter>(filter));
}
/*!
Returns true if a color \a filter is supported.
\since 5.5
*/
bool QCameraImageProcessing::isColorFilterSupported(QCameraImageProcessing::ColorFilter filter) const
{
return d_func()->imageControl->isParameterValueSupported(
QCameraImageProcessingControl::ColorFilter,
QVariant::fromValue<QCameraImageProcessing::ColorFilter>(filter));
}
#include "moc_qcameraimageprocessing.cpp"
QT_END_NAMESPACE

View File

@@ -54,7 +54,7 @@ class QCameraImageProcessingPrivate;
class Q_MULTIMEDIA_EXPORT QCameraImageProcessing : public QObject
{
Q_OBJECT
Q_ENUMS(WhiteBalanceMode)
Q_ENUMS(WhiteBalanceMode ColorFilter)
public:
enum WhiteBalanceMode {
WhiteBalanceAuto = 0,
@@ -69,6 +69,19 @@ public:
WhiteBalanceVendor = 1000
};
enum ColorFilter {
ColorFilterNone,
ColorFilterGrayscale,
ColorFilterNegative,
ColorFilterSolarize,
ColorFilterSepia,
ColorFilterPosterize,
ColorFilterWhiteboard,
ColorFilterBlackboard,
ColorFilterAqua,
ColorFilterVendor = 1000
};
bool isAvailable() const;
WhiteBalanceMode whiteBalanceMode() const;
@@ -90,6 +103,10 @@ public:
qreal denoisingLevel() const;
void setDenoisingLevel(qreal value);
ColorFilter colorFilter() const;
void setColorFilter(ColorFilter filter);
bool isColorFilterSupported(ColorFilter filter) const;
private:
friend class QCamera;
friend class QCameraPrivate;
@@ -104,7 +121,9 @@ private:
QT_END_NAMESPACE
Q_DECLARE_METATYPE(QCameraImageProcessing::WhiteBalanceMode)
Q_DECLARE_METATYPE(QCameraImageProcessing::ColorFilter)
Q_MEDIA_ENUM_DEBUG(QCameraImageProcessing, WhiteBalanceMode)
Q_MEDIA_ENUM_DEBUG(QCameraImageProcessing, ColorFilter)
#endif // QCAMERAIMAGEPROCESSING_H

View File

@@ -171,6 +171,8 @@ QCameraImageProcessingControl::~QCameraImageProcessingControl()
Adjustment of sharpening applied.
\value DenoisingAdjustment
Adjustment of denoising applied.
\value ColorFilter
Image filter applied. Since 5.5
\value ExtendedParameter
The base value for platform specific extended parameters.
*/

View File

@@ -66,6 +66,7 @@ public:
BrightnessAdjustment,
SharpeningAdjustment,
DenoisingAdjustment,
ColorFilter,
ExtendedParameter = 1000
};

View File

@@ -55,6 +55,30 @@ CameraBinImageProcessing::CameraBinImageProcessing(CameraBinSession *session)
m_mappedWbValues[GST_PHOTOGRAPHY_WB_MODE_TUNGSTEN] = QCameraImageProcessing::WhiteBalanceTungsten;
m_mappedWbValues[GST_PHOTOGRAPHY_WB_MODE_FLUORESCENT] = QCameraImageProcessing::WhiteBalanceFluorescent;
unlockWhiteBalance();
#if GST_CHECK_VERSION(1, 0, 0)
m_filterMap.insert(QCameraImageProcessing::ColorFilterNone, GST_PHOTOGRAPHY_COLOR_TONE_MODE_NORMAL);
if (m_session->photography()) {
m_filterMap.insert(QCameraImageProcessing::ColorFilterSepia, GST_PHOTOGRAPHY_COLOR_TONE_MODE_SEPIA);
m_filterMap.insert(QCameraImageProcessing::ColorFilterGrayscale, GST_PHOTOGRAPHY_COLOR_TONE_MODE_GRAYSCALE);
m_filterMap.insert(QCameraImageProcessing::ColorFilterNegative, GST_PHOTOGRAPHY_COLOR_TONE_MODE_NEGATIVE);
m_filterMap.insert(QCameraImageProcessing::ColorFilterSolarize, GST_PHOTOGRAPHY_COLOR_TONE_MODE_SOLARIZE);
#if GST_CHECK_VERSION(1, 2, 0)
m_filterMap.insert(QCameraImageProcessing::ColorFilterPosterize, GST_PHOTOGRAPHY_COLOR_TONE_MODE_POSTERIZE);
m_filterMap.insert(QCameraImageProcessing::ColorFilterWhiteboard, GST_PHOTOGRAPHY_COLOR_TONE_MODE_WHITEBOARD);
m_filterMap.insert(QCameraImageProcessing::ColorFilterBlackboard, GST_PHOTOGRAPHY_COLOR_TONE_MODE_BLACKBOARD);
m_filterMap.insert(QCameraImageProcessing::ColorFilterAqua, GST_PHOTOGRAPHY_COLOR_TONE_MODE_AQUA);
#endif
}
#else
m_filterMap.insert(QCameraImageProcessing::ColorFilterNone, GST_PHOTOGRAPHY_COLOUR_TONE_MODE_NORMAL);
if (m_session->photography()) {
m_filterMap.insert(QCameraImageProcessing::ColorFilterSepia, GST_PHOTOGRAPHY_COLOUR_TONE_MODE_SEPIA);
m_filterMap.insert(QCameraImageProcessing::ColorFilterGrayscale, GST_PHOTOGRAPHY_COLOUR_TONE_MODE_GRAYSCALE);
m_filterMap.insert(QCameraImageProcessing::ColorFilterNegative, GST_PHOTOGRAPHY_COLOUR_TONE_MODE_NEGATIVE);
m_filterMap.insert(QCameraImageProcessing::ColorFilterSolarize, GST_PHOTOGRAPHY_COLOUR_TONE_MODE_SOLARIZE);
}
#endif
#endif
updateColorBalanceValues();
@@ -179,6 +203,14 @@ bool CameraBinImageProcessing::isParameterValueSupported(QCameraImageProcessingC
return qAbs(value.toReal()) <= 1.0;
case WhiteBalancePreset:
return isWhiteBalanceModeSupported(value.value<QCameraImageProcessing::WhiteBalanceMode>());
case ColorFilter: {
const QCameraImageProcessing::ColorFilter filter = value.value<QCameraImageProcessing::ColorFilter>();
#ifdef HAVE_GST_PHOTOGRAPHY
return m_filterMap.contains(filter);
#else
return filter == QCameraImageProcessing::ColorFilterNone;
#endif
}
default:
break;
}
@@ -189,12 +221,28 @@ bool CameraBinImageProcessing::isParameterValueSupported(QCameraImageProcessingC
QVariant CameraBinImageProcessing::parameter(
QCameraImageProcessingControl::ProcessingParameter parameter) const
{
if (parameter == QCameraImageProcessingControl::WhiteBalancePreset)
switch (parameter) {
case QCameraImageProcessingControl::WhiteBalancePreset:
return QVariant::fromValue<QCameraImageProcessing::WhiteBalanceMode>(whiteBalanceMode());
else if (m_values.contains(parameter))
return m_values.value(parameter);
else
return QVariant();
case QCameraImageProcessingControl::ColorFilter:
#ifdef HAVE_GST_PHOTOGRAPHY
if (GstPhotography *photography = m_session->photography()) {
#if GST_CHECK_VERSION(1, 0, 0)
GstPhotographyColorToneMode mode = GST_PHOTOGRAPHY_COLOR_TONE_MODE_NORMAL;
gst_photography_get_color_tone_mode(photography, &mode);
#else
GstColourToneMode mode = GST_PHOTOGRAPHY_COLOUR_TONE_MODE_NORMAL;
gst_photography_get_colour_tone_mode(photography, &mode);
#endif
return QVariant::fromValue(m_filterMap.key(mode, QCameraImageProcessing::ColorFilterNone));
}
#endif
return QVariant::fromValue(QCameraImageProcessing::ColorFilterNone);
default:
return m_values.contains(parameter)
? QVariant(m_values.value(parameter))
: QVariant();
}
}
void CameraBinImageProcessing::setParameter(QCameraImageProcessingControl::ProcessingParameter parameter,
@@ -213,6 +261,21 @@ void CameraBinImageProcessing::setParameter(QCameraImageProcessingControl::Proce
case WhiteBalancePreset:
setWhiteBalanceMode(value.value<QCameraImageProcessing::WhiteBalanceMode>());
break;
case QCameraImageProcessingControl::ColorFilter:
#ifdef HAVE_GST_PHOTOGRAPHY
if (GstPhotography *photography = m_session->photography()) {
#if GST_CHECK_VERSION(1, 0, 0)
gst_photography_set_color_tone_mode(photography, m_filterMap.value(
value.value<QCameraImageProcessing::ColorFilter>(),
GST_PHOTOGRAPHY_COLOR_TONE_MODE_NORMAL));
#else
gst_photography_set_colour_tone_mode(photography, m_filterMap.value(
value.value<QCameraImageProcessing::ColorFilter>(),
GST_PHOTOGRAPHY_COLOUR_TONE_MODE_NORMAL));
#endif
}
#endif
break;
default:
break;
}

View File

@@ -44,6 +44,7 @@
# include <gst/interfaces/photography.h>
# if !GST_CHECK_VERSION(1,0,0)
typedef GstWhiteBalanceMode GstPhotographyWhiteBalanceMode;
typedef GstColourToneMode GstPhotographyColorToneMode;
# endif
#endif
@@ -82,6 +83,7 @@ private:
QMap<QCameraImageProcessingControl::ProcessingParameter, int> m_values;
#ifdef HAVE_GST_PHOTOGRAPHY
QMap<GstPhotographyWhiteBalanceMode, QCameraImageProcessing::WhiteBalanceMode> m_mappedWbValues;
QMap<QCameraImageProcessing::ColorFilter, GstPhotographyColorToneMode> m_filterMap;
#endif
QCameraImageProcessing::WhiteBalanceMode m_whiteBalanceMode;
};