From fcb511b6d6985820e0c049e6bd0f25e8715e9e3f Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Tue, 8 Dec 2015 21:58:16 +0300 Subject: [PATCH] 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 --- .../directshow/camera/dscamerasession.cpp | 56 ++++++------------- .../directshow/camera/dscamerasession.h | 2 +- 2 files changed, 18 insertions(+), 40 deletions(-) diff --git a/src/plugins/directshow/camera/dscamerasession.cpp b/src/plugins/directshow/camera/dscamerasession.cpp index e0261e03..2e92cb37 100644 --- a/src/plugins/directshow/camera/dscamerasession.cpp +++ b/src/plugins/directshow/camera/dscamerasession.cpp @@ -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(&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( - capsFlags == VideoProcAmp_Flags_Auto + (*sourceValueInfo).capsFlags == VideoProcAmp_Flags_Auto ? QCameraImageProcessing::WhiteBalanceAuto : QCameraImageProcessing::WhiteBalanceManual); case QCameraImageProcessingControl::ColorTemperature: - return QVariant::fromValue(sourceValue); + return QVariant::fromValue((*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(property); m_imageProcessingParametersInfos.insert(processingParameter, sourceValueInfo); diff --git a/src/plugins/directshow/camera/dscamerasession.h b/src/plugins/directshow/camera/dscamerasession.h index 619a006f..768e3583 100644 --- a/src/plugins/directshow/camera/dscamerasession.h +++ b/src/plugins/directshow/camera/dscamerasession.h @@ -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);