107
116
io.WriteString(w, "PLTE {\n")
108
117
for i, c := range cpm {
109
r, g, b, a := c.RGBA()
119
switch c := c.(type) {
121
r, g, b, a = c.R, c.G, c.B, 0xff
123
r, g, b, a = c.R, c.G, c.B, c.A
125
panic("unknown palette color type")
116
130
fmt.Fprintf(w, " (%3d,%3d,%3d) # rgb = (0x%02x,0x%02x,0x%02x)\n", r, g, b, r, g, b)
118
132
io.WriteString(w, "}\n")
222
236
// Compare the two, in SNG format, line by line.
224
ps, perr := pb.ReadString('\n')
225
ss, serr := sb.ReadString('\n')
226
if perr == io.EOF && serr == io.EOF {
244
t.Errorf("%s: Different sizes", fn)
238
250
t.Errorf("%s: Mismatch\n%sversus\n%s\n", fn, ps, ss)
255
t.Error(fn, pb.Err())
258
t.Error(fn, sb.Err())
289
func TestPalettedDecodeConfig(t *testing.T) {
290
for _, fn := range filenamesPaletted {
291
f, err := os.Open("testdata/pngsuite/" + fn + ".png")
293
t.Errorf("%s: open failed: %v", fn, err)
297
cfg, err := DecodeConfig(f)
299
t.Errorf("%s: %v", fn, err)
302
pal, ok := cfg.ColorModel.(color.Palette)
304
t.Errorf("%s: expected paletted color model", fn)
308
t.Errorf("%s: palette not initialized", fn)
314
func benchmarkDecode(b *testing.B, filename string, bytesPerPixel int) {
316
data, err := ioutil.ReadFile(filename)
321
cfg, err := DecodeConfig(strings.NewReader(s))
325
b.SetBytes(int64(cfg.Width * cfg.Height * bytesPerPixel))
327
for i := 0; i < b.N; i++ {
328
Decode(strings.NewReader(s))
332
func BenchmarkDecodeGray(b *testing.B) {
333
benchmarkDecode(b, "testdata/benchGray.png", 1)
336
func BenchmarkDecodeNRGBAGradient(b *testing.B) {
337
benchmarkDecode(b, "testdata/benchNRGBA-gradient.png", 4)
340
func BenchmarkDecodeNRGBAOpaque(b *testing.B) {
341
benchmarkDecode(b, "testdata/benchNRGBA-opaque.png", 4)
344
func BenchmarkDecodePaletted(b *testing.B) {
345
benchmarkDecode(b, "testdata/benchPaletted.png", 1)
348
func BenchmarkDecodeRGB(b *testing.B) {
349
benchmarkDecode(b, "testdata/benchRGB.png", 4)