Commit 9f0b749b authored by Rui Ueyama's avatar Rui Ueyama Committed by Nigel Tao

image/png: do not apply filters if level is NoCompression

PNG filters are applied to get better compression ratio.
It does not make sense to apply them if we are not going
to compress.

LGTM=nigeltao
R=nigeltao
CC=golang-codereviews
https://golang.org/cl/137830043
parent 42486ffc
......@@ -417,7 +417,10 @@ func writeImage(w io.Writer, m image.Image, cb int, level int) error {
}
// Apply the filter.
f := filter(&cr, pr, bpp)
f := ftNone
if level != zlib.NoCompression {
f = filter(&cr, pr, bpp)
}
// Write the compressed bytes.
if _, err := zw.Write(cr[f]); err != nil {
......
......@@ -81,20 +81,23 @@ func TestWriterLevels(t *testing.T) {
m := image.NewNRGBA(image.Rect(0, 0, 100, 100))
var b1, b2 bytes.Buffer
var e1, e2 Encoder
if err := e1.Encode(&b1, m); err != nil {
if err := (&Encoder{}).Encode(&b1, m); err != nil {
t.Fatal(err)
}
e2.CompressionLevel = NoCompression
if err := e2.Encode(&b2, m); err != nil {
noenc := &Encoder{CompressionLevel: NoCompression}
if err := noenc.Encode(&b2, m); err != nil {
t.Fatal(err)
}
if b2.Len() <= b1.Len() {
t.Error("DefaultCompression encoding was larger than NoCompression encoding")
}
if _, err := Decode(&b1); err != nil {
t.Error("cannot decode DefaultCompression")
}
if _, err := Decode(&b2); err != nil {
t.Error("cannot decode NoCompression")
}
}
func TestSubImage(t *testing.T) {
......
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