image/png: info loss when encoding non-alpha-premultiplied that's not NRGBA (e.g., NRGBA64, NYCbCrA) #26001
Labels
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
Edit: solution below
Go Version:
1.10.3 windows/amd64 (latest)
I'm not sure if this is an error or if it is by design.
I think this is a problem with the webp and/or vp8 packages, but it could be a problem with my code. I don't know all the ins and outs of the image package.
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.
The WebPs affected are structured like so:
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:
I'm linking to them because they don't display correctly through github
The original PNG before it was encoded to WebP; the Golang logo but completely transparent:
.png
I drew on only the alpha channel of the original so you can see that it still retains color:
.png
Here is the WebP encoded from the original PNG
.webp
Now here is where the problem occurs:
Again, I drew on only the alpha channel so you can see if the color is retained.
Decoded using Google's WebP tool (What I expected to happen):
.png
.png
Decoded using my code (What happened):
.png
.png
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.
It handles NYCbCrA and NRGBA images specially and reformats them to a color.RGBA to give to the png encoder. The RGBA pixel is just set to be completely opaque since I don't need the A values.
Here is the result:
.png
The text was updated successfully, but these errors were encountered: