[comp.sys.mac.programmer] how do I find bit-depth of a window?

mikem@uhccux.uhcc.hawaii.edu (Mike Morton) (07/27/88)

I just MCI-mailed a note to Mac Tech support, and got a note back saying
they're busy this week and will answer me later.  In hopes that someone
on the net can answer more quickly than the "experts", here's a summary
of what I asked:

I have a subroutine which accesses a BitMap's graphical data directly.  When
the screen is one bit deep (2 colors) I believe I can do this safely.  If
it's more than 2 colors, I'll just back off and use QuickDraw calls.  My
questions are:

#1: Given a window, and a Rect in that window's coordinates, how can I tell
if that rectangle's contents are currently displayed on a single monitor
with one-bit color, addressable as an old-style BitMap?

#2: If that rectangle is indeed addressable as a BitMap, but the window
overlaps several monitors, how do I find the address for the Rect in
question?  (In other words, how can a window's single BitMap *or* PixMap
cover an area of the QuickDraw plane which has varyiing bit-depth because
it spans several monitors?)

Please post replies, as I rarely read my mail ;-)

 -- Mike Morton // P.O. Box 11378, Honolulu, HI  96828, (808) 456-8455 HST
      Internet: msm@ceta.ics.hawaii.edu
    (anagrams): Mr. Machine Tool; Ethical Mormon; Chosen Immortal; etc.

wdh@well.UUCP (Bill Hofmann) (07/27/88)

>#1: Given a window, and a Rect in that window's coordinates, how can I tell
>if that rectangle's contents are currently displayed on a single monitor
>with one-bit color, addressable as an old-style BitMap?

First, convert the rect to global coords (by being sure the window is
the current port, then, by doing LocalToGlobal on the topLeft and botRight
points of the Rect.  Then, do a GetMaxDevice(&yourRect), which will return
the deepest device that intersects your rect (it returns a GDHandle). E.g.:

	if (deepest = GetMaxDevice(&yourRect))	/* in case NO device matches */
	{
		if ((*(*deepest)->gdPMap)->pixelSize == 1)
			/* use the pixmap's baseAddr */ ;
	}

>#2: If that rectangle is indeed addressable as a BitMap, but the window
>overlaps several monitors, how do I find the address for the Rect in
>question?

	Once you've done the above, you've got the pixmap for the 1 bit
	device that your window rect is on.  Somewhere in the depths of
	Vol 5 they mention which device the portBits points to-but it
	is pretty much ignored by color QD, as I recall.  I think it's
	the first device on the list that the window's in, or maybe the
	main device, but don't quote me.

	So once you've found the device, you've got the pixmap, and
	thus you have your address (somewhere in NuBus space) and you
	have *your* rect (in global coords) and from the device, you
	can get the rect *it* represents ((*deepest)->gdRect), then
	you can intersect the two, and use your head to figure the
	address, given the rowBytes and etc.  Beware: if you muck with
	the gdRect, you can really screw things up (speaking from 
	experience).  Note esp. that rowBytes MUST be used, not other
	indicators of screen width.

So how is it that MacDTS refuses to answer technical questions 3 weeks
before MacWorld?  Seems like an ill-guided policy to me (I've got at
least one fairly burning question in the queue...).

-Bill Hofmann

wdh@well.UUCP (Bill Hofmann) (08/13/88)

In article <15435@apple.Apple.COM> tecot@apple.com.UUCP (Ed Tecot) writes:
>In article <6641@well.UUCP> wdh@well.UUCP (Bill Hofmann) writes:
>> <..an ill-considered flame at MacDTS..>
>It's not policy.  I don't really know what is going on at MacDTS, but I can
>guess.  As a result of MacWorld, I imageine they are being flooded with
>questions, at a rate much higher than they can handle.  Add to this the fact
>that they also must prepare for the conference, and it seems obvious to me
>that some questions are going to have to wait.  I'd expect that they are
>trying to answer the maximum number of questions they can.

Yes, indeed, they are swamped, and understaffed.  MacDTS has been very 
helpful in the past, and it was only that I had Linked them several questions
and hadn't heard a peep for over a week that caused that gripe.  Imagine
where we'd be without them. <There. Maybe now they'll answer me :-)>

-Bill