Commit de7c28fe authored by Rob Pike's avatar Rob Pike

image/gif: enable images with <8 bits per pixel.

R=nigeltao
CC=golang-dev
https://golang.org/cl/4552042
parent ff109385
......@@ -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},
......
......@@ -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 {
......
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