From: Oliver Tonnhofer Date: Tue, 27 Sep 2016 13:24:00 +0000 (+0200) Subject: image/png: improve compression by skipping filter for paletted images X-Git-Tag: go1.8beta1~1146 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=7de7d20e9f14c3a8fb9a3bcf6a36a299c74e9ddd;p=gostls13.git 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/29872 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- diff --git a/src/image/png/writer.go b/src/image/png/writer.go index df23270ee9..dd87d81629 100644 --- a/src/image/png/writer.go +++ b/src/image/png/writer.go @@ -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) }