Skip to content

Commit ea431a0

Browse files
ADD: Swapcolor
1 parent cb552e8 commit ea431a0

File tree

1 file changed

+69
-6
lines changed

1 file changed

+69
-6
lines changed

graphics/ugraphics.pas

Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(******************************************************************************)
22
(* uGraphiks.pas ??.??.???? *)
33
(* *)
4-
(* Version : 0.08 *)
4+
(* Version : 0.09 *)
55
(* *)
66
(* Author : Uwe Schächterle (Corpsman) *)
77
(* *)
@@ -31,10 +31,11 @@
3131
(* 0.06 - added Rotate*Degrees *)
3232
(* 0.07 - added LeftToRight *)
3333
(* 0.08 - added MulImage *)
34-
(* added aberation *)
35-
(* added vignetting *)
36-
(* added foldImage *)
37-
(* add Wrap Modes *)
34+
(* added aberation *)
35+
(* added vignetting *)
36+
(* added foldImage *)
37+
(* add Wrap Modes *)
38+
(* 0.09 - added floodfill *)
3839
(* *)
3940
(******************************************************************************)
4041

@@ -198,6 +199,13 @@
198199
// Tauscht die Farbe SourceColor mit der Farbe DestColor aus
199200
Procedure SwapColor(Const Bitmap: TBitmap; SourceColor, DestColor: TColor);
200201

202+
(*
203+
* Füllt beginnend von StartX, StartY via Floodfill alles auf,
204+
*
205+
* Wenn AllowDiagonalWalk = True, dann wird zusätzlich auch über die Diagonalen gelaufen
206+
*)
207+
Procedure FloodFill(Const Bitmap: TBitmap; StartX, StartY: Integer; DestColor: TColor; AllowDiagonalWalk: Boolean = false);
208+
201209
// Zeichnet ein Graphic im Biliniear, oder Nearest Neighbour verfahren. ( Unter Windows gibts das Bilinar nicht, unter Linux das NearesNeighbour *g* )
202210
Procedure Stretchdraw(Const Dest: TBitmap; Destrect: Trect; Const Source: Tbitmap; Mode: TInterpolationMode = imNearestNeighbour (* GTK Default wäre imBilinear *)); overload;
203211
Procedure Stretchdraw(Const Dest: TCanvas; Destrect: Trect; Const Source: Tbitmap; Mode: TInterpolationMode = imNearestNeighbour (* GTK Default wäre imBilinear *)); overload;
@@ -215,7 +223,7 @@
215223

216224
Implementation
217225

218-
Uses sysutils; // Exception
226+
Uses sysutils, ufifo; // Exception
219227

220228
Function StringToInterpolationMode(Value: String): TInterpolationMode;
221229
Begin
@@ -1495,6 +1503,61 @@
14951503
TempIntfImg.free;
14961504
End;
14971505

1506+
Procedure FloodFill(Const Bitmap: TBitmap; StartX, StartY: Integer;
1507+
DestColor: TColor; AllowDiagonalWalk: Boolean);
1508+
1509+
Type
1510+
TPointFifo = specialize TBufferedFifo < TPoint > ;
1511+
1512+
Var
1513+
TempIntfImg: TLazIntfImage;
1514+
ImgHandle, ImgMaskHandle: HBitmap;
1515+
SourceCol: TFPColor;
1516+
DestCol: TFPColor;
1517+
fifo: TPointFifo;
1518+
p: Tpoint;
1519+
w, h: integer;
1520+
Begin
1521+
TempIntfImg := TLazIntfImage.Create(0, 0);
1522+
TempIntfImg.LoadFromBitmap(Bitmap.Handle, Bitmap.MaskHandle);
1523+
SourceCol := TempIntfImg.Colors[StartX, StartY];
1524+
DestCol := ColorToFPColor(DestColor);
1525+
If SourceCol = DestCol Then Begin // Das würde Endlos Rekursionen geben !
1526+
TempIntfImg.free;
1527+
exit;
1528+
End;
1529+
fifo := TPointFifo.create();
1530+
fifo.push(point(StartX, StartY));
1531+
w := Bitmap.Width;
1532+
h := Bitmap.Height;
1533+
While Not fifo.isempty Do Begin
1534+
p := fifo.Pop;
1535+
// Nur So lange wir überhaupt im Bild sind
1536+
If (p.x >= 0) And (p.Y >= 0) And
1537+
(p.x < w) And (p.Y < h) Then Begin
1538+
// Es gibt noch was zu tun ;)
1539+
If (TempIntfImg.Colors[p.x, p.y] = SourceCol) Then Begin
1540+
TempIntfImg.Colors[p.x, p.y] := DestCol;
1541+
fifo.Push(point(p.x + 1, p.y));
1542+
fifo.Push(point(p.x - 1, p.y));
1543+
fifo.Push(point(p.x, p.y + 1));
1544+
fifo.Push(point(p.x, p.y - 1));
1545+
If AllowDiagonalWalk Then Begin
1546+
fifo.Push(point(p.x + 1, p.y + 1));
1547+
fifo.Push(point(p.x + 1, p.y - 1));
1548+
fifo.Push(point(p.x - 1, p.y + 1));
1549+
fifo.Push(point(p.x - 1, p.y - 1));
1550+
End;
1551+
End;
1552+
End;
1553+
End;
1554+
TempIntfImg.CreateBitmaps(ImgHandle, ImgMaskHandle, false);
1555+
Bitmap.Handle := ImgHandle;
1556+
Bitmap.MaskHandle := ImgMaskHandle;
1557+
TempIntfImg.free;
1558+
fifo.free;
1559+
End;
1560+
14981561
Procedure Stretchdraw(Const Dest: TBitmap; Destrect: Trect;
14991562
Const Source: Tbitmap; Mode: TInterpolationMode);
15001563
Var

0 commit comments

Comments
 (0)