Archived

This topic is now archived and is closed to further replies.

Alpha blending question

This topic is 6360 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m currently doing stuff in dos graphics(all of my own code(well close enough)) and i was wondering if, in 13h mode and without changing the pallette, there is a way to do the blending....any help?

Share this post


Link to post
Share on other sites
You can do (a sort of) alpha-blending in any palettized mode by precalculating a look-up table of fore-ground back-ground pairs.

That is, your palette has 256 entries, just allocate a 256x256 array in which the pair (i, j) tells the index of the color to use for blending the i-nth color onto the j-nth color.

Of course the table will be precalculated for a given translucency (alpha) value and for a given palette.

You need just a routine to find the "best matching" color, et voila'...

For example, a code like this should work... (not tested, though )

            

void ComputeAlphaBlendingLUT(unsigned char pucLUT[256][256], unsigned char pucPalette[256][3], float fAlpha)
{
int i, j;
float fRed, fGreen, fBlue;

for (i = 0; i < 255; i++) {
for (j = 0; j < 255; j++) {
fRed = (float)pucPalette<i>[0] * fAlpha + (float)pucPalette[j][0] * (1 - fAlpha);
fGreen = (float)pucPalette<i>[1] * fAlpha + (float)pucPalette[j][1] * (1 - fAlpha);
fBlue = (float)pucPalette<i>[2] * fAlpha + (float)pucPalette[j][2] * (1 - fAlpha);

pucLUT[i][j] = FindBestColor(pucPalette, fRed, fGreen, fBlue);
}
}
}

void AlphaPutPixel(int nX, int nY, unsigned char ucColor, unsigned char pucLUT[256][256])
{
PutPixel(nX, nY, pucLUT[ucColor][GetPixel(nX, nY)]);
}



Hope it helps...


Karmalaa



Edited by - karmalaa on July 17, 2000 5:34:40 PM

Edited by - karmalaa on July 17, 2000 5:35:43 PM

Share this post


Link to post
Share on other sites