vtengines/videoteleng/Src/Media/CVtEngImageScaler.cpp
changeset 18 d9b6a8729acd
parent 4 6dc066157ed4
child 23 c378a0498b84
child 27 dcbddbbaf8fd
equal deleted inserted replaced
4:6dc066157ed4 18:d9b6a8729acd
     1 /*
       
     2 * Copyright (c) 2004 - 2006 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 scaler
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "CVtEngSettings.h"
       
    22 #include    "VtEngUtils.h"
       
    23 #include    "CVtEngImageScaler.h"
       
    24 #include    <cvtimagebitmap.h>
       
    25 #include    <fbs.h>
       
    26 #include    <videotelephonyvariant.hrh>
       
    27 #include    <cvtlogger.h>
       
    28 
       
    29 // CONSTANTS
       
    30 // The number of used bitmaps as scaling targets.
       
    31 const TInt KVtEngTargetBitmapCount = 2;
       
    32 
       
    33 // ============================ MEMBER FUNCTIONS ===============================
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CVtEngImageScaler::NewL
       
    37 // Two-phased constructor.
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 MVtEngImageScaler* CVtEngImageScaler::NewL(
       
    41     MVtEngScalerObserver& aObserver )
       
    42     {
       
    43     __VTPRINTENTER( "Scaler.NewL" )
       
    44     CVtEngImageScaler* scaler = new ( ELeave ) CVtEngImageScaler( aObserver );
       
    45     CleanupStack::PushL( scaler );
       
    46     scaler->ConstructL();
       
    47     CleanupStack::Pop( scaler );
       
    48     __VTPRINTEXIT( "Scaler.NewL" )
       
    49     return scaler;
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CVtEngImageScaler::ConstructL
       
    54 // Symbian 2nd phase constructor can leave.
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 void CVtEngImageScaler::ConstructL()
       
    58     {
       
    59     iVtScaler = CVtImageScaler::NewL( *this );
       
    60     GetScalingMethodL();
       
    61     iVtScaler->SetQualityL( iScalingMethod );
       
    62     }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CVtEngImageScaler::ScaleL
       
    66 // Scaling method.
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 void CVtEngImageScaler::ScaleL(
       
    70             TInt aSourceIndex )
       
    71     {
       
    72     __VTPRINTENTER( "Scaler.ScaleL" )
       
    73     __VTPRINT2( DEBUG_MEDIA | DEBUG_DETAIL, "Scaler:ScaleL index=%d",
       
    74         aSourceIndex )
       
    75     __VTPRINT2( DEBUG_MEDIA | DEBUG_DETAIL, "Scaler:ScaleL target index=%d",
       
    76     iTargetBitmapInUse )
       
    77     if ( iVtScaler->IsActive() )
       
    78         {
       
    79         __VTPRINT( DEBUG_MEDIA | DEBUG_DETAIL, "Scaler:ScaleL NActive" )
       
    80         User::Leave( KErrInUse );
       
    81         }
       
    82 
       
    83     // If there is no bitmaps done, do leave.
       
    84     // The caller should call ConfigureL.
       
    85     if ( iSources.Count() <= 0  || iTargets.Count() <= 0 )
       
    86         {
       
    87         __VTPRINT( DEBUG_MEDIA | DEBUG_DETAIL, "Scaler:ScaleL: not conf" )
       
    88         User::Leave( KErrNotReady );
       
    89         }
       
    90     iVtScaler->ScaleL( *iSources[ aSourceIndex ] ,
       
    91          *iTargets[iTargetBitmapInUse] );
       
    92     __VTPRINTEXIT( "Scaler.ScaleL" )
       
    93     }
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CVtEngImageScaler::Configure
       
    97 // Configure scaling.
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 TBool CVtEngImageScaler::ConfigureL(
       
   101     TDisplayMode aDisplayMode,
       
   102     TSize aSize,
       
   103     TInt aSourceHandle1,
       
   104     TInt aSourceHandle2 )
       
   105     {
       
   106     __VTPRINTENTER( "Scaler.ConfigureL" )
       
   107     __VTPRINT( DEBUG_MEDIA , "================== Scaler.Config ==================" )
       
   108     __VTPRINT2( DEBUG_MEDIA, "    aSize.iWidth:%d ", aSize.iWidth)
       
   109     __VTPRINT2( DEBUG_MEDIA, "    aSize.iHeight:%d ", aSize.iHeight )
       
   110     __VTPRINT2( DEBUG_MEDIA, "    aDisplayMode:%d", aDisplayMode )
       
   111     __VTPRINT( DEBUG_MEDIA , "================== Scaler.Config ==================" )
       
   112 
       
   113     TInt sourceHandle1( 0 );
       
   114     if ( iSources.Count() > 0 )
       
   115         {
       
   116         CVtImageBitmap* bmp = iSources[ EFirstBitmap ];
       
   117         if ( bmp )
       
   118             {
       
   119             sourceHandle1 = bmp->Bitmap().Handle();
       
   120             }
       
   121         }
       
   122     TInt sourceHandle2( 0 );
       
   123     if ( iSources.Count() > 1 )
       
   124         {
       
   125         CVtImageBitmap* bmp = iSources[ ESecondBitmap ];
       
   126         if ( bmp )
       
   127             {
       
   128             sourceHandle2 = bmp->Bitmap().Handle();
       
   129             }
       
   130         }
       
   131 
       
   132     // Do we have to cancel scaling first?
       
   133     TBool cancelled( iVtScaler->IsActive() );
       
   134 
       
   135     if ( aSourceHandle1 != sourceHandle1 || aSourceHandle2 != sourceHandle2
       
   136         || aSize != iSize || iMode != aDisplayMode )
       
   137         {
       
   138         if ( cancelled )
       
   139             {
       
   140             __VTPRINT( DEBUG_MEDIA | DEBUG_DETAIL, "Scaler:Config cancel" )
       
   141             Cancel();
       
   142             }
       
   143         }
       
   144     else
       
   145         {
       
   146         // Do we need the update => NO
       
   147         __VTPRINTEXITR( "Scaler.ConfigureL %d", EFalse )
       
   148         return EFalse;
       
   149         }
       
   150 
       
   151     // Store new mode and size.
       
   152     iMode = aDisplayMode;
       
   153     iSize = aSize;
       
   154 
       
   155     // The RVD source images have changed.
       
   156     if ( aSourceHandle1 != sourceHandle1 || aSourceHandle2 != sourceHandle2 )
       
   157         {
       
   158         __VTPRINT( DEBUG_MEDIA | DEBUG_DETAIL,
       
   159             "Scaler:ConfigureL create bitmaps" )
       
   160         CVtImageBitmap* vtBitmap = CVtImageBitmap::NewL( aSourceHandle1 );
       
   161         CleanupStack::PushL( vtBitmap );
       
   162         CVtImageBitmap* vtBitmap2 = CVtImageBitmap::NewL( aSourceHandle2 );
       
   163         CleanupStack::PushL( vtBitmap2 );
       
   164 
       
   165 	    __VTPRINT( DEBUG_MEDIA | DEBUG_DETAIL, "Scaler:ConfigureL source reset" )
       
   166         iSources.ResetAndDestroy();
       
   167         iSources.AppendL( vtBitmap );
       
   168         iSources.AppendL( vtBitmap2 );
       
   169 	    CleanupStack::Pop( KVtEngTargetBitmapCount ); // vtBitMaps
       
   170         }
       
   171 
       
   172     __VTPRINT( DEBUG_MEDIA | DEBUG_DETAIL, "Scaler:ConfigureL create targets" )
       
   173     CVtImageBitmap* vtBitmapT =  CVtImageBitmap::NewL( aSize, aDisplayMode );
       
   174     CleanupStack::PushL( vtBitmapT );
       
   175     CVtImageBitmap* vtBitmapT2 = CVtImageBitmap::NewL( aSize, aDisplayMode );
       
   176     CleanupStack::PushL( vtBitmapT2 );
       
   177 
       
   178     __VTPRINT( DEBUG_MEDIA | DEBUG_DETAIL, "Scaler:ConfigureL target reset" )
       
   179     iTargets.ResetAndDestroy();
       
   180     iTargets.AppendL( vtBitmapT );
       
   181     iTargets.AppendL( vtBitmapT2 );
       
   182     CleanupStack::Pop( KVtEngTargetBitmapCount ); // vtBitMapTs
       
   183 
       
   184     __VTPRINTEXITR( "Scaler.ConfigureL %d", cancelled )
       
   185     return cancelled;
       
   186     }
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // CVtEngImageScaler::ScalingFinished
       
   190 // Callback telling that scaling is done.
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 void CVtEngImageScaler::ScalingFinished( TInt aError )
       
   194     {
       
   195     __VTPRINTENTER( "Scaler.ScalingFinished" )
       
   196 
       
   197     __VTPRINT2( DEBUG_MEDIA | DEBUG_DETAIL, "Scaler:ScaleFin ", aError )
       
   198 
       
   199     if ( aError == KErrNone )
       
   200         {
       
   201         CFbsBitmap& bitmap = iTargets [ iTargetBitmapInUse ]->Bitmap();
       
   202         __VTPRINT2( DEBUG_MEDIA, "Scaler.ScalingFin index", iTargetBitmapInUse )
       
   203 
       
   204         if ( iTargetBitmapInUse == EFirstBitmap )
       
   205             {
       
   206             iTargetBitmapInUse = ESecondBitmap;
       
   207             }
       
   208         else
       
   209             {
       
   210             iTargetBitmapInUse = EFirstBitmap;
       
   211             }
       
   212         // Notify client of done scaling
       
   213         iObserver.ScalingCompleted( &bitmap, aError );
       
   214         }
       
   215     else
       
   216         {
       
   217         iObserver.ScalingCompleted( NULL, aError );
       
   218         }
       
   219     __VTPRINTEXIT( "Scaler.ScalingFinished" )
       
   220     }
       
   221 
       
   222 // -----------------------------------------------------------------------------
       
   223 // CVtEngImageScaler::~CVtEngImageScaler
       
   224 // Destructor.
       
   225 // -----------------------------------------------------------------------------
       
   226 //
       
   227 CVtEngImageScaler::~CVtEngImageScaler()
       
   228     {
       
   229     __VTPRINTENTER( "Scaler.~" )
       
   230 
       
   231     __VTPRINT( DEBUG_MEDIA | DEBUG_DETAIL, "Scaler:Dtor" )
       
   232     iTargets.ResetAndDestroy();
       
   233     iTargets.Close();
       
   234     iSources.ResetAndDestroy();
       
   235     iSources.Close();
       
   236     delete iVtScaler;
       
   237     __VTPRINTEXIT( "Scaler.~" )
       
   238     }
       
   239 
       
   240 // -----------------------------------------------------------------------------
       
   241 // CVtEngImageScaler::CVtEngImageScaler
       
   242 // C++ constructor.
       
   243 // -----------------------------------------------------------------------------
       
   244 //
       
   245 CVtEngImageScaler::CVtEngImageScaler(
       
   246     MVtEngScalerObserver& aObserver ) :
       
   247     iObserver( aObserver ), iTargetBitmapInUse ( EFirstBitmap ),
       
   248     iScalingMethod( CVtImageScaler::EWeightedAverage )
       
   249     {
       
   250     }
       
   251 
       
   252 // -----------------------------------------------------------------------------
       
   253 // CVtEngImageScaler::Release
       
   254 // Interface function implementation to delete the implementation.
       
   255 // -----------------------------------------------------------------------------
       
   256 //
       
   257 void CVtEngImageScaler::Release()
       
   258     {
       
   259     // Delete myself
       
   260   __VTPRINTENTER( "Scaler.Release" )
       
   261     delete this;
       
   262     __VTPRINTEXIT( "Scaler.Release" )
       
   263     }
       
   264 
       
   265 // -----------------------------------------------------------------------------
       
   266 // VtEngScalerFactory::CreateScalerL
       
   267 // Creates the image scaler.
       
   268 // -----------------------------------------------------------------------------
       
   269 //
       
   270 MVtEngImageScaler* VtEngScalerFactory::CreateScalerL(
       
   271     MVtEngScalerObserver& aObserver )
       
   272     {
       
   273     __VTPRINT( DEBUG_MEDIA | DEBUG_DETAIL,
       
   274         "VtEngScalerFactory::CreateScalerL" )
       
   275     return CVtEngImageScaler::NewL( aObserver );
       
   276     }
       
   277 
       
   278 // -----------------------------------------------------------------------------
       
   279 // CVtEngImageScaler::Cancel
       
   280 // Cancels the conversion.
       
   281 // -----------------------------------------------------------------------------
       
   282 //
       
   283 TInt CVtEngImageScaler::Cancel()
       
   284     {
       
   285     __VTPRINTENTER( "Scaler.Cancel" )
       
   286     iVtScaler->Cancel();
       
   287     __VTPRINTEXIT( "Scaler.Cancel" )
       
   288     return KErrNone;
       
   289     }
       
   290 
       
   291 // -----------------------------------------------------------------------------
       
   292 // CVtEngImageScaler::GetScalingMethodL
       
   293 // Gets the used scaling method from local variation.
       
   294 // -----------------------------------------------------------------------------
       
   295 //
       
   296 void CVtEngImageScaler::GetScalingMethodL()
       
   297     {
       
   298     __VTPRINTENTER( "Scaler.GetScalingMethodL" )
       
   299     // Check if the scaling method is non-default
       
   300     CVtEngSettings& settings = CVtEngUtility::Settings();
       
   301     if( settings.CheckBits(
       
   302         KVTLVFlagScalingMethodENearest ) )
       
   303         {
       
   304         iScalingMethod = CVtImageScaler::ENearest;
       
   305         }
       
   306     else if ( settings.CheckBits(
       
   307         KVTLVFlagScalingMethodEBilinear ) )
       
   308         {
       
   309         iScalingMethod = CVtImageScaler::EBilinear;
       
   310         }
       
   311     __VTPRINTEXITR( "Scaler.GetScalingMethodL %d", (TInt) iScalingMethod )
       
   312     }
       
   313 
       
   314 //  End of File