Commit 7de7d20e authored by Oliver Tonnhofer's avatar Oliver Tonnhofer Committed by Brad Fitzpatrick

image/png: improve compression by skipping filter for paletted images

Compression of paletted images is more efficient if they are not filtered.
This patch skips filtering for cbP8 images.
The improvements are demonstrated at https://github.com/olt/compressbench

Fixes #16196

Change-Id: Ie973aad287cacf9057e394bb01cf0e4448a77618
Reviewed-on: https://go-review.googlesource.com/29872Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 590f3f0c
......@@ -420,8 +420,11 @@ func writeImage(w io.Writer, m image.Image, cb int, level int) error {
}
// Apply the filter.
// Skip filter for NoCompression and paletted images (cbP8) as
// "filters are rarely useful on palette images" and will result
// in larger files (see http://www.libpng.org/pub/png/book/chapter09.html).
f := ftNone
if level != zlib.NoCompression {
if level != zlib.NoCompression && cb != cbP8 {
f = filter(&cr, pr, bpp)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment