Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!rutgers!ames!lll-tis!ptsfa!ihnp4!ihlpe!psfales From: psfales@ihlpe.ATT.COM (Pete Fales) Newsgroups: comp.sys.ibm.pc Subject: Re: Graphics driver Message-ID: <2000@ihlpe.ATT.COM> Date: Fri, 28-Aug-87 10:51:09 EDT Article-I.D.: ihlpe.2000 Posted: Fri Aug 28 10:51:09 1987 Date-Received: Sun, 30-Aug-87 01:34:12 EDT References: <1096@ark.cs.vu.nl> <2436@bnrmtv.UUCP> <1099@ark.cs.vu.nl> Organization: AT&T Bell Laboratories - Naperville, Illinois Lines: 71 In article <1099@ark.cs.vu.nl>, lesmem@cs.vu.nl (Marco Lesmeister) writes: > > Can somebody post a fast line drawing algorithm that > uses direct memory writes to CGA memory. > > Thanks in advance, Marco Lesmeister. I won't make any claims about how fast this algorithm is relative to other potential candidates, but it is pretty good. I didn't write it (it was published in the IBM Journal of Research and Development), but I have had several occasions to use it over the years, including some assembly language implementations. It uses only integer arithmetic and multiplications only by powers of 2. ---------------------------- cut here ------------------------------ int xm1[] = { 1, 0, 1, 0,-1, 0,-1, 0 }; int ym1[] = { 0, 1, 0,-1, 0, 1, 0,-1 }; int xm2[] = { 1, 1, 1, 1,-1,-1,-1,-1 }; int ym2[] = { 1, 1,-1,-1, 1, 1,-1,-1 }; /* Bresenham (spelling?) algorithm to draw a line from (x1,y1) to (x2,y2) */ void absline(x1,y1,x2,y2,col) { int m,deltax,deltay,e,cx,savedx,t; m=0; deltax=x2-x1; if ( deltax<0 ) { m=4; deltax = -deltax; } deltay=y2-y1; if (deltay<0 ) { m += 2; deltay = -deltay; } if ( deltax - deltay < 0 ) { m++; t=deltax; deltax=deltay; deltay=t; } deltay *= 2; /* OK, use a shift if you really want speed */ e = deltay-deltax; savedx = deltax; deltax *= 2; for ( cx=savedx+1 ; cx >= 1 ; cx-- ) { scr_wdot(x1,y1,col); if ( e > 0 ) { x1 += xm2[m]; y1 += ym2[m]; e += deltay-deltax; } else { x1 += xm1[m]; y1 += ym1[m]; e += deltay; } } } -- Peter Fales UUCP: ...ihnp4!ihlpe!psfales work: (312) 979-7784 AT&T Information Systems, IW 1Z-243 1100 E. Warrenville Rd., IL 60566