uigraphics/AknIcon/srvsrc/AknIconSrvUtils.cpp
changeset 0 05e9090e2422
child 1 ba33815114d6
equal deleted inserted replaced
-1:000000000000 0:05e9090e2422
       
     1 /*
       
     2 * Copyright (c) 2002 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:  Implementation of class AknIconSrvUtils.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 #include <fbs.h>
       
    23 #include <gdi.h>
       
    24 #include <bitdev.h>
       
    25 #include <mifconvdefs.h>
       
    26 
       
    27 #include "AknIconSrvUtils.h"
       
    28 #include "AknIconFormatHandler.h"
       
    29 #include "AknIconLoader.h"
       
    30 #include "AknIconSrv.h"
       
    31 #include "AknIconFormatHandlerFactory.h"
       
    32 #include "AknIconSrvDef.h"
       
    33 
       
    34 #include "AknBitmap.h"
       
    35 // CONSTANTS
       
    36 
       
    37 // ================= MEMBER FUNCTIONS ==========================================
       
    38 
       
    39 TPtrC8 AknIconSrvUtils::InitIconDataAndHandlerLC(
       
    40     CAknIconLoader* aLoader,
       
    41     RPointerArray<MAknIconFormatHandler>& aHandlerList,
       
    42     MAknIconFormatHandler*& aHandler,
       
    43     const TAknIconParams& aParams,
       
    44     TBool aAnimated )
       
    45     {
       
    46     CleanupStack::PushL( TCleanupItem( CleanupFreeIcon, aLoader ) );
       
    47 
       
    48     if ( aLoader->IconAnimatedL( aParams.iBitmapId ) && !aAnimated )
       
    49         {
       
    50         User::Leave( KAknIconSrvCodeAnimated );
       
    51         }
       
    52 
       
    53     TInt type = aLoader->IconTypeL( aParams.iBitmapId );
       
    54     
       
    55 #ifdef _NGATESTING        
       
    56     type = aLoader->GetDerivedIconTypeL(type, aParams.iFileName);
       
    57 #endif
       
    58     
       
    59     // Check if handler is already present, if so then return with same pointer
       
    60     for ( TInt lIndex = 0; lIndex < aHandlerList.Count(); lIndex++ )
       
    61         {
       
    62         if ( aHandlerList[ lIndex ]->IconFormatType() == type )
       
    63             {
       
    64             aHandler = aHandlerList[ lIndex ]; 
       
    65             break;
       
    66             }
       
    67         }
       
    68 
       
    69     // No Handler found, create one and add to list
       
    70     if ( !aHandler )
       
    71         {
       
    72         aHandler = AknIconFormatHandlerFactory::NewIconFormatHandlerL( type );
       
    73         aHandlerList.Append( aHandler );
       
    74         aHandler->SetAnimated( aAnimated );
       
    75         }
       
    76 
       
    77     return aLoader->IconL( aParams.iBitmapId );
       
    78     }
       
    79 
       
    80 TPtrC8 AknIconSrvUtils::InitIconDataAndHandlerLC(
       
    81     CAknIconLoader* aLoader,
       
    82     MAknIconFormatHandler*& aHandler,
       
    83     TInt aIconId,
       
    84     TBool aAnimated )
       
    85     {
       
    86     CleanupStack::PushL( TCleanupItem( CleanupFreeIcon, aLoader ) );
       
    87 
       
    88     if ( aLoader->IconAnimatedL( aIconId ) && !aAnimated )
       
    89         {
       
    90         User::Leave( KAknIconSrvCodeAnimated );
       
    91         }
       
    92 
       
    93     TInt type = aLoader->IconTypeL( aIconId );
       
    94 
       
    95     if ( !aHandler )
       
    96         {
       
    97         aHandler = AknIconFormatHandlerFactory::NewIconFormatHandlerL( type );
       
    98         aHandler->SetAnimated( aAnimated );
       
    99         }
       
   100 
       
   101     return aLoader->IconL( aIconId );
       
   102     }
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // AknIconSrvUtils::RenderPreparedIconL
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 TAknContentDimensions AknIconSrvUtils::RenderPreparedIconL(
       
   109     MAknIconFormatHandler& aHandler,
       
   110     CFbsBitmap* aBitmap,
       
   111     CFbsBitmap* aMask, // may be NULL
       
   112     TDisplayMode aBitmapDepth,
       
   113     TDisplayMode aPreferredDepth,
       
   114     const TSize& aSize,
       
   115     TScaleMode aMode,
       
   116     TInt aRotationAngle,
       
   117     TRgb aColor,
       
   118     TInt /*aBitmapId*/,
       
   119     TInt /*aMaskId*/,
       
   120     TBool isAppIcon)
       
   121     {
       
   122     TSize resultSize( aSize );
       
   123     CAknBitmap* aknIcon = CAknBitmap::DynamicCast(aBitmap);
       
   124 
       
   125     TAknContentDimensions dimensions;
       
   126     TBool dimensionsRetrieved = EFalse;
       
   127 
       
   128     if ( aMode == EAspectRatioPreservedAndUnusedSpaceRemoved )
       
   129         {
       
   130         if ( !resultSize.iWidth || !resultSize.iHeight )
       
   131             {
       
   132             resultSize.iWidth = 0;
       
   133             resultSize.iHeight = 0;
       
   134             }
       
   135         else
       
   136             {
       
   137             aHandler.GetContentDimensionsL( dimensions );
       
   138             dimensionsRetrieved = ETrue;
       
   139             GetAspectRatioPreservedSize( dimensions, resultSize );
       
   140             }
       
   141         }
       
   142     
       
   143     TDisplayMode definedDepth = aBitmapDepth;
       
   144     // Change display mode to the closest one supported by the engine.
       
   145     aHandler.SupportedDisplayMode( aBitmapDepth, aPreferredDepth );    
       
   146 
       
   147     CFbsBitmap* renderBitmap = aBitmap;
       
   148 
       
   149     // If EGray256 mode was defined, and the engine did not support it,
       
   150     // render the icon first in a temporary bitmap.
       
   151 
       
   152     if ( definedDepth == EGray256 && definedDepth != aBitmapDepth )
       
   153         {
       
   154         renderBitmap = new( ELeave ) CFbsBitmap;
       
   155         CleanupStack::PushL( renderBitmap );
       
   156         }
       
   157 
       
   158     User::LeaveIfError( renderBitmap->Create( resultSize, aBitmapDepth ) );
       
   159     if ( aMask )
       
   160         {
       
   161         // Always use soft masks with SVGs.
       
   162         User::LeaveIfError( aMask->Create( resultSize, EGray256 ) );
       
   163         }
       
   164 
       
   165     aHandler.SetScaleMode( aMode );
       
   166     aHandler.SetRotation( aRotationAngle );
       
   167     aknIcon = CAknBitmap::DynamicCast(aBitmap);
       
   168     aHandler.RenderPreparedIconL(renderBitmap, aMask ,resultSize, aBitmapDepth, EGray256,aColor, isAppIcon);
       
   169 
       
   170     // Copy from temp. render bitmap to real bitmap,
       
   171     // and convert display depth to EGray256.
       
   172     if ( renderBitmap != aBitmap )
       
   173         {
       
   174         User::LeaveIfError( aBitmap->Create( resultSize, EGray256 ) );
       
   175 
       
   176         CFbsBitmapDevice* dev = CFbsBitmapDevice::NewL( aBitmap );
       
   177         CleanupStack::PushL( dev );
       
   178         CFbsBitGc* gc = NULL;
       
   179         User::LeaveIfError( dev->CreateContext( gc ) );
       
   180         CleanupStack::PushL( gc );
       
   181 
       
   182         gc->BitBlt( TPoint( 0, 0 ), renderBitmap );
       
   183 
       
   184         CleanupStack::PopAndDestroy( 3 ); // renderBitmap, dev, gc
       
   185         }
       
   186 
       
   187     if ( !dimensionsRetrieved )
       
   188         {
       
   189         aHandler.GetContentDimensionsL( dimensions );
       
   190         }
       
   191 
       
   192     return dimensions;
       
   193     }
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // AknIconSrvUtils::GetAspectRatioPreservedSize
       
   197 // -----------------------------------------------------------------------------
       
   198 //
       
   199 void AknIconSrvUtils::GetAspectRatioPreservedSize(
       
   200     const TAknContentDimensions& aDimensions,
       
   201     TSize& aSize )
       
   202     {
       
   203     if ( !aDimensions.iWidth || !aDimensions.iHeight )
       
   204         {
       
   205         aSize.iWidth = 0;
       
   206         aSize.iHeight = 0;
       
   207         }
       
   208     else
       
   209         {
       
   210         if ( aSize.iWidth > KMaxTInt16 )
       
   211             {
       
   212             aSize.iWidth = KMaxTInt16;
       
   213             }
       
   214         if ( aSize.iHeight > KMaxTInt16 )
       
   215             {
       
   216             aSize.iHeight = KMaxTInt16;
       
   217             }
       
   218 
       
   219         TReal32 xScaleFactor = (TReal32)(aSize.iWidth) / aDimensions.iWidth;
       
   220         TReal32 yScaleFactor = (TReal32)(aSize.iHeight) / aDimensions.iHeight;
       
   221 
       
   222         if ( xScaleFactor > yScaleFactor )
       
   223             {
       
   224             TReal32 width = aDimensions.iWidth * yScaleFactor; 
       
   225             aSize.iWidth = width;
       
   226             if ( width - aSize.iWidth > 0 ) //rounding
       
   227                 {
       
   228                 aSize.iWidth++;
       
   229                 }
       
   230             }
       
   231         else
       
   232             {
       
   233             TReal32 height = aDimensions.iHeight * xScaleFactor;
       
   234             aSize.iHeight = height;
       
   235             if ( height - aSize.iHeight > 0 ) //rounding
       
   236                 {
       
   237                 aSize.iHeight++;
       
   238                 }
       
   239             }
       
   240         }
       
   241     }
       
   242     
       
   243 // -----------------------------------------------------------------------------
       
   244 // AknIconSrvUtils::GetAspectRatioPreservedSize
       
   245 // -----------------------------------------------------------------------------
       
   246 //
       
   247 void AknIconSrvUtils::GetAspectRatioPreservedSize(
       
   248     const TSize& aDimensions,
       
   249     TSize& aSize,
       
   250     TBool aFitToOriginalSize )
       
   251     {
       
   252     if ( !aDimensions.iWidth || !aDimensions.iHeight )
       
   253         {
       
   254         aSize.iWidth = 0;
       
   255         aSize.iHeight = 0;
       
   256         }
       
   257     else
       
   258         {
       
   259         if ( aSize.iWidth > KMaxTInt16 )
       
   260             {
       
   261             aSize.iWidth = KMaxTInt16;
       
   262             }
       
   263         if ( aSize.iHeight > KMaxTInt16 )
       
   264             {
       
   265             aSize.iHeight = KMaxTInt16;
       
   266             }
       
   267 
       
   268         TInt xScaleFactor = (aSize.iWidth << 16) / aDimensions.iWidth;
       
   269         TInt yScaleFactor = (aSize.iHeight << 16) / aDimensions.iHeight;
       
   270         
       
   271         
       
   272         TBool chooseWidthScaling = (xScaleFactor > yScaleFactor);
       
   273         
       
   274         if (!aFitToOriginalSize)
       
   275             {
       
   276             chooseWidthScaling = !chooseWidthScaling;
       
   277             }
       
   278 
       
   279         if ( chooseWidthScaling )
       
   280             {
       
   281             aSize.iWidth = aDimensions.iWidth * yScaleFactor;
       
   282             TBool rounding = aSize.iWidth & 0x8000;
       
   283 
       
   284             aSize.iWidth >>= 16;
       
   285             if ( rounding )
       
   286                 {
       
   287                 aSize.iWidth++;
       
   288                 }
       
   289             }
       
   290         else
       
   291             {
       
   292             aSize.iHeight = aDimensions.iHeight * xScaleFactor;
       
   293             TBool rounding = aSize.iHeight & 0x8000;
       
   294             
       
   295             aSize.iHeight >>= 16;
       
   296             if ( rounding )
       
   297                 {
       
   298                 aSize.iHeight++;
       
   299                 }
       
   300             }
       
   301         }
       
   302     }    
       
   303 
       
   304 // -----------------------------------------------------------------------------
       
   305 // AknIconSrvUtils::ScaleBitmapIconL
       
   306 // -----------------------------------------------------------------------------
       
   307 //
       
   308 TBool AknIconSrvUtils::ScaleBitmapIconL(
       
   309     const TSize& aSize,
       
   310     const TScaleMode aMode,
       
   311     const TInt aAngle,
       
   312     const TRgb aColor,
       
   313     CFbsBitmap* aSourceBitmap,
       
   314     CFbsBitmap* aSourceMask,
       
   315     CFbsBitmap* aTargetBitmap,
       
   316     CFbsBitmap* aTargetMask )
       
   317     {
       
   318     TSize scaledSize( aSize );
       
   319     TSize originalSize(aSourceBitmap->SizeInPixels());
       
   320     TBool colorIcon = aColor != KColorNotDefined;
       
   321     
       
   322     // Find out the scaled size according to the given scale mode.
       
   323     // Note:In scaling mode EAspectRatioPreservedSlice no need to calculate scaledSize for color icons.
       
   324     if ( aMode != EAspectRatioNotPreserved && (aMode != EAspectRatioPreservedSlice || !colorIcon))
       
   325         {
       
   326         AknIconSrvUtils::GetAspectRatioPreservedSize( originalSize, scaledSize, aMode != EAspectRatioPreservedSlice );
       
   327         }
       
   328 
       
   329     const TSize& bitmapSize =
       
   330         aMode == EAspectRatioPreservedAndUnusedSpaceRemoved ?
       
   331         scaledSize : aSize;    
       
   332 
       
   333     TDisplayMode colorDepth = colorIcon ?
       
   334         EColor64K : aSourceBitmap->DisplayMode();
       
   335 
       
   336     User::LeaveIfError( aTargetBitmap->Create( bitmapSize, colorDepth ) );
       
   337     
       
   338     // Icon should be centered, so calculate x and y margins.
       
   339     TInt xMargin = ( bitmapSize.iWidth - scaledSize.iWidth ) / 2;
       
   340     TInt yMargin = ( bitmapSize.iHeight - scaledSize.iHeight ) / 2;
       
   341 
       
   342     // Target rect inside the target bitmap.
       
   343     TRect targetRect( xMargin, yMargin,
       
   344         xMargin + scaledSize.iWidth, yMargin + scaledSize.iHeight );
       
   345 
       
   346     // Decide if fallback should be forced in ScaleBitmapExtL calls
       
   347     TBool forceFallBack = EFalse;
       
   348     if ( !colorIcon && aSourceBitmap && !aAngle )
       
   349         {
       
   350         forceFallBack = AknIconUtils::DoesScaleBitmapUseFallBack( aSourceBitmap );
       
   351         }
       
   352     if ( aSourceMask && aTargetMask && !aAngle )
       
   353         {
       
   354         forceFallBack = forceFallBack || AknIconUtils::DoesScaleBitmapUseFallBack( aSourceMask );
       
   355         }
       
   356 
       
   357     // If color icon, just fill the bitmap with the defined color.
       
   358     if ( colorIcon )
       
   359         {
       
   360         CFbsBitmapDevice* dev = CFbsBitmapDevice::NewL( aTargetBitmap );
       
   361         CleanupStack::PushL( dev );
       
   362         CFbsBitGc* gc = NULL;
       
   363         User::LeaveIfError( dev->CreateContext( gc ) );
       
   364         CleanupStack::PushL( gc );
       
   365         
       
   366         gc->SetBrushColor( aColor );
       
   367         gc->SetPenStyle( CGraphicsContext::ENullPen );
       
   368         gc->SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   369         // Fill icon with the given color, mask defines the icon shape.
       
   370         gc->DrawRect( TRect( TPoint( 0, 0 ), bitmapSize ) );
       
   371 
       
   372         CleanupStack::PopAndDestroy( 2 ); // dev, gc
       
   373         }
       
   374 
       
   375     // Otherwise, perform bitmap scaling and rotation as required.
       
   376     else
       
   377         {
       
   378         if ( !aAngle )
       
   379             {
       
   380             AknIconUtils::ScaleBitmapExtL( targetRect, aTargetBitmap, aSourceBitmap, forceFallBack );
       
   381             }
       
   382         else
       
   383             {
       
   384             AknIconUtils::RotateAndScaleBitmapL( 
       
   385                 targetRect,
       
   386                 aTargetBitmap,
       
   387                 aSourceBitmap,
       
   388                 aAngle );
       
   389             }
       
   390         }
       
   391 
       
   392     // Optional mask is always scaled and rotated as required.
       
   393     if ( aSourceMask && aTargetMask)
       
   394         {
       
   395         User::LeaveIfError(aTargetMask->Create( bitmapSize, aSourceMask->DisplayMode() ) );
       
   396             
       
   397 
       
   398         // If target mode is EAspectRatioPreserved, there may be unused parts
       
   399         // in the bitmap, so need to initialize soft masks black before scaling.
       
   400         if ( aMode == EAspectRatioPreserved && aTargetMask->DisplayMode() == EGray256 )
       
   401             {
       
   402             CFbsBitmapDevice* dev = CFbsBitmapDevice::NewL( aTargetMask );
       
   403             CleanupStack::PushL( dev );
       
   404             CFbsBitGc* gc = NULL;
       
   405             User::LeaveIfError( dev->CreateContext( gc ) );
       
   406             CleanupStack::PushL( gc );
       
   407             gc->SetBrushColor( KRgbBlack );
       
   408             gc->SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   409             gc->Clear();
       
   410             CleanupStack::PopAndDestroy(2); // dev, gc
       
   411             }
       
   412 
       
   413         if ( !aAngle )
       
   414             {
       
   415             AknIconUtils::ScaleBitmapExtL( targetRect, aTargetMask, aSourceMask, forceFallBack );
       
   416             }
       
   417         else
       
   418             {
       
   419             AknIconUtils::RotateAndScaleBitmapL( 
       
   420                 targetRect,
       
   421                 aTargetMask,
       
   422                 aSourceMask,
       
   423                 aAngle );
       
   424             }
       
   425         }
       
   426 
       
   427     return colorIcon;    
       
   428     }
       
   429 
       
   430 
       
   431 LOCAL_C TInt CheckTransparency(const CFbsBitmap* aBmp, TDes8& aBuffer, TInt aMask, TDisplayMode aMode)
       
   432     {
       
   433     // Note: The following calculations use the below notation.
       
   434     //
       
   435     //     Ha = Actual height of the bitmap
       
   436     //     hTa = Height of the transparent region at the bottom of the bitmap
       
   437     //     hNT = Height of the non-transparent region in the bitmap
       
   438     //     Therefore, Ha = hNT + 2 * hTa
       
   439     // 
       
   440     //     hNTN = New height of the non-transparent region after accomodating 
       
   441     //            for the 12% transparent margins(bottom)
       
   442     //       HaN = New needed height of the bitmap to adjust the transparent area 
       
   443     //           at the bottom to 12%
       
   444     //     R = Ratio of hNTN / hNT 
       
   445     //     C = 2 * hTa
       
   446     //     HaN = Ha * R - C * R + C
       
   447     //
       
   448     //     This means that if the transparent margins are already 12% then 
       
   449     //     R becomes 1 in the above equation and it reduces to 
       
   450     //         HaN = Ha
       
   451     //     If R becomes > 1 i.e. hNTN > hNT, then it would be clipped to 1.
       
   452     const TSize& sz = aBmp->SizeInPixels();	
       
   453 	const TInt lValidMargin = sz.iHeight * 12 / 100; 
       
   454     
       
   455     const TInt Ha = sz.iHeight;
       
   456     TInt hTa = 0;
       
   457     TInt hNT = 0;
       
   458     TInt C = 0;
       
   459     TInt hNTN = Ha - 2.0 * 0.12 * Ha;
       
   460     TReal R = 1.0;
       
   461     TInt HaN = Ha;
       
   462 
       
   463 	switch(aMode)
       
   464 	   {
       
   465 	   case EGray256: // for mask 
       
   466 	      {
       
   467 	      const TInt lastColumn = sz.iWidth - 1;
       
   468 	   	  const TUint8* ptr8 = reinterpret_cast<const TUint8*> (aBuffer.Ptr());
       
   469 	      for ( TInt curRow = 0; curRow < lValidMargin; curRow++ )
       
   470 		     {
       
   471 		     const TInt y = (sz.iHeight - 1) - curRow; // h - 1 is the last line
       
   472 		     aBmp->GetScanLine(aBuffer, TPoint(0, y), sz.iWidth, aMode);
       
   473 		     for ( TInt s = lastColumn; s >= 0; --s )
       
   474 			   {
       
   475 			   TUint8 lPixel = aBuffer[s];
       
   476 			   if ( aBuffer[s] & (TUint8)aMask ) //note that mask is inverted
       
   477 			      {
       
   478 				  hTa = curRow;
       
   479 				  hNT = Ha - 2 * hTa;
       
   480 				  C = 2 * hTa;
       
   481 				  R = ( ( (TReal)hNTN / (TReal)hNT ) > 1.0 ) ? 1 : (TReal)hNTN / (TReal)hNT;
       
   482 				  HaN = Ha * R - C * R + C;
       
   483 			//	  HaN =( 0.88 * Ha) + hTa;
       
   484 			      return( HaN );
       
   485 				  }
       
   486 			   }
       
   487 		     }	
       
   488 	   	  }
       
   489 	   		
       
   490 	   break;
       
   491 	   case EColor16MA:
       
   492 	   	  {
       
   493 	   	  const TInt lastColumn = aBuffer.MaxLength() / sizeof(TUint32) - 1;
       
   494 	   	  const TUint32* ptr = reinterpret_cast<const TUint32*> (aBuffer.Ptr());
       
   495 	      for ( TInt curRow = 0; curRow < lValidMargin; curRow++ )
       
   496 		     {
       
   497 		     const TInt y = (sz.iHeight - 1) - curRow; // h - 1 is the last line
       
   498 		     aBmp->GetScanLine(aBuffer, TPoint(0, y), sz.iWidth, aMode);
       
   499 		     for ( TInt s = lastColumn; s >= 0; --s )
       
   500 			    {
       
   501 			    if ( ptr[s] & aMask ) //note that mask is inverted
       
   502 				   {
       
   503 				   hTa = curRow;
       
   504 				   hNT = Ha - 2 * hTa;
       
   505 				   C = 2 * hTa;
       
   506 				   R = ( ( (TReal)hNTN / (TReal)hNT ) > 1.0 ) ? 1 : (TReal)hNTN / (TReal)hNT;
       
   507 				   HaN = Ha * R - C * R + C;
       
   508 			//	   HaN =( 0.88 * Ha) + hTa;
       
   509 			       return( HaN );
       
   510                    }
       
   511 			    }
       
   512 		     }
       
   513 	
       
   514 	   	   }
       
   515 	   break;
       
   516 	   default:
       
   517 	   break;
       
   518 		
       
   519 	   }
       
   520 
       
   521     return HaN;
       
   522     }
       
   523 
       
   524 
       
   525 TInt AknIconSrvUtils::CheckMaskTransparencyL(const CFbsBitmap* aBmp)
       
   526 	{
       
   527 	const TSize& sz = aBmp->SizeInPixels();
       
   528 	HBufC8* buffer = HBufC8::NewLC(sz.iWidth);
       
   529 	TPtr8 ptr = buffer->Des();
       
   530 	const TInt h = CheckTransparency(aBmp, ptr, 0xFF, EGray256);
       
   531 	CleanupStack::PopAndDestroy();
       
   532 	return h;
       
   533 	}
       
   534 	
       
   535 TInt AknIconSrvUtils::CheckAlphaTransparencyL(const CFbsBitmap* aBmp)
       
   536 	{
       
   537 	const TSize& sz = aBmp->SizeInPixels();
       
   538 	HBufC8* buffer = HBufC8::NewLC(sz.iWidth * sizeof(TUint32));
       
   539 	TPtr8 ptr = buffer->Des();
       
   540 	const TInt h = CheckTransparency(aBmp, ptr, 0xFF000000, EColor16MA);
       
   541 	CleanupStack::PopAndDestroy();
       
   542 	return h;
       
   543 	}	
       
   544 
       
   545 LOCAL_C void ScaleL(const TRect& aRect, CFbsBitmap* aBmp, TUint32 aFillColor, TBool aForceFb)	
       
   546 	{	
       
   547 	CFbsBitmap* bmp = new (ELeave) CFbsBitmap();
       
   548 	CleanupStack::PushL(bmp);
       
   549 	User::LeaveIfError(bmp->Create(aRect.Size(), aBmp->DisplayMode()));
       
   550 	AknIconUtils::ScaleBitmapExtL( 
       
   551             TRect(TPoint(0, 0), aRect.Size()),
       
   552             bmp,
       
   553             aBmp,
       
   554             aForceFb);
       
   555 
       
   556       
       
   557 	CFbsBitmapDevice* dev = CFbsBitmapDevice::NewL(aBmp);
       
   558 	CleanupStack::PushL(dev);
       
   559 	CFbsBitGc* con = NULL;
       
   560 	dev->CreateContext(con);
       
   561 	CleanupStack::PushL(con);
       
   562 	con->SetBrushColor( 0 );
       
   563 	con->Clear();
       
   564 	con->SetPenStyle(CGraphicsContext::ESolidPen);
       
   565 	con->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   566 	con->SetPenColor(aFillColor);
       
   567 	con->SetBrushColor(aFillColor);
       
   568 	const TSize sz = aBmp->SizeInPixels();
       
   569 	con->DrawRect(TRect(TPoint(0, 0), aBmp->SizeInPixels()));
       
   570 	con->BitBlt(aRect.iTl, bmp);
       
   571 	CleanupStack::PopAndDestroy(3);
       
   572 	}
       
   573 
       
   574 
       
   575 
       
   576 
       
   577 void AknIconSrvUtils::EnsureValidSizeL( CFbsBitmap* aBitmap, CFbsBitmap* aMask )
       
   578 	{
       
   579 	if ( aBitmap == NULL ) 
       
   580 	    return;
       
   581 	CFbsBitmap* iBitmap = aBitmap;
       
   582 	CFbsBitmap* iMask = NULL;
       
   583 	if ( aMask )
       
   584 	    {
       
   585 	    iMask = aMask;
       
   586 	    }
       
   587 	TInt  validHeight;
       
   588 	if(iMask != NULL)
       
   589 		{
       
   590 		SEpocBitmapHeader lBmpHeaderMask = iMask->Header();
       
   591 		if ( lBmpHeaderMask.iBitsPerPixel != 8 ) 	
       
   592 			{
       
   593 			return;
       
   594 		    }
       
   595 		validHeight = CheckMaskTransparencyL(iMask);
       
   596 		}
       
   597 	else
       
   598 		{
       
   599 		SEpocBitmapHeader lBmpHeaderBitmap = iBitmap->Header();
       
   600 		if ( lBmpHeaderBitmap.iBitsPerPixel != 32 )
       
   601 			{
       
   602 			return;
       
   603 			}
       
   604 		validHeight = CheckAlphaTransparencyL(iBitmap);
       
   605 		}
       
   606 	
       
   607 	const TSize& size = iBitmap->SizeInPixels();
       
   608 				
       
   609 	if(validHeight == size.iHeight)
       
   610 		return;
       
   611 	
       
   612 	const TInt KOffSet = 16;
       
   613 	
       
   614 	//scale image down, leaving margins on sides
       
   615 	//then using fixed point math to get width
       
   616 	const TInt hmul = (validHeight << KOffSet) / size.iHeight;
       
   617 	const TInt validWidth =  (size.iWidth * hmul + (1 << (KOffSet - 1))) >> KOffSet;  // sz * mul + 0.5
       
   618 	const TSize sz(validWidth, validHeight);
       
   619 
       
   620 	//centrify it
       
   621 	TRect rect(TPoint((size.iWidth - sz.iWidth) >> 1, (size.iHeight - sz.iHeight) >> 1), sz);
       
   622 
       
   623 	//it look better if even when centrified
       
   624 	rect.iTl.iX &= ~1; 
       
   625 	rect.iBr.iX |= 1;
       
   626 	
       
   627 	TBool forceFb = 
       
   628 	    AknIconUtils::DoesScaleBitmapUseFallBack( iBitmap );
       
   629 	
       
   630 	if(iMask != NULL)
       
   631 		{
       
   632 		forceFb = forceFb || AknIconUtils::DoesScaleBitmapUseFallBack( iMask );
       
   633 		const TUint32 maskBytes = iMask->DisplayMode() != EGray256 ? 0xFFFFFFFFF : 0x0;
       
   634 		::ScaleL(rect, iMask, maskBytes, forceFb);
       
   635 		}
       
   636 	
       
   637 	::ScaleL(rect, iBitmap, 0xFF000000, forceFb);
       
   638 	
       
   639 	}  
       
   640 
       
   641 // End of File