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: result of EncodeAll not viewable in Eye of GNOME #13746

Closed
pierrre opened this Issue Dec 27, 2015 · 10 comments

Comments

Projects
None yet
5 participants
@pierrre
Copy link

pierrre commented Dec 27, 2015

Go version: 1.5.2 & 1.6beta1 linux/amd64
Architecture: Linux pierre-vm 4.2.5-1-ARCH #1 SMP PREEMPT Tue Oct 27 08:13:28 CET 2015 x86_64 GNU/Linux

With this image: https://raw.githubusercontent.com/pierrre/imageserver/master/testdata/animated.gif
Run:

package main

import (
    "bytes"
    "image/gif"
    "io/ioutil"
)

func main() {
    b, err := ioutil.ReadFile("/home/pierre/Go/src/github.com/pierrre/imageserver/testdata/animated.gif")
    if err != nil {
        panic(err)
    }
    g, err := gif.DecodeAll(bytes.NewReader(b))
    if err != nil {
        panic(err)
    }
    buf := new(bytes.Buffer)
    err = gif.EncodeAll(buf, g)
    if err != nil {
        panic(err)
    }
    b = buf.Bytes()
    err = ioutil.WriteFile("test.gif", b, 0644)
    if err != nil {
        panic(err)
    }
}

If I open the encoded image (test.gif) with Eye of GNOME 3.18.1 (default image viewer on Gnome), I get an error message: "Circular table entry in GIF file".

I can open the original image with Eye of GNOME.
I can open the encoded image with Firefox, Chrome, or XnView.

@pierrre

This comment has been minimized.

Copy link

pierrre commented Dec 28, 2015

I have a similar issue with this code:

package main

import (
    "bytes"
    "image"
    "image/color"
    "image/gif"
    "io/ioutil"
)

func main() {
    g := &gif.GIF{
        Image: []*image.Paletted{
            image.NewPaletted(image.Rect(0, 0, 100, 100), color.Palette{color.RGBA{0xff, 0, 0, 0xff}}),
        },
        Delay: []int{
            0,
        },
    }
    buf := new(bytes.Buffer)
    err := gif.EncodeAll(buf, g)
    if err != nil {
        panic(err)
    }
    err = ioutil.WriteFile("test.gif", buf.Bytes(), 0644)
    if err != nil {
        panic(err)
    }
}

Eye of GNOME says: "GIF image loader cannot understand this image."

@rsc rsc changed the title image/gif.EncodeAll(): image is not viewable in Eye of GNOME image/gif: result of EncodeAll not viewable in Eye of GNOME Dec 28, 2015

@rsc

This comment has been minimized.

Copy link
Contributor

rsc commented Dec 28, 2015

/cc @nigeltao

@rsc rsc added this to the Go1.6Maybe milestone Dec 28, 2015

@rsc

This comment has been minimized.

Copy link
Contributor

rsc commented Jan 8, 2016

Animated GIF aficionados will have to wait for Go 1.7.

@rsc rsc modified the milestones: Go1.7, Go1.6Maybe Jan 8, 2016

@nigeltao nigeltao self-assigned this Jan 9, 2016

@nigeltao

This comment has been minimized.

Copy link
Contributor

nigeltao commented Jan 9, 2016

Sorry for the late reply. I've been away for some months now, for non-work-related reasons. I'll look at this for Go 1.7.

@tanepiper

This comment has been minimized.

Copy link

tanepiper commented Apr 22, 2016

go version: go1.6.2 windows/amd64
Platform: Windows 10 Pro

Gahh! So one of the first examples in The Go Programming Language book is the lissajous example (https://github.com/adonovan/gopl.io/blob/master/ch1/lissajous/main.go) and while it outputs a file it appears to be non-valid. This would potentially explain why.

@nigeltao

This comment has been minimized.

Copy link
Contributor

nigeltao commented Apr 28, 2016

@pierrre, I believe that these are bugs with Eye-of-Gnome (i.e with gdk-pixbuf) instead of with Go. In particular, I think that gdk-pixbuf's LZW decompressor is at fault.

For example, the "GIF image loader cannot understand this image" error message comes from https://github.com/GNOME/gdk-pixbuf/blob/master/gdk-pixbuf/io-gif.c#L634 in the lzw_read_byte function, and the comment immediately above that says: "FIXME - we should handle this case".

I filed a bug on the gdk-pixbuf project: https://bugzilla.gnome.org/show_bug.cgi?id=765705

@tanepiper, I need more information than "it appears to be non-valid". What programs did you try and open that output file with? What error messages (if any) did it show? Did you try various browsers: Firefox, Google Chrome, Internet Explorer?

@nigeltao nigeltao closed this Apr 28, 2016

@pierrre

This comment has been minimized.

Copy link

pierrre commented Apr 28, 2016

Thank you !

@tanepiper

This comment has been minimized.

Copy link

tanepiper commented Apr 28, 2016

@nigeltao The above example is in the first chapter of http://www.gopl.io/

The book example actually starts off without the web server, here is my version of it: https://gist.github.com/tanepiper/658606e9c424f876f284f60eeaea16cc

output

I've attached the output gif, the output it compiled with go version go1.6.2 windows/amd64 and as you can see it outputs a gif file of 313kb but invalid.

You are correct in that the web version does seem to work (sorry I passed this example in the book after spending a frutsrating hour trying to get the first version working) but when outputting to a file (e.g. lissajoi.exe > output.gif the writer seems to failing. I've tried various versions of the command (lissajoi.exe 1> output.gif, lissajoi.exe > output.gif 2>&1, etc) and nothing seems to work. I'm thinking now it's either an os.Stdout issue or something on Windows itself but outputting to a file like that should work :(

Anyway appreciate the response and that it's not a issue with the gif library.

@tanepiper

This comment has been minimized.

Copy link

tanepiper commented Apr 28, 2016

Hah! So on a random whim tried it in cmd.exe rather than Powershell and it worked! So it seems it's something screwy with Powershell and Stdout. How annoying 😠

@nigeltao

This comment has been minimized.

Copy link
Contributor

nigeltao commented Apr 28, 2016

Perhaps Powershell is converting "\n" to "\r\n", but that's only a guess, and I don't know how to stop that. I'm not much of a Windows dev.

In your Go program, I suspect that you can work around it by writing to a file (the result of os.Create) instead of to os.Stdout.

@golang golang locked and limited conversation to collaborators Apr 28, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.