Skip to main content
GameDev.net gamedev.net
🔒 Locked

Alpha-Blending

Started by morfe Sep 9, 2000 at 11:04 AM 1 replies 900+ views
Original Post
morfe
morfe
I was playing with a 50% alphablend and I reduced it to this: Pascal (What I''ve been playing with) function fiftypt_Trans(color1,color2:word) : word; begin color1 := color1 shr 1; Inc(color1, color2 shr 1); result := (color1 and $00041CDF) - $F7DE; end; C (Converted just now... hope it''s right ) word fiftypt_Trans(word color1, word color2){ color1 = color1 >> 1; color1 += color2 >> 1; return (color1 && 0x00041CDF) - 0xF7DE); } Can I go smaller? And I know there is no error checking ... so shaddap Merrick ------------------------------------------------- Mindphuq Software : "Who do you want to do today?"
"NPCs will be inherited from the basic Entity class. They will be fully independent, and carry out their own lives oblivious to the world around them ... that is, until you set them on fire ..." -- Merrick
cyberben
cyberben
Does that function work? It looks to me like it won''t work...
And that''s for one set of pixels only eh? So if you were to write an alpha blitter you should put that right into the code of the blitter. DON''T call a sub function (Especially that simple of one) 100''s of times when cycling through an image..

So a couple Q''s. Using 16bpp? It looks it ''cause your using words. But you could just be a sloppy programming putting bytes into those params in 8bpp!

If so you need to take into account a few things, to start you gotta take into account wheather it''s 555 or 565 mode.
Then you mask off the lower bit of *each* color, before adding.
So here''s some rough pseudo/real code

if (Is_555 == TRUE) //We''re using 555 mode
{
color1 &= 0x7BDE; //Mask off lower bit of each color
color2 &= 0x7BDE; //Mask off lower bit of each color
}
else /We''re using 565 mode
{
color1 &= 0xF7DE; //Mask off lower bit of each color
color2 &= 0xF7DE; //Mask off lower bit of each color
}
color1 = color1 >> 1; // Shift right 1 (Essentially divide each color value by half)
color2 += color2 >> 1; // Shift right 1 and add last color(Essentially divide each color value by half)
return color1; // Return our mixed colors


That looks a bit more like it...
- Ben
__________________________Mencken's Law:"For every human problem, there is a neat, simple solution; and it's always wrong."
"Computers in the future may weigh no more than 1.5 tons."- Popular Mechanics, forecasting the relentless march of science in 1949
morfe
morfe
Yes it is 16bpp. And 555 format. It''s only in a function just to test that it works. Not for general use.

The original code was this :

color1 := color1 shr 1;
color2 := color2 shr 1;
color1 := (color1 and $3DEF) - $7BEF;
color2 := (color2 and $3DEF) - $7BEF;
result := color1 + color2;

I just removed the unnecessary commands. Sorry I didn''t make myself clear. I will do a separate one for 565 format later ... but for now, I''m doing this one

-------------------------------------------------
Mindphuq Software : "Who do you want to do today?"
"NPCs will be inherited from the basic Entity class. They will be fully independent, and carry out their own lives oblivious to the world around them ... that is, until you set them on fire ..." -- Merrick

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.