-
-
Notifications
You must be signed in to change notification settings - Fork 226
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
Align colors in SDL package to Go specification #581
Conversation
60eec5d
to
7a62974
Compare
This PR should be ready for a more general public verification. The more people that have color scenarios in their apps to verify the better. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job!
I ran into the same issue today. This PR solves all of my issues and does not seem to break anything. NRGBA should be correct indeed 👍
Thank you very much @mokiat! I will merge this into the |
* sdl/surface: handle colors correctly in Surface.Set method * sdl/pixels: fix color models * sdl/surface: handle RGBA correctly in Surface.At method * sdl/pixels: make sdl.Color be of type color.NRGBA * sdl/struct_test: fix compilation issue in sdl package * sdl/pixels: improve binary upscale/downscale precision
Thanks! Using On a side note, asking for future reference: should I have opened the PR against |
Yes, |
Closes #580
This PR does the following changes:
Surface.Set
does not panic by handling colors correctly.Surface.At
to returncolor.NRGBA
instead ofcolor.RGBA
which is the correct type for what is being returned (non-alpha-premultiplied color). This can be a breaking change if anyone ever expected a specific color from the method, despite the interface abstraction.sdl.Color
type tocolor.NRGBA
which is the correct representation of what is held insdl.Color
(non-alpha-premultiplied color). This is a breaking change. Preserving thecolor.RGBA
type mapping would require more code rework.sdl
packageThings to note:
color.RGBA
type in Go represents an alpha-premultiplied color and SDL2 appears to use standard non-alpha premultiplied colors everywhere. This is whycolor.NRGBA
is the correct pick.Color.RGBA
method is expected to return 16bit (i.e. from 0x0000 to 0xFFFF) alpha-premultiplied color components.color.NRGBA
andcolor.NRGBAModel
, since these are the official ones and they have stable and optimized implementations for color conversions between alpha-premultiplied and non-alpha-premultiplied variants and from 8bit-component to 16bit-component colors.Side notes: