examples/Multimedia/ImageConv/src/CImageHandler.cpp

00001 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
00002 // All rights reserved.
00003 // This component and the accompanying materials are made available
00004 // under the terms of "Eclipse Public License v1.0"
00005 // which accompanies this distribution, and is available
00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00007 //
00008 // Initial Contributors:
00009 // Nokia Corporation - initial contribution.
00010 //
00011 // Contributors:
00012 //
00013 // Description:
00014 //
00015 
00016 #include "CImageHandler.h"
00017 
00018 CImageHandler::CImageHandler(CFbsBitmap& aBitmap, RFs& aFs, MImageHandlerCallback& aCallback)
00019         :       CActive(CActive::EPriorityStandard), iBitmap(aBitmap), iFs(aFs), iCallback(aCallback)
00020         {}
00021 
00022 void CImageHandler::ConstructL()
00023         {
00024         iBitmapRotator = CBitmapRotator::NewL();
00025         iBitmapScaler = CBitmapScaler::NewL();
00026         CActiveScheduler::Add(this);
00027         }
00028 
00029 CImageHandler::~CImageHandler()
00030         {
00031         delete iLoadUtil;
00032         delete iSaveUtil;
00033         delete iBitmapRotator;
00034         delete iBitmapScaler;
00035         }
00036 
00037 void CImageHandler::LoadFileL(const TFileName& aFileName, TInt aSelectedFrame)
00038         {
00039         __ASSERT_ALWAYS(!IsActive(),User::Invariant());
00040         // create a CImageDecoder to read the specified file
00041         delete iLoadUtil;
00042         iLoadUtil = NULL;
00043         iLoadUtil = CImageDecoder::FileNewL(iFs, aFileName);
00044         // store the frame information and frame count
00045         iFrameInfo = iLoadUtil->FrameInfo(aSelectedFrame);
00046         iFrameCount = iLoadUtil->FrameCount();
00047         // resize the destination bitmap to fit the required size
00048         TRect bitmapSize = iFrameInfo.iFrameCoordsInPixels;
00049         iBitmap.Resize(bitmapSize.Size());
00050         // start reading the bitmap: RunL called when complete
00051         iLoadUtil->Convert(&iStatus, iBitmap, aSelectedFrame);
00052         SetActive();
00053         }
00054 
00055 void CImageHandler::SaveFileL(const TFileName& aFileName, const TUid& aImageType, const TUid& aImageSubType)
00056         {
00057         __ASSERT_ALWAYS(!IsActive(),User::Invariant());
00058         // create a CImageEncoder to save the bitmap to the specified file in the specified format
00059         delete iSaveUtil;
00060         iSaveUtil = NULL;
00061         iSaveUtil = CImageEncoder::FileNewL(iFs, aFileName, CImageEncoder::EOptionNone, aImageType, aImageSubType);
00062         // start saving the bitmap: RunL called when complete
00063         iSaveUtil->Convert(&iStatus, iBitmap);
00064         SetActive();
00065         }
00066 
00067 void CImageHandler::Mirror()
00068         {
00069         __ASSERT_ALWAYS(!IsActive(),User::Invariant());
00070         // start rotating the bitmap: RunL called when complete
00071         iBitmapRotator->Rotate(&iStatus, iBitmap, CBitmapRotator::EMirrorVerticalAxis);
00072         SetActive();
00073         }
00074 
00075 void CImageHandler::Flip()
00076         {
00077         __ASSERT_ALWAYS(!IsActive(),User::Invariant());
00078         // start rotating the bitmap: RunL called when complete
00079         iBitmapRotator->Rotate(&iStatus, iBitmap, CBitmapRotator::EMirrorHorizontalAxis);
00080         SetActive();
00081         }
00082 
00083 void CImageHandler::FrameRotate(TBool aClockwise)
00084         {
00085         __ASSERT_ALWAYS(!IsActive(),User::Invariant());
00086         // start rotating the bitmap: RunL called when complete
00087         if (aClockwise)
00088                 iBitmapRotator->Rotate(&iStatus, iBitmap, CBitmapRotator::ERotation90DegreesClockwise);
00089         else
00090                 iBitmapRotator->Rotate(&iStatus, iBitmap, CBitmapRotator::ERotation270DegreesClockwise);
00091         SetActive();
00092         }
00093 
00094 void CImageHandler::ZoomFrame(TBool aZoomIn)
00095         {
00096         __ASSERT_ALWAYS(!IsActive(),User::Invariant());
00097         // Determine target zooming size
00098         TSize size(iBitmap.SizeInPixels());
00099         const TSize adjust(size.iWidth/2, size.iHeight/2);
00100         if (aZoomIn)
00101                 size += adjust;
00102         else
00103                 size -= adjust;
00104         // Don't let it go too small
00105         if (size.iWidth <= 10) size.iWidth = 10;
00106         if (size.iHeight <= 10) size.iHeight = 10;
00107 
00108         // start scaling the bitmap: RunL called when complete
00109         iBitmapScaler->Scale(&iStatus, iBitmap, size);
00110         SetActive();
00111         }
00112 
00113 void CImageHandler::RunL()
00114         {
00115         // Operation complete, call back caller
00116         iCallback.ImageOperationCompleteL(iStatus.Int());
00117         }
00118          
00119 void CImageHandler::DoCancel()
00120         {
00121         // Cancel everything possible
00122         if (iLoadUtil) iLoadUtil->Cancel();
00123         if (iSaveUtil) iSaveUtil->Cancel();
00124         iBitmapRotator->Cancel();
00125         iBitmapScaler->Cancel(); 
00126         }

Generated on Thu Jan 21 10:32:59 2010 for TB10.1 Example Applications by  doxygen 1.5.3