For the alpha I was thinking something in the line of:
Code: Select all
destPixel = destPixel + ((sourceAlpha * (sourcePixel - destPixel)) >> 8);
Oh, and nice work btw =)
Code: Select all
destPixel = destPixel + ((sourceAlpha * (sourcePixel - destPixel)) >> 8);
RGBA-RGBA blits look like this for each pixel:Jezze wrote:I guess the 32-32 RGB is just a memcpy right?
For the alpha I was thinking something in the line of:
where each sourcePixel, sourceAlpha and alphaPixel would be a value from 0-255 as in 24 and 32bit color systems.Code: Select all
destPixel = destPixel + ((sourceAlpha * (sourcePixel - destPixel)) >> 8);
Oh, and nice work btw =)
Code: Select all
uint8_t a = _ALP(top);
uint8_t b = ((int)_ALP(bottom) * (255 - a)) / 255;
uint8_t alp = a + b;
uint8_t red = alp ? (int)(_RED(bottom) * (b) + _RED(top) * a) / (alp): 0;
uint8_t gre = alp ? (int)(_GRE(bottom) * (b) + _GRE(top) * a) / (alp): 0;
uint8_t blu = alp ? (int)(_BLU(bottom) * (b) + _BLU(top) * a) / (alp): 0;
Code: Select all
uint8_t a = _ALP(top);
uint8_t b = ((int)_ALP(bottom) * (255 - a)) / 255;
uint8_t alp = a + b;
uint8_t red = alp ? (int)(_RED(bottom) * (b) + _RED(top) * a) / (alp): 0;
uint8_t gre = alp ? (int)(_GRE(bottom) * (b) + _GRE(top) * a) / (alp): 0;
uint8_t blu = alp ? (int)(_BLU(bottom) * (b) + _BLU(top) * a) / (alp): 0;
Code: Select all
reg0 = b1 b2 b1 b2 : b1 b2 b1 b2 ; blend factor
Load Pixel
reg1 = A1 R1 G1 B1 : A2 R2 G2 B2
PSHUFB
reg2 = A1 A2 R1 R2 : G1 G2 B1 B2
PMADDUBSW
DEST[15-0 ] = Saturate(b1B1 + b2B2)
DEST[31-16] = Saturate(b1G1 + b2G2)
DEST[47-32] = Saturate(b1R1 + b2R2)
DEST[63-48] = Saturate(b1A1 + b2A2)
Store Pixel
My implementation is a fully accurate alpha blend. The divisions are mathemetically sound, such that none of the operations will overflow and saturation is implicit with the alpha calculations.bluemoon wrote:It seems do not handle overflow/saturate well, it that blend function designed for purpose?
A normal alpha blend function may look like this:Here you calculate b1, b2, which is the blending factor using the function of your choice - note that this will may depends on alpha of each pixel, or otherwise remain constant for the whole operation.Code: Select all
...
You may expand this to do 4 pixel per iteration as well.