function out = drawline(in,x1,y1,x2,y2);
%
%	Draws a Bresenham line from (x1,y1) -> (x2,y2)
%
%
%	out = drawline(in,x1,y1,x2,y2);



% x1 = round(x1);
%x2 = round(x2);
%y1 = round(y1);
%y2 = round(y2);


x = x1;
y = y1;

deltax = x2 - x1;
deltay = y2 - y1;

if (deltax < 0) 
  xchange = -1;
  deltax = -deltax;
else
  xchange = 1;
end

if (deltay < 0)
  ychange = -1;
  deltay = -deltay; 
else
  ychange = 1;
end

error = 0;

in(y,x) = 255;

if (deltax < deltay)
  length = deltay;
  for i=0:(length-1)
    y = y + ychange;
    error = error + deltax;
    
    if (error >= deltay)
      x = x + xchange;
      error = error - deltay;
    end
    in(y,x) = 255;
  end
else
  length = deltax;
  for i=0:(length-1)
    x = x + xchange;
    error = error + deltay;
   
    if (error >= deltax)
      y = y + ychange;
      error = error - deltax;
    end
    in(y,x) = 255;	
  end
end

out = in;


