Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

image/gif: LoopCount changes on round trip #11287

Closed
dvyukov opened this issue Jun 19, 2015 · 3 comments
Closed

image/gif: LoopCount changes on round trip #11287

dvyukov opened this issue Jun 19, 2015 · 3 comments
Milestone

Comments

@dvyukov
Copy link
Member

dvyukov commented Jun 19, 2015

The following program:

package main

import (
    "bytes"
    "fmt"
    "image/gif"
)

func main() {
    data := []byte("GIF89a000\x00000,0\x00\x00\x00\n\x00" +
        "\n\x00\x80000000\x02\b\xf01u\xb9\xfdal\x05\x00;")
    img, err := gif.DecodeAll(bytes.NewReader(data))
    if err != nil {
        return
    }
    w := new(bytes.Buffer)
    err = gif.EncodeAll(w, img)
    if err != nil {
        panic(err)
    }
    img1, err := gif.DecodeAll(w)
    if err != nil {
        panic(err)
    }
    fmt.Printf("LoopCount: %v -> %v\n", img.LoopCount, img1.LoopCount)
}

prints:

LoopCount: 0 -> -1

Image should be preserved after Encode/Decode round trip. A more consistent behavior would be to:

  • return error from first Decode for LoopCount=0
  • encode image with LoopCount=0
  • patch LoopCount from 0 to -1 in Decode

Can't find anything definitive in the GIF spec on this.

go version devel +514014c Thu Jun 18 15:54:35 2015 +0200 linux/amd64

@dvyukov
Copy link
Member Author

dvyukov commented Jun 19, 2015

Well, LoopCount of 0 loops like a reasonable value (don't loop). So I think we need to encode it as 0.

@ianlancetaylor ianlancetaylor added this to the Go1.6 milestone Jun 19, 2015
@andybons
Copy link
Member

Agreed that it should encode to 0 as a sane default, but FYI a LoopCount of 0 implies that the image should loop infinitely as opposed to not looping at all. (http://www.vurdalakov.net/misc/gif/netscape-looping-application-extension)

@andybons
Copy link
Member

Rather simplistic fix proposed here: https://go-review.googlesource.com/#/c/11256/

@mikioh mikioh modified the milestones: Go1.5, Go1.6 Jun 23, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants