Commit 62ea2c90 authored by Nigel Tao's avatar Nigel Tao

image/gif: be consistent wrt "color map" or "color table" names.

The spec at http://www.w3.org/Graphics/GIF/spec-gif89a.txt always says
"color table" and not "color map".

Change-Id: I4c172e3ade15618cbd616629822ce7d109a200af
Reviewed-on: https://go-review.googlesource.com/9668Reviewed-by: default avatarRob Pike <r@golang.org>
parent 3120adc2
...@@ -84,13 +84,13 @@ type decoder struct { ...@@ -84,13 +84,13 @@ type decoder struct {
hasTransparentIndex bool hasTransparentIndex bool
// Computed. // Computed.
globalColorMap color.Palette globalColorTable color.Palette
// Used when decoding. // Used when decoding.
delay []int delay []int
disposal []byte disposal []byte
image []*image.Paletted image []*image.Paletted
tmp [1024]byte // must be at least 768 so we can read color map tmp [1024]byte // must be at least 768 so we can read color table
} }
// blockReader parses the block structure of GIF image data, which // blockReader parses the block structure of GIF image data, which
...@@ -166,19 +166,19 @@ func (d *decoder) decode(r io.Reader, configOnly bool) error { ...@@ -166,19 +166,19 @@ func (d *decoder) decode(r io.Reader, configOnly bool) error {
if err != nil { if err != nil {
return err return err
} }
useLocalColorMap := d.imageFields&fColorTable != 0 useLocalColorTable := d.imageFields&fColorTable != 0
if useLocalColorMap { if useLocalColorTable {
m.Palette, err = d.readColorMap(d.imageFields) m.Palette, err = d.readColorTable(d.imageFields)
if err != nil { if err != nil {
return err return err
} }
} else { } else {
m.Palette = d.globalColorMap m.Palette = d.globalColorTable
} }
if d.hasTransparentIndex && int(d.transparentIndex) < len(m.Palette) { if d.hasTransparentIndex && int(d.transparentIndex) < len(m.Palette) {
if !useLocalColorMap { if !useLocalColorTable {
// Clone the global color map. // Clone the global color table.
m.Palette = append(color.Palette(nil), d.globalColorMap...) m.Palette = append(color.Palette(nil), d.globalColorTable...)
} }
m.Palette[d.transparentIndex] = color.RGBA{} m.Palette[d.transparentIndex] = color.RGBA{}
} }
...@@ -262,8 +262,8 @@ func (d *decoder) readHeaderAndScreenDescriptor() error { ...@@ -262,8 +262,8 @@ func (d *decoder) readHeaderAndScreenDescriptor() error {
d.height = int(d.tmp[8]) + int(d.tmp[9])<<8 d.height = int(d.tmp[8]) + int(d.tmp[9])<<8
if fields := d.tmp[10]; fields&fColorTable != 0 { if fields := d.tmp[10]; fields&fColorTable != 0 {
d.backgroundIndex = d.tmp[11] d.backgroundIndex = d.tmp[11]
// readColorMap overwrites the contents of d.tmp, but that's OK. // readColorTable overwrites the contents of d.tmp, but that's OK.
if d.globalColorMap, err = d.readColorMap(fields); err != nil { if d.globalColorTable, err = d.readColorTable(fields); err != nil {
return err return err
} }
} }
...@@ -272,19 +272,18 @@ func (d *decoder) readHeaderAndScreenDescriptor() error { ...@@ -272,19 +272,18 @@ func (d *decoder) readHeaderAndScreenDescriptor() error {
return nil return nil
} }
func (d *decoder) readColorMap(fields byte) (color.Palette, error) { func (d *decoder) readColorTable(fields byte) (color.Palette, error) {
n := 1 << (1 + uint(fields&fColorTableBitsMask)) n := 1 << (1 + uint(fields&fColorTableBitsMask))
_, err := io.ReadFull(d.r, d.tmp[:3*n]) _, err := io.ReadFull(d.r, d.tmp[:3*n])
if err != nil { if err != nil {
return nil, fmt.Errorf("gif: short read on color map: %s", err) return nil, fmt.Errorf("gif: short read on color table: %s", err)
} }
colorMap := make(color.Palette, n) j, p := 0, make(color.Palette, n)
j := 0 for i := range p {
for i := range colorMap { p[i] = color.RGBA{d.tmp[j+0], d.tmp[j+1], d.tmp[j+2], 0xFF}
colorMap[i] = color.RGBA{d.tmp[j+0], d.tmp[j+1], d.tmp[j+2], 0xFF}
j += 3 j += 3
} }
return colorMap, nil return p, nil
} }
func (d *decoder) readExtension() error { func (d *decoder) readExtension() error {
...@@ -428,18 +427,18 @@ type GIF struct { ...@@ -428,18 +427,18 @@ type GIF struct {
// and implies that each frame's disposal method is 0 (no disposal // and implies that each frame's disposal method is 0 (no disposal
// specified). // specified).
Disposal []byte Disposal []byte
// Config is the global color map (palette), width and height. A nil or // Config is the global color table (palette), width and height. A nil or
// empty-color.Palette Config.ColorModel means that each frame has its own // empty-color.Palette Config.ColorModel means that each frame has its own
// color map and there is no global color map. Each frame's bounds must be // color table and there is no global color table. Each frame's bounds must
// within the rectangle defined by the two points (0, 0) and (Config.Width, // be within the rectangle defined by the two points (0, 0) and
// Config.Height). // (Config.Width, Config.Height).
// //
// For backwards compatibility, a zero-valued Config is valid to pass to // For backwards compatibility, a zero-valued Config is valid to pass to
// EncodeAll, and implies that the overall GIF's width and height equals // EncodeAll, and implies that the overall GIF's width and height equals
// the first frame's bounds' Rectangle.Max point. // the first frame's bounds' Rectangle.Max point.
Config image.Config Config image.Config
// BackgroundIndex is the background index in the global color map, for use // BackgroundIndex is the background index in the global color table, for
// with the DisposalBackground disposal method. // use with the DisposalBackground disposal method.
BackgroundIndex byte BackgroundIndex byte
} }
...@@ -456,7 +455,7 @@ func DecodeAll(r io.Reader) (*GIF, error) { ...@@ -456,7 +455,7 @@ func DecodeAll(r io.Reader) (*GIF, error) {
Delay: d.delay, Delay: d.delay,
Disposal: d.disposal, Disposal: d.disposal,
Config: image.Config{ Config: image.Config{
ColorModel: d.globalColorMap, ColorModel: d.globalColorTable,
Width: d.width, Width: d.width,
Height: d.height, Height: d.height,
}, },
...@@ -473,7 +472,7 @@ func DecodeConfig(r io.Reader) (image.Config, error) { ...@@ -473,7 +472,7 @@ func DecodeConfig(r io.Reader) (image.Config, error) {
return image.Config{}, err return image.Config{}, err
} }
return image.Config{ return image.Config{
ColorModel: d.globalColorMap, ColorModel: d.globalColorTable,
Width: d.width, Width: d.width,
Height: d.height, Height: d.height,
}, nil }, nil
......
...@@ -17,8 +17,8 @@ import ( ...@@ -17,8 +17,8 @@ import (
const ( const (
headerStr = "GIF89a" + headerStr = "GIF89a" +
"\x02\x00\x01\x00" + // width=2, height=1 "\x02\x00\x01\x00" + // width=2, height=1
"\x80\x00\x00" // headerFields=(a color map of 2 pixels), backgroundIndex, aspect "\x80\x00\x00" // headerFields=(a color table of 2 pixels), backgroundIndex, aspect
paletteStr = "\x10\x20\x30\x40\x50\x60" // the color map, also known as a palette paletteStr = "\x10\x20\x30\x40\x50\x60" // the color table, also known as a palette
trailerStr = "\x3b" trailerStr = "\x3b"
) )
...@@ -141,7 +141,7 @@ var testGIF = []byte{ ...@@ -141,7 +141,7 @@ var testGIF = []byte{
'G', 'I', 'F', '8', '9', 'a', 'G', 'I', 'F', '8', '9', 'a',
1, 0, 1, 0, // w=1, h=1 (6) 1, 0, 1, 0, // w=1, h=1 (6)
128, 0, 0, // headerFields, bg, aspect (10) 128, 0, 0, // headerFields, bg, aspect (10)
0, 0, 0, 1, 1, 1, // color map and graphics control (13) 0, 0, 0, 1, 1, 1, // color table and graphics control (13)
0x21, 0xf9, 0x04, 0x00, 0x00, 0x00, 0xff, 0x00, // (19) 0x21, 0xf9, 0x04, 0x00, 0x00, 0x00, 0xff, 0x00, // (19)
// frame 1 (0,0 - 1,1) // frame 1 (0,0 - 1,1)
0x2c, 0x2c,
......
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