Janilabo

Untitled

Aug 26th, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.42 KB | None | 0 0
  1. procedure TPACentralize(var TPA: TPointArray; area: TBox);
  2. var
  3.   o: TPoint;
  4.   b: TBox;
  5. begin
  6.   if (Length(TPA) > 0) then
  7.   begin
  8.     b := GetTPABounds(TPA);
  9.     o := Point(((Round(area.X1 + ((area.X2 - area.X1) / 2)) - (((b.X2 - b.X1) + 1) div 2)) - b.X1), ((Round(area.Y1 + ((area.Y2 - area.Y1) / 2)) - (((b.Y2 - b.Y1) + 1) div 2)) - b.Y1));
  10.     OffsetTPA(TPA, o);
  11.   end;
  12. end;
  13.  
  14. procedure ZoomTPA(var TPA: TPointArray; Times: Integer);
  15. var
  16.   w, h, l, i, x, y, width, height: Integer;
  17.   m: array of TBoolArray;
  18.   b: TBox;
  19. begin
  20.   if (times <> 0) then
  21.   begin
  22.     l := Length(TPA);
  23.     if (l > 0) then
  24.     begin
  25.       b := GetTPABounds(TPA);
  26.       w := ((b.X2 - b.X1) + 1);
  27.       h := ((b.Y2 - b.Y1) + 1);
  28.       if (times > 0) then
  29.       begin
  30.         width := (w * times);
  31.         height := (h * times);
  32.       end else
  33.       begin
  34.         times := Abs(times);
  35.         width := (w div times);
  36.         height := (h div times);
  37.       end;
  38.       SetLength(m, w);
  39.       for x := 0 to (w - 1) do
  40.       begin
  41.         SetLength(m[x], h);
  42.         for y := 0 to (h - 1) do
  43.           m[x][y] := False;
  44.       end;
  45.       for i := 0 to (l - 1) do
  46.         m[(TPA[i].X - b.X1)][(TPA[i].Y - b.Y1)] := True;
  47.       SetLength(TPA, 0);
  48.       l := 0;
  49.       for y := 0 to (height - 1) do
  50.         for x := 0 to (width - 1) do
  51.           if m[((x * w) div width)][((y * h) div height)] then
  52.           begin
  53.             SetLength(TPA, (l + 1));
  54.             TPA[l] := Point((x + b.X1), (y + b.Y1));
  55.             Inc(l);
  56.           end;
  57.     end;
  58.   end;
  59. end;
  60.  
  61. procedure SetPixels(bmp: Integer; TPA: TPointArray; color: Integer);
  62. var
  63.   a, b, w, h: Integer;
  64. begin
  65.   b := High(TPA);
  66.   if (b > -1) then
  67.   begin
  68.     try
  69.       GetBitmapSize(bmp, w, h);
  70.     except
  71.       Exit;
  72.     end;
  73.     for a := 0 to b do
  74.       if ((TPA[a].X > -1) and (TPA[a].Y > -1) and (TPA[a].X < w) and (TPA[a].Y < h)) then
  75.         FastSetPixel(bmp, TPA[a].X, TPA[a].Y, color);
  76.   end;
  77. end;
  78.  
  79. var
  80.   zoomed, original: TPointArray;
  81.   bmp: Integer;
  82.   b: TBox;
  83.  
  84. const
  85.   ZOOM = 3;
  86.  
  87. begin
  88.   bmp := CreateBitmap(500, 500);
  89.   original := [Point(211, 212), Point(213, 214), Point(215, 216), Point(217, 218)];
  90.   zoomed := CopyTPA(original);
  91.   ZoomTPA(zoomed, ZOOM);
  92.   b := GetTPABounds(original);
  93.   TPACentralize(zoomed, b);
  94.   SetPixels(bmp, zoomed, 255);
  95.   SetPixels(bmp, original, 16777215);
  96.   DisplayDebugImgWindow(500, 500);
  97.   DrawBitmapDebugImg(bmp);
  98. end.
Advertisement
Add Comment
Please, Sign In to add comment