|
1 /* |
|
2 * Copyright (c) 2006 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: MPX album utility API |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <e32std.h> |
|
19 #include <mpxuser.h> |
|
20 #include <mpxmedia.h> |
|
21 #include <mpxmediamusicdefs.h> |
|
22 #include <mpxmediageneraldefs.h> |
|
23 #include <mpxlog.h> |
|
24 |
|
25 #include "mpximageutil.h" |
|
26 #include "mpximageutilsync.h" |
|
27 #include "mpxalbumartutility.h" |
|
28 |
|
29 // ============================== MEMBER FUNCTIONS ============================ |
|
30 |
|
31 // ---------------------------------------------------------------------------- |
|
32 // Create the playback utility object |
|
33 // ---------------------------------------------------------------------------- |
|
34 // |
|
35 EXPORT_C CMPXAlbumArtUtility* CMPXAlbumArtUtility::NewL() |
|
36 { |
|
37 CMPXAlbumArtUtility* self = new( ELeave )CMPXAlbumArtUtility(); |
|
38 CleanupStack::PushL( self ); |
|
39 self->ConstructL(); |
|
40 CleanupStack::Pop( self ); |
|
41 return self; |
|
42 } |
|
43 |
|
44 // ---------------------------------------------------------------------------- |
|
45 // Destructor |
|
46 // ---------------------------------------------------------------------------- |
|
47 // |
|
48 EXPORT_C CMPXAlbumArtUtility::~CMPXAlbumArtUtility() |
|
49 { |
|
50 delete iImageUtil; |
|
51 delete iImageUtilSync; |
|
52 delete iBitmap; |
|
53 delete iAlbumArt; |
|
54 } |
|
55 |
|
56 // ---------------------------------------------------------------------------- |
|
57 // Constructor |
|
58 // ---------------------------------------------------------------------------- |
|
59 // |
|
60 CMPXAlbumArtUtility::CMPXAlbumArtUtility() : |
|
61 CActive( EPriorityStandard ) |
|
62 { |
|
63 CActiveScheduler::Add( this ); |
|
64 } |
|
65 |
|
66 // ---------------------------------------------------------------------------- |
|
67 // Constructor |
|
68 // ---------------------------------------------------------------------------- |
|
69 // |
|
70 void CMPXAlbumArtUtility::ConstructL() |
|
71 { |
|
72 iImageUtil = CMPXImageUtil::NewL(); |
|
73 iImageUtilSync = CMPXImageUtilSync::NewL(); |
|
74 iBitmap = new ( ELeave ) CFbsBitmap(); |
|
75 } |
|
76 |
|
77 // ---------------------------------------------------------------------------- |
|
78 // Create the playback utility object |
|
79 // ---------------------------------------------------------------------------- |
|
80 // |
|
81 EXPORT_C void CMPXAlbumArtUtility::ExtractAlbumArtL(const CMPXMedia& aMedia, |
|
82 MMPXAlbumArtUtilityObserver& aObs, |
|
83 const TSize& aSize, |
|
84 TDisplayMode aDisplayMode /*= EColor64K*/) |
|
85 { |
|
86 MPX_FUNC_EX( "CMPXAlbumArtUtility::ExtractAlbumArtL" ); |
|
87 |
|
88 if ( iCurrentOp != EIdle ) |
|
89 { |
|
90 User::Leave( KErrNotReady ); |
|
91 } |
|
92 |
|
93 if ( aMedia.IsSupported( KMPXMediaMusicAlbumArtFileName ) ) |
|
94 { |
|
95 if ( aMedia.ValueText( KMPXMediaMusicAlbumArtFileName ).Length() == 0) |
|
96 { |
|
97 User::Leave( KErrNotFound ); |
|
98 } |
|
99 } |
|
100 |
|
101 if ( aMedia.IsSupported( KMPXMediaGeneralUri ) && |
|
102 aMedia.IsSupported( KMPXMediaMusicAlbumArtFileName )) |
|
103 { |
|
104 if ( aMedia.ValueText( KMPXMediaGeneralUri ).CompareF( |
|
105 aMedia.ValueText( KMPXMediaMusicAlbumArtFileName ) ) == 0 ) |
|
106 { // embedded album art |
|
107 iObs = &aObs; |
|
108 delete iAlbumArt; |
|
109 iAlbumArt = NULL; |
|
110 iAlbumArt = iImageUtil->ExtractL( aMedia.ValueText( KMPXMediaMusicAlbumArtFileName ) ); |
|
111 if ( iAlbumArt ) |
|
112 { |
|
113 iCurrentOp = EExtractAlbumArtL; |
|
114 iObs->ExtractAlbumArtStarted(); |
|
115 SetActive(); |
|
116 iImageUtil->Decode( iStatus, *iAlbumArt, *iBitmap, aSize, aDisplayMode ); |
|
117 } |
|
118 else |
|
119 { |
|
120 User::Leave( KErrUnderflow ); |
|
121 } |
|
122 } |
|
123 else |
|
124 { |
|
125 iCurrentOp = EExtractAlbumArtL; |
|
126 // TO-DO: if we save externalize bitmap, we only need to internalize bitmap here. |
|
127 iObs->ExtractAlbumArtStarted(); |
|
128 SetActive(); |
|
129 iImageUtil->Decode( iStatus, aMedia.ValueText( |
|
130 KMPXMediaMusicAlbumArtFileName ), *iBitmap, aSize, aDisplayMode ); |
|
131 } |
|
132 } |
|
133 else |
|
134 { |
|
135 User::Leave( KErrNotFound ); |
|
136 } |
|
137 } |
|
138 |
|
139 // ----------------------------------------------------------------------------- |
|
140 // Asynchronously decodes an image from a JPG file. Generates a BMP in memory. |
|
141 // ----------------------------------------------------------------------------- |
|
142 // |
|
143 EXPORT_C void CMPXAlbumArtUtility::Decode( |
|
144 TRequestStatus& aStatus, const TDesC& aSourceJPGFile, |
|
145 CFbsBitmap& aDestBMP, TSize aSize, TDisplayMode aDisplayMode ) |
|
146 { |
|
147 MPX_FUNC_EX( "CMPXAlbumArtUtility::Decode Async File" ); |
|
148 iImageUtil->Decode( aStatus, aSourceJPGFile, aDestBMP, aSize, aDisplayMode ); |
|
149 } |
|
150 |
|
151 // ----------------------------------------------------------------------------- |
|
152 // Asynchronously decodes an image from JPG buffer. Generates a BMP in memory. |
|
153 // ----------------------------------------------------------------------------- |
|
154 // |
|
155 EXPORT_C void CMPXAlbumArtUtility::Decode( |
|
156 TRequestStatus& aStatus, const TDesC8& aSourceJPG, |
|
157 CFbsBitmap& aDestBMP, TSize aSize, TDisplayMode aDisplayMode ) |
|
158 { |
|
159 MPX_FUNC_EX( "CMPXAlbumArtUtility::Decode Async Buffer" ); |
|
160 iImageUtil->Decode( aStatus, aSourceJPG, aDestBMP, aSize, aDisplayMode ); |
|
161 } |
|
162 |
|
163 // ----------------------------------------------------------------------------- |
|
164 // Asynchronously encodes a BMP to a JPG. |
|
165 // ----------------------------------------------------------------------------- |
|
166 // |
|
167 EXPORT_C void CMPXAlbumArtUtility::Encode( |
|
168 TRequestStatus& aStatus, const CFbsBitmap& aSourceBMP, |
|
169 HBufC8*& aDestJPG ) |
|
170 { |
|
171 MPX_FUNC_EX( "CMPXAlbumArtUtility::Encode Async" ); |
|
172 iImageUtil->Encode( aStatus, aSourceBMP, aDestJPG ); |
|
173 } |
|
174 |
|
175 // ----------------------------------------------------------------------------- |
|
176 // Asynchronously scales a BMP to a specified size. Generates another |
|
177 // ----------------------------------------------------------------------------- |
|
178 // |
|
179 EXPORT_C void CMPXAlbumArtUtility::Scale( |
|
180 TRequestStatus& aStatus, CFbsBitmap& aSourceBMP, CFbsBitmap& aDestBMP, |
|
181 TSize aSize, TDisplayMode aDisplayMode ) |
|
182 { |
|
183 MPX_FUNC_EX( "CMPXAlbumArtUtility::Scale Async" ); |
|
184 iImageUtil->Scale( aStatus, aSourceBMP, aDestBMP, aSize, aDisplayMode ); |
|
185 } |
|
186 |
|
187 // ----------------------------------------------------------------------------- |
|
188 // Synchronously decodes an image from a JPG file. |
|
189 // ----------------------------------------------------------------------------- |
|
190 // |
|
191 EXPORT_C CFbsBitmap* CMPXAlbumArtUtility::DecodeL( |
|
192 const TDesC& aSourceJPGFile, TSize aSize, TDisplayMode aDisplayMode ) |
|
193 { |
|
194 MPX_FUNC_EX( "CMPXAlbumArtUtility::DecodeL Sync File" ); |
|
195 return iImageUtilSync->DecodeL( aSourceJPGFile, aSize, aDisplayMode ); |
|
196 } |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // Synchronously converts a JPG buffer to an CFbsBitmap. |
|
200 // ----------------------------------------------------------------------------- |
|
201 // |
|
202 EXPORT_C CFbsBitmap* CMPXAlbumArtUtility::DecodeL( |
|
203 const TDesC8& aSourceJPG, TSize aSize, TDisplayMode aDisplayMode ) |
|
204 { |
|
205 MPX_FUNC_EX( "CMPXAlbumArtUtility::DecodeL Sync Buffer" ); |
|
206 return iImageUtilSync->DecodeL( aSourceJPG, aSize, aDisplayMode ); |
|
207 } |
|
208 |
|
209 // ----------------------------------------------------------------------------- |
|
210 // Synchronously encodes a BMP to JPG. |
|
211 // ----------------------------------------------------------------------------- |
|
212 // |
|
213 EXPORT_C HBufC8* CMPXAlbumArtUtility::EncodeL( const CFbsBitmap& aSourceBMP ) |
|
214 { |
|
215 MPX_FUNC_EX( "CMPXAlbumArtUtility::EncodeL Sync" ); |
|
216 return iImageUtilSync->EncodeL( aSourceBMP ); |
|
217 } |
|
218 |
|
219 // ----------------------------------------------------------------------------- |
|
220 // Synchronously scales a BMP to a specified size |
|
221 // ----------------------------------------------------------------------------- |
|
222 // |
|
223 EXPORT_C CFbsBitmap* CMPXAlbumArtUtility::ScaleL( |
|
224 CFbsBitmap& aSourceBMP, TSize aSize, TDisplayMode aDisplayMode ) |
|
225 { |
|
226 MPX_FUNC_EX( "CMPXAlbumArtUtility::ScaleL Sync" ); |
|
227 return iImageUtilSync->ScaleL( aSourceBMP, aSize, aDisplayMode ); |
|
228 } |
|
229 |
|
230 // ----------------------------------------------------------------------------- |
|
231 // Extracts embedded album art field from the media file. |
|
232 // ----------------------------------------------------------------------------- |
|
233 // |
|
234 EXPORT_C HBufC8* CMPXAlbumArtUtility::ExtractL( const TDesC& aUri ) |
|
235 { |
|
236 MPX_FUNC_EX( "CMPXAlbumArtUtility::ExtractL Sync" ); |
|
237 return iImageUtil->ExtractL( aUri ); |
|
238 } |
|
239 |
|
240 // ----------------------------------------------------------------------------- |
|
241 // Returns a new bitmap object from bitmnap data |
|
242 // ----------------------------------------------------------------------------- |
|
243 // |
|
244 EXPORT_C CFbsBitmap* CMPXAlbumArtUtility::BitmapL( const TDesC8& aBMPData ) |
|
245 { |
|
246 MPX_FUNC_EX( "CMPXAlbumArtUtility::BitmapL Sync" ); |
|
247 return iImageUtil->BitmapL( aBMPData ); |
|
248 } |
|
249 |
|
250 // ----------------------------------------------------------------------------- |
|
251 // Returns bitmap data from a bitmap object |
|
252 // ----------------------------------------------------------------------------- |
|
253 // |
|
254 EXPORT_C HBufC8* CMPXAlbumArtUtility::BitmapDataL( const CFbsBitmap& aBMP ) |
|
255 { |
|
256 MPX_FUNC_EX( "CMPXAlbumArtUtility::BitmapDataL Sync" ); |
|
257 return iImageUtil->BitmapDataL( aBMP ); |
|
258 } |
|
259 |
|
260 // ----------------------------------------------------------------------------- |
|
261 // Cancel Asynch requests |
|
262 // ----------------------------------------------------------------------------- |
|
263 // |
|
264 EXPORT_C void CMPXAlbumArtUtility::CancelRequest() |
|
265 { |
|
266 MPX_FUNC_EX( "CMPXAlbumArtUtility::CancelRequest" ); |
|
267 if ( iImageUtil ) |
|
268 { |
|
269 iImageUtil->CancelRequest(); |
|
270 } |
|
271 } |
|
272 |
|
273 // ----------------------------------------------------------------------------- |
|
274 // CMPXImageUtilSync::DoCancel |
|
275 // ----------------------------------------------------------------------------- |
|
276 // |
|
277 void CMPXAlbumArtUtility::DoCancel() |
|
278 { |
|
279 MPX_FUNC( "CMPXAlbumArtUtility::DoCancel" ); |
|
280 } |
|
281 |
|
282 // ----------------------------------------------------------------------------- |
|
283 // CMPXImageUtilSync::RunL |
|
284 // ----------------------------------------------------------------------------- |
|
285 // |
|
286 void CMPXAlbumArtUtility::RunL() |
|
287 { |
|
288 MPX_FUNC( "CMPXAlbumArtUtility::RunL" ); |
|
289 switch ( iCurrentOp ) |
|
290 { |
|
291 case EExtractAlbumArtL: |
|
292 { |
|
293 iCurrentOp = EIdle; |
|
294 iObs->ExtractAlbumArtCompleted( iBitmap, KErrNone ); |
|
295 delete iAlbumArt; |
|
296 iAlbumArt = NULL; |
|
297 iBitmap = NULL; // ownership transfered |
|
298 iBitmap = new ( ELeave ) CFbsBitmap(); |
|
299 break; |
|
300 } |
|
301 default: |
|
302 { |
|
303 break; |
|
304 } |
|
305 } |
|
306 } |
|
307 |
|
308 // ----------------------------------------------------------------------------- |
|
309 // CMPXImageUtilSync::RunError |
|
310 // ----------------------------------------------------------------------------- |
|
311 // |
|
312 TInt CMPXAlbumArtUtility::RunError( TInt /*aError*/ ) |
|
313 { |
|
314 MPX_FUNC( "CMPXAlbumArtUtility::RunError" ); |
|
315 return KErrNone; |
|
316 } |
|
317 |
|
318 |
|
319 // End of file |