summaryrefslogtreecommitdiff
path: root/src/pkg/image/png/writer_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/image/png/writer_test.go')
-rw-r--r--src/pkg/image/png/writer_test.go27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/pkg/image/png/writer_test.go b/src/pkg/image/png/writer_test.go
index a61e1c95a..f218a5564 100644
--- a/src/pkg/image/png/writer_test.go
+++ b/src/pkg/image/png/writer_test.go
@@ -5,6 +5,7 @@
package png
import (
+ "bytes"
"fmt"
"image"
"io"
@@ -13,15 +14,16 @@ import (
)
func diff(m0, m1 image.Image) os.Error {
- if m0.Width() != m1.Width() || m0.Height() != m1.Height() {
- return os.NewError(fmt.Sprintf("dimensions differ: %dx%d vs %dx%d", m0.Width(), m0.Height(), m1.Width(), m1.Height()))
+ b0, b1 := m0.Bounds(), m1.Bounds()
+ if !b0.Eq(b1) {
+ return fmt.Errorf("dimensions differ: %v vs %v", b0, b1)
}
- for y := 0; y < m0.Height(); y++ {
- for x := 0; x < m0.Width(); x++ {
+ for y := b0.Min.Y; y < b0.Max.Y; y++ {
+ for x := b0.Min.X; x < b0.Max.X; x++ {
r0, g0, b0, a0 := m0.At(x, y).RGBA()
r1, g1, b1, a1 := m1.At(x, y).RGBA()
if r0 != r1 || g0 != g1 || b0 != b1 || a0 != a1 {
- return os.NewError(fmt.Sprintf("colors differ at (%d, %d): %v vs %v", x, y, m0.At(x, y), m1.At(x, y)))
+ return fmt.Errorf("colors differ at (%d, %d): %v vs %v", x, y, m0.At(x, y), m1.At(x, y))
}
}
}
@@ -67,3 +69,18 @@ func TestWriter(t *testing.T) {
}
}
}
+
+func BenchmarkEncodePaletted(b *testing.B) {
+ b.StopTimer()
+ img := image.NewPaletted(640, 480,
+ []image.Color{
+ image.RGBAColor{0, 0, 0, 255},
+ image.RGBAColor{255, 255, 255, 255},
+ })
+ b.StartTimer()
+ buffer := new(bytes.Buffer)
+ for i := 0; i < b.N; i++ {
+ buffer.Reset()
+ Encode(buffer, img)
+ }
+}