lafagnosticuifoundation/animation/src/ICLAnimationDataLoader.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 // Copyright (c) 2004-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 <imageconversion.h>
       
    17 #include <bitmaptransforms.h>
       
    18 #include <fbs.h>
       
    19 #include <e32std.h>
       
    20 #include <ecom/ecom.h>
       
    21 #include <icl/icl_uids.hrh>
       
    22 #include <icl/icl_uids_def.hrh>
       
    23 
       
    24 #include "ICLAnimationDataLoader.h"
       
    25 #include "AnimationFrame.h"
       
    26 
       
    27 EXPORT_C CICLAnimationDataLoader* CICLAnimationDataLoader::NewL(RFs& aFs, MICLAnimationDataLoaderObserver& aCallback)
       
    28 	{
       
    29 	CICLAnimationDataLoader* self = new(ELeave) CICLAnimationDataLoader(aFs, aCallback);
       
    30 	CleanupStack::PushL(self);
       
    31 	self->ConstructL();
       
    32 	CleanupStack::Pop(self);
       
    33 	return self;
       
    34 	}
       
    35 
       
    36 CICLAnimationDataLoader::~CICLAnimationDataLoader()
       
    37 	{
       
    38 	Cancel();
       
    39 	delete iImageDecoder;
       
    40 	}
       
    41 	
       
    42 EXPORT_C void CICLAnimationDataLoader::LoadImageDataL(const TFileName& aFileName)
       
    43 	{
       
    44 	__ASSERT_ALWAYS(!IsActive(),User::Invariant());
       
    45 
       
    46 	delete iImageDecoder;
       
    47 	iImageDecoder = NULL;
       
    48 	
       
    49 	// mng animations need the EOptionMngSubframesNoLoops to behave as other animations (to not repeat unless told)
       
    50 	iImageDecoder = CImageDecoder::FileNewL(iFs, aFileName, CImageDecoder::EOptionMngSubframesNoLoops);	
       
    51 	
       
    52 	iFrameCount = iImageDecoder->FrameCount();
       
    53 	iCurrentFrame = KErrNotFound;
       
    54 	
       
    55 	TUid type; 
       
    56 	TUid subtype; 
       
    57 	iImageDecoder->ImageType(iCurrentFrame+1, type, subtype); 
       
    58 	iIsMngAnimation = (type.iUid==KMngMimeTypeUidValue);
       
    59 	}
       
    60 
       
    61 EXPORT_C TFrameInfo CICLAnimationDataLoader::FrameInfo(const TInt aFrame) const
       
    62 	{
       
    63 	__ASSERT_ALWAYS(iImageDecoder, User::Invariant());
       
    64 	return iImageDecoder->FrameInfo(aFrame);
       
    65 	}
       
    66 
       
    67 /**
       
    68 Not valid for mng animations, for which TFrameInfo::EMngMoreFramesToDecode should be used
       
    69 to find out if there are any more frames to decode.
       
    70 @see CImageDecoder::FrameCount()
       
    71 @see CICLAnimationDataLoader::NextMngOperation()
       
    72 */
       
    73 EXPORT_C TInt CICLAnimationDataLoader::FrameCount() const
       
    74 	{
       
    75 	__ASSERT_ALWAYS(iImageDecoder, User::Invariant());
       
    76 	return iImageDecoder->FrameCount();
       
    77 	}
       
    78 	
       
    79 EXPORT_C TInt CICLAnimationDataLoader::CurrentFrame() const
       
    80 	{
       
    81 	return iCurrentFrame;
       
    82 	}
       
    83 
       
    84 EXPORT_C void CICLAnimationDataLoader::GetNextFrameL(CAnimationFrame* aFrame)
       
    85 	{
       
    86 	__ASSERT_ALWAYS(iImageDecoder, User::Invariant());
       
    87 	__ASSERT_ALWAYS(aFrame, User::Invariant());
       
    88 	
       
    89 	++iCurrentFrame;
       
    90 
       
    91 	const TFrameInfo& frameInfo = iImageDecoder->FrameInfo(iIsMngAnimation ? 0 : iCurrentFrame);
       
    92 	aFrame->CreateL(frameInfo);
       
    93 
       
    94 	if (iIsMngAnimation) 
       
    95 		{
       
    96         iImageDecoder->Convert(&iStatus, *aFrame->Bitmap(), *aFrame->Mask());
       
    97         iOperation = NextMngOperation(iCurrentFrame, frameInfo.iFlags);
       
    98         }
       
    99      else
       
   100      	{
       
   101      	iImageDecoder->Convert(&iStatus, *aFrame->Bitmap(), *aFrame->Mask(), iCurrentFrame);
       
   102      	iOperation = iCurrentFrame < iFrameCount-1 ? 
       
   103      		MICLAnimationDataLoaderObserver::EImagePartialConvert : 
       
   104      		MICLAnimationDataLoaderObserver::EImageConvertComplete;
       
   105      	}
       
   106      	 
       
   107 	SetActive();
       
   108 	}
       
   109 
       
   110 /**
       
   111 To be used to determine if there is more frames to decode in an mng animation.
       
   112 Returns @c EImagePartialConvert if the first frame is still not decoded or if the 
       
   113 @c TFrameInfo::EMngMoreFramesToDecode flag was set when decoding the previous frame.
       
   114 
       
   115 @param aFrame The number of frames already decoded
       
   116 @param aFlags The flags as set during the previous decode operation.
       
   117 @return Next @c TDataLoaderEvent
       
   118 */
       
   119 MICLAnimationDataLoaderObserver::TDataLoaderEvent CICLAnimationDataLoader::NextMngOperation(TInt aFrame, TUint aFlags)
       
   120 	{
       
   121 	return ((0 == aFrame) || (aFlags & TFrameInfo::EMngMoreFramesToDecode)) ? 
       
   122 			MICLAnimationDataLoaderObserver::EImagePartialConvert : 
       
   123         	MICLAnimationDataLoaderObserver::EImageConvertComplete;
       
   124 	}
       
   125 	
       
   126 CICLAnimationDataLoader::CICLAnimationDataLoader(RFs& aFs, MICLAnimationDataLoaderObserver& aCallback)
       
   127 	: CActive(CActive::EPriorityStandard), iFs(aFs), iCallback(aCallback)
       
   128 	{
       
   129 	}
       
   130 	
       
   131 void CICLAnimationDataLoader::ConstructL()
       
   132 	{
       
   133 	CActiveScheduler::Add(this);
       
   134 	}
       
   135 	
       
   136 void CICLAnimationDataLoader::RunL()
       
   137 	{
       
   138 	iCallback.DataLoaderEventL(iOperation, iStatus.Int());
       
   139 	}
       
   140 	
       
   141 void CICLAnimationDataLoader::DoCancel()
       
   142 	{
       
   143 	if(iImageDecoder)
       
   144 		{
       
   145 		iImageDecoder->Cancel();
       
   146 		}	
       
   147 	}
       
   148 
       
   149 TBool CICLAnimationDataLoader::IsMngAnimation()
       
   150 	{
       
   151 	return iIsMngAnimation;
       
   152 	}
       
   153