|
1 /* |
|
2 * Copyright (c) 2005 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <e32base.h> |
|
19 #include <f32file.h> |
|
20 #include <barsc.h> |
|
21 #include <barsread.h> |
|
22 |
|
23 #include <lcdgr.h> |
|
24 #include <lcdgdrv.h> |
|
25 #include <lcdgr.rsg> |
|
26 |
|
27 |
|
28 // |
|
29 // Proxies |
|
30 // |
|
31 #include "CMIDImage.h" |
|
32 #include "CMIDGraphics.h" |
|
33 #include "CMIDImageDecoder.h" |
|
34 #include "MMIDCanvasGraphicsItemPainter.h" |
|
35 |
|
36 // |
|
37 // Implementation |
|
38 // |
|
39 #include "MidProxyMap.h" |
|
40 #include "LcdImage.h" |
|
41 #include "LcdGraphics.h" |
|
42 #include "LcdFbsImage.h" |
|
43 #include "LcdFbsImageCache.h" |
|
44 |
|
45 #include "s60commonutils.h" |
|
46 |
|
47 struct TGraphicsMode |
|
48 { |
|
49 TDisplayMode iScreenMode; |
|
50 TDisplayMode iPrimaryMode; |
|
51 TDisplayMode iTransparencyMode; |
|
52 TDisplayMode iUiColorMode; |
|
53 TDisplayMode iUiAlphaMode; |
|
54 TBool iUiInvertMask; |
|
55 }; |
|
56 |
|
57 struct TGraphicsConfig |
|
58 { |
|
59 TGraphicsMode iGraphicsMode; |
|
60 TBool iUpdateRequired; |
|
61 TBool iDoubleBuffer; |
|
62 }; |
|
63 |
|
64 TBool ValidGraphicsMode(const TGraphicsMode& aConfig); |
|
65 |
|
66 TBool IsAlpha(CFbsBitmap* aBitmap); |
|
67 |
|
68 TInt CompareScreenMode(const TGraphicsMode& aLhs, const TGraphicsMode& aRhs) |
|
69 { |
|
70 return aLhs.iScreenMode - aRhs.iScreenMode; |
|
71 } |
|
72 |
|
73 NONSHARABLE_CLASS(CMIDGraphicsFactory) : public CBase |
|
74 , public MMIDGraphicsFactory |
|
75 , private MImageTypeMap |
|
76 { |
|
77 public: |
|
78 CMIDGraphicsFactory(RFs&); |
|
79 void ConstructL(TDisplayMode); |
|
80 ~CMIDGraphicsFactory(); |
|
81 |
|
82 virtual void Dispose(); |
|
83 virtual TDisplayMode DisplayMode() const; |
|
84 virtual TBool DoubleBuffer() const; |
|
85 virtual MMIDImage* NewMutableImageL(const TSize& aSize); |
|
86 virtual MMIDImage* NewImageL(const TSize& aSize, TInt aTransparency); |
|
87 virtual MMIDImage* NewImageL(MMIDImageDecoder* aDecoder); |
|
88 virtual MMIDImage* NewImageL(MMIDCanvas* aCanvas); |
|
89 virtual MMIDGraphics* NewGraphicsL(MMIDCanvas* aCanvas); |
|
90 virtual MMIDGraphics* NewGraphicsL(MMIDCustomItem* aCustomItem); |
|
91 virtual MMIDGraphics* NewGraphicsL(MMIDImage* aImage); |
|
92 virtual MMIDGraphics* NewGraphicsL(MMIDCanvasGraphicsItemPainter* aCanvasGraphicsPainter); |
|
93 virtual MMIDImageDecoder* NewImageDecoderL(); |
|
94 |
|
95 private: |
|
96 virtual TImageType GetImageType(MMIDImage::TTransparencyType aType); |
|
97 |
|
98 private: |
|
99 void LoadConfigL(RArray<TGraphicsMode>& aModeArray, const TLinearOrder<TGraphicsMode>&); |
|
100 void ConfigureL(TGraphicsMode& aMode); |
|
101 TImageType MutableImageType() const; |
|
102 |
|
103 virtual MMIDGraphics* NewGraphicsL( |
|
104 const CFbsBitmap* aBitmap, TBool aIsImageTarget, TBool aIsCanvasGraphicsItem); |
|
105 |
|
106 private: |
|
107 RFs& iFsSession; |
|
108 CLcdGraphicsDriver* iDriver; |
|
109 CLcdFbsImageCache* iBitmapCache; |
|
110 CMIDProxyMap* iProxyMap; |
|
111 TGraphicsConfig iConfig; |
|
112 TInt iConfigError; // indicates an error when loading config from resource file |
|
113 TImageType iImageTypeArray[3]; |
|
114 }; |
|
115 |
|
116 // |
|
117 // Configuration resource file and constants. |
|
118 // |
|
119 _LIT(KLcdgrResourceFileName, "lcdgr.rsc"); |
|
120 const TInt KDefaultDisplayMode = MMIDBitmapImage::EDefaultDisplayMode; |
|
121 |
|
122 // |
|
123 // The one and only export. |
|
124 // |
|
125 EXPORT_C MMIDGraphicsFactory* NewFactoryL(RFs& aFsSession, TDisplayMode aScreenMode) |
|
126 { |
|
127 CMIDGraphicsFactory* factory = new(ELeave) CMIDGraphicsFactory(aFsSession); |
|
128 CleanupStack::PushL(factory); |
|
129 factory->ConstructL(aScreenMode); |
|
130 CleanupStack::Pop(factory); |
|
131 return factory; |
|
132 } |
|
133 |
|
134 CMIDGraphicsFactory::CMIDGraphicsFactory(RFs& aFsSession) |
|
135 : iFsSession(aFsSession) |
|
136 { |
|
137 // |
|
138 // initialize default configuration. |
|
139 // |
|
140 iConfig.iGraphicsMode.iPrimaryMode = (TDisplayMode)KDefaultDisplayMode; |
|
141 iConfig.iGraphicsMode.iTransparencyMode = (TDisplayMode)KDefaultDisplayMode; |
|
142 iConfig.iGraphicsMode.iUiColorMode = (TDisplayMode)KDefaultDisplayMode; |
|
143 iConfig.iGraphicsMode.iUiAlphaMode = (TDisplayMode)KDefaultDisplayMode; |
|
144 iConfig.iGraphicsMode.iUiInvertMask = EFalse; |
|
145 iConfig.iUpdateRequired = EFalse; |
|
146 iConfig.iDoubleBuffer = EFalse; |
|
147 } |
|
148 |
|
149 void CMIDGraphicsFactory::ConstructL(TDisplayMode aScreenMode) |
|
150 { |
|
151 // |
|
152 // Array of graphics modes sorted on screen mode. |
|
153 // |
|
154 RArray<TGraphicsMode> modeArray(4, _FOFF(TGraphicsMode, iScreenMode)); |
|
155 TLinearOrder<TGraphicsMode> screenModeOrder(CompareScreenMode); |
|
156 CleanupClosePushL(modeArray); |
|
157 TGraphicsMode mode; |
|
158 |
|
159 // |
|
160 // Load config from resource file. |
|
161 // |
|
162 TRAP(iConfigError, LoadConfigL(modeArray, screenModeOrder)); // ignore error - we'll just use defaults |
|
163 if (iConfigError) |
|
164 { |
|
165 modeArray.Reset(); |
|
166 mode.iScreenMode = aScreenMode; |
|
167 mode.iPrimaryMode = aScreenMode; |
|
168 mode.iTransparencyMode = EGray2; |
|
169 mode.iUiColorMode = aScreenMode; |
|
170 mode.iUiAlphaMode = EGray2; |
|
171 mode.iUiInvertMask = EFalse; |
|
172 modeArray.AppendL(mode); |
|
173 } |
|
174 else |
|
175 { |
|
176 mode.iScreenMode = aScreenMode; |
|
177 TInt index = modeArray.FindInOrder(mode, screenModeOrder); |
|
178 if (index < 0) |
|
179 { |
|
180 // |
|
181 // Configuration file does not list screen mode. |
|
182 // |
|
183 User::Leave(KErrNotSupported); |
|
184 } |
|
185 mode = modeArray[index]; |
|
186 } |
|
187 ASSERT(mode.iScreenMode == aScreenMode); |
|
188 |
|
189 // |
|
190 // Evaluate configuration, validating any loaded values and filling |
|
191 // in defaults. This also populates the image type array. |
|
192 // |
|
193 ConfigureL(mode); |
|
194 CleanupStack::PopAndDestroy(); // modes |
|
195 |
|
196 iDriver = CLcdGraphicsDriver::NewL(iConfig.iGraphicsMode.iPrimaryMode); |
|
197 |
|
198 // |
|
199 // Construct bitmap cache for UI controls. |
|
200 // |
|
201 iBitmapCache = CLcdFbsImageCache::NewL(*iDriver, |
|
202 iConfig.iGraphicsMode.iUiColorMode, |
|
203 iConfig.iGraphicsMode.iUiAlphaMode, |
|
204 iConfig.iGraphicsMode.iUiInvertMask); |
|
205 |
|
206 iProxyMap = new(ELeave) CMIDProxyMap; |
|
207 } |
|
208 |
|
209 CMIDGraphicsFactory::~CMIDGraphicsFactory() |
|
210 { |
|
211 if (iBitmapCache) |
|
212 { |
|
213 delete iBitmapCache; |
|
214 iBitmapCache = NULL; |
|
215 } |
|
216 if (iProxyMap) |
|
217 { |
|
218 delete iProxyMap; |
|
219 iProxyMap = NULL; |
|
220 } |
|
221 if (iDriver) |
|
222 { |
|
223 delete iDriver; |
|
224 iDriver = NULL; |
|
225 } |
|
226 } |
|
227 |
|
228 void CMIDGraphicsFactory::Dispose() |
|
229 { |
|
230 delete this; |
|
231 } |
|
232 |
|
233 TDisplayMode CMIDGraphicsFactory::DisplayMode() const |
|
234 { |
|
235 return iConfig.iGraphicsMode.iPrimaryMode; |
|
236 } |
|
237 |
|
238 TBool CMIDGraphicsFactory::DoubleBuffer() const |
|
239 { |
|
240 return iConfig.iDoubleBuffer; |
|
241 } |
|
242 |
|
243 MMIDImage* CMIDGraphicsFactory::NewMutableImageL(const TSize& aSize) |
|
244 { |
|
245 CLcdImage* image = new(ELeave) CLcdImage(*iDriver, ETrue); |
|
246 CleanupStack::PushL(image); |
|
247 image->ConstructL(aSize, MutableImageType()); |
|
248 CMIDImage* proxy = new(ELeave) CMIDImage(*iBitmapCache, *this, image); |
|
249 CleanupStack::Pop(image); |
|
250 CleanupStack::PushL(proxy); |
|
251 proxy->ConstructL(); |
|
252 CleanupStack::Pop(proxy); |
|
253 return proxy; |
|
254 } |
|
255 |
|
256 MMIDImage* CMIDGraphicsFactory::NewImageL(const TSize& aSize, TInt aTransparency) |
|
257 { |
|
258 CLcdImage* image = new(ELeave) CLcdImage(*iDriver, EFalse); |
|
259 CleanupStack::PushL(image); |
|
260 image->ConstructL(aSize, iImageTypeArray[aTransparency]); |
|
261 CMIDImage* proxy = new(ELeave) CMIDImage(*iBitmapCache, *this, image); |
|
262 CleanupStack::Pop(image); |
|
263 CleanupStack::PushL(proxy); |
|
264 proxy->ConstructL(); |
|
265 CleanupStack::Pop(proxy); |
|
266 return proxy; |
|
267 } |
|
268 |
|
269 MMIDImage* CMIDGraphicsFactory::NewImageL(MMIDImageDecoder* aDecoder) |
|
270 { |
|
271 MMIDBitmapImage* bitmapImage = aDecoder->BitmapImage(); |
|
272 if (!bitmapImage) |
|
273 { |
|
274 User::Leave(KErrArgument); |
|
275 } |
|
276 |
|
277 CFbsBitmap* colorBitmap = bitmapImage->ColorBitmap(); |
|
278 CFbsBitmap* alphaBitmap = bitmapImage->AlphaBitmap(); |
|
279 |
|
280 TInt index = MMIDImage::ENone; |
|
281 if (alphaBitmap) |
|
282 { |
|
283 if (IsAlpha(alphaBitmap)) |
|
284 { |
|
285 index = MMIDImage::EAlpha; |
|
286 } |
|
287 else |
|
288 { |
|
289 index = MMIDImage::EMask; |
|
290 } |
|
291 } |
|
292 |
|
293 CLcdImage* image = new(ELeave) CLcdImage(*iDriver, EFalse); |
|
294 CleanupStack::PushL(image); |
|
295 image->ConstructL(colorBitmap, alphaBitmap, iImageTypeArray[index]); |
|
296 CMIDImage* proxy = new(ELeave) CMIDImage(*iBitmapCache, *this, image); |
|
297 CleanupStack::Pop(image); |
|
298 CleanupStack::PushL(proxy); |
|
299 proxy->ConstructL(); |
|
300 CleanupStack::Pop(proxy); |
|
301 return proxy; |
|
302 } |
|
303 |
|
304 /** |
|
305 * Create a framebuffer image |
|
306 */ |
|
307 MMIDImage* CMIDGraphicsFactory::NewImageL(MMIDCanvas* aCanvas) |
|
308 { |
|
309 CFbsBitmap* colorBitmap = aCanvas->FrameBuffer(); |
|
310 CFbsBitmap* alphaBitmap = NULL; |
|
311 |
|
312 if (NULL == colorBitmap) |
|
313 { |
|
314 User::Leave(KErrNotSupported); |
|
315 } |
|
316 |
|
317 CLcdImage* image = new(ELeave) CLcdImage(*iDriver, ETrue); |
|
318 CleanupStack::PushL(image); |
|
319 image->ConstructL(colorBitmap, alphaBitmap, MutableImageType()); |
|
320 CMIDImage* proxy = new(ELeave) CMIDImage(*iBitmapCache, *this, image); |
|
321 CleanupStack::Pop(image); |
|
322 CleanupStack::PushL(proxy); |
|
323 proxy->ConstructL(); |
|
324 CleanupStack::Pop(proxy); |
|
325 return proxy; |
|
326 } |
|
327 |
|
328 |
|
329 #ifdef RD_JAVA_NGA_ENABLED |
|
330 // --------------------------------------------------------------------------- |
|
331 // NGA extension |
|
332 // --------------------------------------------------------------------------- |
|
333 // |
|
334 MMIDGraphics* CMIDGraphicsFactory::NewGraphicsL(MMIDCanvas* aCanvas) |
|
335 { |
|
336 CLcdGraphics* graphics = CLcdGraphics::NewL(*iDriver, aCanvas->FrameBuffer()); |
|
337 CleanupStack::PushL(graphics); |
|
338 CMIDGraphics* proxy = new(ELeave) CMIDGraphics(*iProxyMap, graphics, EFalse, aCanvas); |
|
339 CleanupStack::Pop(graphics); |
|
340 return proxy; |
|
341 } |
|
342 |
|
343 #else // !RD_JAVA_NGA_ENABLED |
|
344 |
|
345 MMIDGraphics* CMIDGraphicsFactory::NewGraphicsL(MMIDCanvas* aCanvas) |
|
346 { |
|
347 CCoeControl& window = aCanvas->Control(); |
|
348 MDirectContainer& container = aCanvas->DirectContainer(); |
|
349 |
|
350 CLcdGraphics* graphics = CLcdGraphics::NewL(*iDriver, window, container, iConfig.iUpdateRequired); |
|
351 CleanupStack::PushL(graphics); |
|
352 CMIDGraphics* proxy = new(ELeave) CMIDGraphics(*iProxyMap, graphics, EFalse); |
|
353 CleanupStack::Pop(graphics); |
|
354 return proxy; |
|
355 } |
|
356 #endif // RD_JAVA_NGA_ENABLED |
|
357 |
|
358 MMIDGraphics* CMIDGraphicsFactory::NewGraphicsL(MMIDCustomItem* aCustomItem) |
|
359 { |
|
360 return NewGraphicsL(aCustomItem->FrameBuffer(), EFalse, EFalse); |
|
361 } |
|
362 |
|
363 MMIDGraphics* CMIDGraphicsFactory::NewGraphicsL(MMIDImage* aImage) |
|
364 { |
|
365 // |
|
366 // All mutable images must be registered bitmap images as we currently |
|
367 // rely on BITGDI to render many primitives. |
|
368 // |
|
369 // We could have a separate map for mutable images if necessary. |
|
370 // |
|
371 MMIDBitmapImage* image = iBitmapCache->GetBitmapImage(aImage); |
|
372 ASSERT(image); |
|
373 MMIDGraphics* graphics = NewGraphicsL(image->ColorBitmap(), ETrue, EFalse); |
|
374 |
|
375 //Graphics duplicates the fbs handle. |
|
376 image->RemoveRef(); |
|
377 return graphics; |
|
378 } |
|
379 |
|
380 MMIDGraphics* CMIDGraphicsFactory::NewGraphicsL(MMIDCanvasGraphicsItemPainter* aCanvasGraphicsItemPainter) |
|
381 { |
|
382 return NewGraphicsL(aCanvasGraphicsItemPainter->FrameBuffer(), EFalse, ETrue); |
|
383 } |
|
384 |
|
385 MMIDGraphics* CMIDGraphicsFactory::NewGraphicsL( |
|
386 const CFbsBitmap* aBitmap, TBool aIsImageTarget, TBool aIsCanvasGraphicsItem) |
|
387 |
|
388 { |
|
389 if (NULL == aBitmap) |
|
390 { |
|
391 User::Leave(KErrArgument); |
|
392 } |
|
393 |
|
394 if (aBitmap->DisplayMode() != iConfig.iGraphicsMode.iPrimaryMode) |
|
395 { |
|
396 User::Leave(KErrArgument); |
|
397 } |
|
398 |
|
399 CLcdGraphics* graphics = CLcdGraphics::NewL(*iDriver, aBitmap); |
|
400 CleanupStack::PushL(graphics); |
|
401 CMIDGraphics* proxy = new(ELeave) CMIDGraphics(*iProxyMap, graphics, aIsImageTarget); |
|
402 CleanupStack::Pop(graphics); |
|
403 |
|
404 // CLcdGraphics instance has to know that rendering target bitmap is framebuffer |
|
405 // of CanavsGraphicsItem. Its because drawing images its not allowed to |
|
406 // transparent target and CanvasGraphicsItem is transparent by default. |
|
407 graphics->SetCanvasGraphicsItemtarget(aIsCanvasGraphicsItem); |
|
408 |
|
409 return proxy; |
|
410 } |
|
411 |
|
412 MMIDImageDecoder* CMIDGraphicsFactory::NewImageDecoderL() |
|
413 { |
|
414 CMIDImageDecoder* decoder = new(ELeave) CMIDImageDecoder(iFsSession, DisplayMode()); |
|
415 CleanupStack::PushL(decoder); |
|
416 decoder->ConstructL(); |
|
417 CleanupStack::Pop(decoder); |
|
418 return decoder; |
|
419 } |
|
420 |
|
421 void CMIDGraphicsFactory::LoadConfigL(RArray<TGraphicsMode>& aModeArray, const TLinearOrder<TGraphicsMode>& aOrder) |
|
422 { |
|
423 TFileName fileName; |
|
424 |
|
425 fileName.Append(KLcdgrResourceFileName); |
|
426 fileName = java::util::S60CommonUtils::ResourceLanguageFileNameL(fileName); |
|
427 |
|
428 RResourceFile configFile; |
|
429 configFile.OpenL(iFsSession, fileName); |
|
430 CleanupClosePushL(configFile); |
|
431 configFile.ConfirmSignatureL(); |
|
432 |
|
433 // |
|
434 // read R_GRAPHICS_CONFIG |
|
435 // |
|
436 |
|
437 // |
|
438 // WARNING! TResourceReader will panic or endless loop on error |
|
439 // (e.g. if the config file is corrupt). |
|
440 // |
|
441 |
|
442 HBufC8* resourceData = configFile.AllocReadLC(R_GRAPHICS_CONFIG); |
|
443 TResourceReader reader; |
|
444 reader.SetBuffer(resourceData); |
|
445 |
|
446 int count = reader.ReadInt16(); |
|
447 for (int i=0; i<count; i++) |
|
448 { |
|
449 TGraphicsMode mode; |
|
450 mode.iScreenMode = (TDisplayMode)reader.ReadInt16(); |
|
451 mode.iPrimaryMode = (TDisplayMode)reader.ReadInt16(); |
|
452 mode.iTransparencyMode = (TDisplayMode)reader.ReadInt16(); |
|
453 mode.iUiColorMode = (TDisplayMode)reader.ReadInt16(); |
|
454 mode.iUiAlphaMode = (TDisplayMode)reader.ReadInt16(); |
|
455 mode.iUiInvertMask = (TBool)reader.ReadInt16(); |
|
456 aModeArray.InsertInOrderL(mode, aOrder); |
|
457 } |
|
458 |
|
459 iConfig.iUpdateRequired = (TBool)reader.ReadInt16(); |
|
460 iConfig.iDoubleBuffer = (TBool)reader.ReadInt16(); |
|
461 |
|
462 CleanupStack::PopAndDestroy(resourceData); |
|
463 |
|
464 CleanupStack::PopAndDestroy(); //configFile |
|
465 } |
|
466 |
|
467 |
|
468 void CMIDGraphicsFactory::ConfigureL(TGraphicsMode& aMode) |
|
469 { |
|
470 // |
|
471 // Fill in defaulted values. |
|
472 // |
|
473 if (aMode.iPrimaryMode == KDefaultDisplayMode) |
|
474 { |
|
475 aMode.iPrimaryMode = aMode.iScreenMode; |
|
476 } |
|
477 |
|
478 if (aMode.iTransparencyMode == KDefaultDisplayMode) |
|
479 { |
|
480 if (aMode.iPrimaryMode == EColor16MA) |
|
481 { |
|
482 aMode.iTransparencyMode = ENone; |
|
483 } |
|
484 else |
|
485 { |
|
486 aMode.iTransparencyMode = EGray2; |
|
487 } |
|
488 } |
|
489 |
|
490 // |
|
491 // Validate the configuration. |
|
492 // |
|
493 |
|
494 if (aMode.iUiColorMode == KDefaultDisplayMode) |
|
495 { |
|
496 aMode.iUiColorMode = aMode.iPrimaryMode; |
|
497 } |
|
498 |
|
499 if (aMode.iUiAlphaMode == KDefaultDisplayMode) |
|
500 { |
|
501 aMode.iUiAlphaMode = EGray2; |
|
502 } |
|
503 |
|
504 if (!ValidGraphicsMode(aMode)) |
|
505 { |
|
506 User::Leave(KErrNotSupported); |
|
507 } |
|
508 |
|
509 iConfig.iGraphicsMode = aMode; |
|
510 |
|
511 // |
|
512 // configure opaque image type |
|
513 // |
|
514 iImageTypeArray[MMIDImage::ENone].iColorMode = aMode.iPrimaryMode; |
|
515 iImageTypeArray[MMIDImage::ENone].iAlphaMode = ENone; |
|
516 iImageTypeArray[MMIDImage::ENone].iTransparency = ETransparencyNone; |
|
517 |
|
518 // |
|
519 // Configure transparent image type |
|
520 // |
|
521 iImageTypeArray[MMIDImage::EMask].iColorMode = aMode.iPrimaryMode; |
|
522 if (aMode.iPrimaryMode == EColor16MA) |
|
523 { |
|
524 iImageTypeArray[MMIDImage::EMask].iAlphaMode = ENone; |
|
525 iImageTypeArray[MMIDImage::EMask].iTransparency = ETransparencyMaskChannel; |
|
526 } |
|
527 else |
|
528 { |
|
529 iImageTypeArray[MMIDImage::EMask].iAlphaMode = aMode.iTransparencyMode; |
|
530 iImageTypeArray[MMIDImage::EMask].iTransparency = ETransparencyMaskBitmap; |
|
531 } |
|
532 |
|
533 // |
|
534 // Configure alpha image type |
|
535 // |
|
536 iImageTypeArray[MMIDImage::EAlpha].iColorMode = aMode.iPrimaryMode; |
|
537 if (aMode.iPrimaryMode == EColor16MA) |
|
538 { |
|
539 iImageTypeArray[MMIDImage::EAlpha].iAlphaMode = ENone; |
|
540 iImageTypeArray[MMIDImage::EAlpha].iTransparency = ETransparencyAlphaChannel; |
|
541 } |
|
542 else |
|
543 { |
|
544 iImageTypeArray[MMIDImage::EAlpha].iAlphaMode = EGray256; |
|
545 iImageTypeArray[MMIDImage::EAlpha].iTransparency = ETransparencyAlphaBitmap; |
|
546 } |
|
547 |
|
548 iConfig.iGraphicsMode = aMode; |
|
549 |
|
550 #ifdef __WINS__ |
|
551 iConfig.iUpdateRequired = ETrue; |
|
552 #endif |
|
553 } |
|
554 |
|
555 TImageType CMIDGraphicsFactory::MutableImageType() const |
|
556 { |
|
557 return iImageTypeArray[MMIDImage::ENone]; |
|
558 } |
|
559 |
|
560 TBool ValidGraphicsMode(const TGraphicsMode& aMode) |
|
561 { |
|
562 if (aMode.iPrimaryMode == EColor16MA) |
|
563 { |
|
564 if (aMode.iTransparencyMode != ENone) |
|
565 { |
|
566 return EFalse; |
|
567 } |
|
568 } |
|
569 else |
|
570 { |
|
571 // transparency alpha mode must be EGray2 or matched mode. |
|
572 if ((aMode.iTransparencyMode != EGray2) && (aMode.iTransparencyMode != aMode.iPrimaryMode)) |
|
573 { |
|
574 return EFalse; |
|
575 } |
|
576 } |
|
577 |
|
578 return ETrue; |
|
579 } |
|
580 |
|
581 TBool IsAlpha(CFbsBitmap* aBitmap) |
|
582 { |
|
583 TBool alpha = EFalse; |
|
584 |
|
585 if (aBitmap->DisplayMode() == EGray256) |
|
586 { |
|
587 TSize size = aBitmap->SizeInPixels(); |
|
588 TInt scan = CFbsBitmap::ScanLineLength(size.iWidth, EGray256); |
|
589 |
|
590 aBitmap->LockHeap(); |
|
591 |
|
592 TUint8* address = (TUint8*)aBitmap->DataAddress(); |
|
593 for (TInt h = size.iHeight; --h>=0;) |
|
594 { |
|
595 TUint8* pix = address; |
|
596 TUint8* end = address + size.iWidth; |
|
597 while (pix < end) |
|
598 { |
|
599 TUint8 value = *pix++; |
|
600 if ((value > 0) && (value < 255)) |
|
601 { |
|
602 alpha = ETrue; |
|
603 goto endLoop; |
|
604 } |
|
605 } |
|
606 address += scan; |
|
607 } |
|
608 |
|
609 endLoop: |
|
610 |
|
611 aBitmap->UnlockHeap(); |
|
612 } |
|
613 |
|
614 return alpha; |
|
615 } |
|
616 |
|
617 #define TYPE_ARRAY_SIZE (sizeof(iImageTypeArray)/sizeof(iImageTypeArray[0])) |
|
618 |
|
619 TImageType CMIDGraphicsFactory::GetImageType(MMIDImage::TTransparencyType aType) |
|
620 { |
|
621 ASSERT((0 <= aType) && (aType < TYPE_ARRAY_SIZE)); |
|
622 return iImageTypeArray[ aType ]; |
|
623 } |