42 |
42 |
43 // --------------------------------------------------------- |
43 // --------------------------------------------------------- |
44 // CWmImageConverter::NewL |
44 // CWmImageConverter::NewL |
45 // --------------------------------------------------------- |
45 // --------------------------------------------------------- |
46 // |
46 // |
47 CWmImageConverter* CWmImageConverter::NewL( MConverterObserver* aObserver ) |
47 CWmImageConverter* CWmImageConverter::NewL() |
48 { |
48 { |
49 CWmImageConverter* self = |
49 CWmImageConverter* self = |
50 new(ELeave) CWmImageConverter(); |
50 new(ELeave) CWmImageConverter(); |
51 CleanupStack::PushL( self ); |
51 CleanupStack::PushL( self ); |
52 self->ConstructL( aObserver ); |
52 self->ConstructL(); |
53 CleanupStack::Pop(self); |
53 CleanupStack::Pop(self); |
54 return self; |
54 return self; |
55 } |
55 } |
56 |
56 |
57 // --------------------------------------------------------- |
57 // --------------------------------------------------------- |
58 // CWmImageConverter::CWmImageConverter |
58 // CWmImageConverter::CWmImageConverter |
59 // --------------------------------------------------------- |
59 // --------------------------------------------------------- |
60 // |
60 // |
61 CWmImageConverter::CWmImageConverter() |
61 CWmImageConverter::CWmImageConverter() |
62 : CActive( EPriorityStandard ) |
62 { |
63 { |
|
64 iState = EIdle; |
|
65 iBitmap = NULL; |
63 iBitmap = NULL; |
66 iMask = NULL; |
64 iMask = NULL; |
67 iObserver = NULL; |
|
68 iConversionMethod = EUnrecognized; |
|
69 CActiveScheduler::Add( this ); |
|
70 } |
65 } |
71 |
66 |
72 // --------------------------------------------------------- |
67 // --------------------------------------------------------- |
73 // CWmImageConverter::ConstructL |
68 // CWmImageConverter::ConstructL |
74 // --------------------------------------------------------- |
69 // --------------------------------------------------------- |
75 // |
70 // |
76 void CWmImageConverter::ConstructL( MConverterObserver* aObserver ) |
71 void CWmImageConverter::ConstructL() |
77 { |
72 { |
78 User::LeaveIfError( iFs.Connect() ); |
73 User::LeaveIfError( iFs.Connect() ); |
79 iFs.ShareProtected(); |
74 iFs.ShareProtected(); |
80 iScaler = CBitmapScaler::NewL(); |
|
81 iObserver = aObserver; |
|
82 } |
75 } |
83 |
76 |
84 // --------------------------------------------------------- |
77 // --------------------------------------------------------- |
85 // CWmImageConverter::~CWmImageConverter |
78 // CWmImageConverter::~CWmImageConverter |
86 // --------------------------------------------------------- |
79 // --------------------------------------------------------- |
87 // |
80 // |
88 CWmImageConverter::~CWmImageConverter() |
81 CWmImageConverter::~CWmImageConverter() |
89 { |
82 { |
90 Cancel(); |
|
91 delete iImageDecoder; |
|
92 iFs.Close(); |
83 iFs.Close(); |
93 if ( iBitmap ) |
84 if ( iBitmap ) |
94 { |
85 { |
95 delete iBitmap; |
86 delete iBitmap; |
96 iBitmap = NULL; |
87 iBitmap = NULL; |
125 { |
127 { |
126 delete iMask; |
128 delete iMask; |
127 iMask = NULL; |
129 iMask = NULL; |
128 } |
130 } |
129 } |
131 } |
|
132 |
130 return err; |
133 return err; |
131 } |
134 } |
132 |
135 |
133 // --------------------------------------------------------- |
136 // --------------------------------------------------------- |
134 // CWmImageConverter::HandleIconStringL |
137 // CWmImageConverter::HandleIconStringL |
135 // --------------------------------------------------------- |
138 // --------------------------------------------------------- |
136 // |
139 // |
137 void CWmImageConverter::HandleIconStringL( |
140 void CWmImageConverter::HandleIconStringL( |
138 TInt aWidth, TInt aHeight, |
141 const TSize& aIconSize, |
139 const TDesC& aIconStr ) |
142 const TDesC& aIconStr ) |
140 { |
143 { |
141 iConversionMethod = EUnrecognized; |
|
142 iState = EDecoding; |
|
143 if ( aIconStr.Length() ) |
144 if ( aIconStr.Length() ) |
144 { |
145 { |
145 TAknsItemID skinItemId; |
146 TAknsItemID skinItemId; |
146 skinItemId.iMajor = 0; |
147 skinItemId.iMajor = 0; |
147 skinItemId.iMinor = 0; |
148 skinItemId.iMinor = 0; |
148 TInt bitmapId( KErrNotFound ); |
149 TInt bitmapId( KErrNotFound ); |
149 TInt maskId( KErrNotFound ); |
150 TInt maskId( KErrNotFound ); |
150 TUid appUid; |
151 TUid appUid; |
151 iFilename = KNullDesC; |
152 iFilename = KNullDesC; |
152 iScaleNeeded = EFalse; |
153 iSize = aIconSize; |
153 iSize.SetSize( aWidth, aHeight ); |
|
154 |
154 |
155 if ( ResolveSkinIdAndMifId( |
155 if ( ResolveSkinIdAndMifId( |
156 aIconStr, skinItemId, bitmapId, maskId, iFilename ) ) |
156 aIconStr, skinItemId, bitmapId, maskId, iFilename ) ) |
157 { |
157 { |
158 if ( bitmapId >= 0 && skinItemId.iMajor > 0 ) |
|
159 iConversionMethod = ESkinAndMifIcon; |
|
160 else if ( bitmapId >= 0 ) |
|
161 iConversionMethod = EMifIcon; |
|
162 else |
|
163 iConversionMethod = ESkinIcon; |
|
164 CreateSkinOrMifIconL( |
158 CreateSkinOrMifIconL( |
165 skinItemId, bitmapId, maskId, iFilename ); |
159 skinItemId, bitmapId, maskId, iFilename ); |
166 } |
160 } |
167 else if ( ResolveUid( aIconStr, appUid ) ) |
161 else if ( ResolveUid( aIconStr, appUid ) ) |
168 { |
162 { |
169 iConversionMethod = EUidIcon; |
|
170 CreateIconFromUidL( appUid ); |
163 CreateIconFromUidL( appUid ); |
171 } |
164 } |
172 else if ( EndsWith( aIconStr, KSvgExt ) ) |
165 else if ( EndsWith( aIconStr, KSvgExt ) ) |
173 { |
166 { |
174 // filename_with_full_path.svg |
167 // filename_with_full_path.svg |
175 iConversionMethod = ESvgIcon; |
|
176 CreateIconFromSvgL( aIconStr ); |
168 CreateIconFromSvgL( aIconStr ); |
177 } |
169 } |
178 else if ( BaflUtils::FileExists( iFs, aIconStr ) ) |
170 else if ( BaflUtils::FileExists( iFs, aIconStr ) ) |
179 { |
171 { |
180 // filename_with_full_path.png/jpg |
172 // filename_with_full_path.png/jpg |
181 iConversionMethod = EImageIcon; |
|
182 CreateIconFromOtherL( aIconStr ); |
173 CreateIconFromOtherL( aIconStr ); |
183 } |
174 } |
184 else |
175 else |
185 { |
176 { |
186 User::Leave( KErrArgument ); |
177 User::Leave( KErrArgument ); |
361 CleanupStack::PopAndDestroy( svgEngine ); |
331 CleanupStack::PopAndDestroy( svgEngine ); |
362 CleanupStack::PopAndDestroy( frameBuffer ); |
332 CleanupStack::PopAndDestroy( frameBuffer ); |
363 |
333 |
364 iBitmap = bitmap; |
334 iBitmap = bitmap; |
365 iMask = mask; |
335 iMask = mask; |
366 iState = EIdle; |
|
367 iObserver->NotifyCompletion( KErrNone ); |
|
368 } |
|
369 |
|
370 // --------------------------------------------------------- |
|
371 // CWmImageConverter::CheckSvgErrorL |
|
372 // --------------------------------------------------------- |
|
373 // |
|
374 void CWmImageConverter::CheckSvgErrorL( MSvgError* aError ) |
|
375 { |
|
376 if ( aError ) |
|
377 { |
|
378 User::LeaveIfError( aError->SystemErrorCode() ); |
|
379 } |
|
380 } |
336 } |
381 |
337 |
382 // --------------------------------------------------------- |
338 // --------------------------------------------------------- |
383 // CWmImageConverter::CreateIconFromOtherL |
339 // CWmImageConverter::CreateIconFromOtherL |
384 // --------------------------------------------------------- |
340 // --------------------------------------------------------- |
385 // |
341 // |
386 void CWmImageConverter::CreateIconFromOtherL( const TDesC& aFileName ) |
342 void CWmImageConverter::CreateIconFromOtherL( const TDesC& aFileName ) |
387 { |
343 { |
388 if ( IsActive() ) |
|
389 { |
|
390 User::Leave( KErrNotReady ); |
|
391 } |
|
392 |
|
393 if ( iImageDecoder ) delete iImageDecoder; iImageDecoder = NULL; |
|
394 if (iBitmap) {delete iBitmap; iBitmap = NULL;} |
344 if (iBitmap) {delete iBitmap; iBitmap = NULL;} |
395 if (iMask) {delete iMask; iMask = NULL;} |
345 if (iMask) {delete iMask; iMask = NULL;} |
396 |
346 |
397 iFilename.Copy( aFileName ); |
347 iFilename.Copy( aFileName ); |
398 |
348 |
399 // create the decoder |
349 // create the decoder |
400 iImageDecoder = CImageDecoder::FileNewL( iFs, iFilename ); |
350 CImageDecoder* imageDecoder = CImageDecoder::FileNewL( |
401 |
351 iFs, iFilename, CImageDecoder::EOptionAlwaysThread ); |
402 TSize size = iImageDecoder->FrameInfo().iOverallSizeInPixels; |
352 CleanupStack::PushL( imageDecoder ); |
|
353 |
|
354 TSize size = imageDecoder->FrameInfo().iOverallSizeInPixels; |
403 |
355 |
404 // create the destination bitmap |
356 // create the destination bitmap |
405 iBitmap = new (ELeave) CFbsBitmap(); |
357 iBitmap = new (ELeave) CFbsBitmap(); |
406 iBitmap->Create( size, |
358 User::LeaveIfError( iBitmap->Create( |
407 iImageDecoder->FrameInfo().iFrameDisplayMode ); |
359 size, imageDecoder->FrameInfo().iFrameDisplayMode ) ); |
408 |
360 |
409 iMask = new (ELeave) CFbsBitmap(); |
361 iMask = new (ELeave) CFbsBitmap(); |
410 iMask->Create( size, EGray256 ); |
362 User::LeaveIfError( iMask->Create( size, EGray256 ) ); |
411 |
363 |
412 if ( size != iSize ) |
|
413 { |
|
414 iScaleNeeded = ETrue; |
|
415 } |
|
416 |
|
417 // start conversion to bitmap |
364 // start conversion to bitmap |
418 iImageDecoder->Convert( &iStatus, *iBitmap, *iMask ); |
365 TRequestStatus status; |
419 SetActive(); |
366 imageDecoder->Convert( &status, *iBitmap, *iMask ); |
420 } |
367 User::WaitForRequest( status ); |
421 |
368 if( status.Int() == KErrUnderflow ) |
422 // --------------------------------------------------------- |
369 { |
423 // CWmImageConverter::DoCancel |
370 imageDecoder->ContinueConvert( &status ); |
424 // --------------------------------------------------------- |
371 User::WaitForRequest( status ); |
425 // |
372 } |
426 void CWmImageConverter::DoCancel() |
373 User::LeaveIfError( status.Int() ); |
427 { |
374 CleanupStack::PopAndDestroy( imageDecoder ); |
428 if( iState == EDecoding && |
375 } |
429 iConversionMethod == EImageIcon ) |
376 |
430 { |
377 // --------------------------------------------------------------------------- |
431 iImageDecoder->Cancel(); |
378 // CWmImageConverter::CreateSkinOrMifIconL |
432 iState = EIdle; |
379 // --------------------------------------------------------------------------- |
433 if ( iObserver ) |
380 // |
434 { |
381 void CWmImageConverter::CreateSkinOrMifIconL( |
435 iObserver->NotifyCompletion( KErrCancel ); |
382 const TAknsItemID& aItemId, TInt aBitmapId, |
436 } |
383 TInt aMaskId, const TDesC& aFileName ) |
437 } |
384 { |
438 else if( iState == EScalingBitmap || |
385 iFilename = aFileName; |
439 iState == EScalingMask ) |
386 CFbsBitmap* bitmap = NULL; |
440 { |
387 CFbsBitmap* mask = NULL; |
441 iScaler->Cancel(); |
388 |
442 iState = EIdle; |
389 // Load from skin |
443 if ( iObserver ) |
390 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
444 { |
391 if ( skin && aItemId.iMajor != 0 && aItemId.iMinor != 0 ) |
445 iObserver->NotifyCompletion( KErrCancel ); |
392 { |
446 } |
393 TInt err( KErrNone ); |
447 } |
394 CAknsMaskedBitmapItemData* itemData = NULL; |
448 else |
395 TRAP( err, itemData = |
449 { |
396 static_cast<CAknsMaskedBitmapItemData*>( |
450 // State is EIdle, do nothing |
397 skin->CreateUncachedItemDataL( aItemId, EAknsITMaskedBitmap ) ); ); |
451 } |
398 if( itemData && KErrNone == err ) |
452 iScaleNeeded = EFalse; |
399 { |
453 } |
400 CleanupStack::PushL( itemData ); |
454 |
401 // Detach bitmaps |
455 // --------------------------------------------------------- |
402 bitmap = itemData->Bitmap(); |
456 // CWmImageConverter::RunL |
403 itemData->SetBitmap( NULL ); |
457 // --------------------------------------------------------- |
404 mask = itemData->Mask(); |
458 // |
405 itemData->SetMask( NULL ); |
459 void CWmImageConverter::RunL() |
406 CleanupStack::PopAndDestroy( itemData ); |
460 { |
407 } |
461 switch( iState ) |
408 else |
462 { |
409 { |
463 case EDecoding: |
410 // look in imagetable |
464 { |
411 CAknsImageTableItemData* iconData = NULL; |
465 if( iStatus.Int() == KErrNone ) |
412 TRAP( err, iconData = static_cast<CAknsImageTableItemData*>( |
|
413 skin->CreateUncachedItemDataL( aItemId, EAknsITImageTable ) ); ); |
|
414 if( iconData && KErrNone == err ) |
466 { |
415 { |
467 if ( iScaleNeeded ) |
416 CleanupStack::PushL( iconData ); |
|
417 if( iconData->NumberOfImages() ) |
|
418 { |
|
419 TAknsItemID iconIId; |
|
420 iconIId.Set( iconData->ImageIID(0) ); |
|
421 TRAP( err, AknsUtils::CreateIconL( |
|
422 skin, iconIId, bitmap, mask, KNullDesC, -1, -1 ); ); |
|
423 } |
|
424 CleanupStack::PopAndDestroy( iconData ); |
|
425 } |
|
426 } |
|
427 |
|
428 if ( KErrNone == err && bitmap ) |
|
429 { |
|
430 TInt err = AknIconUtils::SetSize( |
|
431 bitmap, |
|
432 iSize, |
|
433 EAspectRatioPreserved ); |
|
434 if ( KErrNone == err ) |
|
435 { |
|
436 if ( mask ) |
468 { |
437 { |
469 ScaleBitmap( iSize.iWidth, iSize.iHeight ); |
438 err = AknIconUtils::SetSize( |
|
439 mask, |
|
440 iSize, |
|
441 EAspectRatioPreserved ); |
470 } |
442 } |
471 else |
443 iBitmap = bitmap; |
472 { |
444 iMask = mask; |
473 iState = EIdle; |
445 return; |
474 if ( iObserver ) |
|
475 { |
|
476 iObserver->NotifyCompletion( KErrNone ); |
|
477 } |
|
478 } |
|
479 break; |
|
480 } |
|
481 else if( iStatus.Int() == KErrUnderflow ) |
|
482 { |
|
483 iImageDecoder->ContinueConvert( &iStatus ); |
|
484 SetActive(); |
|
485 break; |
|
486 } |
|
487 else if ( iStatus.Int() == KErrCorrupt ) |
|
488 { |
|
489 iState = EIdle; |
|
490 iScaleNeeded = EFalse; |
|
491 if ( iBitmap ) |
|
492 { |
|
493 delete iBitmap; |
|
494 iBitmap = NULL; |
|
495 } |
|
496 if ( iMask ) |
|
497 { |
|
498 delete iMask; |
|
499 iMask = NULL; |
|
500 } |
|
501 if ( iObserver ) |
|
502 { |
|
503 iObserver->NotifyCompletion( KErrCorrupt ); |
|
504 } |
|
505 break; |
|
506 } |
446 } |
507 else |
447 else |
508 { |
448 { |
509 // Unknown error |
449 if ( bitmap ) { delete bitmap; bitmap = NULL; } |
510 iState = EIdle; |
450 if ( mask ){ delete mask; mask = NULL; } |
511 iScaleNeeded = EFalse; |
|
512 if ( iBitmap ) |
|
513 { |
|
514 delete iBitmap; |
|
515 iBitmap = NULL; |
|
516 } |
|
517 if ( iMask ) |
|
518 { |
|
519 delete iMask; |
|
520 iMask = NULL; |
|
521 } |
|
522 if ( iObserver ) |
|
523 { |
|
524 iObserver->NotifyCompletion( iStatus.Int() ); |
|
525 } |
|
526 break; |
|
527 } |
451 } |
528 } |
452 } |
529 case EScalingBitmap: |
453 } |
530 { |
454 |
531 if( iStatus.Int() == KErrNone && iMask ) |
455 if( aBitmapId != KErrNotFound && !bitmap && |
532 { |
456 aFileName.Length() && BaflUtils::FileExists( iFs, aFileName ) ) |
533 ScaleMask( iSize.iWidth, iSize.iHeight ); |
457 { |
534 } |
458 if ( aMaskId != KErrNotFound ) |
535 else |
459 { |
536 { |
460 // Create icon from Mif filename , bitmap id and mask id |
537 iState = EIdle; |
461 AknIconUtils::CreateIconL( |
538 iScaleNeeded = EFalse; |
462 bitmap, mask, *this, aBitmapId, aMaskId ); |
539 if ( iObserver ) |
463 } |
540 { |
464 else |
541 iObserver->NotifyCompletion( iStatus.Int() ); |
465 { |
542 } |
466 bitmap = AknIconUtils::CreateIconL( *this, aBitmapId ); |
543 } |
467 } |
544 break; |
468 } |
545 } |
469 else |
546 case EScalingMask: |
470 { |
547 { |
471 User::Leave( KErrArgument ); |
548 iState = EIdle; |
472 } |
549 iScaleNeeded = EFalse; |
473 |
550 if ( iObserver ) |
474 iBitmap = bitmap; |
551 { |
475 iMask = mask; |
552 iObserver->NotifyCompletion( iStatus.Int() ); |
476 |
553 } |
477 TInt err = AknIconUtils::SetSize( iBitmap , iSize, EAspectRatioPreserved ); |
554 break; |
478 if ( KErrNone == err && iMask ) |
555 } |
479 { |
556 default: |
480 err = AknIconUtils::SetSize( iMask , iSize, EAspectRatioPreserved ); |
557 break; |
481 } |
558 } |
482 } |
559 } |
483 |
560 |
484 // --------------------------------------------------------- |
561 // --------------------------------------------------------- |
485 // CWmImageConverter::CheckSvgErrorL |
562 // CWmImageConverter::RunError |
486 // --------------------------------------------------------- |
563 // --------------------------------------------------------- |
487 // |
564 // |
488 void CWmImageConverter::CheckSvgErrorL( MSvgError* aError ) |
565 TInt CWmImageConverter::RunError(TInt /*aError*/) |
489 { |
566 { |
490 if ( aError ) |
567 // Our RunL does not contain any method calls that would leave, so this method |
491 { |
568 // should never be called. |
492 User::LeaveIfError( aError->SystemErrorCode() ); |
569 iScaleNeeded = EFalse; |
493 } |
570 return KErrNone; |
|
571 } |
|
572 |
|
573 // --------------------------------------------------------- |
|
574 // CWmImageConverter::ScaleBitmap |
|
575 // --------------------------------------------------------- |
|
576 // |
|
577 void CWmImageConverter::ScaleBitmap( TInt aWidth, TInt aHeight ) |
|
578 { |
|
579 if ( !IsActive() && |
|
580 iBitmap && |
|
581 ( iState == EDecoding || iState == EIdle ) ) |
|
582 { |
|
583 iState = EScalingBitmap; |
|
584 // the maintain aspect ratio is by default set to true |
|
585 iScaler->Scale( &iStatus, *iBitmap, TSize( aWidth,aHeight ), EFalse ); |
|
586 SetActive(); |
|
587 } |
|
588 } |
|
589 |
|
590 // --------------------------------------------------------- |
|
591 // CWmImageConverter::ScaleMask |
|
592 // --------------------------------------------------------- |
|
593 // |
|
594 void CWmImageConverter::ScaleMask( TInt aWidth, TInt aHeight ) |
|
595 { |
|
596 if ( !IsActive() && |
|
597 iState == EScalingBitmap && |
|
598 iMask ) |
|
599 { |
|
600 iState = EScalingMask; |
|
601 // the maintain aspect ratio is by default set to true |
|
602 iScaler->Scale( &iStatus, *iMask, TSize(aWidth,aHeight), EFalse ); |
|
603 SetActive(); |
|
604 } |
|
605 } |
|
606 |
|
607 // --------------------------------------------------------- |
|
608 // CWmImageConverter::Bitmap |
|
609 // --------------------------------------------------------- |
|
610 // |
|
611 CFbsBitmap* CWmImageConverter::Bitmap() |
|
612 { |
|
613 CFbsBitmap* bitmap = NULL; |
|
614 if (iState == EIdle && |
|
615 iBitmap ) |
|
616 { |
|
617 bitmap = iBitmap; // ownership taken |
|
618 iBitmap = NULL; |
|
619 } |
|
620 return bitmap; |
|
621 } |
|
622 |
|
623 // --------------------------------------------------------- |
|
624 // CWmImageConverter::Mask |
|
625 // --------------------------------------------------------- |
|
626 // |
|
627 CFbsBitmap* CWmImageConverter::Mask() |
|
628 { |
|
629 CFbsBitmap* mask = NULL; |
|
630 if (iState == EIdle && |
|
631 iMask ) |
|
632 { |
|
633 mask = iMask; // ownership taken |
|
634 iMask = NULL; |
|
635 } |
|
636 return mask; |
|
637 } |
494 } |
638 |
495 |
639 // --------------------------------------------------------- |
496 // --------------------------------------------------------- |
640 // CWmImageConverter::EndsWith |
497 // CWmImageConverter::EndsWith |
641 // --------------------------------------------------------- |
498 // --------------------------------------------------------- |
772 } |
629 } |
773 return result; |
630 return result; |
774 } |
631 } |
775 |
632 |
776 // --------------------------------------------------------------------------- |
633 // --------------------------------------------------------------------------- |
777 // CWmImageConverter::CreateSkinOrMifIconL |
|
778 // --------------------------------------------------------------------------- |
|
779 // |
|
780 void CWmImageConverter::CreateSkinOrMifIconL( |
|
781 const TAknsItemID& aItemId, TInt aBitmapId, |
|
782 TInt aMaskId, const TDesC& aFileName ) |
|
783 { |
|
784 iFilename = aFileName; |
|
785 CFbsBitmap* bitmap = NULL; |
|
786 CFbsBitmap* mask = NULL; |
|
787 |
|
788 // Load from skin |
|
789 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
790 if ( skin && aItemId.iMajor != 0 && aItemId.iMinor != 0 ) |
|
791 { |
|
792 TInt err( KErrNone ); |
|
793 CAknsMaskedBitmapItemData* itemData = NULL; |
|
794 TRAP( err, itemData = |
|
795 static_cast<CAknsMaskedBitmapItemData*>( |
|
796 skin->CreateUncachedItemDataL( aItemId, EAknsITMaskedBitmap ) ); ); |
|
797 if( itemData && KErrNone == err ) |
|
798 { |
|
799 CleanupStack::PushL( itemData ); |
|
800 // Detach bitmaps |
|
801 bitmap = itemData->Bitmap(); |
|
802 itemData->SetBitmap( NULL ); |
|
803 mask = itemData->Mask(); |
|
804 itemData->SetMask( NULL ); |
|
805 CleanupStack::PopAndDestroy( itemData ); |
|
806 } |
|
807 else |
|
808 { |
|
809 // look in imagetable |
|
810 CAknsImageTableItemData* iconData = NULL; |
|
811 TRAP( err, iconData = static_cast<CAknsImageTableItemData*>( |
|
812 skin->CreateUncachedItemDataL( aItemId, EAknsITImageTable ) ); ); |
|
813 if( iconData && KErrNone == err ) |
|
814 { |
|
815 CleanupStack::PushL( iconData ); |
|
816 if( iconData->NumberOfImages() ) |
|
817 { |
|
818 TAknsItemID iconIId; |
|
819 iconIId.Set( iconData->ImageIID(0) ); |
|
820 TRAP( err, AknsUtils::CreateIconL( |
|
821 skin, iconIId, bitmap, mask, KNullDesC, -1, -1 ); ); |
|
822 } |
|
823 CleanupStack::PopAndDestroy( iconData ); |
|
824 } |
|
825 } |
|
826 |
|
827 if ( KErrNone == err && bitmap ) |
|
828 { |
|
829 TInt err = AknIconUtils::SetSize( bitmap , iSize, EAspectRatioNotPreserved ); |
|
830 if ( KErrNone == err ) |
|
831 { |
|
832 if ( mask ) |
|
833 { |
|
834 err = AknIconUtils::SetSize( mask , iSize, EAspectRatioNotPreserved ); |
|
835 } |
|
836 iBitmap = bitmap; |
|
837 iMask = mask; |
|
838 iState = EIdle; |
|
839 // notify observer |
|
840 iObserver->NotifyCompletion( KErrNone ); |
|
841 return; |
|
842 } |
|
843 else |
|
844 { |
|
845 if ( bitmap ) { delete bitmap; bitmap = NULL; } |
|
846 if ( mask ){ delete mask; mask = NULL; } |
|
847 } |
|
848 } |
|
849 } |
|
850 |
|
851 if( aBitmapId != KErrNotFound && !bitmap && |
|
852 aFileName.Length() && BaflUtils::FileExists( iFs, aFileName ) ) |
|
853 { |
|
854 if ( aMaskId != KErrNotFound ) |
|
855 { |
|
856 // Create icon from Mif filename , bitmap id and mask id |
|
857 AknIconUtils::CreateIconL( |
|
858 bitmap, mask, *this, aBitmapId, aMaskId ); |
|
859 } |
|
860 else |
|
861 { |
|
862 bitmap = AknIconUtils::CreateIconL( *this, aBitmapId ); |
|
863 } |
|
864 } |
|
865 else |
|
866 { |
|
867 iState = EIdle; |
|
868 User::Leave( KErrArgument ); |
|
869 } |
|
870 |
|
871 iBitmap = bitmap; |
|
872 iMask = mask; |
|
873 |
|
874 TInt err = AknIconUtils::SetSize( iBitmap , iSize, EAspectRatioNotPreserved ); |
|
875 if ( KErrNone == err && iMask ) |
|
876 { |
|
877 err = AknIconUtils::SetSize( iMask , iSize, EAspectRatioNotPreserved ); |
|
878 } |
|
879 |
|
880 iState = EIdle; |
|
881 // notify observer |
|
882 iObserver->NotifyCompletion( err ); |
|
883 } |
|
884 |
|
885 // --------------------------------------------------------------------------- |
|
886 // CWmImageConverter::ParseNextUint() |
634 // CWmImageConverter::ParseNextUint() |
887 // --------------------------------------------------------------------------- |
635 // --------------------------------------------------------------------------- |
888 // |
636 // |
889 TInt CWmImageConverter::ParseNextUint( TLex& aLex, TUint& aValue ) |
637 TInt CWmImageConverter::ParseNextUint( TLex& aLex, TUint& aValue ) |
890 { |
638 { |
935 { |
665 { |
936 TInt err = aFile.Open( iFs, iFilename, |
666 TInt err = aFile.Open( iFs, iFilename, |
937 EFileRead | EFileShareReadersOnly ); |
667 EFileRead | EFileShareReadersOnly ); |
938 if ( KErrNone != err ) |
668 if ( KErrNone != err ) |
939 { |
669 { |
940 iState = EIdle; |
|
941 User::Leave( err ); |
670 User::Leave( err ); |
942 } |
671 } |
943 } |
672 } |
944 |
673 |
945 // --------------------------------------------------------------------------- |
674 // --------------------------------------------------------------------------- |
946 // CWmImageConverter::DoesScaleBitmapUseFallBack |
675 // CWmImageConverter::CopyBitmapL |
947 // --------------------------------------------------------------------------- |
676 // --------------------------------------------------------------------------- |
948 // |
677 // |
949 TBool CWmImageConverter::DoesScaleBitmapUseFallBack( CFbsBitmap* aSrcBitmap ) |
678 void CWmImageConverter::CopyBitmapL( |
950 { |
679 CFbsBitmap& aTrgBitmap, |
951 if ( !aSrcBitmap ) |
680 CFbsBitmap& aSrcBitmap ) |
952 { |
681 { |
953 return EFalse; |
682 TSize size( aSrcBitmap.SizeInPixels() ); |
954 } |
683 TDisplayMode displayMode( aSrcBitmap.DisplayMode() ); |
955 |
684 User::LeaveIfError( aTrgBitmap.Create( size, displayMode ) ); |
956 TDisplayMode displayMode = aSrcBitmap->DisplayMode(); |
685 |
957 TBool fallbackOnly = EFalse; |
686 HBufC8* scanLine = HBufC8::NewL( aSrcBitmap.ScanLineLength( |
958 |
687 size.iWidth, displayMode ) ); |
959 switch ( displayMode ) |
688 TPtr8 scanPtr( scanLine->Des() ); |
960 { |
689 TPoint pp; |
961 case EGray2: |
690 for( pp.iY = 0; pp.iY < size.iHeight; ++pp.iY ) |
962 case EGray4: |
691 { |
963 case EGray16: |
692 aSrcBitmap.GetScanLine( scanPtr, pp, size.iWidth, displayMode ); |
964 case EColor16: |
693 aTrgBitmap.SetScanLine( scanPtr, pp.iY ); |
965 case EColor16M: |
694 } |
966 case ERgb: |
695 delete scanLine; |
967 case EColor16MA: |
696 } |
968 fallbackOnly = ETrue; |
697 |
969 break; |
698 // --------------------------------------------------------------------------- |
970 case EGray256: |
699 // CWmImageConverter::Finished |
971 case EColor4K: |
700 // --------------------------------------------------------------------------- |
972 case EColor64K: |
701 // |
973 case EColor256: |
702 void CWmImageConverter::Finished() |
974 case EColor16MU: |
703 { |
975 // These are the supported modes |
704 // finishes using the icon file. No actions needed here. |
976 break; |
705 } |
977 default: |
706 |
978 fallbackOnly = ETrue; |
707 // --------------------------------------------------------------------------- |
979 } |
708 // CWmImageConverter::UpdateImageSize |
980 |
709 // --------------------------------------------------------------------------- |
981 return fallbackOnly; |
710 // |
982 } |
711 void CWmImageConverter::UpdateImageSize( |
983 |
712 const TSize& aSize, |
984 |
713 const TDesC& aIconStr, |
985 // --------------------------------------------------------------------------- |
714 CFbsBitmap& aBitmap, |
986 // CWmImageConverter::ScaleBitmapL |
715 CFbsBitmap& aMask ) |
987 // --------------------------------------------------------------------------- |
716 { |
988 // |
717 if ( aIconStr.Length() && iSize != aSize ) |
989 void CWmImageConverter::ScaleBitmapL( |
718 { |
990 const TSize& aSize, |
719 TAknsItemID skinItemId; |
991 CFbsBitmap* aTrgBitmap, |
720 skinItemId.iMajor = 0; |
992 CFbsBitmap* aSrcBitmap ) |
721 skinItemId.iMinor = 0; |
993 { |
722 TInt bitmapId( KErrNotFound ); |
994 if ( !aSrcBitmap ) User::Leave( KErrArgument ); |
723 TInt maskId( KErrNotFound ); |
995 if ( !aTrgBitmap ) User::Leave( KErrArgument ); |
724 TUid appUid; |
996 if ( aSrcBitmap->DisplayMode() != aTrgBitmap->DisplayMode() ) |
725 iFilename = KNullDesC; |
997 { |
726 iSize = aSize; |
998 User::Leave( KErrArgument ); |
727 |
999 } |
728 if ( ResolveSkinIdAndMifId( |
1000 |
729 aIconStr, skinItemId, bitmapId, maskId, iFilename ) ) |
1001 // make target to correct size |
730 { |
1002 if ( aTrgBitmap->SizeInPixels() != aSize ) |
731 AknIconUtils::SetSize( &aBitmap, iSize ); |
1003 { |
732 AknIconUtils::SetSize( &aMask, iSize ); |
1004 aTrgBitmap->Resize( aSize ); |
733 } |
1005 } |
734 else if ( ResolveUid( aIconStr, appUid ) ) |
1006 |
735 { |
1007 TRect targetRect( aSize ); |
736 if ( appUid.iUid >= KWidgetUidLowerBound && |
1008 |
737 appUid.iUid < KWidgetUidUpperBound ) |
1009 // calculate aspect ratio |
|
1010 TInt srcHeight = aSrcBitmap->SizeInPixels().iHeight; |
|
1011 TInt srcWidth = aSrcBitmap->SizeInPixels().iWidth; |
|
1012 TReal scaleRatio( 1 ); //no scale as defaul |
|
1013 |
|
1014 //If any dimension is 0, then we do not bother to scale |
|
1015 if ( targetRect.Width() > 0 && targetRect.Height() > 0 ) |
|
1016 { |
|
1017 TReal xRatio = ( ( TReal )srcWidth / ( TReal )targetRect.Width() ); |
|
1018 TReal yRatio = ( ( TReal )srcHeight / ( TReal )targetRect.Height() ); |
|
1019 //Find out appropriate scaling factor |
|
1020 xRatio > yRatio ? ( scaleRatio = xRatio ) : ( scaleRatio = yRatio ); |
|
1021 } |
|
1022 |
|
1023 //Scale the size for target bitmap |
|
1024 targetRect.SetHeight( srcHeight / scaleRatio ); |
|
1025 targetRect.SetWidth( srcWidth / scaleRatio ); |
|
1026 |
|
1027 TSize trgBitmapSize = aTrgBitmap->SizeInPixels(); |
|
1028 |
|
1029 // calculate the valid drawing area |
|
1030 TRect drawRect = targetRect; |
|
1031 drawRect.Intersection( TRect( TPoint( 0, 0 ), trgBitmapSize ) ); |
|
1032 |
|
1033 if( drawRect.IsEmpty() || |
|
1034 aSrcBitmap->SizeInPixels().iHeight <= 0 || |
|
1035 aSrcBitmap->SizeInPixels().iWidth <= 0 ) |
|
1036 { |
|
1037 User::Leave( KErrArgument ); |
|
1038 } |
|
1039 |
|
1040 TSize srcSize = aSrcBitmap->SizeInPixels(); |
|
1041 |
|
1042 TBool srcTemporary = EFalse; |
|
1043 if ( aSrcBitmap->IsRomBitmap() ) |
|
1044 { |
|
1045 srcTemporary = ETrue; |
|
1046 } |
|
1047 |
|
1048 TDisplayMode displayMode = aSrcBitmap->DisplayMode(); |
|
1049 TBool fallbackOnly = DoesScaleBitmapUseFallBack( aSrcBitmap ); |
|
1050 |
|
1051 if ( fallbackOnly ) |
|
1052 { |
|
1053 CFbsBitmapDevice* dev = CFbsBitmapDevice::NewL( aTrgBitmap ); |
|
1054 CleanupStack::PushL( dev ); |
|
1055 CFbsBitGc* gc = NULL; |
|
1056 User::LeaveIfError( dev->CreateContext( gc ) ); |
|
1057 CleanupStack::PushL( gc ); |
|
1058 |
|
1059 // write alpha information if it exists |
|
1060 if ( aSrcBitmap->DisplayMode() == EColor16MA ) |
|
1061 { |
|
1062 gc->SetDrawMode( CGraphicsContext::EDrawModeWriteAlpha ); |
|
1063 } |
|
1064 |
|
1065 // targetRect is used because DrawBitmap handles clipping automatically |
|
1066 gc->DrawBitmap( targetRect, aSrcBitmap ); |
|
1067 CleanupStack::PopAndDestroy( 2 ); // dev, gc |
|
1068 return; |
|
1069 } |
|
1070 |
|
1071 // Heap lock for FBServ large chunk to prevent background |
|
1072 // compression of aSrcBitmap after if IsCompressedInRAM returns EFalse |
|
1073 aSrcBitmap->LockHeapLC( ETrue ); // fbsheaplock |
|
1074 TBool fbsHeapLock = ETrue; |
|
1075 if ( aSrcBitmap->IsCompressedInRAM() ) |
|
1076 { |
|
1077 srcTemporary = ETrue; |
|
1078 } |
|
1079 |
|
1080 CFbsBitmap* realSource = aSrcBitmap; |
|
1081 if ( srcTemporary ) |
|
1082 { |
|
1083 CleanupStack::PopAndDestroy(); // fbsheaplock |
|
1084 fbsHeapLock = EFalse; |
|
1085 |
|
1086 realSource = new ( ELeave ) CFbsBitmap(); |
|
1087 CleanupStack::PushL( realSource ); |
|
1088 User::LeaveIfError( |
|
1089 realSource->Create( srcSize, aSrcBitmap->DisplayMode() ) ); |
|
1090 CFbsBitmapDevice* dev = CFbsBitmapDevice::NewL( realSource ); |
|
1091 CleanupStack::PushL( dev ); |
|
1092 CFbsBitGc* gc = NULL; |
|
1093 User::LeaveIfError( dev->CreateContext( gc ) ); |
|
1094 CleanupStack::PushL( gc ); |
|
1095 gc->BitBlt( TPoint( 0, 0 ), aSrcBitmap ); |
|
1096 CleanupStack::PopAndDestroy( 2 ); // dev, gc |
|
1097 } |
|
1098 |
|
1099 if ( !fbsHeapLock ) |
|
1100 { |
|
1101 // Heap lock for FBServ large chunk is only needed with large bitmaps. |
|
1102 if ( realSource->IsLargeBitmap() || aTrgBitmap->IsLargeBitmap() ) |
|
1103 { |
|
1104 aTrgBitmap->LockHeapLC( ETrue ); // fbsheaplock |
|
1105 } |
|
1106 else |
|
1107 { |
|
1108 CleanupStack::PushL( ( TAny* )NULL ); |
|
1109 } |
|
1110 } |
|
1111 |
|
1112 TUint32* srcAddress = realSource->DataAddress(); |
|
1113 TUint32* trgAddress = aTrgBitmap->DataAddress(); |
|
1114 |
|
1115 const TInt xSkip = ( srcSize.iWidth << 8 ) / targetRect.Width(); |
|
1116 const TInt ySkip = ( srcSize.iHeight << 8 ) / targetRect.Height(); |
|
1117 |
|
1118 const TInt drawWidth = drawRect.Width(); |
|
1119 const TInt drawHeight = drawRect.Height(); |
|
1120 |
|
1121 TRect offsetRect( targetRect.iTl, drawRect.iTl ); |
|
1122 const TInt yPosOffset = ySkip * offsetRect.Height(); |
|
1123 const TInt xPosOffset = xSkip * offsetRect.Width(); |
|
1124 |
|
1125 if ( ( displayMode == EGray256 ) || ( displayMode == EColor256 ) ) |
|
1126 { |
|
1127 TInt srcScanLen8 = CFbsBitmap::ScanLineLength( |
|
1128 srcSize.iWidth, displayMode ); |
|
1129 TInt trgScanLen8 = CFbsBitmap::ScanLineLength( |
|
1130 trgBitmapSize.iWidth, displayMode ); |
|
1131 |
|
1132 TUint8* trgAddress8 = reinterpret_cast< TUint8* >( trgAddress ); |
|
1133 |
|
1134 TInt yPos = yPosOffset; |
|
1135 // skip left and top margins in the beginning |
|
1136 trgAddress8 += trgScanLen8 * drawRect.iTl.iY + drawRect.iTl.iX; |
|
1137 |
|
1138 for ( TInt y = 0; y < drawHeight; y++ ) |
|
1139 { |
|
1140 TUint8* srcAddress8 = reinterpret_cast< TUint8* >( srcAddress ) + |
|
1141 ( srcScanLen8 * ( yPos >> 8 ) ); |
|
1142 |
|
1143 TInt xPos = xPosOffset; |
|
1144 for ( TInt x = 0; x < drawWidth; x++ ) |
|
1145 { |
738 { |
1146 *( trgAddress8++ ) = srcAddress8[xPos >> 8]; |
739 //WRT. No resize needed here |
1147 xPos += xSkip; |
740 return; |
1148 } |
741 } |
1149 |
742 else if ( appUid.iUid != KNullUid.iUid ) |
1150 yPos += ySkip; |
|
1151 |
|
1152 trgAddress8 += trgScanLen8 - drawWidth; |
|
1153 } |
|
1154 } |
|
1155 else if ( displayMode == EColor4K || displayMode == EColor64K ) |
|
1156 { |
|
1157 TInt srcScanLen16 = CFbsBitmap::ScanLineLength( |
|
1158 srcSize.iWidth, displayMode ) /2; |
|
1159 TInt trgScanLen16 = CFbsBitmap::ScanLineLength( |
|
1160 trgBitmapSize.iWidth, displayMode ) /2; |
|
1161 |
|
1162 TUint16* trgAddress16 = reinterpret_cast< TUint16* >( trgAddress ); |
|
1163 |
|
1164 TInt yPos = yPosOffset; |
|
1165 // skip left and top margins in the beginning |
|
1166 trgAddress16 += trgScanLen16 * drawRect.iTl.iY + drawRect.iTl.iX; |
|
1167 |
|
1168 for ( TInt y = 0; y < drawHeight; y++ ) |
|
1169 { |
|
1170 TUint16* srcAddress16 = reinterpret_cast< TUint16* >( srcAddress ) + |
|
1171 ( srcScanLen16 * ( yPos >> 8 ) ); |
|
1172 |
|
1173 TInt xPos = xPosOffset; |
|
1174 for ( TInt x = 0; x < drawWidth; x++ ) |
|
1175 { |
743 { |
1176 *( trgAddress16++ ) = srcAddress16[xPos >> 8]; |
744 AknIconUtils::SetSize( &aBitmap, iSize ); |
1177 xPos += xSkip; |
745 AknIconUtils::SetSize( &aMask, iSize ); |
1178 } |
746 } |
1179 |
747 } |
1180 yPos += ySkip; |
748 } |
1181 |
|
1182 trgAddress16 += trgScanLen16 - drawWidth; |
|
1183 } |
|
1184 } |
|
1185 else if ( displayMode == EColor16MU ) |
|
1186 { |
|
1187 TInt srcScanLen32 = CFbsBitmap::ScanLineLength( |
|
1188 srcSize.iWidth, displayMode ) /4; |
|
1189 TInt trgScanLen32 = CFbsBitmap::ScanLineLength( |
|
1190 trgBitmapSize.iWidth, displayMode ) /4; |
|
1191 |
|
1192 TUint32* trgAddress32 = reinterpret_cast< TUint32* >( trgAddress ); |
|
1193 |
|
1194 TInt yPos = yPosOffset; |
|
1195 // skip left and top margins in the beginning |
|
1196 trgAddress32 += trgScanLen32 * drawRect.iTl.iY + drawRect.iTl.iX; |
|
1197 |
|
1198 for ( TInt y = 0; y < drawHeight; y++ ) |
|
1199 { |
|
1200 TUint32* srcAddress32 = reinterpret_cast< TUint32* >( srcAddress ) + |
|
1201 ( srcScanLen32 * ( yPos >> 8 ) ); |
|
1202 |
|
1203 TInt xPos = xPosOffset; |
|
1204 for ( TInt x = 0; x < drawWidth; x++ ) |
|
1205 { |
|
1206 *( trgAddress32++ ) = srcAddress32[xPos >> 8]; |
|
1207 xPos += xSkip; |
|
1208 } |
|
1209 |
|
1210 yPos += ySkip; |
|
1211 |
|
1212 trgAddress32 += trgScanLen32 - drawWidth; |
|
1213 } |
|
1214 } |
|
1215 else |
|
1216 { |
|
1217 User::Leave( KErrUnknown ); |
|
1218 } |
|
1219 |
|
1220 CleanupStack::PopAndDestroy(); // fbsheaplock |
|
1221 |
|
1222 if ( srcTemporary ) |
|
1223 { |
|
1224 CleanupStack::PopAndDestroy(); // realSource |
|
1225 } |
|
1226 } |
|
1227 |
|
1228 // --------------------------------------------------------------------------- |
|
1229 // CWmImageConverter::Finished |
|
1230 // --------------------------------------------------------------------------- |
|
1231 // |
|
1232 void CWmImageConverter::Finished() |
|
1233 { |
|
1234 // finishes using the icon file. No actions needed here. |
|
1235 } |
|
1236 |
|
1237 // --------------------------------------------------------------------------- |
|
1238 // CWmImageConverter::IsProcessing |
|
1239 // --------------------------------------------------------------------------- |
|
1240 // |
|
1241 TBool CWmImageConverter::IsProcessing() |
|
1242 { |
|
1243 return ( ( ( iState != EIdle && iState != EFailed ) || |
|
1244 IsActive() ) ? ETrue : EFalse ); |
|
1245 } |
749 } |
1246 |
750 |
1247 // End of file |
751 // End of file |
1248 |
752 |