Update Go library to r60.
From-SVN: r178910
This commit is contained in:
parent
5548ca3540
commit
adb0401dac
718 changed files with 58911 additions and 30469 deletions
|
@ -10,29 +10,34 @@ import (
|
|||
"os"
|
||||
"testing"
|
||||
|
||||
// TODO(nigeltao): implement bmp decoder.
|
||||
_ "image/bmp"
|
||||
_ "image/gif"
|
||||
_ "image/jpeg"
|
||||
_ "image/png"
|
||||
_ "image/tiff"
|
||||
)
|
||||
|
||||
const goldenFile = "testdata/video-001.png"
|
||||
|
||||
type imageTest struct {
|
||||
filename string
|
||||
tolerance int
|
||||
goldenFilename string
|
||||
filename string
|
||||
tolerance int
|
||||
}
|
||||
|
||||
var imageTests = []imageTest{
|
||||
//{"testdata/video-001.bmp", 0},
|
||||
{"testdata/video-001.png", "testdata/video-001.bmp", 0},
|
||||
// GIF images are restricted to a 256-color palette and the conversion
|
||||
// to GIF loses significant image quality.
|
||||
{"testdata/video-001.gif", 64 << 8},
|
||||
{"testdata/video-001.png", "testdata/video-001.gif", 64 << 8},
|
||||
{"testdata/video-001.png", "testdata/video-001.interlaced.gif", 64 << 8},
|
||||
{"testdata/video-001.png", "testdata/video-001.5bpp.gif", 128 << 8},
|
||||
// JPEG is a lossy format and hence needs a non-zero tolerance.
|
||||
{"testdata/video-001.jpeg", 8 << 8},
|
||||
{"testdata/video-001.png", 0},
|
||||
{"testdata/video-001.tiff", 0},
|
||||
{"testdata/video-001.png", "testdata/video-001.jpeg", 8 << 8},
|
||||
{"testdata/video-001.png", "testdata/video-001.png", 0},
|
||||
{"testdata/video-001.png", "testdata/video-001.tiff", 0},
|
||||
|
||||
// Test grayscale images.
|
||||
{"testdata/video-005.gray.png", "testdata/video-005.gray.jpeg", 8 << 8},
|
||||
{"testdata/video-005.gray.png", "testdata/video-005.gray.png", 0},
|
||||
}
|
||||
|
||||
func decode(filename string) (image.Image, string, os.Error) {
|
||||
|
@ -44,6 +49,15 @@ func decode(filename string) (image.Image, string, os.Error) {
|
|||
return image.Decode(bufio.NewReader(f))
|
||||
}
|
||||
|
||||
func decodeConfig(filename string) (image.Config, string, os.Error) {
|
||||
f, err := os.Open(filename)
|
||||
if err != nil {
|
||||
return image.Config{}, "", err
|
||||
}
|
||||
defer f.Close()
|
||||
return image.DecodeConfig(bufio.NewReader(f))
|
||||
}
|
||||
|
||||
func delta(u0, u1 uint32) int {
|
||||
d := int(u0) - int(u1)
|
||||
if d < 0 {
|
||||
|
@ -63,29 +77,47 @@ func withinTolerance(c0, c1 image.Color, tolerance int) bool {
|
|||
}
|
||||
|
||||
func TestDecode(t *testing.T) {
|
||||
golden, _, err := decode(goldenFile)
|
||||
if err != nil {
|
||||
t.Errorf("%s: %v", goldenFile, err)
|
||||
}
|
||||
golden := make(map[string]image.Image)
|
||||
loop:
|
||||
for _, it := range imageTests {
|
||||
m, _, err := decode(it.filename)
|
||||
g := golden[it.goldenFilename]
|
||||
if g == nil {
|
||||
var err os.Error
|
||||
g, _, err = decode(it.goldenFilename)
|
||||
if err != nil {
|
||||
t.Errorf("%s: %v", it.goldenFilename, err)
|
||||
continue loop
|
||||
}
|
||||
golden[it.goldenFilename] = g
|
||||
}
|
||||
m, imageFormat, err := decode(it.filename)
|
||||
if err != nil {
|
||||
t.Errorf("%s: %v", it.filename, err)
|
||||
continue loop
|
||||
}
|
||||
b := golden.Bounds()
|
||||
b := g.Bounds()
|
||||
if !b.Eq(m.Bounds()) {
|
||||
t.Errorf("%s: want bounds %v got %v", it.filename, b, m.Bounds())
|
||||
continue loop
|
||||
}
|
||||
for y := b.Min.Y; y < b.Max.Y; y++ {
|
||||
for x := b.Min.X; x < b.Max.X; x++ {
|
||||
if !withinTolerance(golden.At(x, y), m.At(x, y), it.tolerance) {
|
||||
t.Errorf("%s: at (%d, %d), want %v got %v", it.filename, x, y, golden.At(x, y), m.At(x, y))
|
||||
if !withinTolerance(g.At(x, y), m.At(x, y), it.tolerance) {
|
||||
t.Errorf("%s: at (%d, %d), want %v got %v", it.filename, x, y, g.At(x, y), m.At(x, y))
|
||||
continue loop
|
||||
}
|
||||
}
|
||||
}
|
||||
if imageFormat == "gif" {
|
||||
// Each frame of a GIF can have a frame-local palette override the
|
||||
// GIF-global palette. Thus, image.Decode can yield a different ColorModel
|
||||
// than image.DecodeConfig.
|
||||
continue
|
||||
}
|
||||
c, _, err := decodeConfig(it.filename)
|
||||
if m.ColorModel() != c.ColorModel {
|
||||
t.Errorf("%s: color models differ", it.filename)
|
||||
continue loop
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue