1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
16 func diff(m0, m1 image.Image) os.Error {
17 b0, b1 := m0.Bounds(), m1.Bounds()
19 return fmt.Errorf("dimensions differ: %v vs %v", b0, b1)
21 for y := b0.Min.Y; y < b0.Max.Y; y++ {
22 for x := b0.Min.X; x < b0.Max.X; x++ {
23 r0, g0, b0, a0 := m0.At(x, y).RGBA()
24 r1, g1, b1, a1 := m1.At(x, y).RGBA()
25 if r0 != r1 || g0 != g1 || b0 != b1 || a0 != a1 {
26 return fmt.Errorf("colors differ at (%d, %d): %v vs %v", x, y, m0.At(x, y), m1.At(x, y))
33 func TestWriter(t *testing.T) {
34 // The filenames variable is declared in reader_test.go.
37 names = filenamesShort
39 for _, fn := range names {
40 qfn := "testdata/pngsuite/" + fn + ".png"
42 m0, err := readPng(qfn)
47 // Read the image again, and push it through a pipe that encodes at the write end, and decodes at the read end.
52 m1, err := readPng(qfn)
77 func BenchmarkEncodePaletted(b *testing.B) {
79 img := image.NewPaletted(640, 480,
81 image.RGBAColor{0, 0, 0, 255},
82 image.RGBAColor{255, 255, 255, 255},
84 b.SetBytes(640 * 480 * 1)
86 for i := 0; i < b.N; i++ {
87 Encode(ioutil.Discard, img)
91 func BenchmarkEncodeRGBOpaque(b *testing.B) {
93 img := image.NewRGBA(640, 480)
94 // Set all pixels to 0xFF alpha to force opaque mode.
96 for y := bo.Min.Y; y < bo.Max.Y; y++ {
97 for x := bo.Min.X; x < bo.Max.X; x++ {
98 img.Set(x, y, image.RGBAColor{0, 0, 0, 255})
102 panic("expected image to be opaque")
104 b.SetBytes(640 * 480 * 4)
106 for i := 0; i < b.N; i++ {
107 Encode(ioutil.Discard, img)
111 func BenchmarkEncodeRGBA(b *testing.B) {
113 img := image.NewRGBA(640, 480)
115 panic("expected image to not be opaque")
117 b.SetBytes(640 * 480 * 4)
119 for i := 0; i < b.N; i++ {
120 Encode(ioutil.Discard, img)