Advertisement
Janilabo

sc2

Dec 23rd, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 3.64 KB | None | 0 0
  1. {$loadlib pumbaa.dll}
  2.  
  3. procedure pp_TPAControlSegment(var TPA: TPointArray; kind: TControlKind; segment: TPointArray; accuracy: Extended);
  4. var
  5.   w, h, k, l, i, j, x, y, v, c, t, n: Integer;
  6.   o: TPoint;
  7.   b, s, g: TBox;
  8.   m, q: T2DBoolArray;
  9.   f, p: TPointArray;
  10.   z: TBoxArray;
  11.   a: Extended;
  12.   u: Integer;
  13. begin
  14.   t := 0;
  15.   k := High(TPA);
  16.   l := High(segment);
  17.   if ((k > -1) and (l > -1) and (accuracy > 0) and not (accuracy > 1)) then
  18.   begin
  19.     s := pp_TPABounds(segment);
  20.     b := pp_TPABounds(TPA);
  21.     w := (b.X2 - b.X1);
  22.     h := (b.Y2 - b.Y1);
  23.     n := Ceil(pp_Percentage((accuracy * 100), (l + 1)));
  24.     if (n < (l + 1)) then
  25.       u := 1;
  26.     case u of
  27.       1:
  28.       begin
  29.         g := b;
  30.         pp_BoxStretch(g, (s.X2 - s.X1), smWidth);
  31.         pp_BoxStretch(g, (s.Y2 - s.Y1), smHeight);
  32.         z := pp_BoxPositions(s, g);
  33.       end;
  34.       0: z := pp_BoxPositions(s, b);
  35.     end;
  36.     v := High(z);
  37.     if (v > -1) then
  38.     begin
  39.       p := pp_Clone(segment);
  40.       o := pp_GetOffset(Point(s.X1, s.Y1), Point(0, 0));
  41.       pp_TPAOffset(p, o);
  42.       o := pp_GetOffset(Point(z[0].X1, z[0].Y1), Point(0, 0));
  43.       pp_TBAOffset(z, o);
  44.       m := pp_Create(False, (w + 1), (h + 1));
  45.       for i := 0 to k do
  46.         m[(TPA[i].X - b.X1)][(TPA[i].Y - b.Y1)] := True;
  47.       SetLength(f, (l + 1));
  48.       q := pp_Create(False, (w + 1), (h + 1));
  49.       case u of
  50.         1:
  51.         for i := 0 to v do
  52.         begin
  53.           c := 0;
  54.           for j := 0 to l do
  55.           begin
  56.             x := (p[j].X + z[i].X1);
  57.             y := (p[j].Y + z[i].Y1);
  58.             if ((x < w) and (y < h)) then
  59.               if m[x][y] then
  60.               begin
  61.                 f[c].X := x;
  62.                 f[c].Y := y;
  63.                 c := (c + 1);
  64.               end;
  65.           end;
  66.           if not (c < n) then
  67.           begin
  68.             c := (c - 1);
  69.             for j := 0 to c do
  70.               q[f[j].X][f[j].Y] := True;
  71.           end;
  72.         end;
  73.         0:
  74.         for i := 0 to v do
  75.         begin
  76.           c := 0;
  77.           for j := 0 to l do
  78.           begin
  79.             x := (p[j].X + z[i].X1);
  80.             y := (p[j].Y + z[i].Y1);
  81.             if m[x][y] then
  82.             begin
  83.               f[c].X := x;
  84.               f[c].Y := y;
  85.               c := (c + 1);
  86.             end;
  87.           end;
  88.           if (c = n) then
  89.           begin
  90.             c := (c - 1);
  91.             for j := 0 to c do
  92.               q[f[j].X][f[j].Y] := True;
  93.           end;
  94.         end;
  95.       end;
  96.       case kind of
  97.         ckExtract:
  98.         for i := 0 to k do
  99.           if q[(TPA[i].X - b.X1)][(TPA[i].Y - b.Y1)] then
  100.           begin
  101.             TPA[t] := TPA[i];
  102.             t := (t + 1);
  103.           end;
  104.         ckFilter:
  105.         for i := 0 to k do
  106.           if not q[(TPA[i].X - b.X1)][(TPA[i].Y - b.Y1)] then
  107.           begin
  108.             TPA[t] := TPA[i];
  109.             t := (t + 1);
  110.           end;
  111.       end;
  112.     end;
  113.   end;
  114.   SetLength(TPA, t);
  115. end;
  116.  
  117. procedure DebugBitmap(bmp: Integer);
  118. var
  119.   w, h: Integer;
  120. begin
  121.   GetBitmapSize(bmp, w, h);
  122.   DisplayDebugImgWindow(w, h);
  123.   DrawBitmapDebugImg(bmp);
  124. end;
  125.  
  126. var
  127.   segment, TPA: TPointArray;
  128.   b: TBox;
  129.   o: TPoint;
  130.   bmp, w, h: Integer;
  131.  
  132. begin
  133.   segment := [Point(5, 2), Point(5, 2), Point(1, 6), Point(4, 3), Point(4, 1)];
  134.   TPA := pp_TPAFromBox(IntToBox(10, 10, 20, 20));
  135.   b := pp_TPABounds(TPA);
  136.   pp_TPADimensions(TPA, w, h);
  137.   pp_TPAControlSegment(TPA, ckExtract, segment, 1);
  138.   bmp := CreateBitmap((w + (b.X1 * 2)), (h + (b.Y1 * 2)));
  139.   DrawTPABitmap(bmp, TPA, 255);
  140.   DrawTPABitmap(bmp, segment, 16777215);
  141.   DebugBitmap(bmp);
  142.   FreeBitmap(bmp);
  143. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement