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