Mon, 13 Nov 2000 Piotr Dubla wrote:
I am trying to re-create an old-demo routine I wrote AGES ago in pascal.
It’s basically a linear cross-fade between to images (both 800*600) using
the old formula C = A + (B-A) * k
where C is the final colour, A is the first image colour, B is the second
image and k is a number between 0 and 1. Now I have to do this for every
pixel on screen, What would be the fastest way to do this. Currently I am
getting about .5 frames a second. WAY to slow.
Well, one real fast way is to hack up a few highly optimized alpha blending
routines of the kind 25/75, 50/50, 75/25 etc (just shifting, masking and adding
- works great with MMX), and then building dither patterns (4x4 pixels for
example) out of these.
If the fade is quick enough, the dithering will look more like analog noise
than dithering. You can see a similar effect on some 16 bit 3D accelerator
drivers on DirectX.
* Doesn’t rely on 24 bit color for smooth fading
If you want full color resolution and no dithering tricks, you could try using
look-up tables, but do keep these small. If they’re too big for the L2 cache,
you’re usually better off doing the real math! Cache misses are quite expensive
these days, especially on the higher frequency CPUs…
As for 24 and 32 bit modes, MMX rules. There are perfect instructions for this
kind of stuff, although there are only 16x16 bit multiplications. Still, you
can do 4 of them at a time (theoretically in 3 cycles, fully piplined so that
you can start one every cycle), so that’s quite a few muls/s. (There are
saturating add and sub as well, but you shouldn’t need that in this particular
case, unless I’m missing something…)
…- M u C o S -------------------------. .- David Olofson --------.
| A Free/Open Source | | Audio Hacker |
| Plugin and Integration Standard | | Linux Advocate |
| for | | Open Source Advocate |
| Professional and Consumer | | Singer |
| Multimedia | | Songwriter |
-----> http://www.linuxdj.com/mucos -'—> david at linuxdj.com -’