From 9af7e1b58b58757c789dc0be477d26acd68e77aa Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Wed, 17 Jun 2015 09:10:39 +1000 Subject: [PATCH] tiff: don't apply the 8 bps predictor to a 1 bps image. Change-Id: I112fc7189f8afdd54b96562e1989f9fca1d24d68 Reviewed-on: https://go-review.googlesource.com/11135 Reviewed-by: Benny Siegert Reviewed-by: Nigel Tao --- tiff/reader.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tiff/reader.go b/tiff/reader.go index ecbd474..cf9b5e1 100644 --- a/tiff/reader.go +++ b/tiff/reader.go @@ -216,7 +216,8 @@ func (d *decoder) decode(dst image.Image, xmin, ymin, xmax, ymax int) error { // In this case, p contains the color difference to the preceding pixel. // See page 64-65 of the spec. if d.firstVal(tPredictor) == prHorizontal { - if d.bpp == 16 { + switch d.bpp { + case 16: var off int n := 2 * len(d.features[tBitsPerSample]) // bytes per sample times samples per pixel for y := ymin; y < ymax; y++ { @@ -231,7 +232,7 @@ func (d *decoder) decode(dst image.Image, xmin, ymin, xmax, ymax int) error { off += 2 } } - } else { + case 8: var off int n := 1 * len(d.features[tBitsPerSample]) // bytes per sample times samples per pixel for y := ymin; y < ymax; y++ { @@ -244,6 +245,8 @@ func (d *decoder) decode(dst image.Image, xmin, ymin, xmax, ymax int) error { off++ } } + case 1: + return UnsupportedError("horizontal predictor with 1 BitsPerSample") } }