[comp.sys.amiga.tech] Cookie Cut BltBitMap

eric@icus.UUCP (Eric L. Hyman) (07/01/88)

I have an Aplication that draws a map based on 16X16 'Shapes'
These shapes are stored in their own Bitmap.
To Draw the map I Loop through Each square calling BltBitMap to copy
from my shape bitmap into the screen bitmap.

The problem:  

Each square contains Terrain(one of several shapes)
as well as A potentially a unit(Represented by another set
of shapes(Again All in the same bitmap)
To draw each squre currently involves 3 calls to
BltBitMap. 1 to draw terrain, 2) to 'zero out' the pixels for the unit
(By using a all 1's mask in the shape of the unit shape(Basically a
cookie cut with no save)) and 3 draw the unit into the square. The net
result is to overlay the unit on the terrain.
What I need/want is a way to do this with a single function..I don't think
any of the stock functions will handle it, and I was
just wondering if Any one code supply some code that would (Aztec 3.6 or
even better an assembly routine that does it all in one Blit)
					Thanxs in Advance for any help
					att    \
					boulder \
Eric Hyman				talcott  !icus!eric
					pacbell /
					sbcs   /

cmcmanis@sun.UUCP (07/02/88)

In article <406@icus.UUCP> eric@icus.UUCP (Eric L. Hyman) writes:
The problem:  

> Each square contains Terrain(one of several shapes) as well as A
> potentially a unit(Represented by another set of shapes(Again All in
> the same bitmap) To draw each squre currently involves 3 calls to
> BltBitMap. 1 to draw terrain, 2) to 'zero out' the pixels for the unit
> (By using a all 1's mask in the shape of the unit shape(Basically a
> cookie cut with no save)) and 3 draw the unit into the square. The net
> result is to overlay the unit on the terrain.  What I need/want is a
> way to do this with a single function..I don't think any of the stock
> functions will handle it, and I was just wondering if Any one code
> supply some code that would (Aztec 3.6 or even better an assembly
> routine that does it all in one Blit)
> Eric Hyman				talcott  !icus!eric

Eric, you can do this in exactly n Blits where 'n' is the depth of your
screen. First though, understand that a call to BltBitMap() on a 16 color
screen actually does fours calls to the blitter. One for each bitplane.

The best place to start is to get a copy of BlitLab that was done by 
Tom Rokicki. In it, you will find a very easy to use routine that 
will call the blitter directly for you. Assuming you have a 4 plane
screen (16 colors), set up each blit with the "A" source pointing
at your unit's image, the "B" source pointing at the terrain image,
and the "D"estination pointed at your real image. The minterm you
will use is A+~AB which is "bit from A if it is non zero, otherwise
take the bit from B", Do this blit 4 times, targeting each plane in
the unit, background, and destination appropriately. And poof instant
appearance of the unit on the screen. In the minimum time. But wait
their's more...

Since your images are exactly 16 bits wide, if your "squares" or limits
of motion is on 16 pixel boundaries (ie if you split the screen up into 
a bunch of 16 X 16 squares) then you can probably achieve the same
effect at nearly the same speed by using the CPU.


-- 
--Chuck McManis
uucp: {anywhere}!sun!cmcmanis   BIX: cmcmanis  ARPAnet: cmcmanis@sun.com
These opinions are my own and no one elses. But you knew that, didn't you.

jesup@cbmvax.UUCP (Randell Jesup) (07/03/88)

In article <2238@sugar.UUCP> peter@sugar.UUCP (Peter da Silva) writes:
>In article <58733@sun.uucp>, cmcmanis@sun.uucp (Chuck McManis) writes:
>> Assuming you have a 4 plane
>> screen (16 colors), set up each blit with the "A" source pointing
>> at your unit's image, the "B" source pointing at the terrain image,
>> and the "D"estination pointed at your real image. The minterm you
>> will use is A+~AB which is "bit from A if it is non zero, otherwise
>> take the bit from B",

>I think you would still need a mask, since in a given bitplane a bit might
>be zero in A, 1 in B, but still be in the object represented by A. You need
>to or all the bitplanes in A together to produce the mask (in C). You can
>do this with the blitter, and you might be able to do it in setup. Then you
>do AC+B~C...

	Exactly correct, the "cookie cutter" blit.  As a word of advise, with
a "fake" bitmap that has all planes pointing to on bitplane a
BltBitMap(srcBM,0,0,fakeBM,0,0,sizex,sizey,0xE0,-1L,NULL) will create your
mask for you.

>Isn't there already a function that does this? Nope, now that I look, there
>isn't. Why isn't there a general Blt function?
>
>	Blt(src1, src1x, src1y, src2, src2x, src2y, src3, src3x, src3y,
>		destrp, destx, desty, sizex, sizey, minterm);
>
>Or is this the function you mentioned in BlitLab? If so, does the blitlab
>function go through the layers library?

	I'd love such a function too.  Unfortunately, for certain cases
arbitrary rectangle operations require the A source for a mask.  Tom can 
explain it better than I.  I think the killer is when the sources must be
shifted in different directions, or when the byte counts are wrong, or some
such; and the FWM/LWM don't always hit the right word.

	It's part of the problem of having a BIMMER, not a BLITTER.  We deal
with words, not bits.

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

peter@sugar.UUCP (Peter da Silva) (07/03/88)

In article <4177@cbmvax.UUCP>, jesup@cbmvax.UUCP (Randell Jesup) writes:
> >Why isn't there a general Blt function?

> >	Blt(src1, src1x, src1y, src2, src2x, src2y, src3, src3x, src3y,
> >		destrp, destx, desty, sizex, sizey, minterm);

> 	I'd love such a function too.  Unfortunately, for certain cases
> arbitrary rectangle operations require the A source for a mask.  Tom can 
> explain it better than I.  I think the killer is when the sources must be
> shifted in different directions, or when the byte counts are wrong, or some
> such; and the FWM/LWM don't always hit the right word.

	OK, how about this one:

	Blt(src1, src2, src3, src3x, src3y,
		destrp, destx, desty, sizex, sizey, minterm);

Since most of the time when you do this src1 and src2 are going to be blitted
in in their entirety... src1==object, src2==mask, src3==image. Often src3 and
dest are the same thing. I'm sure that the BoB routines must have some sort
of cookie-cutter blit-in function. I couldn't find one in the manuals. How
about providing an entry point for that?

	BltObject(object, mask, destrp, x, y, sizex, sizey);

The set of library routines for doing Blits seems pretty incomplete. Maybe we
need a blit.library???

Does BlitLab go through the layers library?
-- 
-- `-_-' Peter (have you hugged your wolf today?) da Silva.
--   U   Mail to ...!uunet!sugar!peter, flames to /dev/null.
-- "Running DOS on a '386 is like driving an Indy car to the Stop-N-Go"