Commit a6f95ad3 authored by Andrew Bonventre's avatar Andrew Bonventre Committed by Nigel Tao

image/gif: don't write superfluous global color table

R=r, nigeltao
CC=golang-dev
https://golang.org/cl/11446043
parent c5c52f07
......@@ -52,9 +52,6 @@ type encoder struct {
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
}
......@@ -118,23 +115,19 @@ func (e *encoder) writeHeader() {
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.
......@@ -232,7 +225,7 @@ func (e *encoder) writeImageBlock(pm *image.Paletted, delay int) {
// Local Color Table.
e.writeColorTable(pm.Palette, paddedSize)
litWidth := e.bitsPerPixel
litWidth := paddedSize + 1
if litWidth < 2 {
litWidth = 2
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment