phonebookui/Phonebook2/Presentation/src/CPbk2ImageReader.cpp
branchRCL_3
changeset 3 04ab22b956c2
parent 0 e686773b3f54
child 15 e8e3147d53eb
equal deleted inserted replaced
0:e686773b3f54 3:04ab22b956c2
    21 #include "CPbk2ImageReader.h"
    21 #include "CPbk2ImageReader.h"
    22 
    22 
    23 // From Phonebook2
    23 // From Phonebook2
    24 #include "MPbk2ImageReaderObserver.h"
    24 #include "MPbk2ImageReaderObserver.h"
    25 #include "TPbk2ImageManagerParams.h"
    25 #include "TPbk2ImageManagerParams.h"
       
    26 #include <Pbk2CmdExtRes.rsg>
       
    27 #include "Pbk2PresentationUtils.h"
    26 
    28 
    27 // From Virtual Phonebook
    29 // From Virtual Phonebook
    28 
    30 
    29 // From System
    31 // From System
    30 #include <imageconversion.h>
    32 #include <imageconversion.h>
    31 #include <bitmaptransforms.h>
    33 #include <bitmaptransforms.h>
    32 #include <JP2KUids.hrh>
    34 #include <JP2KUids.hrh>
       
    35 #include <aknnotewrappers.h>
       
    36 #include <StringLoader.h>
       
    37 #include <AknIconUtils.h>
    33 
    38 
    34 /// Unnamed namespace for local defintions
    39 /// Unnamed namespace for local defintions
    35 namespace {
    40 namespace {
    36 
    41 
    37 // ============== LOCAL CONSTANTS AND MACROS ===============
    42 // ============== LOCAL CONSTANTS AND MACROS ===============
   277     {
   282     {
   278     delete iMimeString;
   283     delete iMimeString;
   279     iMimeString = NULL;
   284     iMimeString = NULL;
   280     iMimeString = HBufC8::NewL(KMaxMimeTypeLength);
   285     iMimeString = HBufC8::NewL(KMaxMimeTypeLength);
   281     TPtr8 mimePtr = iMimeString->Des();
   286     TPtr8 mimePtr = iMimeString->Des();
   282     CImageDecoder::GetMimeTypeFileL(iFsSession, aFileName, mimePtr);
   287     
       
   288     TRAPD( err, CImageDecoder::GetMimeTypeFileL(iFsSession, aFileName, mimePtr) );
       
   289     	
       
   290     if( err == KErrNotFound )
       
   291         {
       
   292         HBufC* prompt = StringLoader::LoadLC( R_QTN_ALBUM_ERR_FORMAT_UNKNOWN );
       
   293         CAknInformationNote* dlg = new ( ELeave ) CAknInformationNote( ETrue );
       
   294         dlg->ExecuteLD( *prompt );
       
   295         CleanupStack::PopAndDestroy( prompt );
       
   296         User::Leave( err );
       
   297         }    		
   283     }
   298     }
   284 
   299 
   285 // --------------------------------------------------------------------------
   300 // --------------------------------------------------------------------------
   286 // CPbk2ImageReader::RecognizeFormatFromBufferL
   301 // CPbk2ImageReader::RecognizeFormatFromBufferL
   287 // --------------------------------------------------------------------------
   302 // --------------------------------------------------------------------------
   383 // CPbk2ImageReader::CropImageToSquareL
   398 // CPbk2ImageReader::CropImageToSquareL
   384 // --------------------------------------------------------------------------
   399 // --------------------------------------------------------------------------
   385 //
   400 //
   386 void CPbk2ImageReader::CropImageToSquareL()
   401 void CPbk2ImageReader::CropImageToSquareL()
   387 	{
   402 	{
   388 	TInt useCropping = 0x0008;
       
   389 	// if cropping is wanted
   403 	// if cropping is wanted
   390 	if( iParams.iFlags & useCropping )	//TODO change value ( contacts_plat/image_managemet_api/TPbk2ImageManagerParams )
   404 	if( iParams.iFlags & TPbk2ImageManagerParams::ECropImage )	
   391 		{
   405 		{
   392 		TSize size = iBitmap->SizeInPixels();
   406         Pbk2PresentationImageUtils::CropImageL( 
   393 		// crop the image only if the width is bigger than height 
   407                 *iBitmap, 
   394 		if( size.iHeight >= size.iWidth )
   408                 Pbk2PresentationImageUtils::ELandscapeOptimizedCropping, 
   395 			{
   409                 iParams.iSize );
   396 			// no cropping
       
   397 			return;
       
   398 			}
       
   399 		// take the shorter side
       
   400 		TInt sideSize = size.iHeight;	
       
   401 		
       
   402 		// set target size
       
   403 		TSize targetSize( sideSize,sideSize );
       
   404 	
       
   405 		// crop from both sides
       
   406 		TRect targetRect( TPoint( ( size.iWidth - targetSize.iWidth ) / 2,
       
   407 								  ( size.iHeight - targetSize.iHeight ) / 2 ),
       
   408 									targetSize );
       
   409 		
       
   410 		// create new bitmap
       
   411 		CFbsBitmap* target = new( ELeave ) CFbsBitmap;
       
   412 		CleanupStack::PushL( target );
       
   413 		User::LeaveIfError( target->Create( targetSize, iBitmap->DisplayMode() ) );
       
   414 		
       
   415 		// get scanline
       
   416 		HBufC8* scanLine = HBufC8::NewLC( iBitmap->ScanLineLength
       
   417 			( targetSize.iWidth, iBitmap->DisplayMode() ) );
       
   418 		TPtr8 scanLinePtr = scanLine->Des();
       
   419 		
       
   420 		TPoint startPoint( targetRect.iTl.iX, targetRect.iTl.iY );
       
   421 		TInt targetY = 0;
       
   422 		for (; startPoint.iY < targetRect.iBr.iY; ++startPoint.iY )
       
   423 			{
       
   424 			iBitmap->GetScanLine( scanLinePtr, startPoint, targetSize.iWidth, iBitmap->DisplayMode() );
       
   425 			target->SetScanLine( scanLinePtr, targetY++ );
       
   426 			}
       
   427 	
       
   428 		iBitmap->Reset();
       
   429 		User::LeaveIfError( iBitmap->Duplicate( target->Handle() ) );
       
   430 		CleanupStack::PopAndDestroy(2, target); // scanLine, target
       
   431 		}
   410 		}
   432 	}
   411 	}
   433 
   412 
   434 
   413 
   435 // --------------------------------------------------------------------------
   414 // --------------------------------------------------------------------------
   438 //
   417 //
   439 void CPbk2ImageReader::ScaleBitmapL()
   418 void CPbk2ImageReader::ScaleBitmapL()
   440     {
   419     {
   441     __ASSERT_DEBUG(iBitmap, Panic(EPanicPreCond_ScaleBitmapL));
   420     __ASSERT_DEBUG(iBitmap, Panic(EPanicPreCond_ScaleBitmapL));
   442 
   421 
       
   422     const TSize bitmapSize = iBitmap->SizeInPixels();
   443     if ((iParams.iFlags & TPbk2ImageManagerParams::EScaleImage) && 
   423     if ((iParams.iFlags & TPbk2ImageManagerParams::EScaleImage) && 
   444         !(iParams.iFlags & TPbk2ImageManagerParams::EUseFastScaling))
   424          !(iParams.iFlags & TPbk2ImageManagerParams::EUseFastScaling) &&
   445         {
   425          (iParams.iFlags & TPbk2ImageManagerParams::EUseSpeedOptimizedScaling) &&
   446         const TSize bitmapSize = iBitmap->SizeInPixels();
   426          ( bitmapSize.iHeight == bitmapSize.iWidth ) )
       
   427         {
       
   428         if( bitmapSize.iWidth > iParams.iSize.iWidth || 
       
   429             bitmapSize.iHeight > iParams.iSize.iHeight )
       
   430             {
       
   431             // Use avkon scaler
       
   432             TRect targetRect(TPoint(0,0), 
       
   433                     TSize( ( iParams.iSize.iWidth ), 
       
   434                            ( iParams.iSize.iHeight ) ) );
       
   435             
       
   436             CFbsBitmap* target = new( ELeave ) CFbsBitmap;
       
   437             CleanupStack::PushL( target );
       
   438             User::LeaveIfError( target->Create( 
       
   439                     targetRect.Size(), iBitmap->DisplayMode() ) );
       
   440             
       
   441             AknIconUtils::ScaleBitmapL( targetRect, target, iBitmap );
       
   442             
       
   443             iBitmap->Reset();
       
   444             User::LeaveIfError( iBitmap->Duplicate( target->Handle() ) );
       
   445             CleanupStack::PopAndDestroy( target );
       
   446             
       
   447             NextStateL();
       
   448             return;
       
   449             }
       
   450         }
       
   451     else if ((iParams.iFlags & TPbk2ImageManagerParams::EScaleImage) && 
       
   452              !(iParams.iFlags & TPbk2ImageManagerParams::EUseFastScaling) )
       
   453         {
   447         if (bitmapSize.iWidth > iParams.iSize.iWidth || 
   454         if (bitmapSize.iWidth > iParams.iSize.iWidth || 
   448             bitmapSize.iHeight > iParams.iSize.iHeight)
   455             bitmapSize.iHeight > iParams.iSize.iHeight)
   449             {
   456             {
   450             if (!iBitmapScaler)
   457             if (!iBitmapScaler)
   451                 {
   458                 {
   454             iBitmapScaler->Scale(&iStatus, *iBitmap, iParams.iSize);
   461             iBitmapScaler->Scale(&iStatus, *iBitmap, iParams.iSize);
   455             SetActive();
   462             SetActive();
   456             return;
   463             return;
   457             }
   464             }
   458         }
   465         }
   459 
   466     
   460     // No scaling requested or needed, go directly to next state
   467     // No scaling requested or needed, go directly to next state
   461     NextStateL();
   468     NextStateL();
   462     }
   469     }
   463 
   470 
   464 // --------------------------------------------------------------------------
   471 // --------------------------------------------------------------------------