phonebookui/Phonebook2/Presentation/src/CPbk2ImageReader.cpp
branchRCL_3
changeset 15 e8e3147d53eb
parent 3 04ab22b956c2
child 64 c1e8ba0c2b16
equal deleted inserted replaced
14:81f8547efd4f 15:e8e3147d53eb
    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 #include "Pbk2PresentationUtils.h"
    28 
    27 
    29 // From Virtual Phonebook
    28 // From Virtual Phonebook
    30 
    29 
    31 // From System
    30 // From System
   104 TInt Ceil(const TInt aVal, const TInt aDiv)
   103 TInt Ceil(const TInt aVal, const TInt aDiv)
   105     {
   104     {
   106     return (((aVal%aDiv)>0) ? (TInt)((aVal/aDiv)+1):(TInt)(aVal/aDiv));
   105     return (((aVal%aDiv)>0) ? (TInt)((aVal/aDiv)+1):(TInt)(aVal/aDiv));
   107     }
   106     }
   108 
   107 
   109 
       
   110 /**
   108 /**
   111  * Calculates the the size based on divider. Uses Ceil function for ceiling
   109  * Calculates the the size based on divider. Uses Ceil function for ceiling
   112  * the calculated size.
   110  * the calculated size.
   113  *
   111  *
   114  * @param aSize Orginal size.
   112  * @param aSize Orginal size.
   163                    || (aNeededSize <= resSize && resSize <= aOriginalSize),
   161                    || (aNeededSize <= resSize && resSize <= aOriginalSize),
   164                    Panic(EPanicPostCond_OptimalLoadingSize));
   162                    Panic(EPanicPostCond_OptimalLoadingSize));
   165 
   163 
   166     return resSize;
   164     return resSize;
   167     }
   165     }
   168 
       
   169 }  // namespace
   166 }  // namespace
   170 
   167 
   171 
   168 
   172 // ================= MEMBER FUNCTIONS =======================
   169 // ================= MEMBER FUNCTIONS =======================
   173 
   170 
   228         (const TDesC& aFileName, const TPbk2ImageManagerParams* aParams)
   225         (const TDesC& aFileName, const TPbk2ImageManagerParams* aParams)
   229     {
   226     {
   230     InitReadL(aParams);
   227     InitReadL(aParams);
   231     delete iImageDecoder;
   228     delete iImageDecoder;
   232     iImageDecoder = NULL;
   229     iImageDecoder = NULL;
   233     iImageDecoder = CImageDecoder::FileNewL(iFsSession, aFileName);
   230                
       
   231     TRAPD( err, iImageDecoder = CImageDecoder::FileNewL( iFsSession, aFileName ) );
   234 
   232 
   235     // Make the open phase asynchronous as well by signaling own iStatus
   233     // Make the open phase asynchronous as well by signaling own iStatus
   236     iState = EStateOpenImage;
   234     iState = EStateOpenImage;
   237     TRequestStatus* status = &iStatus;
   235     TRequestStatus* status = &iStatus;
   238     User::RequestComplete(status, KErrNone);
   236     User::RequestComplete( status, err );            
   239     SetActive();
   237     SetActive();
   240     }
   238     }
   241 
   239 
   242 // --------------------------------------------------------------------------
   240 // --------------------------------------------------------------------------
   243 // CPbk2ImageReader::ReadFromBufferL
   241 // CPbk2ImageReader::ReadFromBufferL
   247         (const TDesC8& aBuffer, const TPbk2ImageManagerParams* aParams/*=NULL*/)
   245         (const TDesC8& aBuffer, const TPbk2ImageManagerParams* aParams/*=NULL*/)
   248     {
   246     {
   249     InitReadL(aParams);
   247     InitReadL(aParams);
   250     delete iImageDecoder;
   248     delete iImageDecoder;
   251     iImageDecoder = NULL;
   249     iImageDecoder = NULL;
   252     iImageDecoder = CImageDecoder::DataNewL(iFsSession, aBuffer);
   250     TRAPD( err, iImageDecoder = CImageDecoder::DataNewL( iFsSession, aBuffer ) );
   253 
   251     
   254     // Make the open phase asynchronous as well by signaling own iStatus
   252     // Make the open phase asynchronous as well by signaling own iStatus
   255     iState = EStateOpenImage;
   253     iState = EStateOpenImage;
   256     TRequestStatus* status = &iStatus;
   254     TRequestStatus* status = &iStatus;
   257     User::RequestComplete(status, KErrNone);
   255     User::RequestComplete( status, err );
   258     SetActive();
   256     SetActive();
   259     }
   257     }
   260 
   258 
   261 // --------------------------------------------------------------------------
   259 // --------------------------------------------------------------------------
   262 // CPbk2ImageReader::MimeString
   260 // CPbk2ImageReader::MimeString
   283     delete iMimeString;
   281     delete iMimeString;
   284     iMimeString = NULL;
   282     iMimeString = NULL;
   285     iMimeString = HBufC8::NewL(KMaxMimeTypeLength);
   283     iMimeString = HBufC8::NewL(KMaxMimeTypeLength);
   286     TPtr8 mimePtr = iMimeString->Des();
   284     TPtr8 mimePtr = iMimeString->Des();
   287     
   285     
   288     TRAPD( err, CImageDecoder::GetMimeTypeFileL(iFsSession, aFileName, mimePtr) );
   286     TRAPD( err, CImageDecoder::GetMimeTypeFileL( iFsSession, aFileName, mimePtr ) );
   289     	
   287     	    
   290     if( err == KErrNotFound )
   288     if( err != KErrNone )
   291         {
   289         {
   292         HBufC* prompt = StringLoader::LoadLC( R_QTN_ALBUM_ERR_FORMAT_UNKNOWN );
   290         iObserver.ImageReadFailed( *this, err );           
   293         CAknInformationNote* dlg = new ( ELeave ) CAknInformationNote( ETrue );
   291         }    
   294         dlg->ExecuteLD( *prompt );
       
   295         CleanupStack::PopAndDestroy( prompt );
       
   296         User::Leave( err );
       
   297         }    		
       
   298     }
   292     }
   299 
   293 
   300 // --------------------------------------------------------------------------
   294 // --------------------------------------------------------------------------
   301 // CPbk2ImageReader::RecognizeFormatFromBufferL
   295 // CPbk2ImageReader::RecognizeFormatFromBufferL
   302 // --------------------------------------------------------------------------
   296 // --------------------------------------------------------------------------
   305     {
   299     {
   306     delete iMimeString;
   300     delete iMimeString;
   307     iMimeString = NULL;
   301     iMimeString = NULL;
   308     iMimeString = HBufC8::NewL(KMaxMimeTypeLength);
   302     iMimeString = HBufC8::NewL(KMaxMimeTypeLength);
   309     TPtr8 mimePtr = iMimeString->Des();
   303     TPtr8 mimePtr = iMimeString->Des();
   310     CImageDecoder::GetMimeTypeDataL(aBuffer, mimePtr);
   304     TRAPD( err, CImageDecoder::GetMimeTypeDataL( aBuffer, mimePtr ) );
       
   305         
       
   306     if( err != KErrNone )
       
   307         {
       
   308         iObserver.ImageReadFailed( *this, err );           
       
   309         }    
   311     }
   310     }
   312 
   311 
   313 // --------------------------------------------------------------------------
   312 // --------------------------------------------------------------------------
   314 // CPbk2ImageReader::FrameInfo
   313 // CPbk2ImageReader::FrameInfo
   315 // --------------------------------------------------------------------------
   314 // --------------------------------------------------------------------------
   390 
   389 
   391     // Convert image to bitmap
   390     // Convert image to bitmap
   392     iImageDecoder->Convert(&iStatus, *iBitmap, iParams.iFrameNumber);
   391     iImageDecoder->Convert(&iStatus, *iBitmap, iParams.iFrameNumber);
   393     SetActive();
   392     SetActive();
   394     }
   393     }
   395 
       
   396 
   394 
   397 // --------------------------------------------------------------------------
   395 // --------------------------------------------------------------------------
   398 // CPbk2ImageReader::CropImageToSquareL
   396 // CPbk2ImageReader::CropImageToSquareL
   399 // --------------------------------------------------------------------------
   397 // --------------------------------------------------------------------------
   400 //
   398 //
   403 	// if cropping is wanted
   401 	// if cropping is wanted
   404 	if( iParams.iFlags & TPbk2ImageManagerParams::ECropImage )	
   402 	if( iParams.iFlags & TPbk2ImageManagerParams::ECropImage )	
   405 		{
   403 		{
   406         Pbk2PresentationImageUtils::CropImageL( 
   404         Pbk2PresentationImageUtils::CropImageL( 
   407                 *iBitmap, 
   405                 *iBitmap, 
   408                 Pbk2PresentationImageUtils::ELandscapeOptimizedCropping, 
   406                 Pbk2PresentationImageUtils::EOptimizedCropping, 
   409                 iParams.iSize );
   407                 iParams.iSize );
   410 		}
   408 		}
   411 	}
   409 	}
   412 
       
   413 
   410 
   414 // --------------------------------------------------------------------------
   411 // --------------------------------------------------------------------------
   415 // CPbk2ImageReader::ScaleBitmapL
   412 // CPbk2ImageReader::ScaleBitmapL
   416 // --------------------------------------------------------------------------
   413 // --------------------------------------------------------------------------
   417 //
   414 //
   522 // --------------------------------------------------------------------------
   519 // --------------------------------------------------------------------------
   523 //
   520 //
   524 void CPbk2ImageReader::RunL()
   521 void CPbk2ImageReader::RunL()
   525     {
   522     {
   526     TInt status = iStatus.Int();
   523     TInt status = iStatus.Int();
       
   524         
   527     switch (status)
   525     switch (status)
   528         {
   526         {
   529         case KErrNone:
   527         case KErrNone:
   530             {
   528             {
   531             if (iState == EStateOpenImage)
   529             if (iState == EStateOpenImage)
   539             {
   537             {
   540             // In case of cancel the observer is not signaled
   538             // In case of cancel the observer is not signaled
   541             break;
   539             break;
   542             }
   540             }
   543         default:
   541         default:
   544             {
   542             {                              
   545             // Jpeg2000 decoder might need more heap than Phonebook can 
   543             // Jpeg2000 decoder might need more heap than Phonebook can 
   546             // provide, the situation is handled so, that "Feature not 
   544             // provide, the situation is handled so, that "Feature not 
   547             // supported" -note is shown if memory runs out when decoding 
   545             // supported" -note is shown if memory runs out when decoding 
   548             // Jpeg2000 image instead of "Out of memory" -note.
   546             // Jpeg2000 image instead of "Out of memory" -note.
   549             //
   547             //
   553             // Increasing phonebook heap size doesn't help on this issue,
   551             // Increasing phonebook heap size doesn't help on this issue,
   554             // since jp2 decoder heap usage is increased linearly when a bigger
   552             // since jp2 decoder heap usage is increased linearly when a bigger
   555             // image is tried to be decoded.
   553             // image is tried to be decoded.
   556             if ( status == KErrNoMemory )            
   554             if ( status == KErrNoMemory )            
   557                 {
   555                 {
       
   556                 
   558                 TUid imageType;
   557                 TUid imageType;
   559                 TUid imageSubType;
   558                 TUid imageSubType;
   560                 iImageDecoder->ImageType(iParams.iFrameNumber, 
   559                 iImageDecoder->ImageType(iParams.iFrameNumber, 
   561                                          imageType, 
   560                                          imageType, 
   562                                          imageSubType);
   561                                          imageSubType);
   563 
   562 
   564                 if ( imageType.iUid == KImageTypeJ2KUid )
   563                 if ( imageType.iUid == KImageTypeJ2KUid )
   565                     {
   564                     {
   566                     status = KErrNotSupported;
   565                     status = KErrNotSupported;
   567                     }
   566                     }
   568                 }            
   567                 }                   
       
   568             
   569             iObserver.ImageReadFailed(*this, status);
   569             iObserver.ImageReadFailed(*this, status);
   570             break;
   570             break;
   571             }
   571             }
   572         }
   572         }
   573     }
   573     }