1 /* |
|
2 * Copyright (c) 2010 Ixonos Plc. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "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 * Ixonos Plc |
|
14 * |
|
15 * Description: |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include "VeiImageConverter.h" |
|
23 |
|
24 #include <fbs.h> |
|
25 #include <ImageConversion.h> |
|
26 #include <BitmapTransforms.h> |
|
27 #include "VideoEditorCommon.h" |
|
28 #include "VideoEditorDebugUtils.h" |
|
29 |
|
30 |
|
31 |
|
32 // ================= MEMBER FUNCTIONS ======================= |
|
33 |
|
34 // --------------------------------------------------------- |
|
35 // CVeiImageConverter::CVeiImageConverter::NewL( |
|
36 // MConverterController* aController ) |
|
37 // --------------------------------------------------------- |
|
38 // |
|
39 EXPORT_C CVeiImageConverter* CVeiImageConverter::NewL( |
|
40 MConverterController* aController ) |
|
41 { |
|
42 CVeiImageConverter* self = |
|
43 new(ELeave) CVeiImageConverter( aController ); |
|
44 CleanupStack::PushL( self ); |
|
45 |
|
46 self->ConstructL(); |
|
47 |
|
48 CleanupStack::Pop( self ); |
|
49 return self; |
|
50 } |
|
51 // --------------------------------------------------------- |
|
52 // CVeiImageConverter::CVeiImageConverter( |
|
53 // MConverterController* aController ) |
|
54 // --------------------------------------------------------- |
|
55 // |
|
56 CVeiImageConverter::CVeiImageConverter( |
|
57 MConverterController* aController ) : |
|
58 CActive( EPriorityStandard ), iController( aController ) |
|
59 { |
|
60 } |
|
61 |
|
62 // --------------------------------------------------------- |
|
63 // CVeiImageConverter::ConstructL() |
|
64 // EPOC two phased constructor |
|
65 // --------------------------------------------------------- |
|
66 // |
|
67 void CVeiImageConverter::ConstructL() |
|
68 { |
|
69 User::LeaveIfError( iFs.Connect() ); |
|
70 // create the destination bitmap |
|
71 |
|
72 iBitmapScaler = CBitmapScaler::NewL(); |
|
73 |
|
74 CActiveScheduler::Add( this ); |
|
75 } |
|
76 |
|
77 // Destructor |
|
78 EXPORT_C CVeiImageConverter::~CVeiImageConverter() |
|
79 { |
|
80 LOG(KVideoEditorLogFile, "CVeiImageConverter::~CVeiImageConverter(): in"); |
|
81 if ( IsActive() ) |
|
82 { |
|
83 Cancel(); |
|
84 } |
|
85 |
|
86 delete iImageEncoder; |
|
87 delete iBitmapScaler; |
|
88 // CImageDecoder must be deleted before the |
|
89 iFs.Close(); // related RFs is closed, |
|
90 delete iBitmap; // otherwise a related thread might panic |
|
91 |
|
92 iController = NULL; |
|
93 |
|
94 LOG(KVideoEditorLogFile, "CVeiImageConverter::~CVeiImageConverter(): out"); |
|
95 } |
|
96 |
|
97 |
|
98 |
|
99 // --------------------------------------------------------- |
|
100 // CVeiImageConverter::StartToEncodeL( |
|
101 // TFileName& aFileName, TUid aImageType, TUid aImageSubType ) |
|
102 // --------------------------------------------------------- |
|
103 // |
|
104 EXPORT_C void CVeiImageConverter::StartToEncodeL( |
|
105 const TDesC& aFileName, const TUid& aImageType, const TUid& aImageSubType ) |
|
106 { |
|
107 LOG(KVideoEditorLogFile, "CVeiImageConverter::StartToEncodeL(): In"); |
|
108 if ( iImageEncoder ) |
|
109 { |
|
110 delete iImageEncoder; |
|
111 iImageEncoder = NULL; |
|
112 } |
|
113 |
|
114 // create the encoder |
|
115 LOG(KVideoEditorLogFile, "CVeiImageConverter::StartToEncodeL(): 2, own thread started"); |
|
116 iImageEncoder = CImageEncoder::FileNewL( iFs, aFileName, |
|
117 CImageEncoder::EOptionAlwaysThread, aImageType, aImageSubType ); |
|
118 |
|
119 iState = EEncoding; |
|
120 iImageEncoder->Convert( &iStatus, *iBitmap ); |
|
121 |
|
122 SetActive(); |
|
123 LOG(KVideoEditorLogFile, "CVeiImageConverter::StartToEncodeL(): Out"); |
|
124 } |
|
125 // --------------------------------------------------------- |
|
126 // CVeiImageConverter::DoCancel() |
|
127 // --------------------------------------------------------- |
|
128 // |
|
129 void CVeiImageConverter::DoCancel() |
|
130 { |
|
131 LOG(KVideoEditorLogFile, "CVeiImageConverter::DoCancel(): in"); |
|
132 if ( iState == EEncoding && iImageEncoder ) |
|
133 { |
|
134 iImageEncoder->Cancel(); |
|
135 } |
|
136 else if ( iState == EScaling ) |
|
137 { |
|
138 iBitmapScaler->Cancel(); |
|
139 } |
|
140 LOG(KVideoEditorLogFile, "CVeiImageConverter::DoCancel(): out"); |
|
141 } |
|
142 // --------------------------------------------------------- |
|
143 // CVeiImageConverter::RunL() |
|
144 // --------------------------------------------------------- |
|
145 // |
|
146 void CVeiImageConverter::RunL() |
|
147 { |
|
148 LOG(KVideoEditorLogFile, "CVeiImageConverter::RunL: In"); |
|
149 switch( iState ) |
|
150 { |
|
151 case EEncoding: |
|
152 { |
|
153 iState = EIdle; |
|
154 iController->NotifyCompletion( iStatus.Int() ); |
|
155 break; |
|
156 } |
|
157 |
|
158 default: // some error |
|
159 { |
|
160 LOG(KVideoEditorLogFile, "CVeiImageConverter::RunL: Scale completed"); |
|
161 iState = EIdle; |
|
162 iController->NotifyCompletion( iStatus.Int() ); |
|
163 } |
|
164 } |
|
165 } |
|
166 |
|
167 // --------------------------------------------------------- |
|
168 // CVeiImageConverter::RunError(TInt aError) |
|
169 // --------------------------------------------------------- |
|
170 // |
|
171 TInt CVeiImageConverter::RunError(TInt aError) |
|
172 { |
|
173 LOGFMT(KVideoEditorLogFile, "CVeiImageConverter::RunError(): in, aError:%d", aError); |
|
174 TInt err; |
|
175 err = aError; |
|
176 return err; |
|
177 } |
|
178 |
|
179 // --------------------------------------------------------- |
|
180 // CVeiImageConverter::GetEncoderImageTypesL( |
|
181 // RImageTypeDescriptionArray& aImageTypeArray ) |
|
182 // --------------------------------------------------------- |
|
183 // |
|
184 EXPORT_C void CVeiImageConverter::GetEncoderImageTypesL( |
|
185 RImageTypeDescriptionArray& aImageTypeArray ) |
|
186 { |
|
187 CImageEncoder::GetImageTypesL( aImageTypeArray ); |
|
188 } |
|
189 |
|
190 // --------------------------------------------------------- |
|
191 // CVeiImageConverter::SetBitmap() |
|
192 // --------------------------------------------------------- |
|
193 // |
|
194 EXPORT_C void CVeiImageConverter::SetBitmap( CFbsBitmap* aBitmap ) |
|
195 { |
|
196 LOG(KVideoEditorLogFile, "CVeiImageConverter::SetBitmap(): in"); |
|
197 if (iBitmap) |
|
198 { |
|
199 delete iBitmap; |
|
200 iBitmap = NULL; |
|
201 } |
|
202 iBitmap = aBitmap; |
|
203 LOG(KVideoEditorLogFile, "CVeiImageConverter::SetBitmap(): out"); |
|
204 } |
|
205 |
|
206 // --------------------------------------------------------- |
|
207 // CVeiImageConverter::GetBitmap() |
|
208 // --------------------------------------------------------- |
|
209 // |
|
210 EXPORT_C CFbsBitmap* CVeiImageConverter::GetBitmap() |
|
211 { |
|
212 return iBitmap; |
|
213 } |
|
214 |
|
215 // --------------------------------------------------------- |
|
216 // CVeiImageConverter::Scale() |
|
217 // --------------------------------------------------------- |
|
218 // |
|
219 EXPORT_C void CVeiImageConverter::ScaleL(CFbsBitmap* aSrcBitmap,CFbsBitmap* aDestBitmap, const TSize& aSize) |
|
220 { |
|
221 LOG(KVideoEditorLogFile, "CVeiImageConverter::Scale: in"); |
|
222 if ( IsActive() ) |
|
223 { |
|
224 Cancel(); |
|
225 } |
|
226 |
|
227 if ( iBitmap ) |
|
228 { |
|
229 delete iBitmap; |
|
230 iBitmap = NULL; |
|
231 } |
|
232 /* Create new bitmap where scaled bitmap is stored |
|
233 When scaling is ready, NotifyCompletion() callback and |
|
234 bitmap address can be asked with GetBitmap function */ |
|
235 |
|
236 iBitmap = aDestBitmap; |
|
237 iBitmap = new (ELeave) CFbsBitmap; |
|
238 iBitmap->Create( aSize, aSrcBitmap->DisplayMode() ); |
|
239 |
|
240 iState = EScaling; |
|
241 iBitmapScaler->Scale( &iStatus, *aSrcBitmap, *iBitmap, EFalse ); |
|
242 |
|
243 SetActive(); |
|
244 |
|
245 LOG(KVideoEditorLogFile, "CVeiImageConverter::Scale: out"); |
|
246 } |
|
247 |
|
248 // --------------------------------------------------------- |
|
249 // CVeiImageConverter::CancelEncoding() |
|
250 // --------------------------------------------------------- |
|
251 // |
|
252 EXPORT_C void CVeiImageConverter::CancelEncoding() |
|
253 { |
|
254 if ( iImageEncoder ) |
|
255 { |
|
256 delete iImageEncoder; |
|
257 iImageEncoder = NULL; |
|
258 } |
|
259 } |
|
260 |
|
261 // End of File |
|