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