err error
// g is a reference to the data that is being encoded.
g *GIF
- // bitsPerPixel is the number of bits required to represent each color
- // in the image.
- bitsPerPixel int
// buf is a scratch buffer. It must be at least 768 so we can write the color map.
buf [1024]byte
}
return
}
- // TODO: This bases the global color table on the first image
- // only.
pm := e.g.Image[0]
// Logical screen width and height.
writeUint16(e.buf[0:2], uint16(pm.Bounds().Dx()))
writeUint16(e.buf[2:4], uint16(pm.Bounds().Dy()))
e.write(e.buf[:4])
- e.bitsPerPixel = log2(len(pm.Palette)) + 1
- e.buf[0] = 0x80 | ((uint8(e.bitsPerPixel) - 1) << 4) | (uint8(e.bitsPerPixel) - 1)
+ // All frames have a local color table, so a global color table
+ // is not needed.
+ e.buf[0] = 0x00
e.buf[1] = 0x00 // Background Color Index.
e.buf[2] = 0x00 // Pixel Aspect Ratio.
e.write(e.buf[:3])
- // Global Color Table.
- e.writeColorTable(pm.Palette, e.bitsPerPixel-1)
-
// Add animation info if necessary.
if len(e.g.Image) > 1 {
e.buf[0] = 0x21 // Extension Introducer.
// Local Color Table.
e.writeColorTable(pm.Palette, paddedSize)
- litWidth := e.bitsPerPixel
+ litWidth := paddedSize + 1
if litWidth < 2 {
litWidth = 2
}