|
1 | 1 | (******************************************************************************)
|
2 | 2 | (* uGraphiks.pas ??.??.???? *)
|
3 | 3 | (* *)
|
4 |
| -(* Version : 0.08 *) |
| 4 | +(* Version : 0.09 *) |
5 | 5 | (* *)
|
6 | 6 | (* Author : Uwe Schächterle (Corpsman) *)
|
7 | 7 | (* *)
|
|
31 | 31 | (* 0.06 - added Rotate*Degrees *)
|
32 | 32 | (* 0.07 - added LeftToRight *)
|
33 | 33 | (* 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 *) |
38 | 39 | (* *)
|
39 | 40 | (******************************************************************************)
|
40 | 41 |
|
|
198 | 199 | // Tauscht die Farbe SourceColor mit der Farbe DestColor aus
|
199 | 200 | Procedure SwapColor(Const Bitmap: TBitmap; SourceColor, DestColor: TColor);
|
200 | 201 |
|
| 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 | + |
201 | 209 | // Zeichnet ein Graphic im Biliniear, oder Nearest Neighbour verfahren. ( Unter Windows gibts das Bilinar nicht, unter Linux das NearesNeighbour *g* )
|
202 | 210 | Procedure Stretchdraw(Const Dest: TBitmap; Destrect: Trect; Const Source: Tbitmap; Mode: TInterpolationMode = imNearestNeighbour (* GTK Default wäre imBilinear *)); overload;
|
203 | 211 | Procedure Stretchdraw(Const Dest: TCanvas; Destrect: Trect; Const Source: Tbitmap; Mode: TInterpolationMode = imNearestNeighbour (* GTK Default wäre imBilinear *)); overload;
|
|
215 | 223 |
|
216 | 224 | Implementation
|
217 | 225 |
|
218 |
| -Uses sysutils; // Exception |
| 226 | +Uses sysutils, ufifo; // Exception |
219 | 227 |
|
220 | 228 | Function StringToInterpolationMode(Value: String): TInterpolationMode;
|
221 | 229 | Begin
|
|
1495 | 1503 | TempIntfImg.free;
|
1496 | 1504 | End;
|
1497 | 1505 |
|
| 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 | + |
1498 | 1561 | Procedure Stretchdraw(Const Dest: TBitmap; Destrect: Trect;
|
1499 | 1562 | Const Source: Tbitmap; Mode: TInterpolationMode);
|
1500 | 1563 | Var
|
|
0 commit comments