uiservicetab/vimpstdetailsviewplugin/src/cvimpstdetailsimagedecoder.cpp
branchRCL_3
changeset 4 f5911524345e
parent 0 5e5d6b214f4f
equal deleted inserted replaced
0:5e5d6b214f4f 4:f5911524345e
    20 
    20 
    21 #include "cvimpstdetailsheadercontrol.h"
    21 #include "cvimpstdetailsheadercontrol.h"
    22 
    22 
    23 #include <cbsbitmap.h>
    23 #include <cbsbitmap.h>
    24 #include <imageconversion.h> 
    24 #include <imageconversion.h> 
       
    25 #include <bitmaptransforms.h>
    25 
    26 
    26 // ---------------------------------------------------------------------------
    27 // ---------------------------------------------------------------------------
    27 // CVIMPSTDetailsImageDecoder::NewL
    28 // CVIMPSTDetailsImageDecoder::NewL
    28 // Two-phase construction
    29 // Two-phase construction
    29 // ---------------------------------------------------------------------------
    30 // ---------------------------------------------------------------------------
    54 // ---------------------------------------------------------------------------
    55 // ---------------------------------------------------------------------------
    55 //
    56 //
    56 void CVIMPSTDetailsImageDecoder::ConstructL(const TDesC8& aBitmapData)
    57 void CVIMPSTDetailsImageDecoder::ConstructL(const TDesC8& aBitmapData)
    57     {
    58     {
    58     iBitmapData = aBitmapData.AllocL();
    59     iBitmapData = aBitmapData.AllocL();
    59     User::LeaveIfError( iFs.Connect() );
    60     User::LeaveIfError( iFs.Connect() );   
    60     iImgDecoder = CImageDecoder::DataNewL( iFs, *iBitmapData );
       
    61     TFrameInfo info = iImgDecoder->FrameInfo();
       
    62     iBitmap = new ( ELeave ) CFbsBitmap;
       
    63     User::LeaveIfError( iBitmap->Create( info.iOverallSizeInPixels, info.iFrameDisplayMode ));
       
    64     }
    61     }
    65 
    62 
    66 // ---------------------------------------------------------------------------
    63 // ---------------------------------------------------------------------------
    67 // CVIMPSTDetailsImageDecoder::~CVIMPSTDetailsImageDecoder
    64 // CVIMPSTDetailsImageDecoder::~CVIMPSTDetailsImageDecoder
    68 // ---------------------------------------------------------------------------
    65 // ---------------------------------------------------------------------------
    83     if (iBitmapData)
    80     if (iBitmapData)
    84         {
    81         {
    85         delete iBitmapData;
    82         delete iBitmapData;
    86         iBitmapData = NULL;
    83         iBitmapData = NULL;
    87         }
    84         }
       
    85     if (iBitmapScaler)
       
    86         {
       
    87         delete iBitmapScaler;
       
    88         iBitmapScaler = NULL;
       
    89         }
       
    90 
    88     iFs.Close();
    91     iFs.Close();
    89     }
    92     }
    90 
    93 
    91 // ---------------------------------------------------------------------------
    94 // ---------------------------------------------------------------------------
    92 // CVIMPSTDetailsImageDecoder::Start
    95 // CVIMPSTDetailsImageDecoder::Start
    93 // Starts the decoding process
    96 // Starts the decoding process
    94 // ---------------------------------------------------------------------------
    97 // ---------------------------------------------------------------------------
    95 //
    98 //
    96 void CVIMPSTDetailsImageDecoder::Start()
    99 void CVIMPSTDetailsImageDecoder::StartL(TSize aBitmapSize)
    97     {
   100     {
    98     iStatus = KRequestPending;
   101     iDecoderState = ECcaConvertThumbnailImage;
    99     iImgDecoder->Convert( &iStatus, *iBitmap );
   102     iBitmapSize = aBitmapSize;
   100     SetActive();
   103     CreateBitmapL();
   101     }
   104     }
   102 
   105 
   103 // ---------------------------------------------------------------------------
   106 // ---------------------------------------------------------------------------
   104 // CVIMPSTDetailsImageDecoder::RunL
   107 // CVIMPSTDetailsImageDecoder::RunL
   105 // Called by the active object framework when the decoding (request) is
   108 // Called by the active object framework when the decoding (request) is
   107 // ---------------------------------------------------------------------------
   110 // ---------------------------------------------------------------------------
   108 //
   111 //
   109 void CVIMPSTDetailsImageDecoder::RunL() 
   112 void CVIMPSTDetailsImageDecoder::RunL() 
   110 	{
   113 	{
   111 	User::LeaveIfError( iStatus.Int() );
   114 	User::LeaveIfError( iStatus.Int() );
   112 	// Ownership of the bitmap is transferred
   115 	switch ( iDecoderState )
   113 	iHeader.SetBitmap(iBitmap, NULL );
   116 	    {
   114 	iBitmap = NULL;
   117 	    case ECcaConvertThumbnailImage:
       
   118 	        {
       
   119 	        iDecoderState = ECcaScaleThumbnail;
       
   120 	        ScaleBitmapL();
       
   121 	        break;
       
   122 	        }
       
   123 	    case ECcaScaleThumbnail:
       
   124 	        {
       
   125 	        // don't delete
       
   126 	        // Ownership of the bitmap is transferred   
       
   127 	        iHeader.SetBitmap(iBitmap, NULL );
       
   128 	        iBitmap = NULL;
       
   129 	        }
       
   130 	    default:
       
   131 	        break;
       
   132 	    }	
       
   133 	
   115    }
   134    }
   116 
   135 
   117 // ---------------------------------------------------------------------------
   136 // ---------------------------------------------------------------------------
   118 // CVIMPSTDetailsImageDecoder::DoCancel
   137 // CVIMPSTDetailsImageDecoder::DoCancel
   119 // Called when the decoding (request) is cancelled for some reason.
   138 // Called when the decoding (request) is cancelled for some reason.
   122 void CVIMPSTDetailsImageDecoder::DoCancel()
   141 void CVIMPSTDetailsImageDecoder::DoCancel()
   123     { 
   142     { 
   124     iImgDecoder->Cancel(); 
   143     iImgDecoder->Cancel(); 
   125     }
   144     }
   126 
   145 
       
   146 // ---------------------------------------------------------------------------
       
   147 // CVIMPSTDetailsImageDecoder::ScaleBitmapL
       
   148 // scaling it to fit to the screen
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151 void CVIMPSTDetailsImageDecoder::ScaleBitmapL()
       
   152     {   
       
   153     iBitmapScaler = CBitmapScaler::NewL();
       
   154     iBitmapScaler->Scale( &iStatus, *iBitmap, iBitmapSize );
       
   155     SetActive();
       
   156     }
       
   157 
       
   158 // ---------------------------------------------------------------------------
       
   159 // CVIMPSTDetailsImageDecoder::CreateBitmapL
       
   160 // creates the bitmap
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 
       
   164 void CVIMPSTDetailsImageDecoder::CreateBitmapL()
       
   165     {
       
   166     if ( iDecoderState == ECcaConvertThumbnailImage )
       
   167         {
       
   168         iImgDecoder = CImageDecoder::DataNewL( iFs, *iBitmapData, CImageDecoder::EOptionAlwaysThread );
       
   169         }   
       
   170    if ( !iBitmap )
       
   171        {
       
   172        TFrameInfo info = iImgDecoder->FrameInfo();
       
   173        iBitmap = new ( ELeave ) CFbsBitmap;
       
   174        User::LeaveIfError( iBitmap->Create( info.iOverallSizeInPixels, info.iFrameDisplayMode ));
       
   175        } 
       
   176     iStatus = KRequestPending;
       
   177     iImgDecoder->Convert( &iStatus, *iBitmap );
       
   178     SetActive();
       
   179     }
   127 // end of file
   180 // end of file