imageeditorengine/src/CFilterStack.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 "CFilterStack.h"
       
    21 #include <f32file.h>
       
    22 
       
    23 //  Debug logger definitions
       
    24 #include "imageeditordebugutils.h"
       
    25 _LIT(KMIAWrapperLogFile,"EngineWrapper.log");
       
    26 
       
    27 CFilterStack* CFilterStack::NewL()
       
    28 	{
       
    29 	CFilterStack* self = new( ELeave )CFilterStack();
       
    30 	CleanupStack::PushL( self );
       
    31 	self->ConstructL();
       
    32 	CleanupStack::Pop( self );
       
    33 	return self;
       
    34 	}
       
    35 
       
    36 
       
    37 
       
    38 CFilterStack::~CFilterStack()
       
    39 	{
       
    40 	iStack.ResetAndDestroy();
       
    41 	}
       
    42 
       
    43 
       
    44 
       
    45 CFilterStack::CFilterStack()
       
    46 	{
       
    47 
       
    48 	}
       
    49 
       
    50 
       
    51 
       
    52 void CFilterStack::ConstructL()
       
    53 	{
       
    54 	/*
       
    55 	TFileName fileName( _L("c:\\filterscript.txt") );
       
    56 
       
    57 	RFs fs;
       
    58 	User::LeaveIfError( fs.Connect() );
       
    59 	CleanupClosePushL( fs );
       
    60 
       
    61 	RFile file;
       
    62 	User::LeaveIfError( file.Open( fs, fileName, EFileRead ) );
       
    63 	CleanupClosePushL( file );
       
    64 
       
    65 	TInt l = 0;
       
    66 	file.Size( l );
       
    67 	TUint8* t = new TUint8[ l ];
       
    68 	CleanupStack::PushL( t );
       
    69 	TPtr8 txt8o( t, l );
       
    70 	User::LeaveIfError( file.Read( txt8o ) );
       
    71 	TPtrC8 txt8( txt8o );
       
    72 	TInt strl = txt8.Find( _L8(" ") );
       
    73 
       
    74 	while( strl > 0 )
       
    75 		{
       
    76 		TPtrC8 filterName( txt8.Ptr(), strl );
       
    77 		txt8.Set( txt8.Mid( strl+1 ) );
       
    78 		
       
    79 		strl = txt8.Find( _L8("\r") );
       
    80 		TPtrC8 filterParam( txt8.Ptr(), strl );
       
    81 		txt8.Set( txt8.Mid( strl+1 ) );
       
    82 
       
    83 		if( txt8.Length() > 0 )
       
    84 			{
       
    85 			if( txt8[ 0 ] == '\n' )
       
    86 				{
       
    87 				txt8.Set( txt8.Mid( 1 ) );
       
    88 				}
       
    89 			}
       
    90 
       
    91 		strl = txt8.Find( _L8(" ") );
       
    92 
       
    93 		TFilter* f = new( ELeave )TFilter;
       
    94 		TInt error = KErrNone;
       
    95 
       
    96 		if( filterName.Compare( _L8("jpegsource") ) == 0 )
       
    97 			{
       
    98 			error = f->iLibrary.Load( _L("FilterJpegSource.dll" ) );
       
    99 			}
       
   100 		else if( filterName.Compare( _L8("jpegtarget") ) == 0 )
       
   101 			{
       
   102 			error = f->iLibrary.Load( _L("FilterJpegTarget.dll" ) );
       
   103 			}
       
   104 		else if( filterName.Compare( _L8("negate") ) == 0 )
       
   105 			{
       
   106 			error = f->iLibrary.Load( _L("FilterNegate.dll" ) );
       
   107 			}
       
   108 		else if( filterName.Compare( _L8("buffer") ) == 0 )
       
   109 			{
       
   110 			error = f->iLibrary.Load( _L("FilterBuffer.dll" ) );
       
   111 			}
       
   112 		
       
   113 		User::LeaveIfError( error );
       
   114 
       
   115 		MImageFilter*& filter = f->iFilter;
       
   116 		filter = (MImageFilter*)(f->iLibrary.Lookup( 1 )());
       
   117 		
       
   118 		if( filter == NULL )
       
   119 			{
       
   120 			delete f;
       
   121 			User::Panic( _L("Could not load filter"), 0 );
       
   122 			}
       
   123 		
       
   124 		f->iFilter = filter;
       
   125 		iStack.Append( f );
       
   126 		InitStack();
       
   127 		TBuf< 100 > cmd16;
       
   128 		cmd16.Copy( filterParam );
       
   129 		filter->CmdL( cmd16 );
       
   130 		}
       
   131 	
       
   132 	
       
   133 	CleanupStack::PopAndDestroy( 3 ); // t, file, fs
       
   134 	*/
       
   135 	}
       
   136 
       
   137 
       
   138 
       
   139 void CFilterStack::InitStack()
       
   140 	{
       
   141 	TInt c = iStack.Count();
       
   142 	TInt i;
       
   143 	for( i=0; i<c; i++ )
       
   144 		{
       
   145 		TInt childn = i-1;
       
   146 		TInt parentn = i+1;
       
   147 		if( childn >= 0 )
       
   148 			{
       
   149 			iStack[ i ]->iFilter->SetChild( iStack[ childn ]->iFilter );
       
   150 			}
       
   151 		if( parentn < c )
       
   152 			{
       
   153 			iStack[ i ]->iFilter->SetParent( iStack[ parentn ]->iFilter );
       
   154 			}
       
   155 		}
       
   156 	}
       
   157 
       
   158 
       
   159 
       
   160 MImageFilter* CFilterStack::Filter( TInt aPosition )
       
   161 	{
       
   162 	return iStack[ aPosition ]->iFilter;
       
   163 	}
       
   164 
       
   165 
       
   166 
       
   167 void CFilterStack::AddFilterL( const TDesC& aName )
       
   168 	{
       
   169 	AddFilterL( aName, iStack.Count() );
       
   170 	}
       
   171 
       
   172 
       
   173 
       
   174 void CFilterStack::AddFilterL( const TDesC& aName, TInt aPosition )
       
   175 	{
       
   176 	LOG ( KMIAWrapperLogFile, "CFilterStack::AddFilterL" );
       
   177 
       
   178 	TFilter* f = new( ELeave )TFilter;
       
   179 	CleanupStack::PushL(f);
       
   180 	
       
   181 	LOG ( KMIAWrapperLogFile, "CFilterStack::AddFilterL: Loading" );
       
   182 	User::LeaveIfError( f->iLibrary.Load( aName ) );
       
   183 	MImageFilter*& filter = f->iFilter;
       
   184 
       
   185 	LOG ( KMIAWrapperLogFile, "CFilterStack::AddFilterL: Lookup" );
       
   186 	filter = (MImageFilter*)(f->iLibrary.Lookup( 1 )());
       
   187 	if( filter == NULL )
       
   188 		{
       
   189 		LOG ( KMIAWrapperLogFile, "CFilterStack::AddFilterL: Filter null" );
       
   190 		f->iLibrary.Close();
       
   191 		User::Leave( KErrNoMemory );
       
   192 		}
       
   193 	f->iFilter = filter;
       
   194 
       
   195 	if( iStack.Count() == aPosition )
       
   196 		{
       
   197 		iStack.Append( f );
       
   198 		}
       
   199 	else
       
   200 		{
       
   201 		/*
       
   202 		iStack.Append( 0 );
       
   203 
       
   204 		TInt s = aPosition;
       
   205 		TInt e = iStack.Count()-2;
       
   206 		TInt i;
       
   207 		for( i=s; i<e; i++ )
       
   208 			{
       
   209 			iStack[ i+1 ] = iStack[ i ];
       
   210 			}
       
   211 			*/
       
   212 		iStack.Insert( f, aPosition );
       
   213 		}
       
   214 	CleanupStack::Pop();
       
   215 	LOG ( KMIAWrapperLogFile, "CFilterStack::AddFilterL: Initializing stack" );
       
   216 		
       
   217 	InitStack();
       
   218 	}
       
   219 
       
   220 void CFilterStack::AddFilterL( const TFilter * aFilter )
       
   221 {
       
   222 	AddFilterL( aFilter, iStack.Count() );
       
   223 }
       
   224 
       
   225 void CFilterStack::AddFilterL( const TFilter * aFilter, const TInt aPosition )
       
   226 {
       
   227 	LOG ( KMIAWrapperLogFile, "CFilterStack::AddFilterL" );
       
   228 	if ( iStack.Count() == aPosition )
       
   229 	{
       
   230 		iStack.Append( aFilter );
       
   231 	}
       
   232 	else
       
   233 	{
       
   234 		iStack.Insert( aFilter, aPosition );
       
   235 	}
       
   236 
       
   237 	LOG ( KMIAWrapperLogFile, "CFilterStack::AddFilterL: Initializing stack" );
       
   238 		
       
   239 	InitStack();
       
   240 }
       
   241 
       
   242 
       
   243 void CFilterStack::RemoveFilter( TInt aPosition )
       
   244 	{
       
   245 	delete iStack[ aPosition ];
       
   246 	iStack.Remove( aPosition );
       
   247 	InitStack();
       
   248 	}
       
   249 
       
   250 void CFilterStack::RemoveFilter ( TInt aPosition, TFilter *& aFilter )
       
   251 {
       
   252 	aFilter = iStack[aPosition];
       
   253 	iStack.Remove( aPosition );
       
   254 	InitStack();
       
   255 }
       
   256 
       
   257 TInt CFilterStack::FunctionL( TInt aPosition, const TDesC& aCmd )
       
   258 	{
       
   259 	return iStack[ aPosition ]->iFilter->CmdL( aCmd );
       
   260 	}
       
   261 
       
   262 
       
   263 
       
   264 
       
   265 TInt CFilterStack::NumFilters()
       
   266 	{
       
   267 	return iStack.Count();
       
   268 	}