unit filterIntegration;
(* ***** 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)
eburgel (filters@burgel.com)
}
interface
uses
filter, fparameters, image;
type
TFilterIntegration = class(TFilter)
public
constructor Create; override;
procedure Run(); override;
private
parameterImageIn, parameterImageOut : TParameterImage;
parameterScale : TParameterSingle ;
parameterAmort : TParameterSingle ;
parameterOffset : TParameterSingle ;
imgIn, imgOut : PBitmap32 ;
procedure _run();
end;
implementation
uses
imageIO;
constructor TFilterIntegration.Create;
begin
inherited;
parameterImageIn:=addParameterImage('inImage', 'input image to integration');
parameterImageOut:=addParameterImage('outImage', 'result image of integration');
parameterScale := addParameterSingle('scale', 'scale', -10, 10, 0.5);
parameterAmort := addParameterSingle('amortissement', 'amortissement', 0, 1, 1);
parameterOffset := addParameterSingle('offset', 'offset', -200, 200, 64) ;
end;
procedure TFilterIntegration.Run();
begin
imgIn := parameterImageIn.Image ;
imgOut := parameterImageOut.Image ;
if (imgIn<>nil) and (imgOut<>nil) then begin
_run();
end;
end;
procedure TFilterIntegration._run();
var
pSrc, PDest : PColor32Array;
x, y, maxX, maxY : Integer ;
scale, Amort : Single ;
Sum : Single ;
Level : Single ;
offset : Single ;
begin
// Parameters
scale := parameterScale.Value ;
Amort := parameterAmort.Value ;
offset := parameterOffset.Value ;
maxX := scanWidth(imgIn)-1 ;
maxY := scanHeight(imgIn)-1 ;
eraseImage(imgOut);
for y:=0 to maxY do begin
pSrc := scanLine(imgIn, y) ;
pDest := scanLine(imgOut, y) ;
sum := 0 ;
for x:=0 to maxX do begin
Level := Intensity(pSrc^[0]) ;
sum := (sum + (Level-offset)*scale)* Amort ;
pDest^[0] := Gray32(trunc(sum / 10)+127);
inc(pDest) ;
inc(pSrc) ;
end ;
end ;
end;
end.