phonebookui/Phonebook2/Presentation/src/Pbk2PresentationUtils.cpp
branchRCL_3
changeset 3 04ab22b956c2
parent 0 e686773b3f54
child 6 e8e3147d53eb
equal deleted inserted replaced
0:e686773b3f54 3:04ab22b956c2
    19 // INCLUDE FILES
    19 // INCLUDE FILES
    20 #include "Pbk2PresentationUtils.h"
    20 #include "Pbk2PresentationUtils.h"
    21 
    21 
    22 // From system
    22 // From system
    23 #include <featmgr.h>
    23 #include <featmgr.h>
       
    24 #include <fbs.h>
    24 
    25 
    25 /// Namespace for local PresentationUtils definitions
    26 /// Namespace for local PresentationUtils definitions
    26 namespace __RVCT_UNS_Pbk2PresentationUtils {
    27 namespace __RVCT_UNS_Pbk2PresentationUtils {
    27 
    28 
    28 // LOCAL CONSTANTS
    29 // LOCAL CONSTANTS
   223         {
   224         {
   224         return KPbk2PresentationResFileChinese;
   225         return KPbk2PresentationResFileChinese;
   225         }
   226         }
   226     return KPbk2PresentationResFile;
   227     return KPbk2PresentationResFile;
   227     }    
   228     }    
   228     
   229 
   229     
   230 
       
   231 // --------------------------------------------------------------------------
       
   232 // Pbk2PresentationImageUtils::CropImageL
       
   233 // --------------------------------------------------------------------------
       
   234 //
       
   235 EXPORT_C void Pbk2PresentationImageUtils::CropImageL( 
       
   236         CFbsBitmap& aBitmap, 
       
   237         TCroppingMode aCroppingMode, 
       
   238         const TSize& aTargetSize  )
       
   239     {
       
   240     const TSize sourceSize( aBitmap.SizeInPixels() );
       
   241     // crop the image only if the width is bigger than height 
       
   242     if( sourceSize.iHeight >= sourceSize.iWidth )
       
   243         {
       
   244         // no cropping
       
   245         return;
       
   246         }
       
   247     // take the shorter side
       
   248     const TInt sideSize( sourceSize.iHeight );   
       
   249     TInt sideSizeW( sourceSize.iHeight );   
       
   250     if( ELandscapeOptimizedCropping &&
       
   251         sideSizeW < aTargetSize.iWidth )
       
   252         {
       
   253         sideSizeW = aTargetSize.iWidth;
       
   254         if( sideSizeW >= sourceSize.iWidth )
       
   255             {
       
   256             return; // no cropping
       
   257             }
       
   258         }
       
   259     
       
   260     // set target size
       
   261     const TSize targetSize( sideSizeW, sideSize );
       
   262 
       
   263     // crop from both sides
       
   264     const TRect targetRect( TPoint( ( sourceSize.iWidth - targetSize.iWidth ) / 2,
       
   265                               ( sourceSize.iHeight - targetSize.iHeight ) / 2 ),
       
   266                               targetSize );
       
   267     
       
   268     // create new bitmap
       
   269     CFbsBitmap* target = new( ELeave ) CFbsBitmap;
       
   270     CleanupStack::PushL( target );
       
   271     const TDisplayMode displayMode( aBitmap.DisplayMode() );
       
   272     User::LeaveIfError( target->Create( targetSize, displayMode ) );
       
   273     
       
   274     // get scanline
       
   275     HBufC8* scanLine = HBufC8::NewLC( aBitmap.ScanLineLength
       
   276         ( targetSize.iWidth, displayMode ) );
       
   277     TPtr8 scanLinePtr = scanLine->Des();
       
   278     
       
   279     TPoint startPoint( targetRect.iTl.iX, targetRect.iTl.iY );
       
   280     TInt targetY = 0;
       
   281     for (; startPoint.iY < targetRect.iBr.iY; ++startPoint.iY )
       
   282         {
       
   283         aBitmap.GetScanLine( scanLinePtr, startPoint, targetSize.iWidth, displayMode );
       
   284         target->SetScanLine( scanLinePtr, targetY++ );
       
   285         }
       
   286 
       
   287     aBitmap.Reset();
       
   288     User::LeaveIfError( aBitmap.Duplicate( target->Handle() ) );
       
   289     CleanupStack::PopAndDestroy( 2, target ); // scanLine, target    
       
   290     }    
       
   291 
   230 // End of File
   292 // End of File