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: Encode encodes 8 bit paletted output when palette will fit in less space #19879

takeyourhatoff opened this issue Apr 7, 2017 · 4 comments


Copy link

@takeyourhatoff takeyourhatoff commented Apr 7, 2017

What did you do?

Call png.Encode(w, p) where p is a image.Paletted and len(p.Palette) <= 16.

What did you expect to see?

Encode to encode a 4 bit paletted image

What did you see instead?

Encode encodes a 8 bit paletted image

System details

go version go1.8 linux/amd64
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build470515352=/tmp/go-build -gno-record-gcc-switches"
GOROOT/bin/go version: go version go1.8 linux/amd64
GOROOT/bin/go tool compile -V: compile version go1.8 X:framepointer
uname -sr: Linux 4.9.10-200.fc25.x86_64
/lib64/ GNU C Library (GNU libc) stable release version 2.24, by Roland McGrath et al.
gdb --version: GNU gdb (GDB) Fedora 7.12.1-46.fc25
Copy link

@splace splace commented Dec 28, 2017

i found the same thing saving a back/white implementation of image.PalettedImage, when you look at the standard lib, there is only encoding support for 8-bit index colormaps, there is decoding support for 1,2,4,8 bits.

it seems to me that png has compression that works well on images that can be paletted, because you tend to get sequences of the same color. without support for the bit packed formats you dont benefit much at all, in file size, from using a palette. you can gain as much by pushing an image through a palette, and back, to reduce the color depth, then save un-paletted..

however, the built-in image.Paletted type, stores in memory in this 8-bit format, so loading saving should be very fast.

this is all that png compliance requires, but like you, in a language library like this you might have hoped for it.

@andybons andybons added this to the Unplanned milestone Apr 11, 2018
Copy link

@gopherbot gopherbot commented Sep 8, 2018

Change mentions this issue: image/png: pack image data for small bitdepth paletted images

@gopherbot gopherbot closed this in b84a580 Sep 25, 2018
Copy link

@nightlyone nightlyone commented Sep 25, 2018

@andybons this might be useful to mention as a new feature in the release notes. It will have different content hashes when hashing the output of such png images created with Go 1.11 and Go 1.12. This may be relevant to know for transcoding image servers.

Copy link

@andybons andybons commented Sep 25, 2018

@nightlyone added comment to the change to ensure it gets mentioned in release notes.

@golang golang locked and limited conversation to collaborators Sep 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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.