Skip to content
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

image/png: unexpected behaviour while encoding paletted image with transparency #26395

Closed
prl900 opened this issue Jul 16, 2018 · 2 comments
Closed

Comments

@prl900
Copy link

@prl900 prl900 commented Jul 16, 2018

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.10 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
...

What did you do?

This simple program defines a palette with increasing alpha from 0 to 255 for the blue color. A paletted image using this palette is defined with a horizontal gradient from 0 to 255. This image is then encoded as a png on disk.

https://gist.github.com/prl900/b94fc4d71a25185ff962154e5209c563

What did you expect to see?

blue-white_gradient

What did you see instead?

test_paletted

@ysmolsky ysmolsky changed the title Unexpected behaviour png encoding paletted image with transparency image: unexpected behaviour png encoding paletted image with transparency Jul 16, 2018
@odeke-em
Copy link
Member

@odeke-em odeke-em commented Jul 16, 2018

@odeke-em odeke-em changed the title image: unexpected behaviour png encoding paletted image with transparency image/png: unexpected behaviour while encoding paletted image with transparency Jul 16, 2018
@odeke-em odeke-em added this to the Unreleased milestone Jul 16, 2018
@FiloSottile FiloSottile modified the milestones: Unreleased, Unplanned Jul 16, 2018
@nigeltao
Copy link
Contributor

@nigeltao nigeltao commented Jul 16, 2018

Your gist has this line:

palette[i] = color.RGBA{0x00, 0x00, 0xff, uint8(i)}

The RGBA should be NRGBA. As https://golang.org/pkg/image/color/#RGBA and https://golang.org/pkg/image/color/#NRGBA say, RGBA is alpha-premultiplied and that "An alpha-premultiplied color component C has been scaled by alpha (A), so has valid values 0 <= C <= A" and NRGBA is non-alpha-premultiplied.

@nigeltao nigeltao closed this Jul 16, 2018
@golang golang locked and limited conversation to collaborators Jul 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.