photosgallery/viewframework/texturemanager/src/glxbitmapdecoderwrapper.cpp
branchRCL_3
changeset 47 f9e827349359
parent 32 78ad99c24f08
equal deleted inserted replaced
35:420f6808bf21 47:f9e827349359
    27 #include <glxlog.h>
    27 #include <glxlog.h>
    28 #include <hal.h>
    28 #include <hal.h>
    29 #include <hal_data.h>
    29 #include <hal_data.h>
    30 #include <mglxcache.h>
    30 #include <mglxcache.h>
    31 #include <oommonitorsession.h>
    31 #include <oommonitorsession.h>
       
    32 #include <e32math.h>
       
    33 #include <apgcli.h>
       
    34 
    32 namespace
    35 namespace
    33 {
    36     {
    34 const TInt KGlxDecodingThreshold = 3000000;
    37     const TInt KGlxDecodingThreshold = 3000000;
    35 const TInt KGlxDecodingThresholdDimension = 2000;
    38     const TInt KGlxDecodingThresholdDimension = 2000;
    36 
    39 
    37 
    40     // Photos low_ram_threshold [8.637 MB] as in oomconfig.xml
    38 // Photos low_ram_threshold [8.637 MB] as in oomconfig.xml
    41     const TInt KGlxCriticalRAMForPhotos = 9056550;
    39 const TInt KGlxCriticalRAMForPhotos = 9056550;
    42     const TInt KGlxDecodeBitmapFactor = 3;
    40 const TInt KGlxDecodeBitmapFactor = 3;
    43     
    41 // All EXIF data is within the first KGlxMaxExifSize bytes of the file
    44     _LIT(KMimeJpeg,"image/jpeg");
    42 const TInt KGlxMaxExifSize = 0x10000;
    45     _LIT(KMimeJpg,"image/jpg");
    43 }
    46     }
    44 
    47 
    45 // ---------------------------------------------------------------------------
    48 // ---------------------------------------------------------------------------
    46 // Two-phased constructor.
    49 // Two-phased constructor.
    47 // ---------------------------------------------------------------------------
    50 // ---------------------------------------------------------------------------
    48 //
    51 //
    49 CGlxBitmapDecoderWrapper* CGlxBitmapDecoderWrapper::NewL(MGlxBitmapDecoderObserver* aObserver)
    52 CGlxBitmapDecoderWrapper* CGlxBitmapDecoderWrapper::NewL(
    50     {
    53         MGlxBitmapDecoderObserver* aObserver)
    51     TRACER("CGlxBitmapDecoderWrapper:: NewL ");
    54     {
    52     CGlxBitmapDecoderWrapper* self = new(ELeave)CGlxBitmapDecoderWrapper();
    55     TRACER("CGlxBitmapDecoderWrapper::NewL()");
       
    56     CGlxBitmapDecoderWrapper* self = new (ELeave) CGlxBitmapDecoderWrapper();
    53     CleanupStack::PushL(self);
    57     CleanupStack::PushL(self);
    54     self->ConstructL(aObserver);
    58     self->ConstructL(aObserver);
    55     CleanupStack::Pop(self);
    59     CleanupStack::Pop(self);
    56     return self;
    60     return self;
    57     }
    61     }
    58 
    62 
    59 // ---------------------------------------------------------------------------
    63 // ---------------------------------------------------------------------------
    60 // Constructor
    64 // Constructor
    61 // ---------------------------------------------------------------------------
    65 // ---------------------------------------------------------------------------
    62 //
    66 //
    63 CGlxBitmapDecoderWrapper::CGlxBitmapDecoderWrapper()
    67 CGlxBitmapDecoderWrapper::CGlxBitmapDecoderWrapper() :
    64                          :CActive( EPriorityLow )
    68     CActive(EPriorityLow)
    65 		        {
    69     {
    66 		        TRACER("CGlxBitmapDecoderWrapper:: NewL ");
    70     TRACER("CGlxBitmapDecoderWrapper::CGlxBitmapDecoderWrapper()");
    67 		        }		
    71     }		
    68 
    72 
    69 // ---------------------------------------------------------------------------
    73 // ---------------------------------------------------------------------------
    70 // Destructor
    74 // Destructor
    71 // ---------------------------------------------------------------------------
    75 // ---------------------------------------------------------------------------
    72 //
    76 //
    73 
       
    74 CGlxBitmapDecoderWrapper::~CGlxBitmapDecoderWrapper()
    77 CGlxBitmapDecoderWrapper::~CGlxBitmapDecoderWrapper()
    75     {
    78     {
    76     TRACER("CGlxBitmapDecoderWrapper:: ~CGlxBitmapDecoderWrapper ");
    79     TRACER("CGlxBitmapDecoderWrapper::~CGlxBitmapDecoderWrapper()");
    77     iFs.Close();
    80     iFs.Close();
    78     Cancel();
    81     Cancel();
    79     if (iImageDecoder)
    82     if (iImageDecoder)
    80         {
    83         {
    81         delete iImageDecoder;
    84         delete iImageDecoder;
    82         iImageDecoder = NULL;
    85         iImageDecoder = NULL;
       
    86         }
       
    87     if (iImagePath)
       
    88         {
       
    89         delete iImagePath;
       
    90         iImagePath = NULL;
    83         }
    91         }
    84     }
    92     }
    85 
    93 
    86 // ---------------------------------------------------------------------------
    94 // ---------------------------------------------------------------------------
    87 // ConstructL
    95 // ConstructL
    95     }
   103     }
    96 
   104 
    97 // ---------------------------------------------------------------------------
   105 // ---------------------------------------------------------------------------
    98 // DoDecodeImageL
   106 // DoDecodeImageL
    99 // ---------------------------------------------------------------------------		
   107 // ---------------------------------------------------------------------------		
   100 
   108 void CGlxBitmapDecoderWrapper::DoDecodeImageL(const TDesC& aSourceFileName,
   101 void CGlxBitmapDecoderWrapper::DoDecodeImageL(const TDesC & aSourceFileName,TInt aIndex)
   109         TInt aIndex)
   102     {
   110     {
   103     TRACER("CGlxBitmapDecoderWrapper:: DoDecodeImageL ");
   111     TRACER("CGlxBitmapDecoderWrapper::DoDecodeImageL()");
       
   112     GLX_LOG_URI("CGlxBitmapDecoderWrapper::DoDecodeImageL(%S)",
       
   113             &aSourceFileName);
       
   114 
   104     iThumbnailIndex = aIndex;
   115     iThumbnailIndex = aIndex;
   105     //Variable used to get the decoder type used
   116 
   106     TBool isExtDecoderUsed = ETrue;
       
   107     
       
   108 #ifdef _DEBUG
   117 #ifdef _DEBUG
   109     iDecodeProcessstartTime.HomeTime();
   118     iStartTime.HomeTime();
   110 #endif                          
   119 #endif                          
   111 
   120 
   112     if (iImageDecoder)
   121     if (iImageDecoder)
   113         {
   122         {
   114         delete iImageDecoder;
   123         delete iImageDecoder;
   115         iImageDecoder = NULL;
   124         iImageDecoder = NULL;
   116         }
   125         }
   117     
   126 
   118     CImageDecoder::TOptions options = (CImageDecoder::TOptions)
   127     CImageDecoder::TOptions options =
   119             ( CImageDecoder::EOptionNoDither | CImageDecoder::EOptionAlwaysThread );
   128             (CImageDecoder::TOptions) (CImageDecoder::EOptionNoDither
       
   129                     | CImageDecoder::EOptionAlwaysThread);
   120 
   130 
   121     // Use extended JPEG decoder
   131     // Use extended JPEG decoder
       
   132     GLX_DEBUG1("DoDecodeImageL:: EHwImplementation" );
   122     TRAPD( err, iImageDecoder = CExtJpegDecoder::FileNewL(
   133     TRAPD( err, iImageDecoder = CExtJpegDecoder::FileNewL(
   123             CExtJpegDecoder::EHwImplementation, iFs, aSourceFileName, options  ) );
   134                     CExtJpegDecoder::EHwImplementation, iFs,
   124     if ( KErrNone != err )
   135                     aSourceFileName, options ) );
   125         {
   136     GLX_DEBUG2("DoDecodeImageL:: EHwImplementation (%d)", err);
   126         GLX_LOG_INFO( "DoDecodeImageL:: ESwImplementation" );
   137     if (KErrNone != err)
       
   138         {
   127         TRAP(err,iImageDecoder = CExtJpegDecoder::FileNewL(
   139         TRAP(err,iImageDecoder = CExtJpegDecoder::FileNewL(
   128                 CExtJpegDecoder::ESwImplementation, iFs, aSourceFileName, options  ) );
   140                         CExtJpegDecoder::ESwImplementation, iFs,
   129         if ( KErrNone != err )
   141                         aSourceFileName, options ) );
       
   142         GLX_DEBUG2("DoDecodeImageL:: ESwImplementation (%d)", err);
       
   143         if (KErrNone != err)
   130             {
   144             {
   131             GLX_LOG_INFO( "DoDecodeImageL:: CImageDecoder" );
   145             GLX_DEBUG1("DoDecodeImageL::CImageDecoder");
   132             // Not a JPEG - use standard decoder
   146             // Not a JPEG - use standard decoder
   133             iImageDecoder = CImageDecoder::FileNewL( iFs, aSourceFileName, options  );
   147             iImageDecoder = CImageDecoder::FileNewL(iFs, aSourceFileName,
   134             isExtDecoderUsed = EFalse;
   148                     options);
   135             }
   149             }
   136         }
   150         }
   137 #ifdef _DEBUG
   151 #ifdef _DEBUG
   138         iStopTime.HomeTime();
   152     iStopTime.HomeTime();
   139         GLX_DEBUG1("=== DECODER CREATION ===");
   153     GLX_DEBUG2("*** Decoder Creation took <%d> us ***",
   140         GLX_DEBUG2("Decoder Creation took <%d> us", 
   154             (TInt)iStopTime.MicroSecondsFrom(iStartTime).Int64());
   141                    (TInt)iStopTime.MicroSecondsFrom(iDecodeProcessstartTime).Int64());   
       
   142 #endif                          
   155 #endif                          
   143 		
   156 
   144     TSize imageSize = iImageDecoder->FrameInfo().iOverallSizeInPixels;
   157     TSize imageSize = iImageDecoder->FrameInfo().iOverallSizeInPixels;
   145     if(isExtDecoderUsed)
   158     GLX_DEBUG3("GlxDecoderWrapper::DecodeImageL() - OverallSize: w=%d, h=%d",
   146         {
   159             imageSize.iWidth, imageSize.iHeight);
   147         TUint16 orientation=0;
       
   148         //Read the orientation from the Exif header of the image if present
       
   149         TRAPD(error, orientation=GetOrientationL(aSourceFileName));
       
   150         if(KErrNone == error )
       
   151             {
       
   152             //Get the rotation angle and the flip status from orientation
       
   153             TInt rotAngle = 0;
       
   154             TBool flipStatus = EFalse;
       
   155             GetRotationParameters(orientation, rotAngle, flipStatus);
       
   156             //Set the parameters to the decoder
       
   157             CExtJpegDecoder* extDecoder = (CExtJpegDecoder*)iImageDecoder;
       
   158             extDecoder->SetRotationL(rotAngle);
       
   159             if(flipStatus)
       
   160                 {
       
   161                 extDecoder->SetMirroringL();
       
   162                 }
       
   163             //Switch Image Height and width in case orientation > 4 as that 
       
   164             //corresponds to angles 180 and 270 degrees
       
   165             if (orientation > 4)
       
   166                 {
       
   167                 imageSize.SetSize(imageSize.iHeight,imageSize.iWidth);
       
   168                 }
       
   169             }
       
   170 
       
   171         }
       
   172     iOriginalSize.iWidth = imageSize.iWidth;
   160     iOriginalSize.iWidth = imageSize.iWidth;
   173     iOriginalSize.iHeight = imageSize.iHeight;
   161     iOriginalSize.iHeight = imageSize.iHeight;
   174 
   162 
   175     if (iBitmap)
   163     if (iBitmap)
   176         {
   164         {
   177         delete iBitmap;
   165         delete iBitmap;
   178         iBitmap = NULL;
   166         iBitmap = NULL;
   179         }
   167         }
       
   168     
       
   169     if (iImagePath)
       
   170         {
       
   171         delete iImagePath;
       
   172         iImagePath = NULL;
       
   173         }
       
   174     iImagePath = aSourceFileName.Alloc();
       
   175     
   180     DecodeImageL();
   176     DecodeImageL();
   181     }
   177     }
       
   178 
   182 // ---------------------------------------------------------------------------
   179 // ---------------------------------------------------------------------------
   183 // DecodeImageL
   180 // DecodeImageL
   184 // ---------------------------------------------------------------------------
   181 // ---------------------------------------------------------------------------
   185 //
   182 //
   186 void CGlxBitmapDecoderWrapper::DecodeImageL()
   183 void CGlxBitmapDecoderWrapper::DecodeImageL()
   187     {
   184     {
   188     TRACER("CGlxBitmapDecoderWrapper:: DecodeImageL ");
   185     TRACER("CGlxBitmapDecoderWrapper::DecodeImageL()");
   189     TReal32 mFactor = 1;
   186     TReal32 mFactor = 1;
   190     TReal32 mFactor1 = 1;
   187     TReal mFactor1 = 1;
   191     TReal32 mFactor2 = 1;
   188     TReal32 mFactor2 = 1;
   192     //Set Size according to level and state
   189     //Set Size according to level and state
   193     TReal32 width = iOriginalSize.iWidth;
   190     TReal32 width = iOriginalSize.iWidth;
   194     TReal32 height = iOriginalSize.iHeight;
   191     TReal32 height = iOriginalSize.iHeight;
   195     GLX_LOG_INFO1("DecodeImageL:width=%f", width);
   192 
   196     GLX_LOG_INFO1("DecodeImageL:height=%f",height);
   193     if (KGlxDecodingThreshold < (width * height))
   197     
   194         {
   198     if ( KGlxDecodingThreshold < (width * height))
   195         TReal tempFactor = TReal32(KGlxDecodingThreshold)
   199         {
   196                 / (width * height);
   200         mFactor1 = TReal32(KGlxDecodingThreshold) / (width*height);
   197         User::LeaveIfError(Math::Sqrt(mFactor1, tempFactor));
   201         GLX_LOG_INFO1("mFactor1 =%f",mFactor1);
   198         GLX_DEBUG2("DecodeImageL() - mFactor1 = %f", mFactor1);
   202         }
   199         }
   203     
   200 
   204     if ( KGlxDecodingThresholdDimension < width || KGlxDecodingThresholdDimension < height)
   201     if (KGlxDecodingThresholdDimension < width
   205         {
   202             || KGlxDecodingThresholdDimension < height)
   206         mFactor2 = TReal32(KGlxDecodingThresholdDimension) / Max(width, height);
   203         {
   207         GLX_LOG_INFO1("mFactor2 =%f",mFactor2);
   204         mFactor2 = TReal32(KGlxDecodingThresholdDimension) / Max(width,
   208         }
   205                 height);
   209 
   206         GLX_DEBUG2("DecodeImageL() - mFactor2 = %f", mFactor2);
   210     mFactor = Min(mFactor1 , mFactor2);
   207         }
   211     GLX_LOG_INFO1("Final mFactor =%f",mFactor);
   208 
       
   209     mFactor = Min(TReal32(mFactor1), mFactor2);
       
   210     GLX_DEBUG2("DecodeImageL() - Final mFactor = %f", mFactor);
   212 
   211 
   213     // create the destination bitmap
   212     // create the destination bitmap
   214     if(!iBitmap)
   213     if (!iBitmap)
   215         {
   214         {
   216         TInt freeMemory = 0;
   215         TInt freeMemory = 0;
   217         HAL::Get( HALData::EMemoryRAMFree, freeMemory );
   216         HAL::Get(HALData::EMemoryRAMFree, freeMemory);
   218         width*=mFactor;
   217         width *= mFactor;
   219         height*=mFactor;
   218         height *= mFactor;
   220         TInt minmemorytodecode = KGlxDecodeBitmapFactor*width*height;     
   219         TInt minmemorytodecode = KGlxDecodeBitmapFactor * width * height;
   221         GLX_LOG_INFO2("DecodeImageL: after factoring width=%f, height=%f", width, height);
   220         GLX_DEBUG3("DecodeImageL: minmemorytodecode=%d, freememory=%d",
   222         GLX_LOG_INFO2("DecodeImageL:minmemorytodecode=%d, freememory=%d",
       
   223                 minmemorytodecode, freeMemory);
   221                 minmemorytodecode, freeMemory);
   224         if(minmemorytodecode < (freeMemory - KGlxCriticalRAMForPhotos))
   222         
       
   223         iTargetBitmapSize.iWidth = width;
       
   224         iTargetBitmapSize.iHeight = height;
       
   225         GLX_DEBUG3("DecodeImageL: iTargetBitmapSize w=%d, h=%d",
       
   226                 iTargetBitmapSize.iWidth, iTargetBitmapSize.iHeight);
       
   227         __ASSERT_DEBUG(width > 0 && height > 0, Panic(EGlxPanicIllegalArgument));      
       
   228 
       
   229         if (minmemorytodecode < (freeMemory - KGlxCriticalRAMForPhotos))
   225             {
   230             {
   226             GLX_LOG_INFO("DecodeImageL:RAM available decoding image");
   231             GLX_DEBUG1("DecodeImageL:RAM available decoding image");            
   227 
       
   228             iBitmap = new (ELeave) CFbsBitmap();
   232             iBitmap = new (ELeave) CFbsBitmap();
   229             iBitmap->Create( TSize(width,height),iImageDecoder->FrameInfo().iFrameDisplayMode );
   233             iBitmap->Create(ReCalculateSizeL(),
       
   234                     iImageDecoder->FrameInfo().iFrameDisplayMode);
   230 #ifdef _DEBUG
   235 #ifdef _DEBUG
   231             iStartTime.HomeTime(); // Get home time
   236             iStartTime.HomeTime(); // Get home time
   232 #endif                          
   237 #endif                          
   233             iImageDecoder->Convert( &iStatus, *iBitmap );
   238             iImageDecoder->Convert(&iStatus, *iBitmap);
   234             }
   239             }
   235         else
   240         else
   236             {
   241             {
   237             //case when sufficient memory is not available
   242             //case when sufficient memory is not available
   238             //request OOM FW to release the required memory
   243             //request OOM FW to release the required memory
   239             GLX_LOG_INFO("DecodeImageL:insufficient RAM - request OOM");
   244             GLX_DEBUG1("DecodeImageL:insufficient RAM - request OOM");
   240             TInt err = OOMRequestFreeMemoryL(minmemorytodecode);
   245             TInt err = OOMRequestFreeMemoryL(minmemorytodecode);
   241             if(err == KErrNoMemory)
   246             if (err == KErrNoMemory)
   242                 {
   247                 {
   243                 //if OOM fails, release Photos Cache
   248                 //if OOM fails, release Photos Cache
   244                 GLX_LOG_INFO("DecodeImageL:insufficient RAM - OOM failed - request Cache");
   249                 GLX_DEBUG1("DecodeImageL:insufficient RAM - OOM failed"
       
   250                         " - request Cache");
   245                 MGlxCache* cacheManager = MGlxCache::InstanceL();
   251                 MGlxCache* cacheManager = MGlxCache::InstanceL();
   246                 cacheManager->ReleaseRAML(ETrue);            
   252                 cacheManager->ReleaseRAML(ETrue);
   247                 cacheManager->Close();
   253                 cacheManager->Close();
   248                 //Try and release memory again
   254                 //Try and release memory again
   249                 err = OOMRequestFreeMemoryL(minmemorytodecode);
   255                 err = OOMRequestFreeMemoryL(minmemorytodecode);
   250                 }
   256                 }
   251             if(err != KErrNoMemory)
   257             if (err != KErrNoMemory)
   252                 {
   258                 {
   253                 GLX_LOG_INFO("DecodeImageL:Sufficient RAM available");
   259                 GLX_DEBUG1("DecodeImageL:Sufficient RAM available");                
   254                 iBitmap = new (ELeave) CFbsBitmap();
   260                 iBitmap = new (ELeave) CFbsBitmap();
   255                 iBitmap->Create( TSize(width,height),iImageDecoder->FrameInfo().iFrameDisplayMode );
   261                 iBitmap->Create(ReCalculateSizeL(),
       
   262                         iImageDecoder->FrameInfo().iFrameDisplayMode);
   256 #ifdef _DEBUG
   263 #ifdef _DEBUG
   257 	            iStartTime.HomeTime(); // Get home time
   264                 iStartTime.HomeTime(); // Get home time
   258 #endif                          
   265 #endif                          
   259                 iImageDecoder->Convert( &iStatus, *iBitmap );
   266                 iImageDecoder->Convert(&iStatus, *iBitmap);
   260                 }
   267                 }
   261             else
   268             else
   262                 {
   269                 {
   263                 GLX_LOG_INFO("NOT ENOUGH MEMORY - Using the Fullscreen Thumbnail For Zoom");
   270                 GLX_DEBUG1("NOT ENOUGH MEMORY - "
       
   271                         "Using the Fullscreen Thumbnail For Zoom");
   264                 //release the file held by decoder immediately.
   272                 //release the file held by decoder immediately.
   265                 iImageDecoder->Cancel();
   273                 iImageDecoder->Cancel();
   266                 delete iImageDecoder;
   274                 delete iImageDecoder;
   267                 iImageDecoder = NULL;
   275                 iImageDecoder = NULL;
   268                 //Inform the client that there is no decode happened and there we take care 
   276                 //Inform the client that there is no decode happened and there we take care 
   269                 //of showing the fullscreen thumbnail.
   277                 //of showing the fullscreen thumbnail.
   270                 iObserver->HandleBitmapDecodedL(iThumbnailIndex,NULL);
   278                 iObserver->HandleBitmapDecodedL(iThumbnailIndex, NULL);
   271                 return;                
   279                 return;
   272                 }
   280                 }
   273             }
   281             }
   274 
   282 
   275         SetActive();
   283         SetActive();
   276         }
   284         }
   277     }
   285     }
       
   286 
   278 // ---------------------------------------------------------------------------
   287 // ---------------------------------------------------------------------------
   279 // RunL
   288 // RunL
   280 // ---------------------------------------------------------------------------
   289 // ---------------------------------------------------------------------------
   281 //
   290 //
   282 void CGlxBitmapDecoderWrapper::RunL()
   291 void CGlxBitmapDecoderWrapper::RunL()
   283     {
   292     {
   284     TRACER("CGlxBitmapDecoderWrapper:: RunL ");
   293     TRACER("CGlxBitmapDecoderWrapper::RunL()");
   285     if( iStatus == KErrNone )
   294     if( iStatus == KErrNone )
   286         {
   295         {
   287         iObserver->HandleBitmapDecodedL(iThumbnailIndex,iBitmap);
   296         iObserver->HandleBitmapDecodedL(iThumbnailIndex,iBitmap);
   288         iBitmap = NULL;
   297         iBitmap = NULL;
   289 
   298 
   290         //release the file held by decoder immediately.
   299         //release the file held by decoder immediately.
   291         GLX_LOG_INFO( " CGlxBitmapDecoderWrapper::RunL:Decoding Finished" );
   300         GLX_DEBUG1("CGlxBitmapDecoderWrapper::RunL:Decoding Finished");
   292         iImageDecoder->Cancel();
   301         iImageDecoder->Cancel();
   293         delete iImageDecoder;
   302         delete iImageDecoder;
   294         iImageDecoder = NULL;
   303         iImageDecoder = NULL;
   295 #ifdef _DEBUG
   304 #ifdef _DEBUG
   296         iStopTime.HomeTime();
   305         iStopTime.HomeTime();
   297         GLX_DEBUG1("=== IMAGE DECODE ===");
   306         GLX_DEBUG2("*** Image Decode took <%d> us ***", 
   298         GLX_DEBUG2("=>Image Decode Took took <%d> us", 
       
   299                        (TInt)iStopTime.MicroSecondsFrom(iStartTime).Int64());            
   307                        (TInt)iStopTime.MicroSecondsFrom(iStartTime).Int64());            
   300 #endif                          
   308 #endif                          
   301 
   309 
   302         }
   310         }
   303     }
   311     }
       
   312 
   304 // ---------------------------------------------------------------------------
   313 // ---------------------------------------------------------------------------
   305 // DoCancel
   314 // DoCancel
   306 // ---------------------------------------------------------------------------
   315 // ---------------------------------------------------------------------------
   307 //
   316 //
   308 void CGlxBitmapDecoderWrapper::DoCancel()
   317 void CGlxBitmapDecoderWrapper::DoCancel()
   309     {
   318     {
   310     TRACER("CGlxBitmapDecoderWrapper:: DoCancel ");
   319     TRACER("CGlxBitmapDecoderWrapper::DoCancel ");
   311     if(iImageDecoder)
   320     if(iImageDecoder)
   312         {
   321         {
   313         GLX_LOG_INFO( " CGlxBitmapDecoderWrapper::DoCancel:Deleting" );
   322         GLX_DEBUG1("CGlxBitmapDecoderWrapper::DoCancel iImageDecoder delete");
   314         iImageDecoder->Cancel();
   323         iImageDecoder->Cancel();
   315         delete iImageDecoder;
   324         delete iImageDecoder;
   316         iImageDecoder = NULL;
   325         iImageDecoder = NULL;
   317         }
   326         }
   318     if(iBitmap)
   327     if(iBitmap)
   321         iBitmap = NULL;
   330         iBitmap = NULL;
   322         }
   331         }
   323     }
   332     }
   324 
   333 
   325 // ---------------------------------------------------------------------------
   334 // ---------------------------------------------------------------------------
   326 // GetOrientationL
       
   327 // ---------------------------------------------------------------------------
       
   328 //
       
   329 TUint16 CGlxBitmapDecoderWrapper::GetOrientationL(const TDesC& aFileName)
       
   330     {
       
   331     TRACER("CGlxBitmapDecoderWrapper:: GetOrientationL ");
       
   332     //Get Exif Metadata and the orientation tag from the file first
       
   333             RFile file;
       
   334             CleanupClosePushL(file);
       
   335             User::LeaveIfError(file.Open(iFs,
       
   336                     aFileName, EFileRead));
       
   337             TInt size;
       
   338             User::LeaveIfError(file.Size(size));
       
   339             if ( KGlxMaxExifSize < size )
       
   340                 {
       
   341                 size = KGlxMaxExifSize;
       
   342                 }
       
   343             TUint16 orientation = 9;
       
   344             HBufC8* exifData = HBufC8::NewLC(size);
       
   345             TPtr8 ptr(exifData->Des());
       
   346             User::LeaveIfError(file.Read(ptr));
       
   347             CExifRead* exifReader = NULL;
       
   348             TRAPD(exifErr,exifReader = CExifRead::NewL(*exifData, CExifRead::ENoJpeg));
       
   349             if(exifErr == KErrNone)
       
   350                 {
       
   351                 CleanupStack::PushL(exifReader);
       
   352 
       
   353                 TInt readErr = exifReader->GetOrientation(orientation);
       
   354                 if(readErr != KErrNone)
       
   355                     {
       
   356                     orientation = 9;
       
   357                     }
       
   358                 CleanupStack::PopAndDestroy(exifReader);
       
   359                 }
       
   360             CleanupStack::PopAndDestroy(exifData);
       
   361             //Close and pop file Session
       
   362             CleanupStack::PopAndDestroy(&file);
       
   363             return orientation;
       
   364     
       
   365     }
       
   366 // ---------------------------------------------------------------------------
       
   367 // DoCancel
       
   368 // ---------------------------------------------------------------------------
       
   369 //
       
   370 void CGlxBitmapDecoderWrapper::GetRotationParameters(TUint16 aOrientation, TInt& aRotAngle, TBool& aFlipStatus) 
       
   371     {
       
   372     TRACER("CGlxBitmapDecoderWrapper:: DoCancel ");
       
   373     //Get the orientation and set rotation on the decoder 
       
   374     //as well as update the original size
       
   375     aRotAngle =  0;
       
   376     aFlipStatus = EFalse;
       
   377     TInt isOrientationOdd = aOrientation%2;
       
   378     if(aOrientation>8)
       
   379         {
       
   380         return;
       
   381         }
       
   382     if(aOrientation >= 3 && aOrientation < 5)
       
   383         {
       
   384         aRotAngle = 180;
       
   385         }
       
   386     else if(aOrientation >= 5 && aOrientation < 7)
       
   387         {
       
   388         aRotAngle = 90;
       
   389 
       
   390         }
       
   391     else if(aOrientation >= 7 && aOrientation <= 8)
       
   392         {
       
   393         aRotAngle = 270;
       
   394         }
       
   395     if(aOrientation>4 )
       
   396         {
       
   397         if(isOrientationOdd )
       
   398             {
       
   399             aFlipStatus = ETrue;
       
   400             }
       
   401         }   
       
   402 
       
   403     }
       
   404 
       
   405 // ---------------------------------------------------------------------------
       
   406 // OOMRequestFreeMemoryL
   335 // OOMRequestFreeMemoryL
   407 // ---------------------------------------------------------------------------
   336 // ---------------------------------------------------------------------------
   408 //
   337 //
   409 TInt CGlxBitmapDecoderWrapper::OOMRequestFreeMemoryL( TInt aBytesRequested)
   338 TInt CGlxBitmapDecoderWrapper::OOMRequestFreeMemoryL(TInt aBytesRequested)
   410     {
   339     {
   411     TRACER("CGlxBitmapDecoderWrapper::OOMRequestFreeMemoryL");
   340     TRACER("CGlxBitmapDecoderWrapper::OOMRequestFreeMemoryL");
   412     GLX_LOG_INFO1("CGlxBitmapDecoderWrapper::OOMRequestFreeMemoryL() aBytesRequested=%d",
   341     GLX_LOG_INFO1("CGlxBitmapDecoderWrapper::OOMRequestFreeMemoryL() "
   413             aBytesRequested);
   342             "aBytesRequested=%d", aBytesRequested);
   414     ROomMonitorSession oomMonitor;
   343     ROomMonitorSession oomMonitor;
   415     User::LeaveIfError( oomMonitor.Connect() );
   344     User::LeaveIfError(oomMonitor.Connect());
   416     // No leaving code after this point, so no need to use cleanup stack
   345     // No leaving code after this point, so no need to use cleanup stack
   417     // for oomMonitor
   346     // for oomMonitor
   418     TInt errorCode = oomMonitor.RequestFreeMemory( aBytesRequested );
   347     TInt errorCode = oomMonitor.RequestFreeMemory(aBytesRequested);
   419     GLX_LOG_INFO1("CGlxBitmapDecoderWrapper::OOMRequestFreeMemoryL(1) errorCode=%d",errorCode);
   348     GLX_LOG_INFO1("CGlxBitmapDecoderWrapper::OOMRequestFreeMemoryL(1) "
   420     if ( errorCode != KErrNone )
   349             "errorCode=%d",errorCode);
       
   350     if (errorCode != KErrNone)
   421         {
   351         {
   422         // try one more time 
   352         // try one more time 
   423         errorCode = oomMonitor.RequestFreeMemory( aBytesRequested );
   353         errorCode = oomMonitor.RequestFreeMemory(aBytesRequested);
   424         GLX_LOG_INFO1("CGlxBitmapDecoderWrapper::OOMRequestFreeMemoryL(2) errorCode=%d",errorCode);
   354         GLX_LOG_INFO1("CGlxBitmapDecoderWrapper::OOMRequestFreeMemoryL(2) "
       
   355                 "errorCode=%d",errorCode);
   425         }
   356         }
   426     oomMonitor.Close();
   357     oomMonitor.Close();
   427     return errorCode;
   358     return errorCode;
   428     }
   359     }
       
   360 
       
   361 // -----------------------------------------------------------------------------
       
   362 // DoesMimeTypeNeedsRecalculateL()
       
   363 // -----------------------------------------------------------------------------
       
   364 //
       
   365 TBool CGlxBitmapDecoderWrapper::DoesMimeTypeNeedsRecalculateL()
       
   366     {
       
   367     TRACER("CGlxBitmapDecoderWrapper::DoesMimeTypeNeedsRecalculateL");
       
   368     RApaLsSession session;
       
   369     TDataType mimeType;
       
   370     TUid uid;
       
   371 
       
   372     User::LeaveIfError(session.Connect());
       
   373     CleanupClosePushL(session);
       
   374     User::LeaveIfError(session.AppForDocument(iImagePath->Des(), uid,
       
   375             mimeType));
       
   376     CleanupStack::PopAndDestroy(&session);
       
   377 
       
   378     if (mimeType.Des().Compare(KMimeJpeg) == 0 || mimeType.Des().Compare(
       
   379             KMimeJpg) == 0)
       
   380         {
       
   381         GLX_LOG_INFO("CGlxBitmapDecoderWrapper::DoesMimeTypeNeedsRecalculateL - jpeg");
       
   382         return EFalse;
       
   383         }
       
   384     else
       
   385         {
       
   386         GLX_LOG_INFO("CGlxHdmiSurfaceUpdater::DoesMimeTypeNeedsRecalculateL - non jpeg");
       
   387         return ETrue;
       
   388         }
       
   389     }
       
   390 
       
   391 // -----------------------------------------------------------------------------
       
   392 // ReCalculateSize 
       
   393 // -----------------------------------------------------------------------------
       
   394 TSize CGlxBitmapDecoderWrapper::ReCalculateSizeL()
       
   395     {
       
   396     TRACER("CGlxBitmapDecoderWrapper::ReCalculateSizeL()");
       
   397     if (DoesMimeTypeNeedsRecalculateL())
       
   398         {
       
   399         TSize fullFrameSize = iImageDecoder->FrameInfo().iOverallSizeInPixels;
       
   400         // calculate the reduction factor on what size we need
       
   401         TInt reductionFactor = iImageDecoder->ReductionFactor(fullFrameSize,
       
   402                 iTargetBitmapSize);
       
   403         // get the reduced size onto destination size
       
   404         TSize destSize;
       
   405         User::LeaveIfError(iImageDecoder->ReducedSize(fullFrameSize,
       
   406                 reductionFactor, destSize));
       
   407         GLX_LOG_INFO2("CGlxBitmapDecoderWrapper::ReCalculateSizeL() "
       
   408                         "destSize=%d, %d",destSize.iWidth,destSize.iHeight);
       
   409         return destSize;
       
   410         }
       
   411     else
       
   412         {
       
   413         return iTargetBitmapSize;
       
   414         }
       
   415     }