imagehandlingutilities/thumbnailmanager/thumbnailserver/src/thumbnailscaletask.cpp
branchRCL_3
changeset 40 6257223ede8a
parent 38 2b4b06654caa
child 41 9d4d3445ce6e
equal deleted inserted replaced
38:2b4b06654caa 40:6257223ede8a
    26 #include "thumbnailprovider.h"
    26 #include "thumbnailprovider.h"
    27 #include "thumbnailserver.h"
    27 #include "thumbnailserver.h"
    28 #include "thumbnailmanagerconstants.h"
    28 #include "thumbnailmanagerconstants.h"
    29 #include "thumbnaillog.h"
    29 #include "thumbnaillog.h"
    30 #include "thumbnailpanic.h"
    30 #include "thumbnailpanic.h"
       
    31 #include "OstTraceDefinitions.h"
       
    32 #ifdef OST_TRACE_COMPILER_IN_USE
       
    33 #include "thumbnailscaletaskTraces.h"
       
    34 #endif
       
    35 
    31 
    36 
    32 
    37 
    33 // ======== MEMBER FUNCTIONS ========
    38 // ======== MEMBER FUNCTIONS ========
    34 
    39 
    35 // ---------------------------------------------------------------------------
    40 // ---------------------------------------------------------------------------
    76     iDisplayMode( aDisplayMode ), iFilename( aFilename ), iTargetUri( aTargetUri ),
    81     iDisplayMode( aDisplayMode ), iFilename( aFilename ), iTargetUri( aTargetUri ),
    77     iThumbnailSize(aThumbnailSize), iModified(aModified),
    82     iThumbnailSize(aThumbnailSize), iModified(aModified),
    78     iBitmapToPool(aBitmapToPool), iEXIF(aEXIF), iVirtualUri( aVirtualUri )
    83     iBitmapToPool(aBitmapToPool), iEXIF(aEXIF), iVirtualUri( aVirtualUri )
    79     {
    84     {
    80     TN_DEBUG2( "CThumbnailScaleTask(0x%08x)::CThumbnailScaleTask()", this );
    85     TN_DEBUG2( "CThumbnailScaleTask(0x%08x)::CThumbnailScaleTask()", this );
       
    86     OstTrace1( TRACE_NORMAL, CTHUMBNAILSCALETASK_CTHUMBNAILSCALETASK, "CThumbnailScaleTask::CThumbnailScaleTask;this=%o", this );
    81     
    87     
    82     iRequestId = aRequestId;
    88     iRequestId = aRequestId;
    83     }
    89     }
    84 
    90 
    85 
    91 
   112     iServer.CancelScale();
   118     iServer.CancelScale();
   113     
   119     
   114     if ( iBitmapInPool && iBitmap )
   120     if ( iBitmapInPool && iBitmap )
   115         {
   121         {
   116         TN_DEBUG1("CThumbnailScaleTask()::~CThumbnailScaleTask() delete original bitmap from pool");
   122         TN_DEBUG1("CThumbnailScaleTask()::~CThumbnailScaleTask() delete original bitmap from pool");
       
   123         OstTrace0( TRACE_NORMAL, DUP1_CTHUMBNAILSCALETASK_CTHUMBNAILSCALETASK, "CThumbnailScaleTask::~CThumbnailScaleTask - delete original bitmap from pool" );
   117         
   124         
   118         // Original bitmap is owned by server, decrease reference count
   125         // Original bitmap is owned by server, decrease reference count
   119         iServer.DeleteBitmapFromPool( iBitmap->Handle());
   126         iServer.DeleteBitmapFromPool( iBitmap->Handle());
   120         }
   127         }
   121 
   128 
   130 // ---------------------------------------------------------------------------
   137 // ---------------------------------------------------------------------------
   131 //
   138 //
   132 void CThumbnailScaleTask::StartL()
   139 void CThumbnailScaleTask::StartL()
   133     {
   140     {
   134     TN_DEBUG2( "CThumbnailScaleTask(0x%08x)::StartL()", this );
   141     TN_DEBUG2( "CThumbnailScaleTask(0x%08x)::StartL()", this );
       
   142     OstTrace1( TRACE_NORMAL, CTHUMBNAILSCALETASK_STARTL, "CThumbnailScaleTask::StartL;this=%o", this );
   135 
   143 
   136     CThumbnailTask::StartL();
   144     CThumbnailTask::StartL();
   137 
   145 
   138     if ( !iCrop )
   146     if ( !iCrop )
   139         {
   147         {
   140         TN_DEBUG2( "CThumbnailScaleTask(0x%08x)::StartL() - cropping OFF", this );
   148         TN_DEBUG2( "CThumbnailScaleTask(0x%08x)::StartL() - cropping OFF", this );
       
   149         OstTrace1( TRACE_NORMAL, DUP1_CTHUMBNAILSCALETASK_STARTL, "CThumbnailScaleTask::StartL - cropping OFF;this=%o", this );
   141     
   150     
   142         // target size at max, keep aspect ratio
   151         // target size at max, keep aspect ratio
   143         CalculateTargetSize();
   152         CalculateTargetSize();
   144         }
   153         }
   145     else
   154     else
   146         {
   155         {
   147         TN_DEBUG2( "CThumbnailScaleTask(0x%08x)::StartL() - cropping ON", this );
   156         TN_DEBUG2( "CThumbnailScaleTask(0x%08x)::StartL() - cropping ON", this );
       
   157         OstTrace1( TRACE_NORMAL, DUP2_CTHUMBNAILSCALETASK_STARTL, "CThumbnailScaleTask::StartL - cropping ON;this=%o", this );
   148     
   158     
   149         // exact target size, crop excess
   159         // exact target size, crop excess
   150         CalculateCropRectangle();
   160         CalculateCropRectangle();
   151         }
   161         }
   152     
   162     
   153     TN_DEBUG2( "CThumbnailScaleTask(0x%08x)::StartL() - sizes calculated", this );
   163     TN_DEBUG2( "CThumbnailScaleTask(0x%08x)::StartL() - sizes calculated", this );
       
   164     OstTrace1( TRACE_NORMAL, DUP3_CTHUMBNAILSCALETASK_STARTL, "CThumbnailScaleTask::StartL - sizes calculated;this=%o", this );
   154     
   165     
   155 #ifdef _DEBUG
   166 #ifdef _DEBUG
   156     aStart.UniversalTime();
   167     aStart.UniversalTime();
   157 #endif
   168 #endif
   158     
   169     
   163     TSize bitmapSize = iBitmap->SizeInPixels();
   174     TSize bitmapSize = iBitmap->SizeInPixels();
   164     
   175     
   165     if(bitmapSize.iHeight == iTargetSize.iHeight && bitmapSize.iWidth == iTargetSize.iWidth)
   176     if(bitmapSize.iHeight == iTargetSize.iHeight && bitmapSize.iWidth == iTargetSize.iWidth)
   166         {
   177         {
   167         TN_DEBUG2( "CThumbnailScaleTask(0x%08x)::StartL() - no need for scaling", this);
   178         TN_DEBUG2( "CThumbnailScaleTask(0x%08x)::StartL() - no need for scaling", this);
       
   179         OstTrace1( TRACE_NORMAL, DUP4_CTHUMBNAILSCALETASK_STARTL, "CThumbnailScaleTask::StartL - no need for scaling;this=%o", this );
   168     
   180     
   169         // copy bitmap 1:1
   181         // copy bitmap 1:1
   170         User::LeaveIfError( iScaledBitmap->Create( bitmapSize, iBitmap->DisplayMode() ));
   182         User::LeaveIfError( iScaledBitmap->Create( bitmapSize, iBitmap->DisplayMode() ));
   171         CFbsBitmapDevice* device = CFbsBitmapDevice::NewL(iScaledBitmap);
   183         CFbsBitmapDevice* device = CFbsBitmapDevice::NewL(iScaledBitmap);
   172         CleanupStack::PushL(device);
   184         CleanupStack::PushL(device);
   181         ResetMessageData();
   193         ResetMessageData();
   182         }
   194         }
   183     else
   195     else
   184         {
   196         {
   185         TN_DEBUG2( "CThumbnailScaleTask(0x%08x)::StartL() - scaling", this);
   197         TN_DEBUG2( "CThumbnailScaleTask(0x%08x)::StartL() - scaling", this);
       
   198         OstTrace1( TRACE_NORMAL, DUP5_CTHUMBNAILSCALETASK_STARTL, "CThumbnailScaleTask::StartL - scaling;this=%o", this );
   186         
   199         
   187         User::LeaveIfError( iScaledBitmap->Create( iTargetSize, iBitmap->DisplayMode() ));
   200         User::LeaveIfError( iScaledBitmap->Create( iTargetSize, iBitmap->DisplayMode() ));
   188         iServer.ScaleBitmapL( iStatus, * iBitmap, * iScaledBitmap, iCropRectangle );
   201         iServer.ScaleBitmapL( iStatus, * iBitmap, * iScaledBitmap, iCropRectangle );
   189         SetActive();
   202         SetActive();
   190         }  
   203         }  
   191     
   204     
   192     TN_DEBUG2( "CThumbnailScaleTask(0x%08x)::StartL() end", this );
   205     TN_DEBUG2( "CThumbnailScaleTask(0x%08x)::StartL() end", this );
       
   206     OstTrace1( TRACE_NORMAL, DUP6_CTHUMBNAILSCALETASK_STARTL, "CThumbnailScaleTask::StartL - end;this=%o", this );
   193     }
   207     }
   194 
   208 
   195 
   209 
   196 // ---------------------------------------------------------------------------
   210 // ---------------------------------------------------------------------------
   197 // CThumbnailScaleTask::RunL()
   211 // CThumbnailScaleTask::RunL()
   200 void CThumbnailScaleTask::RunL()
   214 void CThumbnailScaleTask::RunL()
   201     {
   215     {
   202     TInt err = iStatus.Int();
   216     TInt err = iStatus.Int();
   203 
   217 
   204     TN_DEBUG3( "CThumbnailScaleTask(0x%08x)::RunL() err=%d)", this, err );
   218     TN_DEBUG3( "CThumbnailScaleTask(0x%08x)::RunL() err=%d)", this, err );
       
   219     OstTrace1( TRACE_NORMAL, CTHUMBNAILSCALETASK_RUNL, "CThumbnailScaleTask::RunL;this=%o", this );
       
   220     OstTrace1( TRACE_NORMAL, DUP1_CTHUMBNAILSCALETASK_RUNL, "CThumbnailScaleTask::RunL;err=%d", err );
   205 
   221 
   206     #ifdef _DEBUG
   222     #ifdef _DEBUG
   207     aStop.UniversalTime();
   223     aStop.UniversalTime();
       
   224     TInt tookTime = (TInt)aStop.MicroSecondsFrom(aStart).Int64()/1000;
   208     TN_DEBUG2( "CThumbnailScaleTask::RunL() scale took %d ms", (TInt)aStop.MicroSecondsFrom(aStart).Int64()/1000);
   225     TN_DEBUG2( "CThumbnailScaleTask::RunL() scale took %d ms", (TInt)aStop.MicroSecondsFrom(aStart).Int64()/1000);
       
   226     OstTrace1( TRACE_NORMAL, DUP2_CTHUMBNAILSCALETASK_RUNL, "CThumbnailScaleTask::RunL - scale took ms;tookTime=%d", tookTime );
   209     #endif
   227     #endif
   210 
   228 
   211     if ( !err )
   229     if ( !err )
   212         {
   230         {
   213         TRAP( err, StoreAndCompleteL());
   231         TRAP( err, StoreAndCompleteL());
   223 // ---------------------------------------------------------------------------
   241 // ---------------------------------------------------------------------------
   224 //
   242 //
   225 void CThumbnailScaleTask::DoCancel()
   243 void CThumbnailScaleTask::DoCancel()
   226     {
   244     {
   227     TN_DEBUG2( "CThumbnailScaleTask(0x%08x)::DoCancel()", this );
   245     TN_DEBUG2( "CThumbnailScaleTask(0x%08x)::DoCancel()", this );
       
   246     OstTrace1( TRACE_NORMAL, CTHUMBNAILSCALETASK_DOCANCEL, "CThumbnailScaleTask::DoCancel;this=%o", this );
   228     iServer.CancelScale();
   247     iServer.CancelScale();
   229     }
   248     }
   230 
   249 
   231 
   250 
   232 // ---------------------------------------------------------------------------
   251 // ---------------------------------------------------------------------------
   331 //
   350 //
   332 void CThumbnailScaleTask::StoreAndCompleteL()
   351 void CThumbnailScaleTask::StoreAndCompleteL()
   333     {
   352     {
   334     TN_DEBUG6( "CThumbnailScaleTask(0x%08x)::StoreAndCompleteL() iFilename=%S, iThumbnailSize=%d, iBitmap=0x%08x, iScaledBitmap=0x%08x)", 
   353     TN_DEBUG6( "CThumbnailScaleTask(0x%08x)::StoreAndCompleteL() iFilename=%S, iThumbnailSize=%d, iBitmap=0x%08x, iScaledBitmap=0x%08x)", 
   335                this, &iFilename, iThumbnailSize, iBitmap, iScaledBitmap );
   354                this, &iFilename, iThumbnailSize, iBitmap, iScaledBitmap );
       
   355     OstTrace1( TRACE_NORMAL, CTHUMBNAILSCALETASK_STOREANDCOMPLETEL, "CThumbnailScaleTask::StoreAndCompleteL;this=%o", this );
       
   356 	OstTraceExt1( TRACE_NORMAL, DUP1_CTHUMBNAILSCALETASK_STOREANDCOMPLETEL, "CThumbnailScaleTask::StoreAndCompleteL;iFilename=%S", iFilename );
       
   357 	OstTrace1( TRACE_NORMAL, DUP2_CTHUMBNAILSCALETASK_STOREANDCOMPLETEL, "CThumbnailScaleTask::StoreAndCompleteL;iBitmap=%o", iBitmap );
       
   358 	
   336 		 
   359 		 
   337     // do not store TN if quality is too low eg. orignal size of image is smaller than requested size
   360     // do not store TN if quality is too low eg. orignal size of image is smaller than requested size
   338     // (do not store upscaled images)
   361     // (do not store upscaled images)
   339     if ( (iTargetSizeTN.iWidth > iOriginalSize.iWidth || iTargetSizeTN.iHeight > iOriginalSize.iHeight) && iEXIF)
   362     if ( (iTargetSizeTN.iWidth > iOriginalSize.iWidth || iTargetSizeTN.iHeight > iOriginalSize.iHeight) && iEXIF)
   340         {
   363         {
   341         TN_DEBUG1("CThumbnailScaleTask()::StoreAndCompleteL() too low quality");
   364         TN_DEBUG1("CThumbnailScaleTask()::StoreAndCompleteL() too low quality");
       
   365         OstTrace0( TRACE_NORMAL, DUP3_CTHUMBNAILSCALETASK_STOREANDCOMPLETEL, "CThumbnailScaleTask::StoreAndCompleteL - too low quality" );
   342         iDoStore = EFalse;
   366         iDoStore = EFalse;
   343         }
   367         }
   344     
   368     
   345     TN_DEBUG3("CThumbnailScaleTask(0x%08x)::StoreAndCompleteL() iDoStore = %d", this, iDoStore);
   369     TN_DEBUG3("CThumbnailScaleTask(0x%08x)::StoreAndCompleteL() iDoStore = %d", this, iDoStore);
       
   370     OstTrace1( TRACE_NORMAL, DUP4_CTHUMBNAILSCALETASK_STOREANDCOMPLETEL, "CThumbnailScaleTask::StoreAndCompleteL;this=%o", this );
   346     
   371     
   347     if ( iDoStore )
   372     if ( iDoStore )
   348         {
   373         {
   349         if (iTargetUri != KNullDesC)
   374         if (iTargetUri != KNullDesC)
   350             {
   375             {
   375                     
   400                     
   376         // if need to add scaled bitmap to pool
   401         // if need to add scaled bitmap to pool
   377         if (iBitmapToPool)
   402         if (iBitmapToPool)
   378             {
   403             {
   379             TN_DEBUG1("CThumbnailScaleTask()::StoreAndCompleteL() scaled bitmap handle to params");
   404             TN_DEBUG1("CThumbnailScaleTask()::StoreAndCompleteL() scaled bitmap handle to params");
       
   405             OstTrace0( TRACE_NORMAL, DUP5_CTHUMBNAILSCALETASK_STOREANDCOMPLETEL, "CThumbnailScaleTask::StoreAndCompleteL" );
   380             
   406             
   381             params.iBitmapHandle = iScaledBitmap->Handle();
   407             params.iBitmapHandle = iScaledBitmap->Handle();
   382             }    
   408             }    
   383 		
   409 		
   384 	    if( params.iQualityPreference == CThumbnailManager::EOptimizeForQualityWithPreview
   410 	    if( params.iQualityPreference == CThumbnailManager::EOptimizeForQualityWithPreview
   385 	        && iEXIF && !iDoStore)
   411 	        && iEXIF && !iDoStore)
   386 	        {
   412 	        {
   387             TN_DEBUG1("CThumbnailScaleTask()::StoreAndCompleteL() EThumbnailPreviewThumbnail");
   413             TN_DEBUG1("CThumbnailScaleTask()::StoreAndCompleteL() EThumbnailPreviewThumbnail");
   388 	    
   414             OstTrace0( TRACE_NORMAL, DUP6_CTHUMBNAILSCALETASK_STOREANDCOMPLETEL, "CThumbnailScaleTask::StoreAndCompleteL - EThumbnailPreviewThumbnail" );
       
   415             
   389 		    // this is upscaled preview image
   416 		    // this is upscaled preview image
   390 	        params.iControlFlags = EThumbnailPreviewThumbnail;
   417 	        params.iControlFlags = EThumbnailPreviewThumbnail;
   391 	        }
   418 	        }
   392 	    
   419 	    
   393         TN_DEBUG1("CThumbnailScaleTask()::StoreAndCompleteL() write params to message");
   420         TN_DEBUG1("CThumbnailScaleTask()::StoreAndCompleteL() write params to message");
       
   421         OstTrace0( TRACE_NORMAL, DUP7_CTHUMBNAILSCALETASK_STOREANDCOMPLETEL, "CThumbnailScaleTask::StoreAndCompleteL - write params to message" );
   394         
   422         
   395 	    // pass bitmap handle to client
   423 	    // pass bitmap handle to client
   396 	    iMessage.WriteL( 0, iParamsBuf );
   424 	    iMessage.WriteL( 0, iParamsBuf );
   397 	    
   425 	    
   398         if (iBitmapToPool)
   426         if (iBitmapToPool)
   399             {
   427             {
   400             TN_DEBUG1("CThumbnailScaleTask()::StoreAndCompleteL() scaled bitmap to pool");
   428             TN_DEBUG1("CThumbnailScaleTask()::StoreAndCompleteL() scaled bitmap to pool");
   401         
   429             OstTrace0( TRACE_NORMAL, DUP8_CTHUMBNAILSCALETASK_STOREANDCOMPLETEL, "CThumbnailScaleTask::StoreAndCompleteL - scaled bitmap to pool" );
       
   430             
   402             iServer.AddBitmapToPoolL( iRequestId.iSession, iScaledBitmap, iRequestId );
   431             iServer.AddBitmapToPoolL( iRequestId.iSession, iScaledBitmap, iRequestId );
   403             iScaledBitmap = NULL; // Server owns the bitmap now
   432             iScaledBitmap = NULL; // Server owns the bitmap now
   404             }
   433             }
   405         }
   434         }
   406     
   435     
   407     TN_DEBUG1("CThumbnailScaleTask()::StoreAndCompleteL() - end");
   436     TN_DEBUG1("CThumbnailScaleTask()::StoreAndCompleteL() - end");
       
   437     OstTrace0( TRACE_NORMAL, DUP9_CTHUMBNAILSCALETASK_STOREANDCOMPLETEL, "CThumbnailScaleTask::StoreAndCompleteL - end" );
   408     }
   438     }
   409 
   439 
   410 
   440 
   411 // ---------------------------------------------------------------------------
   441 // ---------------------------------------------------------------------------
   412 // CThumbnailScaleTask::StoreAndCompleteL()
   442 // CThumbnailScaleTask::StoreAndCompleteL()