skins/AknSkins/rlpluginsrc/AknsRlEffectPluginContrast.cpp
changeset 0 05e9090e2422
equal deleted inserted replaced
-1:000000000000 0:05e9090e2422
       
     1 /*
       
     2 * Copyright (c) 2004-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:  Provides functionality adjust image contrast.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "AknsRlEffectPluginContrast.h"
       
    21 #include "AknsRlEffectUtil.h"
       
    22 #include "fx_asm_versions.h"
       
    23 
       
    24 // ================ TEMPLATE IMPL. OF CONTRAST =================================
       
    25 /**
       
    26 * Template implementation of Contrast. Type defines the used data type for
       
    27 * iterating over the bitmap data. X, R, G and B define the used pixel color bit
       
    28 * layout.
       
    29 */
       
    30 template<class Type,TInt X, TInt R, TInt G, TInt B>
       
    31 class AknsRlEffectContrast
       
    32     {
       
    33     public:
       
    34     //------------------------------------------------------------------------
       
    35     static void Process( const CFbsBitmap& aTarget,
       
    36                          const CFbsBitmap& aSource,
       
    37                          const TInt aAdjustment )
       
    38         {
       
    39         // ScanLineLength returns bytes, but width must match the Type
       
    40         TInt width  = CFbsBitmap::ScanLineLength( aSource.SizeInPixels().iWidth,
       
    41                                                   aSource.DisplayMode() ) / sizeof(Type);
       
    42         TInt height = aSource.SizeInPixels().iHeight;
       
    43 
       
    44         TInt pixelCount = width * height;
       
    45         TInt r,g,b;
       
    46 
       
    47         aTarget.LockHeap( ETrue ); // Lock the global bitmap buffer
       
    48         Type* dataT = reinterpret_cast<Type*>( aTarget.DataAddress() );
       
    49         Type* dataS = reinterpret_cast<Type*>( aSource.DataAddress() );
       
    50 
       
    51         for( TInt index = 0; index < pixelCount; ++index )
       
    52             {
       
    53             // Contrast is simple, blend with middle gray (127)
       
    54             // Note: It is assumed that arithmetic shifting is supported
       
    55             // -> negative values are shifted correctly
       
    56             r = (AknsRlRgb<Type,X,R,G,B>::R8(*dataS) * (255 + aAdjustment) - aAdjustment * 127) >> 8;
       
    57             g = (AknsRlRgb<Type,X,R,G,B>::G8(*dataS) * (255 + aAdjustment) - aAdjustment * 127) >> 8;
       
    58             b = (AknsRlRgb<Type,X,R,G,B>::B8(*dataS) * (255 + aAdjustment) - aAdjustment * 127) >> 8;
       
    59 
       
    60             if( r < 0 ) r = 0; else if( r > 255 ) r = 255;
       
    61             if( g < 0 ) g = 0; else if( g > 255 ) g = 255;
       
    62             if( b < 0 ) b = 0; else if( b > 255 ) b = 255;
       
    63 
       
    64             AknsRlRgb<Type,X,R,G,B>::SetRgb8( dataT, TUint8(r), TUint8(g), TUint8(b) );
       
    65 
       
    66             dataT++;
       
    67             dataS++;
       
    68             }
       
    69 
       
    70         aTarget.UnlockHeap( ETrue );
       
    71         }
       
    72     }; // End of AknsRlEffectContrast
       
    73 
       
    74 // ============================ MEMBER FUNCTIONS ===============================
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CAknsRlEffectPluginContrast::CAknsRlEffectPluginContrast
       
    78 // C++ default constructor can NOT contain any code, that
       
    79 // might leave.
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 CAknsRlEffectPluginContrast::CAknsRlEffectPluginContrast()
       
    83     {
       
    84     }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // Destructor
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 CAknsRlEffectPluginContrast::~CAknsRlEffectPluginContrast()
       
    91     {
       
    92     iContext = NULL; // Removes lint nag
       
    93     }
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CAknsRlEffectPluginContrast::EffectUid
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 TUid CAknsRlEffectPluginContrast::EffectUid() const
       
   100     {
       
   101     return TUid::Uid( KAknsRlEffectPluginContrastUID );
       
   102     }
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // CAknsRlEffectPluginContrast::Effect
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 MAknsRlEffect* CAknsRlEffectPluginContrast::Effect( const TInt aInterface )
       
   109     {
       
   110     if( aInterface == KAknsRlEffectPluginInterfaceEffect )
       
   111         return this;
       
   112     return NULL;
       
   113     }
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // CAknsRlEffectPluginContrast::InitializeL
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 void CAknsRlEffectPluginContrast::InitializeL()
       
   120     {
       
   121     iContext = NULL;
       
   122     }
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // CAknsRlEffectPluginContrast::Release
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 void CAknsRlEffectPluginContrast::Release()
       
   129     {
       
   130     }
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // CAknsRlEffectPluginContrast::ActivateL
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 void CAknsRlEffectPluginContrast::ActivateL( MAknsRlEffectContext* aContext )
       
   137     {
       
   138     if( !aContext ) // We absolutely need the context
       
   139         {
       
   140         User::Leave( KErrArgument );
       
   141         }
       
   142 
       
   143     iContext = aContext;
       
   144 
       
   145     iAdjustment = 0;
       
   146     }
       
   147 
       
   148 // -----------------------------------------------------------------------------
       
   149 // CAknsRlEffectPluginContrast::Deactivate
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 void CAknsRlEffectPluginContrast::Deactivate()
       
   153     {
       
   154     }
       
   155 
       
   156 // -----------------------------------------------------------------------------
       
   157 // CAknsRlEffectPluginContrast::SetParametersL
       
   158 // -----------------------------------------------------------------------------
       
   159 //
       
   160 void CAknsRlEffectPluginContrast::SetParametersL( MAknsRlParameterIterator& aParameters )
       
   161     {
       
   162     // Iterate over available parameters
       
   163     while( aParameters.HasNext() )
       
   164         {
       
   165         const TAknsRlParameterData* param = aParameters.NextL();
       
   166 
       
   167         // Fetch adjustment value
       
   168         if( param->iName->Compare( KAknsRlEffectContrastAdjustment ) == 0 )
       
   169             {
       
   170             if( param->iType != EAknsRlParameterTypeNumber )
       
   171                 User::Leave( KErrArgument );
       
   172 
       
   173             iAdjustment = param->iNumber;
       
   174             }
       
   175         }
       
   176     }
       
   177 
       
   178 // -----------------------------------------------------------------------------
       
   179 // CAknsRlEffectPluginContrast::GetCapabilities
       
   180 // -----------------------------------------------------------------------------
       
   181 //
       
   182 void CAknsRlEffectPluginContrast::GetCapabilities( TAknsRlEffectCaps& aCaps )
       
   183     {
       
   184     aCaps.iOutputLayerSupport = KAknsRlLayerRGBOnly;
       
   185     aCaps.iInputLayerASupport = KAknsRlLayerRGBOnly;
       
   186     aCaps.iInputLayerBSupport = KAknsRlLayerNone;
       
   187     }
       
   188 
       
   189 // -----------------------------------------------------------------------------
       
   190 // CAknsRlEffectPluginContrast::Render
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 TInt CAknsRlEffectPluginContrast::Render( const TAknsRlRenderOpParam& aParam )
       
   194     {
       
   195     if( !iContext ) // We absolutely need the context
       
   196         {
       
   197         return KErrBadHandle;
       
   198         }
       
   199 
       
   200     // To do anything we need both, the output layer and input layer
       
   201     if( ( aParam.iOutputLayerStatus & KAknsRlLayerRGBOnly ) &&
       
   202         ( aParam.iInputLayerAStatus & KAknsRlLayerRGBOnly ) )
       
   203         {
       
   204         // Query the layers, uninitialized because we process the whole image
       
   205         TAknsRlLayerData dataTarget;
       
   206         TRAPD( err, iContext->GetLayerDataL( dataTarget, aParam.iOutputLayerIndex,
       
   207                                              aParam.iOutputLayerStatus, EFalse ) );
       
   208         if( KErrNone != err )
       
   209             return KErrArgument;
       
   210 
       
   211         TAknsRlLayerData dataSource;
       
   212         TRAP( err, iContext->GetLayerDataL( dataSource, aParam.iInputLayerAIndex,
       
   213                                             aParam.iInputLayerAStatus, EFalse ) );
       
   214         if( KErrNone != err )
       
   215             return KErrArgument;
       
   216 
       
   217         if( !dataTarget.iRGBBitmap ) // We need the target bitmap
       
   218             return KErrBadHandle;
       
   219 
       
   220         if( !dataSource.iRGBBitmap ) // We need the source bitmap
       
   221             return KErrBadHandle;
       
   222 
       
   223         TDisplayMode modeT = dataTarget.iRGBBitmap->DisplayMode();
       
   224         TDisplayMode modeS = dataSource.iRGBBitmap->DisplayMode();
       
   225 
       
   226 #ifndef ARM_VERSION // winscw
       
   227         // Process the filter
       
   228         if( EColor64K == modeS && EColor64K == modeT )
       
   229             {
       
   230             AknsRlEffectContrast<TUint16,0,5,6,5>::Process(
       
   231                             *dataTarget.iRGBBitmap,
       
   232                             *dataSource.iRGBBitmap,
       
   233                             iAdjustment );
       
   234             }
       
   235         else if( EColor16MU == modeS && EColor16MU == modeT )
       
   236             {
       
   237             AknsRlEffectContrast<TUint32,8,8,8,8>::Process(
       
   238                             *dataTarget.iRGBBitmap,
       
   239                             *dataSource.iRGBBitmap,
       
   240                             iAdjustment );
       
   241             }
       
   242 #else // ARM
       
   243         // Process the filter
       
   244         if( (EColor64K == modeS && EColor64K == modeT) ||
       
   245             (EColor16MU == modeS && EColor16MU == modeT) )
       
   246             {
       
   247             AProcessContrast(*dataTarget.iRGBBitmap,
       
   248                              *dataSource.iRGBBitmap,
       
   249                              iAdjustment,
       
   250                              modeS );
       
   251             }
       
   252 #endif
       
   253         else
       
   254             {
       
   255             // Provided layers have illegal display mode combination
       
   256             return KErrArgument;
       
   257             }
       
   258         }
       
   259     else
       
   260         {
       
   261         // Required layers were not provided
       
   262         return KErrArgument;
       
   263         }
       
   264 
       
   265     return KErrNone;
       
   266     }
       
   267 
       
   268 // End of File