[comp.sys.amiga.tech] blitting bitmaps

ahinds@hvrunix.UUCP (Alexander Hinds) (01/30/89)

	I'm involved in a game port, and I need to be able to blit
bitmaps (or rasters).  The problem is that I want to copy a whole
source BitMap, except for color 14 to a destination BitMap.  The RKM's
weren't too clear on how or if this can be done.  I'd appreciate any help,
whatsoever.  Mail would be better.  Thanks in advance.

Alexander Hinds
A_HINDS@HVRFORD	:preferable bitnet address
ahinds@hvrford	:usenet address

rokicki@polya.Stanford.EDU (Tomas G. Rokicki) (01/30/89)

In article <503@hvrunix.UUCP>, ahinds@hvrunix.UUCP (Alexander Hinds) writes:
> 	I'm involved in a game port, and I need to be able to blit
> bitmaps (or rasters).  The problem is that I want to copy a whole
> source BitMap, except for color 14 to a destination BitMap.  The RKM's
> weren't too clear on how or if this can be done.

You don't mention if you want it to work on windows or screens.  But, in
any case, first you want to create a mask that tells what portion of the
bitmap is color 14.  This will take two blits for 4-5 planes.  Then, you
want to do a copy blit using this as a mask.  Are you going through the
standard graphics library, or are you driving the blitter yourself?  The
real question is, do you want layers or not?  Let me know and I'll give
you the appropriate functions . . .

-tom

jesup@cbmvax.UUCP (Randell Jesup) (01/31/89)

In article <503@hvrunix.UUCP> ahinds@hvrunix.UUCP (Alexander Hinds) writes:
>
>	I'm involved in a game port, and I need to be able to blit
>bitmaps (or rasters).  The problem is that I want to copy a whole
>source BitMap, except for color 14 to a destination BitMap.  The RKM's
>weren't too clear on how or if this can be done.  I'd appreciate any help,
>whatsoever.  Mail would be better.  Thanks in advance.

	I think this might be of general interest.

	The first thing to realize is the blitting occurs on bitplanes, not
bitmaps.  Therefor, the blitter doesn't know about colors.  So you have to
contruct a mask of where color 14 is and is not.  One way might be this:

	Create a mask bitplane and a bitmap structure for it (InitBitMap, etc).
		(I'll call this Bitmap bmask)
	set bmask's bitplane (BltClr or whatever) to all 1 bits.
	Create another bitmap structure similar to the first (no bitplane).
		(I'll call this Bitmap btemp)
	for (i = 0; i < #planes in source; i++)
	{
		Set the bitplane pointer 0 of bmask to source bitmap plane[i]
		if ((1L << i) & color)	/* color = 14 */
			BltBitMap(btemp,0,0,bdest,0,0,SIZEX,SIZEY,
		  		  ABC,0xff,NULL);
		else
			BltBitMap(btemp,0,0,bdest,0,0,SIZEX,SIZEY,
		  		  ANBC,0xff,NULL);
	}
	/* btemp now has a 1-bitplane mask with 1's where color is. */
	/* now use the mask to copy */
/*
 * there are three ways to do this:
 * 1.	BltMaskBitMapRastPort - slow but easy to use.  Does 3 blits, and
 *		temporarily modifies the source in the process (fixes it
 *		up when done.)  "glitchy" looking destination during blit.
 * 2.	One blit to clear part of the desination, using 0x20, and a faked
 *		bitmap that has pointers to the mask plane in all the plane
 *		pointers, and says it's the same size as the source.  Second
 *		blit from source, using 0xE0 for a minterm. Faster
 *		by a bit (2 passes versus 3), doesn't modify source ever.
 *		Less glitchy than 1, but still has glitches in masked area.
 * 3.	OwnBlitter(); WaitBlit(), do a cookie cutter blit.  Requires the
 *		bitmaps be alligned conveniently so an next-to-last-word
 *		mask in the A source isn't needed.  Tom Rokicki recently
 *		posted about this, I believe.  Fastest, least glitches (though
 *		as with all blits, there may be some).  Toughest to code
 *		(hitting the blitter registers).
 */

Note: written off the top of my head, without error-checking.  Caveat User.

	Hope this helps!

-- 
Randell Jesup, Commodore Engineering {uunet|rutgers|allegra}!cbmvax!jesup