Advertisement

Lookup table?

Started by February 03, 2000 06:13 PM
2 comments, last by ziplux 25 years, 1 month ago
How would I use a lookup table to implement alpha blending? I have the values of the red,green, and blue pixels and wrote a function to alpha-blend them, but it is VERY slow, and I''ve heard lookup tables can be used to make it faster, I just haven''t seen any examples. Thanks in advance for any help!
My Geekcode: "GCS d s: a14 C++$ P+(++) L+ E-- W+++$ K- w++(+++) O---- M-- Y-- PGP- t XR- tv+ b++ DI+(+++) D- G e* h!"Decode my geekcode!Geekcode.com
Visit our web site:Asylum Entertainment
Just precompute all the calculations and put them in a huge array.
Alexbigshot@austin.rr.comFoolish man give wife grand piano. Wise man give wife upright organ.
Advertisement
Could you please show me an example? I''m using this code:
snip..............................
red = (128 * (0 - red) >> 8) + red ;
green = (128 * (0 - green) >> 8) + green;
blue = (128 * (31 - blue) >> 8) + blue;

vidbuffer[index_x + (index_y*lPitch16)] = _RGB16BIT565(red,green,blue);
snip..............................

Where vidbuffer is the video buffer, _RGB16BIT565 is a macro
to build a 16bit color, and red, green, and blue are unsigned chars colors.

My Geekcode: "GCS d s: a14 C++$ P+(++) L+ E-- W+++$ K- w++(+++) O---- M-- Y-- PGP- t XR- tv+ b++ DI+(+++) D- G e* h!"Decode my geekcode!Geekcode.com
Visit our web site:Asylum Entertainment
I wouldn''t use lookup tables for alpha blending at all. In fact, on newer CPU''s it''s faster to compute everything "on the fly" rather then using a "huge array" of precomputed values. The keyword here is "huge array", and it isn''t about memory consumption (we have plenty of it, right?). When doing alpha blending, you''re generally going to access this array on _random_ indexes, which means a very high probability of cache miss, which, in turn, costs more then a couple of arithmetic operations you need to perform blending. My own implementation blends a 320x240 sprite in 16bpp at 50 fps on Pentuim 100 (uh, I got lost in prepositions).

This topic is closed to new replies.

Advertisement