image/gif: set default loop count to 0 when app ext. is not present

It was otherwise not being preserved across
specific Decode->Encode->Decode calls.

Fixes #11287

Change-Id: I40602da7fa39ec67403bed52ff403f361c6171bb
Reviewed-on: https://go-review.googlesource.com/11256
Reviewed-by: Nigel Tao <nigeltao@golang.org>
This commit is contained in:
Andrew Bonventre 2015-06-19 13:29:58 -04:00 committed by Nigel Tao
parent f2662f2c93
commit 4bba6729f8
2 changed files with 21 additions and 1 deletions

View File

@ -271,7 +271,6 @@ func (d *decoder) readHeaderAndScreenDescriptor() error {
}
}
// d.tmp[12] is the Pixel Aspect Ratio, which is ignored.
d.loopCount = -1
return nil
}

View File

@ -253,3 +253,24 @@ func TestPixelOutsidePaletteRange(t *testing.T) {
try(t, b.Bytes(), want)
}
}
func TestLoopCount(t *testing.T) {
data := []byte("GIF89a000\x00000,0\x00\x00\x00\n\x00" +
"\n\x00\x80000000\x02\b\xf01u\xb9\xfdal\x05\x00;")
img, err := DecodeAll(bytes.NewReader(data))
if err != nil {
t.Fatal("DecodeAll:", err)
}
w := new(bytes.Buffer)
err = EncodeAll(w, img)
if err != nil {
t.Fatal("EncodeAll:", err)
}
img1, err := DecodeAll(w)
if err != nil {
t.Fatal("DecodeAll:", err)
}
if img.LoopCount != img1.LoopCount {
t.Errorf("loop count mismatch: %d vs %d", img.LoopCount, img1.LoopCount)
}
}