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