Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Original SCARExt-based concept developed by slacky (Jarl)
- {$loadlib pumbaa.dll}
- var
- TPA: TPointArray;
- TBA: TBoxArray;
- bmp, i, t: Integer;
- area: TBox;
- shapes: T2DPointArray;
- procedure SetupShapes;
- begin
- SetLength(shapes, 4);
- shapes[0] := TPAFromBox(IntToBox(40, 10, 80, 90));
- shapes[1] := TPAFromBox(IntToBox(20, 30, 60, 70));
- shapes[2] := pp_TPAFromCircle(Point(80, 80), 15.5);
- shapes[3] := pp_TPAFromEllipse(Point(60, 20), 15, 6);
- end;
- procedure DebugBitmap(bmp: Integer);
- var
- w, h: Integer;
- begin
- GetBitmapSize(bmp, w, h);
- DisplayDebugImgWindow(w, h);
- DrawBitmapDebugImg(bmp);
- end;
- function GetTPABoxes(TPA: TPointArray): TBoxArray;
- var
- w, h, i, l, r: Integer;
- a: TBox;
- b: T2DBoolArray;
- m, p, c: TPointArray;
- o: T2DPointArray;
- begin
- r := 0;
- l := Length(TPA);
- if (l > 0) then
- begin
- c := pp_Clone(TPA);
- a := pp_TPABounds(c);
- pp_BoxExpand(a);
- pp_BoxDimensions(a, w, h);
- SetLength(b, w, h);
- p := pp_TPAFloodFill(c, Point(a.X1, a.Y1), sd4Ways, a);
- m := pp_Merge(c, p);
- SetLength(p, 0);
- SetLength(c, 0);
- pp_TPAInvert(m);
- o := pp_TPABlob(m, sd4ways);
- SetLength(m, 0);
- l := Length(o);
- SetLength(Result, l);
- for i := 0 to (l - 1) do
- begin
- Result[i] := pp_TPABounds(o[i]);
- pp_BoxExpand(Result[i]);
- end;
- SetLength(o, 0);
- end else
- SetLength(Result, 0);
- end;
- function CreateShapes(shapes: T2DPointArray): TPointArray;
- var
- h, i: Integer;
- c: TPointArray;
- begin
- SetLength(Result, 0);
- h := High(shapes);
- for i := 0 to h do
- begin
- c := pp_Clone(shapes[i]);
- if (i > 0) then
- pp_TPAFilterPoints(Result, shapes[i]);
- pp_TPAEdge(c);
- pp_Append(Result, c);
- SetLength(c, 0);
- end;
- end;
- begin
- area := pp_TPABounds(shapes);
- SetupShapes;
- bmp := CreateBitmap((area.X2 + 150), (area.Y2 + 150));
- TPA := CreateShapes(shapes);
- DrawTPABitmap(bmp, TPA, 255);
- DebugBitmap(bmp);
- t := GetSystemTime;
- TBA := GetTPABoxes(TPA);
- WriteLn('GetTPABoxes took ' + IntToStr(GetSystemTime - t) + ' ms.');
- Wait(1000);
- for i := 0 to High(TBA) do
- DrawTPABitmap(bmp, TPAFromBox(TBA[i]), Random(16777215));
- DebugBitmap(bmp);
- FreeBitmap(bmp);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement