idlehomescreen/xmluirendering/renderingplugins/xnbitmapfactory/src/xnimagedecoder.cpp
branchRCL_3
changeset 26 1b758917cafc
equal deleted inserted replaced
25:137ebc85284b 26:1b758917cafc
       
     1 /*
       
     2 * Copyright (c) 2008 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:
       
    13 *
       
    14 * Description:  Image decoder
       
    15 *
       
    16 */
       
    17 
       
    18 // System includes
       
    19 #include <imageconversion.h>
       
    20 
       
    21 // User includes
       
    22 #include "xncomponent.h"
       
    23 #include "xnnodepluginif.h"
       
    24 #include "xnuienginepluginif.h"
       
    25 #include "xnbitmapadapter.h"
       
    26 #include "xnimagedecoder.h"
       
    27 
       
    28 using namespace ContentAccess;
       
    29 
       
    30 // Constants
       
    31     
       
    32 // ============================ LOCAL FUNCTIONS ================================
       
    33 // ============================ MEMBER FUNCTIONS ===============================
       
    34 // -----------------------------------------------------------------------------
       
    35 // CXnImageDecoder::NewL()
       
    36 // Two-phased constructor.
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 CXnImageDecoder* CXnImageDecoder::NewL( CXnBitmapAdapter& aAdapter, RFs& aFs ) 
       
    40     {
       
    41     CXnImageDecoder* self = CXnImageDecoder::NewLC( aAdapter, aFs );
       
    42     CleanupStack::Pop( self );
       
    43     return self;
       
    44     }
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // CXnImageDecoder::NewLC()
       
    48 // Two-phased constructor.
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 CXnImageDecoder* CXnImageDecoder::NewLC( CXnBitmapAdapter& aAdapter, RFs& aFs )
       
    52     {
       
    53     CXnImageDecoder* self = new ( ELeave ) CXnImageDecoder( aAdapter, aFs );
       
    54     CleanupStack::PushL( self );
       
    55     self->ConstructL();
       
    56     return self;
       
    57     }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CXnImageDecoder::~CXnImageDecoder()
       
    61 // C++ default destructor.
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CXnImageDecoder::~CXnImageDecoder()
       
    65     {    
       
    66     Cancel();
       
    67     
       
    68     Cleanup();
       
    69     }
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // CXnImageDecoder::CXnImageDecoder()
       
    73 // C++ default constructor.
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 CXnImageDecoder::CXnImageDecoder( CXnBitmapAdapter& aAdapter, RFs& aFs )
       
    77     : CActive( CActive::EPriorityHigh ), iAdapter( aAdapter ), iFs( aFs )
       
    78     {
       
    79     CActiveScheduler::Add( this );
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CXnImageDecoder::ConstructL()
       
    84 // 2nd phase constructor.
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 void CXnImageDecoder::ConstructL()
       
    88     {                     
       
    89     }
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CXnImageDecoder::RunL()
       
    93 // 
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 void CXnImageDecoder::RunL()
       
    97     {   
       
    98     // Takes ownership of iBitmap and iMask
       
    99     iAdapter.SetContentBitmaps( iBitmap, iMask );
       
   100     
       
   101     iBitmap = NULL;
       
   102     iMask = NULL;
       
   103     
       
   104     delete iDecoder;
       
   105     iDecoder = NULL;
       
   106     
       
   107     iAdapter.Component()->Node()->UiEngineL()->RenderUIL();
       
   108     }
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // CXnImageDecoder::RunError()
       
   112 // 
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 TInt CXnImageDecoder::RunError( TInt /*aError*/ )
       
   116     {
       
   117     Cleanup();
       
   118     
       
   119     // Set NULL bitmaps
       
   120     TRAP_IGNORE( RunL() );
       
   121     
       
   122     // Ignore
       
   123     return KErrNone;
       
   124     }
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // CXnImageDecoder::DoCancel()
       
   128 // 
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 void CXnImageDecoder::DoCancel()
       
   132     {
       
   133     Cleanup();
       
   134     }
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // CXnImageDecoder::DecodeL()
       
   138 // 
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 void CXnImageDecoder::DecodeL( TFileName& aFilename )
       
   142     {     
       
   143     Cancel();
       
   144     
       
   145     TInt options( 
       
   146         CImageDecoder::EOptionAlwaysThread | 
       
   147         CImageDecoder::EPreferFastDecode );
       
   148          
       
   149     iDecoder = CImageDecoder::FileNewL( iFs, aFilename, EView, 
       
   150         ( CImageDecoder::TOptions ) options ); 
       
   151     
       
   152     TFrameInfo frameInfo( iDecoder->FrameInfo( 0 ) );
       
   153     
       
   154     CFbsBitmap* bitmap = new ( ELeave ) CFbsBitmap;
       
   155     CleanupStack::PushL( bitmap );
       
   156     
       
   157     User::LeaveIfError( bitmap->Create( 
       
   158         frameInfo.iOverallSizeInPixels, frameInfo.iFrameDisplayMode ) );
       
   159                              
       
   160     if ( frameInfo.iFlags & TFrameInfo::ETransparencyPossible )
       
   161         {
       
   162         CFbsBitmap* mask = new ( ELeave ) CFbsBitmap;
       
   163         CleanupStack::PushL( mask );
       
   164         
       
   165         User::LeaveIfError( mask->Create( frameInfo.iOverallSizeInPixels,                
       
   166             ( frameInfo.iFlags & TFrameInfo::EAlphaChannel ) ? EGray256 : EGray2 ) );
       
   167         
       
   168         iDecoder->Convert( &iStatus, *bitmap, *mask );
       
   169         
       
   170         CleanupStack::Pop( mask );
       
   171         iMask = mask;
       
   172         }
       
   173     else
       
   174         {
       
   175         iDecoder->Convert( &iStatus, *bitmap );               
       
   176         }
       
   177     
       
   178     CleanupStack::Pop( bitmap );
       
   179     iBitmap = bitmap;
       
   180         
       
   181     SetActive();    
       
   182     }
       
   183 
       
   184 // -----------------------------------------------------------------------------
       
   185 // CXnImageDecoder::Cleanup()
       
   186 // 
       
   187 // -----------------------------------------------------------------------------
       
   188 //
       
   189 void CXnImageDecoder::Cleanup()
       
   190     {
       
   191     if ( iDecoder )
       
   192         {
       
   193         iDecoder->Cancel();        
       
   194         }
       
   195     
       
   196     delete iDecoder;
       
   197     iDecoder = NULL;
       
   198     
       
   199     delete iBitmap;
       
   200     iBitmap = NULL;
       
   201     
       
   202     delete iMask;
       
   203     iMask = NULL;      
       
   204     }
       
   205 
       
   206 // End of file