diff --git a/src/pkg/image/decode_test.go b/src/pkg/image/decode_test.go index a0fba6fdbaa..c957c8209e9 100644 --- a/src/pkg/image/decode_test.go +++ b/src/pkg/image/decode_test.go @@ -30,6 +30,7 @@ var imageTests = []imageTest{ // to GIF loses significant image quality. {"testdata/video-001.gif", 64 << 8}, {"testdata/video-001.interlaced.gif", 64 << 8}, + {"testdata/video-001.5bpp.gif", 128 << 8}, // JPEG is a lossy format and hence needs a non-zero tolerance. {"testdata/video-001.jpeg", 8 << 8}, {"testdata/video-001.png", 0}, diff --git a/src/pkg/image/gif/reader.go b/src/pkg/image/gif/reader.go index e27b74b64da..5dd404036ce 100644 --- a/src/pkg/image/gif/reader.go +++ b/src/pkg/image/gif/reader.go @@ -173,11 +173,10 @@ Loop: if err != nil { return err } - if litWidth > 8 { + if litWidth < 2 || litWidth > 8 { return fmt.Errorf("gif: pixel size in decode out of range: %d", litWidth) } - // A wonderfully Go-like piece of magic. Unfortunately it's only at its - // best for 8-bit pixels. + // A wonderfully Go-like piece of magic. lzwr := lzw.NewReader(&blockReader{r: d.r}, lzw.LSB, int(litWidth)) if _, err = io.ReadFull(lzwr, m.Pix); err != nil { break @@ -379,7 +378,6 @@ func (d *decoder) uninterlace(m *image.Paletted) { // Decode reads a GIF image from r and returns the first embedded // image as an image.Image. -// Limitation: The file must be 8 bits per pixel. func Decode(r io.Reader) (image.Image, os.Error) { var d decoder if err := d.decode(r, false); err != nil { @@ -397,7 +395,6 @@ type GIF struct { // DecodeAll reads a GIF image from r and returns the sequential frames // and timing information. -// Limitation: The file must be 8 bits per pixel. func DecodeAll(r io.Reader) (*GIF, os.Error) { var d decoder if err := d.decode(r, false); err != nil { diff --git a/src/pkg/image/testdata/video-001.5bpp.gif b/src/pkg/image/testdata/video-001.5bpp.gif new file mode 100644 index 00000000000..ce53104b2d2 Binary files /dev/null and b/src/pkg/image/testdata/video-001.5bpp.gif differ