Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- procedure TMufasaBitmap.FloodFillEx(const StartPT: TPoint; const SearchCol, ReplaceCol: TColor; 8Way: Boolean);
- var
- Stack : TPointArray;
- SIndex : Integer;
- CurrX,CurrY : integer;
- Search,Replace : LongWord;
- procedure AddToStack(x,y : integer);inline;
- begin
- if LongWord(FData[y * w + x]) = Search then
- begin
- LongWord(FData[y * w + x]) := Replace;
- Stack[SIndex].x := x;
- Stack[SIndex].y := y;
- inc(SIndex);
- end;
- end;
- begin
- ValidatePoint(StartPT.x,StartPT.y);
- Search := LongWord(RGBToBGR(SearchCol));
- Replace := LongWord(RGBToBGR(ReplaceCol));
- SetAlphaValue(0);
- if LongWord(FData[StartPT.y * w + StartPT.x]) <> Search then //Only add items to the stack that are the searchcol.
- Exit;
- SetLength(Stack,w * h);
- SIndex := 0;
- AddToStack(StartPT.x,StartPT.y);
- SIndex := 0;
- case 8Way of
- True:
- while (SIndex >= 0) do
- begin;
- CurrX := Stack[SIndex].x;
- Curry := Stack[SIndex].y;
- if (CurrX > 0) and (CurrY > 0) then AddToStack(CurrX - 1, CurrY - 1);
- if (CurrX > 0) then AddToStack(CurrX - 1, CurrY);
- if (CurrX > 0) and (CurrY + 1 < h) then AddToStack(CurrX - 1, CurrY + 1);
- if (CurrY + 1 < h) then AddToStack(CurrX , CurrY + 1);
- if (CurrX + 1 < w) and (CurrY + 1 < h) then AddToStack(CurrX + 1, CurrY + 1);
- if (CurrX + 1 < w) then AddToStack(CurrX + 1, CurrY );
- if (CurrX + 1 < w) and (CurrY > 0) then AddToStack(CurrX + 1, CurrY - 1);
- if (CurrY > 0) then AddToStack(CurrX , CurrY - 1);
- Dec(SIndex);
- end;
- False:
- while (SIndex >= 0) do
- begin;
- CurrX := Stack[SIndex].x;
- Curry := Stack[SIndex].y;
- if (CurrX > 0) then AddToStack(CurrX - 1, CurrY);
- if (CurrY + 1 < h) then AddToStack(CurrX , CurrY + 1);
- if (CurrX + 1 < w) then AddToStack(CurrX + 1, CurrY );
- if (CurrY > 0) then AddToStack(CurrX , CurrY - 1);
- Dec(SIndex);
- end;
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment