Commit 9d6e0274 authored by Volker Dobler's avatar Volker Dobler Committed by Nigel Tao

image/png: always set up palette during DecodeConfig

The old code would decode the palette only for 8-bit
images during a DecodeConfig.
This CL keeps the behavior for 8-bit images and sets
up the decoded palette also for 1, 2 and 4-bit images.

Fixes #4279.

R=golang-dev, nigeltao
CC=golang-dev
https://golang.org/cl/7421048
parent 15825dc9
......@@ -652,10 +652,11 @@ func DecodeConfig(r io.Reader) (image.Config, error) {
}
return image.Config{}, err
}
if d.stage == dsSeenIHDR && d.cb != cbP8 {
paletted := d.cb == cbP8 || d.cb == cbP4 || d.cb == cbP2 || d.cb == cbP1
if d.stage == dsSeenIHDR && !paletted {
break
}
if d.stage == dsSeenPLTE && d.cb == cbP8 {
if d.stage == dsSeenPLTE && paletted {
break
}
}
......
......@@ -38,6 +38,14 @@ var filenames = []string{
"basn6a16",
}
var filenamesPaletted = []string{
"basn3p01",
"basn3p02",
"basn3p04",
"basn3p08",
"basn3p08-trns",
}
var filenamesShort = []string{
"basn0g01",
"basn0g04-31",
......@@ -278,6 +286,31 @@ func TestReaderError(t *testing.T) {
}
}
func TestPalettedDecodeConfig(t *testing.T) {
for _, fn := range filenamesPaletted {
f, err := os.Open("testdata/pngsuite/" + fn + ".png")
if err != nil {
t.Errorf("%s: open failed: %v", fn, err)
continue
}
defer f.Close()
cfg, err := DecodeConfig(f)
if err != nil {
t.Errorf("%s: %v", fn, err)
continue
}
pal, ok := cfg.ColorModel.(color.Palette)
if !ok {
t.Errorf("%s: expected paletted color model", fn)
continue
}
if pal == nil {
t.Errorf("%s: palette not initialized", fn)
continue
}
}
}
func benchmarkDecode(b *testing.B, filename string, bytesPerPixel int) {
b.StopTimer()
data, err := ioutil.ReadFile(filename)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment