unit filterStackProcessor;
(* ***** 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 ***** *)
{
eburgel (filters@burgel.com)
edurand (filters@edurand.com)
}
interface
uses
filter, fparameters, image;
type
TFilterStackProcessor = class(TFilter)
public
constructor Create(); override;
destructor Destroy; override;
procedure Run(); override;
private
parameterImagesIn : TParameterImages;
parameterImagesOut : TParameterImages;
parameterFilter : TParameterPointer;
inImages : ArrayOfPBitmap32 ;
outImages : ArrayOfPBitmap32;
_filter : TFilter ;
procedure destroyImageOuts();
end;
implementation
uses
imageIO ;
constructor TFilterStackProcessor.Create();
begin
inherited Create() ;
parameterImagesIn := addParameterImages('inImages', 'inImages') ;
parameterImagesOut := addOutputParameterImages('outImages', 'outImages');
parameterFilter := addParameterPointer('filter','a pointer on the filter to apply on the stack of images');
_filter := nil;
end;
destructor TFilterStackProcessor.Destroy;
begin
destroyImageOuts();
inherited;
end;
procedure TFilterStackProcessor.destroyImageOuts();
var
i : Integer;
begin
for i:=0 to Length(outImages)-1 do begin
image.freeImage(outImages[i]);
end;
SetLength(outImages,0);
end;
procedure TFilterStackProcessor.run();
Var
i : Integer ;
imageIn : PBitmap32 ;
imageOut : PBitmap32 ;
begin
inImages := parameterImagesIn.Images ;
_filter := TFilter(parameterFilter.Value);
if (inImages<>nil) then begin
destroyImageOuts();
SetLength(outImages, Length(inImages)) ;
for i := 0 to Length(inImages)-1 do Begin
imageIn := inImages[i] ;
imageOut := createImageLike(imageIn) ;
if _filter <> nil then begin
_filter.setParameterImage('inImage', imageIn);
_filter.setParameterImage('outImage', imageOut);
_filter.Run;
end else begin
image.copyImageToImage(imageIn,imageOut);
end ;
outImages[i] := imageOut;
End ;
setOutputParameterImages('outImages', outImages);
end;
end;
end.