Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
image/png: info loss when encoding non-alpha-premultiplied that's not NRGBA (e.g., NRGBA64, NYCbCrA) #26001
Edit: solution below
I'm not sure if this is an error or if it is by design.
When decoding WebPs (and converting to PNG), color data is lost for pixels that are completely transparent. I don't think that this should be happening.
This loss does not occur when I decode the same WebP using Google's WebP tools.
Here is my Go code:
I reproduced the problem with an example image:
The original PNG before it was encoded to WebP; the Golang logo but completely transparent:
I drew on only the alpha channel of the original so you can see that it still retains color:
Here is the WebP encoded from the original PNG
Now here is where the problem occurs:
Does anyone know why this is happening? Is it a bug/intentional in the WebP packages? Is it my code?
Edit: Here is the solution I implemented.
Here is the result:
It's by design. The Go image and color model treats "transparent red" and "transparent blue" equivalently, as they're both transparent. In other words, it works primarily with alpha-premultiplied values. The documentation for the fundamental interface, https://golang.org/pkg/image/color/#Color, says (emphasis added):
Decoding the WebP image is giving you an
It's arguably a bug in the
It's not a trivial thing to implement, though, especially with chroma subsampling.
I also don't have much spare time to work on this myself. Sorry.