[comp.sys.mac.programmer] Drawing Points Fast ??

osborn@ux1.lbl.gov (James R Osborn) (03/10/89)

	Hi there,

	A short while ago there was an ongoing discussion about drawing
a bunch of points into a window fast.  Some people suggested drawing into
the bitmap directly or into an offscreen one directly and then copybitsing
into place.  I was wondering...

Would

BitSet(bytePtr, numBit)   and   BitClr(bytePtr, numBit)

be faster than using MoveTo(h, v) with Line(0, 0)?  I guess you would
have to calculate numBit, but it is fairly easy (but fast?) to do.  If
your Point is in global coordinates, then

numBit = Point.v * rowBytes * 8 + Point.h

and

bytePtr = baseAddr   (of the screen)


So would this be faster than MoveTo(h, v) with Line(0, 0)?  I know I know, you
would have to make sure you did not draw outside of your window (unless you're
trying to draw into the whole screen).  And you would get some funky results
if the cursor is visible.  You could call hide and show I suppose.  Any other
problems?

Would BitSet and BitClr be faster than manipulating the memory yourself?
(i.e. - how optimized are these routines anyway :-)

James R. Osborn
Lawrence Berkeley Laboratory
osborn@ux1.lbl.gov

yahnke@vms.macc.wisc.edu (Ross Yahnke, MACC) (03/10/89)

In article <2068@helios.ee.lbl.gov>, osborn@ux1.lbl.gov (James R Osborn) writes...
>Would
> 
>BitSet(bytePtr, numBit)   and   BitClr(bytePtr, numBit)
> 
>be faster than using MoveTo(h, v) with Line(0, 0)?  I guess you would

Short of writing assembler, isn't the following even faster
than BitSet & BitClr?

  byte *bmOrg;  /* ptr to start of bitmap image */
  int  bmRB;    /* rowBytes of bitmap image */
  byte *bytePtr;


  /* equivalent to: BitClr(bmOrg + (bmRB * y), x); */
  bytePtr = bmOrg + (bmRB * y) + (x >> 3);
  *bytePtr &= ~(1 << (7 - (x & 7)));

  /* equivalent to: BitSet(bmOrg + (bmRB * y), x); */
  bytePtr = bmOrg + (bmRB * y) + (x >> 3);
  *bytePtr |= (1 << (7 - (x & 7)));

(all assuming offscreen bitmaps, your own range checking and copybits
 to onscreen window, of course)

////////////////////////////////////////////////////////////
 Internet: yahnke@vms.macc.wisc.edu
   Bitnet: yahnke@wiscmacc(.bitnet)
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

lipa@polya.Stanford.EDU (William J. Lipa) (03/11/89)

Going directly to the screen memory is a Bad Idea if you're interested in
future compatibility. For example, your program won't work as written on a
machine with Color Quickdraw, and undoubtedly would fail if/when Apple
introduces hardware-accelerated graphics.

Bill Lipa