vtprotocolplugins/DisplaySink/src/CVtImageScalerImpl.cpp
changeset 0 ed9695c8bcbe
equal deleted inserted replaced
-1:000000000000 0:ed9695c8bcbe
       
     1 /*
       
     2 * Copyright (c) 2004 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 Transforms subsystem.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include <e32svr.h>
       
    22 #include <fbs.h>
       
    23 
       
    24 #include "CVtImageScalerImpl.h"
       
    25 #include "cvtimage.h"
       
    26 #include "CVtImageBitmap.h"
       
    27 
       
    28 // MACROS
       
    29 
       
    30 #ifdef _DEBUG
       
    31     #include <e32debug.h>
       
    32     #define PRINT RDebug::Print
       
    33     #define _IFDBG(a) a
       
    34 #else
       
    35     #define PRINT
       
    36     #define _IFDBG(a)
       
    37 #endif
       
    38 
       
    39 
       
    40 // ============================ MEMBER FUNCTIONS ===============================
       
    41 
       
    42 // ========================== CVtImageScalerImpl ==============================
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CVtImageScalerImpl::CVtImageScalerImpl()
       
    46 // -----------------------------------------------------------------------------
       
    47 CVtImageScalerImpl::CVtImageScalerImpl() : CActive( EPriorityStandard )
       
    48     {
       
    49     _IFDBG(PRINT( _L("ScaleImpl.Ctor<") ));
       
    50     CActiveScheduler::Add( this );
       
    51     _IFDBG(PRINT( _L("ScaleImpl.Ctor>") ));
       
    52     }
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CVtImageScalerImpl::~CVtImageScalerImpl()
       
    56 // -----------------------------------------------------------------------------
       
    57 CVtImageScalerImpl::~CVtImageScalerImpl()
       
    58     {
       
    59     _IFDBG(PRINT( _L("ScaleImpl.~<") ));
       
    60     Cancel();
       
    61     delete iScaler;
       
    62     _IFDBG(PRINT( _L("ScaleImpl.~>") ));
       
    63     }
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CVtImageScalerImpl::SetSourceTargetL(
       
    67 //  const CVtImage& aSource, CVtImage& aTarget )
       
    68 // -----------------------------------------------------------------------------
       
    69 void CVtImageScalerImpl::SetSourceTargetL(
       
    70     const CVtImage& aSource,
       
    71     CVtImage& aTarget )
       
    72     {
       
    73     iSource = iTarget = 0;
       
    74     LeaveIfNotValidSizeL( aSource.Size(), TSize( 2, 2 ) );
       
    75     LeaveIfNotValidSizeL( aTarget.Size() );
       
    76     ValidateSourceTargetL( aSource, aTarget );
       
    77     iSource = &aSource;
       
    78     iTarget = &aTarget;
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CVtImageScalerImpl::NeedHeapLock() const
       
    83 // -----------------------------------------------------------------------------
       
    84 TBool CVtImageScalerImpl::NeedHeapLock() const
       
    85     {
       
    86     return iSource->NeedHeapLock() || iTarget->NeedHeapLock();
       
    87     }
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // CVtImageScalerImpl::ScaleWithBitmapScalerL()
       
    91 // -----------------------------------------------------------------------------
       
    92 void CVtImageScalerImpl::ScaleWithBitmapScalerL(
       
    93     const CBitmapScaler::TQualityAlgorithm
       
    94 #ifdef _DEBUG
       
    95     aQuality
       
    96 #endif // _DEBUG
       
    97      )
       
    98     {
       
    99     _IFDBG(PRINT( _L("ScaleImpl.ScaleWithBitmapScalerL<") ));
       
   100     if ( IsActive() || iActiveSchedulerWait.IsStarted() )
       
   101         {
       
   102         _IFDBG(PRINT( _L("ScaleImpl.ScaleWithBitmapScalerL LEAVE KErrInUse>") ));
       
   103         User::Leave( KErrInUse );
       
   104         }
       
   105     _IFDBG(PRINT( _L("ScaleImpl::ScaleWithBitmapScalerL aQuality = %d"), aQuality ));
       
   106     CFbsBitmap& source( static_cast< CVtImageBitmap* >(
       
   107         const_cast< CVtImage* >( iSource ) )->Bitmap() );
       
   108     CFbsBitmap& target( static_cast< CVtImageBitmap* >( iTarget )->Bitmap() );
       
   109     iScaler = CBitmapScaler::NewL();
       
   110     SetActive();
       
   111     iScaler->Scale( &iStatus, source, target, EFalse );
       
   112     iActiveSchedulerWait.Start();
       
   113     delete iScaler; iScaler = NULL;
       
   114     _IFDBG(PRINT( _L("ScaleImpl.ScaleWithBitmapScalerL iStatus.Int() = %d"), iStatus.Int() ));
       
   115     User::LeaveIfError( iStatus.Int() );
       
   116     _IFDBG(PRINT( _L("ScaleImpl.ScaleWithBitmapScalerL>") ));
       
   117     }
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // CVtImageScalerImpl::LeaveIfNotValidSizeL(
       
   121 //  const TSize& aSize, const TSize aMinSize )
       
   122 // -----------------------------------------------------------------------------
       
   123 void CVtImageScalerImpl::LeaveIfNotValidSizeL(
       
   124     const TSize& aSize,
       
   125     const TSize aMinSize )
       
   126     {
       
   127     _IFDBG(PRINT( _L("ScaleImpl.LeaveIfNotValidSizeL<") ));
       
   128     if( ( aSize.iWidth < aMinSize.iWidth ) ||
       
   129         ( aSize.iHeight < aMinSize.iHeight ) )
       
   130         {
       
   131         User::Leave( KErrNotSupported );
       
   132         }
       
   133     _IFDBG(PRINT( _L("ScaleImpl.LeaveIfNotValidSizeL>") ));
       
   134     }
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // CVtImageScalerImpl::RunL()
       
   138 // -----------------------------------------------------------------------------
       
   139 void CVtImageScalerImpl::RunL()
       
   140     {
       
   141     _IFDBG(PRINT( _L("CVtImageScalerImpl.RunL") ));
       
   142     iActiveSchedulerWait.AsyncStop();
       
   143     }
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // CVtImageScalerImpl::RunL()
       
   147 // -----------------------------------------------------------------------------
       
   148 void CVtImageScalerImpl::DoCancel()
       
   149     {
       
   150     _IFDBG(PRINT( _L("CVtImageScalerImpl.DoCancel") ));
       
   151     iScaler->Cancel();
       
   152     iActiveSchedulerWait.AsyncStop();
       
   153     }
       
   154 
       
   155 // End of File
       
   156 
       
   157