unit filterArithmeticConstantAdd;
(* ***** 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, image;
type
TFilterArithmeticConstantAdd = class(TFilter)
public
constructor Create; override;
procedure Run(); override;
private
parameterImageIn, parameterImageOut : TParameterImage;
parameterConstant : TParameterInteger;
parameterOverflowingMode : TParameterString;
procedure saturation();
procedure wrap_around_zero();
end;
implementation
constructor TFilterArithmeticConstantAdd.Create;
begin
inherited;
parameterImageIn:=addParameterImage('inImage','explication...');
parameterImageOut:=addParameterImage('outImage','explication...');
parameterConstant:=addParameterInteger('constant','explication...',-255,255,0);
parameterOverflowingMode:=addParameterString('overflowingMode','SATURATION or WRAP_AROUND_ZERO','SATURATION');
end;
procedure TFilterArithmeticConstantAdd.Run();
begin
if (parameterImageIn.Image<>nil) and (parameterImageOut.Image<>nil) then begin
if parameterOverflowingMode.Value = 'WRAP_AROUND_ZERO' then begin
wrap_around_zero()
end else begin
saturation();
end;
end;
end;
procedure TFilterArithmeticConstantAdd.saturation();
var
pSrc, PDest : PColor32Array;
w,h :Integer;
x, max : Cardinal ;
constant : Integer;
r,g,b : Integer;
color : TColor32;
begin
constant := parameterConstant.Value ;
pSrc:=parameterImageIn.Image.Bits;
pDest:=parameterImageOut.Image.Bits;
h:=parameterImageIn.Image.Height ;
w:=parameterImageIn.Image.Width ;
max := h*w-1 ;
for x:= 0 to max do Begin
color:=pSrc^[0];
r:=RedComponent(color);
inc(r,constant);
if r>255 then r:=255
else if r<0 then r:=0;
g:=GreenComponent(color);
inc(g,constant);
if g>255 then g:=255
else if g<0 then g:=0;
b:=BlueComponent(color);
inc(b,constant);
if b>255 then b:=255
else if b<0 then b:=0;
pDest[0]:=Color32(r,g,b);
inc(pSrc) ;
inc(pDest) ;
end ;
end;
procedure TFilterArithmeticConstantAdd.wrap_around_zero();
var
pSrc, PDest : PColor32Array;
w,h :Integer;
x, max : Cardinal ;
constant : Integer;
r,g,b : Byte;
color : TColor32;
begin
constant := parameterConstant.Value ;
pSrc:=parameterImageIn.Image.Bits;
pDest:=parameterImageOut.Image.Bits;
h:=parameterImageIn.Image.Height ;
w:=parameterImageIn.Image.Width ;
max := h*w-1 ;
for x:= 0 to max do Begin
color:=pSrc^[0];
r:=RedComponent(color);
inc(r,constant);
g:=GreenComponent(color);
inc(g,constant);
b:=BlueComponent(color);
inc(b,constant);
pDest[0]:=Color32(r,g,b);
inc(pSrc) ;
inc(pDest) ;
end ;
end;
end.