imageeditorengine/filters/FilterCrop/Src/CFilterCrop.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 "CFilterCrop.h"
       
    21 
       
    22 EXPORT_C TInt CFilterCrop::Create()
       
    23 	{
       
    24 	CFilterCrop* ptr = NULL;
       
    25 	TRAPD( error, ptr = NewL(); );
       
    26 	if( error != KErrNone )
       
    27 		{
       
    28 		ptr = NULL;
       
    29 		}
       
    30 	return (TInt)((MImageFilter*)ptr);
       
    31 	}
       
    32 
       
    33 
       
    34 
       
    35 CFilterCrop* CFilterCrop::NewL()
       
    36 	{
       
    37 	CFilterCrop* self = new( ELeave )CFilterCrop();
       
    38 	CleanupStack::PushL( self );
       
    39 	self->ConstructL();
       
    40 	CleanupStack::Pop( self );
       
    41 	return self;
       
    42 	}
       
    43 
       
    44 
       
    45 
       
    46 CFilterCrop::~CFilterCrop()
       
    47 	{
       
    48 	}
       
    49 
       
    50 
       
    51 
       
    52 CFilterCrop::CFilterCrop()
       
    53 	{
       
    54 
       
    55 	}
       
    56 
       
    57 
       
    58 
       
    59 void CFilterCrop::ConstructL()
       
    60 	{
       
    61 
       
    62 	}
       
    63 
       
    64 
       
    65 
       
    66 TRect CFilterCrop::Rect()
       
    67 	{
       
    68 	
       
    69 	if ( iRect == TRect(0,0,0,0) )
       
    70 		{
       
    71 		return iChild->Rect();
       
    72 		}
       
    73 	else
       
    74 		{
       
    75 	    TReal relscale = iChild->Scale();
       
    76 		TRect rect;
       
    77 	    rect.iTl.iX = (TInt)(iRect.iTl.iX * relscale + 0.5);
       
    78 	    rect.iTl.iY = (TInt)(iRect.iTl.iY * relscale + 0.5);
       
    79 	    rect.iBr.iX = (TInt)(iRect.iBr.iX * relscale + 0.5);
       
    80 	    rect.iBr.iY = (TInt)(iRect.iBr.iY * relscale + 0.5);
       
    81 		rect.Intersection( iChild->Rect() );
       
    82 		return rect;
       
    83 		}
       
    84 	}
       
    85 
       
    86 TReal CFilterCrop::Scale()
       
    87 	{
       
    88 	return iChild->Scale();
       
    89 	}
       
    90 
       
    91 TSize CFilterCrop::ViewPortSize()
       
    92 	{
       
    93 	if (iRect == TRect(0,0,0,0))
       
    94 		{
       
    95 		return iChild->ViewPortSize();	
       
    96 		}
       
    97 	else
       
    98 		{
       
    99 		return iRect.Size();	
       
   100 		}
       
   101 	}
       
   102 
       
   103 TBlock * CFilterCrop::GetBlockL ( const TRect & aRect )
       
   104 	{
       
   105     return iChild->GetBlockL (aRect);
       
   106 	}
       
   107 
       
   108 
       
   109 void CFilterCrop::SetParent( MImageFilter* aParent )
       
   110 	{
       
   111 	iParent = aParent;
       
   112 	}
       
   113 
       
   114 
       
   115 
       
   116 
       
   117 void CFilterCrop::SetChild( MImageFilter* aChild )
       
   118 	{
       
   119 	iChild = aChild;
       
   120 	}
       
   121 
       
   122 
       
   123 
       
   124 TInt CFilterCrop::CmdL( const TDesC16& aCmd )
       
   125 	{
       
   126 	TLex lex( aCmd );
       
   127 
       
   128 	while( ! lex.Eos() )
       
   129 		{
       
   130 		TPtrC token = lex.NextToken();
       
   131 		if( token.Compare( _L("x1") ) == 0 )
       
   132 			{
       
   133             TReal relscale = iChild->Scale();
       
   134             TInt param = 0;
       
   135 			lex.Inc ();
       
   136 			lex.Val (param);
       
   137             iRect.iTl.iX = (TInt)((param / relscale) + 0.5);
       
   138 			}
       
   139 		else if( token.Compare( _L("y1") ) == 0 )
       
   140 			{
       
   141             TReal relscale = iChild->Scale();
       
   142             TInt param = 0;
       
   143 			lex.Inc ();
       
   144 			lex.Val (param);
       
   145             iRect.iTl.iY = (TInt)((param / relscale) + 0.5);
       
   146 			}
       
   147 		else if( token.Compare( _L("x2") ) == 0 )
       
   148 			{
       
   149             TReal relscale = iChild->Scale();
       
   150             TInt param = 0;
       
   151 			lex.Inc ();
       
   152 			lex.Val (param);
       
   153             iRect.iBr.iX = (TInt)((param / relscale) + 0.5);
       
   154 			}
       
   155 		else if( token.Compare( _L("y2") ) == 0 )
       
   156 			{
       
   157             TReal relscale = iChild->Scale();
       
   158             TInt param = 0;
       
   159 			lex.Inc ();
       
   160 			lex.Val (param);
       
   161             iRect.iBr.iY = (TInt)((param / relscale) + 0.5);
       
   162 			}
       
   163 		}
       
   164 	return 0;
       
   165 	}
       
   166 
       
   167 
       
   168 
       
   169 const char* CFilterCrop::Type()
       
   170 	{
       
   171 	return "crop";
       
   172 	}
       
   173 	
       
   174 #if !defined(EKA2)
       
   175 GLDEF_C TInt E32Dll( TDllReason )
       
   176     {
       
   177     return KErrNone;
       
   178     }	
       
   179 #endif