Advertisement
WarPie90

Untitled

Aug 11th, 2014
429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.49 KB | None | 0 0
  1. procedure TMufasaBitmap.ResizeBilinear(NewW,NewH:Int32);
  2. var
  3.   x,y,i,size,col,row,idx,wid: Integer;
  4.   ratioX,ratioY,dx,dy: Single;
  5.   p0,p1,p2,p3:TRGB32;
  6.   Temp,ptr: PRGB32;
  7. begin
  8.   Size := NewW * NewH;
  9.   Temp := GetMem(Size * SizeOf(TRGB32));
  10.  
  11.   ratioX := (Self.Width-1)  / NewW;
  12.   ratioY := (Self.Height-1) / NewH;
  13.   Wid := Self.Width;
  14.   Dec(size);
  15.   ptr := temp;
  16.   for i:=0 to size do
  17.   begin
  18.     row := i div NewW;
  19.     col := i-row*NewW;
  20.     x := Trunc(ratioX * col);
  21.     y := Trunc(ratioY * row);
  22.     dX := ratioX * col - x;
  23.     dY := ratioY * row - y;
  24.  
  25.     p0 := Self.FData[y*Wid+x];
  26.     p1 := Self.FData[y*Wid+x+1];
  27.     p2 := Self.FData[(y+1)*Wid+x];
  28.     p3 := Self.FData[(y+1)*Wid+x+1];
  29.  
  30.     (* Possibly a speedup instead of the above
  31.     idx:= y*wid+x;
  32.     p0 := Self.FData[idx];
  33.     p1 := Self.FData[idx+1];
  34.     p2 := Self.FData[idx+wid];
  35.     p3 := Self.FData[idx+wid+1];
  36.     *)
  37.  
  38.     ptr^.R := Trunc(p0.R * (1-dX) * (1-dY) +
  39.                     p1.R * (dX * (1-dY)) +
  40.                     p2.R * (dY * (1-dX)) +
  41.                     p3.R * (dX * dY));
  42.  
  43.     ptr^.G := Trunc(p0.G * (1-dX) * (1-dY) +
  44.                     p1.G * (dX * (1-dY)) +
  45.                     p2.G * (dY * (1-dX)) +
  46.                     p3.G * (dX * dY));
  47.  
  48.     ptr^.B := Trunc(p0.B * (1-dX) * (1-dY) +
  49.                     p1.B * (dX * (1-dY)) +
  50.                     p2.B * (dY * (1-dX)) +
  51.                     p3.B * (dX * dY));  
  52.     Inc(ptr);
  53.   end;
  54.  
  55.   FreeMem(FData);
  56.   Self.FData := Temp;
  57. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement