#### Archived

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

# Alpha blending question

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

## 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 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[0] * fAlpha + (float)pucPalette[j][0] * (1 - fAlpha); fGreen = (float)pucPalette[1] * fAlpha + (float)pucPalette[j][1] * (1 - fAlpha); fBlue = (float)pucPalette[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

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 11
• 13
• 86
• 11
• 10
• ### Forum Statistics

• Total Topics
632973
• Total Posts
3009614
• ### Who's Online (See full list)

There are no registered users currently online

×