|
1 /* |
|
2 * Copyright (c) 2004-2008 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: Solarize provides functionality to solarize bitmap images on per |
|
15 * channel basis. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "AknsRlEffectPluginSolarize.h" |
|
22 #include "AknsRlEffectUtil.h" |
|
23 |
|
24 // ================= TEMPLATE IMPL. OF SOLARIZE ================================ |
|
25 /** |
|
26 * Template implementation of Solarize. Type defines the used data type for |
|
27 * iterating over the bitmap data. X, R, G and B define the used pixel color bit |
|
28 * layout. |
|
29 */ |
|
30 template<class Type,TInt X, TInt R, TInt G, TInt B> |
|
31 class AknsRlEffectSolarize |
|
32 { |
|
33 public: |
|
34 static void Process( const CFbsBitmap& aTarget, |
|
35 const CFbsBitmap& aSource, |
|
36 const TInt aTreshold, |
|
37 const TUint8 aChannelMask, |
|
38 const TInt aBlendFactor ) |
|
39 { |
|
40 // ScanLineLength returns bytes, but width must match the Type |
|
41 TInt width = CFbsBitmap::ScanLineLength( aSource.SizeInPixels().iWidth, |
|
42 aSource.DisplayMode() ) / sizeof(Type); |
|
43 TInt height = aSource.SizeInPixels().iHeight; |
|
44 |
|
45 TInt pixelCount = width * height; |
|
46 TInt r,g,b; |
|
47 TInt shade; |
|
48 |
|
49 aTarget.LockHeap( ETrue ); // Lock the global bitmap heap |
|
50 Type* dataT = reinterpret_cast<Type*>( aTarget.DataAddress() ); |
|
51 Type* dataS = reinterpret_cast<Type*>( aSource.DataAddress() ); |
|
52 |
|
53 for( TInt index = 0; index < pixelCount; ++index ) |
|
54 { |
|
55 r = AknsRlRgb<Type,X,R,G,B>::R8(*dataS); |
|
56 g = AknsRlRgb<Type,X,R,G,B>::G8(*dataS); |
|
57 b = AknsRlRgb<Type,X,R,G,B>::B8(*dataS); |
|
58 |
|
59 shade = AknsRlUtil::Grayscale( TUint8(r), TUint8(g), TUint8(b) ); |
|
60 |
|
61 if( aTreshold < shade ) |
|
62 { |
|
63 if( CAknsRlEffectPluginSolarize::EMaskR & aChannelMask ) |
|
64 r = 255 - r; |
|
65 if( CAknsRlEffectPluginSolarize::EMaskG & aChannelMask ) |
|
66 g = 255 - g; |
|
67 if( CAknsRlEffectPluginSolarize::EMaskB & aChannelMask ) |
|
68 b = 255 - b; |
|
69 } |
|
70 |
|
71 // Exposure blending |
|
72 // Note: It is assumed that arithmetic shifting is supported |
|
73 // -> negative values are shifted correctly |
|
74 r = ( r * aBlendFactor + (255 - aBlendFactor) * AknsRlRgb<Type,X,R,G,B>::R8(*dataS) ) >> 8; |
|
75 g = ( g * aBlendFactor + (255 - aBlendFactor) * AknsRlRgb<Type,X,R,G,B>::G8(*dataS) ) >> 8; |
|
76 b = ( b * aBlendFactor + (255 - aBlendFactor) * AknsRlRgb<Type,X,R,G,B>::B8(*dataS) ) >> 8; |
|
77 |
|
78 if( r < 0 ) r = 0; else if( r > 255 ) r = 255; |
|
79 if( g < 0 ) g = 0; else if( g > 255 ) g = 255; |
|
80 if( b < 0 ) b = 0; else if( b > 255 ) b = 255; |
|
81 |
|
82 AknsRlRgb<Type,X,R,G,B>::SetRgb8( dataT, TUint8(r), TUint8(g), TUint8(b) ); |
|
83 |
|
84 dataT++; |
|
85 dataS++; |
|
86 } |
|
87 |
|
88 aTarget.UnlockHeap( ETrue ); // Unlock the global bitmap heap |
|
89 } |
|
90 }; // End of AknsRlEffectSolarize |
|
91 |
|
92 // ================= GRAYSCALE IMPL. OF SOLARIZE =============================== |
|
93 class AknsRlEffectSolarizeGray |
|
94 { |
|
95 public: |
|
96 static void Process( const CFbsBitmap& aTarget, |
|
97 const CFbsBitmap& aSource, |
|
98 const TInt aTreshold, |
|
99 const TInt aBlendFactor ) |
|
100 { |
|
101 TInt width = CFbsBitmap::ScanLineLength( aSource.SizeInPixels().iWidth, |
|
102 aSource.DisplayMode() ); |
|
103 TInt height = aSource.SizeInPixels().iHeight; |
|
104 |
|
105 TInt pixelCount = width * height; |
|
106 TInt shade; |
|
107 |
|
108 aTarget.LockHeap( ETrue ); // Lock the global bitmap heap |
|
109 TUint8* dataT = reinterpret_cast<TUint8*>( aTarget.DataAddress() ); |
|
110 TUint8* dataS = reinterpret_cast<TUint8*>( aSource.DataAddress() ); |
|
111 |
|
112 for( TInt index = 0; index < pixelCount; ++index ) |
|
113 { |
|
114 shade = *dataS; |
|
115 |
|
116 if( aTreshold < shade ) |
|
117 shade = 255 - shade; |
|
118 |
|
119 // Exposure blending |
|
120 // Note: It is assumed that arithmetic shifting is supported |
|
121 // -> negative values are shifted correctly |
|
122 shade = ( shade * aBlendFactor + (255 - aBlendFactor) * (*dataS)) >> 8; //lint !e702 Arithmetic shifting assumed |
|
123 |
|
124 if( shade < 0 ) shade = 0; |
|
125 else if( shade > 255 ) shade = 255; |
|
126 |
|
127 *dataT = TUint8(shade); |
|
128 |
|
129 dataT++; |
|
130 dataS++; |
|
131 } |
|
132 |
|
133 aTarget.UnlockHeap( ETrue ); // Unlock the global bitmap heap |
|
134 } |
|
135 }; // End of AknsRlEffectSolarize |
|
136 |
|
137 // ============================ MEMBER FUNCTIONS =============================== |
|
138 |
|
139 // ----------------------------------------------------------------------------- |
|
140 // CAknsRlEffectPluginSolarize::CAknsRlEffectPluginSolarize |
|
141 // C++ default constructor can NOT contain any code, that |
|
142 // might leave. |
|
143 // ----------------------------------------------------------------------------- |
|
144 // |
|
145 CAknsRlEffectPluginSolarize::CAknsRlEffectPluginSolarize() |
|
146 { |
|
147 } |
|
148 |
|
149 // ----------------------------------------------------------------------------- |
|
150 // Destructor |
|
151 // ----------------------------------------------------------------------------- |
|
152 // |
|
153 CAknsRlEffectPluginSolarize::~CAknsRlEffectPluginSolarize() |
|
154 { |
|
155 iContext = NULL; // Removes lint nag |
|
156 } |
|
157 |
|
158 // ----------------------------------------------------------------------------- |
|
159 // CAknsRlEffectPluginSolarize::EffectUid |
|
160 // ----------------------------------------------------------------------------- |
|
161 // |
|
162 TUid CAknsRlEffectPluginSolarize::EffectUid() const |
|
163 { |
|
164 return TUid::Uid( KAknsRlEffectPluginSolarizeUID ); |
|
165 } |
|
166 |
|
167 // ----------------------------------------------------------------------------- |
|
168 // CAknsRlEffectPluginSolarize::Effect |
|
169 // ----------------------------------------------------------------------------- |
|
170 // |
|
171 MAknsRlEffect* CAknsRlEffectPluginSolarize::Effect( const TInt aInterface ) |
|
172 { |
|
173 if( aInterface == KAknsRlEffectPluginInterfaceEffect ) |
|
174 return this; |
|
175 return NULL; |
|
176 } |
|
177 |
|
178 // ----------------------------------------------------------------------------- |
|
179 // CAknsRlEffectPluginSolarize::InitializeL |
|
180 // ----------------------------------------------------------------------------- |
|
181 // |
|
182 void CAknsRlEffectPluginSolarize::InitializeL() |
|
183 { |
|
184 iContext = NULL; |
|
185 } |
|
186 |
|
187 // ----------------------------------------------------------------------------- |
|
188 // CAknsRlEffectPluginSolarize::Release |
|
189 // ----------------------------------------------------------------------------- |
|
190 // |
|
191 void CAknsRlEffectPluginSolarize::Release() |
|
192 { |
|
193 } |
|
194 |
|
195 // ----------------------------------------------------------------------------- |
|
196 // CAknsRlEffectPluginSolarize::ActivateL |
|
197 // ----------------------------------------------------------------------------- |
|
198 // |
|
199 void CAknsRlEffectPluginSolarize::ActivateL( MAknsRlEffectContext* aContext ) |
|
200 { |
|
201 if( !aContext ) // We absolutely need the context |
|
202 { |
|
203 User::Leave( KErrArgument ); |
|
204 } |
|
205 |
|
206 iContext = aContext; |
|
207 |
|
208 iTreshold = 127; |
|
209 iBlendFactor = 255; |
|
210 iChannelMask = EMaskR | EMaskG | EMaskB; |
|
211 } |
|
212 |
|
213 // ----------------------------------------------------------------------------- |
|
214 // CAknsRlEffectPluginSolarize::Deactivate |
|
215 // ----------------------------------------------------------------------------- |
|
216 // |
|
217 void CAknsRlEffectPluginSolarize::Deactivate() |
|
218 { |
|
219 } |
|
220 |
|
221 // ----------------------------------------------------------------------------- |
|
222 // CAknsRlEffectPluginSolarize::SetParametersL |
|
223 // ----------------------------------------------------------------------------- |
|
224 // |
|
225 void CAknsRlEffectPluginSolarize::SetParametersL( MAknsRlParameterIterator& aParameters ) |
|
226 { |
|
227 // Iterate over available parameters |
|
228 while( aParameters.HasNext() ) |
|
229 { |
|
230 const TAknsRlParameterData* param = aParameters.NextL(); |
|
231 |
|
232 // Fetch treshold value |
|
233 if( param->iName->Compare( KAknsRlEffectSolarizeTreshold ) == 0 ) |
|
234 { |
|
235 if( param->iType != EAknsRlParameterTypeNumber ) |
|
236 User::Leave( KErrArgument ); |
|
237 |
|
238 iTreshold = param->iNumber; |
|
239 } |
|
240 // Fetch channel mask value |
|
241 else if( param->iName->Compare( KAknsRlEffectSolarizeChannels ) == 0 ) |
|
242 { |
|
243 if( param->iType != EAknsRlParameterTypeNumber ) |
|
244 User::Leave( KErrArgument ); |
|
245 |
|
246 iChannelMask = TUint8( param->iNumber ); |
|
247 } |
|
248 // Fetch blend factor value |
|
249 else if( param->iName->Compare( KAknsRlEffectSolarizeBlendFactor ) == 0 ) |
|
250 { |
|
251 if( param->iType != EAknsRlParameterTypeNumber ) |
|
252 User::Leave( KErrArgument ); |
|
253 |
|
254 iBlendFactor = param->iNumber; |
|
255 } |
|
256 } |
|
257 } |
|
258 |
|
259 // ----------------------------------------------------------------------------- |
|
260 // CAknsRlEffectPluginSolarize::GetCapabilities |
|
261 // ----------------------------------------------------------------------------- |
|
262 // |
|
263 void CAknsRlEffectPluginSolarize::GetCapabilities( TAknsRlEffectCaps& aCaps ) |
|
264 { |
|
265 aCaps.iOutputLayerSupport = KAknsRlLayerRGBOnly; |
|
266 aCaps.iInputLayerASupport = KAknsRlLayerRGBOnly; |
|
267 aCaps.iInputLayerBSupport = KAknsRlLayerNone; |
|
268 } |
|
269 |
|
270 // ----------------------------------------------------------------------------- |
|
271 // CAknsRlEffectPluginSolarize::Render |
|
272 // ----------------------------------------------------------------------------- |
|
273 // |
|
274 TInt CAknsRlEffectPluginSolarize::Render( const TAknsRlRenderOpParam& aParam ) |
|
275 { |
|
276 if( !iContext ) // We absolutely need the context |
|
277 { |
|
278 return KErrBadHandle; |
|
279 } |
|
280 |
|
281 // To do anything we need both, the output layer and input layer |
|
282 if( ( aParam.iOutputLayerStatus & KAknsRlLayerRGBOnly ) && |
|
283 ( aParam.iInputLayerAStatus & KAknsRlLayerRGBOnly ) ) |
|
284 { |
|
285 // Query the layers, uninitialized because we process the whole image |
|
286 TAknsRlLayerData dataTarget; |
|
287 TRAPD( err, iContext->GetLayerDataL( dataTarget, aParam.iOutputLayerIndex, |
|
288 aParam.iOutputLayerStatus, EFalse ) ); |
|
289 if( KErrNone != err ) |
|
290 return KErrArgument; |
|
291 |
|
292 TAknsRlLayerData dataSource; |
|
293 TRAP( err, iContext->GetLayerDataL( dataSource, aParam.iInputLayerAIndex, |
|
294 aParam.iInputLayerAStatus, EFalse ) ); |
|
295 if( KErrNone != err ) |
|
296 return KErrArgument; |
|
297 |
|
298 if( !dataTarget.iRGBBitmap ) // We need the target bitmap |
|
299 return KErrBadHandle; |
|
300 |
|
301 if( !dataSource.iRGBBitmap ) // We need the source bitmap |
|
302 return KErrBadHandle; |
|
303 |
|
304 TDisplayMode modeT = dataTarget.iRGBBitmap->DisplayMode(); |
|
305 TDisplayMode modeS = dataSource.iRGBBitmap->DisplayMode(); |
|
306 |
|
307 // Rgb -> Rgb modes |
|
308 if( EColor64K == modeS && EColor64K == modeT ) |
|
309 { |
|
310 AknsRlEffectSolarize<TUint16,0,5,6,5>::Process( |
|
311 *dataTarget.iRGBBitmap, |
|
312 *dataSource.iRGBBitmap, |
|
313 iTreshold, |
|
314 iChannelMask, |
|
315 iBlendFactor ); |
|
316 } |
|
317 else if( EColor16MU == modeS && EColor16MU == modeT ) |
|
318 { |
|
319 AknsRlEffectSolarize<TUint32,8,8,8,8>::Process( |
|
320 *dataTarget.iRGBBitmap, |
|
321 *dataSource.iRGBBitmap, |
|
322 iTreshold, |
|
323 iChannelMask, |
|
324 iBlendFactor ); |
|
325 } |
|
326 // Gray -> Gray mode |
|
327 else if( EGray256 == modeS && EGray256 == modeT ) |
|
328 { |
|
329 AknsRlEffectSolarizeGray::Process( |
|
330 *dataTarget.iRGBBitmap, |
|
331 *dataSource.iRGBBitmap, |
|
332 iTreshold, |
|
333 iBlendFactor ); |
|
334 } |
|
335 else |
|
336 { |
|
337 // Provided layers have illegal display mode combination |
|
338 return KErrArgument; |
|
339 } |
|
340 } |
|
341 else |
|
342 { |
|
343 // Required layers were not provided |
|
344 return KErrArgument; |
|
345 } |
|
346 |
|
347 return KErrNone; |
|
348 } |
|
349 |
|
350 // End of File |