git.lucas.co / go_mono
git clone https://git.lucas.co/go_mono.git

commit9af7e1b58b58757c789dc0be477d26acd68e77aa
parent3157439762
authorNigel Tao <nigeltao@golang.org>
date2015-06-17 09:10
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 <bsiegert@gmail.com>
Reviewed-by: Nigel Tao <nigeltao@golang.org>

 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")
 		}
 	}