if err != nil {
return nil, err
}
- d.mergePassInto(img, imagePass, pass)
+ if imagePass != nil {
+ d.mergePassInto(img, imagePass, pass)
+ }
}
}
// Add the multiplication factor and subtract one, effectively rounding up.
width = (width - p.xOffset + p.xFactor - 1) / p.xFactor
height = (height - p.yOffset + p.yFactor - 1) / p.yFactor
+ // A PNG image can't have zero width or height, but for an interlaced
+ // image, an individual pass might have zero width or height. If so, we
+ // shouldn't even read a per-row filter type byte, so return early.
+ if width == 0 || height == 0 {
+ return nil, nil
+ }
}
switch d.cb {
case cbG1, cbG2, cbG4, cbG8:
cdat[i] += p
}
case ftAverage:
+ // The first column has no column to the left of it, so it is a
+ // special case. We know that the first column exists because we
+ // check above that width != 0, and so len(cdat) != 0.
for i := 0; i < bytesPerPixel; i++ {
cdat[i] += pdat[i] / 2
}
"io"
"io/ioutil"
"os"
+ "reflect"
"strings"
"testing"
)
}
}
+func TestInterlaced(t *testing.T) {
+ a, err := readPNG("testdata/gray-gradient.png")
+ if err != nil {
+ t.Fatal(err)
+ }
+ b, err := readPNG("testdata/gray-gradient.interlaced.png")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !reflect.DeepEqual(a, b) {
+ t.Fatalf("decodings differ:\nnon-interlaced:\n%#v\ninterlaced:\n%#v", a, b)
+ }
+}
+
func TestIncompleteIDATOnRowBoundary(t *testing.T) {
// The following is an invalid 1x2 grayscale PNG image. The header is OK,
// but the zlib-compressed IDAT payload contains two bytes "\x02\x00",