|
1 /* |
|
2 * Copyright (c) 2004 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 Transforms subsystem. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include <e32svr.h> |
|
22 #include <fbs.h> |
|
23 |
|
24 #include "CVtImageScaler.h" |
|
25 #include "CVtImageScalerImpl.h" |
|
26 #include "CVtImageScalerImplNearest.h" |
|
27 #include "CVtImageScalerImplWeightedAverage.h" |
|
28 #include "CVtImageScalerImplBilinear.h" |
|
29 |
|
30 // CONSTANTS |
|
31 |
|
32 _LIT( KModuleName, "CVtImageScaler" ); |
|
33 |
|
34 // MACROS |
|
35 |
|
36 #ifdef _DEBUG |
|
37 # define __IF_DEBUG(t) {RDebug::t;} |
|
38 #else |
|
39 # define __IF_DEBUG(t) |
|
40 #endif |
|
41 |
|
42 // ============================ MEMBER FUNCTIONS =============================== |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // CVtImageScaler::NewL( MVtImageScalerObserver& aObserver, TQuality aQuality, |
|
46 // TPriority aPriority ) |
|
47 // ----------------------------------------------------------------------------- |
|
48 EXPORT_C CVtImageScaler* CVtImageScaler::NewL( |
|
49 MVtImageScalerObserver& aObserver, |
|
50 TQuality aQuality, |
|
51 TPriority aPriority ) |
|
52 { |
|
53 CVtImageScaler* self = new ( ELeave ) CVtImageScaler( aObserver, aPriority ); |
|
54 CleanupStack::PushL( self ); |
|
55 self->ConstructL( aQuality ); |
|
56 CleanupStack::Pop(); // self |
|
57 return self; |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // CVtImageScaler::~CVtImageScaler() |
|
62 // ----------------------------------------------------------------------------- |
|
63 EXPORT_C CVtImageScaler::~CVtImageScaler() |
|
64 { |
|
65 Cancel(); |
|
66 delete iAsyncCallBack; |
|
67 delete iHeapLock; |
|
68 delete iScalerImpl; |
|
69 } |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // CVtImageScaler::SetQualityL( TQuality aQuality ) |
|
73 // ----------------------------------------------------------------------------- |
|
74 EXPORT_C void CVtImageScaler::SetQualityL( TQuality aQuality ) |
|
75 { |
|
76 delete iScalerImpl; |
|
77 iScalerImpl = 0; |
|
78 |
|
79 switch( aQuality ) |
|
80 { |
|
81 case ENearest: |
|
82 iScalerImpl = new ( ELeave ) CVtImageScalerImplNearest(); |
|
83 break; |
|
84 |
|
85 case EWeightedAverage: |
|
86 iScalerImpl = new ( ELeave ) CVtImageScalerImplWeightedAverage(); |
|
87 break; |
|
88 |
|
89 case EBilinear: |
|
90 iScalerImpl = new ( ELeave ) CVtImageScalerImplBilinear(); |
|
91 break; |
|
92 } |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // CVtImageScaler::ScaleL( const CVtImage& aSource, CVtImage& aTarget ) |
|
97 // ----------------------------------------------------------------------------- |
|
98 EXPORT_C void CVtImageScaler::ScaleL( |
|
99 const CVtImage& aSource, |
|
100 CVtImage& aTarget ) |
|
101 { |
|
102 if( !IsActive() ) |
|
103 { |
|
104 if( !iScalerImpl ) |
|
105 { |
|
106 User::Leave( KErrNotReady ); |
|
107 } |
|
108 iScalerImpl->SetSourceTargetL( aSource, aTarget ); |
|
109 iCancelled = EFalse; |
|
110 Activate(); |
|
111 iAsyncCallBack->CallBack(); |
|
112 } |
|
113 else |
|
114 { |
|
115 User::Panic( KModuleName(), EBusy ); |
|
116 } |
|
117 } |
|
118 |
|
119 // ----------------------------------------------------------------------------- |
|
120 // CVtImageScaler::Scale( const CVtImage& aSource, CVtImage& aTarget ) |
|
121 // ----------------------------------------------------------------------------- |
|
122 EXPORT_C void CVtImageScaler::Scale( |
|
123 const CVtImage& aSource, |
|
124 CVtImage& aTarget ) |
|
125 { |
|
126 TRAPD( result, ScaleL( aSource, aTarget ) ); |
|
127 if( result != KErrNone ) |
|
128 { |
|
129 Activate(); |
|
130 Signal( result ); |
|
131 } |
|
132 } |
|
133 |
|
134 // ----------------------------------------------------------------------------- |
|
135 // CVtImageScaler::ScaleNowL( const CVtImage& aSource, CVtImage& aTarget ) |
|
136 // ----------------------------------------------------------------------------- |
|
137 EXPORT_C void CVtImageScaler::ScaleNowL( |
|
138 const CVtImage& aSource, CVtImage& aTarget ) |
|
139 { |
|
140 if( !iScalerImpl ) |
|
141 { |
|
142 User::Leave( KErrNotReady ); |
|
143 } |
|
144 |
|
145 iScalerImpl->SetSourceTargetL( aSource, aTarget ); |
|
146 |
|
147 TInt result; |
|
148 TBool more; |
|
149 TBool needsLock( iScalerImpl->NeedHeapLock() ); |
|
150 do |
|
151 { |
|
152 |
|
153 if ( needsLock ) |
|
154 { |
|
155 iHeapLock->LockHeap( ETrue ); |
|
156 } |
|
157 |
|
158 result = iScalerImpl->Scale( more ); |
|
159 |
|
160 if ( needsLock ) |
|
161 { |
|
162 iHeapLock->UnlockHeap( ETrue ); |
|
163 } |
|
164 |
|
165 } while ( more && ( result == KErrNone ) ); |
|
166 |
|
167 User::LeaveIfError( result ); |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // CVtImageScaler::CVtImageScaler() |
|
172 // ----------------------------------------------------------------------------- |
|
173 CVtImageScaler::CVtImageScaler( MVtImageScalerObserver& aObserver, TPriority aPriority ) |
|
174 : CActive( aPriority ), iObserver( aObserver ) |
|
175 { |
|
176 CActiveScheduler::Add( this ); |
|
177 } |
|
178 |
|
179 // ----------------------------------------------------------------------------- |
|
180 // CVtImageScaler::ConstructL( TQuality aQuality ) |
|
181 // ----------------------------------------------------------------------------- |
|
182 void CVtImageScaler::ConstructL( TQuality aQuality ) |
|
183 { |
|
184 SetQualityL( aQuality ); |
|
185 iHeapLock = new ( ELeave ) CFbsBitmap(); |
|
186 iHeapLock->Create( TSize( 1, 1 ), EColor256 ); |
|
187 iAsyncCallBack = new ( ELeave ) |
|
188 CAsyncCallBack( TCallBack( StaticScale, this ), Priority() ); |
|
189 } |
|
190 |
|
191 // ----------------------------------------------------------------------------- |
|
192 // CVtImageScaler::Activate |
|
193 // ----------------------------------------------------------------------------- |
|
194 void CVtImageScaler::Activate() |
|
195 { |
|
196 iStatus = KRequestPending; |
|
197 SetActive(); |
|
198 } |
|
199 |
|
200 // ----------------------------------------------------------------------------- |
|
201 // CVtImageScaler::Signal( TInt aError ) |
|
202 // ----------------------------------------------------------------------------- |
|
203 void CVtImageScaler::Signal( TInt aError ) |
|
204 { |
|
205 TRequestStatus* pStatus = &iStatus; |
|
206 User::RequestComplete( pStatus, aError ); |
|
207 } |
|
208 |
|
209 // ----------------------------------------------------------------------------- |
|
210 // CVtImageScaler::RunL() |
|
211 // ----------------------------------------------------------------------------- |
|
212 void CVtImageScaler::RunL() |
|
213 { |
|
214 iObserver.ScalingFinished( iStatus.Int() ); |
|
215 } |
|
216 |
|
217 // ----------------------------------------------------------------------------- |
|
218 // CVtImageScaler::DoCancel() |
|
219 // ----------------------------------------------------------------------------- |
|
220 void CVtImageScaler::DoCancel() |
|
221 { |
|
222 if ( iStatus == KRequestPending ) |
|
223 { |
|
224 iCancelled = ETrue; |
|
225 Signal( KErrCancel ); |
|
226 iObserver.ScalingFinished( KErrCancel ); |
|
227 } |
|
228 } |
|
229 |
|
230 // ----------------------------------------------------------------------------- |
|
231 // CVtImageScaler::StaticScale() |
|
232 // ----------------------------------------------------------------------------- |
|
233 TInt CVtImageScaler::StaticScale( TAny* aPtr ) |
|
234 { |
|
235 CVtImageScaler* self = reinterpret_cast< CVtImageScaler* >( aPtr ); |
|
236 self->DoScale(); |
|
237 return KErrNone; |
|
238 } |
|
239 |
|
240 // ----------------------------------------------------------------------------- |
|
241 // CVtImageScaler::DoScale |
|
242 // ----------------------------------------------------------------------------- |
|
243 void CVtImageScaler::DoScale() |
|
244 { |
|
245 if ( !iCancelled ) |
|
246 { |
|
247 TBool more; |
|
248 TBool needsLock = iScalerImpl->NeedHeapLock(); |
|
249 if ( needsLock ) |
|
250 { |
|
251 iHeapLock->LockHeap( ETrue ); |
|
252 } |
|
253 TInt result = iScalerImpl->Scale( more ); |
|
254 if ( needsLock ) |
|
255 { |
|
256 iHeapLock->UnlockHeap( ETrue ); |
|
257 } |
|
258 if ( !more || ( result != KErrNone ) ) |
|
259 { |
|
260 Signal( result ); |
|
261 } |
|
262 else |
|
263 { |
|
264 iAsyncCallBack->CallBack(); |
|
265 } |
|
266 } |
|
267 } |
|
268 |
|
269 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
270 |
|
271 // End of File |
|
272 |
|
273 |