go.image/bmp: add a test image for top-down BMPs.
LGTM=ruiu R=ruiu CC=bsiegert, golang-codereviews https://golang.org/cl/149090043
This commit is contained in:
parent
8a2d4aba20
commit
8d4fc1653b
|
@ -5,6 +5,7 @@
|
||||||
package bmp
|
package bmp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -14,10 +15,10 @@ import (
|
||||||
|
|
||||||
const testdataDir = "../testdata/"
|
const testdataDir = "../testdata/"
|
||||||
|
|
||||||
func compare(t *testing.T, img0, img1 image.Image) {
|
func compare(t *testing.T, img0, img1 image.Image) error {
|
||||||
b := img1.Bounds()
|
b := img1.Bounds()
|
||||||
if !b.Eq(img0.Bounds()) {
|
if !b.Eq(img0.Bounds()) {
|
||||||
t.Fatalf("wrong image size: want %s, got %s", img0.Bounds(), b)
|
return fmt.Errorf("wrong image size: want %s, got %s", img0.Bounds(), b)
|
||||||
}
|
}
|
||||||
for y := b.Min.Y; y < b.Max.Y; y++ {
|
for y := b.Min.Y; y < b.Max.Y; y++ {
|
||||||
for x := b.Min.X; x < b.Max.X; x++ {
|
for x := b.Min.X; x < b.Max.X; x++ {
|
||||||
|
@ -26,34 +27,49 @@ func compare(t *testing.T, img0, img1 image.Image) {
|
||||||
r0, g0, b0, a0 := c0.RGBA()
|
r0, g0, b0, a0 := c0.RGBA()
|
||||||
r1, g1, b1, a1 := c1.RGBA()
|
r1, g1, b1, a1 := c1.RGBA()
|
||||||
if r0 != r1 || g0 != g1 || b0 != b1 || a0 != a1 {
|
if r0 != r1 || g0 != g1 || b0 != b1 || a0 != a1 {
|
||||||
t.Fatalf("pixel at (%d, %d) has wrong color: want %v, got %v", x, y, c0, c1)
|
return fmt.Errorf("pixel at (%d, %d) has wrong color: want %v, got %v", x, y, c0, c1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestDecode tests that decoding a PNG image and a BMP image result in the
|
// TestDecode tests that decoding a PNG image and a BMP image result in the
|
||||||
// same pixel data.
|
// same pixel data.
|
||||||
func TestDecode(t *testing.T) {
|
func TestDecode(t *testing.T) {
|
||||||
f0, err := os.Open(testdataDir + "video-001.png")
|
testCases := []string{
|
||||||
if err != nil {
|
"video-001",
|
||||||
t.Fatal(err)
|
"yellow_rose-small",
|
||||||
}
|
|
||||||
defer f0.Close()
|
|
||||||
img0, _, err := image.Decode(f0)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
f1, err := os.Open(testdataDir + "video-001.bmp")
|
for _, tc := range testCases {
|
||||||
if err != nil {
|
f0, err := os.Open(testdataDir + tc + ".png")
|
||||||
t.Fatal(err)
|
if err != nil {
|
||||||
}
|
t.Errorf("%s: Open PNG: %v", tc, err)
|
||||||
defer f1.Close()
|
continue
|
||||||
img1, _, err := image.Decode(f1)
|
}
|
||||||
if err != nil {
|
defer f0.Close()
|
||||||
t.Fatal(err)
|
img0, _, err := image.Decode(f0)
|
||||||
}
|
if err != nil {
|
||||||
|
t.Errorf("%s: Decode PNG: %v", tc, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
compare(t, img0, img1)
|
f1, err := os.Open(testdataDir + tc + ".bmp")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("%s: Open BMP: %v", tc, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
defer f1.Close()
|
||||||
|
img1, _, err := image.Decode(f1)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("%s: Decode BMP: %v", tc, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := compare(t, img0, img1); err != nil {
|
||||||
|
t.Errorf("%s: %v", tc, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
BIN
testdata/yellow_rose-small.bmp
vendored
Normal file
BIN
testdata/yellow_rose-small.bmp
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 822 B |
BIN
testdata/yellow_rose-small.png
vendored
Normal file
BIN
testdata/yellow_rose-small.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 692 B |
Loading…
Reference in New Issue
Block a user