1
0
mirror of https://github.com/golang/go synced 2024-11-21 15:24:45 -07:00

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

R=nigeltao
CC=golang-dev
https://golang.org/cl/4552042
This commit is contained in:
Rob Pike 2011-05-16 16:00:41 -07:00
parent ff1093852f
commit de7c28fe76
3 changed files with 3 additions and 5 deletions

View File

@ -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},

View File

@ -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 {

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB