-
-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong alpha values applied when blitting to an SRCALPHA Surface #2706
Comments
I think the main issue you are encountering here is the classic 'straight alpha' composition problem. For example if I switch to premultiplied blending, the problem goes away:
It is just a bit of a confusing way of getting there as setting the global alpha switches a colorkey surface to use standard alpha blending rather than the special color key blending. If this is for a specific workflow rather than a general problem you are having with 'straight alpha' blending, you could just fill the intermediate transparent surface with white in the RGB and the blend will be a lot closer:
You can read more about the composition problems with straight alpha blending and why premultipled is superior over here: |
I'm going to close this now, because this is just the results of the 'straight alpha' blending formula when blending two surfaces with alpha and there isn't really anything we can do about it. You are basically getting (255-225) = 30 alpha worth of extra black over what you were intuitively expecting. This (blending onto a 'transparent' surface) is basically the standard case which makes people discover pre-multiplied alpha blending. |
Environment:
Windows 10
pygame-ce 2.4.0 (SDL 2.28.5, Python 3.12.0)
Current behavior:
When blitting a Surface with a global alpha value to an SRCALPHA Surface the alpha value is applied twice.
Expected behavior:
Each pixel of the SRCALPHA surface should maintain the alpha value of the surface blitted to it and not apply the global alpha value a second time. In the below code the two images should be identical.
Test code
The text was updated successfully, but these errors were encountered: