Source Alpha to Source Alpha Surface Blit Guarantees
The Pygame blit function for SRCALPHA to SRCALPHA surface blits has changed over the history of the package. For increased performance it is implemented as an integer arithmetic approximation of the floating point blend equation1 for alpha blitting. As such it has been refined to make its values more in line with what is expected. Unfortunately these revisions also made it prone to breakage2. So starting with Pygame 1.9 there are guarantees about the behavior of the alpha blit.
For the the blit function blend(src, dst, src_alpha):
The blit function for Pygame 1.9 is:
What this means
What do these mean in practice:
1 fblend(s, d, a) = (d * (255.0 - a) + s * a) / 255.0
2 The earlier 1.8 function is:
blend(s, d, sA, dA) = (((s - d) * a) >> 8) + d, dA > 0 = s, dA == 0
This function has the unexpected behavior of:
blend(c, d, 255, dA) = c - 1, 1 <= c < 255, 1 <= dA <= 255
It also breaks on computer hardware where the right shift operator does not preserve the sign of its target (propagate the left most bit), as (s - d) can go negative, but the eight bit shift returns a positive.