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