mirror of
https://github.com/golang/go
synced 2024-11-26 18:16:48 -07:00
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
This commit is contained in:
parent
15825dc935
commit
9d6e02742c
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user