Re: mem routines

new topic     » goto parent     » topic index » view thread      » older message » newer message

Lucius L Hilley III wrote:
>I plan to release some image utilities soon.  They will be great for
>drawing sprites.

>fore = a foreground image.
>back = a background image.
>--if fore is a 2D sequence 10x20 then
>--back must be a 2D sequence 10x20
>filter = filter image of fore.
>mixed = fore with back showing through.

>Code would look something like this.

>filter = (fore = 0)--Create boolean filter
>filter = fliter * 255--set filter to where back can show through.

>mixed = and_bits(filter, back)--mixed will equal part of back to show.
>mixed = or_bits(fore, mixed)--mixed equal fore with back showing.

>NOTE: Multiplying by 255 is slow.
>    I suggest creating the filter once and reusing it.
>ALSO: My background changes according to where
>    I am going to place fore.  SO I have to call
>    and_bits & or_bits every time.

>Please give credit where credit is due.
>These are only 4 lines of code but it took me a few hours
>to figure out just what order and how this would work.

>I have another Idea that MIGHT be faster that uses xor_bits.
>So far I haven't succeeded in getting it put together.

Since color bitmaps contain byte-level information (colors), it
isn't necessary to resort to bit-level math.  Try the following:

--
filter = not fore  -- creates boolean mask
mixed = filter*back  -- masks the background image
mixed = mixed+fore  -- adds the foreground image
--

Or, more concisely stated:

--
mixed = fore+back*not fore
--

This method runs about 20% faster than yours, and works on
euphoria version 1.4.  It is the best that I have been able to do
without resorting to (agghh!) machine code.

If you look at my bitmap demo on the euphoria home page, you will
see lots of examples of the above type of bitmap manipulation.

Colin Taylor
71630.1776 at compuserve.com

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu