imageeditorengine/filters/FilterBrightness/src/CFilterBrightness.cpp
changeset 1 edfc90759b9f
equal deleted inserted replaced
0:57d4cdd99204 1:edfc90759b9f
       
     1 /*
       
     2 * Copyright (c) 2010 Ixonos Plc.
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the "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 * Ixonos Plc
       
    14 *
       
    15 * Description:
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include <e32math.h>
       
    21 #include "CFilterBrightness.h"
       
    22 
       
    23 const TInt KBrightnessScale = 80;
       
    24 
       
    25 EXPORT_C TInt CFilterBrightness::Create()
       
    26 	{
       
    27 	CFilterBrightness* ptr = NULL;
       
    28 	TRAPD( error, ptr = NewL(); );
       
    29 	if( error != KErrNone )
       
    30 		{
       
    31 		ptr = NULL;
       
    32 		}
       
    33 	return (TInt)((MImageFilter*)ptr);
       
    34 	}
       
    35 
       
    36 
       
    37 
       
    38 CFilterBrightness* CFilterBrightness::NewL()
       
    39 	{
       
    40 	CFilterBrightness* self = new( ELeave )CFilterBrightness();
       
    41 	CleanupStack::PushL( self );
       
    42 	self->ConstructL();
       
    43 	CleanupStack::Pop( self );
       
    44 	return self;
       
    45 	}
       
    46 
       
    47 
       
    48 
       
    49 CFilterBrightness::~CFilterBrightness()
       
    50 	{
       
    51 	}
       
    52 
       
    53 
       
    54 
       
    55 CFilterBrightness::CFilterBrightness()
       
    56 	{
       
    57 
       
    58 	}
       
    59 
       
    60 
       
    61 
       
    62 void CFilterBrightness::ConstructL()
       
    63 	{
       
    64 
       
    65 	}
       
    66 
       
    67 
       
    68 
       
    69 TRect CFilterBrightness::Rect()
       
    70 	{
       
    71 	return iChild->Rect();
       
    72 	}
       
    73 
       
    74 TReal CFilterBrightness::Scale()
       
    75 	{
       
    76     return iChild->Scale();
       
    77 	}
       
    78 
       
    79 TSize CFilterBrightness::ViewPortSize()
       
    80 {
       
    81     return iChild->ViewPortSize();
       
    82 }
       
    83 
       
    84 TBlock * CFilterBrightness::GetBlockL ( const TRect & aRect )
       
    85 {
       
    86     TBlock * pB = iChild->GetBlockL (aRect);
       
    87     if (!pB) return NULL;
       
    88     TUint32 * pD = pB->iData;
       
    89     for (TInt i = 0; i < pB->iDataLength; ++i)
       
    90     {
       
    91         TUint32 c = *pD;
       
    92 
       
    93         TInt r = c & 0xFF0000;
       
    94         r += iAdjR;
       
    95         if (r > 0xFF0000)
       
    96         {
       
    97             r = 0xFF0000;
       
    98         }
       
    99         else if (r < 0)
       
   100         {
       
   101             r = 0;
       
   102         }
       
   103 
       
   104         TInt g = c & 0xFF00;
       
   105         g += iAdjG;
       
   106         if (g > 0xFF00)
       
   107         {
       
   108             g = 0xFF00;
       
   109         }
       
   110         else if (g < 0)
       
   111         {
       
   112             g = 0;
       
   113         }
       
   114 
       
   115         TInt b = c & 0xFF;
       
   116         b += iAdjB;
       
   117         if (b > 0xFF)
       
   118         {
       
   119             b = 0xFF;
       
   120         }
       
   121         if (b < 0)
       
   122         {
       
   123             b = 0;
       
   124         }
       
   125         *pD++ = 0 | r | g | b;
       
   126     }
       
   127     return pB;
       
   128 }
       
   129 
       
   130 
       
   131 
       
   132 void CFilterBrightness::SetParent( MImageFilter* aParent )
       
   133 	{
       
   134 	iParent = aParent;
       
   135 	}
       
   136 
       
   137 
       
   138 
       
   139 
       
   140 void CFilterBrightness::SetChild( MImageFilter* aChild )
       
   141 	{
       
   142 	iChild = aChild;
       
   143 	}
       
   144 
       
   145 
       
   146 
       
   147 TInt CFilterBrightness::CmdL( const TDesC16& aCmd )
       
   148 {
       
   149 
       
   150 	TLex lex (aCmd);
       
   151 
       
   152     //  Get brightness parameter [-100,100]
       
   153 	while ( ! lex.Eos() )
       
   154     {
       
   155 		TPtrC token = lex.NextToken();
       
   156 
       
   157         if ( token.Compare( _L("brightness") ) == 0)
       
   158         {
       
   159             TInt bpar = 0;
       
   160 			lex.Inc();
       
   161 			lex.Val (bpar);
       
   162 	        if (bpar < - 100)
       
   163 	        {
       
   164 		        bpar = -100;
       
   165 	        }
       
   166 	        else if (bpar > 100)
       
   167 	        {
       
   168 		        bpar = 100;
       
   169 	        }
       
   170 
       
   171             iBrightness = ((bpar * KBrightnessScale) / 100);
       
   172             iAdjR = iBrightness << 16;
       
   173             iAdjG = iBrightness << 8;
       
   174             iAdjB = iBrightness;
       
   175 		}
       
   176     }
       
   177     return 0;
       
   178 }
       
   179 
       
   180 const char* CFilterBrightness::Type()
       
   181 	{
       
   182 	return "brightness";
       
   183 	}
       
   184 	
       
   185 #if !defined(EKA2)
       
   186 GLDEF_C TInt E32Dll( TDllReason )
       
   187     {
       
   188     return KErrNone;
       
   189     }	
       
   190 
       
   191 #endif