imaging/imagingfws/ImageProcessor/src/imageprocessorimpl.cpp
changeset 0 5752a19fdefe
equal deleted inserted replaced
-1:000000000000 0:5752a19fdefe
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <e32std.h>
       
    17 #include <ecom/ecom.h>
       
    18 #include <ecom/implementationinformation.h>
       
    19 #include <caf/caf.h>
       
    20 #include <caf/content.h>
       
    21 #include <caf/data.h>
       
    22 #include <mm/mmcleanup.h>
       
    23 #include <mm/mmpluginutils.h>
       
    24 #include <imageframe.h>
       
    25 #include <imageprocessor/imageprocessor_uids.hrh>
       
    26 #include "imageprocessorimpl.h"
       
    27 #include <imageprocessor/imageprocessorobserver.h>
       
    28 #include <imageprocessor/imageprocessorplugin.h>
       
    29 #include <imageprocessor/imageprocessoreffect.h>
       
    30 #include "imageprocessorcallback.h"
       
    31 #include <imageprocessor/imageprocessorpreview.h>
       
    32 #include <imageprocessor/imageprocessorpreviewintf.h>
       
    33 #include <imageprocessor/imageprocessoroverlay.h>
       
    34 #include <imageprocessor/imageprocessoroverlayintf.h>
       
    35 #include <imageprocessor/imageprocessorprogressinfo.h>
       
    36 #include <imageprocessor/imageprocessorprogressinfointf.h>
       
    37 #include <imageprocessor/imageprocessorinputinfo.h>
       
    38 #include <imageprocessor/imageprocessorinputinfointf.h>
       
    39 #include <imageprocessor/imageprocessoroutputinfo.h>
       
    40 #include <imageprocessor/imageprocessoroutputinfointf.h>
       
    41 #include "imageprocessormain.h"
       
    42 
       
    43 using namespace ImageProcessor;
       
    44 
       
    45 // current state = row
       
    46 // new state = column
       
    47 const TBool CImageProcessorImpl::iValidStates[CImgProcessor::EStatesCount][CImgProcessor::EStatesCount] = 
       
    48 	{
       
    49 	
       
    50 		//	EUninitialized	EInitializing	EInitialized	EEffectActive	EProcessing	PInit	PRend
       
    51 		{	
       
    52 			ETrue, 			ETrue, 			EFalse, 		EFalse, 		EFalse,		EFalse,	EFalse	//EUninitialized
       
    53 		},		
       
    54 		{	
       
    55 			ETrue, 			ETrue, 			ETrue, 			EFalse,			EFalse,		EFalse,	EFalse	//EInitializing
       
    56 		},
       
    57 		{	
       
    58 			ETrue,	 		EFalse,			ETrue, 			ETrue, 			ETrue,		ETrue,	ETrue	//EInitialized
       
    59 		},		
       
    60 		{	
       
    61 			EFalse, 		EFalse,			ETrue,			ETrue, 			ETrue,		ETrue,	ETrue	//EEffectActive
       
    62 		},
       
    63 		{	
       
    64 			EFalse, 		EFalse,			ETrue,			ETrue,			ETrue,		EFalse,	EFalse	//EProcessing
       
    65 		},
       
    66 		{	
       
    67 			EFalse, 		EFalse,			ETrue,			ETrue,			EFalse,		ETrue,	EFalse	//EPreviewInitializing
       
    68 		},
       
    69 		{	
       
    70 			EFalse, 		EFalse,			ETrue,			ETrue,			EFalse,		EFalse,	ETrue	//EPreviewRendering
       
    71 		}
       
    72 	};
       
    73 
       
    74 CImageProcessorImpl* CImageProcessorImpl::NewL(RFs& aFileServerSession, CImgProcessor& aImageProcessor, MImgProcessorObserver& aObserver, TUid aPluginUid)
       
    75 	{
       
    76 	CImageProcessorImpl* self = new (ELeave) CImageProcessorImpl(aFileServerSession, aImageProcessor, aPluginUid);
       
    77 	CleanupStack::PushL(self);
       
    78 	self->ConstructL(aObserver);
       
    79 	CleanupStack::Pop(self);
       
    80 	return self;
       
    81 	}
       
    82 
       
    83 CImageProcessorImpl::CImageProcessorImpl(RFs& aFileServerSession, CImgProcessor& aImageProcessor, TUid aPluginUid):
       
    84 	iFileServerSession(aFileServerSession),
       
    85 	iImageProcessor(aImageProcessor),
       
    86 	iPluginUid(aPluginUid)
       
    87 	{
       
    88 	}
       
    89    
       
    90 void CImageProcessorImpl::ConstructL(MImgProcessorObserver& aObserver)
       
    91 	{
       
    92 	iCallbackHandler = CImageProcessorCallback::NewL(iImageProcessor,aObserver);
       
    93 	}
       
    94 
       
    95 void CImageProcessorImpl::Cleanup()
       
    96 	{
       
    97 	Cancel();
       
    98 	
       
    99 	TInt err = KErrNone;
       
   100 	
       
   101 	if (iOverlay) 
       
   102 		{
       
   103 		TRAP(err, iOverlay->ResetL());
       
   104 		}
       
   105 	
       
   106 	for (TInt i=0; i < iEffects.Count(); i++ )
       
   107 		{ 
       
   108 		TRAP(err, iEffects[i]->ResetL());
       
   109 		}
       
   110 	
       
   111 	for (TInt i=0; i < iPreviews.Count(); i++ )
       
   112 		{ 
       
   113 		TRAP(err, iPreviews[i]->ResetL());
       
   114 		TRAP(err, iPreviews[i]->UninitializeL());
       
   115 		}
       
   116 	
       
   117 	if (iPlugin)
       
   118 		{
       
   119 		TRAP(err, iPlugin->ResetL());
       
   120 		}
       
   121 
       
   122 	delete iCallbackHandler;
       
   123 	iCallbackHandler = NULL;
       
   124 	
       
   125 	delete iOverlay;
       
   126 	iOverlay = NULL;
       
   127 
       
   128 	delete iProgressInfo;
       
   129 	iProgressInfo = NULL;
       
   130 	
       
   131 	delete iInputInfo;
       
   132 	iInputInfo = NULL;
       
   133 
       
   134 	delete iOutputInfo;
       
   135 	iOutputInfo = NULL;
       
   136 
       
   137 	delete iDrmInput;
       
   138 	iDrmInput = NULL;
       
   139 	
       
   140 	delete iOverlayDrmInput;
       
   141 	iOverlayDrmInput = NULL;
       
   142 	
       
   143 	
       
   144 	iEffects.ResetAndDestroy();
       
   145 	iPreviews.ResetAndDestroy();
       
   146 	iOverlayDrmInputs.ResetAndDestroy();
       
   147 	iFrameworkEffects.Close();
       
   148 	iPluginEffects.Close();
       
   149 	iInputFormats.Close();
       
   150 	iInputImageFrameFormats.Close();
       
   151 	iInputDisplayModes.Close();
       
   152 	iOutputFormats.Close();
       
   153 	iOutputImageFrameFormats.Close();
       
   154 	iOutputDisplayModes.Close();
       
   155 	iPreviewOutputImageFrameFormats.Close();
       
   156 	iPreviewOutputDisplayModes.Close();
       
   157 	iOverlayInputFormats.Close();
       
   158 	iOverlayInputImageFrameFormats.Close();
       
   159 	iOverlayInputDisplayModes.Close();
       
   160 	iTypesUtilityArray.ResetAndDestroy();
       
   161 	
       
   162 	if(iPlugin)
       
   163 		{
       
   164 		iPlugin->Destroy();
       
   165 		iPlugin = NULL;
       
   166 		REComSession::DestroyedImplementation(iPluginDtorKey);      
       
   167 		}
       
   168 
       
   169 	iState = CImgProcessor::EUninitialized;
       
   170 	iPreviousState = CImgProcessor::EUninitialized;
       
   171 	
       
   172 	iSupportedOptions = CImgProcessor::EOptionNone;
       
   173 	iOptions = CImgProcessor::EOptionNone;
       
   174 	iSupportedOperations = CImgProcessor::EOperationNone;
       
   175 	
       
   176 	iIsInputSet = EFalse;
       
   177 	iIsOutputSet = EFalse;
       
   178 	}
       
   179 
       
   180 CImageProcessorImpl::~CImageProcessorImpl()
       
   181 	{
       
   182 	Cleanup();
       
   183 	}
       
   184 
       
   185 void CImageProcessorImpl::SupportedEffectsL(RArray<TUid>& aEffects) const
       
   186 	{
       
   187 	aEffects = iPluginEffects;
       
   188 	}
       
   189 
       
   190 void CImageProcessorImpl::SupportedInputFormatsL(RArray<TUid>& aFormats) const
       
   191 	{
       
   192 	aFormats = iInputFormats;
       
   193 	}
       
   194 
       
   195 void CImageProcessorImpl::SupportedInputSubFormatsL(TUid aFormats, RArray<TUid>& aSubFormats) const
       
   196 	{
       
   197 	iPlugin->SupportedInputSubFormatsL(aFormats, aSubFormats);
       
   198 	}
       
   199 
       
   200 void CImageProcessorImpl::SupportedInputImageFrameFormatsL(RArray<TUid>& aFormats) const
       
   201 	{
       
   202 	aFormats = iInputImageFrameFormats;
       
   203 	}
       
   204 
       
   205 void CImageProcessorImpl::SupportedInputDisplayModesL(RArray<TDisplayMode>& aDisplayModes) const
       
   206 	{
       
   207 	aDisplayModes = iInputDisplayModes;
       
   208 	}
       
   209 
       
   210 void CImageProcessorImpl::SupportedOutputFormatsL(RArray<TUid>& aFormats) const
       
   211 	{
       
   212 	aFormats = iOutputFormats;
       
   213 	}
       
   214 
       
   215 void CImageProcessorImpl::SupportedOutputSubFormatsL(TUid aFormat, RArray<TUid>& aSubFormats) const
       
   216 	{
       
   217 	iPlugin->SupportedOutputSubFormatsL(aFormat, aSubFormats);
       
   218 	}
       
   219 
       
   220 void CImageProcessorImpl::SupportedOutputImageFrameFormatsL(RArray<TUid>& aFormats) const
       
   221 	{
       
   222 	aFormats = iOutputImageFrameFormats;
       
   223 	}
       
   224 
       
   225 void CImageProcessorImpl::SupportedOutputDisplayModesL(RArray<TDisplayMode>& aDisplayModes) const
       
   226 	{
       
   227 	aDisplayModes = iOutputDisplayModes;
       
   228 	}
       
   229 
       
   230 TUint64 CImageProcessorImpl::SupportedOptions() const
       
   231 	{
       
   232 	return iSupportedOptions;
       
   233 	}
       
   234 
       
   235 TUint CImageProcessorImpl::SupportedOperations() const
       
   236 	{	
       
   237 	return iSupportedOperations;
       
   238 	}
       
   239    
       
   240 void CImageProcessorImpl::SetOptionsL(TUint64 aOptions)
       
   241 	{
       
   242 	if ((aOptions | iSupportedOptions) != iSupportedOptions) 
       
   243 		{
       
   244 		User::Leave(KErrNotSupported);
       
   245 		}
       
   246 	CheckStateL(CImgProcessor::EInitialized);
       
   247 	iPlugin->SetOptionsL(aOptions);
       
   248 	iOptions = aOptions;
       
   249 	}
       
   250 
       
   251 void CImageProcessorImpl::ApplyOperationL(CImgProcessor::TOperation aOperation)
       
   252 	{
       
   253 	if ((aOperation | iSupportedOperations) != iSupportedOperations) 
       
   254 		{
       
   255 		User::Leave(KErrNotSupported);
       
   256 		}
       
   257 	__ASSERT_ALWAYS(((iState == CImgProcessor::EInitialized) && (iIsInputSet)), User::Leave(KErrNotReady));
       
   258 	iPlugin->ApplyOperationL(aOperation);
       
   259 	}
       
   260 
       
   261 void CImageProcessorImpl::CheckStateL(CImgProcessor::TState aState) const
       
   262 	{
       
   263 	if (iState != aState) 
       
   264 		{
       
   265 		User::Leave(KErrNotReady);
       
   266 		}
       
   267 	}
       
   268 
       
   269 CImgProcessor::TState CImageProcessorImpl::State() const
       
   270 	{
       
   271 	return iState;
       
   272 	}
       
   273    
       
   274 void CImageProcessorImpl::SetInputL(const TDesC& aFilename, const TUid& aFormat, const TUid& aSubFormat)
       
   275 	{
       
   276 	__ASSERT_ALWAYS((iState == CImgProcessor::EInitialized), User::Leave(KErrNotReady));
       
   277 	CheckInputFormatL(aFormat, aSubFormat);
       
   278 	iPlugin->SetInputL(aFilename, aFormat, aSubFormat);
       
   279 
       
   280 	delete iDrmInput;
       
   281 	iDrmInput = NULL;
       
   282 	
       
   283 	iIsInputSet = ETrue;
       
   284 	}
       
   285    
       
   286 void CImageProcessorImpl::SetInputL(RFile& aFile, const TUid& aFormat, const TUid& aSubFormat)
       
   287 	{
       
   288 	__ASSERT_ALWAYS((iState == CImgProcessor::EInitialized), User::Leave(KErrNotReady));
       
   289 	CheckInputFormatL(aFormat, aSubFormat);
       
   290 	iPlugin->SetInputL(aFile, aFormat, aSubFormat);
       
   291 
       
   292 	delete iDrmInput;
       
   293 	iDrmInput = NULL;
       
   294 
       
   295 	iIsInputSet = ETrue;
       
   296 	}
       
   297 
       
   298 void CImageProcessorImpl::SetInputL(TMMSource& aDrmFile, const TUid& aFormat, const TUid& aSubFormat)
       
   299 	{
       
   300 	__ASSERT_ALWAYS((iState == CImgProcessor::EInitialized), User::Leave(KErrNotReady));
       
   301 	CheckInputFormatL(aFormat, aSubFormat);
       
   302 	
       
   303 	CImageProcessorDrmInput* drmInput = CImageProcessorDrmInput::NewL(aDrmFile);
       
   304 	
       
   305 	CleanupStack::PushL(drmInput);
       
   306 	SetInputL(*(drmInput->Buffer()), aFormat, aSubFormat);
       
   307 	CleanupStack::Pop();
       
   308 
       
   309 	iDrmInput = drmInput;
       
   310 	}
       
   311    
       
   312 void CImageProcessorImpl::SetInputL(const TDesC8& aBuffer, const TUid& aFormat, const TUid& aSubFormat)
       
   313 	{
       
   314 	__ASSERT_ALWAYS((iState == CImgProcessor::EInitialized), User::Leave(KErrNotReady));
       
   315 	CheckInputFormatL(aFormat, aSubFormat);
       
   316 	
       
   317 	if (aBuffer.Size() == 0) 
       
   318 		{
       
   319 		User::Leave(KErrArgument);
       
   320 		}
       
   321 
       
   322 	iPlugin->SetInputL(aBuffer, aFormat, aSubFormat);
       
   323 
       
   324 	delete iDrmInput;
       
   325 	iDrmInput = NULL;
       
   326 
       
   327 	iIsInputSet = ETrue;
       
   328 	}
       
   329    
       
   330 void CImageProcessorImpl::SetInputL(const CFbsBitmap& aBitmap, const CFbsBitmap* aMask)
       
   331 	{
       
   332 	__ASSERT_ALWAYS((iState == CImgProcessor::EInitialized), User::Leave(KErrNotReady));
       
   333 	
       
   334 	if (aBitmap.SizeInPixels() == TSize(0,0)) 
       
   335 		{
       
   336 		User::Leave(KErrArgument);
       
   337 		}
       
   338 	
       
   339 	if((aBitmap.Handle()!=0 && aBitmap.ExtendedBitmapType()!=KNullUid) || (aMask!=NULL && aMask->Handle()!=0 && aMask->ExtendedBitmapType()!=KNullUid))
       
   340         {
       
   341         User::Leave(KErrNotSupported);
       
   342         }
       
   343 	
       
   344 	if ((aMask != NULL) && (aMask->SizeInPixels() == TSize(0,0))) 
       
   345 		{
       
   346 		User::Leave(KErrArgument);
       
   347 		}
       
   348 
       
   349 	iPlugin->SetInputL(aBitmap, aMask);
       
   350 
       
   351 	delete iDrmInput;
       
   352 	iDrmInput = NULL;
       
   353 
       
   354 	iIsInputSet = ETrue;
       
   355 	}
       
   356    
       
   357 void CImageProcessorImpl::SetInputL(const CImageFrame& aPixelBuffer)
       
   358 	{
       
   359 	__ASSERT_ALWAYS((iState == CImgProcessor::EInitialized), User::Leave(KErrNotReady));
       
   360 	
       
   361 	if (aPixelBuffer.FrameSizeInPixels() == TSize(0,0)) 
       
   362 		{
       
   363 		User::Leave(KErrArgument);
       
   364 		}
       
   365 	
       
   366 	iPlugin->SetInputL(aPixelBuffer);
       
   367 
       
   368 	delete iDrmInput;
       
   369 	iDrmInput = NULL;
       
   370 
       
   371 	iIsInputSet = ETrue;
       
   372 	}
       
   373 
       
   374 void CImageProcessorImpl::SetInputL(CImagePanorama& aPanorama)
       
   375 	{
       
   376 	__ASSERT_ALWAYS((iState == CImgProcessor::EInitialized), User::Leave(KErrNotReady));
       
   377 	
       
   378 	//get the extenstion interface to panorama image as input
       
   379 	TAny* any = iPlugin->Extension(TUid::Uid(KImageProcessorExtensionPanoramaInputUidValue));
       
   380 	MImgProcessorPluginPanoramaInput* extension = static_cast<MImgProcessorPluginPanoramaInput*>(any);
       
   381 	if(extension == NULL)
       
   382 		{
       
   383 		User::Leave(KErrNotSupported);
       
   384 		}
       
   385 	extension->SetInputL(aPanorama);
       
   386 	
       
   387 	delete iDrmInput;
       
   388 	iDrmInput = NULL;
       
   389 
       
   390 	iIsInputSet = ETrue;
       
   391 	}
       
   392 
       
   393 void CImageProcessorImpl::SetInputRectL(const TRect& aRect)
       
   394 	{
       
   395 	__ASSERT_ALWAYS(((iState == CImgProcessor::EInitialized) && (iIsInputSet)), User::Leave(KErrNotReady));
       
   396 	
       
   397 	if (aRect == TRect(0,0,0,0) || aRect.Size() == TSize(0,0)) 
       
   398 		{
       
   399 		User::Leave(KErrArgument);
       
   400 		}
       
   401 	
       
   402 	TSize size = iPlugin->CurrentSizeL();
       
   403 
       
   404 	if (!TRect(size).Intersects(aRect)) 
       
   405 		{
       
   406 		User::Leave(KErrArgument);
       
   407 		}
       
   408 
       
   409 	iPlugin->SetInputRectL(aRect);
       
   410 	}
       
   411 
       
   412 TSize CImageProcessorImpl::CurrentSizeL() const
       
   413 	{
       
   414 	__ASSERT_ALWAYS(iIsInputSet, User::Leave(KErrNotReady));
       
   415 	return iPlugin->CurrentSizeL();
       
   416 	}
       
   417 
       
   418 TInt CImageProcessorImpl::CalculatePixelBufferSizeL(TSize aSizeInPixels, TDisplayMode aDisplayMode, TUint32 aScanLineLength) const
       
   419 	{
       
   420 	__ASSERT_ALWAYS((iState != CImgProcessor::EUninitialized), User::Leave(KErrNotReady));
       
   421 	return iPlugin->CalculatePixelBufferSizeL(aSizeInPixels, aDisplayMode, aScanLineLength);
       
   422 	}
       
   423 
       
   424 TInt CImageProcessorImpl::CalculatePixelBufferSizeL(TSize aSizeInPixels, const TUid& aFormat, TUint32 aScanLineLength) const
       
   425 	{
       
   426 	__ASSERT_ALWAYS((iState != CImgProcessor::EUninitialized), User::Leave(KErrNotReady));
       
   427 	return iPlugin->CalculatePixelBufferSizeL(aSizeInPixels, aFormat, aScanLineLength);
       
   428 	}
       
   429 
       
   430 void CImageProcessorImpl::CreateInputL(CFbsBitmap& aBitmap)
       
   431 	{
       
   432 	__ASSERT_ALWAYS((iState == CImgProcessor::EInitialized), User::Leave(KErrNotReady));
       
   433 	
       
   434 	if (aBitmap.SizeInPixels() == TSize(0,0)) 
       
   435 		{
       
   436 		User::Leave(KErrArgument);
       
   437 		}
       
   438 	
       
   439 	if(aBitmap.Handle()!=0 && aBitmap.ExtendedBitmapType()!=KNullUid)
       
   440         {
       
   441         User::Leave(KErrNotSupported);
       
   442         }
       
   443 
       
   444 	iPlugin->CreateInputL(aBitmap);
       
   445 	
       
   446 	delete iDrmInput;
       
   447 	iDrmInput = NULL;
       
   448 	
       
   449 	iIsInputSet = ETrue;
       
   450 	}
       
   451 
       
   452 void CImageProcessorImpl::CreateInputL(CImageFrame& aPixelBuffer)
       
   453 	{
       
   454 	__ASSERT_ALWAYS((iState == CImgProcessor::EInitialized), User::Leave(KErrNotReady));
       
   455 
       
   456 	if (aPixelBuffer.FrameSizeInPixels() == TSize(0,0)) 
       
   457 		{
       
   458 		User::Leave(KErrArgument);
       
   459 		}
       
   460 	
       
   461 	iPlugin->CreateInputL(aPixelBuffer);
       
   462 	
       
   463 	delete iDrmInput;
       
   464 	iDrmInput = NULL;
       
   465 	
       
   466 	iIsInputSet = ETrue;
       
   467 	}
       
   468 
       
   469 void CImageProcessorImpl::CreateInputL(const TSize& aSize, const TRgb& aColor)
       
   470 	{
       
   471 	__ASSERT_ALWAYS((iState == CImgProcessor::EInitialized), User::Leave(KErrNotReady));
       
   472 	
       
   473 	if (aSize == TSize(0,0)) 
       
   474 		{
       
   475 		User::Leave(KErrArgument);
       
   476 		}
       
   477 	
       
   478 	iPlugin->CreateInputL(aSize, aColor);
       
   479 	
       
   480 	delete iDrmInput;
       
   481 	iDrmInput = NULL;
       
   482 	
       
   483 	iIsInputSet = ETrue;
       
   484 	}
       
   485 
       
   486 void CImageProcessorImpl::InputUpdatedL()
       
   487 	{
       
   488 	__ASSERT_ALWAYS(((iState == CImgProcessor::EInitialized) && (iIsInputSet)), User::Leave(KErrNotReady));
       
   489 	iPlugin->InputUpdatedL();
       
   490 	}
       
   491 
       
   492 void CImageProcessorImpl::ResetL() 
       
   493 	{
       
   494 	__ASSERT_ALWAYS(((iState != CImgProcessor::EUninitialized) && (iState != CImgProcessor::EInitializing)), User::Leave(KErrNotReady));
       
   495 
       
   496 	Cancel();
       
   497 	
       
   498 	if (iOverlay) 
       
   499 		{
       
   500 		iOverlay->ResetL();
       
   501 		}
       
   502 	
       
   503 	delete iOverlayDrmInput;
       
   504 	iOverlayDrmInput = NULL;
       
   505 	
       
   506 	for (TInt i=0; i < iEffects.Count(); i++ )
       
   507 		{ 
       
   508 		iEffects[i]->ResetL();
       
   509 		}
       
   510 	
       
   511 	for (TInt i=0; i < iPreviews.Count(); i++ )
       
   512 		{ 
       
   513 		iPreviews[i]->ResetL();
       
   514 		}
       
   515 	
       
   516 	iPlugin->ResetL();
       
   517 	
       
   518 	delete iDrmInput;
       
   519 	iDrmInput = NULL;
       
   520 
       
   521 	delete iProgressInfo;
       
   522 	iProgressInfo = NULL;
       
   523 	
       
   524 	delete iInputInfo;
       
   525 	iInputInfo = NULL;
       
   526 	
       
   527 	delete iOutputInfo;
       
   528 	iOutputInfo = NULL;
       
   529 	
       
   530 	iPreviews.ResetAndDestroy();
       
   531 	iOverlayDrmInputs.ResetAndDestroy();
       
   532 
       
   533 	iIsInputSet = EFalse;
       
   534 	iIsOutputSet = EFalse;
       
   535 	
       
   536 	iOptions = CImgProcessor::EOptionNone;
       
   537 	}
       
   538    
       
   539 void CImageProcessorImpl::InitializeL(TUint64 aOptions)
       
   540 	{
       
   541 	__ASSERT_ALWAYS((iState == CImgProcessor::EUninitialized), User::Leave(KErrNotReady));
       
   542 	
       
   543 	// Client whishes to choose the plugin given by framework.
       
   544 	if(iPluginUid == KNullUid)
       
   545 		{
       
   546 		TUid interfaceUid = {KImageProcessorPluginInterfaceUidValue};
       
   547 		// Get the higher version of plugin
       
   548 		iPlugin = static_cast<MImgProcessorPlugin*>(MmPluginUtils::CreateImplementationL(interfaceUid, iPluginDtorKey));   
       
   549 		}
       
   550 	// If client has passed the plugin uid.	
       
   551 	else
       
   552 		{
       
   553 		iPlugin = static_cast<MImgProcessorPlugin*>(REComSession::CreateImplementationL(iPluginUid, iPluginDtorKey));   
       
   554 		}	
       
   555 		
       
   556 	iPlugin->SetFileServerSession(iFileServerSession);
       
   557 	iPlugin->SetObserver(*this);
       
   558 	iPlugin->SupportedEffectsL(iPluginEffects);
       
   559 	iPlugin->SupportedInputFormatsL(iInputFormats);
       
   560 	iPlugin->SupportedInputImageFrameFormatsL(iInputImageFrameFormats);
       
   561 	iPlugin->SupportedInputDisplayModesL(iInputDisplayModes);
       
   562 	iPlugin->SupportedOutputFormatsL(iOutputFormats);
       
   563 	iPlugin->SupportedOutputImageFrameFormatsL(iOutputImageFrameFormats);
       
   564 	iPlugin->SupportedOutputDisplayModesL(iOutputDisplayModes);
       
   565 	
       
   566 	iSupportedOptions = iPlugin->SupportedOptions();
       
   567 	if ((aOptions | iSupportedOptions) != iSupportedOptions) 
       
   568 		{
       
   569 		User::Leave(KErrNotSupported);
       
   570 		}
       
   571 	iPlugin->SetOptionsL(aOptions);
       
   572 	iOptions = aOptions;
       
   573 	
       
   574 	iSupportedOperations = iPlugin->SupportedOperations();
       
   575 
       
   576 	iPlugin->SupportedPreviewOutputImageFrameFormatsL(iPreviewOutputImageFrameFormats);
       
   577 	iPlugin->SupportedPreviewOutputDisplayModesL(iPreviewOutputDisplayModes);
       
   578 	iPlugin->SupportedOverlayInputFormatsL(iOverlayInputFormats);
       
   579 	iPlugin->SupportedOverlayInputImageFrameFormatsL(iOverlayInputImageFrameFormats);
       
   580 	iPlugin->SupportedOverlayInputDisplayModesL(iOverlayInputDisplayModes);
       
   581 
       
   582 	CImageDecoder::GetFileTypesL(iTypesUtilityArray);	
       
   583 
       
   584 	InitializeFrameworkEffectsL();
       
   585 	
       
   586 	SetStateL(CImgProcessor::EInitializing);
       
   587 
       
   588 	iPlugin->InitializeL();
       
   589 
       
   590 	if ((iOptions & CImgProcessor::EOptionSyncProcessing) != 0) 
       
   591 		{
       
   592 		SetStateL(CImgProcessor::EInitialized);
       
   593 		}
       
   594 	}
       
   595 
       
   596 void CImageProcessorImpl::InitializeFrameworkEffectsL() 
       
   597 	{
       
   598 	//PhotoArt
       
   599 	iFrameworkEffects.AppendL(ImageProcessor::KEffectSepiaUid);
       
   600 	iFrameworkEffects.AppendL(ImageProcessor::KEffectGrayscaleUid);
       
   601 	iFrameworkEffects.AppendL(ImageProcessor::KEffectNegativeUid);
       
   602 	iFrameworkEffects.AppendL(ImageProcessor::KEffectGrayscaleNegativeUid);
       
   603 	iFrameworkEffects.AppendL(ImageProcessor::KEffectOilyUid);
       
   604 	iFrameworkEffects.AppendL(ImageProcessor::KEffectPaintUid);
       
   605 	iFrameworkEffects.AppendL(ImageProcessor::KEffectMilkyUid);
       
   606 	iFrameworkEffects.AppendL(ImageProcessor::KEffectFogUid);
       
   607 	iFrameworkEffects.AppendL(ImageProcessor::KEffectMirrorLeftToRightUid);
       
   608 	iFrameworkEffects.AppendL(ImageProcessor::KEffectMagicPenUid);
       
   609 	iFrameworkEffects.AppendL(ImageProcessor::KEffectAntiqueUid);
       
   610 	
       
   611 	iFrameworkEffects.AppendL(ImageProcessor::KEffectBrightnessUid);
       
   612 	iFrameworkEffects.AppendL(ImageProcessor::KEffectSharpnessUid);
       
   613 	iFrameworkEffects.AppendL(ImageProcessor::KEffectRotationUid);
       
   614 	iFrameworkEffects.AppendL(ImageProcessor::KEffectContrastUid);
       
   615 	iFrameworkEffects.AppendL(ImageProcessor::KEffectRgbColorAdjustUid);
       
   616 	iFrameworkEffects.AppendL(ImageProcessor::KEffectEmbossUid);
       
   617 	iFrameworkEffects.AppendL(ImageProcessor::KEffectSolarizeUid);
       
   618 	iFrameworkEffects.AppendL(ImageProcessor::KEffectPosterizeUid);
       
   619 	iFrameworkEffects.AppendL(ImageProcessor::KEffectStampUid);
       
   620 	iFrameworkEffects.AppendL(ImageProcessor::KEffectSketchUid);
       
   621 	iFrameworkEffects.AppendL(ImageProcessor::KEffectNoiseUid);
       
   622 	iFrameworkEffects.AppendL(ImageProcessor::KEffectMoonlightUid);
       
   623 	iFrameworkEffects.AppendL(ImageProcessor::KEffectFrostedGlassUid);
       
   624 	iFrameworkEffects.AppendL(ImageProcessor::KEffectDespeckleUid);
       
   625 	iFrameworkEffects.AppendL(ImageProcessor::KEffectBlurUid);
       
   626 	iFrameworkEffects.AppendL(ImageProcessor::KEffectColorizationUid);
       
   627 	iFrameworkEffects.AppendL(ImageProcessor::KEffectCartoonUid);
       
   628 		
       
   629 	//ClearShot
       
   630 	iFrameworkEffects.AppendL(ImageProcessor::KEffectLocalBoostUid);
       
   631 	iFrameworkEffects.AppendL(ImageProcessor::KEffectColorBoostUid);
       
   632 	iFrameworkEffects.AppendL(ImageProcessor::KEffectWhiteBalanceUid);
       
   633 	iFrameworkEffects.AppendL(ImageProcessor::KEffectAutoLevelsUid);
       
   634 	iFrameworkEffects.AppendL(ImageProcessor::KEffectLevelsUid);
       
   635 	iFrameworkEffects.AppendL(ImageProcessor::KEffectExposureUid);
       
   636 
       
   637 	iFrameworkEffects.AppendL(ImageProcessor::KEffectSpotLightUid);
       
   638 	iFrameworkEffects.AppendL(ImageProcessor::KEffectCustomTransformationUid);
       
   639 	
       
   640 	//Others
       
   641 	iFrameworkEffects.AppendL(ImageProcessor::KGeometricalOperationUid);
       
   642 	iFrameworkEffects.AppendL(ImageProcessor::KEffectBorderUid);
       
   643 	}
       
   644       
       
   645 void CImageProcessorImpl::ProcessL(const TSize& aSize, TBool aMaintainAspectRatio)
       
   646 	{
       
   647 	__ASSERT_ALWAYS(((iState == CImgProcessor::EInitialized) && (iIsInputSet) && (iIsOutputSet)), User::Leave(KErrNotReady));
       
   648 	SetStateL(CImgProcessor::EProcessing);
       
   649 
       
   650 	TRAPD(err, iPlugin->ProcessL(aSize, aMaintainAspectRatio));
       
   651 
       
   652 	if (err != KErrNone) 
       
   653 		{
       
   654 		RestoreStateL();
       
   655 		User::Leave(err);
       
   656 		}
       
   657 
       
   658 	if ((iOptions & CImgProcessor::EOptionSyncProcessing) != 0) 
       
   659 		{
       
   660 		if (iDrmInput) 
       
   661 			{
       
   662 			TRAPD(drmErr, iDrmInput->ExecuteIntentL());
       
   663 			if (drmErr != KErrNone) 
       
   664 				{
       
   665 				iPlugin->CleanupOutput(); //should delete/cleanup unauthorised output
       
   666 				User::Leave(drmErr);
       
   667 				}
       
   668 			}
       
   669 		
       
   670 		for (TInt i=0; i < iOverlayDrmInputs.Count(); i++ )
       
   671 			{ 
       
   672 			TRAPD(overlayDrmErr, iOverlayDrmInputs[i]->ExecuteIntentL());
       
   673 			if (overlayDrmErr != KErrNone) 
       
   674 				{
       
   675 				iPlugin->CleanupOutput(); //should delete/cleanup unauthorised output
       
   676 				User::Leave(overlayDrmErr);
       
   677 				}
       
   678 			}
       
   679 		RestoreStateL();
       
   680 		}
       
   681 
       
   682 	}
       
   683    
       
   684 void CImageProcessorImpl::Cancel()
       
   685 	{
       
   686 	if(iState == CImgProcessor::EInitializing || iState == CImgProcessor::EProcessing)
       
   687 		{
       
   688 		iState = iPreviousState;
       
   689 		iPlugin->Cancel();
       
   690 		}
       
   691 	else if (iState == CImgProcessor::EPreviewInitializing || iState == CImgProcessor::EPreviewRendering) 
       
   692 		{
       
   693 		for (TInt i=0; i < iPreviews.Count(); i++ )
       
   694 			{ 
       
   695 			iPreviews[i]->Cancel();
       
   696 			}
       
   697 		// RestoreStateL should be called in preview cancel but double check here
       
   698 		if (iState == CImgProcessor::EPreviewInitializing || iState == CImgProcessor::EPreviewRendering) 
       
   699 			{
       
   700 			iState = iPreviousState;
       
   701 			}
       
   702 		iPlugin->Cancel();
       
   703 		}
       
   704 	}
       
   705    
       
   706 void CImageProcessorImpl::SetBackgroundColorL(const TRgb& aColor)
       
   707 	{
       
   708 	__ASSERT_ALWAYS(((iState == CImgProcessor::EInitialized) && (iIsInputSet)), User::Leave(KErrNotReady));
       
   709 	iPlugin->SetBackgroundColorL(aColor);
       
   710 	}
       
   711    
       
   712 TRgb CImageProcessorImpl::BackgroundColorL() const
       
   713 	{
       
   714 	__ASSERT_ALWAYS(iIsInputSet, User::Leave(KErrNotReady));
       
   715 	return iPlugin->BackgroundColorL();
       
   716 	}
       
   717 
       
   718 void CImageProcessorImpl::CheckInputFormatL(const TUid& aFormat, const TUid& aSubFormat) 
       
   719 	{
       
   720 	if (aFormat == KNullUid && aSubFormat == aSubFormat) 
       
   721 		{
       
   722 		return;	
       
   723 		}
       
   724 	
       
   725 	User::LeaveIfError(iInputFormats.Find(aFormat));
       
   726 	if (aSubFormat != KNullUid) 
       
   727 		{
       
   728 		RArray<TUid> subFormats;
       
   729 		iPlugin->SupportedInputSubFormatsL(aFormat, subFormats);
       
   730 		TInt err = subFormats.Find(aSubFormat);
       
   731 		subFormats.Close();
       
   732 		User::LeaveIfError(err);
       
   733 		}
       
   734 	}
       
   735 
       
   736 void CImageProcessorImpl::CheckOutputFormatL(const TUid& aFormat, const TUid& aSubFormat)
       
   737 	{
       
   738 	User::LeaveIfError(iOutputFormats.Find(aFormat));
       
   739 	if (aSubFormat != KNullUid) 
       
   740 		{
       
   741 		RArray<TUid> subFormats;
       
   742 		iPlugin->SupportedOutputSubFormatsL(aFormat, subFormats);
       
   743 		TInt err = subFormats.Find(aSubFormat);
       
   744 		subFormats.Close();
       
   745 		User::LeaveIfError(err);
       
   746 		}
       
   747 	}
       
   748 
       
   749 TBool CImageProcessorImpl::IsFrameworkEffect(TUid aEffect) const
       
   750 	{
       
   751 	return (iFrameworkEffects.Find(aEffect) != KErrNotFound);
       
   752 	}
       
   753 
       
   754 TBool CImageProcessorImpl::IsPluginEffect(TUid aEffect) const
       
   755 	{
       
   756 	return (iPluginEffects.Find(aEffect) != KErrNotFound);
       
   757 	}
       
   758 
       
   759 TBool FindEffectRelation(const TUid* aKey, const TEffect& aEffect)
       
   760 	{
       
   761 	return (*aKey==aEffect.Type());
       
   762 	}
       
   763 
       
   764 TEffect* CImageProcessorImpl::FindEffect(TUid aEffect) const
       
   765 	{
       
   766 	const TInt idx = iEffects.Find<TUid>(aEffect, FindEffectRelation);
       
   767 	
       
   768 	TEffect* effect=NULL;
       
   769 	if(idx != KErrNotFound)
       
   770 		{
       
   771 		//Effect found
       
   772 		effect = iEffects[idx];
       
   773 		}
       
   774 	return effect;
       
   775 	}
       
   776 
       
   777 TEffect* CImageProcessorImpl::CreateEffectL(TUid aEffect)
       
   778 	{	
       
   779 	//Ownership stays with plugin
       
   780 	Plugin::MEffect* pluginEffect = iPlugin->EffectL(aEffect);
       
   781 	ASSERT(pluginEffect);
       
   782 	
       
   783 	TEffect* effect = EffectFactoryL(aEffect, pluginEffect);
       
   784 	
       
   785 	if (!effect || (iEffects.Append(effect) != KErrNone)) 
       
   786 		{
       
   787 		delete effect;
       
   788 		TInt err = KErrNone;
       
   789 		TRAP(err, ResetL());
       
   790 		iEffects.ResetAndDestroy();
       
   791 		iPlugin->CleanupEffects();
       
   792 		User::Leave(KErrNoMemory);
       
   793 		}
       
   794 
       
   795 	ASSERT(effect);
       
   796 	return effect;
       
   797 	}
       
   798 
       
   799 TEffect* CImageProcessorImpl::EffectFactoryL(TUid aEffect, Plugin::MEffect* aPluginEffect)
       
   800 	{
       
   801 	if(aEffect == KEffectSepiaUid)
       
   802 		{
       
   803 		return new TEffectSepia(*aPluginEffect, *this);
       
   804 		}
       
   805 	else if(aEffect == KEffectGrayscaleUid)
       
   806 		{
       
   807 		return new TEffectGrayscale(*aPluginEffect, *this);
       
   808 		}
       
   809 	else if(aEffect == KEffectNegativeUid)
       
   810 		{
       
   811 		return new TEffectNegative(*aPluginEffect, *this);
       
   812 		}
       
   813 	else if(aEffect == KEffectGrayscaleNegativeUid)
       
   814 		{
       
   815 		return new TEffectGrayscaleNegative(*aPluginEffect, *this);
       
   816 		}
       
   817 	else if(aEffect == KEffectOilyUid)
       
   818 		{
       
   819 		return new TEffectOily(*aPluginEffect, *this);
       
   820 		}
       
   821 	else if(aEffect == KEffectPaintUid)
       
   822 		{
       
   823 		return new TEffectPaint(*aPluginEffect, *this);
       
   824 		}
       
   825 	else if(aEffect == KEffectMilkyUid)
       
   826 		{
       
   827 		return new TEffectMilky(*aPluginEffect, *this);
       
   828 		}
       
   829 	else if(aEffect == KEffectFogUid)
       
   830 		{
       
   831 		return new TEffectFog(*aPluginEffect, *this);
       
   832 		}
       
   833 	else if(aEffect == KEffectMirrorLeftToRightUid)
       
   834 		{
       
   835 		return new TEffectMirrorLeftToRight(*aPluginEffect, *this);
       
   836 		}
       
   837 	else if(aEffect == KEffectMagicPenUid)
       
   838 		{
       
   839 		return new TEffectMagicPen(*aPluginEffect, *this);
       
   840 		}
       
   841 	else if(aEffect == KEffectBrightnessUid)
       
   842 		{
       
   843 		return new TEffectBrightness(*aPluginEffect, *this);
       
   844 		}
       
   845 	else if(aEffect == KEffectSharpnessUid)
       
   846 		{
       
   847 		return new TEffectSharpness(*aPluginEffect, *this);
       
   848 		}
       
   849 	else if(aEffect == KEffectRotationUid)
       
   850 		{
       
   851 		return new TEffectRotation(*aPluginEffect, *this);
       
   852 		}
       
   853 	else if(aEffect == KEffectContrastUid)
       
   854 		{
       
   855 		return new TEffectContrast(*aPluginEffect, *this);
       
   856 		}
       
   857 	else if(aEffect == KEffectRgbColorAdjustUid)
       
   858 		{
       
   859 		return new TEffectRgbColorAdjust(*aPluginEffect, *this);
       
   860 		}
       
   861 	else if(aEffect == KEffectEmbossUid)
       
   862 		{
       
   863 		return new TEffectEmboss(*aPluginEffect, *this);
       
   864 		}
       
   865 	else if(aEffect == KEffectSolarizeUid)
       
   866 		{
       
   867 		return new TEffectSolarize(*aPluginEffect, *this);
       
   868 		}
       
   869 	else if(aEffect == KEffectPosterizeUid)
       
   870 		{
       
   871 		return new TEffectPosterize(*aPluginEffect, *this);
       
   872 		}
       
   873 	else if(aEffect == KEffectStampUid)
       
   874 		{
       
   875 		return new TEffectStamp(*aPluginEffect, *this);
       
   876 		}
       
   877 	else if(aEffect == KEffectSketchUid)
       
   878 		{
       
   879 		return new TEffectSketch(*aPluginEffect, *this);
       
   880 		}
       
   881 	else if(aEffect == KEffectNoiseUid)
       
   882 		{
       
   883 		return new TEffectNoise(*aPluginEffect, *this);
       
   884 		}
       
   885 	else if(aEffect == KEffectMoonlightUid)
       
   886 		{
       
   887 		return new TEffectMoonlight(*aPluginEffect, *this);
       
   888 		}
       
   889 	else if(aEffect == KEffectFrostedGlassUid)
       
   890 		{
       
   891 		return new TEffectFrostedGlass(*aPluginEffect, *this);
       
   892 		}
       
   893 	else if(aEffect == KEffectDespeckleUid)
       
   894 		{
       
   895 		return new TEffectDespeckle(*aPluginEffect, *this);
       
   896 		}
       
   897 	else if(aEffect == KEffectBlurUid)
       
   898 		{
       
   899 		return new TEffectBlur(*aPluginEffect, *this);
       
   900 		}
       
   901 	else if(aEffect == KEffectColorizationUid)
       
   902 		{
       
   903 		return new TEffectColorization(*aPluginEffect, *this);
       
   904 		}
       
   905 	else if(aEffect == KEffectCartoonUid)
       
   906 		{
       
   907 		return new TEffectCartoon(*aPluginEffect, *this);
       
   908 		}
       
   909 	else if(aEffect == KEffectLocalBoostUid)
       
   910 		{
       
   911 		return new TEffectLocalBoost(*aPluginEffect, *this);
       
   912 		}
       
   913 	else if(aEffect == KEffectColorBoostUid)
       
   914 		{
       
   915 		return new TEffectColorBoost(*aPluginEffect, *this);
       
   916 		}
       
   917 	else if(aEffect == KEffectWhiteBalanceUid)
       
   918 		{
       
   919 		return new TEffectWhiteBalance(*aPluginEffect, *this);
       
   920 		}
       
   921 	else if(aEffect == KEffectAutoLevelsUid)
       
   922 		{
       
   923 		return new TEffectAutoLevels(*aPluginEffect, *this);
       
   924 		}
       
   925 	else if(aEffect == KEffectLevelsUid)
       
   926 		{
       
   927 		return new TEffectLevels(*aPluginEffect, *this);
       
   928 		}
       
   929 	else if(aEffect == KEffectExposureUid)
       
   930 		{
       
   931 		return new TEffectExposure(*aPluginEffect, *this);
       
   932 		}
       
   933 	else if(aEffect == KEffectSpotLightUid)
       
   934 		{
       
   935 		return new TEffectSpotLight(*aPluginEffect, *this);
       
   936 		}
       
   937 	else if(aEffect == KEffectCustomTransformationUid)
       
   938 		{
       
   939 		return new TEffectCustomTransformation(*aPluginEffect, *this);
       
   940 		}
       
   941 	else if(aEffect == KGeometricalOperationUid)
       
   942 		{
       
   943 		return new TGeometricalOperation(*aPluginEffect, *this);
       
   944 		}
       
   945 	else if(aEffect == KEffectBorderUid)
       
   946 		{
       
   947 		return new TEffectBorder(*aPluginEffect, *this);
       
   948 		}
       
   949 	else if (aEffect == KEffectAntiqueUid)
       
   950 		{
       
   951 		return new TEffectAntique(*aPluginEffect, *this);
       
   952 		}
       
   953 	
       
   954 	User::Leave(KErrNotSupported);
       
   955 	return NULL;
       
   956 	}
       
   957 
       
   958 TEffect* CImageProcessorImpl::EffectL(TUid aEffect)
       
   959 	{
       
   960 	__ASSERT_ALWAYS(((iState != CImgProcessor::EUninitialized) && (iState != CImgProcessor::EInitializing)), User::Leave(KErrNotReady));
       
   961 	//All effects must be supported by the plugin
       
   962 	__ASSERT_ALWAYS(IsPluginEffect(aEffect), User::Leave(KErrNotSupported));
       
   963 	
       
   964 	TEffect* effect=NULL;	
       
   965 		
       
   966 	if(IsFrameworkEffect(aEffect))
       
   967 		{
       
   968 		effect = FindEffect(aEffect);
       
   969 		if(effect == NULL)
       
   970 			{
       
   971 			effect=CreateEffectL(aEffect);
       
   972 			}		
       
   973 		}
       
   974 	else
       
   975 		{
       
   976 		Plugin::MEffect* pluginEffect = iPlugin->EffectL(aEffect);
       
   977 		effect = new TEffect(aEffect, *pluginEffect, *this);
       
   978 		
       
   979 		if (!effect || (iEffects.Append(effect) != KErrNone)) 
       
   980 			{
       
   981 			delete effect;
       
   982 			TInt err = KErrNone;
       
   983 			TRAP(err, ResetL());
       
   984 			iEffects.ResetAndDestroy();
       
   985 			iPlugin->CleanupEffects();
       
   986 			User::Leave(KErrNoMemory);
       
   987 			}
       
   988 		}
       
   989 		
       
   990 	ASSERT(effect);
       
   991 	return effect;
       
   992 	}
       
   993 
       
   994 TBool CImageProcessorImpl::CanUndoL() const
       
   995 	{
       
   996 	__ASSERT_ALWAYS(((iState == CImgProcessor::EInitialized) && (iIsInputSet)), User::Leave(KErrNotReady));
       
   997 	return iPlugin->CanUndoL();
       
   998 	}
       
   999    
       
  1000 void CImageProcessorImpl::UndoL()
       
  1001 	{
       
  1002 	__ASSERT_ALWAYS(((iState == CImgProcessor::EInitialized) && (iIsInputSet)), User::Leave(KErrNotReady));
       
  1003 	iPlugin->UndoL();
       
  1004 	}
       
  1005    
       
  1006 void CImageProcessorImpl::UndoAllL()
       
  1007 	{
       
  1008 	__ASSERT_ALWAYS(((iState == CImgProcessor::EInitialized) && (iIsInputSet)), User::Leave(KErrNotReady));
       
  1009 	iPlugin->UndoAllL();
       
  1010 	}
       
  1011 
       
  1012 TBool CImageProcessorImpl::CanRedoL() const
       
  1013 	{
       
  1014 	__ASSERT_ALWAYS(((iState == CImgProcessor::EInitialized) && (iIsInputSet)), User::Leave(KErrNotReady));
       
  1015 	return iPlugin->CanRedoL();
       
  1016 	}
       
  1017    
       
  1018 void CImageProcessorImpl::RedoL()
       
  1019 	{
       
  1020 	__ASSERT_ALWAYS(((iState == CImgProcessor::EInitialized) && (iIsInputSet)), User::Leave(KErrNotReady));
       
  1021 	iPlugin->RedoL();
       
  1022 	}
       
  1023    
       
  1024 void CImageProcessorImpl::RedoAllL()
       
  1025 	{
       
  1026 	__ASSERT_ALWAYS(((iState == CImgProcessor::EInitialized) && (iIsInputSet)), User::Leave(KErrNotReady));
       
  1027 	iPlugin->RedoAllL();
       
  1028 	}
       
  1029 
       
  1030 TBool FindPreviewRelation(const TInt* aPreviewId, const TPreview& aPreview)
       
  1031 	{
       
  1032 	return (aPreview.PreviewId() == *aPreviewId);
       
  1033 	}
       
  1034 
       
  1035 TPreview* CImageProcessorImpl::FindPreview(TInt aPreviewId) const
       
  1036 	{
       
  1037 	const TInt idx = iPreviews.Find<TInt>(aPreviewId, FindPreviewRelation);
       
  1038 	
       
  1039 	TPreview* preview = NULL;
       
  1040 	if(idx != KErrNotFound)
       
  1041 		{
       
  1042 		preview = iPreviews[idx];
       
  1043 		}
       
  1044 	return preview;
       
  1045 	}
       
  1046    
       
  1047 TPreview* CImageProcessorImpl::PreviewL(TInt aPreviewId)
       
  1048 	{
       
  1049 	__ASSERT_ALWAYS(((iState != CImgProcessor::EUninitialized) && (iState != CImgProcessor::EInitializing)), User::Leave(KErrNotReady));
       
  1050 
       
  1051 	TPreview* preview = FindPreview(aPreviewId);
       
  1052 	if (preview == NULL) 
       
  1053 		{
       
  1054 		Plugin::MPreview* pluginPreview = iPlugin->PreviewL(aPreviewId);
       
  1055 		preview = new TPreview(*pluginPreview, *this);
       
  1056 
       
  1057 		if (!preview || (iPreviews.Append(preview) != KErrNone)) 
       
  1058 			{
       
  1059 			delete preview;
       
  1060 			TInt err = KErrNone;
       
  1061 			TRAP(err, ResetL());
       
  1062 			User::Leave(KErrNoMemory);
       
  1063 			}		
       
  1064 		}
       
  1065 	return preview;
       
  1066 	}
       
  1067 
       
  1068 TOverlay* CImageProcessorImpl::OverlayL()
       
  1069 	{
       
  1070 	__ASSERT_ALWAYS(((iState != CImgProcessor::EUninitialized) && (iState != CImgProcessor::EInitializing)), User::Leave(KErrNotReady));
       
  1071 
       
  1072 	if (iOverlay == NULL) 
       
  1073 		{
       
  1074 		Plugin::MOverlay* pluginOverlay = iPlugin->OverlayL();
       
  1075 		iOverlay = new TOverlay(*pluginOverlay, *this);
       
  1076 		
       
  1077 		if (!iOverlay) 
       
  1078 			{
       
  1079 			TInt err = KErrNone;
       
  1080 			TRAP(err, ResetL());
       
  1081 			User::Leave(KErrNoMemory);
       
  1082 			}
       
  1083 		}
       
  1084 	return iOverlay;
       
  1085 	}
       
  1086 
       
  1087 TProgressInfo* CImageProcessorImpl::ProgressInfoL()
       
  1088 	{
       
  1089 	__ASSERT_ALWAYS(((iState != CImgProcessor::EUninitialized) && (iState != CImgProcessor::EInitializing)), User::Leave(KErrNotReady));
       
  1090 
       
  1091 	if (iProgressInfo == NULL) 
       
  1092 		{
       
  1093 		Plugin::MProgressInfo* pluginProgressInfo = iPlugin->ProgressInfoL();
       
  1094 		iProgressInfo = new TProgressInfo(*pluginProgressInfo, *this);
       
  1095 		
       
  1096 		if (!iProgressInfo) 
       
  1097 			{
       
  1098 			TInt err = KErrNone;
       
  1099 			TRAP(err, ResetL());
       
  1100 			User::Leave(KErrNoMemory);
       
  1101 			}
       
  1102 		}
       
  1103 	return iProgressInfo;
       
  1104 	}
       
  1105 
       
  1106 TInputInfo* CImageProcessorImpl::InputInfoL()
       
  1107 	{
       
  1108 	__ASSERT_ALWAYS(((iState != CImgProcessor::EUninitialized) && (iState != CImgProcessor::EInitializing)), User::Leave(KErrNotReady));
       
  1109 	
       
  1110 	if (iInputInfo == NULL) 
       
  1111 		{
       
  1112 		Plugin::MInputInfo* pluginInputInfo = iPlugin->InputInfoL();
       
  1113 		iInputInfo = new TInputInfo(*pluginInputInfo, *this);
       
  1114 
       
  1115 		if (!iInputInfo) 
       
  1116 			{
       
  1117 			TInt err = KErrNone;
       
  1118 			TRAP(err, ResetL());
       
  1119 			User::Leave(KErrNoMemory);
       
  1120 			}
       
  1121 		}
       
  1122 	return iInputInfo;
       
  1123 	}
       
  1124 
       
  1125 TOutputInfo* CImageProcessorImpl::OutputInfoL()
       
  1126 	{
       
  1127 	__ASSERT_ALWAYS(((iState != CImgProcessor::EUninitialized) && (iState != CImgProcessor::EInitializing)), User::Leave(KErrNotReady));
       
  1128 	
       
  1129 	if (iOutputInfo == NULL) 
       
  1130 		{
       
  1131 		Plugin::MOutputInfo* pluginOutputInfo = iPlugin->OutputInfoL();
       
  1132 		iOutputInfo = new TOutputInfo(*pluginOutputInfo, *this);
       
  1133 
       
  1134 		if (!iOutputInfo) 
       
  1135 			{
       
  1136 			TInt err = KErrNone;
       
  1137 			TRAP(err, ResetL());
       
  1138 			User::Leave(KErrNoMemory);
       
  1139 			}
       
  1140 		}
       
  1141 	return iOutputInfo;
       
  1142 	}
       
  1143 
       
  1144 void CImageProcessorImpl::SetOutputL(const TDesC& aFilename, const TUid& aFormat, const TUid& aSubFormat)
       
  1145 	{
       
  1146 	__ASSERT_ALWAYS((iState == CImgProcessor::EInitialized), User::Leave(KErrNotReady));
       
  1147 	CheckOutputFormatL(aFormat, aSubFormat);
       
  1148 	iPlugin->SetOutputL(aFilename, aFormat, aSubFormat);
       
  1149 	iIsOutputSet = ETrue;
       
  1150 	}
       
  1151    
       
  1152 void CImageProcessorImpl::SetOutputL(RFile& aFile, const TUid& aFormat, const TUid& aSubFormat)
       
  1153 	{
       
  1154 	__ASSERT_ALWAYS((iState == CImgProcessor::EInitialized), User::Leave(KErrNotReady));
       
  1155 	CheckOutputFormatL(aFormat, aSubFormat);
       
  1156 	iPlugin->SetOutputL(aFile, aFormat, aSubFormat);
       
  1157 	iIsOutputSet = ETrue;
       
  1158 	}
       
  1159    
       
  1160 void CImageProcessorImpl::SetOutputL(RBuf8& aBuffer, const TUid& aFormat, const TUid& aSubFormat)
       
  1161 	{
       
  1162 	__ASSERT_ALWAYS((iState == CImgProcessor::EInitialized), User::Leave(KErrNotReady));
       
  1163 	CheckOutputFormatL(aFormat, aSubFormat);
       
  1164 	iPlugin->SetOutputL(aBuffer, aFormat, aSubFormat);
       
  1165 	iIsOutputSet = ETrue;
       
  1166 	}
       
  1167    
       
  1168 void CImageProcessorImpl::SetOutputL(CImageFrame& aPixelBuffer)
       
  1169 	{
       
  1170 	__ASSERT_ALWAYS((iState == CImgProcessor::EInitialized), User::Leave(KErrNotReady));
       
  1171 	
       
  1172 	if (aPixelBuffer.FrameSizeInPixels() == TSize(0,0)) 
       
  1173 		{
       
  1174 		User::Leave(KErrArgument);
       
  1175 		}
       
  1176 	
       
  1177 	iPlugin->SetOutputL(aPixelBuffer);
       
  1178 	iIsOutputSet = ETrue;
       
  1179 	}
       
  1180 
       
  1181 void CImageProcessorImpl::SetOutputL(CFbsBitmap& aBitmap, CFbsBitmap* aMask)
       
  1182 	{
       
  1183 	__ASSERT_ALWAYS((iState == CImgProcessor::EInitialized), User::Leave(KErrNotReady));
       
  1184 
       
  1185 	if (aBitmap.SizeInPixels() == TSize(0,0)) 
       
  1186 		{
       
  1187 		User::Leave(KErrArgument);
       
  1188 		}
       
  1189 	
       
  1190 	if((aBitmap.Handle()!=0 && aBitmap.ExtendedBitmapType()!=KNullUid) || (aMask!=NULL && aMask->Handle()!=0 && aMask->ExtendedBitmapType()!=KNullUid))
       
  1191         {
       
  1192         User::Leave(KErrNotSupported);
       
  1193         }
       
  1194 	
       
  1195 	if ((aMask != NULL) && (aMask->SizeInPixels() == TSize(0,0))) 
       
  1196 		{
       
  1197 		User::Leave(KErrArgument);
       
  1198 		}
       
  1199 	
       
  1200 	iPlugin->SetOutputL(aBitmap, aMask);
       
  1201 	iIsOutputSet = ETrue;
       
  1202 	}
       
  1203 
       
  1204 void CImageProcessorImpl::PostEvent(TInt aEventId, TUid aUid, TInt aId, TInt aError)
       
  1205 	{
       
  1206 	if (aEventId == CImgProcessor::EEventProcessingComplete && aError == KErrNone) 
       
  1207 		{
       
  1208 		if (iDrmInput != NULL) 
       
  1209 			{
       
  1210 			TRAPD(drmErr, iDrmInput->ExecuteIntentL());
       
  1211 			if (drmErr != KErrNone) 
       
  1212 				{
       
  1213 				iPlugin->CleanupOutput();//should delete/cleanup unauthorised output
       
  1214 				iCallbackHandler->AddCallback(aEventId, aUid, aId, drmErr);
       
  1215 				return;
       
  1216 				}
       
  1217 			}
       
  1218 		
       
  1219 		for (TInt i=0; i < iOverlayDrmInputs.Count(); i++ )
       
  1220 			{ 
       
  1221 			TRAPD(overlayDrmErr, iOverlayDrmInputs[i]->ExecuteIntentL());
       
  1222 			if (overlayDrmErr != KErrNone) 
       
  1223 				{
       
  1224 				iPlugin->CleanupOutput();//should delete/cleanup unauthorised output
       
  1225 				iCallbackHandler->AddCallback(aEventId, aUid, aId, overlayDrmErr);
       
  1226 				return;
       
  1227 				}
       
  1228 			}
       
  1229 		}
       
  1230 	
       
  1231 	TRAPD(err, ProcessEventL(aEventId, aUid, aId, aError));
       
  1232 
       
  1233 	if (err != KErrNone) 
       
  1234 		{
       
  1235 		//strayed event?
       
  1236 		if (aError == KErrNone) 
       
  1237 			{
       
  1238 			aError = err;
       
  1239 			}
       
  1240 		}
       
  1241 	
       
  1242 	iCallbackHandler->AddCallback(aEventId, aUid, aId, aError);
       
  1243 	}
       
  1244 
       
  1245 void CImageProcessorImpl::ProcessEventL(TInt aEventId, TUid /*aUid*/, TInt aId, TInt aError)
       
  1246 	{
       
  1247 	switch (aEventId) 
       
  1248 		{
       
  1249 		case CImgProcessor::EEventInitializingComplete:
       
  1250 			SetStateL((aError == KErrNone)? CImgProcessor::EInitialized: CImgProcessor::EUninitialized);
       
  1251 			break;
       
  1252 		
       
  1253 		case CImgProcessor::EEventProcessingComplete:
       
  1254 			RestoreStateL();
       
  1255 			break;
       
  1256 		
       
  1257 		case CImgProcessor::EEventPreviewInitializingComplete:
       
  1258 			PreviewL(aId)->SetStateL((aError == KErrNone)? TPreview::EInitialized: TPreview::EUninitialized);
       
  1259 			RestoreStateL();
       
  1260 			break;
       
  1261 
       
  1262 		case CImgProcessor::EEventPreviewRenderingComplete:
       
  1263 			PreviewL(aId)->SetStateL(TPreview::EInitialized);
       
  1264 			RestoreStateL();
       
  1265 			break;
       
  1266 		}
       
  1267 	}
       
  1268 
       
  1269 TAny* CImageProcessorImpl::Extension(TUid aExtension)
       
  1270 	{
       
  1271 	__ASSERT_ALWAYS((iState == CImgProcessor::EInitialized), Panic(EPanicNotInitialized));
       
  1272 	return iPlugin->Extension(aExtension);
       
  1273 	}
       
  1274 
       
  1275 TBool CImageProcessorImpl::IsBusy(CImgProcessor::TState aState) const 
       
  1276 	{
       
  1277 	return (aState == CImgProcessor::EInitializing || 
       
  1278 		aState == CImgProcessor::EProcessing || 
       
  1279 		aState == CImgProcessor::EPreviewInitializing || 
       
  1280 		aState == CImgProcessor::EPreviewRendering);
       
  1281 	}
       
  1282 
       
  1283 void CImageProcessorImpl::SetStateL(CImgProcessor::TState aState)
       
  1284 	{
       
  1285 	if(iState != aState)
       
  1286 		{
       
  1287 		if (!iValidStates[iState][aState]) 
       
  1288 			{
       
  1289 			User::Leave(KErrNotReady);
       
  1290 			}
       
  1291 		
       
  1292 		if (IsBusy(aState))
       
  1293 			{
       
  1294 			iPreviousState = iState;
       
  1295 			}
       
  1296 
       
  1297 		iState = aState;
       
  1298 		}
       
  1299 	}
       
  1300 
       
  1301 void CImageProcessorImpl::RestoreStateL()
       
  1302 	{
       
  1303 	SetStateL(iPreviousState);
       
  1304 	}
       
  1305 
       
  1306 void CImageProcessorImpl::ConvertMimeTypeToUidL(const TDesC8& aMimeType, TUid& aFormat, TUid& aSubFormat)
       
  1307 	{
       
  1308 	for (TInt i = 0; i < iTypesUtilityArray.Count(); i++)
       
  1309 		{
       
  1310 		CFileExtensionMIMEType& fileExtAndMIMEType = *iTypesUtilityArray[i];
       
  1311 				
       
  1312 		if ( (fileExtAndMIMEType.MIMEType().Length() > 0)
       
  1313 		     && (aMimeType.Find(fileExtAndMIMEType.MIMEType()) != KErrNotFound) ) 
       
  1314 			{
       
  1315 			aFormat = fileExtAndMIMEType.ImageType(); 
       
  1316 			aSubFormat = fileExtAndMIMEType.ImageSubType();
       
  1317 			return;
       
  1318 			}
       
  1319 		}
       
  1320 	User::Leave(KErrNotFound);
       
  1321 	}
       
  1322 
       
  1323 void CImageProcessorImpl::ConvertFileExtensionToUidL(const TDesC& aFileExtension, TUid& aFormat, TUid& aSubFormat)
       
  1324 	{
       
  1325 	for (TInt i = 0; i < iTypesUtilityArray.Count(); i++)
       
  1326 		{
       
  1327 		CFileExtensionMIMEType& fileExtAndMIMEType = *iTypesUtilityArray[i];
       
  1328 		
       
  1329 		if ( (fileExtAndMIMEType.FileExtension().Length() > 0 ) 
       
  1330 		     && (aFileExtension.Find(fileExtAndMIMEType.FileExtension()) != KErrNotFound) ) 
       
  1331 			{
       
  1332 			aFormat = fileExtAndMIMEType.ImageType(); 
       
  1333 			aSubFormat = fileExtAndMIMEType.ImageSubType();
       
  1334 			return;
       
  1335 			}
       
  1336 		}
       
  1337 	User::Leave(KErrNotFound);
       
  1338 	}
       
  1339 
       
  1340 void CImageProcessorImpl::ConvertUidToMimeTypeL(TDes8& aMimeType, const TUid& aFormat, const TUid& /*aSubFormat*/)
       
  1341 	{
       
  1342 	for (TInt i = 0; i < iTypesUtilityArray.Count(); i++)
       
  1343 		{
       
  1344 		CFileExtensionMIMEType& fileExtAndMIMEType = *iTypesUtilityArray[i];
       
  1345 		
       
  1346 		if (fileExtAndMIMEType.ImageType() == aFormat) 
       
  1347 			{
       
  1348 			aMimeType = fileExtAndMIMEType.MIMEType();
       
  1349 			return;
       
  1350 			}
       
  1351 		}
       
  1352 	User::Leave(KErrNotFound);
       
  1353 	}
       
  1354 
       
  1355 void CImageProcessorImpl::ConvertUidToFileExtensionL(TDes& aFileExtension, const TUid& aFormat, const TUid& /*aSubFormat*/)
       
  1356 	{
       
  1357 	for (TInt i = 0; i < iTypesUtilityArray.Count(); i++)
       
  1358 		{
       
  1359 		CFileExtensionMIMEType& fileExtAndMIMEType = *iTypesUtilityArray[i];
       
  1360 		
       
  1361 		if (fileExtAndMIMEType.ImageType() == aFormat) 
       
  1362 			{
       
  1363 			aFileExtension = fileExtAndMIMEType.FileExtension();
       
  1364 			return;
       
  1365 			}
       
  1366 		}
       
  1367 	User::Leave(KErrNotFound);
       
  1368 	}
       
  1369 
       
  1370 void CImageProcessorImpl::AppendOverlayDrmInputL() 
       
  1371 	{
       
  1372 	if (iOverlayDrmInput != NULL) 
       
  1373 		{
       
  1374 		iOverlayDrmInputs.AppendL(iOverlayDrmInput);
       
  1375 		iOverlayDrmInput = NULL;
       
  1376 		}
       
  1377 	}
       
  1378 
       
  1379 CImageProcessorDrmInput* CImageProcessorDrmInput::NewL(TMMSource& aDrmFile)
       
  1380 	{
       
  1381 	CImageProcessorDrmInput* self = new (ELeave) CImageProcessorDrmInput();
       
  1382 	CleanupStack::PushL(self);
       
  1383 	self->ConstructL(aDrmFile);
       
  1384 	CleanupStack::Pop(self);
       
  1385 	return self;
       
  1386 	}
       
  1387 
       
  1388 void CImageProcessorDrmInput::ConstructL(TMMSource& aDrmFile)
       
  1389 	{
       
  1390 		{
       
  1391 		using namespace ContentAccess;
       
  1392 		
       
  1393 		TUid sourceType = aDrmFile.SourceType();
       
  1394 		const TDesC& uniqueId = aDrmFile.UniqueId();
       
  1395 		TIntent intent = aDrmFile.Intent();
       
  1396 		CContent* content = NULL;
       
  1397 		
       
  1398 		if (sourceType == KUidMMFileHandleSource)
       
  1399 			{
       
  1400 			const TMMFileHandleSource& source = static_cast<const TMMFileHandleSource&>(aDrmFile);
       
  1401 			content = CContent::NewL(source.Handle());
       
  1402 			}
       
  1403 		else if (sourceType == KUidMMFileSource) 
       
  1404 			{
       
  1405 			const TMMFileSource& fileSource = static_cast<const TMMFileSource&>(aDrmFile);
       
  1406 		
       
  1407 			TRAPD(err, content = CContent::NewL(fileSource.Name(), EContentShareReadOnly));
       
  1408         
       
  1409 			if(err != KErrNone && err != KErrNoMemory) //We retry in case the client already has the file open.
       
  1410 				{
       
  1411 				content = CContent::NewL(fileSource.Name(), EContentShareReadWrite);
       
  1412 				}
       
  1413 			}
       
  1414 		else 
       
  1415 			{
       
  1416 			// unknown source type
       
  1417 			User::Leave(KErrNotSupported);
       
  1418 			}
       
  1419         
       
  1420 		CleanupStack::PushL(content);
       
  1421 
       
  1422 		CData* data = content->OpenContentL(intent, uniqueId);
       
  1423 		CleanupStack::PushL(data);
       
  1424 
       
  1425 		User::LeaveIfError(data->EvaluateIntent(intent));
       
  1426 	
       
  1427 		TInt size = 0;
       
  1428 		data->DataSizeL(size);
       
  1429 		HBufC8 *readBuffer = HBufC8::NewMaxL(size);
       
  1430 		CleanupStack::PushL(readBuffer);
       
  1431 	
       
  1432 		TPtr8 ptr(readBuffer->Des());
       
  1433 		TInt pos = 0;
       
  1434 		User::LeaveIfError(data->Seek(ESeekStart, pos));
       
  1435 		User::LeaveIfError(data->Read(ptr, size));
       
  1436 
       
  1437 		CleanupStack::Pop(3);
       
  1438 
       
  1439 		iDecryptedBuffer = readBuffer;
       
  1440 		iContent = content;
       
  1441 		iData = data;
       
  1442 		iIntent = intent;
       
  1443 		}
       
  1444 	}
       
  1445 
       
  1446 void CImageProcessorDrmInput::ExecuteIntentL()
       
  1447 	{
       
  1448 	User::LeaveIfError(iData->ExecuteIntent(iIntent));
       
  1449 	}
       
  1450 
       
  1451 CImageProcessorDrmInput::~CImageProcessorDrmInput() 
       
  1452 	{
       
  1453 	delete iDecryptedBuffer;
       
  1454 	delete iContent;
       
  1455 	delete iData;
       
  1456 	}
       
  1457 
       
  1458 //EOF