[comp.sys.3b1] calculation of srcwidth and dstwidth for wrastop

tcamp@uncecs.edu (Ted A. Campbell) (04/19/91)

I am writing an application utilizing tam() and wrastop()
routines for graphics output. The work has gone well, 
except that at certain points I need to save screen 
images to memory, and blit images from memory to the
display, etc. The wrastop() routines allow this, but 
the calculation of the srcwidth and dstwidth parameters
remains a great mystery to me. Why, if the rectangle
width is specified later, do these parameters need to
be given. I have tried several methods of calculation:
none seems to work all of the time. If anyone has had
experience in the mysteries of wrastop() and can open 
this mystery to me, I shall be most appreciative.

Thanks very much.

Ted A. Campbell
tcamp@uncecs.edu

sladkey@cbnewsb.cb.att.com (john.r.sladkey..jr) (04/20/91)

In article <1991Apr19.133128.22408@uncecs.edu>
	tcamp@uncecs.edu (Ted A. Campbell) writes:

> I am writing an application utilizing tam() and wrastop()
> routines for graphics output...
>            ...The wrastop() routines allow this, but 
> the calculation of the srcwidth and dstwidth parameters
> remains a great mystery to me. Why, if the rectangle
> width is specified later, do these parameters need to
> be given.

I too struggled with this question.  Eventually, I figured out that
one need not always blit WHOLE bitmaps!  Full bitmaps have dimensions
which make sense.  The x dimension is rounded up to the next multiple
of 16 to get whole 68000 words, then multiplied by 2 to get the width in bytes.
This looks like:

/* hand optimization of this seemingly simple formula
	is left as an exercise for the reader (grin) */

width = (dx + 15)/16 * 2;

Now that RASTOP knows the full byte-wise row-size it can do the proper
row/column addressing to get at the individual bytes and bits.  (One of
my gripes with C lang is that ordinary (static) multi-dimensional arrays cannot
be passed to a function without a lot of hassle, this example is a
case in point.)  Now if you want to blit a small portion of this bitmap,
just limit the dx and dy to your desired size.  In any case, RASTOP
needs to know (and cannot figure out any other way) what the actual bitmap
dimensions are.

Rick Sladkey
mvjrs@mvgpk.att.com