Mercurial > s60_experiments
diff DemoCube/src/ImageLoader.cpp @ 1:0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Tue, 12 Feb 2008 17:32:01 -0600 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DemoCube/src/ImageLoader.cpp Tue Feb 12 17:32:01 2008 -0600 @@ -0,0 +1,144 @@ +/*===================================================================== + + Copyright © 2007 Nokia Corporation. All rights reserved. + +======================================================================*/ + +// ImageSaver.cpp: implementation of the CImageLoader class. +// +////////////////////////////////////////////////////////////////////// + +#include <eikenv.h> // for CEikonEnv - "Eikon Environment" +#include <PathInfo.h> +#include <ImageConversion.h> + +#include "ImageLoader.h" + +_LIT8(KMimeType,"image/png"); + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +void CImageLoader::ConstructL() +{ +} + + +CImageLoader* CImageLoader::NewL(TChar tDrive) +{ + CImageLoader* self = new (ELeave) CImageLoader(tDrive); + + CleanupStack::PushL( self ); + self->ConstructL(); + CleanupStack::Pop(); + + return self; +} + + +CImageLoader::CImageLoader(TChar tDrive):CActive( CActive::EPriorityStandard ) +{ + CActiveScheduler::Add( this ); + + pImageDecoder = NULL; + iDrive = tDrive; +} + + +CImageLoader::~CImageLoader() +{ + if (pImageDecoder) + delete pImageDecoder; + pImageDecoder = NULL; + +// delete iImagePath; +} + + +//functions +void CImageLoader::DoCancel() +{ + //in case image saving is cancelled for whatever reason + pImageDecoder->Cancel(); + + DeleteDecoder(); +} + + +void CImageLoader::RunL() +{ + if (iStatus != KErrNone) { + TRequestStatus* s=&iStatus; + User::RequestComplete(s, KErrNone); + + SetActive(); + return; + } + + DeleteDecoder(); +} + + +void CImageLoader::RunError() +{ + RunL(); //cleanup +} + + +void CImageLoader::DeleteDecoder() +{ + if (pImageDecoder) + delete pImageDecoder; + pImageDecoder = NULL; +} + + +void CImageLoader::LoadImage(const TDesC &aFilename, CFbsBitmap *pImg) +{ + RFs fSystem = CEikonEnv::Static()->FsSession(); + +#if defined( __WINS__ ) + _LIT(SpriteFilePath, "%c:\\pictures\\"); // Path for emulator build + iFilename.Format( SpriteFilePath, iDrive ); + iFilename.Append(aFilename); +#else +// _LIT(KFileName, "%c:\\system\\apps\\Track\\"); // Path for HW release + _LIT(SpriteFilePath, "%c:\\"); // Path for HW release + iFilename.Format( SpriteFilePath, (char)iDrive ); + iFilename.Append(aFilename); +#endif + + iNewFileName.Copy(iFilename); + + if (!pImageDecoder) + pImageDecoder = CImageDecoder::FileNewL(fSystem, iNewFileName, KMimeType, CImageDecoder::EOptionAlwaysThread ); + + //if not busy, start to do the conversion + if ( !IsActive() ) { + pImageDecoder->Convert( &iStatus, *pImg ); + SetActive(); + + //loop until the encoding is done + do { +// SleepForSecs(1); + SleepForMicrosecs(1); + } while (iStatus != KErrNone); + } +} + + + +void CImageLoader::SleepForMicrosecs(TInt iMicroSecsToSleep) +{ + TTime tNow; + tNow.HomeTime(); + + TTimeIntervalMicroSeconds tMicroSecsToSleep; + tMicroSecsToSleep = iMicroSecsToSleep; + + //sleep for iMicroSecsToSleep + User::At(tNow + tMicroSecsToSleep); + +} +