You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import (
"bytes""fmt""image/color""image/gif""io/ioutil"
)
funcmain() {
b, err:=ioutil.ReadFile("/home/pierre/Go/src/github.com/pierrre/imageserver/testdata/animated.gif")
iferr!=nil {
panic(err)
}
g, err:=gif.DecodeAll(bytes.NewReader(b))
iferr!=nil {
panic(err)
}
ifg.Config.ColorModel==nil {
fmt.Println("no global color model")
return
}
pa, ok:=g.Config.ColorModel.(color.Palette)
if!ok {
fmt.Println("global color model is not a Palette")
return
}
iflen(pa) ==0 {
fmt.Println("global palette is empty")
return
}
fori, p:=rangeg.Image {
iflen(p.Palette) !=len(pa) {
fmt.Printf("image %d: palette length is not equal: current=%d, global=%d\n", i, len(p.Palette), len(pa))
continue
}
forj:=rangep.Palette {
ifp.Palette[j] !=pa[j] {
fmt.Printf("image %d: palette index %d: color is not equal: current=%#v, global=%#v\n", i, j, p.Palette[j], pa[j])
}
}
}
fmt.Printf("background index: %d\n", g.BackgroundIndex)
}
I get:
image 0: palette index 255: color is not equal: current=color.RGBA{R:0x0, G:0x0, B:0x0, A:0x0}, global=color.RGBA{R:0xff, G:0xff, B:0xff, A:0xff}
image 1: palette index 255: color is not equal: current=color.RGBA{R:0x0, G:0x0, B:0x0, A:0x0}, global=color.RGBA{R:0xff, G:0xff, B:0xff, A:0xff}
image 2: palette index 255: color is not equal: current=color.RGBA{R:0x0, G:0x0, B:0x0, A:0x0}, global=color.RGBA{R:0xff, G:0xff, B:0xff, A:0xff}
image 3: palette index 255: color is not equal: current=color.RGBA{R:0x0, G:0x0, B:0x0, A:0x0}, global=color.RGBA{R:0xff, G:0xff, B:0xff, A:0xff}
image 4: palette index 255: color is not equal: current=color.RGBA{R:0x0, G:0x0, B:0x0, A:0x0}, global=color.RGBA{R:0xff, G:0xff, B:0xff, A:0xff}
image 5: palette index 255: color is not equal: current=color.RGBA{R:0x0, G:0x0, B:0x0, A:0x0}, global=color.RGBA{R:0xff, G:0xff, B:0xff, A:0xff}
image 6: palette index 255: color is not equal: current=color.RGBA{R:0x0, G:0x0, B:0x0, A:0x0}, global=color.RGBA{R:0xff, G:0xff, B:0xff, A:0xff}
image 7: palette index 255: color is not equal: current=color.RGBA{R:0x0, G:0x0, B:0x0, A:0x0}, global=color.RGBA{R:0xff, G:0xff, B:0xff, A:0xff}
image 8: palette index 255: color is not equal: current=color.RGBA{R:0x0, G:0x0, B:0x0, A:0x0}, global=color.RGBA{R:0xff, G:0xff, B:0xff, A:0xff}
image 9: palette index 255: color is not equal: current=color.RGBA{R:0x0, G:0x0, B:0x0, A:0x0}, global=color.RGBA{R:0xff, G:0xff, B:0xff, A:0xff}
image 10: palette index 255: color is not equal: current=color.RGBA{R:0x0, G:0x0, B:0x0, A:0x0}, global=color.RGBA{R:0xff, G:0xff, B:0xff, A:0xff}
image 11: palette index 255: color is not equal: current=color.RGBA{R:0x0, G:0x0, B:0x0, A:0x0}, global=color.RGBA{R:0xff, G:0xff, B:0xff, A:0xff}
image 12: palette index 255: color is not equal: current=color.RGBA{R:0x0, G:0x0, B:0x0, A:0x0}, global=color.RGBA{R:0xff, G:0xff, B:0xff, A:0xff}
image 13: palette index 255: color is not equal: current=color.RGBA{R:0x0, G:0x0, B:0x0, A:0x0}, global=color.RGBA{R:0xff, G:0xff, B:0xff, A:0xff}
image 14: palette index 255: color is not equal: current=color.RGBA{R:0x0, G:0x0, B:0x0, A:0x0}, global=color.RGBA{R:0xff, G:0xff, B:0xff, A:0xff}
image 15: palette index 255: color is not equal: current=color.RGBA{R:0x0, G:0x0, B:0x0, A:0x0}, global=color.RGBA{R:0xff, G:0xff, B:0xff, A:0xff}
image 16: palette index 255: color is not equal: current=color.RGBA{R:0x0, G:0x0, B:0x0, A:0x0}, global=color.RGBA{R:0xff, G:0xff, B:0xff, A:0xff}
image 17: palette index 255: color is not equal: current=color.RGBA{R:0x0, G:0x0, B:0x0, A:0x0}, global=color.RGBA{R:0xff, G:0xff, B:0xff, A:0xff}
image 18: palette index 255: color is not equal: current=color.RGBA{R:0x0, G:0x0, B:0x0, A:0x0}, global=color.RGBA{R:0xff, G:0xff, B:0xff, A:0xff}
image 19: palette index 255: color is not equal: current=color.RGBA{R:0x0, G:0x0, B:0x0, A:0x0}, global=color.RGBA{R:0xff, G:0xff, B:0xff, A:0xff}
image 20: palette index 255: color is not equal: current=color.RGBA{R:0x0, G:0x0, B:0x0, A:0x0}, global=color.RGBA{R:0xff, G:0xff, B:0xff, A:0xff}
image 21: palette index 255: color is not equal: current=color.RGBA{R:0x0, G:0x0, B:0x0, A:0x0}, global=color.RGBA{R:0xff, G:0xff, B:0xff, A:0xff}
image 22: palette index 255: color is not equal: current=color.RGBA{R:0x0, G:0x0, B:0x0, A:0x0}, global=color.RGBA{R:0xff, G:0xff, B:0xff, A:0xff}
image 23: palette index 255: color is not equal: current=color.RGBA{R:0x0, G:0x0, B:0x0, A:0x0}, global=color.RGBA{R:0xff, G:0xff, B:0xff, A:0xff}
image 24: palette index 255: color is not equal: current=color.RGBA{R:0x0, G:0x0, B:0x0, A:0x0}, global=color.RGBA{R:0xff, G:0xff, B:0xff, A:0xff}
image 25: palette index 255: color is not equal: current=color.RGBA{R:0x0, G:0x0, B:0x0, A:0x0}, global=color.RGBA{R:0xff, G:0xff, B:0xff, A:0xff}
image 26: palette index 255: color is not equal: current=color.RGBA{R:0x0, G:0x0, B:0x0, A:0x0}, global=color.RGBA{R:0xff, G:0xff, B:0xff, A:0xff}
image 27: palette index 255: color is not equal: current=color.RGBA{R:0x0, G:0x0, B:0x0, A:0x0}, global=color.RGBA{R:0xff, G:0xff, B:0xff, A:0xff}
image 28: palette index 255: color is not equal: current=color.RGBA{R:0x0, G:0x0, B:0x0, A:0x0}, global=color.RGBA{R:0xff, G:0xff, B:0xff, A:0xff}
image 29: palette index 255: color is not equal: current=color.RGBA{R:0x0, G:0x0, B:0x0, A:0x0}, global=color.RGBA{R:0xff, G:0xff, B:0xff, A:0xff}
image 30: palette index 255: color is not equal: current=color.RGBA{R:0x0, G:0x0, B:0x0, A:0x0}, global=color.RGBA{R:0xff, G:0xff, B:0xff, A:0xff}
image 31: palette index 255: color is not equal: current=color.RGBA{R:0x0, G:0x0, B:0x0, A:0x0}, global=color.RGBA{R:0xff, G:0xff, B:0xff, A:0xff}
image 32: palette index 255: color is not equal: current=color.RGBA{R:0x0, G:0x0, B:0x0, A:0x0}, global=color.RGBA{R:0xff, G:0xff, B:0xff, A:0xff}
image 33: palette index 255: color is not equal: current=color.RGBA{R:0x0, G:0x0, B:0x0, A:0x0}, global=color.RGBA{R:0xff, G:0xff, B:0xff, A:0xff}
image 34: palette index 255: color is not equal: current=color.RGBA{R:0x0, G:0x0, B:0x0, A:0x0}, global=color.RGBA{R:0xff, G:0xff, B:0xff, A:0xff}
image 35: palette index 255: color is not equal: current=color.RGBA{R:0x0, G:0x0, B:0x0, A:0x0}, global=color.RGBA{R:0xff, G:0xff, B:0xff, A:0xff}
background index: 255
At index 255, the color is transparent in all frames, and white in the global palette.
If the ColorModel is defined in GIF, and it's a non empty Palette, I expect to have the same Palette in all frames.
Is it related to the background color index?
Thank you.
The text was updated successfully, but these errors were encountered:
rsc
changed the title
image/gif.GIF: last color in Palette is different
image/gif: last color in per-image Palette is different from global Palette
Dec 28, 2015
Yes, that's probably why. The background color index says that that color is "transparent", meaning R=G=B=A=0. White would be R=G=B=A=0xFF, and black would be R=G=B=0, A=0xFF. So the global palette says white, but the per-image palette correctly says transparent. But I still don't understand why the global palette doesn't report transparent too.
Background Color Index (a property of the Global Color Table) is defined in section 18.
Transparent Color Index (a property of a Local Color Table) is defined in section 23. Transparency is important when composing successive frames, using the "Do not dispose" disposal method, but a limitation of the GIF format is that none of the Global Color Table's entries can be transparent.
Note that, even without a Transparent Color Index set, a frame of an animated GIF can have a different ColorModel (i.e. palette) than the overall global ColorModel. See section 21 re Local Color Tables.
Go version: 1.5.2 & 1.6beta1
I tried to decode an animated GIF image. (https://raw.githubusercontent.com/pierrre/imageserver/master/testdata/animated.gif)
I get a GIF with a
Palette
ColorModel
, and a slice ofPaletted
images.If I compare the global palette, with the palette of each frame, the last color is different.
I wrote a small program:
I get:
At index 255, the color is transparent in all frames, and white in the global palette.
If the
ColorModel
is defined inGIF
, and it's a non emptyPalette
, I expect to have the samePalette
in all frames.Is it related to the background color index?
Thank you.
The text was updated successfully, but these errors were encountered: