Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- procedure TMufasaBitmap.ResizeBilinear(NewW,NewH:Int32);
- var
- x,y,i,size,col,row,idx,wid: Integer;
- ratioX,ratioY,dx,dy: Single;
- p0,p1,p2,p3:TRGB32;
- Temp,ptr: PRGB32;
- begin
- Size := NewW * NewH;
- Temp := GetMem(Size * SizeOf(TRGB32));
- ratioX := (Self.Width-1) / NewW;
- ratioY := (Self.Height-1) / NewH;
- Wid := Self.Width;
- Dec(size);
- ptr := temp;
- for i:=0 to size do
- begin
- row := i div NewW;
- col := i-row*NewW;
- x := Trunc(ratioX * col);
- y := Trunc(ratioY * row);
- dX := ratioX * col - x;
- dY := ratioY * row - y;
- p0 := Self.FData[y*Wid+x];
- p1 := Self.FData[y*Wid+x+1];
- p2 := Self.FData[(y+1)*Wid+x];
- p3 := Self.FData[(y+1)*Wid+x+1];
- (* Possibly a speedup instead of the above
- idx:= y*wid+x;
- p0 := Self.FData[idx];
- p1 := Self.FData[idx+1];
- p2 := Self.FData[idx+wid];
- p3 := Self.FData[idx+wid+1];
- *)
- ptr^.R := Trunc(p0.R * (1-dX) * (1-dY) +
- p1.R * (dX * (1-dY)) +
- p2.R * (dY * (1-dX)) +
- p3.R * (dX * dY));
- ptr^.G := Trunc(p0.G * (1-dX) * (1-dY) +
- p1.G * (dX * (1-dY)) +
- p2.G * (dY * (1-dX)) +
- p3.G * (dX * dY));
- ptr^.B := Trunc(p0.B * (1-dX) * (1-dY) +
- p1.B * (dX * (1-dY)) +
- p2.B * (dY * (1-dX)) +
- p3.B * (dX * dY));
- Inc(ptr);
- end;
- FreeMem(FData);
- Self.FData := Temp;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement