diff --git a/testdata/no_compress.tiff b/testdata/no_compress.tiff new file mode 100644 index 0000000..3f72b29 Binary files /dev/null and b/testdata/no_compress.tiff differ diff --git a/tiff/reader.go b/tiff/reader.go index fcb2b56..ea4f1f2 100644 --- a/tiff/reader.go +++ b/tiff/reader.go @@ -11,6 +11,7 @@ import ( "compress/lzw" "compress/zlib" "encoding/binary" + "fmt" "image" "image/color" "io" @@ -553,7 +554,11 @@ func Decode(r io.Reader) (img image.Image, err error) { offset := int64(blockOffsets[j*blocksAcross+i]) n := int64(blockCounts[j*blocksAcross+i]) switch d.firstVal(tCompression) { - case cNone: + + // According to the spec, Compression does not have a default value, + // but some tools interpret a missing Compression value as none so we do + // the same. + case cNone, 0: if b, ok := d.r.(*buffer); ok { d.buf, err = b.Slice(int(offset), int(n)) } else { @@ -574,7 +579,7 @@ func Decode(r io.Reader) (img image.Image, err error) { case cPackBits: d.buf, err = unpackBits(io.NewSectionReader(d.r, offset, n)) default: - err = UnsupportedError("compression") + err = UnsupportedError(fmt.Sprintf("compression value %d", d.firstVal(tCompression))) } if err != nil { return nil, err diff --git a/tiff/reader_test.go b/tiff/reader_test.go index 8539e9c..d62e277 100644 --- a/tiff/reader_test.go +++ b/tiff/reader_test.go @@ -44,6 +44,15 @@ func TestNoRPS(t *testing.T) { } } +// TestNoCompression tries to decode an images that has no Compression tag. +// This tag is mandatory, but most tools interpret a missing value as no compression. +func TestNoCompression(t *testing.T) { + _, err := load("no_compress.tiff") + if err != nil { + t.Fatal(err) + } +} + // TestUnpackBits tests the decoding of PackBits-encoded data. func TestUnpackBits(t *testing.T) { var unpackBitsTests = []struct {