|
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 */ |
|
46 virtual void ImageOperationCompleteL(TInt aError) = 0; |
|
47 }; |
|
48 |
|
49 // ============================================================================ |
|
50 class TImageStruct |
|
51 { |
|
52 public: |
|
53 CFbsBitmap* iScaledImage; |
|
54 TSize iScaledSize; |
|
55 MImageHandlerCallback* iCallBack; |
|
56 TFileName iFileName; |
|
57 }; |
|
58 /** |
|
59 * CImageHandler |
|
60 * Image loader and scaler class. |
|
61 */ |
|
62 class CImageHandler : public CActive |
|
63 { |
|
64 public: // Constructors and destructor |
|
65 /** |
|
66 * Factory method that constructs a CImageHandler by using the NewLC method |
|
67 * and then cleans the cleanup stack. |
|
68 * @param aBitmap Bitmap where the image data is loaded to. |
|
69 * @param aScaledBitmap Bitmap where the scaled image data is loaded to. |
|
70 * @param aFs File server reference that is used to load the image data. |
|
71 * @param aCallback Listener interface implementation that is notified |
|
72 * when an image has been loaded. |
|
73 * @return pointer to created CImageHandler-object |
|
74 */ |
|
75 IMPORT_C static CImageHandler* NewL(RFs& aFs); |
|
76 |
|
77 /** |
|
78 * Factory method that constructs a CImageHandler and leaves it to the |
|
79 * cleanup stack. |
|
80 * @param aBitmap Bitmap where the image data is loaded to. |
|
81 * @param aScaledBitmap Bitmap where the scaled image data is loaded to. |
|
82 * @param aFs File server reference that is used to load the image data. |
|
83 * @param aCallback Listener interface implementation that is notified |
|
84 * when an image has been loaded. |
|
85 * @return pointer to created CImageHandler-object |
|
86 */ |
|
87 IMPORT_C static CImageHandler* NewLC(RFs& aFs); |
|
88 /** |
|
89 * Desctructor. Destroys the CImageDecoder used by the image handler. |
|
90 */ |
|
91 IMPORT_C virtual ~CImageHandler(); |
|
92 IMPORT_C CFbsBitmap* ScaledBitmap(); |
|
93 public: // New functions |
|
94 |
|
95 /** |
|
96 * Loads a the given frame from the given file and scale it to the |
|
97 * specified size |
|
98 * @param aFileName Filename wherefrom the bitmap data is loaded. |
|
99 * @param aSize the target size for the scaling |
|
100 * @param aSelectedFrame A single frame index in a multi-frame file. |
|
101 * If not given the first frame is loaded. |
|
102 */ |
|
103 IMPORT_C void LoadFileAndScaleL(CFbsBitmap* aScaledBitmap, |
|
104 const TFileName& aFileName, |
|
105 const TSize &aSize, |
|
106 MImageHandlerCallback& aCallback, |
|
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 |
|
143 * corresponding attributes. |
|
144 * @param aScaledBitmap Bitmap where the scaled image data is loaded to. |
|
145 * @param aFs File server reference that is used to load the image data. |
|
146 * @param aCallback Listener interface implementation that is notified |
|
147 * when an image has been loaded. |
|
148 */ |
|
149 CImageHandler(RFs& aFs); |
|
150 /** |
|
151 * 2nd phase constructor. Adds this object to the active scheduler. |
|
152 */ |
|
153 void ConstructL(); |
|
154 |
|
155 private: // Data |
|
156 /** Image decoder that is used to load the image data from file. */ |
|
157 CImageDecoder *iDecoder; |
|
158 |
|
159 /** Image scaler that is used to scale the image */ |
|
160 CBitmapScaler *iScaler; |
|
161 |
|
162 /** Listener that is notified when an image has been loaded. */ |
|
163 MImageHandlerCallback * iCallback; |
|
164 |
|
165 /** Bitmap (owned by the user of this class) where the loaded image is put */ |
|
166 CFbsBitmap *iBitmap; |
|
167 |
|
168 /** Bitmap (owned by the user of this class) where the SCALED image is put */ |
|
169 CFbsBitmap *iScaledBitmap; |
|
170 |
|
171 /** File server session (owned by the user of this class) */ |
|
172 RFs &iFs; |
|
173 |
|
174 /** Current image frame information. */ |
|
175 TFrameInfo iFrameInfo; |
|
176 |
|
177 /** target size for scaled image */ |
|
178 TSize iSize; |
|
179 RArray<TImageStruct> iCallbackQue; |
|
180 }; |
|
181 |
|
182 #endif |
|
183 |