1 /* |
|
2 * Copyright (c) 2008-2009 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: Classes for thumbnail-related tasks. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 /** |
|
21 * @internal reviewed 31/07/2007 by Simon Brooks |
|
22 */ |
|
23 |
|
24 #include "glxtnquickthumbnailtask.h" |
|
25 |
|
26 #include <ExifRead.h> |
|
27 #include <glxassert.h> |
|
28 #include <glxtracer.h> |
|
29 #include <imageconversion.h> |
|
30 |
|
31 #include "glxtnfileinfo.h" |
|
32 #include "glxtnfileutility.h" |
|
33 #include "glxtnimagedecoderfactory.h" |
|
34 #include "glxtnthumbnailrequest.h" |
|
35 #include "glxtnvideoutility.h" |
|
36 #include "mglxtnthumbnailcreatorclient.h" |
|
37 |
|
38 |
|
39 // All EXIF data is within the first KGlxMaxExifSize bytes of the file |
|
40 const TInt KGlxMaxExifSize = 0x10000; |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // NewL |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 CGlxtnQuickThumbnailTask* CGlxtnQuickThumbnailTask::NewL( |
|
47 const TGlxThumbnailRequest& aRequestInfo, |
|
48 CGlxtnFileUtility& aFileUtility, MGlxtnThumbnailCreatorClient& aClient) |
|
49 { |
|
50 TRACER("CGlxtnQuickThumbnailTask::NewL()"); |
|
51 CGlxtnQuickThumbnailTask* task = new (ELeave) CGlxtnQuickThumbnailTask( |
|
52 aRequestInfo, aFileUtility, aClient); |
|
53 CleanupStack::PushL(task); |
|
54 task->ConstructL(aRequestInfo.iBitmapHandle); |
|
55 CleanupStack::Pop( task ); |
|
56 return task; |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // Constructor |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 CGlxtnQuickThumbnailTask::CGlxtnQuickThumbnailTask( |
|
64 const TGlxThumbnailRequest& aRequestInfo, |
|
65 CGlxtnFileUtility& aFileUtility, |
|
66 MGlxtnThumbnailCreatorClient& aClient ) : |
|
67 CGlxtnLoadThumbnailTask( KGlxtnTaskIdQuickThumbnail, |
|
68 aRequestInfo, aFileUtility, aClient ), |
|
69 iQuality( EGlxThumbnailQualityLow ) |
|
70 { |
|
71 TRACER("CGlxtnQuickThumbnailTask::CGlxtnQuickThumbnailTask()"); |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // Destructor |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 CGlxtnQuickThumbnailTask::~CGlxtnQuickThumbnailTask() |
|
79 { |
|
80 TRACER("CGlxtnQuickThumbnailTask::~CGlxtnQuickThumbnailTask()"); |
|
81 delete iUtility; |
|
82 delete iVideoFrame; |
|
83 } |
|
84 |
|
85 // ----------------------------------------------------------------------------- |
|
86 // DoStartL |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 TBool CGlxtnQuickThumbnailTask::DoStartL(TRequestStatus& aStatus) |
|
90 { |
|
91 TRACER("TBool CGlxtnQuickThumbnailTask::DoStartL()"); |
|
92 iInfo = new (ELeave) CGlxtnFileInfo; |
|
93 Client().FetchFileInfoL(iInfo, ItemId(), &aStatus); |
|
94 iState = EStateFetchingUri; |
|
95 |
|
96 return ETrue; |
|
97 } |
|
98 |
|
99 // ----------------------------------------------------------------------------- |
|
100 // DoCancel |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 void CGlxtnQuickThumbnailTask::DoCancel() |
|
104 { |
|
105 TRACER("void CGlxtnQuickThumbnailTask::DoCancel()"); |
|
106 CGlxtnLoadThumbnailTask::DoCancel(); |
|
107 |
|
108 if ( EStateFetchingUri == iState ) |
|
109 { |
|
110 Client().CancelFetchUri( ItemId() ); |
|
111 } |
|
112 |
|
113 if ( iUtility ) |
|
114 { |
|
115 iUtility->Cancel(); |
|
116 } |
|
117 |
|
118 iFileUtility.ClearBadFileMarker(); |
|
119 } |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // DoRunL |
|
123 // ----------------------------------------------------------------------------- |
|
124 // |
|
125 TBool CGlxtnQuickThumbnailTask::DoRunL(TRequestStatus& aStatus) |
|
126 { |
|
127 TRACER("TBool CGlxtnQuickThumbnailTask::DoRunL()"); |
|
128 TInt error = aStatus.Int(); |
|
129 TBool active = EFalse; |
|
130 |
|
131 if ( KErrNone == error ) |
|
132 { |
|
133 switch ( iState ) |
|
134 { |
|
135 case EStateFetchingUri: |
|
136 User::LeaveIfNull(iInfo); |
|
137 iBadFileMarkerNotNeededFlag = ETrue; |
|
138 |
|
139 TBool protectedFile; |
|
140 iInfo->IdentifyFileL(iVideo, protectedFile); |
|
141 |
|
142 // leave if file is DRM protected and client has no DRM |
|
143 // capablity |
|
144 if ( protectedFile && !iDrmAllowed ) |
|
145 { |
|
146 User::Leave(KErrAccessDenied); |
|
147 } |
|
148 |
|
149 if ( !LoadThumbnailL( aStatus ) ) |
|
150 { |
|
151 iBadFileMarkerNotNeededFlag = EFalse; |
|
152 iFileUtility.CheckBadFileListL( iInfo->FilePath() ); |
|
153 QuickDecodeL(aStatus); |
|
154 } |
|
155 active = ETrue; |
|
156 break; |
|
157 |
|
158 case EStateLoading: |
|
159 iQuality = EGlxThumbnailQualityHigh; |
|
160 active = HandleLoadedThumbnailL(aStatus); |
|
161 break; |
|
162 |
|
163 case EStateDecodingThumbnail: |
|
164 // Nothing to do |
|
165 break; |
|
166 |
|
167 case EStateDecodingImage: |
|
168 QuickScaleL(); |
|
169 break; |
|
170 |
|
171 default: |
|
172 GLX_ASSERT_ALWAYS( EFalse, Panic( EGlxPanicIllegalState ), |
|
173 "CGlxtnQuickThumbnailTask: Illegal state" ); |
|
174 break; |
|
175 } |
|
176 } |
|
177 else |
|
178 { |
|
179 if ( EStateLoading == iState ) |
|
180 { |
|
181 // Loading failed - generate low quality thumbnail instead |
|
182 iBadFileMarkerNotNeededFlag = EFalse; |
|
183 iFileUtility.CheckBadFileListL( iInfo->FilePath() ); |
|
184 QuickDecodeL(aStatus); |
|
185 active = ETrue; |
|
186 } |
|
187 } |
|
188 |
|
189 if ( !active ) |
|
190 { |
|
191 if ( !iBadFileMarkerNotNeededFlag ) |
|
192 { |
|
193 iFileUtility.ClearBadFileMarker(); |
|
194 } |
|
195 Client().ThumbnailFetchComplete(ItemId(), iQuality, error); |
|
196 } |
|
197 |
|
198 return active; |
|
199 } |
|
200 |
|
201 // ----------------------------------------------------------------------------- |
|
202 // DoRunError |
|
203 // ----------------------------------------------------------------------------- |
|
204 // |
|
205 TBool CGlxtnQuickThumbnailTask::DoRunError(TInt aError) |
|
206 { |
|
207 TRACER("TBool CGlxtnQuickThumbnailTask::DoRunError(TInt aError)"); |
|
208 iFileUtility.ClearBadFileMarker(); |
|
209 Client().ThumbnailFetchComplete(ItemId(), iQuality, aError); |
|
210 |
|
211 return EFalse; |
|
212 } |
|
213 |
|
214 // ----------------------------------------------------------------------------- |
|
215 // QuickDecodeL |
|
216 // ----------------------------------------------------------------------------- |
|
217 // |
|
218 void CGlxtnQuickThumbnailTask::QuickDecodeL(TRequestStatus& aStatus) |
|
219 { |
|
220 TRACER("void CGlxtnQuickThumbnailTask::QuickDecodeL(TRequestStatus& aStatus)"); |
|
221 iQuality = EGlxThumbnailQualityLow; |
|
222 |
|
223 if ( iVideo ) |
|
224 { |
|
225 RArray<TSize> targetSizes; |
|
226 CleanupClosePushL(targetSizes); |
|
227 targetSizes.AppendL( TSize(iRequestedSize) ); |
|
228 iUtility = new (ELeave) CGlxtnVideoUtility; |
|
229 iUtility->GetVideoFrameL(&aStatus, iVideoFrame, iInfo->FilePath(), targetSizes, iThumbnail->DisplayMode() ); |
|
230 iState = EStateDecodingImage; |
|
231 CleanupStack::PopAndDestroy(&targetSizes); |
|
232 } |
|
233 else |
|
234 { |
|
235 ReadThumbnailL(aStatus); |
|
236 } |
|
237 } |
|
238 |
|
239 // ----------------------------------------------------------------------------- |
|
240 // ReadThumbnailL |
|
241 // ----------------------------------------------------------------------------- |
|
242 // |
|
243 void CGlxtnQuickThumbnailTask::ReadThumbnailL(TRequestStatus& aStatus) |
|
244 { |
|
245 TRACER("void CGlxtnQuickThumbnailTask::ReadThumbnailL(TRequestStatus& aStatus)"); |
|
246 TBool scaleBitmap = EFalse; |
|
247 |
|
248 TRAPD(error, ReadExifThumbnailL()); |
|
249 if ( KErrNotFound == error || KErrCorrupt == error |
|
250 || KErrNotSupported == error ) |
|
251 { |
|
252 // Use CImageDecoder to get the EXIF thumbnail instead |
|
253 iDecoder = GlxtnImageDecoderFactory::NewL( |
|
254 iFileUtility.FsSession(), iInfo->FilePath() ); |
|
255 |
|
256 TRAPD( error2, iDecoder->SetImageTypeL( |
|
257 CImageDecoder::EImageTypeThumbnail ) ); |
|
258 if ( KErrNotFound == error2 ) |
|
259 { |
|
260 // No EXIF thumbnail - load whole image and scale quickly |
|
261 scaleBitmap = ETrue; |
|
262 } |
|
263 else |
|
264 { |
|
265 User::LeaveIfError( error2 ); |
|
266 } |
|
267 } |
|
268 else |
|
269 { |
|
270 User::LeaveIfError(error); |
|
271 iDecoder = GlxtnImageDecoderFactory::NewL( |
|
272 iFileUtility.FsSession(), *iThumbData ); |
|
273 } |
|
274 |
|
275 DecodeThumbnailL(aStatus, scaleBitmap); |
|
276 } |
|
277 |
|
278 // ----------------------------------------------------------------------------- |
|
279 // ReadExifThumbnailL |
|
280 // ----------------------------------------------------------------------------- |
|
281 // |
|
282 void CGlxtnQuickThumbnailTask::ReadExifThumbnailL() |
|
283 { |
|
284 TRACER("void CGlxtnQuickThumbnailTask::ReadExifThumbnailL()"); |
|
285 __ASSERT_ALWAYS(iInfo, Panic(EGlxPanicNullPointer)); |
|
286 |
|
287 RFile file; |
|
288 CleanupClosePushL(file); |
|
289 User::LeaveIfError(file.Open(iFileUtility.FsSession(), |
|
290 iInfo->FilePath(), EFileRead)); |
|
291 TInt size; |
|
292 User::LeaveIfError(file.Size(size)); |
|
293 if ( KGlxMaxExifSize < size ) |
|
294 { |
|
295 size = KGlxMaxExifSize; |
|
296 } |
|
297 |
|
298 HBufC8* exifData = HBufC8::NewLC(size); |
|
299 TPtr8 ptr(exifData->Des()); |
|
300 User::LeaveIfError(file.Read(ptr)); |
|
301 |
|
302 CExifRead* exifReader = CExifRead::NewL(*exifData, CExifRead::ENoJpeg); |
|
303 CleanupStack::PushL(exifReader); |
|
304 delete iThumbData; |
|
305 iThumbData = NULL; |
|
306 iThumbData = exifReader->GetThumbnailL(); |
|
307 |
|
308 CleanupStack::PopAndDestroy(exifReader); |
|
309 CleanupStack::PopAndDestroy(exifData); |
|
310 CleanupStack::PopAndDestroy(&file); |
|
311 } |
|
312 |
|
313 // ----------------------------------------------------------------------------- |
|
314 // QuickScaleL |
|
315 // ----------------------------------------------------------------------------- |
|
316 // |
|
317 void CGlxtnQuickThumbnailTask::QuickScaleL() |
|
318 { |
|
319 TRACER("void CGlxtnQuickThumbnailTask::QuickScaleL()"); |
|
320 User::LeaveIfNull(iVideoFrame); |
|
321 |
|
322 TSize frameSize(iVideoFrame->SizeInPixels()); |
|
323 TSize thumbSize(iRequestedSize); |
|
324 |
|
325 // Reduce target thumbSize to same aspect ratio as source image |
|
326 if ( thumbSize.iHeight * frameSize.iWidth < thumbSize.iWidth * frameSize.iHeight ) |
|
327 { |
|
328 // Source has taller aspect than target so reduce target width |
|
329 thumbSize.iWidth = (thumbSize.iHeight * frameSize.iWidth) / frameSize.iHeight; |
|
330 } |
|
331 else |
|
332 { |
|
333 // Source has wider aspect than target so reduce target height |
|
334 thumbSize.iHeight = (thumbSize.iWidth * frameSize.iHeight) / frameSize.iWidth; |
|
335 } |
|
336 |
|
337 // Resize empty bitmap to required size |
|
338 User::LeaveIfError( iThumbnail->Resize( thumbSize ) ); |
|
339 |
|
340 CFbsBitmapDevice* device = CFbsBitmapDevice::NewL( iThumbnail ); |
|
341 CleanupStack::PushL(device); |
|
342 CFbsBitGc* context = NULL; |
|
343 User::LeaveIfError(device->CreateContext(context)); |
|
344 CleanupStack::PushL(context); |
|
345 |
|
346 context->DrawBitmap(TRect(thumbSize), iVideoFrame); |
|
347 |
|
348 CleanupStack::PopAndDestroy(context); |
|
349 CleanupStack::PopAndDestroy(device); |
|
350 } |
|