unit fmask;
(* ***** 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)
eburgel (filters@burgel.com)
}
interface
uses
image, windows;
type
TMaskType = ( maskCustom, maskFilled, maskDisk, maskCross );
function createMask( const aWidth,aHeight:Integer; const aType : TMaskType ) : PBitmap32;
implementation
uses
Math;
function createMask( const aWidth,aHeight:Integer; const aType : TMaskType ) : PBitmap32;
var
mask : PBitmap32;
r : TRect;
center : TFPoint;
radius : Single;
w_3, h_3 : Integer;
w_2d3, h_2d3 : Integer;
row, col : Integer;
t : TMaskType;
begin
t := aType;
if (t=maskDisk) and (aWidth=3) and (aHeight=3) then t:=maskCross; // a special case
mask := image.createImage( aWidth, aHeight );
center.x := aWidth / 2 -0.5;
center.y := aHeight / 2 -0.5;
radius := Min(aWidth,aHeight) / 2;
case t of
maskCustom :
begin
end;
maskFilled :
begin
r.Left := 0;
r.Top := 0;
r.Right := aWidth-1;
r.Bottom := aHeight-1;
image.drawRectFilled( mask, r, clWhite32);
end;
maskDisk :
begin
image.drawDisk( mask, center.x, center.y, radius, clWhite32 );
end;
maskCross :
begin
w_3 := aWidth div 3;
h_3 := aHeight div 3;
w_2d3 := aWidth-1 - w_3;
h_2d3 := aHeight-1 - h_3;
for row:=0 to aHeight-1 do begin
for col:=0 to aWidth-1 do begin
if not ((row=0) and (col=aWidth-1)) and
not ((row=aHeight-1) and (col=0)) and
not ((row=aHeight-1) and (col=aWidth-1)) then begin
if ((row>=h_3) and (row<=h_2d3)) or
((col>=w_3) and (col<=w_2d3)) then begin
image.setPixel( mask, col, row, clWhite32 );
end;
end;
end;
end;
end;
end;
Result := mask;
end;
end.