unit filterInvert;
(* ***** 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
TFilterInvert = class(TFilter)
public
constructor Create; override;
procedure Run(); override;
private
parameterImageIn, parameterImageOut : TParameterImage;
imgIn, imgOut : PBitmap32 ;
procedure _run();
end;
implementation
uses
imageIO;
constructor TFilterInvert.Create;
begin
inherited;
parameterImageIn:=addParameterImage('inImage', 'input image to invert');
parameterImageOut:=addParameterImage('outImage', 'result image of invertion');
end;
procedure TFilterInvert.Run();
begin
imgIn := parameterImageIn.Image ;
imgOut := parameterImageOut.Image ;
if (imgIn<>nil) and (imgOut<>nil) then begin
_run();
end;
end;
procedure TFilterInvert._run();
var
pSrc, PDest : PColor32Array;
x, y, maxX, maxY : Integer ;
begin
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) ;
for x:=0 to maxX do begin
pDest^[0] :=
(pSrc^[0] and $FF000000) +
(not pSrc^[0] and $00FFFFFF);
inc(pDest) ;
inc(pSrc) ;
end ;
end ;
end;
end.