imageeditorengine/filters/FilterContrast/Src/CFilterContrast.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 "CFilterContrast.h"
       
    22 
       
    23 EXPORT_C TInt CFilterContrast::Create()
       
    24 	{
       
    25 	CFilterContrast* ptr = NULL;
       
    26 	TRAPD( error, ptr = NewL(); );
       
    27 	if( error != KErrNone )
       
    28 		{
       
    29 		ptr = NULL;
       
    30 		}
       
    31 	return (TInt)((MImageFilter*)ptr);
       
    32 	}
       
    33 
       
    34 
       
    35 
       
    36 CFilterContrast* CFilterContrast::NewL()
       
    37 	{
       
    38 	CFilterContrast* self = new( ELeave )CFilterContrast();
       
    39 	CleanupStack::PushL( self );
       
    40 	self->ConstructL();
       
    41 	CleanupStack::Pop( self );
       
    42 	return self;
       
    43 	}
       
    44 
       
    45 
       
    46 
       
    47 CFilterContrast::~CFilterContrast()
       
    48 	{
       
    49 	}
       
    50 
       
    51 
       
    52 
       
    53 CFilterContrast::CFilterContrast()
       
    54 	{
       
    55 
       
    56 	}
       
    57 
       
    58 
       
    59 
       
    60 void CFilterContrast::ConstructL()
       
    61 	{
       
    62 	ComputeContrastStretchL();
       
    63 	}
       
    64 
       
    65 
       
    66 
       
    67 TRect CFilterContrast::Rect()
       
    68 	{
       
    69 	return iChild->Rect();
       
    70 	}
       
    71 
       
    72 TReal CFilterContrast::Scale()
       
    73 	{
       
    74 	return iChild->Scale();
       
    75 	}
       
    76 
       
    77 TSize CFilterContrast::ViewPortSize()
       
    78 {
       
    79     return iChild->ViewPortSize();
       
    80 }
       
    81 
       
    82 
       
    83 TBlock * CFilterContrast::GetBlockL ( const TRect & aRect )
       
    84 {
       
    85     TBlock * pB = iChild->GetBlockL (aRect);
       
    86     if (!pB) return NULL;
       
    87     TUint32 * pD = pB->iData;
       
    88     for (TInt i = 0; i < pB->iDataLength; ++i)
       
    89     {
       
    90         TUint32 c = *pD;
       
    91         TUint8 b = iLUT[c & 0xFF];
       
    92 	    c >>= 8;
       
    93 	    TUint8 g = iLUT[c & 0xFF];
       
    94         c >>= 8;
       
    95 	    TUint8 r = iLUT[c & 0xFF];
       
    96         *pD++ = 0 | b | (g << 8) | (r << 16);
       
    97     }
       
    98     return pB;
       
    99 }
       
   100 
       
   101 
       
   102 
       
   103 void CFilterContrast::SetParent( MImageFilter* aParent )
       
   104 	{
       
   105 	iParent = aParent;
       
   106 	}
       
   107 
       
   108 
       
   109 
       
   110 
       
   111 void CFilterContrast::SetChild( MImageFilter* aChild )
       
   112 	{
       
   113 	iChild = aChild;
       
   114 	}
       
   115 
       
   116 
       
   117 
       
   118 TInt CFilterContrast::CmdL( const TDesC16& aCmd )
       
   119 {
       
   120 
       
   121 	TLex lex (aCmd);
       
   122 
       
   123 	while ( ! lex.Eos() )
       
   124     {
       
   125 		TPtrC token = lex.NextToken();
       
   126 
       
   127         if ( token.Compare( _L("contrast") ) == 0)
       
   128         {
       
   129 
       
   130 		    lex.Inc();
       
   131 		    lex.Val (iContrast);
       
   132 
       
   133 	        //	Check parameter
       
   134 	        if ( iContrast < -100)
       
   135 	        {
       
   136 		        iContrast = -100;
       
   137 	        }
       
   138 	        else if ( iContrast > 100)
       
   139 	        {
       
   140 		        iContrast = 100;
       
   141 	        }
       
   142             ComputeContrastStretchL();
       
   143 		}
       
   144     }
       
   145     return 0;
       
   146 }
       
   147 
       
   148 const char* CFilterContrast::Type()
       
   149 	{
       
   150 	return "contrast";
       
   151 	}
       
   152 
       
   153 void CFilterContrast::ComputeContrastStretchL()
       
   154 	{
       
   155         //  Compute luminance histogram, if not computed
       
   156 	    if ( iContrast >= 0 )
       
   157 	    {
       
   158 		    TInt val_low = (iContrast * 127) / 100;
       
   159 		    TInt val_high = 255 - val_low;
       
   160 		    TInt range = val_high - val_low + 1;
       
   161 
       
   162 		    TInt i = 0;
       
   163 		    for ( ; i <= val_low; i++)
       
   164 		    {
       
   165 			    iLUT[i] = 0;
       
   166 		    }
       
   167 		    for ( ; i < val_high; ++i)
       
   168 		    {
       
   169 			    iLUT[i] = (TUint8)(((i - val_low) * 255) / range);
       
   170 		    }
       
   171 		    for ( ; i <= 255; i++)
       
   172 		    {
       
   173 			    iLUT[i] = 255;
       
   174 		    }
       
   175 	    }
       
   176 	    else
       
   177 	    {
       
   178 
       
   179 		    TInt val_low = (-iContrast * 127) / 100;
       
   180 		    TInt val_high = 255 - val_low;
       
   181 		    TInt range = val_high - val_low + 1;
       
   182 
       
   183 		    for ( TInt i = 0; i <= 255; i++ )
       
   184 		    {
       
   185 			    iLUT[i] = (TUint8)(val_low + (i * range) / 255);
       
   186 		    }
       
   187 	    }
       
   188 	}
       
   189 
       
   190 #if !defined(EKA2)
       
   191 GLDEF_C TInt E32Dll( TDllReason )
       
   192     {
       
   193     return KErrNone;
       
   194     }	
       
   195 #endif