author | Sebastian Brannstrom <sebastianb@symbian.org> |
Thu, 21 Oct 2010 21:36:03 +0100 | |
branch | 3rded |
changeset 262 | 81bb9210fd4c |
parent 60 | 4d230e702aa3 |
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 |
#ifndef IMAGEHANDLER_H |
|
20 |
#define IMAGEHANDLER_H |
|
21 |
||
22 |
#include <f32file.h> |
|
23 |
#include <ImageConversion.h> |
|
24 |
#include <BitmapTransforms.h> |
|
60 | 25 |
class CPodcastModel; |
2 | 26 |
|
27 |
/** |
|
28 |
* Listener interface that can be used to listen for image loading operation |
|
29 |
* completion events from CImageHandler. |
|
30 |
* |
|
31 |
* The class is intended to be implemented by a client class that observes the |
|
32 |
* loading operation of image handler. The methods in this class |
|
33 |
* are called by the image handler (class CImageHandler) when it loads |
|
34 |
* an image. |
|
35 |
* |
|
36 |
* Reference to implementations of this listener interface can be passed as |
|
37 |
* a parameter to the constructor of the image handler (class CImageHandler). |
|
38 |
*/ |
|
39 |
class MImageHandlerCallback |
|
40 |
{ |
|
41 |
public: |
|
42 |
/** |
|
43 |
* Called by CImageHandler when an image has been loaded. |
|
44 |
* @param aError Error code given by the CImageHandler or 0 (zero) if the |
|
45 |
* image was loaded successfully. |
|
60 | 46 |
* @param image handle |
47 |
* @param reference to podcast model |
|
2 | 48 |
*/ |
60 | 49 |
virtual void ImageOperationCompleteL(TInt aError, TUint aHandle, CPodcastModel& aPodcastModel) = 0; |
2 | 50 |
}; |
51 |
||
52 |
// ============================================================================ |
|
53 |
class TImageStruct |
|
54 |
{ |
|
55 |
public: |
|
56 |
CFbsBitmap* iScaledImage; |
|
57 |
TSize iScaledSize; |
|
58 |
MImageHandlerCallback* iCallBack; |
|
59 |
TFileName iFileName; |
|
32
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
2
diff
changeset
|
60 |
TUint iHandle; |
2 | 61 |
}; |
62 |
/** |
|
63 |
* CImageHandler |
|
64 |
* Image loader and scaler class. |
|
65 |
*/ |
|
66 |
class CImageHandler : public CActive |
|
67 |
{ |
|
68 |
public: // Constructors and destructor |
|
69 |
/** |
|
70 |
* Factory method that constructs a CImageHandler by using the NewLC method |
|
60 | 71 |
* and then cleans the cleanup stack. |
2 | 72 |
* @param aFs File server reference that is used to load the image data. |
60 | 73 |
* @param Reference to podcast model |
2 | 74 |
* when an image has been loaded. |
75 |
* @return pointer to created CImageHandler-object |
|
76 |
*/ |
|
60 | 77 |
IMPORT_C static CImageHandler* NewL(RFs& aFs,CPodcastModel& aPodcastModel); |
2 | 78 |
|
79 |
/** |
|
80 |
* Factory method that constructs a CImageHandler and leaves it to the |
|
81 |
* cleanup stack. |
|
82 |
* @param aFs File server reference that is used to load the image data. |
|
60 | 83 |
* @param Reference to podcast model |
2 | 84 |
* @return pointer to created CImageHandler-object |
85 |
*/ |
|
60 | 86 |
IMPORT_C static CImageHandler* NewLC(RFs& aFs,CPodcastModel& aPodcastModel); |
2 | 87 |
/** |
88 |
* Desctructor. Destroys the CImageDecoder used by the image handler. |
|
89 |
*/ |
|
90 |
IMPORT_C virtual ~CImageHandler(); |
|
91 |
IMPORT_C CFbsBitmap* ScaledBitmap(); |
|
92 |
public: // New functions |
|
93 |
||
94 |
/** |
|
95 |
* Loads a the given frame from the given file and scale it to the |
|
96 |
* specified size |
|
97 |
* @param aFileName Filename wherefrom the bitmap data is loaded. |
|
98 |
* @param aSize the target size for the scaling |
|
99 |
* @param aSelectedFrame A single frame index in a multi-frame file. |
|
100 |
* If not given the first frame is loaded. |
|
101 |
*/ |
|
102 |
IMPORT_C void LoadFileAndScaleL(CFbsBitmap* aScaledBitmap, |
|
103 |
const TFileName& aFileName, |
|
104 |
const TSize &aSize, |
|
105 |
MImageHandlerCallback& aCallback, |
|
32
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
2
diff
changeset
|
106 |
TUint aHandle, |
2 | 107 |
TInt aSelectedFrame = 0); |
108 |
||
109 |
/** |
|
110 |
* Returns the current frame information. |
|
111 |
* @return Current frame information. |
|
112 |
*/ |
|
113 |
const TFrameInfo& FrameInfo() const; |
|
114 |
private: |
|
115 |
/** |
|
116 |
* Loads a the given frame from the given file. |
|
117 |
* @param aFileName Filename wherefrom the bitmap data is loaded. |
|
118 |
* @param aSelectedFrame A single frame index in a multi-frame file. If not given the first frame is loaded. |
|
119 |
*/ |
|
120 |
void LoadFileL(const TFileName& aFileName, TInt aSelectedFrame = 0); |
|
121 |
||
122 |
/** |
|
123 |
* Scales a loaded image |
|
124 |
* Scales a loaded image to the target size (given in LoadFileAndScaleL or |
|
125 |
* FitToScreenL). The scaled image is stored into iScaledBitmap. |
|
126 |
*/ |
|
127 |
void ScaleL(); |
|
128 |
||
129 |
private: // Functions from base classes |
|
130 |
||
131 |
/** |
|
132 |
* CActive::RunL() implementation. Called on image load success/failure. |
|
133 |
*/ |
|
134 |
void RunL(); |
|
135 |
/** |
|
136 |
* CActive::Cancel() implementation. Stops decoding. |
|
137 |
*/ |
|
138 |
void DoCancel(); |
|
139 |
||
140 |
protected: |
|
141 |
/** |
|
142 |
* C++ default constructor. Just stores the given parameters to |
|
60 | 143 |
* corresponding attributes. |
2 | 144 |
* @param aFs File server reference that is used to load the image data. |
60 | 145 |
* @param Reference to podcast model |
2 | 146 |
* when an image has been loaded. |
147 |
*/ |
|
60 | 148 |
CImageHandler(RFs& aFs, CPodcastModel& aPodcastModel); |
2 | 149 |
/** |
150 |
* 2nd phase constructor. Adds this object to the active scheduler. |
|
151 |
*/ |
|
152 |
void ConstructL(); |
|
153 |
||
154 |
private: // Data |
|
155 |
/** Image decoder that is used to load the image data from file. */ |
|
156 |
CImageDecoder *iDecoder; |
|
157 |
||
158 |
/** Image scaler that is used to scale the image */ |
|
159 |
CBitmapScaler *iScaler; |
|
160 |
||
161 |
/** Listener that is notified when an image has been loaded. */ |
|
162 |
MImageHandlerCallback * iCallback; |
|
163 |
||
164 |
/** Bitmap (owned by the user of this class) where the loaded image is put */ |
|
165 |
CFbsBitmap *iBitmap; |
|
166 |
||
167 |
/** Bitmap (owned by the user of this class) where the SCALED image is put */ |
|
168 |
CFbsBitmap *iScaledBitmap; |
|
169 |
||
170 |
/** File server session (owned by the user of this class) */ |
|
171 |
RFs &iFs; |
|
172 |
||
173 |
/** Current image frame information. */ |
|
174 |
TFrameInfo iFrameInfo; |
|
175 |
||
176 |
/** target size for scaled image */ |
|
177 |
TSize iSize; |
|
32
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
2
diff
changeset
|
178 |
RArray<TImageStruct> iCallbackQue; |
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
2
diff
changeset
|
179 |
|
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
2
diff
changeset
|
180 |
/* Handle passed back to caller */ |
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
2
diff
changeset
|
181 |
TUint iHandle; |
60 | 182 |
|
183 |
/** Reference to the podcast model used for callbacks to be able to notify*/ |
|
184 |
CPodcastModel& iPodcastModel; |
|
2 | 185 |
}; |
186 |
||
187 |
#endif |
|
188 |