|
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 |
|
30 // ============================ MEMBER FUNCTIONS =============================== |
|
31 //------------------------------------------------------------------------ |
|
32 // CThumbnailImageDecoder::CThumbnailImageDecoder() |
|
33 // C++ default constructor can NOT contain any code, that might leave. |
|
34 // --------------------------------------------------------------------------- |
|
35 // |
|
36 CThumbnailImageDecoderv2::CThumbnailImageDecoderv2( RFs& aFs): CActive( |
|
37 EPriorityStandard ), iFs( aFs ) |
|
38 { |
|
39 CActiveScheduler::Add( this ); |
|
40 } |
|
41 |
|
42 |
|
43 // --------------------------------------------------------------------------- |
|
44 // CThumbnailImageDecoder::~CThumbnailImageDecoder() |
|
45 // Destructor. |
|
46 // --------------------------------------------------------------------------- |
|
47 // |
|
48 CThumbnailImageDecoderv2::~CThumbnailImageDecoderv2() |
|
49 { |
|
50 Release(); |
|
51 } |
|
52 |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // CThumbnailImageDecoder::CreateL() |
|
56 // Creates thumbnail of image |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 void CThumbnailImageDecoderv2::CreateL(TDesC8& aBuffer, MThumbnailProviderObserver& aObserver) |
|
60 { |
|
61 TN_DEBUG1( "CThumbnailImageDecoderv2::CreateL() start" ); |
|
62 |
|
63 iBuffer = &aBuffer; |
|
64 iObserver = &aObserver; |
|
65 |
|
66 CreateDecoderL(); |
|
67 |
|
68 TN_DEBUG1( "CThumbnailImageDecoderv2::CreateL() end" ); |
|
69 } |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // CThumbnailImageDecoder::DecodeL() |
|
73 // Decode the thumbnail image |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 void CThumbnailImageDecoderv2::DecodeL( ) |
|
77 { |
|
78 TN_DEBUG1( "CThumbnailImageDecoderv2::DecodeL() start" ); |
|
79 |
|
80 // Create the bitmap |
|
81 if ( !iBitmap ) |
|
82 { |
|
83 iBitmap = new( ELeave )CFbsBitmap(); |
|
84 } |
|
85 |
|
86 //set displaymode from global constants |
|
87 User::LeaveIfError( iBitmap->Create( iDecoder->FrameInfo().iOverallSizeInPixels, iDecoder->FrameInfo().iFrameDisplayMode) ); |
|
88 |
|
89 iDecoder->Convert( &iStatus, * iBitmap ); |
|
90 while ( iStatus == KErrUnderflow ) |
|
91 { |
|
92 iDecoder->ContinueConvert( &iStatus ); |
|
93 } |
|
94 SetActive(); |
|
95 |
|
96 TN_DEBUG1( "CThumbnailImageDecoderv2::DecodeL() end" ); |
|
97 } |
|
98 |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // CThumbnailImageDecoder::Release() |
|
102 // Releases resources |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 void CThumbnailImageDecoderv2::Release() |
|
106 { |
|
107 Cancel(); |
|
108 delete iDecoder; |
|
109 iDecoder = NULL; |
|
110 } |
|
111 |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // CThumbnailImageDecoder::DoCancel() |
|
115 // ----------------------------------------------------------------------------- |
|
116 // |
|
117 void CThumbnailImageDecoderv2::DoCancel() |
|
118 { |
|
119 if ( iDecoder ) |
|
120 { |
|
121 iDecoder->Cancel(); |
|
122 delete iDecoder; |
|
123 iDecoder = NULL; |
|
124 } |
|
125 } |
|
126 |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // CThumbnailImageDecoder::RunL() |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 void CThumbnailImageDecoderv2::RunL() |
|
133 { |
|
134 // This call takes ownership of iBitmap |
|
135 // EXIF always false |
|
136 // Rotated always false |
|
137 iObserver->ThumbnailProviderReady( iStatus.Int(), iBitmap, iOriginalSize, EFalse, EFalse); |
|
138 |
|
139 iBitmap = NULL; // owned by server now |
|
140 iBuffer = NULL; |
|
141 Release(); |
|
142 } |
|
143 |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // CThumbnailImageDecoder::CreateDecoderL |
|
147 // Creates image decoder |
|
148 // ----------------------------------------------------------------------------- |
|
149 // |
|
150 void CThumbnailImageDecoderv2::CreateDecoderL() |
|
151 { |
|
152 TN_DEBUG1( "CThumbnailImageDecoderv2::CreateDecoderL() start" ); |
|
153 |
|
154 delete iDecoder; |
|
155 iDecoder = NULL; |
|
156 |
|
157 CImageDecoder::TOptions options = ( CImageDecoder::TOptions )( |
|
158 CImageDecoder::EOptionNoDither | CImageDecoder::EPreferFastDecode ); |
|
159 |
|
160 TRAPD( decErr, iDecoder = CExtJpegDecoder::DataNewL( |
|
161 CExtJpegDecoder::EHwImplementation, iFs, *iBuffer, options )); |
|
162 |
|
163 if ( decErr != KErrNone ) |
|
164 { |
|
165 TRAP( decErr, iDecoder = CExtJpegDecoder::DataNewL( |
|
166 CExtJpegDecoder::ESwImplementation, iFs, *iBuffer, options )); |
|
167 |
|
168 if ( decErr != KErrNone ) |
|
169 { |
|
170 TRAP( decErr, iDecoder = CImageDecoder::DataNewL( iFs, *iBuffer, KJpegMime(), options ) ); |
|
171 |
|
172 if ( decErr != KErrNone ) |
|
173 { |
|
174 // don't force any mime type |
|
175 TRAPD( decErr, iDecoder = CImageDecoder::DataNewL( iFs, *iBuffer, options ) ); |
|
176 if ( decErr != KErrNone ) |
|
177 { |
|
178 TN_DEBUG1( "CThumbnailImageDecoderv2::CreateDecoderL() - error" ); |
|
179 |
|
180 User::Leave( decErr ); |
|
181 } |
|
182 } |
|
183 |
|
184 TN_DEBUG1( "CThumbnailImageDecoderv2::CreateDecoderL() - CImageDecoder created" ); |
|
185 } |
|
186 else |
|
187 { |
|
188 TN_DEBUG1( "CThumbnailImageDecoderv2:CreateDecoderL() - SW CExtJpegDecoder created" ); |
|
189 } |
|
190 } |
|
191 else |
|
192 { |
|
193 TN_DEBUG1( "CThumbnailImageDecoderv2::CreateDecoderL() - HW CExtJpegDecoder created" ); |
|
194 } |
|
195 |
|
196 TN_DEBUG1( "CThumbnailImageDecoderv2::CreateDecoderL() end" ); |
|
197 } |
|
198 |
|
199 //End of file |