unit filterImageCreator;
(* ***** BEGIN LICENSE BLOCK *****
* Copyright (C) 2004 Durand Emmanuel
* Copyright (C) 2004 Burgel Eric
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact :
* filters@edurand.com
* filters@burgel.com
*
* ***** END LICENSE BLOCK ***** *)
{
edurand (filters@edurand.com)
}
interface
uses
filter, fparameters, image;
type
TFilterImageCreator = class(TFilter)
public
constructor Create; override;
destructor Destroy; override;
procedure Run(); override;
private
parameterCommand : TParameterString;
outputParameterImageOut : TParameterImage;
imageOut : PBitmap32;
procedure destroyImageOut();
end;
implementation
uses
imageIO, classes, StrUtils, SysUtils, fmask;
constructor TFilterImageCreator.Create;
begin
inherited;
parameterCommand := addParameterString( 'command',
'a command in the following format : function(parameter1,parameter..). ' + #13#10 +
'Example : ' + #13#10 +
'createImageTest(512,512) ' + #13#10 +
'createMask( 100, 100, ''maskDisk'' ) ' + #13#10
, 'createImageTest(512,512)' );
outputParameterImageOut := addOutputParameterImage( 'outImage', 'created image' );
end;
destructor TFilterImageCreator.Destroy;
begin
destroyImageOut();
inherited;
end;
procedure TFilterImageCreator.destroyImageOut();
begin
image.freeImage( imageOut );
end;
procedure TFilterImageCreator.Run();
var
command, fct, parameters : String;
parameterlist : TStringList;
p1, p2 : Integer;
maskType : TMaskType;
function paramInt( index : Integer ) : Integer;
begin
Result := StrToInt( Trim( parameterlist.Strings[index-1] ) );
end;
function paramStr( index : Integer ) : String;
var
str : String;
begin
str := Trim( parameterlist.Strings[index-1] );
str := MidStr( str, 2, Length(str)-2 );
Result := str;
end;
begin
destroyImageOut();
command := parameterCommand.Value;
p1 := Pos( '(', command );
p2 := Pos( ')', command );
if (p1>0) and (p2>0) and (p2>p1) then begin
fct := LeftStr( command, p1-1 );
parameters := MidStr( command, p1+1, p2-p1-1 );
parameterlist := TStringList.Create;
try
ExtractStrings( [','], [], PChar(parameters), parameterlist );
if fct='createImageTest' then begin
imageOut := image.createImageTest( paramInt(1) , paramInt(2) );
end else
if fct='createMask' then begin
maskType := maskCustom;
if paramStr(3)='maskFilled' then maskType:=maskFilled
else if paramStr(3)='maskDisk' then maskType:=maskDisk
else if paramStr(3)='maskCross' then maskType:=maskCross;
imageOut := fmask.createMask( paramInt(1) , paramInt(2), maskType );
end;
finally
parameterlist.Free;
end;
end;
if imageOut=nil then begin
imageOut := image.createImage( 0, 0 );
end;
setOutputParameterImage( 'outImage', imageOut );
end;
end.