unit filterOnOffCell;
(* ***** 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, filterConvolution, image;
type
TFilterOnOffCell = class(TFilter)
public
constructor Create; override;
destructor Destroy; override;
procedure Run(); override;
procedure setParameterImage( const aName: String; const aImage: PBitmap32);
private
parameterImageIn, parameterImageOutON, parameterImageOutOFF : TParameterImage;
filterConvON, filterConvOFF : TFilterConvolution ;
convImageON, convImageOFF : PBitmap32 ;
end;
implementation
uses
imageIO, Math;
constructor TFilterOnOffCell.Create;
begin
inherited;
parameterImageIn:=addParameterImage('inImage','explication...');
parameterImageOutON:=addParameterImage('outImageON','explication...');
parameterImageOutOFF:=addParameterImage('outImageOFF','explication...');
filterConvON := TFilterConvolution.Create ;
convImageON := image.createImage(3, 3) ;
setWeight(convImageON, 0, 0, -16) ;
setWeight(convImageON, 1, 0, -16) ;
setWeight(convImageON, 2, 0, -16) ;
setWeight(convImageON, 0, 1, -16) ;
setWeight(convImageON, 1, 1, 127) ;
setWeight(convImageON, 2, 1, -16) ;
setWeight(convImageON, 0, 2, -16) ;
setWeight(convImageON, 1, 2, -16) ;
setWeight(convImageON, 2, 2, -16) ;
filterConvON.setParameterImage('imageConv',convImageON);
filterConvON.setParameterInteger('z', $100);
filterConvOFF := TFilterConvolution.Create ;
convImageOFF := image.createImage(3, 3) ;
setWeight(convImageOFF, 0, 0, 16) ;
setWeight(convImageOFF, 1, 0, 16) ;
setWeight(convImageOFF, 2, 0, 16) ;
setWeight(convImageOFF, 0, 1, 16) ;
setWeight(convImageOFF, 1, 1, -127) ;
setWeight(convImageOFF, 2, 1, 16) ;
setWeight(convImageOFF, 0, 2, 16) ;
setWeight(convImageOFF, 1, 2, 16) ;
setWeight(convImageOFF, 2, 2, 16) ;
filterConvOFF.setParameterImage('imageConv',convImageOFF);
filterConvOFF.setParameterInteger('z', $100);
end;
destructor TFilterOnOffCell.Destroy;
begin
filterConvON.Free;
filterConvOFF.Free;
image.freeImage(convImageON);
image.freeImage(convImageOFF);
end;
procedure TFilterOnOffCell.setParameterImage( const aName: String; const aImage: PBitmap32);
begin
inherited;
end;
procedure TFilterOnOffCell.Run();
var
imageIn : PBitmap32;
const Half : double = 0.5 ;
begin
imageIn:=parameterImageIn.Image;
if imageIn<>nil then begin
// ON
filterConvON.setParameterImage('inImage',imageIn);
filterConvON.setParameterImage('outImage',parameterImageOutON.Image);
filterConvON.setParameterString('convType','user');
filterConvON.Run;
// OFF
filterConvOFF.setParameterImage('inImage',imageIn);
filterConvOFF.setParameterImage('outImage',parameterImageOutOFF.Image);
filterConvOFF.setParameterString('convType','user');
filterConvOFF.Run;
end;
end;
end.