|
1 /* |
|
2 * Copyright (c) 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: Class declaration of CMPXImageUtil. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef MPXIMAGEUTIL_H |
|
20 #define MPXIMAGEUTIL_H |
|
21 |
|
22 // INCLUDES |
|
23 #include <e32base.h> |
|
24 #include <imageconversion.h> |
|
25 |
|
26 // FORWARD DECLARATIONS |
|
27 class CFbsBitmap; |
|
28 class CBitmapScaler; |
|
29 class CImageDecoder; |
|
30 class CImageEncoder; |
|
31 |
|
32 // CLASS DECLARATION |
|
33 |
|
34 /** |
|
35 * Image utilities class. |
|
36 * @lib MPXSQLiteDbCommon.lib |
|
37 **/ |
|
38 NONSHARABLE_CLASS( CMPXImageUtil ) : public CBase |
|
39 { |
|
40 public: // Constructors and destructor |
|
41 /** |
|
42 * Two-phased constructor. |
|
43 * @return A pointer to a newly created object |
|
44 */ |
|
45 static CMPXImageUtil* NewL(); |
|
46 |
|
47 /** |
|
48 * Destructor. |
|
49 */ |
|
50 ~CMPXImageUtil(); |
|
51 |
|
52 public: // New functions |
|
53 |
|
54 /** |
|
55 * Extracts embedded album art field from the media file. |
|
56 * @param aUri file URI |
|
57 * @return embebded JPG album art, ownership transferred. |
|
58 */ |
|
59 HBufC8* ExtractL(const TDesC& aUri); |
|
60 |
|
61 /* |
|
62 * Asynchronously decodes an image from a JPG file. Generates a BMP in memory. |
|
63 * @param aStatus request status |
|
64 * @param aSourceJPGFile Full path and filename of the image to be decoded. |
|
65 * @param aDestBMP Destination bitmap, allocated inside. |
|
66 * @param aSize destination size to be used for calculating the optimal loading size |
|
67 * @param aDisplayMode the display mode of the destination BMP |
|
68 */ |
|
69 void Decode(TRequestStatus& aStatus, const TDesC& aSourceJPGFile, |
|
70 CFbsBitmap& aDestBMP, TSize aSize, TDisplayMode aDisplayMode = EColor64K); |
|
71 |
|
72 /* |
|
73 * Asynchronously decodes an image from JPG buffer. Generates a BMP in memory. |
|
74 * @param aStatus request status |
|
75 * @param aSourceJPG JPG data |
|
76 * @param aDestBMP destination bitmap, created inside. |
|
77 * @param aSize destination size to be used for calculating the optimal loading size |
|
78 * @param aDisplayMode the display mode of the destination BMP |
|
79 */ |
|
80 void Decode(TRequestStatus& aStatus, const TDesC8& aSourceJPG, CFbsBitmap& aDestBMP, |
|
81 TSize aSize, TDisplayMode aDisplayMode = EColor64K); |
|
82 |
|
83 /* |
|
84 * Asynchronously encodes a BMP to a JPG. |
|
85 * @param aStatus request status for ther asynchronous operation |
|
86 * @param aSourceBMP source BMP |
|
87 * @param aDestJPG destination JPG |
|
88 */ |
|
89 void Encode(TRequestStatus& aStatus, const CFbsBitmap& aSourceBMP, |
|
90 HBufC8*& aDestJPG); |
|
91 |
|
92 /* |
|
93 * Asynchronously scales a BMP to a specified size. Generates another |
|
94 * BMP in memory. |
|
95 * @param aStatus request status for ther asynchronous operation |
|
96 * @param aSourceBMP source BMP |
|
97 * @param aDestBMP destination BMP |
|
98 * @param aSize size to scale to |
|
99 * @param aDisplayMode display mode for the destination image |
|
100 */ |
|
101 void Scale(TRequestStatus& aStatus, CFbsBitmap& aSourceBMP, CFbsBitmap& aDestBMP, |
|
102 TSize aSize, TDisplayMode aDisplayMode = EColor64K); |
|
103 |
|
104 /* |
|
105 * Returns a new bitmap object from bitmnap data |
|
106 * @param aBMPData source BMP data |
|
107 * @return new bitmap object. Ownership is transferred. |
|
108 */ |
|
109 CFbsBitmap* BitmapL(const TDesC8& aBMPData); |
|
110 |
|
111 /* |
|
112 * Returns bitmap data from a bitmap object |
|
113 * @param aBMP source BMP |
|
114 * @return bitmap data. Ownership is transferred. |
|
115 */ |
|
116 HBufC8* BitmapDataL(const CFbsBitmap& aBMP); |
|
117 |
|
118 /* |
|
119 * Cancels any outstanding asynchronous request. |
|
120 */ |
|
121 void CancelRequest(); |
|
122 |
|
123 private: // New functions |
|
124 /* |
|
125 * Asynchronously decodes an image from a JPG file - leaving version. |
|
126 * @param aStatus request status |
|
127 * @param aSourceJPGFile Full path and filename of the image to be decoded. |
|
128 * @param aDestBMP Destination bitmap, allocated inside. |
|
129 * @param aSize size that should be considered when loading the image. |
|
130 * Used to determine the optimal loading size. |
|
131 * @param aDisplayMode the display mode of the destination BMP |
|
132 */ |
|
133 void DoDecodeL(TRequestStatus& aStatus, const TDesC& aSourceJPGFile, CFbsBitmap& aDestBMP, |
|
134 TSize aSize, TDisplayMode aDisplayMode = EColor64K); |
|
135 |
|
136 /* |
|
137 * Asynchronously decodes an image from JPG buffer - leaving version. |
|
138 * @param aStatus request status |
|
139 * @param aSourceJPG JPG data |
|
140 * @param aDestBMP destination bitmap, allocated inside. |
|
141 * @param aSize size that should be considered when loading the image. |
|
142 * Used to determine the optimal loading size. |
|
143 * @param aDisplayMode the display mode of the destination BMP |
|
144 */ |
|
145 void DoDecodeL(TRequestStatus& aStatus, const TDesC8& aSourceJPG, CFbsBitmap& aDestBMP, |
|
146 TSize aSize, TDisplayMode aDisplayMode = EColor64K); |
|
147 |
|
148 /* |
|
149 * Asynchronously encodes a BMP to JPG - leaving version. |
|
150 * @param aStatus request status for ther asynchronous operation |
|
151 * @param aSourceBMP source BMP |
|
152 * @param aDestJPG destination JPG |
|
153 */ |
|
154 void DoEncodeL(TRequestStatus& aStatus, const CFbsBitmap& aSourceBMP, |
|
155 HBufC8*& aDestJPG); |
|
156 |
|
157 /* |
|
158 * Asynchronously scales a BMP to a specified size - leaving version. |
|
159 * @param aStatus request status for ther asynchronous operation |
|
160 * @param aSourceBMP source BMP |
|
161 * @param aDestBMP destination BMP |
|
162 * @param aSize size to scale to |
|
163 * @param aDisplayMode display mode for the destination image |
|
164 */ |
|
165 void DoScaleL(TRequestStatus& aStatus, CFbsBitmap& aSourceBMP, |
|
166 CFbsBitmap& aDestBMP, TSize aSize, TDisplayMode aDisplayMode = EColor64K); |
|
167 |
|
168 /** |
|
169 * Gets an optimum loading size for the bitmap. You have a bitmap that has a |
|
170 * size of 640x480. You need to produce a bitmap with size 44x48 calling |
|
171 * this method returns the maximum downscaled size: 80, 60. Using this size |
|
172 * (80x60) you get the fastest loading speed and less usage of memory when |
|
173 * you load the bitmap in memory. This method also handles the needed |
|
174 * rounding if the original size can not be divided evenly! |
|
175 * @param aOriginalSize the size of the unscaled bitmap |
|
176 * @param aNeededSize the needed size |
|
177 * @return the optimal loading size |
|
178 */ |
|
179 TSize OptimalLoadingSize(const TSize& aOriginalSize, const TSize& aNeededSize); |
|
180 |
|
181 /** |
|
182 * Reduce target size to same aspect ratio as source image. |
|
183 * @param aSourceSize source size |
|
184 * @param aTargetSize target size |
|
185 * @return adjusted size |
|
186 */ |
|
187 TSize AdjustSize(const TSize& aSourceSize, const TSize& aTargetSize); |
|
188 |
|
189 private: |
|
190 |
|
191 /** |
|
192 * C++ default constructor. |
|
193 */ |
|
194 CMPXImageUtil(); |
|
195 |
|
196 /** |
|
197 * Second phase constructor. |
|
198 */ |
|
199 void ConstructL(); |
|
200 |
|
201 private: |
|
202 // Internal operation codes |
|
203 enum TOperation |
|
204 { |
|
205 EIdle = 0, |
|
206 EDecoding, |
|
207 EEncoding, |
|
208 EScaling |
|
209 }; |
|
210 |
|
211 private: // Data |
|
212 CImageDecoder* iDecoder; // decoder |
|
213 CBitmapScaler* iScaler; // bitmap scaler |
|
214 CImageEncoder* iEncoder; // encoder |
|
215 RFs iFs; // for opening/saving images from/to files |
|
216 TOperation iOperation; // current operation |
|
217 }; |
|
218 |
|
219 #endif // MPXIMAGEUTIL_H |
|
220 |
|
221 // End of File |