os/mm/mmplugins/cameraplugins/source/testcamera/test_image_processing.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmplugins/cameraplugins/source/testcamera/test_image_processing.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,441 @@
     1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// testimageprocessing.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include "test_image_processing.h"
    1.22 +#include <ecamerrors.h>
    1.23 +#include "ecamversion.h"
    1.24 +
    1.25 +CTestCamImgProc::CTestCamImgProc(CTestCamera& aOwner): iOwner(aOwner)
    1.26 +	{}
    1.27 +	
    1.28 +CTestCamImgProc::~CTestCamImgProc()
    1.29 +	{
    1.30 +	iSupportedTranformations.Close();
    1.31 +	iActiveTransformations.Close();
    1.32 +	iActiveTransformSequence.Close();
    1.33 +	
    1.34 +	CDataGlobal* globalData = static_cast <CDataGlobal*> (Dll::Tls());	
    1.35 +	if(globalData != NULL)
    1.36 +		{
    1.37 +		if(!globalData->iTestCamAdvSet && !globalData->iTestCamPresets && !globalData->iTestCamSnapshot)
    1.38 +			{
    1.39 +			delete globalData;
    1.40 +			Dll::FreeTls();
    1.41 +			}	
    1.42 +		else
    1.43 +			{
    1.44 +			globalData->iTestCamImgProc = NULL;	
    1.45 +			Dll::SetTls(globalData);
    1.46 +			}
    1.47 +		}
    1.48 +	}
    1.49 +		
    1.50 +CTestCamImgProc* CTestCamImgProc::NewL(CTestCamera& aOwner)
    1.51 +	{
    1.52 +	CDataGlobal* globalData = static_cast <CDataGlobal*> (Dll::Tls());
    1.53 +	
    1.54 +	if(globalData == NULL)
    1.55 +		{
    1.56 +		globalData = new (ELeave) CDataGlobal;
    1.57 +		CleanupStack::PushL(globalData);
    1.58 +		globalData->iImgProcReferenceCount = 0;
    1.59 +		globalData->iTestCamImgProc = new (ELeave) CTestCamImgProc(aOwner);
    1.60 +		CleanupStack::PushL(globalData->iTestCamImgProc);
    1.61 +		globalData->iTestCamImgProc->ConstructL();
    1.62 +		globalData->iTestCamImgProc->iRefCount = 1;
    1.63 +		User::LeaveIfError(Dll::SetTls(globalData));
    1.64 +		CleanupStack::Pop(globalData->iTestCamImgProc);
    1.65 +		CleanupStack::Pop(globalData);
    1.66 +		return globalData->iTestCamImgProc;
    1.67 +		}
    1.68 +	else
    1.69 +		{
    1.70 +		if(globalData->iTestCamImgProc == NULL)
    1.71 +			{
    1.72 +			globalData->iImgProcReferenceCount = 0;
    1.73 +			globalData->iTestCamImgProc = new (ELeave) CTestCamImgProc(aOwner);
    1.74 +			CleanupStack::PushL(globalData->iTestCamImgProc);
    1.75 +			globalData->iTestCamImgProc->ConstructL();
    1.76 +			globalData->iTestCamImgProc->iRefCount = 1;
    1.77 +			User::LeaveIfError(Dll::SetTls(globalData));
    1.78 +			CleanupStack::Pop(globalData->iTestCamImgProc);
    1.79 +			return globalData->iTestCamImgProc;
    1.80 +			}
    1.81 +			
    1.82 +		CTestCamImgProc* self = globalData->iTestCamImgProc;
    1.83 +		
    1.84 +		globalData->iImgProcReferenceCount++;
    1.85 +		self->iRefCount = globalData->iImgProcReferenceCount + 1;
    1.86 +		if (globalData->iImgProcReferenceCount == KNumOfImgProcExtensions-1)
    1.87 +			{
    1.88 +			globalData->iTestCamImgProc = NULL;
    1.89 +			if(!globalData->iTestCamAdvSet && !globalData->iTestCamPresets && !globalData->iTestCamSnapshot)
    1.90 +				{
    1.91 +				delete globalData;
    1.92 +				Dll::FreeTls();
    1.93 +				}
    1.94 +			else
    1.95 +				{
    1.96 +				User::LeaveIfError(Dll::SetTls(globalData));	
    1.97 +				}
    1.98 +			}
    1.99 +		else
   1.100 +			{
   1.101 +			User::LeaveIfError(Dll::SetTls(globalData));	
   1.102 +			}
   1.103 +		return self;		
   1.104 +		}
   1.105 +	}
   1.106 +
   1.107 +void CTestCamImgProc::Release()
   1.108 +	{
   1.109 +	iRefCount--; 
   1.110 +	if(iRefCount == 0)
   1.111 +		{
   1.112 +		iOwner.iImgProcImpl = NULL;
   1.113 +		delete this;
   1.114 +		}
   1.115 +	}	
   1.116 +	
   1.117 +void CTestCamImgProc::ConstructL()
   1.118 +	{
   1.119 +	iSupportedTranformations.Reset();
   1.120 +	iSupportedTranformations.AppendL(KUidECamEventImageProcessingAdjustBrightness);
   1.121 +	iSupportedTranformations.AppendL(KUidECamEventImageProcessingAdjustContrast);
   1.122 +	
   1.123 +	iActiveTransformations.Reset();
   1.124 +	
   1.125 +	iActiveTransformSequence.Reset();
   1.126 +	}
   1.127 +	
   1.128 +void CTestCamImgProc::GetSupportedTransformationsL(RArray<TUid>& aTransformations) const
   1.129 +	{
   1.130 +	aTransformations.Reset();
   1.131 +	for(TInt index=0; index < iSupportedTranformations.Count(); index++)
   1.132 +		{
   1.133 +		aTransformations.AppendL(iSupportedTranformations[index]);
   1.134 +		}
   1.135 +	}
   1.136 +
   1.137 +void CTestCamImgProc::GetActiveTransformationsL(RArray<TUid>& aTransformations) const
   1.138 +	{
   1.139 +	aTransformations.Reset();
   1.140 +	for(TInt index=0; index < iActiveTransformations.Count(); index++)
   1.141 +		{
   1.142 +		aTransformations.AppendL(iActiveTransformations[index]);
   1.143 +		}	
   1.144 +	}
   1.145 +	
   1.146 +void CTestCamImgProc::GetTransformationSupportedValuesL(TUid aTransformation, RArray<TInt>& aValues, TValueInfo& aInfo) const
   1.147 +	{
   1.148 +	TInt err = iActiveTransformations.Find(aTransformation);
   1.149 +	if(err == KErrNotFound)
   1.150 +		{
   1.151 +		User::Leave(err);
   1.152 +		}
   1.153 +		
   1.154 +	switch(aTransformation.iUid)
   1.155 +		{
   1.156 +		case KUidECamEventImageProcessingAdjustBrightnessUidValue:
   1.157 +			{
   1.158 +			aInfo = EContinuousRangeMinMax;
   1.159 +			aValues.Reset();
   1.160 +			aValues.AppendL(KMinBrightness);
   1.161 +			aValues.AppendL(KMaxBrightness);	
   1.162 +			break;
   1.163 +			}
   1.164 +			
   1.165 +		case KUidECamEventImageProcessingAdjustContrastUidValue:
   1.166 +			{
   1.167 +			aInfo = EContinuousRangeMinMax;
   1.168 +			aValues.Reset();
   1.169 +			aValues.AppendL(KMinContrast);
   1.170 +			aValues.AppendL(KMaxContrast);	
   1.171 +			break;
   1.172 +			}
   1.173 +			
   1.174 +		default:
   1.175 +			User::Leave(KErrNotSupported);
   1.176 +		}
   1.177 +	}
   1.178 +	
   1.179 +TInt CTestCamImgProc::TransformationValue(TUid aTransformation) const
   1.180 +	{
   1.181 +	switch(aTransformation.iUid)
   1.182 +		{
   1.183 +		case KUidECamEventImageProcessingAdjustBrightnessUidValue:
   1.184 +			{
   1.185 +			return iOwner.iImgProcBrightness;
   1.186 +			}
   1.187 +			
   1.188 +		case KUidECamEventImageProcessingAdjustContrastUidValue:
   1.189 +			{
   1.190 +			return iOwner.iImgProcContrast;
   1.191 +			}
   1.192 +			
   1.193 +		default:
   1.194 +			return 0;
   1.195 +		}	
   1.196 +	}
   1.197 +	
   1.198 +TInt CTestCamImgProc::GetTransformationValue(TUid aTransformation, TInt& aTransformationValue) const
   1.199 +	{
   1.200 +	switch(aTransformation.iUid)
   1.201 +		{
   1.202 +		case KUidECamEventImageProcessingAdjustBrightnessUidValue:
   1.203 +			{
   1.204 +			aTransformationValue = iOwner.iImgProcBrightness;
   1.205 +			return KErrNone;
   1.206 +			}
   1.207 +			
   1.208 +		case KUidECamEventImageProcessingAdjustContrastUidValue:
   1.209 +			{
   1.210 +			aTransformationValue = iOwner.iImgProcContrast;
   1.211 +			return KErrNone;
   1.212 +			}
   1.213 +			
   1.214 +		default:
   1.215 +			return KErrNotSupported;
   1.216 +		}	
   1.217 +	}
   1.218 +	
   1.219 +void CTestCamImgProc::SetTransformationValue(TUid aTransformation, TInt aValue)
   1.220 +	{
   1.221 +	TInt eventError = iOwner.CheckReserveAndPower();
   1.222 +	
   1.223 +	if(eventError == KErrNone)
   1.224 +		{
   1.225 +		switch(aTransformation.iUid)
   1.226 +			{
   1.227 +			case KUidECamEventImageProcessingAdjustBrightnessUidValue:
   1.228 +				{
   1.229 +				if(aValue < KMinBrightness)
   1.230 +					{
   1.231 +					iOwner.iImgProcBrightness = KMinBrightness;
   1.232 +					}
   1.233 +				else
   1.234 +					{
   1.235 +					if(aValue > KMaxBrightness)	
   1.236 +						{
   1.237 +						iOwner.iImgProcBrightness = KMaxBrightness;
   1.238 +						}
   1.239 +					else
   1.240 +						{
   1.241 +						iOwner.iImgProcBrightness = aValue;	
   1.242 +						}
   1.243 +					}
   1.244 +				break;
   1.245 +				}
   1.246 +				
   1.247 +			case KUidECamEventImageProcessingAdjustContrastUidValue:
   1.248 +				{
   1.249 +				if(aValue < KMinContrast)
   1.250 +					{
   1.251 +					iOwner.iImgProcContrast = KMinContrast;
   1.252 +					}
   1.253 +				else
   1.254 +					{
   1.255 +					if(aValue > KMaxContrast)	
   1.256 +						{
   1.257 +						iOwner.iImgProcContrast = KMaxContrast;
   1.258 +						}
   1.259 +					else
   1.260 +						{
   1.261 +						iOwner.iImgProcContrast = aValue;	
   1.262 +						}
   1.263 +					}
   1.264 +				break;
   1.265 +				}
   1.266 +				
   1.267 +			default:
   1.268 +				eventError = KErrNotSupported;
   1.269 +			}	
   1.270 +		}
   1.271 +	
   1.272 +	if(eventError == KErrNone)	
   1.273 +		{
   1.274 +		eventError = iActiveTransformations.Find(aTransformation);
   1.275 +		
   1.276 +		if(eventError == KErrNotFound)
   1.277 +			{
   1.278 +			eventError = iActiveTransformations.Append(aTransformation);
   1.279 +			
   1.280 +			if(eventError == KErrNone)
   1.281 +				{
   1.282 +				if(IsTransform(aTransformation))
   1.283 +					{
   1.284 +					eventError = iActiveTransformSequence.Append(aTransformation);
   1.285 +					}
   1.286 +				}
   1.287 +			}
   1.288 +		else
   1.289 +			{
   1.290 +			eventError = KErrNone;	
   1.291 +			}	
   1.292 +		}
   1.293 +		
   1.294 +	TECAMEvent ecamevent(aTransformation, eventError);
   1.295 +	
   1.296 +	iOwner.iECamEvent = ecamevent;
   1.297 +	iOwner.iHandleEventAsync.CallBack();
   1.298 +	}
   1.299 +	
   1.300 +void CTestCamImgProc::GetActiveTransformSequenceL(RArray<TUid>& aTransformSequence) const
   1.301 +	{
   1.302 +	aTransformSequence.Reset();
   1.303 +	for(TInt index=0; index < iActiveTransformSequence.Count(); index++)
   1.304 +		{
   1.305 +		aTransformSequence.AppendL(iActiveTransformSequence[index]);
   1.306 +		}	
   1.307 +	}
   1.308 +	
   1.309 +void CTestCamImgProc::SetActiveTransformSequenceL(RArray<TUid>& aTransformSequence)
   1.310 +	{
   1.311 +	TInt err = KErrNone;
   1.312 +	for(TInt index=0; index < aTransformSequence.Count(); index++)
   1.313 +		{
   1.314 +		err = iActiveTransformations.Find(aTransformSequence[index]);
   1.315 +		if(err == KErrNotFound)
   1.316 +			{
   1.317 +			User::Leave(err);
   1.318 +			}
   1.319 +		}
   1.320 +		
   1.321 +	iActiveTransformSequence.Reset();
   1.322 +	for(TInt index=0; index < aTransformSequence.Count(); index++)
   1.323 +		{
   1.324 +		iActiveTransformSequence.AppendL(aTransformSequence[index]);
   1.325 +		}
   1.326 +	}
   1.327 +	
   1.328 +void CTestCamImgProc::SetSourceRect(const TRect& /*aRect*/)
   1.329 +	{
   1.330 +	return;
   1.331 +	}
   1.332 +
   1.333 +void CTestCamImgProc::GetSourceRect(TRect& /*aRect*/) const
   1.334 +	{
   1.335 +	return;	
   1.336 +	}
   1.337 +	
   1.338 +void CTestCamImgProc::GetConcurrentColorSwappingsSupportedL(TInt& /*aConcurrentColorSwappingSupported*/) const
   1.339 +	{
   1.340 +	User::Leave(KErrNotSupported);
   1.341 +	}
   1.342 +	
   1.343 +void CTestCamImgProc::GetColorSwapCapabilitiesL(TInt /*aIndex*/, CCamera::CCameraImageProcessing::TColorOperationCapabilities& /*aColorSwapCapabilities*/) const
   1.344 +	{
   1.345 +	User::Leave(KErrNotSupported);	
   1.346 +	}
   1.347 +	
   1.348 +void CTestCamImgProc::SetColorSwapEntry(TInt aIndex, const CCamera::CCameraImageProcessing::TColorOperationEntry& /*aColorSwapParameters*/)
   1.349 +	{
   1.350 +	TECAMEvent2 ecamevent2(KUidECamEventCIPSetColorSwapEntry, KErrNotSupported, aIndex);
   1.351 +	
   1.352 +	iOwner.iECamEvent2 = ecamevent2;
   1.353 +	iOwner.iHandleEvent2Async.CallBack();
   1.354 +	}
   1.355 +	
   1.356 +void CTestCamImgProc::RemoveColorSwapEntry(TInt aIndex)
   1.357 +	{
   1.358 +	TECAMEvent2 ecamevent2(KUidECamEventCIPRemoveColorSwapEntry, KErrNotSupported, aIndex);
   1.359 +	
   1.360 +	iOwner.iECamEvent2 = ecamevent2;
   1.361 +	iOwner.iHandleEvent2Async.CallBack();
   1.362 +	}
   1.363 +	
   1.364 +void CTestCamImgProc::GetColorSwapEntryL(TInt /*aIndex*/, CCamera::CCameraImageProcessing::TColorOperationEntry& /*aColorSwapParameters*/) const
   1.365 +	{
   1.366 +	User::Leave(KErrNotSupported);	
   1.367 +	}
   1.368 +	
   1.369 +void CTestCamImgProc::StartColorSwapping()
   1.370 +	{
   1.371 +	TECAMEvent ecamevent(KUidECamEventCIPStartColorSwap, KErrNotSupported);
   1.372 +	
   1.373 +	iOwner.iECamEvent = ecamevent;
   1.374 +	iOwner.iHandleEventAsync.CallBack();
   1.375 +	}
   1.376 +	
   1.377 +void CTestCamImgProc::CancelColorSwappingL()
   1.378 +	{
   1.379 +	User::Leave(KErrNotSupported);
   1.380 +	}
   1.381 +	
   1.382 +void CTestCamImgProc::GetConcurrentColorAccentSupportedL(TInt& /*aConcurrentColorAccentSupported*/) const
   1.383 +	{
   1.384 +	User::Leave(KErrNotSupported);	
   1.385 +	}
   1.386 +	
   1.387 +void CTestCamImgProc::GetColorAccentCapabilitiesL(TInt /*aIndex*/, CCamera::CCameraImageProcessing::TColorOperationCapabilities& /*aColorAccentCapabilities*/) const
   1.388 +	{
   1.389 +	User::Leave(KErrNotSupported);	
   1.390 +	}
   1.391 +	
   1.392 +void CTestCamImgProc::SetColorAccentEntry(TInt aIndex, const CCamera::CCameraImageProcessing::TColorOperationEntry& /*aColorAccentParameters*/)
   1.393 +	{
   1.394 +	TECAMEvent2 ecamevent2(KUidECamEventCIPSetColorAccentEntry, KErrNotSupported, aIndex);
   1.395 +	
   1.396 +	iOwner.iECamEvent2 = ecamevent2;
   1.397 +	iOwner.iHandleEvent2Async.CallBack();
   1.398 +	}
   1.399 +	
   1.400 +void CTestCamImgProc::RemoveColorAccentEntry(TInt aIndex)
   1.401 +	{
   1.402 +	TECAMEvent2 ecamevent2(KUidECamEventCIPRemoveColorAccentEntry, KErrNotSupported, aIndex);
   1.403 +	
   1.404 +	iOwner.iECamEvent2 = ecamevent2;
   1.405 +	iOwner.iHandleEvent2Async.CallBack();
   1.406 +	}
   1.407 +	
   1.408 +void CTestCamImgProc::GetColorAccentEntryL(TInt /*aIndex*/, CCamera::CCameraImageProcessing::TColorOperationEntry& /*aColorAccentParameters*/) const
   1.409 +	{
   1.410 +	User::Leave(KErrNotSupported);	
   1.411 +	}
   1.412 +	
   1.413 +void CTestCamImgProc::StartColorAccent()
   1.414 +	{
   1.415 +	TECAMEvent ecamevent(KUidECamEventCIPStartColorAccent, KErrNotSupported);
   1.416 +	
   1.417 +	iOwner.iECamEvent = ecamevent;
   1.418 +	iOwner.iHandleEventAsync.CallBack();
   1.419 +	}
   1.420 +	
   1.421 +void CTestCamImgProc::CancelColorAccentL()
   1.422 +	{
   1.423 +	User::Leave(KErrNotSupported);
   1.424 +	}
   1.425 +
   1.426 +TBool CTestCamImgProc::IsTransform(TUid aTransformation)
   1.427 +	{
   1.428 +	switch(aTransformation.iUid)
   1.429 +		{
   1.430 +		//fall through
   1.431 +		case KUidECamEventImageProcessingTransformCropUidValue:
   1.432 +		case KUidECamEventImageProcessingTransformRotateUidValue:
   1.433 +		case KUidECamEventImageProcessingTransformMirrorUidValue:
   1.434 +		case KUidECamEventImageProcessingTransformScaleUidValue:
   1.435 +		case KUidECamEventImageProcessingSourceRectUidValue:
   1.436 +		case KUidECamEventImageProcessingNoiseReductionUidValue:
   1.437 +		case KUidECamEventImageProcessingGlareRemovalUidValue:
   1.438 +			{
   1.439 +			return ETrue;	
   1.440 +			}
   1.441 +		default:
   1.442 +			return EFalse;
   1.443 +		}
   1.444 +	}