-
Notifications
You must be signed in to change notification settings - Fork 18
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
Issues with transparency #23
Comments
Thanks, I will look into it. |
This is the expected behaviour in RGBA with uncorrelated alpha channel. The usual way to avoid it is to convert the image to premultiplied RGBA color space, i.e.
Then resize, and to get the usual uncorrelated RGBA back, divide by alpha (with care about division by 0) You will also have to use bilinear filter, because other filters sharpen the channels, and "sharpening" of alpha makes no sense. |
Do other resizing tools do this automatically? Do they use bilinear for the alpha only, or drop down to bilinear for all channels? |
fwiw, ImageMagick seems to handle it automatically, but I haven't looked into what it does. |
In my tools I do it automatically :) macOS goes as far as only supporting premultiplied RGBA color space. You have to use bilinear for all channels. If you use other method, RGB and A will "go out of sync" at the edges and expose nonsense pixels. |
@kornelski should we provide method to do RGBA premultiplication in public library API? |
Conversion back and forth is expensive and lossy, so apps may want to structure it in a way that minimizes conversions throughout the entire app. I think we should only document this pitfall, but leave conversion to other crates. |
Here's the gmail logo:
And here's the logo reduced a little using triangle:
Note the border around the mail icon. I'm guessing it's sampling colours in the transparent area of the image. This seems to happen with all the filters.
The text was updated successfully, but these errors were encountered: