phonebookui/Phonebook2/Presentation/src/Pbk2PresentationUtils.cpp
branchRCL_3
changeset 6 e8e3147d53eb
parent 3 04ab22b956c2
equal deleted inserted replaced
5:81f8547efd4f 6:e8e3147d53eb
   236         CFbsBitmap& aBitmap, 
   236         CFbsBitmap& aBitmap, 
   237         TCroppingMode aCroppingMode, 
   237         TCroppingMode aCroppingMode, 
   238         const TSize& aTargetSize  )
   238         const TSize& aTargetSize  )
   239     {
   239     {
   240     const TSize sourceSize( aBitmap.SizeInPixels() );
   240     const TSize sourceSize( aBitmap.SizeInPixels() );
   241     // crop the image only if the width is bigger than height 
   241     // crop the image only if the width is bigger than height
       
   242     TBool landscape( ETrue );
   242     if( sourceSize.iHeight >= sourceSize.iWidth )
   243     if( sourceSize.iHeight >= sourceSize.iWidth )
   243         {
   244         {
   244         // no cropping
   245         // portrait image
   245         return;
   246         landscape = EFalse;
   246         }
   247         }
   247     // take the shorter side
   248     // take the shorter side
   248     const TInt sideSize( sourceSize.iHeight );   
   249     const TInt sideSizeH( 
   249     TInt sideSizeW( sourceSize.iHeight );   
   250             landscape ? sourceSize.iHeight : sourceSize.iWidth );
   250     if( ELandscapeOptimizedCropping &&
   251     const TInt targetSizeW( 
   251         sideSizeW < aTargetSize.iWidth )
   252             landscape ? aTargetSize.iWidth : aTargetSize.iHeight );
   252         {
   253     TInt sideSizeW( sideSizeH );   
   253         sideSizeW = aTargetSize.iWidth;
   254     if( EOptimizedCropping == aCroppingMode &&
   254         if( sideSizeW >= sourceSize.iWidth )
   255         sideSizeW < targetSizeW )
       
   256         {
       
   257         sideSizeW = targetSizeW;
       
   258         if( sideSizeW >= 
       
   259                 ( landscape ? sourceSize.iWidth : sourceSize.iHeight ) )
   255             {
   260             {
   256             return; // no cropping
   261             return; // no cropping
   257             }
   262             }
   258         }
   263         }
   259     
   264     
   260     // set target size
   265     // set target size
   261     const TSize targetSize( sideSizeW, sideSize );
   266     const TSize targetSize( landscape? 
       
   267             TSize(sideSizeW, sideSizeH ): TSize( sideSizeH, sideSizeW ) );
   262 
   268 
   263     // crop from both sides
   269     // crop from both sides
   264     const TRect targetRect( TPoint( ( sourceSize.iWidth - targetSize.iWidth ) / 2,
   270     const TPoint targetPoint( ( sourceSize.iWidth - targetSize.iWidth ) / 2,
   265                               ( sourceSize.iHeight - targetSize.iHeight ) / 2 ),
   271                               ( sourceSize.iHeight - targetSize.iHeight ) / 2 );
   266                               targetSize );
   272     const TRect targetRect( targetPoint, targetSize );
   267     
   273     
   268     // create new bitmap
   274     // create new bitmap
   269     CFbsBitmap* target = new( ELeave ) CFbsBitmap;
   275     CFbsBitmap* target = new( ELeave ) CFbsBitmap;
   270     CleanupStack::PushL( target );
   276     CleanupStack::PushL( target );
   271     const TDisplayMode displayMode( aBitmap.DisplayMode() );
   277     const TDisplayMode displayMode( aBitmap.DisplayMode() );
   278     
   284     
   279     TPoint startPoint( targetRect.iTl.iX, targetRect.iTl.iY );
   285     TPoint startPoint( targetRect.iTl.iX, targetRect.iTl.iY );
   280     TInt targetY = 0;
   286     TInt targetY = 0;
   281     for (; startPoint.iY < targetRect.iBr.iY; ++startPoint.iY )
   287     for (; startPoint.iY < targetRect.iBr.iY; ++startPoint.iY )
   282         {
   288         {
   283         aBitmap.GetScanLine( scanLinePtr, startPoint, targetSize.iWidth, displayMode );
   289         aBitmap.GetScanLine( 
       
   290                 scanLinePtr, startPoint, targetSize.iWidth, displayMode );
   284         target->SetScanLine( scanLinePtr, targetY++ );
   291         target->SetScanLine( scanLinePtr, targetY++ );
   285         }
   292         }
   286 
   293 
   287     aBitmap.Reset();
   294     aBitmap.Reset();
   288     User::LeaveIfError( aBitmap.Duplicate( target->Handle() ) );
   295     User::LeaveIfError( aBitmap.Duplicate( target->Handle() ) );