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 "thumbnailimagedecoderv2.h" |
|
26 #include "thumbnaillog.h" |
|
27 #include "thumbnailpanic.h" |
|
28 #include "thumbnailmanagerconstants.h" |
|
29 #include "OstTraceDefinitions.h" |
|
30 #ifdef OST_TRACE_COMPILER_IN_USE |
|
31 #include "thumbnailimagedecoderv2Traces.h" |
|
32 #endif |
|
33 |
|
34 |
|
35 // ============================ MEMBER FUNCTIONS =============================== |
|
36 //------------------------------------------------------------------------ |
|
37 // CThumbnailImageDecoder::CThumbnailImageDecoder() |
|
38 // C++ default constructor can NOT contain any code, that might leave. |
|
39 // --------------------------------------------------------------------------- |
|
40 // |
|
41 CThumbnailImageDecoderv2::CThumbnailImageDecoderv2( RFs& aFs): |
|
42 CActive(EPriorityStandard ), iBitmap( NULL ), iFs( aFs ), iBuffer( NULL ) |
|
43 { |
|
44 CActiveScheduler::Add( this ); |
|
45 } |
|
46 |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // CThumbnailImageDecoder::~CThumbnailImageDecoder() |
|
50 // Destructor. |
|
51 // --------------------------------------------------------------------------- |
|
52 // |
|
53 CThumbnailImageDecoderv2::~CThumbnailImageDecoderv2() |
|
54 { |
|
55 Release(); |
|
56 } |
|
57 |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CThumbnailImageDecoder::CreateL() |
|
61 // Creates thumbnail of image |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 void CThumbnailImageDecoderv2::CreateL(TDesC8& aBuffer, MThumbnailProviderObserver& aObserver) |
|
65 { |
|
66 TN_DEBUG1( "CThumbnailImageDecoderv2::CreateL() start" ); |
|
67 OstTrace0( TRACE_NORMAL, CTHUMBNAILIMAGEDECODERV2_CREATEL, "CThumbnailImageDecoderv2::CreateL - start" ); |
|
68 |
|
69 iBuffer = &aBuffer; |
|
70 iObserver = &aObserver; |
|
71 |
|
72 CreateDecoderL(); |
|
73 |
|
74 TN_DEBUG1( "CThumbnailImageDecoderv2::CreateL() end" ); |
|
75 OstTrace0( TRACE_NORMAL, DUP1_CTHUMBNAILIMAGEDECODERV2_CREATEL, "CThumbnailImageDecoderv2::CreateL - end" ); |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CThumbnailImageDecoder::DecodeL() |
|
80 // Decode the thumbnail image |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 void CThumbnailImageDecoderv2::DecodeL( ) |
|
84 { |
|
85 TN_DEBUG1( "CThumbnailImageDecoderv2::DecodeL() start" ); |
|
86 OstTrace0( TRACE_NORMAL, CTHUMBNAILIMAGEDECODERV2_DECODEL, "CThumbnailImageDecoderv2::DecodeL - start" ); |
|
87 |
|
88 // Create the bitmap |
|
89 if ( !iBitmap ) |
|
90 { |
|
91 iBitmap = new( ELeave )CFbsBitmap(); |
|
92 } |
|
93 |
|
94 //set displaymode from global constants |
|
95 TInt err = iBitmap->Create( iDecoder->FrameInfo().iOverallSizeInPixels, iDecoder->FrameInfo().iFrameDisplayMode); |
|
96 if (err != KErrNone) |
|
97 { |
|
98 delete iBitmap; |
|
99 iBitmap = NULL; |
|
100 User::Leave(err); |
|
101 } |
|
102 |
|
103 iDecoder->Convert( &iStatus, * iBitmap ); |
|
104 |
|
105 SetActive(); |
|
106 |
|
107 TN_DEBUG1( "CThumbnailImageDecoderv2::DecodeL() end" ); |
|
108 OstTrace0( TRACE_NORMAL, DUP1_CTHUMBNAILIMAGEDECODERV2_DECODEL, "CThumbnailImageDecoderv2::DecodeL - end" ); |
|
109 } |
|
110 |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // CThumbnailImageDecoder::Release() |
|
114 // Releases resources |
|
115 // ----------------------------------------------------------------------------- |
|
116 // |
|
117 void CThumbnailImageDecoderv2::Release() |
|
118 { |
|
119 Cancel(); |
|
120 |
|
121 delete iDecoder; |
|
122 iDecoder = NULL; |
|
123 |
|
124 delete iBitmap; |
|
125 iBitmap = NULL; |
|
126 |
|
127 iBuffer = NULL; // we don't own the buffer |
|
128 } |
|
129 |
|
130 |
|
131 // ----------------------------------------------------------------------------- |
|
132 // CThumbnailImageDecoder::DoCancel() |
|
133 // ----------------------------------------------------------------------------- |
|
134 // |
|
135 void CThumbnailImageDecoderv2::DoCancel() |
|
136 { |
|
137 if ( iDecoder ) |
|
138 { |
|
139 iDecoder->Cancel(); |
|
140 delete iDecoder; |
|
141 iDecoder = NULL; |
|
142 } |
|
143 |
|
144 delete iBitmap; |
|
145 iBitmap = NULL; |
|
146 |
|
147 iBuffer = NULL; // we don't own the buffer |
|
148 } |
|
149 |
|
150 |
|
151 // ----------------------------------------------------------------------------- |
|
152 // CThumbnailImageDecoder::RunL() |
|
153 // ----------------------------------------------------------------------------- |
|
154 // |
|
155 void CThumbnailImageDecoderv2::RunL() |
|
156 { |
|
157 // This call takes ownership of iBitmap |
|
158 // EXIF always false |
|
159 // Rotated always false |
|
160 iObserver->ThumbnailProviderReady( iStatus.Int(), iBitmap, iOriginalSize, EFalse, EFalse); |
|
161 |
|
162 iBitmap = NULL; // owned by server now |
|
163 iBuffer = NULL; // we don't own the buffer |
|
164 |
|
165 Release(); |
|
166 } |
|
167 |
|
168 |
|
169 // ----------------------------------------------------------------------------- |
|
170 // CThumbnailImageDecoder::CreateDecoderL |
|
171 // Creates image decoder |
|
172 // ----------------------------------------------------------------------------- |
|
173 // |
|
174 void CThumbnailImageDecoderv2::CreateDecoderL() |
|
175 { |
|
176 TN_DEBUG1( "CThumbnailImageDecoderv2::CreateDecoderL() start" ); |
|
177 OstTrace0( TRACE_NORMAL, CTHUMBNAILIMAGEDECODERV2_CREATEDECODERL, "CThumbnailImageDecoderv2::CreateDecoderL - start" ); |
|
178 |
|
179 delete iDecoder; |
|
180 iDecoder = NULL; |
|
181 |
|
182 CImageDecoder::TOptions options = ( CImageDecoder::TOptions )( |
|
183 CImageDecoder::EOptionNoDither ); |
|
184 |
|
185 TRAPD( decErr, iDecoder = CExtJpegDecoder::DataNewL( |
|
186 CExtJpegDecoder::EHwImplementation, iFs, *iBuffer, options )); |
|
187 |
|
188 if ( decErr != KErrNone ) |
|
189 { |
|
190 TN_DEBUG2( "CThumbnailImageDecoderv2::CreateDecoderL() - HW CExtJpegDecoder failed = %d", decErr ); |
|
191 OstTrace1( TRACE_NORMAL, DUP1_CTHUMBNAILIMAGEDECODERV2_CREATEDECODERL, "CThumbnailImageDecoderv2::CreateDecoderL - HW CExtJpegDecoder failed;decErr=%d", decErr ); |
|
192 TRAP( decErr, iDecoder = CExtJpegDecoder::DataNewL( |
|
193 CExtJpegDecoder::ESwImplementation, iFs, *iBuffer, options )); |
|
194 |
|
195 if ( decErr != KErrNone ) |
|
196 { |
|
197 TN_DEBUG2( "CThumbnailImageDecoderv2::CreateDecoderL() - SW CExtJpegDecoder failed %d", decErr); |
|
198 OstTrace1( TRACE_NORMAL, DUP2_CTHUMBNAILIMAGEDECODERV2_CREATEDECODERL, "CThumbnailImageDecoderv2::CreateDecoderL - SW CExtJpegDecoder failed;decErr=%d", decErr ); |
|
199 LeaveIfCorruptL( decErr ); |
|
200 |
|
201 TRAP( decErr, iDecoder = CImageDecoder::DataNewL( iFs, *iBuffer, KJpegMime(), options ) ); |
|
202 |
|
203 if ( decErr != KErrNone ) |
|
204 { |
|
205 TN_DEBUG2( "CThumbnailImageDecoderv2::CreateDecoderL() - CImageDecoder failed %d", decErr); |
|
206 OstTrace1( TRACE_NORMAL, DUP3_CTHUMBNAILIMAGEDECODERV2_CREATEDECODERL, "CThumbnailImageDecoderv2::CreateDecoderL - CImageDecoder failed;decErr=%d", decErr ); |
|
207 LeaveIfCorruptL( decErr ); |
|
208 |
|
209 // don't force any mime type |
|
210 TRAPD( decErr, iDecoder = CImageDecoder::DataNewL( iFs, *iBuffer, options ) ); |
|
211 if ( decErr != KErrNone ) |
|
212 { |
|
213 TN_DEBUG2( "CThumbnailImageDecoderv2::CImageDecoder() - CImageDecoder no mime error %d", decErr ); |
|
214 OstTrace1( TRACE_NORMAL, DUP4_CTHUMBNAILIMAGEDECODERV2_CREATEDECODERL, "CThumbnailImageDecoderv2::CreateDecoderL - CImageDecoder no mime error;decErr=%d", decErr ); |
|
215 User::Leave( decErr ); |
|
216 } |
|
217 } |
|
218 |
|
219 TN_DEBUG1( "CThumbnailImageDecoderv2::CreateDecoderL() - CImageDecoder created" ); |
|
220 OstTrace0( TRACE_NORMAL, DUP5_CTHUMBNAILIMAGEDECODERV2_CREATEDECODERL, "CThumbnailImageDecoderv2::CreateDecoderL - CImageDecoder created" ); |
|
221 } |
|
222 else |
|
223 { |
|
224 TN_DEBUG1( "CThumbnailImageDecoderv2:CreateDecoderL() - SW CExtJpegDecoder created" ); |
|
225 OstTrace0( TRACE_NORMAL, DUP6_CTHUMBNAILIMAGEDECODERV2_CREATEDECODERL, "CThumbnailImageDecoderv2::CreateDecoderL - SW CExtJpegDecoder created" ); |
|
226 } |
|
227 } |
|
228 else |
|
229 { |
|
230 TN_DEBUG1( "CThumbnailImageDecoderv2::CreateDecoderL() - HW CExtJpegDecoder created" ); |
|
231 OstTrace0( TRACE_NORMAL, DUP7_CTHUMBNAILIMAGEDECODERV2_CREATEDECODERL, "CThumbnailImageDecoderv2::CreateDecoderL - HW CExtJpegDecoder created" ); |
|
232 } |
|
233 |
|
234 TN_DEBUG1( "CThumbnailImageDecoderv2::CreateDecoderL() end" ); |
|
235 OstTrace0( TRACE_NORMAL, DUP8_CTHUMBNAILIMAGEDECODERV2_CREATEDECODERL, "CThumbnailImageDecoderv2::CreateDecoderL - end" ); |
|
236 } |
|
237 |
|
238 // ----------------------------------------------------------------------------- |
|
239 // CThumbnailImageDecoderv2::LeaveIfCorruptL() |
|
240 // Leave if image is corrupted |
|
241 // ----------------------------------------------------------------------------- |
|
242 // |
|
243 void CThumbnailImageDecoderv2::LeaveIfCorruptL(const TInt aError ) |
|
244 { |
|
245 //no sense to try other codecs if image is corrupted |
|
246 if( aError == KErrCorrupt || aError == KErrUnderflow) |
|
247 { |
|
248 User::Leave( aError ); |
|
249 } |
|
250 } |
|
251 |
|
252 //End of file |
|