From de7c28fe7689fccbf7b415eb5f5defb8b43ba390 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Mon, 16 May 2011 16:00:41 -0700 Subject: [PATCH] image/gif: enable images with <8 bits per pixel. R=nigeltao CC=golang-dev https://golang.org/cl/4552042 --- src/pkg/image/decode_test.go | 1 + src/pkg/image/gif/reader.go | 7 ++----- src/pkg/image/testdata/video-001.5bpp.gif | Bin 0 -> 6214 bytes 3 files changed, 3 insertions(+), 5 deletions(-) create mode 100644 src/pkg/image/testdata/video-001.5bpp.gif diff --git a/src/pkg/image/decode_test.go b/src/pkg/image/decode_test.go index a0fba6fdba..c957c8209e 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 e27b74b64d..5dd404036c 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 0000000000000000000000000000000000000000..ce53104b2d2d3405cfdbda4a40751dc1a6d6431d GIT binary patch literal 6214 zcmV-M7`f+1Nk%w1VU_@A0Q3L=4iE_|4+bwZFCZo!dJ+ItEEhLJIb2CHPf$v2UQ{?i zMu!*xkS+nAI~12k1f^5~q+=VNZdl28T+@+rv50IUV#=qRn)0uc-m94U&a(2?u>9=L z`T6?h*V3xI)=Z7rA^8LV00000EC2ui0G0q}000I4AVDl6DW0NPmP^}?@avj$E!!!H z>$iQ2fPjm^^Z6P^V=Rd}%~mQND_NVmpww!Xnj#be1>$y0WIFPojY{KHNVHM00j+VrnbsQHLI+ehds!_p>N5J zu3rJR3#XI5mM+$LYeY^&<}lDS+a%LhmG?uv{O2?C0h)<`H$-1A0;|x8AxA6FyjI>? zZQ4h%pT#7r|L{L4yX+ z&!MA)jGcQvvuSM=$$91Uu?G>x@%}_W1m4{xLT1BBFo6UGI3QO~O#}kgJYG;>AAK9t z_aO$MRp-%xAvvZHNYw$j-w-Ie!;yiMh#~=l7i4fj1P=Iu*#i<#aF>vV)pki;D3~J+ zdtP7=;szXq2%>%UMSxgAP9av=KaTO25Q51tAP$&K86`pl4M?Ct25f@nqXZ8?z~BK< zEv1T4NHDNoPV(4NlouI1Nu`t@(wBjit6_OqVj$6`R*U@cu@+QEUU}YvTVcSaju%`Y zftV0rpuq$ThSn$-e8y9i2nEb%pQsyTQ0N8r<(PqPv~`&!U5QoHSRV@ody_&UaHJ$Z z&)kGn0|gMEDW{xX0P6-5{u~fN1Yps4Tnk}r*j{42X&|boYs&gzr|2GS2OhW(u;oZr3!|%@lIf-Z*C!>3q}Br2It1)#j!mpl&?&hgnt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