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

Closed
takeyourhatoff opened this issue Apr 7, 2017 · 4 comments
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@takeyourhatoff
Copy link

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
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/tyho/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build470515352=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
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/libc.so.6: 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
@splace
Copy link

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 help wanted NeedsFix The path to resolution is known, but the work has not been done. labels Apr 11, 2018
@andybons andybons added this to the Unplanned milestone Apr 11, 2018
@gopherbot
Copy link

Change https://golang.org/cl/134235 mentions this issue: image/png: pack image data for small bitdepth paletted images

@nightlyone
Copy link
Contributor

@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.

@andybons
Copy link
Member

@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.
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants