Skip to content

image/gif: LoopCount changes on round trip #11287

Closed
@dvyukov

Description

@dvyukov

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions