summaryrefslogtreecommitdiff
path: root/libgo/go/image/png/reader_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/image/png/reader_test.go')
-rw-r--r--libgo/go/image/png/reader_test.go57
1 files changed, 42 insertions, 15 deletions
diff --git a/libgo/go/image/png/reader_test.go b/libgo/go/image/png/reader_test.go
index fefceee3a5d..8314a833877 100644
--- a/libgo/go/image/png/reader_test.go
+++ b/libgo/go/image/png/reader_test.go
@@ -13,23 +13,23 @@ import (
"testing"
)
-// The go PNG library currently supports only a subset of the full PNG specification.
-// In particular, bit depths other than 8 or 16 are not supported, nor are grayscale-
-// alpha images.
var filenames = []string{
- //"basn0g01", // bit depth is not 8 or 16
- //"basn0g02", // bit depth is not 8 or 16
- //"basn0g04", // bit depth is not 8 or 16
+ "basn0g01",
+ "basn0g01-30",
+ "basn0g02",
+ "basn0g02-29",
+ "basn0g04",
+ "basn0g04-31",
"basn0g08",
"basn0g16",
"basn2c08",
"basn2c16",
- //"basn3p01", // bit depth is not 8 or 16
- //"basn3p02", // bit depth is not 8 or 16
- //"basn3p04", // bit depth is not 8 or 16
+ "basn3p01",
+ "basn3p02",
+ "basn3p04",
"basn3p08",
- //"basn4a08", // grayscale-alpha color model
- //"basn4a16", // grayscale-alpha color model
+ "basn4a08",
+ "basn4a16",
"basn6a08",
"basn6a16",
}
@@ -58,7 +58,16 @@ func sng(w io.WriteCloser, filename string, png image.Image) {
cpm, _ := cm.(image.PalettedColorModel)
var paletted *image.Paletted
if cpm != nil {
- bitdepth = 8
+ switch {
+ case len(cpm) <= 2:
+ bitdepth = 1
+ case len(cpm) <= 4:
+ bitdepth = 2
+ case len(cpm) <= 16:
+ bitdepth = 4
+ default:
+ bitdepth = 8
+ }
paletted = png.(*image.Paletted)
}
@@ -131,8 +140,15 @@ func sng(w io.WriteCloser, filename string, png image.Image) {
fmt.Fprintf(w, "%04x%04x%04x%04x ", nrgba64.R, nrgba64.G, nrgba64.B, nrgba64.A)
}
case cpm != nil:
+ var b, c int
for x := bounds.Min.X; x < bounds.Max.X; x++ {
- fmt.Fprintf(w, "%02x", paletted.ColorIndexAt(x, y))
+ b = b<<uint(bitdepth) | int(paletted.ColorIndexAt(x, y))
+ c++
+ if c == 8/bitdepth {
+ fmt.Fprintf(w, "%02x", b)
+ b = 0
+ c = 0
+ }
}
}
io.WriteString(w, "\n")
@@ -143,14 +159,25 @@ func sng(w io.WriteCloser, filename string, png image.Image) {
func TestReader(t *testing.T) {
for _, fn := range filenames {
// Read the .png file.
- image, err := readPng("testdata/pngsuite/" + fn + ".png")
+ img, err := readPng("testdata/pngsuite/" + fn + ".png")
if err != nil {
t.Error(fn, err)
continue
}
+
+ if fn == "basn4a16" {
+ // basn4a16.sng is gray + alpha but sng() will produce true color + alpha
+ // so we just check a single random pixel.
+ c := img.At(2, 1).(image.NRGBA64Color)
+ if c.R != 0x11a7 || c.G != 0x11a7 || c.B != 0x11a7 || c.A != 0x1085 {
+ t.Error(fn, fmt.Errorf("wrong pixel value at (2, 1): %x", c))
+ }
+ continue
+ }
+
piper, pipew := io.Pipe()
pb := bufio.NewReader(piper)
- go sng(pipew, fn, image)
+ go sng(pipew, fn, img)
defer piper.Close()
// Read the .sng file.