EngSrc/IEBitmapLoader.cpp
changeset 3 93fff7023be8
equal deleted inserted replaced
2:e1e28b0273b0 3:93fff7023be8
       
     1 /*
       
     2 * Copyright (c) 2009 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: Juha Kauppinen, Mika Hokkanen
       
    13 * 
       
    14 * Description: Photo Browser
       
    15 *
       
    16 */
       
    17 // Include files
       
    18 #include <hal.h> 
       
    19 #include "IEBitmapLoader.h"
       
    20 #include "IEFileLoader.h"
       
    21 #include "IEEngineUtils.h"
       
    22 
       
    23 _LIT8(KMimeMbm, "image/x-epoc-mbm");
       
    24 _LIT8(KMimeJpeg, "image/jpeg");
       
    25 
       
    26 #define USE_EXIF_TN
       
    27 #define USE_EXIF_TN_CROP
       
    28 //#define USE_EXIF_TN_EXT_CROP
       
    29 
       
    30 #ifdef USE_EXIF_TN
       
    31 #include <iclextjpegapi.h>  // For CExtJpegDecoder
       
    32 #endif
       
    33 
       
    34 const TInt KMemoryThresholdForSuperZoom = 12*1024;
       
    35 
       
    36 
       
    37 // ============================ MEMBER FUNCTIONS =========================== \\
       
    38 
       
    39 CIEBitmapLoader* CIEBitmapLoader::NewL(RFs& aFileServer, MBitmapLoaderObserver& aBitmapLoaderObserver, RCriticalSection* aCritical)
       
    40 {
       
    41  	CIEBitmapLoader* self = new (ELeave) CIEBitmapLoader(aFileServer, aBitmapLoaderObserver, aCritical);
       
    42 	CleanupStack::PushL(self);
       
    43 	self->ConstructL();
       
    44 	CleanupStack::Pop();
       
    45 	return self;
       
    46 }
       
    47 
       
    48 CIEBitmapLoader::~CIEBitmapLoader()
       
    49     {
       
    50     DP0_IMAGIC(_L("CIEBitmapLoader::~CIEBitmapLoader++"));
       
    51   	if(iImageDecoder)
       
    52   	    {
       
    53   	    iImageDecoder->Cancel();
       
    54 		delete iImageDecoder;
       
    55 		iImageDecoder = NULL;	
       
    56         }
       
    57   	
       
    58     if (iExifBitmap)
       
    59         {
       
    60         delete iExifBitmap;
       
    61         iExifBitmap = NULL;
       
    62         }
       
    63 #ifdef DECODE_FROM_BUFFER    
       
    64     if(iSourceData) 
       
    65         {
       
    66         delete iSourceData;
       
    67         iSourceData = NULL;
       
    68         }
       
    69 #endif
       
    70     DP0_IMAGIC(_L("CIEBitmapLoader::~CIEBitmapLoader--"));
       
    71   	}
       
    72  
       
    73 CIEBitmapLoader::CIEBitmapLoader(RFs& aFileServer, MBitmapLoaderObserver& aBitmapLoaderObserver, RCriticalSection* aCritical)
       
    74     //:CActive(EPriorityLow),    
       
    75     :CActive(EPriorityStandard),
       
    76     //:CActive(EPriorityUserInput),
       
    77     //:CActive(CActive::EPriorityHigh),
       
    78     iFileServer(aFileServer), 
       
    79     iBitmapLoaderObserver(aBitmapLoaderObserver),
       
    80 #ifdef DECODE_FROM_BUFFER    
       
    81     iSourceData(NULL), 
       
    82 #endif        
       
    83     iCritical(aCritical)
       
    84     {
       
    85     }
       
    86 
       
    87 void CIEBitmapLoader::ConstructL()
       
    88     {
       
    89 	CActiveScheduler::Add(this);
       
    90 	iExifTn = NULL;
       
    91 	iImageDecoder = NULL;
       
    92 	iImageArrayMode = EImages;
       
    93 	iOutputBitmap = NULL;
       
    94 	iExifBitmap = NULL;
       
    95 #ifdef GET_DECODER_UID
       
    96 	decoderUid = CIEEngineUtils::GetImageDecoderUid();	
       
    97 #else
       
    98 	decoderUid = KNullUid;
       
    99 #endif
       
   100     }
       
   101 
       
   102 void CIEBitmapLoader::CropImageL(CFbsBitmap* aOutput, CFbsBitmap* aInput) const
       
   103     {
       
   104     const TInt KMaxScanLine = 320 * 3;
       
   105     TSize inputSize = aInput->SizeInPixels();
       
   106     TSize outputSize = aOutput->SizeInPixels();
       
   107     TDisplayMode mode = aOutput->DisplayMode();
       
   108     
       
   109     // need to have same display mode and output cannot be bigger
       
   110     if (mode != aInput->DisplayMode() || 
       
   111         outputSize.iWidth > inputSize.iWidth ||
       
   112         outputSize.iHeight > inputSize.iHeight)
       
   113         User::Leave(KErrNotSupported);
       
   114 
       
   115     TInt len = CFbsBitmap::ScanLineLength(outputSize.iWidth, mode);
       
   116     TBuf8<KMaxScanLine> buf;
       
   117     if (len > KMaxScanLine)
       
   118         {
       
   119         User::Leave(KErrOverflow);
       
   120         }
       
   121     
       
   122     TPoint point((inputSize.iWidth - outputSize.iWidth + 1) / 2,
       
   123                  (inputSize.iHeight - outputSize.iHeight + 1) / 2);
       
   124     for (TInt i = 0;i < outputSize.iHeight;i++, point.iY++)
       
   125         {
       
   126         aInput->GetScanLine(buf, point, outputSize.iWidth, mode);
       
   127         aOutput->SetScanLine(buf, i);
       
   128         }
       
   129     }
       
   130 
       
   131 void CIEBitmapLoader::RunL()
       
   132     {
       
   133     DP0_IMAGIC(_L("CIEBitmapLoader::RunL++"));
       
   134     
       
   135     SetPriority(EPriorityStandard);
       
   136     iThumbRes = ENotDefined;
       
   137 	TInt error = iStatus.Int();
       
   138 	
       
   139 	DP1_IMAGIC(_L("CIEBitmapLoader::RunL - Error: %d"),error);
       
   140 	
       
   141 	if(iImageDecoder)
       
   142 	    {
       
   143         delete iImageDecoder;
       
   144         iImageDecoder = NULL;   
       
   145 	    }
       
   146 	
       
   147 #ifdef DECODE_FROM_BUFFER    
       
   148     if(iSourceData) 
       
   149         {
       
   150         delete iSourceData;
       
   151         iSourceData = NULL;
       
   152         }
       
   153 #endif
       
   154 	
       
   155 #ifdef USE_EXIF_TN
       
   156     if (iExifTn)
       
   157         {
       
   158         delete iExifTn;
       
   159         iExifTn = NULL;
       
   160         }   
       
   161 	
       
   162 	if(iUseExifTn && iImageData && error == KErrNone) 
       
   163 	    {
       
   164 	    iImageData->SetImageReady(EExifThumb, ETrue);
       
   165 	    
       
   166 	    // Crop exif thumbnail
       
   167 	    if (iExifBitmap && iOutputBitmap)
       
   168 	        {
       
   169 	        TRAP(error, CropImageL(iOutputBitmap, iExifBitmap));
       
   170 	        }
       
   171 	    }
       
   172 
       
   173 	if (iExifBitmap)
       
   174 	    {
       
   175 	    delete iExifBitmap;
       
   176 	    iExifBitmap = NULL;
       
   177 	    }
       
   178 	
       
   179     iOutputBitmap = NULL;
       
   180 #endif
       
   181     
       
   182 	iBitmapLoaderObserver.BitmapsLoadedL(error);
       
   183 	
       
   184 	DP0_IMAGIC(_L("CIEBitmapLoader::RunL--"));
       
   185     }
       
   186 
       
   187 void CIEBitmapLoader::DoCancel()
       
   188     {
       
   189     }
       
   190 
       
   191 TInt CIEBitmapLoader::RunError(TInt aError)
       
   192     {
       
   193     DP1_IMAGIC(_L("CIEBitmapLoader::RunError - Error: %d"),aError);
       
   194     
       
   195     return KErrNone;
       
   196     }
       
   197 
       
   198 void CIEBitmapLoader::GetOneBitmapL(CImageData* aImageData, CFbsBitmap* aBitmap, TThumbSize aThumbRes)
       
   199     {
       
   200     DP0_IMAGIC(_L("CIEBitmapLoader::GetOneBitmapL++"));
       
   201     DP1_IMAGIC(_L("CIEBitmapLoader::GetOneBitmapL - TN res: %d"), aThumbRes);
       
   202 
       
   203     ASSERT(iImageDecoder == NULL);    
       
   204     
       
   205     iThumbRes = aThumbRes;
       
   206     TBool thumbnailExists = ETrue;
       
   207     //TBool isFileJpg = ETrue;
       
   208     iUseExifTn = EFalse;
       
   209     iImageData = aImageData;
       
   210     iOutputBitmap = aBitmap;
       
   211     
       
   212 #ifdef USE_EXIF_TN    
       
   213     CExtJpegDecoder* extImageDecoder = NULL;
       
   214 #endif    
       
   215     
       
   216     TFileName fileName;
       
   217     if(aThumbRes == EFullSize)
       
   218         {
       
   219         if(iImageData->IsImageReady(EFullSize))
       
   220             {
       
   221             //SetPriority(EPriorityUserInput);
       
   222             iImageData->GetFileName(fileName, EFullSize);
       
   223             DP1_IMAGIC(_L("CIEBitmapLoader::GetOneBitmapL - filename: %S"), &fileName);
       
   224             }
       
   225         else
       
   226             {
       
   227             //If TN is not ready we just return
       
   228             DP1_IMAGIC(_L("CIEBitmapLoader::GetOneBitmapL - TN res: %d, not found"), aThumbRes);
       
   229             thumbnailExists = EFalse;
       
   230             //iBitmapLoaderObserver.BitmapsLoadedL(KErrNotFound);
       
   231             User::Leave(KErrNotFound);
       
   232             return;
       
   233             }
       
   234         }
       
   235     else if(aThumbRes == ESize128x128)
       
   236         {
       
   237 #ifdef USE_64X64_BITMAP_TN
       
   238         //isFileJpg = EFalse;
       
   239         iImageData->GetFileName(fileName, ESize128x128);
       
   240         DP1_IMAGIC(_L("CIEBitmapLoader::GetOneBitmapL - filename: %S"), &fileName);
       
   241         TInt error = aBitmap->Load(fileName);
       
   242         if (error == KErrNone)
       
   243             {
       
   244             SetPriority(EPriorityUserInput);
       
   245             SetActive();
       
   246             TRequestStatus* status = &iStatus;
       
   247             User::RequestComplete(status, KErrNone);
       
   248             return;
       
   249             }
       
   250         
       
   251 #ifdef USE_EXIF_TN
       
   252         else if(iImageData->IsImageReady(EFullSize))
       
   253             {
       
   254             iUseExifTn = ETrue;
       
   255             iImageData->GetFileName(fileName, EFullSize);
       
   256             DP1_IMAGIC(_L("CIEBitmapLoader::GetOneBitmapL - filename: %S"), &fileName);
       
   257             }
       
   258 #endif
       
   259         else
       
   260             {
       
   261             //If TN is not ready we just return
       
   262             DP1_IMAGIC(_L("CIEBitmapLoader::GetOneBitmapL - TN res: %d, not found"), aThumbRes);
       
   263             thumbnailExists = EFalse;     
       
   264             iImageData->SetImageReady(EExifThumb, EFalse);
       
   265             User::Leave(KErrNotFound);
       
   266             return;
       
   267             }
       
   268 #else
       
   269         if(iImageData->IsImageReady(ESize128x128))
       
   270             {
       
   271             SetPriority(EPriorityUserInput);
       
   272             //isFileJpg = EFalse;
       
   273             iImageData->GetFileName(fileName, ESize128x128);
       
   274             DP1_IMAGIC(_L("CIEBitmapLoader::GetOneBitmapL - filename: %S"), &fileName);
       
   275             }
       
   276 #ifdef USE_EXIF_TN
       
   277         //else if(iImageData->IsImageReady((TThumbSize)(EFullSize|EExifThumb)))
       
   278         else if(iImageData->IsImageReady(EExifThumb))
       
   279             {
       
   280             SetPriority(EPriorityUserInput);
       
   281             iUseExifTn = ETrue;
       
   282             iImageData->GetFileName(fileName, EFullSize);
       
   283             DP1_IMAGIC(_L("CIEBitmapLoader::GetOneBitmapL - filename: %S"), &fileName);
       
   284             }
       
   285 #endif
       
   286         else
       
   287             {
       
   288             //If TN is not ready we just return
       
   289             DP1_IMAGIC(_L("CIEBitmapLoader::GetOneBitmapL - TN res: %d, not found"), aThumbRes);
       
   290             
       
   291             thumbnailExists = EFalse;
       
   292             iImageData->SetImageReady(EExifThumb, EFalse);
       
   293             //iBitmapLoaderObserver.BitmapsLoadedL(KErrNotFound);
       
   294             User::Leave(KErrNotFound);
       
   295             return;
       
   296             }
       
   297 #endif
       
   298         }
       
   299     
       
   300     else if(aThumbRes == ESize512x512)
       
   301         {
       
   302         if(iImageData->IsImageReady(ESize512x512))
       
   303             {
       
   304             iImageData->GetFileName(fileName, ESize512x512);
       
   305             DP1_IMAGIC(_L("CIEBitmapLoader::GetOneBitmapL - filename: %S"), &fileName);
       
   306             }
       
   307         else
       
   308             {
       
   309             //If TN is not ready we just return
       
   310             DP1_IMAGIC(_L("CIEBitmapLoader::GetOneBitmapL - TN res: %d, not found"), aThumbRes);
       
   311             thumbnailExists = EFalse;
       
   312             iImageData->SetImageReady(EExifThumb, EFalse);
       
   313             User::Leave(KErrNotFound);
       
   314             return;
       
   315             }
       
   316         }
       
   317     else if(aThumbRes == ESize32x32)
       
   318         {
       
   319         if(iImageData->IsImageReady(ESize32x32))
       
   320             {
       
   321             //isFileJpg = EFalse;
       
   322             iImageData->GetFileName(fileName, ESize32x32);
       
   323             DP1_IMAGIC(_L("CIEBitmapLoader::GetOneBitmapL - filename: %S"), &fileName);
       
   324             TInt error = aBitmap->Load(fileName);
       
   325             if (error == KErrNone)
       
   326                 {
       
   327                 SetPriority(EPriorityUserInput);
       
   328                 SetActive();
       
   329                 TRequestStatus* status = &iStatus;
       
   330                 User::RequestComplete(status, KErrNone);
       
   331                 return;
       
   332                 }
       
   333             }
       
   334 #ifdef USE_EXIF_TN
       
   335         else if(iImageData->IsImageReady(EFullSize))
       
   336             {
       
   337             iUseExifTn = ETrue;
       
   338             iImageData->GetFileName(fileName, EFullSize);
       
   339             DP1_IMAGIC(_L("CIEBitmapLoader::GetOneBitmapL - filename: %S"), &fileName);
       
   340             }
       
   341 #endif
       
   342         else
       
   343             {
       
   344             //If TN is not ready we just return
       
   345             DP1_IMAGIC(_L("CIEBitmapLoader::GetOneBitmapL - TN res: %d, not found"), aThumbRes);
       
   346             thumbnailExists = EFalse;     
       
   347             iImageData->SetImageReady(EExifThumb, EFalse);
       
   348             User::Leave(KErrNotFound);
       
   349             return;
       
   350             }
       
   351         }
       
   352             
       
   353     if(thumbnailExists)
       
   354         {
       
   355         TInt error = KErrNone;
       
   356         
       
   357 #ifdef USE_EXIF_TN
       
   358         if (iUseExifTn)
       
   359             {
       
   360             ASSERT(iExifTn == NULL);
       
   361             TRAP(error, iExifTn = CIEEngineUtils::ReadExifThumbnailL(iFileServer, fileName));
       
   362         
       
   363             DP0_IMAGIC(_L("CIEBitmapLoader::GetOneBitmapL - create decoder"));
       
   364             if (error == KErrNone)
       
   365                 {
       
   366                 DP1_IMAGIC(_L("CIEBitmapLoader::GetOneBitmapL data size: %d"), iExifTn->Length());
       
   367                 TRAP(error, extImageDecoder = CExtJpegDecoder::DataNewL(iFileServer, *iExifTn, /*KMimeJpeg,*/ CImageDecoder::EOptionNone));
       
   368                 iImageDecoder = extImageDecoder;
       
   369                 }
       
   370             else
       
   371                 {
       
   372                 DP0_IMAGIC(_L("CIEBitmapLoader::GetOneBitmapL - no exif thumb"));
       
   373                 iImageData->SetImageReady(EExifThumb, EFalse);
       
   374                 }
       
   375 
       
   376             DP2_IMAGIC(_L("CIEBitmapLoader::GetOneBitmapL - Image exif thumb decoder - TN res: %d, error: %d"), aThumbRes, error);
       
   377             }
       
   378         else
       
   379 #endif
       
   380             {
       
   381             DP0_IMAGIC(_L("CIEBitmapLoader::GetOneBitmapL - create decoder"));
       
   382             /*CExtJpegDecoder * extImageDecoder;
       
   383             TRAP(error, iImageDecoder = extImageDecoder = CExtJpegDecoder::FileNewL(
       
   384                     CExtJpegDecoder::EHwImplementation,
       
   385                     iFileServer, 
       
   386                     fileName,
       
   387                     CImageDecoder::EPreferFastDecode));*/
       
   388 #ifdef DECODE_FROM_BUFFER    
       
   389             if(iSourceData) 
       
   390                 {
       
   391                 delete iSourceData;
       
   392                 iSourceData = NULL;
       
   393                 }
       
   394             
       
   395             RFile jpgFile;
       
   396             TInt fileSize;
       
   397             
       
   398             User::LeaveIfError(jpgFile.Open(iFileServer, fileName, EFileRead));
       
   399             jpgFile.Size(fileSize);
       
   400             iSourceData = HBufC8::NewL(fileSize);
       
   401             
       
   402             TPtr8 buffer = iSourceData->Des();
       
   403             
       
   404             jpgFile.Read(buffer, fileSize);
       
   405             
       
   406             jpgFile.Close();
       
   407             
       
   408             iImageDecoder = CImageDecoder::DataNewL(
       
   409                     iFileServer, 
       
   410                     *iSourceData, 
       
   411                     //CImageDecoder::EOptionNone,
       
   412                     CImageDecoder::TOptions(CImageDecoder::EPreferFastDecode|CImageDecoder::EOptionAlwaysThread),
       
   413                     KNullUid, 
       
   414                     KNullUid, 
       
   415                     decoderUid);
       
   416 #else
       
   417             TRAP(error, iImageDecoder = CImageDecoder::FileNewL(
       
   418                     iFileServer, 
       
   419                     fileName,
       
   420                     //CImageDecoder::EPreferFastDecode,
       
   421                     CImageDecoder::TOptions(CImageDecoder::EPreferFastDecode|CImageDecoder::EOptionAlwaysThread),
       
   422                     KNullUid,
       
   423                     KNullUid,
       
   424                     decoderUid));
       
   425 #endif
       
   426             }
       
   427 
       
   428         if(error != KErrNone)
       
   429             {
       
   430             DP2_IMAGIC(_L("CIEBitmapLoader::GetOneBitmapL - Image Decoder - TN res: %d, error: %d"), aThumbRes, error);
       
   431             delete iImageDecoder;
       
   432             iImageDecoder = NULL; 
       
   433 
       
   434 #ifdef USE_EXIF_TN
       
   435             if (iExifTn)
       
   436                 {
       
   437                 delete iExifTn;
       
   438                 iExifTn = NULL;
       
   439                 }
       
   440 #endif
       
   441 //            iBitmapLoaderObserver.BitmapsLoadedL(error);
       
   442             User::Leave(error);
       
   443             return;
       
   444             }
       
   445         
       
   446         TFrameInfo frameInfo = iImageDecoder->FrameInfo();
       
   447         if(aThumbRes == ESize128x128)
       
   448             iImageDecoder->SetDecoderThreadPriority(/*EPriorityNormal*/EPriorityMuchMore);
       
   449         else
       
   450             iImageDecoder->SetDecoderThreadPriority(EPriorityLess);
       
   451         
       
   452         
       
   453 #ifdef _IMAGIC_DEBUG
       
   454         TInt mem = 0;
       
   455         TInt ret = HAL::Get(HALData::EMemoryRAMFree, mem);
       
   456 #endif
       
   457         DP0_IMAGIC(_L("CIEBitmapLoader::GetOneBitmapL - #1"));        
       
   458         TSize frameSize = frameInfo.iFrameCoordsInPixels.Size();
       
   459         //If we are loading full resolution image, we have to create smaller target bitmap 
       
   460         //to save memory and to improve speed of further image processing
       
   461         if(aThumbRes == EFullSize)
       
   462             {
       
   463             TInt mem = 0;
       
   464             TInt ret = HAL::Get(HALData::EMemoryRAMFree, mem);
       
   465             if(mem < KMemoryThresholdForSuperZoom*1024)
       
   466                 {
       
   467                 //User::Leave(KErrNoMemory);
       
   468 #ifdef USE_OOM            	
       
   469                 ROomMonitorSession oomMonitor;
       
   470                 oomMonitor.Connect();
       
   471                 TInt errorCode = oomMonitor.RequestFreeMemory( 1024*KMemoryThresholdForSuperZoom );
       
   472                 
       
   473                 if ( errorCode != KErrNone )
       
   474                     {
       
   475                     // try one more time 
       
   476                     errorCode = oomMonitor.RequestFreeMemory( 1024*KMemoryThresholdForSuperZoom );
       
   477                     }
       
   478                 oomMonitor.Close();
       
   479 #endif                
       
   480                 }
       
   481                 
       
   482             
       
   483             //TSize tgtSize(1024, 1024);
       
   484             //DP0_IMAGIC(_L("CIEBitmapLoader::GetOneBitmapL - #3"));
       
   485             //TargetDecodingSize(tgtSize, frameSizue);
       
   486             if(frameSize.iHeight >= 1024 || frameSize.iWidth >= 1024)
       
   487                 {
       
   488                 frameSize.iHeight = Min(1024, iBitmapLoaderObserver.GetGleMaxRes());
       
   489                 frameSize.iWidth = Min(1024, iBitmapLoaderObserver.GetGleMaxRes());
       
   490                 }
       
   491             else
       
   492                 {
       
   493                 frameSize.iHeight=512;
       
   494                 frameSize.iWidth=512;
       
   495                 }
       
   496             }   
       
   497         
       
   498         // Crop thumbnail if aspect ratio is not same as full size image
       
   499 #ifdef USE_EXIF_TN
       
   500 #ifdef USE_EXIF_TN_CROP
       
   501         if (iUseExifTn)
       
   502             {
       
   503 #ifdef USE_EXIF_TN_EXT_CROP              
       
   504             TInt cap;
       
   505             TRAP(error, cap = extImageDecoder->CapabilitiesL());
       
   506             if (error == KErrNone && cap & CExtJpegDecoder::ECapCropping)
       
   507 #endif                
       
   508                 {
       
   509                 TReal aspectRatio = aImageData->GetAspectRatio();
       
   510                 TReal thumbAspectRatio = TReal(frameSize.iWidth) / frameSize.iHeight; 
       
   511             
       
   512                 // calculate final frame size
       
   513                 //if (frameSize.iWidth / frameSize.iHeight != size.iWidth / size.iHeight)
       
   514                 if (thumbAspectRatio != aspectRatio)
       
   515                     {
       
   516                     TRect finalFrameRect;
       
   517                     finalFrameRect.SetSize(frameSize);
       
   518                     if (thumbAspectRatio < aspectRatio)
       
   519                         {
       
   520                         TInt h = frameSize.iWidth / aspectRatio;
       
   521                         h += h & 1;
       
   522                         finalFrameRect.SetHeight(h);
       
   523                         }
       
   524                     else
       
   525                         {
       
   526                         TInt w = frameSize.iHeight * aspectRatio;
       
   527                         w += w & 1;
       
   528                         finalFrameRect.SetWidth(w);
       
   529                         }
       
   530                     
       
   531                     finalFrameRect.Move(
       
   532                             (frameSize.iWidth - finalFrameRect.Width() + 1) / 2,
       
   533                             (frameSize.iHeight - finalFrameRect.Height() + 1) / 2);
       
   534 #ifdef USE_EXIF_TN_EXT_CROP                    
       
   535                     TRAP(error, extImageDecoder->SetCroppingL(finalFrameRect));
       
   536 #else         
       
   537                     // Create temporal bitmap
       
   538                     iExifBitmap = new CFbsBitmap;
       
   539                     if (iExifBitmap == NULL)
       
   540                         error = KErrGeneral;
       
   541                     else
       
   542                         error = iExifBitmap->Create(frameSize, frameInfo.iFrameDisplayMode);
       
   543                     aBitmap = iExifBitmap;                 
       
   544 #endif
       
   545                     // Reduce final image size
       
   546                     if (error == KErrNone)
       
   547                         {
       
   548                         frameSize.iWidth = finalFrameRect.Width();
       
   549                         frameSize.iHeight = finalFrameRect.Height();
       
   550                         }                    
       
   551                     }
       
   552                 }
       
   553             }
       
   554 #endif        
       
   555 #endif        
       
   556         
       
   557         if (error == KErrNone)
       
   558             {
       
   559 #ifdef USE_RGBA
       
   560             error = iOutputBitmap->Create(frameSize, EColor16MU);
       
   561 #else
       
   562             error = iOutputBitmap->Create(frameSize, frameInfo.iFrameDisplayMode);
       
   563 #endif
       
   564             }
       
   565         
       
   566         if (error == KErrNone)
       
   567             {
       
   568 #ifdef USE_EXIF_TN
       
   569             /*if(iUseExifTn)
       
   570                 {
       
   571                 TRAP(error, iExifDecoder->Convert(&iStatus, *aBitmap));
       
   572                 }
       
   573             else*/
       
   574 #endif
       
   575                 {
       
   576                 TRAP(error, iImageDecoder->Convert(&iStatus, *aBitmap));
       
   577                 }
       
   578             }
       
   579         
       
   580         if(error != KErrNone)
       
   581             {
       
   582             DP2_IMAGIC(_L("CIEBitmapLoader::GetOneBitmapL - Image Decoder convert - TN res: %d, error: %d"), aThumbRes, error);
       
   583             delete iImageDecoder;
       
   584             iImageDecoder = NULL; 
       
   585             //aImageData->iGridData.iCorrupted = ETrue;//mika. added 03.06. maybe not good idea????????
       
   586             User::Leave(error);
       
   587             return;
       
   588             }
       
   589         else
       
   590             {
       
   591             DP1_IMAGIC(_L("CIEBitmapLoader::GetOneBitmapL - Decoding started TN res: %d"), aThumbRes);
       
   592             
       
   593             if(!IsActive())
       
   594                 SetActive();
       
   595             }
       
   596         }
       
   597     
       
   598     DP0_IMAGIC(_L("CIEBitmapLoader::GetOneBitmapL--"));
       
   599     }
       
   600 
       
   601 /**
       
   602 Opens file and creates file pointer
       
   603 @param aFileName The specified file to open
       
   604 @return imageInMemoryPtr A Pointer to iImageInMemory
       
   605 @leave System-wide error codes
       
   606 */  
       
   607 /*TPtr8 CIEBitmapLoader::LoadImageIntoMemoryLC(const TDesC& aFileName)
       
   608     {
       
   609     RFile file;
       
   610     TInt fileSize = 0;
       
   611 
       
   612     // Open the file for decoding
       
   613     User::LeaveIfError(file.Open(iFileServer, aFileName, EFileRead));
       
   614     file.Size(fileSize);    
       
   615 
       
   616     //HBufC8* imageInMemory = HBufC8::NewMaxLC(fileSize);
       
   617     HBufC8* imageInMemory = HBufC8::NewMaxL(fileSize);
       
   618     TPtr8 imageInMemoryPtr = imageInMemory->Des();
       
   619     if(file.SubSessionHandle())
       
   620         {
       
   621         User::LeaveIfError(file.Read(imageInMemoryPtr));    
       
   622         }
       
   623         
       
   624     file.Close();
       
   625 
       
   626     return imageInMemoryPtr;
       
   627     }*/
       
   628 
       
   629 void CIEBitmapLoader::TargetDecodingSize(TSize aTgtSize, TSize& aSrcSize)
       
   630     {
       
   631     DP0_IMAGIC(_L("CIEBitmapLoader::TargetDecodingSize++"));
       
   632     
       
   633     DP2_IMAGIC(_L("CIEBitmapLoader::TargetDecodingSize - Tgt size.iHeigth: %d, Tgt size.iWidth: %d"),aTgtSize.iHeight, aTgtSize.iWidth);
       
   634     DP2_IMAGIC(_L("CIEBitmapLoader::TargetDecodingSize - Src size.iHeigth: %d, Src size.iWidth: %d"),aSrcSize.iHeight, aSrcSize.iWidth);
       
   635     
       
   636     // up to 32 times downscale in scaler
       
   637     for (TInt i = 0;i < 5;i++)
       
   638         {
       
   639         if (aSrcSize.iWidth < aTgtSize.iWidth * 2 ||
       
   640             aSrcSize.iHeight < aTgtSize.iHeight * 2) 
       
   641             {
       
   642             break;
       
   643             }
       
   644             
       
   645             aSrcSize.iWidth >>= 1;
       
   646             aSrcSize.iHeight >>= 1;
       
   647         }
       
   648     
       
   649     // Check that we do not create odd resolution size thumbnail
       
   650     if(aSrcSize.iHeight & 1)
       
   651         aSrcSize.iHeight++;
       
   652     if(aSrcSize.iWidth & 1)
       
   653         aSrcSize.iWidth++;
       
   654     
       
   655     DP2_IMAGIC(_L("CIEBitmapLoader::TargetDecodingSize - Src size.iHeigth: %d, Src size.iWidth: %d"),aSrcSize.iHeight, aSrcSize.iWidth);
       
   656      
       
   657     DP0_IMAGIC((_L("CIEBitmapLoader::TargetDecodingSize--")));
       
   658     }
       
   659 
       
   660 
       
   661 void CIEBitmapLoader::CancelFullSizeLoading()
       
   662     {
       
   663     //Cancel only if full resolution loading was on
       
   664     DP0_IMAGIC(_L("CIEBitmapLoader::CancelFullSizeLoading++"));
       
   665     if(iThumbRes == EFullSize)
       
   666         {
       
   667         DP0_IMAGIC(_L("CIEBitmapLoader::CancelFullSizeLoading 1"));        
       
   668         if(iImageDecoder)
       
   669             {
       
   670             iImageDecoder->Cancel();
       
   671             delete iImageDecoder;
       
   672             iImageDecoder = NULL;   
       
   673             }
       
   674         DP0_IMAGIC(_L("CIEBitmapLoader::CancelFullSizeLoading 2"));
       
   675         if(IsActive())
       
   676             {
       
   677             Cancel();
       
   678             DP0_IMAGIC(_L("CIEBitmapLoader::CancelFullSizeLoading 21"));
       
   679             iBitmapLoaderObserver.BitmapsLoadedL(KErrCancel);
       
   680             }
       
   681 #ifdef DECODE_FROM_BUFFER    
       
   682         if(iSourceData) 
       
   683             {
       
   684             DP0_IMAGIC(_L("CIEBitmapLoader::CancelFullSizeLoading 3"));
       
   685             delete iSourceData;
       
   686             iSourceData = NULL;
       
   687             }
       
   688 #endif
       
   689         DP0_IMAGIC(_L("CIEBitmapLoader::CancelFullSizeLoading 4"));
       
   690         }
       
   691         DP0_IMAGIC(_L("CIEBitmapLoader::CancelFullSizeLoading--"));
       
   692     }
       
   693 
       
   694 void CIEBitmapLoader::SetImageDataMode(TImageArrayMode aMode)
       
   695     {
       
   696     iImageArrayMode = aMode;
       
   697     }
       
   698 
       
   699 
       
   700 // EOF