imagingandcamerafws/imagingfws/MediaClientImage/Source/Client/Image/Mclvidpriv.cpp
changeset 0 40261b775718
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     1 // Copyright (c) 1997-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 <bitdev.h>
       
    17 #include <mdaimageconverter.h>
       
    18 #include "MdaImageConverterPriv.h"
       
    19 #include <ecom/ecom.h>
       
    20 
       
    21 #include <imageconversion.h>
       
    22 #include <bitmaptransforms.h>
       
    23 
       
    24 #include "CompatAids.h"
       
    25 
       
    26 #if defined(__ECOM_POWERDOWN_WORKAROUND)
       
    27 	const TInt KWaitTimeMax = 8;
       
    28 	const TInt KWaitTimeIncrement = 250000; // 0.25s
       
    29 #endif  // defined(__ECOM_POWERDOWN_WORKAROUND)
       
    30 
       
    31 GLDEF_C void Panic (TInt aPanic)
       
    32 	{
       
    33 	_LIT(KMdaImageConverter, "MDA Image Converter");
       
    34 	User::Panic(KMdaImageConverter, aPanic);
       
    35 	}
       
    36 
       
    37 
       
    38 //
       
    39 // CMdaImageUtilityPriv
       
    40 //
       
    41 
       
    42 CMdaImageUtilityPriv::CMdaImageUtilityPriv(MMdaImageUtilObserver& aObserver, CMdaImageUtility* aParent):
       
    43 	iObserver(aObserver), iParent(aParent)
       
    44 	{}
       
    45 
       
    46 CMdaImageUtilityPriv::~CMdaImageUtilityPriv()
       
    47 	{
       
    48 	delete iImageData;
       
    49 	delete iFrameData;
       
    50 	iFs.Close();
       
    51 	CloseEcomSession();
       
    52 #if defined(__ECOM_POWERDOWN_WORKAROUND)
       
    53 	iWaitTimer.Close(); 
       
    54 #endif  // defined(__ECOM_POWERDOWN_WORKAROUND)
       
    55 	}
       
    56 
       
    57 void CMdaImageUtilityPriv::CloseEcomSession()
       
    58 	{
       
    59 	if (iEcomSession)
       
    60 		iEcomSession->Close();
       
    61 	iEcomSession = NULL;
       
    62 	}
       
    63 
       
    64 void CMdaImageUtilityPriv::OpenEcomSessionL()
       
    65 	{
       
    66 	if (iEcomSession==NULL)
       
    67 		iEcomSession = &(REComSession::OpenL());
       
    68 	}
       
    69 
       
    70 /**
       
    71  *
       
    72  * Closes the open file-based or descriptor-based image.
       
    73  *
       
    74  * Any conversion operation in progress is cancelled.
       
    75  *
       
    76  */
       
    77 void CMdaImageUtilityPriv::Close()
       
    78 	{
       
    79 	Close(ETrue);
       
    80 	}
       
    81 
       
    82 // officially reset at end - in practice we always make this call before opening too
       
    83 void CMdaImageUtilityPriv::Close(TBool aFullClose)
       
    84 	{
       
    85 	ASSERT(iParent);
       
    86 	iParent->Cancel();
       
    87 	DoClose();
       
    88 	if (aFullClose)
       
    89 		CloseEcomSession();
       
    90 #if defined(__ECOM_POWERDOWN_WORKAROUND)
       
    91 	iWaitTimeCount = 0; 
       
    92 #endif  // defined(__ECOM_POWERDOWN_WORKAROUND)
       
    93 	}
       
    94 
       
    95 void CMdaImageUtilityPriv::DoClose()
       
    96 	{
       
    97 	}
       
    98 
       
    99 void CMdaImageUtilityPriv::Initialize()
       
   100 	{
       
   101 	ASSERT(iParent);
       
   102 	CActiveScheduler::Add(iParent);
       
   103 	}
       
   104 
       
   105 void CMdaImageUtilityPriv::OpenFsSessionL()
       
   106 	{
       
   107 	ASSERT(iFs.Handle()==0); // intended for use from ConstructL only
       
   108 
       
   109 	User::LeaveIfError(iFs.Connect());
       
   110 	}
       
   111 
       
   112 #if defined(__ECOM_POWERDOWN_WORKAROUND)
       
   113 void CMdaImageUtilityPriv::OpenWaitTimerL()
       
   114 	{
       
   115 	ASSERT(iWaitTimer.Handle()==0); // intended for use from ConstructL etc only
       
   116 	User::LeaveIfError(iWaitTimer.CreateLocal());
       
   117 	}
       
   118 #endif  // defined(__ECOM_POWERDOWN_WORKAROUND)
       
   119 
       
   120 /**
       
   121 Retrieves information about the specified frame.
       
   122 
       
   123 This function should only be called after an existing image has been
       
   124 successfully opened or a new image successfully created.
       
   125 
       
   126 @param     aFrame
       
   127            The frame number. This value is relative to zero. The
       
   128            value must be less than the total number of frames in
       
   129            the image, otherwise the function raises a USER 0
       
   130            panic
       
   131 @param     aInfo
       
   132            Frame information.
       
   133 */
       
   134 void CMdaImageUtilityPriv::FrameInfo(TInt /*aFrame*/,TFrameInfo& /*aInfo*/) const
       
   135 	{
       
   136 	__PANIC_COMPAT(Panic(EMDAImConvPanicNotImplemented)); // only implemented for data read
       
   137 	}
       
   138 
       
   139 /**
       
   140 Returns the number of frames in the image.
       
   141 
       
   142 @return   The number of frames in the image
       
   143 */
       
   144 TInt CMdaImageUtilityPriv::FrameCount() const
       
   145 	{
       
   146 	__PANIC_COMPAT(Panic(EMDAImConvPanicNotImplemented)); // only implemented for data read
       
   147 	return 0; 
       
   148 	}
       
   149 
       
   150 //
       
   151 // Performs a User::RequestComplete() operation on this itself.
       
   152 //
       
   153 void CMdaImageUtilityPriv::SelfComplete(TInt aError)
       
   154 	{
       
   155 	ASSERT(iParent);
       
   156 	iParent->SelfComplete(aError);
       
   157 	}
       
   158 
       
   159 // Effectively converts the old format converts to the new ones. The
       
   160 // results are placed in iImageType and iImageSubType, plus perhaps iImageData
       
   161 //
       
   162 //	TMdaClipFormat* aFormat = NULL
       
   163 //		The data format. This is optional.
       
   164 //	TMdaPackage* aCodec = NULL
       
   165 //		The codec to use. This is optional.
       
   166 //	TMdaPackage* aExtra = NULL
       
   167 //		Additional information which the Media Server may need
       
   168 //		to recognise the data format. This is optional.
       
   169 //
       
   170 void CMdaImageUtilityPriv::SetUidsFromOrigFormatsL(TMdaClipFormat* aFormat,
       
   171 											   TMdaPackage* aCodec,
       
   172 											   TMdaPackage* /*aExtra*/)
       
   173 	{
       
   174 	// set default values first
       
   175 	delete iImageData; iImageData=NULL;
       
   176 	iImageType = KNullUid;
       
   177 	iImageSubType = KNullUid;
       
   178 
       
   179 	// Note in general below we ignore the codec settings, unless the latter is used
       
   180 	// to indicate format. 
       
   181 
       
   182 	if (aFormat)
       
   183 		{
       
   184 		TUid formatUid = aFormat->Uid();
       
   185 		if (formatUid==KUidMdaBmpClipFormat)
       
   186 			{
       
   187 			iImageType = KImageTypeBMPUid;
       
   188 			if (aCodec)
       
   189 				{
       
   190 				iImageData = new (ELeave) TBmpImageData;
       
   191 				TBmpImageData *data = STATIC_CAST(TBmpImageData*,iImageData);
       
   192 				if (aCodec->Uid() == KUidMda1BppBmpCodec)
       
   193 					data->iBitsPerPixel = 1;
       
   194 				else if (aCodec->Uid() == KUidMda4BppBmpCodec)
       
   195 					data->iBitsPerPixel = 4;
       
   196 				else if (aCodec->Uid() == KUidMda8BppBmpCodec)
       
   197 					data->iBitsPerPixel = 8;
       
   198 				else if (aCodec->Uid() == KUidMda24BppBmpCodec)
       
   199 					data->iBitsPerPixel = 24;
       
   200 				else
       
   201 					{
       
   202 					// unknown value - so leave undefined
       
   203 					delete iImageData; iImageData = NULL;
       
   204 					}
       
   205 				}
       
   206 			}
       
   207 		else if (formatUid==KUidMdaGif87aClipFormat || formatUid==KUidMdaGif89aClipFormat) 
       
   208 			iImageType = KImageTypeGIFUid; 
       
   209 		else if (formatUid==KUidMdaJfifClipFormat)
       
   210 			{
       
   211 			TMdaJfifClipFormat *jfifFormat = STATIC_CAST(TMdaJfifClipFormat*, aFormat);
       
   212 			TMdaJpgSettings::TColorSampling sampling = jfifFormat->iSettings.iSampleScheme;
       
   213 			iImageType = KImageTypeJPGUid; 
       
   214 			iImageData = new (ELeave) TJpegImageData;
       
   215 			TJpegImageData* data = STATIC_CAST(TJpegImageData*, iImageData);
       
   216 			ASSERT(TInt(TMdaJpgSettings::EMonochrome)==TInt(TJpegImageData::EMonochrome)); // check old sample type = new one
       
   217 			ASSERT(TInt(TMdaJpgSettings::EColor420)==TInt(TJpegImageData::EColor420));
       
   218 			ASSERT(TInt(TMdaJpgSettings::EColor422)==TInt(TJpegImageData::EColor422));
       
   219 			ASSERT(TInt(TMdaJpgSettings::EColor444)==TInt(TJpegImageData::EColor444));
       
   220 			ASSERT(sampling>=TMdaJpgSettings::EMonochrome && sampling <= TMdaJpgSettings::EColor444); // valid range
       
   221 			data->iSampleScheme = TJpegImageData::TColorSampling(sampling); // can just copy value
       
   222 			data->iQualityFactor = jfifFormat->iSettings.iQualityFactor;
       
   223 			}
       
   224 		else if (formatUid==KUidMdaMbmClipFormat)
       
   225 			{
       
   226 			TMdaMbmClipFormat *mbmFormat = STATIC_CAST(TMdaMbmClipFormat*, aFormat);
       
   227 			TDisplayMode displayMode = mbmFormat->iDisplayMode;
       
   228 			iImageType = KImageTypeMBMUid;
       
   229 			iFrameData = new (ELeave) TMbmEncodeData;
       
   230 			TMbmEncodeData* data = STATIC_CAST(TMbmEncodeData*, iFrameData);
       
   231 			data->iDisplayMode = displayMode;
       
   232 			}
       
   233 		else if (formatUid==KUidMdaOtaClipFormat) // SMS OTA format
       
   234 			iImageType = KImageTypeOTAUid; 
       
   235 		else if (formatUid==KUidMdaWbmpClipFormat)
       
   236 			iImageType = KImageTypeWBMPUid;
       
   237 		else if (formatUid==KUidMdaPngClipFormat)
       
   238 			iImageType = KImageTypePNGUid;
       
   239 		else if (formatUid==KUidMdaTiffLittleEndianClipFormat ||
       
   240 				 formatUid==KUidMdaTiffBigEndianClipFormat)
       
   241 			{
       
   242 			iImageType=KImageTypeTIFFUid;
       
   243 			if (formatUid==KUidMdaTiffLittleEndianClipFormat)
       
   244 				iImageSubType=KImageTypeTIFFSubTypeLittleEndianUid;
       
   245 			else
       
   246 				{
       
   247 				ASSERT(formatUid==KUidMdaTiffBigEndianClipFormat);
       
   248 				iImageSubType=KImageTypeTIFFSubTypeBigEndianUid;
       
   249 				}
       
   250 			}
       
   251 		else if (formatUid==KUidMdaTiffBigEndianClipFormat)
       
   252 			{
       
   253 			iImageType = KImageTypeTIFFUid;
       
   254 			iImageSubType = KImageTypeTIFFSubTypeBigEndianUid;
       
   255 			}
       
   256 		else if (formatUid==KUidMdaWmfClipFormat ||
       
   257 			     formatUid==KUidMdaWmfApmClipFormat ||
       
   258 			     formatUid==KUidMdaWmfClpClipFormat)
       
   259 			{
       
   260 			iImageType = KImageTypeWMFUid;
       
   261 			if (formatUid==KUidMdaWmfApmClipFormat)
       
   262 				iImageSubType = KImageTypeWMFSubTypeApmUid;
       
   263 			else if (formatUid==KUidMdaWmfClpClipFormat)
       
   264 				iImageSubType = KImageTypeWMFSubTypeClpUid;
       
   265 			else
       
   266 				{
       
   267 				ASSERT(formatUid==KUidMdaWmfClipFormat);
       
   268 				iImageSubType = KImageTypeWMFSubTypeStdUid;
       
   269 				}
       
   270 			}
       
   271 		else
       
   272 			User::Leave(KErrNotSupported);
       
   273 		}
       
   274 	}
       
   275 
       
   276 //
       
   277 // CMdaImageDataReadUtilityPriv
       
   278 //
       
   279 
       
   280 CMdaImageDataReadUtilityPriv::CMdaImageDataReadUtilityPriv(MMdaImageUtilObserver& aObserver,
       
   281 														   CMdaImageDataReadUtility* aParent):
       
   282 	CMdaImageUtilityPriv(aObserver, aParent)
       
   283 	{
       
   284 	}
       
   285 
       
   286 CMdaImageDataReadUtilityPriv::~CMdaImageDataReadUtilityPriv()
       
   287 	{
       
   288 	Close(ETrue);
       
   289 	ASSERT(iDecoder==NULL); // should have been deleted by Close
       
   290 	}
       
   291 
       
   292 void CMdaImageDataReadUtilityPriv::ConvertL(CFbsBitmap& aBitmap,TInt aFrameNumber)
       
   293 	{
       
   294 	ASSERT(Parent());
       
   295 	if (iState != EStateOpen)
       
   296 		User::Leave(KErrNotReady);
       
   297 
       
   298 	ASSERT(iDecoder);
       
   299 
       
   300 	TBool doContinue = EFalse;
       
   301 	if (iPrevConvertUnderflowed && iKeptFrameNumber == aFrameNumber)
       
   302 		{
       
   303 		// if previous convert Underflowed, and same bitmap, we ContinueConvert instead of Convert
       
   304 		if (iDestinationHandle == aBitmap.Handle() && 
       
   305 			iDestinationDisplayMode == aBitmap.DisplayMode() && 
       
   306 			iDestinationMaskHandle == 0 &&
       
   307 			iDestinationSize == aBitmap.SizeInPixels())
       
   308 			doContinue = ETrue;
       
   309 		}
       
   310 
       
   311 	if (doContinue)
       
   312 		iDecoder->ContinueConvert(&Parent()->iStatus);
       
   313 	else
       
   314 		{
       
   315 		iDestinationHandle = aBitmap.Handle();
       
   316 		iDestinationMaskHandle = 0;
       
   317 		if (aBitmap.Handle())
       
   318 			{
       
   319 			iDestinationDisplayMode = aBitmap.DisplayMode();
       
   320 			iDestinationSize = aBitmap.SizeInPixels();
       
   321 			}
       
   322 		iDecoder->Convert(&Parent()->iStatus, aBitmap, aFrameNumber); 
       
   323 		}
       
   324 	Parent()->SetActive();
       
   325 	iState = EStateConverting;
       
   326 	}
       
   327 
       
   328 void CMdaImageDataReadUtilityPriv::ConvertL(CFbsBitmap& aBitmap,CFbsBitmap& aMaskBitmap,TInt aFrameNumber)
       
   329 	{
       
   330 	ASSERT(Parent());
       
   331 	if (iState != EStateOpen)
       
   332 		User::Leave(KErrNotReady);
       
   333 
       
   334 	ASSERT(iDecoder);
       
   335 
       
   336 	TBool doContinue = EFalse;
       
   337 	if (iPrevConvertUnderflowed && iKeptFrameNumber == aFrameNumber)
       
   338 		{
       
   339 		// if previous convert Underflowed, and same bitmap, we ContinueConvert instead of Convert
       
   340 		if (iDestinationHandle == aBitmap.Handle() && 
       
   341 			iDestinationDisplayMode == aBitmap.DisplayMode() && 
       
   342 			iDestinationMaskHandle == aMaskBitmap.Handle() &&
       
   343 			iDestinationMaskDisplayMode == aMaskBitmap.DisplayMode() && 
       
   344 			iDestinationSize == aBitmap.SizeInPixels())
       
   345 			doContinue = ETrue;
       
   346 		}
       
   347 
       
   348 	if (doContinue)
       
   349 		iDecoder->ContinueConvert(&Parent()->iStatus);
       
   350 	else
       
   351 		{
       
   352 		iDestinationHandle = aBitmap.Handle();
       
   353 		iDestinationMaskHandle = aMaskBitmap.Handle();
       
   354 		if (aBitmap.Handle())
       
   355 			{
       
   356 			iDestinationDisplayMode = aBitmap.DisplayMode();
       
   357 			iDestinationSize = aBitmap.SizeInPixels();
       
   358 			}
       
   359 		if (aMaskBitmap.Handle())
       
   360 			iDestinationMaskDisplayMode = aMaskBitmap.DisplayMode();
       
   361 		iDecoder->Convert(&Parent()->iStatus, aBitmap, aMaskBitmap, aFrameNumber); 
       
   362 		}
       
   363 	Parent()->SetActive();
       
   364 	iState = EStateConverting;
       
   365 	}
       
   366 
       
   367 void CMdaImageDataReadUtilityPriv::CancelConvertL()
       
   368 	{
       
   369 	Parent()->Cancel();
       
   370 	}
       
   371 
       
   372 void CMdaImageDataReadUtilityPriv::RunL()
       
   373 	{
       
   374 	ASSERT(Parent());
       
   375 	switch (iState)
       
   376 		{
       
   377 		case EStateClosed:
       
   378 			ASSERT(EFalse); // should not happen
       
   379 			break;
       
   380 		case EStateOpening:
       
   381 			{
       
   382 			TInt error = Parent()->iStatus.Int();
       
   383 			if (error==KErrNone)
       
   384 				TRAP(error, OpenEcomSessionL());
       
   385 			if (error==KErrNone)
       
   386 				TRAP(error, DoOpenL());
       
   387 			ASSERT(error!=KErrNone || iDecoder); // if successful should have an iDecoder
       
   388 			if (error==KErrNone)
       
   389 				{
       
   390 				iState=EStateOpen;
       
   391 				iObserver.MiuoOpenComplete(error);
       
   392 				}
       
   393 			else
       
   394 				{
       
   395 #if defined(__ECOM_POWERDOWN_WORKAROUND)
       
   396 				if (error==KEComErrListCurrentlyUnavailable && iWaitTimeCount < KWaitTimeMax)
       
   397 					{
       
   398 					iWaitTimeCount ++;
       
   399 					TInt waitTime = iWaitTimeCount * KWaitTimeIncrement;
       
   400 					iState = EStateOpeningWait;
       
   401 					iWaitTimer.After(Parent()->iStatus, waitTime);
       
   402 					Parent()->SetActive();
       
   403 					}
       
   404 				else
       
   405 #endif  // defined(__ECOM_POWERDOWN_WORKAROUND)
       
   406 					{
       
   407 					if (error!=KErrUnderflow) // keep ecom session on streaming
       
   408 						CloseEcomSession();
       
   409 					iState=EStateClosed;
       
   410 					iObserver.MiuoOpenComplete(error);
       
   411 					}
       
   412 				}
       
   413 			}
       
   414 			break;
       
   415 		case EStateOpeningWait:
       
   416 #if defined(__ECOM_POWERDOWN_WORKAROUND)
       
   417 			{
       
   418 			TInt error = Parent()->iStatus.Int();	
       
   419 			if (error!=KErrNone)
       
   420 				{
       
   421 				CloseEcomSession();
       
   422 				iState = EStateClosed;
       
   423 				iObserver.MiuoOpenComplete(error);
       
   424 				}
       
   425 			else
       
   426 				{
       
   427 				iState = EStateOpening;
       
   428 				SelfComplete(error);
       
   429 				}
       
   430 			}
       
   431 #else
       
   432 			ASSERT(EFalse); // should not get here if __ECOM_POWERDOWN_WORKAROUND not defined
       
   433 #endif  // defined(__ECOM_POWERDOWN_WORKAROUND)
       
   434 			break;
       
   435 		case EStateOpen:
       
   436 			ASSERT(EFalse); // should not happen
       
   437 			break;
       
   438 		case EStateConverting:
       
   439 			{
       
   440 			TInt error = Parent()->iStatus.Int();
       
   441 
       
   442 			//Add comments
       
   443 			if(error==KErrNone)
       
   444 				TRAP(error,GetCommentL());
       
   445 
       
   446 			iState = EStateOpen; // clear first to allow immediate re-conversion
       
   447 			iPrevConvertUnderflowed = error==KErrUnderflow;
       
   448 			iObserver.MiuoConvertComplete(error);
       
   449 			}
       
   450 			break;
       
   451 		default:
       
   452 			ASSERT(EFalse); // unknown state
       
   453 		}
       
   454 	}
       
   455 
       
   456 void CMdaImageDataReadUtilityPriv::DoCancel()
       
   457 	{
       
   458 	switch (iState)
       
   459 		{
       
   460 		case EStateClosed:
       
   461 			ASSERT(EFalse); // should not happen
       
   462 			break;
       
   463 		case EStateOpening:
       
   464 			// ignore - makes no difference to do something here
       
   465 			break;
       
   466 		case EStateOpeningWait:
       
   467 #if defined(__ECOM_POWERDOWN_WORKAROUND)
       
   468 			iWaitTimer.Cancel();
       
   469 #else
       
   470 			ASSERT(EFalse);
       
   471 #endif  // defined(__ECOM_POWERDOWN_WORKAROUND)
       
   472 			break;
       
   473 		case EStateOpen:
       
   474 			ASSERT(EFalse); // should not happen
       
   475 			break;
       
   476 		case EStateConverting:
       
   477 			{
       
   478 			iDecoder->Cancel(); 
       
   479 			iState = EStateOpen; 
       
   480 			}
       
   481 			break;
       
   482 		default:
       
   483 			ASSERT(EFalse); // unknown state
       
   484 		}
       
   485 	}
       
   486 
       
   487 void CMdaImageDataReadUtilityPriv::DoClose()
       
   488 	{
       
   489 	ASSERT(Parent());
       
   490 	ASSERT(!Parent()->IsActive()); // Cancel should be called by this point
       
   491 	if (iDecoder)
       
   492 		iDecoder->Cancel();
       
   493 	delete iDecoder; iDecoder = NULL;
       
   494 	iComment.ResetAndDestroy();
       
   495 	iPrevConvertUnderflowed = EFalse;
       
   496 	iState = EStateClosed;
       
   497 	}
       
   498 
       
   499 const TDesC& CMdaImageDataReadUtilityPriv::FrameCommentL(TInt aFrameNumber)
       
   500 	{
       
   501 	if (aFrameNumber >= iComment.Count())
       
   502 		User::Leave(KErrArgument);
       
   503 
       
   504 	if (iComment[aFrameNumber])
       
   505 		return *iComment[aFrameNumber];
       
   506 
       
   507 	return KNullDesC;
       
   508 	}
       
   509 
       
   510 void CMdaImageDataReadUtilityPriv::GetCommentL()
       
   511 	{
       
   512 	if(iDecoder->IsImageHeaderProcessingComplete()&&iComment.Count()==0)
       
   513 		{
       
   514 		TInt noOfComments = 0;
       
   515 		TInt commentNo = 0;
       
   516 
       
   517 		const TInt noOfFrames = iDecoder->FrameCount();
       
   518 		for(TInt currentFrame=0; currentFrame<noOfFrames; currentFrame++)
       
   519 			{
       
   520 			HBufC* nullComment = KNullDesC().AllocL();
       
   521 			CleanupStack::PushL(nullComment);
       
   522 			User::LeaveIfError(iComment.Append(nullComment));
       
   523 			CleanupStack::Pop(nullComment);
       
   524 
       
   525 			//Add the general comments if it is the first frame
       
   526 			if(currentFrame==0)
       
   527 				{
       
   528 				noOfComments = iDecoder->NumberOfImageComments();
       
   529 				for(commentNo = 0; commentNo < noOfComments; commentNo++)
       
   530 					{
       
   531 					HBufC* currentComment = iComment[currentFrame];
       
   532 					HBufC* newComment = iDecoder->ImageCommentL(commentNo);
       
   533 					CleanupStack::PushL(newComment);
       
   534 
       
   535 					TInt newLength = currentComment->Length() + newComment->Length();
       
   536 
       
   537 					iComment[currentFrame] = currentComment->ReAllocL(newLength);
       
   538 					iComment[currentFrame]->Des().Append(*newComment);
       
   539 
       
   540 					CleanupStack::PopAndDestroy(newComment);
       
   541 					}
       
   542 				}
       
   543 
       
   544 			//Add the frame comments
       
   545 			noOfComments = iDecoder->NumberOfFrameComments(currentFrame);
       
   546 			for(commentNo = 0; commentNo < noOfComments; commentNo++)
       
   547 				{
       
   548 				HBufC* currentComment = iComment[currentFrame];
       
   549 				HBufC* newComment = iDecoder->FrameCommentL(currentFrame,commentNo);
       
   550 				CleanupStack::PushL(newComment);
       
   551 
       
   552 				TInt newLength = currentComment->Length() + newComment->Length();
       
   553 
       
   554 				iComment[currentFrame] = currentComment->ReAllocL(newLength);
       
   555 				iComment[currentFrame]->Des().Append(*newComment);
       
   556 
       
   557 				CleanupStack::PopAndDestroy(newComment);
       
   558 				}
       
   559 			}
       
   560 		}
       
   561 	}
       
   562 
       
   563 /**
       
   564  *
       
   565  * Retrieves information about the specified frame.
       
   566  *
       
   567  * This function should only be called after an existing image has been
       
   568  * successfully opened or a new image successfully created.
       
   569  *
       
   570  * @param     "TInt aFrame"
       
   571  *            The frame number. This value is relative to zero. The
       
   572  *            value must be less than the total number of frames in
       
   573  *            the image, otherwise the function raises a USER 0
       
   574  *            panic
       
   575  * @param     "TFrameInfo& aInfo"
       
   576  *            Frame information.
       
   577  */
       
   578 void CMdaImageDataReadUtilityPriv::FrameInfo(TInt aFrame,TFrameInfo& aInfo) const
       
   579 	{
       
   580 	__ASSERT_ALWAYS(iDecoder,Panic(EMDAImConvPanicNotYetOpen));
       
   581 	TFrameInfo iclInfo = iDecoder->FrameInfo(aFrame);
       
   582 	aInfo.iFrameCoordsInPixels = iclInfo.iFrameCoordsInPixels;
       
   583 	aInfo.iFrameSizeInTwips = iclInfo.iFrameSizeInTwips;
       
   584 	aInfo.iBitsPerPixel = iclInfo.iBitsPerPixel;
       
   585 	aInfo.iDelay = iclInfo.iDelay;
       
   586 	aInfo.iFlags = iclInfo.iFlags;
       
   587 	aInfo.iOverallSizeInPixels = iclInfo.iOverallSizeInPixels;
       
   588 	}
       
   589 
       
   590 /**
       
   591  *
       
   592  * Returns the number of frames in the image.
       
   593  *
       
   594  * @return   "TInt"
       
   595  *            The number of frames in the image
       
   596  */
       
   597 TInt CMdaImageDataReadUtilityPriv::FrameCount() const
       
   598 	{
       
   599 	__ASSERT_ALWAYS(iDecoder,Panic(EMDAImConvPanicNotYetOpen));
       
   600 	return iDecoder->FrameCount();
       
   601 	}
       
   602 
       
   603 //
       
   604 // CMdaImageDataWriteUtilityPriv
       
   605 //
       
   606 
       
   607 CMdaImageDataWriteUtilityPriv::CMdaImageDataWriteUtilityPriv(MMdaImageUtilObserver& aObserver,
       
   608 															 CMdaImageDataWriteUtility* aParent):
       
   609 	CMdaImageUtilityPriv(aObserver, aParent)
       
   610 	{}
       
   611 
       
   612 CMdaImageDataWriteUtilityPriv::~CMdaImageDataWriteUtilityPriv()
       
   613 	{
       
   614 	Close(ETrue);
       
   615 	ASSERT(iEncoder==NULL); // should have been deleted by Close
       
   616 	ASSERT(iFrameImageData==NULL); // ditto
       
   617 	}
       
   618 
       
   619 void CMdaImageDataWriteUtilityPriv::ConvertL(CFbsBitmap& aBitmap,TInt aFrameNumber)
       
   620 	{
       
   621 	ASSERT(Parent())
       
   622 	if (iState == EStateCancelled) 
       
   623 		{
       
   624 		delete iEncoder;
       
   625 		iEncoder = NULL;
       
   626 
       
   627 		TRAPD(err,DoCreateL(EFalse));
       
   628 
       
   629 		if (err==KErrNone)
       
   630 			iState = EStateOpen;
       
   631 		}
       
   632 
       
   633 	if (iState != EStateOpen)
       
   634 		User::Leave(KErrNotReady);
       
   635 
       
   636 	if (aFrameNumber != 0)
       
   637 		User::Leave(KErrArgument);
       
   638 
       
   639 	ASSERT(iEncoder);
       
   640 
       
   641 	iEncoder->Convert(&Parent()->iStatus, aBitmap, iFrameImageData);
       
   642 
       
   643 	Parent()->SetActive();
       
   644 	iState = EStateConverting;
       
   645 	}
       
   646 
       
   647 void CMdaImageDataWriteUtilityPriv::ConvertL(CFbsBitmap& /*aBitmap*/,const TRect& /*aSourceRect*/,TInt /*aFrameNumber*/)
       
   648 	{
       
   649 	User::Leave(KErrNotSupported);
       
   650 	}
       
   651 
       
   652 void CMdaImageDataWriteUtilityPriv::ConvertL(CFbsBitmap& /*aBitmap*/,CFbsBitmap& /*aMaskBitmap*/,TInt /*aFrameNumber*/)
       
   653 	{
       
   654 	User::Leave(KErrNotSupported);
       
   655 	}
       
   656 
       
   657 void CMdaImageDataWriteUtilityPriv::CancelConvertL()
       
   658 	{
       
   659 	ASSERT(Parent());
       
   660 	Parent()->Cancel();
       
   661 	}
       
   662 
       
   663 void CMdaImageDataWriteUtilityPriv::RunL()
       
   664 	{
       
   665 	ASSERT(Parent());
       
   666 	switch (iState)
       
   667 		{
       
   668 		case EStateClosed:
       
   669 			ASSERT(EFalse); // should not happen
       
   670 			break;
       
   671 		case EStateCreating:
       
   672 			{
       
   673 			TInt error = Parent()->iStatus.Int();
       
   674 			if (error==KErrNone)
       
   675 				TRAP(error, DoCreateL());
       
   676 			if (error==KErrNone)
       
   677 				iState=EStateOpen;
       
   678 			else
       
   679 				iState=EStateClosed;
       
   680 			iObserver.MiuoCreateComplete(error);
       
   681 			}
       
   682 			break;
       
   683 		case EStateOpen:
       
   684 			ASSERT(EFalse); // should not happen
       
   685 			break;
       
   686 		case EStateConverting:
       
   687 			{
       
   688 			TInt error = Parent()->iStatus.Int();
       
   689 			if (error!=KErrNone)
       
   690 				{
       
   691 				iState = EStateOpen; // clear first to allow immediate re-conversion
       
   692 				iObserver.MiuoConvertComplete(error);
       
   693 				}
       
   694 			else
       
   695 				{
       
   696 				iState = EStateCopying;
       
   697 				SelfComplete(KErrNone);
       
   698 				}
       
   699 			}
       
   700 			break;
       
   701 		case EStateCopying:
       
   702 			{
       
   703 			TInt error = KErrNone;
       
   704 			TRAP(error,DoFinalCopyL()); // assumes can't fail
       
   705 			iState = EStateOpen; // even if fail, we go to "open"
       
   706 			iObserver.MiuoConvertComplete(error);
       
   707 			}
       
   708 			break;
       
   709 		case EStateCancelled:
       
   710 			ASSERT(EFalse); // should not get here!
       
   711 			break;
       
   712 		default:
       
   713 			ASSERT(EFalse);
       
   714 		}
       
   715 	}
       
   716 
       
   717 void CMdaImageDataWriteUtilityPriv::DoCancel()
       
   718 	{
       
   719 	switch (iState)
       
   720 		{
       
   721 		case EStateClosed:
       
   722 			ASSERT(EFalse); // should not happen
       
   723 			break;
       
   724 		case EStateCreating:
       
   725 			// ignore - makes no difference to do something here
       
   726 			break;
       
   727 		case EStateOpen:
       
   728 			ASSERT(EFalse); // should not happen
       
   729 			break;
       
   730 		case EStateConverting:
       
   731 			{
       
   732 			iEncoder->Cancel(); 
       
   733 			iState = EStateCancelled;
       
   734 			}
       
   735 			break;
       
   736 		case EStateCopying:
       
   737 			// ignore - makes no difference to do something here
       
   738 			break;
       
   739 		default:
       
   740 			ASSERT(EFalse);
       
   741 		}
       
   742 	}
       
   743 
       
   744 CImageEncoder* CMdaImageDataWriteUtilityPriv::Encoder() const
       
   745 	{
       
   746 	return iEncoder;
       
   747 	}
       
   748 
       
   749 void CMdaImageDataWriteUtilityPriv::DoClose()
       
   750 	{
       
   751 	ASSERT(Parent());
       
   752 	ASSERT(!Parent()->IsActive()); // Cancel should be called by this point
       
   753 	if (iEncoder)
       
   754 		iEncoder->Cancel();
       
   755 	delete iEncoder; iEncoder = NULL;
       
   756 	delete iFrameImageData; iFrameImageData=NULL;
       
   757 	iState=EStateClosed;
       
   758 	}
       
   759 
       
   760 void CMdaImageDataWriteUtilityPriv::DoFinalCopyL()
       
   761 	{
       
   762 	}
       
   763 
       
   764 void CMdaImageDataWriteUtilityPriv::CompleteEncoderCreationL()
       
   765 	{
       
   766 	ASSERT(iEncoder); // should have been created by now
       
   767 	delete iFrameImageData; iFrameImageData=NULL;
       
   768 
       
   769 	if(iFrameData || iImageData)
       
   770 		{
       
   771 		iFrameImageData = CFrameImageData::NewL();
       
   772 		}
       
   773 
       
   774 	if (iFrameData)
       
   775 		{
       
   776 		User::LeaveIfError(iFrameImageData->AppendFrameData(iFrameData));
       
   777 		iFrameData = NULL;
       
   778 		}
       
   779 
       
   780 	if (iImageData)
       
   781 		{
       
   782 		User::LeaveIfError(iFrameImageData->AppendImageData(iImageData));
       
   783 		iImageData = NULL;
       
   784 		}
       
   785 
       
   786 	}
       
   787 
       
   788 //
       
   789 // CMdaImageFileToBitmapUtilityPriv
       
   790 //
       
   791 
       
   792 CMdaImageFileToBitmapUtilityPriv* CMdaImageFileToBitmapUtilityPriv::NewL(MMdaImageUtilObserver& aObserver,
       
   793 																		 CMdaImageFileToBitmapUtility* aParent)
       
   794 	{
       
   795 	CMdaImageFileToBitmapUtilityPriv* self = new(ELeave) CMdaImageFileToBitmapUtilityPriv(aObserver, aParent);
       
   796 	CleanupStack::PushL(self);
       
   797 	self->ConstructL();
       
   798 #if defined(__ECOM_POWERDOWN_WORKAROUND)
       
   799 	self->OpenWaitTimerL();
       
   800 #endif  // defined(__ECOM_POWERDOWN_WORKAROUND)
       
   801 	CleanupStack::Pop(); // self
       
   802 	return self;
       
   803 	}
       
   804 
       
   805 CMdaImageFileToBitmapUtilityPriv::CMdaImageFileToBitmapUtilityPriv(MMdaImageUtilObserver& aObserver,
       
   806 																   CMdaImageFileToBitmapUtility* aParent):
       
   807 	CMdaImageDataReadUtilityPriv(aObserver, aParent)
       
   808 	{
       
   809 	}
       
   810 
       
   811 void CMdaImageFileToBitmapUtilityPriv::ConstructL()
       
   812 	{
       
   813 	Initialize(); 
       
   814 	OpenFsSessionL();
       
   815 	}
       
   816 
       
   817 CMdaImageFileToBitmapUtilityPriv::~CMdaImageFileToBitmapUtilityPriv()
       
   818 	{
       
   819 	delete iFileName;
       
   820 	}
       
   821 
       
   822 void CMdaImageFileToBitmapUtilityPriv::OpenL(const TDesC& aFileName,TMdaClipFormat* aFormat,TMdaPackage* aCodec,TMdaPackage* aExtra)
       
   823 	{
       
   824 	Close(EFalse);
       
   825 	ASSERT(iState == EStateClosed);
       
   826 	delete iFileName; iFileName = NULL;
       
   827 
       
   828 	iState = EStateOpening;
       
   829 
       
   830 	TRAPD(error, iFileName = aFileName.AllocL());
       
   831 	if (error==KErrNone) 
       
   832 		TRAP(error,SetUidsFromOrigFormatsL(aFormat, aCodec, aExtra));
       
   833 
       
   834 	// note handle error on AO to approximate original functionality that did not leave
       
   835 	SelfComplete(error);
       
   836 	}
       
   837 
       
   838 void CMdaImageFileToBitmapUtilityPriv::DoOpenL()
       
   839 	{
       
   840 	ASSERT(iDecoder==NULL); // should have been deleted before this
       
   841 	ASSERT(iFileName); // should already exist
       
   842 	iDecoder=CImageDecoder::FileNewL(iFs, *iFileName, CImageDecoder::EOptionNone, iImageType, iImageSubType);
       
   843 	}
       
   844 
       
   845 
       
   846 //
       
   847 // CMdaImageDescToBitmapUtilityPriv
       
   848 //
       
   849 
       
   850 CMdaImageDescToBitmapUtilityPriv* CMdaImageDescToBitmapUtilityPriv::NewL(MMdaImageUtilObserver& aObserver,
       
   851 																		 CMdaImageDescToBitmapUtility* aParent)
       
   852 	{
       
   853 	CMdaImageDescToBitmapUtilityPriv* self = new(ELeave) CMdaImageDescToBitmapUtilityPriv(aObserver, aParent);
       
   854 	CleanupStack::PushL(self);
       
   855 	self->ConstructL();
       
   856 #if defined(__ECOM_POWERDOWN_WORKAROUND)
       
   857 	self->OpenWaitTimerL();
       
   858 #endif  // defined(__ECOM_POWERDOWN_WORKAROUND)
       
   859 	CleanupStack::Pop(); // self
       
   860 	return self; 
       
   861 	}
       
   862 
       
   863 CMdaImageDescToBitmapUtilityPriv::CMdaImageDescToBitmapUtilityPriv(MMdaImageUtilObserver& aObserver,
       
   864 																   CMdaImageDescToBitmapUtility* aParent):
       
   865 	CMdaImageDataReadUtilityPriv(aObserver, aParent)
       
   866 	{
       
   867 	}
       
   868 
       
   869 void CMdaImageDescToBitmapUtilityPriv::OpenL(const TDesC8& aDescriptor,TMdaClipFormat* aFormat,TMdaPackage* aCodec,TMdaPackage* aExtra)
       
   870 	{
       
   871 	Close(EFalse);
       
   872 	ASSERT(iState == EStateClosed);
       
   873 
       
   874 	iState = EStateOpening;
       
   875 
       
   876 	iDescriptor = &aDescriptor;
       
   877 
       
   878 	TRAPD(error, SetUidsFromOrigFormatsL(aFormat, aCodec, aExtra));
       
   879 
       
   880 	SelfComplete(error);
       
   881 	}
       
   882 
       
   883 void CMdaImageDescToBitmapUtilityPriv::DoOpenL()
       
   884 	{
       
   885 	ASSERT(iDecoder==NULL);
       
   886 	iDecoder=CImageDecoder::DataNewL(iFs, *iDescriptor, CImageDecoder::EOptionNone, iImageType, iImageSubType);
       
   887 	}
       
   888 
       
   889 void CMdaImageDescToBitmapUtilityPriv::ConstructL()
       
   890 	{
       
   891 	Initialize(); 
       
   892 	OpenFsSessionL();
       
   893 	}
       
   894 
       
   895 //
       
   896 // CMdaImageBitmapToFileUtilityPriv
       
   897 //
       
   898 
       
   899 CMdaImageBitmapToFileUtilityPriv* CMdaImageBitmapToFileUtilityPriv::NewL(MMdaImageUtilObserver& aObserver,CMdaImageBitmapToFileUtility* aParent)
       
   900 	{
       
   901 	CMdaImageBitmapToFileUtilityPriv* self = new(ELeave) CMdaImageBitmapToFileUtilityPriv(aObserver, aParent);
       
   902 	CleanupStack::PushL(self);
       
   903 	self->ConstructL();
       
   904 #if defined(__ECOM_POWERDOWN_WORKAROUND)
       
   905 	self->OpenWaitTimerL();
       
   906 #endif  // defined(__ECOM_POWERDOWN_WORKAROUND)
       
   907 	CleanupStack::Pop(); // self
       
   908 	return self;
       
   909 	}
       
   910 
       
   911 CMdaImageBitmapToFileUtilityPriv::CMdaImageBitmapToFileUtilityPriv(MMdaImageUtilObserver& aObserver,
       
   912 																   CMdaImageBitmapToFileUtility* aParent):
       
   913 	CMdaImageDataWriteUtilityPriv(aObserver, aParent)
       
   914 	{
       
   915 	}
       
   916 
       
   917 void CMdaImageBitmapToFileUtilityPriv::ConstructL()
       
   918 	{
       
   919 	Initialize(); 
       
   920 	OpenFsSessionL();
       
   921 	}
       
   922 
       
   923 CMdaImageBitmapToFileUtilityPriv::~CMdaImageBitmapToFileUtilityPriv()
       
   924 	{
       
   925 	delete iFileName;
       
   926 	}
       
   927 
       
   928 void CMdaImageBitmapToFileUtilityPriv::CreateL(const TDesC& aFileName,TMdaClipFormat* aFormat,TMdaPackage* aCodec,TMdaPackage* aExtra)
       
   929 	{
       
   930 	Close(EFalse);
       
   931 	ASSERT(iState == EStateClosed);
       
   932 	delete iFileName; iFileName = NULL;
       
   933 
       
   934 	iState = EStateCreating;
       
   935 
       
   936 	TRAPD(error, iFileName = aFileName.AllocL());
       
   937 
       
   938 	if (error==KErrNone)
       
   939 		TRAP(error,SetUidsFromOrigFormatsL(aFormat, aCodec, aExtra));
       
   940 
       
   941 	SelfComplete (error);
       
   942 	}
       
   943 
       
   944 void CMdaImageBitmapToFileUtilityPriv::DoCreateL(TBool aFullCreate)
       
   945 	{
       
   946 	ASSERT(iEncoder==NULL); // assumed to have been deleted first
       
   947 	ASSERT(iFileName); // should be set by this point
       
   948 	iEncoder = CImageEncoder::FileNewL(iFs, *iFileName, CImageEncoder::EOptionNone, iImageType, iImageSubType);
       
   949 	if (aFullCreate)
       
   950 		CompleteEncoderCreationL();
       
   951 	}
       
   952 
       
   953 //
       
   954 // CMdaImageBitmapToDescUtilityPriv
       
   955 //
       
   956 
       
   957 CMdaImageBitmapToDescUtilityPriv* CMdaImageBitmapToDescUtilityPriv::NewL(MMdaImageUtilObserver& aObserver,
       
   958 																		 CMdaImageBitmapToDescUtility* aParent)
       
   959 	{
       
   960 	CMdaImageBitmapToDescUtilityPriv* self = new(ELeave) CMdaImageBitmapToDescUtilityPriv(aObserver, aParent);
       
   961 	self->Initialize();
       
   962 #if defined(__ECOM_POWERDOWN_WORKAROUND)
       
   963 	CleanupStack::PushL(self);
       
   964 	self->OpenWaitTimerL();
       
   965 	CleanupStack::Pop();
       
   966 #endif  // defined(__ECOM_POWERDOWN_WORKAROUND)
       
   967 	return self;
       
   968 	}
       
   969 
       
   970 CMdaImageBitmapToDescUtilityPriv::CMdaImageBitmapToDescUtilityPriv(MMdaImageUtilObserver& aObserver,
       
   971 																   CMdaImageBitmapToDescUtility* aParent):
       
   972 	CMdaImageDataWriteUtilityPriv(aObserver, aParent)
       
   973 	{
       
   974 	}
       
   975 
       
   976 CMdaImageBitmapToDescUtilityPriv::~CMdaImageBitmapToDescUtilityPriv()
       
   977 	{
       
   978 	Close(ETrue);
       
   979 	delete iSecondBuffer;
       
   980 	}
       
   981 
       
   982 void CMdaImageBitmapToDescUtilityPriv::CreateL(TDes8& aDescriptor,TMdaClipFormat* aFormat,TMdaPackage* aCodec,TMdaPackage* aExtra)
       
   983 	{
       
   984 	Close(EFalse);
       
   985 	ASSERT(iState == EStateClosed);
       
   986 
       
   987 	iState = EStateCreating;
       
   988 
       
   989 	iDescriptor = &aDescriptor;
       
   990 
       
   991 	TRAPD(error, SetUidsFromOrigFormatsL(aFormat, aCodec, aExtra));
       
   992 
       
   993 	SelfComplete (error);
       
   994 	}
       
   995 
       
   996 void CMdaImageBitmapToDescUtilityPriv::DoCreateL(TBool aFullCreate)
       
   997 	{
       
   998 	ASSERT(iEncoder==NULL);
       
   999 	delete iSecondBuffer; iSecondBuffer = NULL; // ensure no previous buffer left around
       
  1000 	iEncoder = CImageEncoder::DataNewL(iSecondBuffer, CImageEncoder::EOptionNone, iImageType, iImageSubType);
       
  1001 	if (aFullCreate)
       
  1002 		CompleteEncoderCreationL();
       
  1003 	}
       
  1004 
       
  1005 void CMdaImageBitmapToDescUtilityPriv::DoFinalCopyL()
       
  1006 	{
       
  1007 	ASSERT(iSecondBuffer!=NULL); // should have been set during conversion
       
  1008 	TInt error = KErrNone;
       
  1009 	if (iDescriptor->MaxLength() < iSecondBuffer->Length())
       
  1010 		error = KErrArgument; // will leave with this
       
  1011 	else
       
  1012 		*iDescriptor = *iSecondBuffer; // safe to copy buffer
       
  1013 	delete iSecondBuffer; iSecondBuffer = NULL; // save space - throw away the buffer we no longer need
       
  1014 	User::LeaveIfError(error);
       
  1015 	}
       
  1016 
       
  1017 // CMdaImageBitmapToBitmapUtilityPriv
       
  1018 
       
  1019 CMdaImageBitmapToBitmapUtilityPriv::CMdaImageBitmapToBitmapUtilityPriv(
       
  1020 									MMdaImageUtilObserver& aObserver, 
       
  1021 									CMdaImageBitmapToBitmapUtility* aParent)
       
  1022 	: CMdaImageUtilityPriv(aObserver, aParent)
       
  1023 	{
       
  1024 	}
       
  1025 
       
  1026 CMdaImageBitmapToBitmapUtilityPriv* CMdaImageBitmapToBitmapUtilityPriv::NewL(MMdaImageUtilObserver& aObserver, CMdaImageBitmapToBitmapUtility* aParent)
       
  1027 	{
       
  1028 	CMdaImageBitmapToBitmapUtilityPriv* self = new(ELeave) CMdaImageBitmapToBitmapUtilityPriv(aObserver, aParent);
       
  1029 	self->Initialize();
       
  1030 	return self;
       
  1031 	}
       
  1032 
       
  1033 CMdaImageBitmapToBitmapUtilityPriv::~CMdaImageBitmapToBitmapUtilityPriv()
       
  1034 	{
       
  1035 	Close();
       
  1036 	delete iBitmapCopier;
       
  1037 	}
       
  1038 
       
  1039 void CMdaImageBitmapToBitmapUtilityPriv::OpenL(CFbsBitmap& aBitmap)
       
  1040 	{
       
  1041 	if (iState != EClosed)
       
  1042 		Close();
       
  1043 
       
  1044 	if (!iBitmapCopier)
       
  1045 		iBitmapCopier = CBitmapConverter::NewL();
       
  1046 
       
  1047 	iSrcBitmap=&aBitmap;
       
  1048 
       
  1049 	iState = EOpening;
       
  1050 	SelfComplete(KErrNone);	//& perform callback
       
  1051 	}
       
  1052 
       
  1053 void CMdaImageBitmapToBitmapUtilityPriv::ConvertL(CFbsBitmap& aBitmap, TInt aFrameNumber)
       
  1054 	{
       
  1055 	if (iState != EReady)
       
  1056 		User::Leave(KErrNotReady);
       
  1057 
       
  1058 	if (aFrameNumber != 0)
       
  1059 		User::Leave(KErrArgument);
       
  1060 
       
  1061 	iBitmapCopier->Convert(&Parent()->iStatus, aBitmap, *iSrcBitmap);
       
  1062 	iState = ECopying;
       
  1063 	Parent()->SetActive();
       
  1064 	}
       
  1065 
       
  1066 void CMdaImageBitmapToBitmapUtilityPriv::ConvertL(CFbsBitmap& /* aBitmap */, CFbsBitmap& /* aMaskBitmap */, TInt /* aFrameNumber = 0 */)
       
  1067 	{
       
  1068 	User::Leave(KErrNotSupported);
       
  1069 	}
       
  1070 
       
  1071 void CMdaImageBitmapToBitmapUtilityPriv::CancelConvertL()
       
  1072 	{
       
  1073 	Parent()->Cancel();
       
  1074 	}
       
  1075 
       
  1076 void CMdaImageBitmapToBitmapUtilityPriv::RunL()
       
  1077 	{
       
  1078 	//Called only on completion of OpenL() or ConvertL()
       
  1079 	TInt errorStatus = Parent()->iStatus.Int();	//should always be KErrNone
       
  1080 	
       
  1081 	switch (iState)
       
  1082 		{
       
  1083 	case EOpening:
       
  1084 		iState = EReady;
       
  1085 		iObserver.MiuoOpenComplete(errorStatus);
       
  1086 		return;
       
  1087 	case ECopying:
       
  1088 		iState = EReady;
       
  1089 		iObserver.MiuoConvertComplete(errorStatus);
       
  1090 		return;
       
  1091 	default:
       
  1092 		User::Invariant();
       
  1093 		}
       
  1094 	}
       
  1095 
       
  1096 void CMdaImageBitmapToBitmapUtilityPriv::DoCancel()
       
  1097 	{
       
  1098 	switch (iState)
       
  1099 		{
       
  1100 	case EReady:
       
  1101 	case EClosed:
       
  1102 		return;
       
  1103 	case EOpening:
       
  1104 		//Message will have already been completed with KErrNone
       
  1105 		// INC037143. This unnecessary Close() call causes infinite 
       
  1106 		// recursion if the utility is cancelled in the EOpening state.
       
  1107 		//Close();
       
  1108 		return;
       
  1109 	case ECopying:
       
  1110 		//Copier will complete our message with KErrCancel
       
  1111 		iBitmapCopier->Cancel();
       
  1112 		return;
       
  1113 	default:
       
  1114 		User::Invariant();
       
  1115 		}
       
  1116 	}
       
  1117 
       
  1118 void CMdaImageBitmapToBitmapUtilityPriv::DoClose()
       
  1119 	{
       
  1120 	if(iState != EClosed)
       
  1121 		{
       
  1122 		iState = EClosed;
       
  1123 		CMdaImageUtilityPriv::DoClose();
       
  1124 		}
       
  1125 	}