Advertisement
WarPie90

temp

Jan 18th, 2016
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.19 KB | None | 0 0
  1. procedure TNalaBitmap.Thumbnail(NewWidth, NewHeight: UInt32; TargetBitmap: TNalaBitmap);
  2. var
  3.   w,h,x,y,rx,ry,dx,dy:Int32;
  4.   xx,yy,r,g,b,n,rr,gg,bb:Int32;
  5.   wr,hr:Double;
  6.   TargetData,rowPtr:PRGB32;
  7.   offset:PtrUInt;
  8. begin
  9.   TargetBitmap.SetSize(NewWidth, NewHeight);
  10.   TargetData := TargetBitmap.FData;
  11.  
  12.   wr := FWidth / NewWidth;
  13.   hr := FHeight / NewHeight;
  14.   w := FWidth - 1;
  15.   h := FHeight - 1;
  16.  
  17.   for y:=0 to NewHeight - 1 do
  18.   begin
  19.     ry := Trunc(y*hr);
  20.     dy := Min(ry+Trunc(hr), h);
  21.     for x:=0 to NewWidth - 1 do
  22.     begin
  23.       rx := Trunc(x*wr);
  24.       dx := Min(rx+Trunc(wr), w);
  25.       r := 0;
  26.       g := 0;
  27.       b := 0;
  28.       n := 0;
  29.       rowPtr := @FData[ry * FWidth];
  30.       offset := PtrUInt(@FData[dy * FWidth]);
  31.       while PtrUInt(rowPtr) <= offset do
  32.       begin
  33.         for xx:=rx to dx do
  34.         begin
  35.           R += rowPtr[xx].R;
  36.           G += rowPtr[xx].G;
  37.           B += rowPtr[xx].B;
  38.           Inc(n);
  39.         end;
  40.         Inc(rowPtr,FWidth);
  41.       end;
  42.       r := r div n;
  43.       g := g div n;
  44.       b := b div n;
  45.  
  46.       Ptr := @TargetData[y * NewWidth + x];
  47.       Ptr^.R := r;
  48.       Ptr^.G := g;
  49.       Ptr^.B := b;
  50.     end;
  51.   end;
  52. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement