-
Notifications
You must be signed in to change notification settings - Fork 10
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
Incorrect compositing for WebP with alpha #117
Comments
Actually, here's a non-animated image with the same issue: |
Could you check whether |
Yes, That is probably slightly faster as well, because we don't have to Code used for testing, for completenessuse std::error::Error;
use image::{codecs::webp::WebPDecoder, DynamicImage, ImageFormat, ImageReader, Rgba};
fn main() -> Result<(), Box<dyn Error>> {
let input = std::env::args().nth(1).unwrap();
let output = std::env::args().nth(2).unwrap();
let reader = ImageReader::open(input)?.into_inner();
let mut decoder = WebPDecoder::new(reader)?;
decoder.set_background_color(Rgba([0,0,0,0]))?;
let image = DynamicImage::from_decoder(decoder)?;
image.save(output)?;
Ok(())
} |
My guess is that the image contains a background color set to opaque white, but ImageMagick is ignoring it and compositing onto a fully transparent canvas instead. This is what the WebP spec says about the image's background color:
|
Firefox and Chrome displays the images with transparent background as well. And the images are clearly meant to be displayed like that, too. I think we'll have to change the way background color is treated for compatibility with real-world images targeting libwebp, regardless of what the spec says. |
We should certainly match what other software does. The spec is clearly written to allow transparent background behavior from Firefox and Chrome, it is just frustrating that the spec's suggested approach doesn't align with that. I propose adding a The only question left to figure out is whether browsers always use a transparent background or whether it varies based on the settings in the image. For instance, if the image doesn't have the Alpha bit set in the header, is a different background color used? |
To be clear, I haven't actually inspected whether the background color is set in the file or not, because I do not know how to do that. We should verify that this is indeed the case before we implement a fix based on this assumption.
(emphasis mine) Right now compositing doesn't apply the background color to the pixels of the first frame, resulting in a transparent "hole" around the beetle. That is also a bug. |
You can use the
|
I'm not actually sure this is a bug. Both images have
|
I see. That makes sense. I guess WebP background color is just a mess and we'll have to join other decoders in ignoring it 😅 |
This happens in
image
from git on commit 5976c195939bfbede976fe1e0a80225d192a793c withimage-webp
v0.2.0Expected
convert bug.webp[0] bug.png
produces an image that's fully transparent, other than the beetle:Actual behaviour
With
image
extracting the first frame results in a mostly white image, with a bit of transparency around the beetle:Reproduction steps
Image triggering the issue: bug.webp.gz
Code to reproduce it:
The text was updated successfully, but these errors were encountered: