|
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: Base class for tasks which load thumbnails |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include "glxtnloadthumbnailtask.h" |
|
22 |
|
23 #include <glxassert.h> |
|
24 #include <glxtracer.h> |
|
25 #include <glxlog.h> |
|
26 #include <glxthumbnail.h> |
|
27 #include <imageconversion.h> |
|
28 #include <s32mem.h> |
|
29 |
|
30 #include "glxtnfileinfo.h" |
|
31 #include "glxtnfileutility.h" |
|
32 #include "glxtnimagedecoderfactory.h" |
|
33 #include "glxtnthumbnailrequest.h" |
|
34 #include "mglxtnstorage.h" |
|
35 |
|
36 |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // Constructor |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 CGlxtnLoadThumbnailTask::CGlxtnLoadThumbnailTask( const TGlxtnTaskId& aId, |
|
43 const TGlxThumbnailRequest& aRequestInfo, |
|
44 CGlxtnFileUtility& aFileUtility, |
|
45 MGlxtnThumbnailCreatorClient& aClient) : |
|
46 CGlxtnClientTask( aId, aRequestInfo.iId, aClient ), |
|
47 iFileUtility( aFileUtility ), iRequestedSize( aRequestInfo.iSizeClass ), |
|
48 iDrmAllowed( aRequestInfo.iDrmAllowed ) |
|
49 { |
|
50 TRACER("CGlxtnLoadThumbnailTask::CGlxtnLoadThumbnailTask()"); |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // Destructor |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 CGlxtnLoadThumbnailTask::~CGlxtnLoadThumbnailTask() |
|
58 { |
|
59 TRACER("CGlxtnLoadThumbnailTask::~CGlxtnLoadThumbnailTask()"); |
|
60 delete iDecoder; |
|
61 delete iThumbnail; |
|
62 delete iThumbData; |
|
63 delete iInfo; |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // ConstructL |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 void CGlxtnLoadThumbnailTask::ConstructL( TInt aBitmapHandle ) |
|
71 { |
|
72 TRACER("void CGlxtnLoadThumbnailTask::ConstructL()"); |
|
73 // Duplicate the client's bitmap |
|
74 iThumbnail = new (ELeave) CFbsBitmap(); |
|
75 User::LeaveIfError( iThumbnail->Duplicate( aBitmapHandle ) ); |
|
76 } |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // DoCancel |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 void CGlxtnLoadThumbnailTask::DoCancel() |
|
83 { |
|
84 TRACER("void CGlxtnLoadThumbnailTask::DoCancel()"); |
|
85 if ( iDecoder ) |
|
86 { |
|
87 iDecoder->Cancel(); |
|
88 } |
|
89 |
|
90 Storage()->StorageCancel(); |
|
91 } |
|
92 |
|
93 // --------------------------------------------------------------------------- |
|
94 // LoadThumbnailL |
|
95 // --------------------------------------------------------------------------- |
|
96 // |
|
97 TBool CGlxtnLoadThumbnailTask::LoadThumbnailL( TRequestStatus& aStatus ) |
|
98 { |
|
99 TRACER("TBool CGlxtnLoadThumbnailTask::LoadThumbnailL()"); |
|
100 GLX_ASSERT_DEBUG( iInfo, Panic( EGlxPanicNullPointer ), "No file info" ); |
|
101 |
|
102 if ( Storage() && iFileUtility.IsPersistentSize( iRequestedSize ) ) |
|
103 { |
|
104 Storage()->LoadThumbnailDataL( iThumbData, iFormat, ItemId(), |
|
105 *iInfo, iRequestedSize, &aStatus ); |
|
106 iState = EStateLoading; |
|
107 |
|
108 return ETrue; |
|
109 } |
|
110 |
|
111 return EFalse; |
|
112 } |
|
113 |
|
114 // --------------------------------------------------------------------------- |
|
115 // HandleLoadedThumbnailL |
|
116 // --------------------------------------------------------------------------- |
|
117 // |
|
118 TBool CGlxtnLoadThumbnailTask::HandleLoadedThumbnailL(TRequestStatus& aStatus) |
|
119 { |
|
120 TRACER("CGlxtnLoadThumbnailTask::HandleLoadedThumbnailL()"); |
|
121 TBool active = EFalse; |
|
122 |
|
123 User::LeaveIfNull( iThumbData ); |
|
124 |
|
125 switch ( iFormat ) |
|
126 { |
|
127 case EGlxIDF_Bitmap: |
|
128 { |
|
129 CFbsBitmap* bitmap = new (ELeave) CFbsBitmap; |
|
130 CleanupStack::PushL( bitmap ); |
|
131 |
|
132 RDesReadStream stream( *iThumbData ); |
|
133 CleanupClosePushL( stream ); |
|
134 stream >> *bitmap; |
|
135 CleanupStack::PopAndDestroy( &stream ); |
|
136 |
|
137 User::LeaveIfError( iThumbnail->Resize( bitmap->SizeInPixels() ) ); |
|
138 |
|
139 CFbsBitmapDevice* device = CFbsBitmapDevice::NewL( iThumbnail ); |
|
140 CleanupStack::PushL( device ); |
|
141 CFbsBitGc* context = NULL; |
|
142 User::LeaveIfError( device->CreateContext( context ) ); |
|
143 CleanupStack::PushL( context ); |
|
144 |
|
145 context->BitBlt( TPoint(), bitmap ); |
|
146 |
|
147 CleanupStack::PopAndDestroy( context ); |
|
148 CleanupStack::PopAndDestroy( device ); |
|
149 |
|
150 CleanupStack::PopAndDestroy( bitmap ); |
|
151 } |
|
152 break; |
|
153 |
|
154 case EGlxIDF_JPEG: |
|
155 iDecoder = GlxtnImageDecoderFactory::NewL( |
|
156 iFileUtility.FsSession(), *iThumbData ); |
|
157 DecodeThumbnailL( aStatus, EFalse ); |
|
158 active = ETrue; |
|
159 break; |
|
160 |
|
161 default: |
|
162 User::Leave( KErrNotSupported ); |
|
163 break; |
|
164 } |
|
165 |
|
166 return active; |
|
167 } |
|
168 |
|
169 // --------------------------------------------------------------------------- |
|
170 // DecodeThumbnailL |
|
171 // --------------------------------------------------------------------------- |
|
172 // |
|
173 void CGlxtnLoadThumbnailTask::DecodeThumbnailL( TRequestStatus& aStatus, |
|
174 TBool /*aScaleBitmap*/ ) |
|
175 { |
|
176 TRACER("CGlxtnLoadThumbnailTask::DecodeThumbnailL()"); |
|
177 GLX_ASSERT_DEBUG( iDecoder, Panic( EGlxPanicNullPointer ), "No decoder" ); |
|
178 |
|
179 // Resize empty bitmap to required size |
|
180 TSize thumbSize( iDecoder->FrameInfo().iOverallSizeInPixels ); |
|
181 GLX_DEBUG3("CGlxtnLoadThumbnailTask::DecodeThumbnailL() thumbSize w(%d) h(%d)", |
|
182 thumbSize.iWidth, thumbSize.iHeight); |
|
183 |
|
184 // Always adjust the target bitmap size |
|
185 // as Exif thumbnail could be bigger in size |
|
186 TSize targetSize = iRequestedSize; |
|
187 if( (thumbSize.iWidth <= targetSize.iWidth ) && |
|
188 (thumbSize.iHeight <= targetSize.iHeight ) ) |
|
189 { |
|
190 targetSize.iWidth = thumbSize.iWidth; |
|
191 targetSize.iHeight = thumbSize.iHeight; |
|
192 } |
|
193 else if ( targetSize.iHeight * thumbSize.iWidth |
|
194 < targetSize.iWidth * thumbSize.iHeight ) |
|
195 { |
|
196 // Source has taller aspect than target so reduce target width |
|
197 targetSize.iWidth = ( ( targetSize.iHeight * thumbSize.iWidth ) |
|
198 / ( thumbSize.iHeight ) ); |
|
199 } |
|
200 else |
|
201 { |
|
202 // Source has wider aspect than target so reduce target height |
|
203 targetSize.iHeight = (targetSize.iWidth * thumbSize.iHeight) |
|
204 / thumbSize.iWidth; |
|
205 } |
|
206 GLX_DEBUG3("CGlxtnLoadThumbnailTask::DecodeThumbnailL() targetSize w(%d) h(%d)", |
|
207 targetSize.iWidth, targetSize.iHeight); |
|
208 |
|
209 User::LeaveIfError( iThumbnail->Resize(targetSize) ); |
|
210 |
|
211 iDecoder->Convert( &aStatus, *iThumbnail ); |
|
212 iState = EStateDecodingThumbnail; |
|
213 } |