|
1 /* |
|
2 * Copyright (c) 2006-2007 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: Image thumbnail decoder |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 //INCLUDE FILES |
|
20 #include <e32base.h> |
|
21 #include <imageconversion.h> |
|
22 #include <exifread.h> |
|
23 |
|
24 #include <iclextjpegapi.h> |
|
25 #include "thumbnailimagedecoderv3.h" |
|
26 #include "thumbnaillog.h" |
|
27 #include "thumbnailpanic.h" |
|
28 |
|
29 |
|
30 // CImageDecoder supports up to 1/8 size reduction if EFullyScaleable is |
|
31 // not set. |
|
32 const TInt KMaximumReductionFactor = 8; |
|
33 |
|
34 |
|
35 // ============================ MEMBER FUNCTIONS =============================== |
|
36 |
|
37 // --------------------------------------------------------------------------- |
|
38 // CThumbnailImageDecoder::CThumbnailImageDecoder() |
|
39 // C++ default constructor can NOT contain any code, that might leave. |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 CThumbnailImageDecoderv3::CThumbnailImageDecoderv3( RFs& aFs ): CActive( |
|
43 EPriorityStandard ), iFs( aFs ) |
|
44 { |
|
45 CActiveScheduler::Add( this ); |
|
46 } |
|
47 |
|
48 |
|
49 // --------------------------------------------------------------------------- |
|
50 // CThumbnailImageDecoderv3::~CThumbnailImageDecoderv3() |
|
51 // Destructor. |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 CThumbnailImageDecoderv3::~CThumbnailImageDecoderv3() |
|
55 { |
|
56 Release(); |
|
57 } |
|
58 |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // CThumbnailImageDecoderv3::CreateL() |
|
62 // Creates thumbnail of image |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 void CThumbnailImageDecoderv3::CreateL( const TDesC8* aBuffer, MThumbnailProviderObserver& |
|
66 aObserver, const CThumbnailManager::TThumbnailFlags /*aFlags*/, const |
|
67 TDataType& aMimeType, const TSize& aSize ) |
|
68 { |
|
69 |
|
70 TN_DEBUG1( "CCThumbnailImageDecoderv3::CreateL() called" ); |
|
71 |
|
72 iSize = aSize; |
|
73 iMimeType = aMimeType; |
|
74 iObserver = &aObserver; |
|
75 iBuffer = aBuffer; |
|
76 |
|
77 CreateDecoderL(); |
|
78 |
|
79 const TFrameInfo info( iDecoder->FrameInfo()); |
|
80 if (( info.iOverallSizeInPixels.iWidth < 1 ) || ( |
|
81 info.iOverallSizeInPixels.iHeight < 1 )) |
|
82 { |
|
83 User::Leave( KErrCorrupt ); |
|
84 } |
|
85 iFrameInfoFlags = info.iFlags; |
|
86 iOriginalSize = info.iOverallSizeInPixels; |
|
87 } |
|
88 |
|
89 // ----------------------------------------------------------------------------- |
|
90 // CThumbnailImageDecoderv3::DecodeL() |
|
91 // Decode the thumbnail image |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 void CThumbnailImageDecoderv3::DecodeL( const TDisplayMode aDisplayMode ) |
|
95 { |
|
96 // Create the bitmap |
|
97 if ( !iBitmap ) |
|
98 { |
|
99 iBitmap = new( ELeave )CFbsBitmap(); |
|
100 } |
|
101 |
|
102 //Size in both x and y dimension must be non-zero, positive value |
|
103 TSize loadSize( iOriginalSize) ; |
|
104 |
|
105 // If EFullyScaleable flag is not set, we need to figure out a size |
|
106 // reduction factor. 1/1, 1/2, 1/4, and 1/8 are possible values for all |
|
107 // plug-ins. SVG graphics can be rendered at any size even though |
|
108 // EFullyScaleable is not set. |
|
109 if ( !( iFrameInfoFlags& TFrameInfo::EFullyScaleable ) ) |
|
110 { |
|
111 loadSize = iOriginalSize; |
|
112 TInt reductionFactor = 1; |
|
113 while ( reductionFactor < KMaximumReductionFactor && ( iSize.iWidth < |
|
114 loadSize.iWidth / 2 ) && ( iSize.iHeight < loadSize.iHeight / 2 )) |
|
115 { |
|
116 // magic: use loadSize that is half of previous size |
|
117 loadSize.iWidth /= 2; |
|
118 loadSize.iHeight /= 2; |
|
119 reductionFactor *= 2; |
|
120 } |
|
121 // If original size is not an exact multiple of reduction factor, |
|
122 // we need to round loadSize up |
|
123 if ( reductionFactor && iOriginalSize.iWidth % reductionFactor ) |
|
124 { |
|
125 loadSize.iWidth++; |
|
126 } |
|
127 if ( reductionFactor && iOriginalSize.iHeight % reductionFactor ) |
|
128 { |
|
129 loadSize.iHeight++; |
|
130 } |
|
131 TN_DEBUG4( |
|
132 "EFullyScaleable not set for image - loadSize=(%d,%d) reduction=1/%d ", loadSize.iWidth, loadSize.iHeight, reductionFactor ); |
|
133 } |
|
134 |
|
135 User::LeaveIfError( iBitmap->Create( loadSize, aDisplayMode )); |
|
136 |
|
137 iDecoder->Convert( &iStatus, * iBitmap ); |
|
138 while ( iStatus == KErrUnderflow ) |
|
139 { |
|
140 iDecoder->ContinueConvert( &iStatus ); |
|
141 } |
|
142 SetActive(); |
|
143 } |
|
144 |
|
145 |
|
146 // ----------------------------------------------------------------------------- |
|
147 // CThumbnailImageDecoderv3::Release() |
|
148 // Releases resources |
|
149 // ----------------------------------------------------------------------------- |
|
150 // |
|
151 void CThumbnailImageDecoderv3::Release() |
|
152 { |
|
153 Cancel(); |
|
154 delete iDecoder; |
|
155 iDecoder = NULL; |
|
156 } |
|
157 |
|
158 |
|
159 // ----------------------------------------------------------------------------- |
|
160 // CThumbnailImageDecoderv3::DoCancel() |
|
161 // ----------------------------------------------------------------------------- |
|
162 // |
|
163 void CThumbnailImageDecoderv3::DoCancel() |
|
164 { |
|
165 if ( iDecoder ) |
|
166 { |
|
167 iDecoder->Cancel(); |
|
168 delete iDecoder; |
|
169 iDecoder = NULL; |
|
170 } |
|
171 } |
|
172 |
|
173 |
|
174 // ----------------------------------------------------------------------------- |
|
175 // CThumbnailImageDecoderv3::RunL() |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 void CThumbnailImageDecoderv3::RunL() |
|
179 { |
|
180 // This call takes ownership of iBitmap |
|
181 iObserver->ThumbnailProviderReady( iStatus.Int(), iBitmap, iOriginalSize, EFalse, EFalse ); |
|
182 |
|
183 iBitmap = NULL; // owned by server now |
|
184 delete iBuffer; |
|
185 iBuffer = NULL; |
|
186 Release(); |
|
187 } |
|
188 |
|
189 |
|
190 // ----------------------------------------------------------------------------- |
|
191 // CThumbnailImageDecoderv3::CreateDecoderL |
|
192 // Creates image decoder |
|
193 // ----------------------------------------------------------------------------- |
|
194 // |
|
195 void CThumbnailImageDecoderv3::CreateDecoderL() |
|
196 { |
|
197 delete iDecoder; |
|
198 iDecoder = NULL; |
|
199 |
|
200 CImageDecoder::TOptions options = ( CImageDecoder::TOptions )( |
|
201 CImageDecoder::EOptionNoDither | CImageDecoder::EPreferFastDecode ); |
|
202 |
|
203 TRAPD( decErr, iDecoder = CExtJpegDecoder::DataNewL( |
|
204 CExtJpegDecoder::EHwImplementation, iFs, *iBuffer, options )); |
|
205 |
|
206 if ( decErr != KErrNone ) |
|
207 { |
|
208 TRAP( decErr, iDecoder = CExtJpegDecoder::DataNewL( |
|
209 CExtJpegDecoder::ESwImplementation, iFs, *iBuffer, options )); |
|
210 |
|
211 if ( decErr != KErrNone ) |
|
212 { |
|
213 // don't force any mime type |
|
214 TRAPD( decErr, iDecoder = CImageDecoder::DataNewL( iFs, *iBuffer, options ) ); |
|
215 if ( decErr != KErrNone ) |
|
216 { |
|
217 delete iBuffer; |
|
218 iBuffer = NULL; |
|
219 |
|
220 TN_DEBUG1( "CThumbnailImageDecoderv3::CreateDecoderL() - error" ); |
|
221 |
|
222 User::Leave( decErr ); |
|
223 } |
|
224 |
|
225 TN_DEBUG1( "CThumbnailImageDecoderv3::CreateDecoderL() - CImageDecoder created" ); |
|
226 } |
|
227 else |
|
228 { |
|
229 TN_DEBUG1( "CThumbnailImageDecoderv3::CreateDecoderL() - SW CExtJpegDecoder created" ); |
|
230 } |
|
231 } |
|
232 else |
|
233 { |
|
234 TN_DEBUG1( "CThumbnailImageDecoderv3::CreateDecoderL() - HW CExtJpegDecoder created" ); |
|
235 } |
|
236 } |
|
237 |
|
238 |
|
239 // ----------------------------------------------------------------------------- |
|
240 // CThumbnailImageDecoderv3::CreateExifDecoderL() |
|
241 // Returns size of original image |
|
242 // ----------------------------------------------------------------------------- |
|
243 // |
|
244 const TSize& CThumbnailImageDecoderv3::OriginalSize()const |
|
245 { |
|
246 return iOriginalSize; |
|
247 } |
|
248 |
|
249 //End of file |