DirectShow: Get current image processing parameter from the cache

We can simplify a code, do not need to call pVideoProcAmp->Get()
each time when we want to get current parameter value. It is
better to do this once from updateImageProcessingParametersInfos().
In this case we will return desired parameter from the local cache.

Change-Id: If33c3882230c9ae817071ace5b792dfe31685a7f
Reviewed-by: Yoann Lopes <yoann.lopes@theqtcompany.com>
This commit is contained in:
Denis Shienkov
2015-12-08 21:58:16 +03:00
committed by Yoann Lopes
parent 5becd7c1a9
commit fcb511b6d6
2 changed files with 18 additions and 40 deletions

View File

@@ -231,16 +231,16 @@ void DSCameraSession::setViewfinderSettings(const QCameraViewfinderSettings &set
}
qreal DSCameraSession::scaledImageProcessingParameterValue(
qint32 sourceValue, const ImageProcessingParameterInfo &sourceValueInfo)
const ImageProcessingParameterInfo &sourceValueInfo)
{
if (sourceValue == sourceValueInfo.defaultValue) {
if (sourceValueInfo.currentValue == sourceValueInfo.defaultValue) {
return 0.0f;
} else if (sourceValue < sourceValueInfo.defaultValue) {
return ((sourceValue - sourceValueInfo.minimumValue)
} else if (sourceValueInfo.currentValue < sourceValueInfo.defaultValue) {
return ((sourceValueInfo.currentValue - sourceValueInfo.minimumValue)
/ qreal(sourceValueInfo.defaultValue - sourceValueInfo.minimumValue))
+ (-1.0f);
} else {
return ((sourceValue - sourceValueInfo.defaultValue)
return ((sourceValueInfo.currentValue - sourceValueInfo.defaultValue)
/ qreal(sourceValueInfo.maximumValue - sourceValueInfo.defaultValue));
}
}
@@ -349,52 +349,22 @@ QVariant DSCameraSession::imageProcessingParameter(
if (sourceValueInfo == m_imageProcessingParametersInfos.constEnd())
return QVariant();
IAMVideoProcAmp *pVideoProcAmp = NULL;
HRESULT hr = m_graphBuilder->FindInterface(
NULL,
NULL,
m_sourceFilter,
IID_IAMVideoProcAmp,
reinterpret_cast<void**>(&pVideoProcAmp)
);
if (FAILED(hr) || !pVideoProcAmp) {
qWarning() << "failed to find the video proc amp";
return QVariant();
}
LONG sourceValue = 0;
LONG capsFlags = 0;
hr = pVideoProcAmp->Get(
(*sourceValueInfo).videoProcAmpProperty,
&sourceValue,
&capsFlags);
pVideoProcAmp->Release();
if (FAILED(hr)) {
qWarning() << "failed to get the parameter value";
return QVariant();
}
switch (parameter) {
case QCameraImageProcessingControl::WhiteBalancePreset:
return QVariant::fromValue<QCameraImageProcessing::WhiteBalanceMode>(
capsFlags == VideoProcAmp_Flags_Auto
(*sourceValueInfo).capsFlags == VideoProcAmp_Flags_Auto
? QCameraImageProcessing::WhiteBalanceAuto
: QCameraImageProcessing::WhiteBalanceManual);
case QCameraImageProcessingControl::ColorTemperature:
return QVariant::fromValue<qint32>(sourceValue);
return QVariant::fromValue<qint32>((*sourceValueInfo).currentValue);
case QCameraImageProcessingControl::ContrastAdjustment: // falling back
case QCameraImageProcessingControl::SaturationAdjustment: // falling back
case QCameraImageProcessingControl::BrightnessAdjustment: // falling back
case QCameraImageProcessingControl::SharpeningAdjustment:
return scaledImageProcessingParameterValue(
sourceValue, (*sourceValueInfo));
return scaledImageProcessingParameterValue((*sourceValueInfo));
default:
return QVariant();
@@ -1032,7 +1002,7 @@ void DSCameraSession::updateImageProcessingParametersInfos()
ImageProcessingParameterInfo sourceValueInfo;
LONG steppingDelta = 0;
const HRESULT hr = pVideoProcAmp->GetRange(
HRESULT hr = pVideoProcAmp->GetRange(
property,
&sourceValueInfo.minimumValue,
&sourceValueInfo.maximumValue,
@@ -1043,6 +1013,14 @@ void DSCameraSession::updateImageProcessingParametersInfos()
if (FAILED(hr))
continue;
hr = pVideoProcAmp->Get(
property,
&sourceValueInfo.currentValue,
&sourceValueInfo.capsFlags);
if (FAILED(hr))
continue;
sourceValueInfo.videoProcAmpProperty = static_cast<VideoProcAmpProperty>(property);
m_imageProcessingParametersInfos.insert(processingParameter, sourceValueInfo);

View File

@@ -161,7 +161,7 @@ private:
// These static functions are used for scaling of adjustable parameters,
// which have the ranges from -1.0 to +1.0 in the QCameraImageProcessing API.
static qreal scaledImageProcessingParameterValue(
qint32 sourceValue, const ImageProcessingParameterInfo &sourceValueInfo);
const ImageProcessingParameterInfo &sourceValueInfo);
static qint32 sourceImageProcessingParameterValue(
qreal scaledValue, const ImageProcessingParameterInfo &sourceValueInfo);