|
1 /* |
|
2 * Copyright (c) 2002-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Phonebook image reader class definition. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef CPBK2IMAGEREADER_H |
|
21 #define CPBK2IMAGEREADER_H |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32base.h> // CBase |
|
25 #include <f32file.h> // RFs |
|
26 #include "TPbk2ImageManagerParams.h" |
|
27 |
|
28 // FORWARD DECLARATIONS |
|
29 class MPbk2ImageReaderObserver; |
|
30 class CImageDecoder; |
|
31 class CBitmapScaler; |
|
32 class TFrameInfo; |
|
33 class CFbsBitmap; |
|
34 |
|
35 // CLASS DECLARATIONS |
|
36 |
|
37 /** |
|
38 * Phonebook image file or buffer -> bitmap reader. |
|
39 */ |
|
40 NONSHARABLE_CLASS(CPbk2ImageReader) : |
|
41 public CActive |
|
42 { |
|
43 public: // interface |
|
44 /** |
|
45 * Creates a new instance of this class. |
|
46 * |
|
47 * @param aObserver observer to notify about progress of this |
|
48 * operation. |
|
49 * @return Image reader |
|
50 */ |
|
51 static CPbk2ImageReader* NewL(MPbk2ImageReaderObserver& aObserver); |
|
52 |
|
53 /** |
|
54 * Destructor. Cancels any executing read operation and destroys this |
|
55 * object. Observer is not notified about the cancellation. |
|
56 */ |
|
57 ~CPbk2ImageReader(); |
|
58 |
|
59 /** |
|
60 * Reads bitmap from file. Cancels any previously executing read |
|
61 * operation. Observer is not notified about the cancellation. |
|
62 * |
|
63 * @param aFileName name of the image file to read |
|
64 * @param aParams optional parameters, @see TPbkImageLoadParameters |
|
65 */ |
|
66 void ReadFromFileL |
|
67 (const TDesC& aFileName, |
|
68 const TPbk2ImageManagerParams* aParams=NULL); |
|
69 |
|
70 /** |
|
71 * Reads bitmap from buffer. Cancels any previously executing read |
|
72 * operation. Observer is not notified about the cancellation. |
|
73 * |
|
74 * @param aBuffer the buffer to read the image from. Caller must keep |
|
75 * the buffer alive as long as this reader is |
|
76 * executing |
|
77 * @param aParams optional parameters, @see TPbkImageLoadParameters |
|
78 */ |
|
79 void ReadFromBufferL |
|
80 (const TDesC8& aBuffer, |
|
81 const TPbk2ImageManagerParams* aParams=NULL); |
|
82 |
|
83 /** |
|
84 * Recognizes image format in a file. |
|
85 * |
|
86 * @param aFileName file to recognize image format from. |
|
87 * @see ImageFormat(). |
|
88 */ |
|
89 void RecognizeFormatFromFileL(const TDesC& aFileName); |
|
90 |
|
91 /** |
|
92 * Recognizes image format in a buffer. |
|
93 * |
|
94 * @param aBuffer buffer to recognize image format from. |
|
95 * @see ImageFormat(). |
|
96 */ |
|
97 void RecognizeFormatFromBufferL(const TDesC8& aBuffer); |
|
98 |
|
99 /** |
|
100 * Returns Mime string of the recognized format. Recognizing |
|
101 * function has to be called before this, otherwise Mime string |
|
102 * is not known and NULL descriptor will be returned. |
|
103 * |
|
104 * @return Mime string of the recognized format. |
|
105 */ |
|
106 const TDesC8& MimeString() const; |
|
107 |
|
108 /** |
|
109 * Returns information about a frame of the image. |
|
110 * Can be called after this object calls ImageOpenComplete to its |
|
111 * observer. |
|
112 * |
|
113 * @param aFrame number of the frame to get inforamtion of. |
|
114 * @param aInfo frame information is written to this parameter. |
|
115 * @precond aFrame>=0 && aFrame<FrameCount() |
|
116 * @see CImageDecoder::FrameInfo |
|
117 */ |
|
118 void FrameInfo(TInt aFrame, TFrameInfo& aInfo) const; |
|
119 |
|
120 /** |
|
121 * Returns the frame count of the image. |
|
122 * Can be called after this object calls ImageOpenComplete to its |
|
123 * observer. |
|
124 * |
|
125 * @return Frame count |
|
126 * @see CImageDecoder::FrameCount |
|
127 */ |
|
128 TInt FrameCount() const; |
|
129 |
|
130 /** |
|
131 * This is overridden from CActive because |
|
132 * observers may be called from RunL. If observers then call |
|
133 * Cancel method, the CActive implementation does not call DoCancel. |
|
134 * However, in this case it has to be called so that resources |
|
135 * are freed immediately in case of Cancel. |
|
136 */ |
|
137 void Cancel(); |
|
138 |
|
139 private: // From CActive |
|
140 void RunL(); |
|
141 TInt RunError(TInt aError); |
|
142 void DoCancel(); |
|
143 |
|
144 private: // implementation |
|
145 CPbk2ImageReader(MPbk2ImageReaderObserver& aObserver); |
|
146 void ConstructL(); |
|
147 void NextStateL(); |
|
148 void ConvertImageToBitmapL(); |
|
149 /* |
|
150 * Crops the image to square if the width is bigger than the height |
|
151 */ |
|
152 void CropImageToSquareL(); |
|
153 void ScaleBitmapL(); |
|
154 void Complete(); |
|
155 void InitReadL(const TPbk2ImageManagerParams* aParams); |
|
156 void CloseImage(); |
|
157 |
|
158 private: // data members |
|
159 /// Ref: observer |
|
160 MPbk2ImageReaderObserver& iObserver; |
|
161 /// Own: currect asynchronous step |
|
162 TInt iState; |
|
163 /// Own: reading parameters |
|
164 TPbk2ImageManagerParams iParams; |
|
165 /// Own: file server session |
|
166 RFs iFsSession; |
|
167 /// Own: image decoder |
|
168 CImageDecoder* iImageDecoder; |
|
169 /// Own: read bitmap |
|
170 CFbsBitmap* iBitmap; |
|
171 /// Own: bitmap scaler |
|
172 CBitmapScaler* iBitmapScaler; |
|
173 /// Own: Mime string of the read image |
|
174 HBufC8* iMimeString; |
|
175 }; |
|
176 |
|
177 #endif // CPBK2IMAGEREADER_H |
|
178 |
|
179 // End of File |