unit filterCopy;
(* ***** 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
* Site :
* http://filters.sourceforge.net/
*
* ***** END LICENSE BLOCK ***** *)
{
edurand (filters@edurand.com)
}
interface
uses
filter, fparameters, image, SysUtils;
type
TFilterCopy = class(TFilter)
public
constructor Create; override;
destructor Destroy; override;
procedure Run(); override;
private
parameterImageIn : TParameterImage;
parameterOutputColor : TParameterString;
outputparameterImageOut : TParameterImage;
outImage : PBitmap32;
imgIn : PBitmap32 ;
procedure _run();
procedure deleteImages;
end;
implementation
uses
imageIO, Math;
constructor TFilterCopy.Create;
begin
inherited;
parameterImageIn := addParameterImage( 'inImage', 'image to copy' );
parameterOutputColor := addParameterString( 'outputColor', 'UNCHANGED/INTENSITY','UNCHANGED' );
outputparameterImageOut := addOutputParameterImage( 'outImage', 'outImage' );
end;
destructor TFilterCopy.Destroy;
begin
deleteImages;
inherited;
end;
procedure TFilterCopy.deleteImages;
begin
image.freeImage(outImage);
end;
procedure TFilterCopy.Run();
begin
imgIn := parameterImageIn.Image ;
if (imgIn<>nil) then begin
_run();
end;
end;
procedure TFilterCopy._run();
var
pSrc, PDest : PColor32Array;
imgOutWidth, imageOutHeight : Integer;
x, y, maxX, maxY : Integer ;
imgOut : PBitmap32 ;
c : TColor32;
mode : Byte;
tIntensity : Byte;
begin
mode := 0;
if parameterOutputColor.Value='INTENSITY' then mode :=1;
deleteImages;
imgOutWidth := scanWidth(imgIn);
imageOutHeight := scanHeight(imgIn);
maxX := imgOutWidth-1;
maxY := imageOutHeight-1;
outImage := createImage(imgOutWidth,imageOutHeight);
imgOut := outImage;
eraseImage(imgOut);
for y:=0 to maxY do begin
pDest := imgOut.Bits;
Inc(pDest,y*imgOutWidth);
pSrc := scanLine(imgIn, y) ;
for x:=0 to maxX do begin
case mode of
0 : begin
pDest^[0] := pSrc^[0];
end;
1 : begin
c := pSrc^[0];
tIntensity :=
(
(Byte(c shr 16) * 61) +
(Byte(c shr 8) * 174) +
(Byte(c) * 21)
) shr 8;
pDest^[0] := TColor32(0) shl 24 + TColor32(tIntensity) shl 16 + TColor32(tIntensity) shl 8 + TColor32(tIntensity);
end;
end;
inc(pDest) ;
inc(pSrc) ;
end ;
end ;
setOutputParameterImage( 'outImage', outImage );
end;
end.