| author | jakl.martin@cell-telecom.com | 
| Mon, 19 Jul 2010 13:46:06 +0200 | |
| changeset 187 | 45e21fd808cd | 
| parent 93 | bbf5c5204844 | 
| child 228 | c553fa9dcbe5 | 
| permissions | -rw-r--r-- | 
| 2 | 1 | /* | 
| 2 | * Copyright (c) 2007-2010 Sebastian Brannstrom, Lars Persson, EmbedDev AB | |
| 3 | * | |
| 4 | * All rights reserved. | |
| 5 | * This component and the accompanying materials are made available | |
| 6 | * under the terms of the License "Eclipse Public License v1.0" | |
| 7 | * which accompanies this distribution, and is available | |
| 8 | * at the URL "http://www.eclipse.org/legal/epl-v10.html". | |
| 9 | * | |
| 10 | * Initial Contributors: | |
| 11 | * EmbedDev AB - initial contribution. | |
| 12 | * | |
| 13 | * Contributors: | |
| 14 | * Example code from OcrExample Copyright (c) 2006 Nokia Corporation. | |
| 15 | * Description: | |
| 16 | * | |
| 17 | */ | |
| 18 | ||
| 19 | #include "ImageHandler.h" | |
| 32 
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
 teknolog parents: 
2diff
changeset | 20 | #include "debug.h" | 
| 2 | 21 | |
| 22 | // ============================================================================= | |
| 23 | // CImageHandler, a utility class for loading images. | |
| 24 | // ============================================================================= | |
| 25 | ||
| 26 | // ============================= MEMBER FUNCTIONS =============================== | |
| 27 | ||
| 28 | // ----------------------------------------------------------------------------- | |
| 29 | // CImageHandler::CImageHandler | |
| 30 | // C++ constructor can NOT contain any code, that | |
| 31 | // might leave. | |
| 32 | // ----------------------------------------------------------------------------- | |
| 33 | // | |
| 93 
bbf5c5204844
We always build the static version of sqlite for now. Further improvements for signaling when icons has been generated so these can be used in the feedview
 Lars Persson <lars.persson@embeddev.se> parents: 
32diff
changeset | 34 | CImageHandler::CImageHandler( RFs& aFs, CPodcastModel& aPodcastModel ) | 
| 2 | 35 | : CActive(CActive::EPriorityStandard) | 
| 36 | , iDecoder(NULL) | |
| 37 | , iScaler(NULL) | |
| 38 | , iFs(aFs) | |
| 39 | , iSize(0,0) | |
| 93 
bbf5c5204844
We always build the static version of sqlite for now. Further improvements for signaling when icons has been generated so these can be used in the feedview
 Lars Persson <lars.persson@embeddev.se> parents: 
32diff
changeset | 40 | , iPodcastModel(aPodcastModel) | 
| 2 | 41 |     {
 | 
| 42 | } | |
| 43 | ||
| 44 | // ----------------------------------------------------------------------------- | |
| 45 | // CImageHandler::ConstructL | |
| 46 | // Symbian 2nd phase constructor can leave. | |
| 47 | // ----------------------------------------------------------------------------- | |
| 48 | // | |
| 49 | void CImageHandler::ConstructL() | |
| 50 |     {
 | |
| 51 | CActiveScheduler::Add(this); | |
| 52 | iBitmap = new (ELeave) CFbsBitmap; | |
| 53 | } | |
| 54 | ||
| 55 | // ----------------------------------------------------------------------------- | |
| 56 | // CImageHandler::NewLC | |
| 57 | // Two-phased constructor. | |
| 58 | // ----------------------------------------------------------------------------- | |
| 59 | // | |
| 93 
bbf5c5204844
We always build the static version of sqlite for now. Further improvements for signaling when icons has been generated so these can be used in the feedview
 Lars Persson <lars.persson@embeddev.se> parents: 
32diff
changeset | 60 | EXPORT_C CImageHandler* CImageHandler::NewL(RFs& aFs, CPodcastModel& aPodcastModel) | 
| 2 | 61 |     {
 | 
| 93 
bbf5c5204844
We always build the static version of sqlite for now. Further improvements for signaling when icons has been generated so these can be used in the feedview
 Lars Persson <lars.persson@embeddev.se> parents: 
32diff
changeset | 62 | CImageHandler* self = NewLC(aFs, aPodcastModel); | 
| 2 | 63 | CleanupStack::Pop(); | 
| 64 | return self; | |
| 65 | } | |
| 66 | ||
| 67 | // ----------------------------------------------------------------------------- | |
| 68 | // CImageHandler::NewLC | |
| 69 | // Two-phased constructor. | |
| 70 | // ----------------------------------------------------------------------------- | |
| 71 | // | |
| 93 
bbf5c5204844
We always build the static version of sqlite for now. Further improvements for signaling when icons has been generated so these can be used in the feedview
 Lars Persson <lars.persson@embeddev.se> parents: 
32diff
changeset | 72 | EXPORT_C CImageHandler* CImageHandler::NewLC(RFs& aFs, CPodcastModel& aPodcastModel) | 
| 2 | 73 |     {
 | 
| 93 
bbf5c5204844
We always build the static version of sqlite for now. Further improvements for signaling when icons has been generated so these can be used in the feedview
 Lars Persson <lars.persson@embeddev.se> parents: 
32diff
changeset | 74 | CImageHandler* self = new (ELeave) CImageHandler(aFs, aPodcastModel); | 
| 2 | 75 | CleanupStack::PushL( self ); | 
| 76 | self->ConstructL(); | |
| 77 | ||
| 78 | return self; | |
| 79 | } | |
| 80 | ||
| 81 | // Destructor | |
| 82 | EXPORT_C CImageHandler::~CImageHandler() | |
| 83 |     {
 | |
| 84 | // Cancel any outstanding request | |
| 85 | Cancel(); | |
| 86 | Deque(); | |
| 87 | delete iDecoder; | |
| 88 | delete iScaler; | |
| 89 | delete iBitmap; | |
| 90 | iCallbackQue.Close(); | |
| 91 | } | |
| 92 | ||
| 93 | // ----------------------------------------------------------------------------- | |
| 94 | // CImageHandler::LoadFileL | |
| 95 | // Loads a selected frame from a named file | |
| 96 | // ----------------------------------------------------------------------------- | |
| 97 | // | |
| 98 | void CImageHandler::LoadFileL(const TFileName& aFileName, TInt aSelectedFrame) | |
| 99 |     {
 | |
| 100 | __ASSERT_ALWAYS(!IsActive(),User::Invariant()); | |
| 101 | if ( iDecoder ) | |
| 102 |         {
 | |
| 103 | delete iDecoder; | |
| 104 | iDecoder = NULL; | |
| 105 | } | |
| 106 | ||
| 107 | iDecoder = CImageDecoder::FileNewL(iFs, aFileName); | |
| 108 | // Get image information | |
| 109 | iFrameInfo = iDecoder->FrameInfo(aSelectedFrame); | |
| 110 | // Resize to fit. | |
| 111 | TRect bitmap = iFrameInfo.iFrameCoordsInPixels; | |
| 112 | ||
| 113 | // release possible previous image | |
| 114 | iBitmap->Reset(); | |
| 115 | iBitmap->Create(bitmap.Size(), EColor16M); | |
| 116 | ||
| 117 | // Decode as bitmap. | |
| 118 | iDecoder->Convert(&iStatus, *iBitmap, aSelectedFrame); | |
| 119 | SetActive(); | |
| 120 | } | |
| 121 | ||
| 122 | EXPORT_C void CImageHandler::LoadFileAndScaleL(CFbsBitmap* aScaledBitmap, | |
| 123 | const TFileName& aFileName, | |
| 124 | const TSize &aSize, | |
| 125 | MImageHandlerCallback& aCallback, | |
| 32 
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
 teknolog parents: 
2diff
changeset | 126 | TUint aHandle, | 
| 2 | 127 | TInt aSelectedFrame) | 
| 32 
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
 teknolog parents: 
2diff
changeset | 128 |     {
 | 
| 
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
 teknolog parents: 
2diff
changeset | 129 |     DP1("CImageHandler::LoadFileAndScaleL, iCallbackQueue.Count()=%d", iCallbackQue.Count());
 | 
| 
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
 teknolog parents: 
2diff
changeset | 130 | |
| 2 | 131 | if(!IsActive()) | 
| 132 |     	{
 | |
| 133 | __ASSERT_ALWAYS(!IsActive(),User::Invariant()); | |
| 134 | iSize = aSize; | |
| 135 | iScaledBitmap = aScaledBitmap; | |
| 136 | iScaledBitmap->Reset(); | |
| 137 | iScaledBitmap->Create(aSize, EColor16M); | |
| 32 
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
 teknolog parents: 
2diff
changeset | 138 | iCallback = &aCallback; | 
| 
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
 teknolog parents: 
2diff
changeset | 139 | iHandle = aHandle; | 
| 2 | 140 | LoadFileL(aFileName, aSelectedFrame); | 
| 141 | } | |
| 142 | else | |
| 143 |     	{
 | |
| 32 
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
 teknolog parents: 
2diff
changeset | 144 | for (int i=0;i<iCallbackQue.Count();i++) | 
| 
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
 teknolog parents: 
2diff
changeset | 145 |     		{
 | 
| 
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
 teknolog parents: 
2diff
changeset | 146 | if (iCallbackQue[i].iFileName.Compare(aFileName) == 0) | 
| 
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
 teknolog parents: 
2diff
changeset | 147 |     			{
 | 
| 
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
 teknolog parents: 
2diff
changeset | 148 | User::Leave(KErrAlreadyExists); | 
| 
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
 teknolog parents: 
2diff
changeset | 149 | } | 
| 
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
 teknolog parents: 
2diff
changeset | 150 | } | 
| 
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
 teknolog parents: 
2diff
changeset | 151 | |
| 2 | 152 | TImageStruct imageStruct; | 
| 153 | imageStruct.iCallBack = &aCallback; | |
| 154 | imageStruct.iScaledImage = aScaledBitmap; | |
| 155 | imageStruct.iScaledSize = aSize; | |
| 156 | imageStruct.iFileName = aFileName; | |
| 32 
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
 teknolog parents: 
2diff
changeset | 157 | imageStruct.iHandle = aHandle; | 
| 2 | 158 | iCallbackQue.Append(imageStruct); | 
| 159 | } | |
| 160 | } | |
| 161 | ||
| 162 | EXPORT_C CFbsBitmap* CImageHandler::ScaledBitmap() | |
| 163 | 	{
 | |
| 164 | return iScaledBitmap; | |
| 165 | } | |
| 166 | ||
| 167 | void CImageHandler::ScaleL() | |
| 168 |     {
 | |
| 169 | __ASSERT_ALWAYS(!IsActive(),User::Invariant()); | |
| 170 | if ( iScaler ) | |
| 171 |         {
 | |
| 172 | delete iScaler; | |
| 173 | } | |
| 174 | iScaler = NULL; | |
| 175 | iScaler = CBitmapScaler::NewL(); | |
| 176 | iScaler->Scale(&iStatus, *iBitmap, *iScaledBitmap, ETrue); | |
| 177 | SetActive(); | |
| 178 | } | |
| 179 | ||
| 180 | // ----------------------------------------------------------------------------- | |
| 181 | // CImageHandler::FrameInfo | |
| 182 | // Get the current frame information. | |
| 183 | // ----------------------------------------------------------------------------- | |
| 184 | // | |
| 185 | const TFrameInfo& CImageHandler::FrameInfo() const | |
| 186 |     {
 | |
| 187 | return iFrameInfo; | |
| 188 | } | |
| 189 | ||
| 190 | // ----------------------------------------------------------------------------- | |
| 191 | // CImageHandler::RunL | |
| 192 | // CActive::RunL() implementation. Called on image load success/failure. | |
| 193 | // ----------------------------------------------------------------------------- | |
| 194 | // | |
| 195 | void CImageHandler::RunL() | |
| 196 |     {
 | |
| 32 
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
 teknolog parents: 
2diff
changeset | 197 |     DP1("CImageHandler::RunL(), iCallbackQueue.Count()=%d", iCallbackQue.Count());
 | 
| 2 | 198 | if ((! iStatus.Int()) && (iSize.iWidth != 0) && (iSize.iHeight != 0)) | 
| 199 |         {
 | |
| 200 | ScaleL(); | |
| 201 | iSize.SetSize(0,0); | |
| 202 | } | |
| 203 | else | |
| 204 |         {
 | |
| 205 | // Invoke callback. | |
| 93 
bbf5c5204844
We always build the static version of sqlite for now. Further improvements for signaling when icons has been generated so these can be used in the feedview
 Lars Persson <lars.persson@embeddev.se> parents: 
32diff
changeset | 206 | iCallback->ImageOperationCompleteL(iStatus.Int(), iHandle, iPodcastModel); | 
| 2 | 207 | if(iCallbackQue.Count()) | 
| 208 |         	{
 | |
| 209 | TInt loaderror = KErrNotFound; | |
| 210 | while(loaderror != KErrNone && iCallbackQue.Count()) | |
| 211 |         		{
 | |
| 212 | TImageStruct imageStruct= iCallbackQue[0]; | |
| 213 | iCallbackQue.Remove(0); | |
| 32 
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
 teknolog parents: 
2diff
changeset | 214 | TRAP(loaderror, LoadFileAndScaleL(imageStruct.iScaledImage, imageStruct.iFileName, imageStruct.iScaledSize, *imageStruct.iCallBack, imageStruct.iHandle)); | 
| 2 | 215 | } | 
| 216 | } | |
| 217 | } | |
| 218 | ||
| 219 | } | |
| 220 | ||
| 221 | // ----------------------------------------------------------------------------- | |
| 222 | // CImageHandler::DoCancel | |
| 223 | // CActive::Cancel() implementation. Stops decoding. | |
| 224 | // ----------------------------------------------------------------------------- | |
| 225 | // | |
| 226 | void CImageHandler::DoCancel() | |
| 227 |     {
 | |
| 228 | if ( iDecoder ) | |
| 229 |         {
 | |
| 230 | iDecoder->Cancel(); | |
| 231 | } | |
| 232 | if ( iScaler ) | |
| 233 |         {
 | |
| 234 | iScaler->Cancel(); | |
| 235 | } | |
| 236 | } | |
| 237 | ||
| 238 | ||
| 239 |