imageFields byte
// From graphics control.
- transparentIndex byte
+ transparentIndex byte
+ hasTransparentIndex bool
// Computed.
pixelSize uint
if err != nil {
return err
}
- // TODO: do we set transparency in this map too? That would be
- // d.setTransparency(m.Palette)
} else {
m.Palette = d.globalColorMap
}
+ if d.hasTransparentIndex && int(d.transparentIndex) < len(m.Palette) {
+ m.Palette[d.transparentIndex] = color.RGBA{}
+ }
litWidth, err := d.r.ReadByte()
if err != nil {
return err
d.image = append(d.image, m)
d.delay = append(d.delay, d.delayTime)
- d.delayTime = 0 // TODO: is this correct, or should we hold on to the value?
+ // The GIF89a spec, Section 23 (Graphic Control Extension) says:
+ // "The scope of this extension is the first graphic rendering block
+ // to follow." We therefore reset the GCE fields to zero.
+ d.delayTime = 0
+ d.hasTransparentIndex = false
case sTrailer:
if len(d.image) == 0 {
d.delayTime = int(d.tmp[2]) | int(d.tmp[3])<<8
if d.flags&gcTransparentColorSet != 0 {
d.transparentIndex = d.tmp[4]
- d.setTransparency(d.globalColorMap)
+ d.hasTransparentIndex = true
}
return nil
}
-func (d *decoder) setTransparency(colorMap color.Palette) {
- if int(d.transparentIndex) < len(colorMap) {
- colorMap[d.transparentIndex] = color.RGBA{}
- }
-}
-
func (d *decoder) newImageFromDescriptor() (*image.Paletted, error) {
if _, err := io.ReadFull(d.r, d.tmp[0:9]); err != nil {
return nil, fmt.Errorf("gif: can't read image descriptor: %s", err)