-
Notifications
You must be signed in to change notification settings - Fork 18k
image/color: NRGBA provides alpha-premultiplied values, and RGBA provides non-alpha-premultiplied values. The doc claims the exact opposite. #55327
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
Comments
Also, the 64bit |
I think you indeed misinterpreted the documentation. For Also, see https://pkg.go.dev/image/color#RGBA64
So For your second comment, the RGBA method satisfies the https://pkg.go.dev/image/color#Color interface. Note that for Closing as working as intended. Thanks. |
Thanks, I had already started working all of this out in the time after submitting this. I still feel like something could be changed to make it harder to accidentally create an invalid struct. Maybe it'd be worth it to add a NewColor function that takes straight r,g,b,a values and returns a valid color.RGBA object, doing the multiplication for the developer. Otherwise, developers will keep making their own structs manually which often results in incorrect behavior. But, it could be argued that it's up to the developers to avoid making this kind of mistake. |
Since https://pkg.go.dev/image/color#RGBA already documents that
I think it is expected that the user would not create invalid values. For a |
Commenting here since this currently is the first Google result for All the handling of alpha values by the standard library is a bit funky. The premultiplication done by method |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes. This issue has been present in every version since weekly.2011-10-06.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://go.dev/play/p/ckINKpbqQ2L
What did you expect to see?
This should be alpha-premultiplied (0 0 0 0): 0 0 0 0
This should be alpha-premultiplied (0 0 0 0): 0 0 0 0
This shouldn't be alpha-premultiplied (0 32639 65535 0): 0 32639 65535 0
This shouldn't be alpha-premultiplied (0 2147483647 4294967295 0): 0 2147483647 4294967295 0
What did you see instead?
This should be alpha-premultiplied (0 0 0 0): 0 32639 65535 0
This should be alpha-premultiplied (0 0 0 0): 0 32767 65535 0
This shouldn't be alpha-premultiplied (0 32639 65535 0): 0 0 0 0
This shouldn't be alpha-premultiplied (0 2147483647 4294967295 0): 0 0 0 0
I may be completely misinterpreting the documentation, or even misinterpreting the concept of alpha-premultiplication, but based on the Wikipedia page for Alpha compositing the current behavior is inverted.
The text was updated successfully, but these errors were encountered: