mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
graphics: Update TestImageScale
This commit is contained in:
parent
4f45c0361d
commit
98054928ac
@ -208,19 +208,20 @@ func TestImageSelf(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestImageScale(t *testing.T) {
|
func TestImageScale(t *testing.T) {
|
||||||
|
for _, scale := range []int{2, 3, 4} {
|
||||||
img0, _, err := openEbitenImage("testdata/ebiten.png")
|
img0, _, err := openEbitenImage("testdata/ebiten.png")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w, h := img0.Size()
|
w, h := img0.Size()
|
||||||
img1, err := NewImage(w*2, h*2, FilterNearest)
|
img1, err := NewImage(w*scale, h*scale, FilterNearest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
op := &DrawImageOptions{}
|
op := &DrawImageOptions{}
|
||||||
op.GeoM.Scale(2, 2)
|
op.GeoM.Scale(float64(scale), float64(scale))
|
||||||
if err := img1.DrawImage(img0, op); err != nil {
|
if err := img1.DrawImage(img0, op); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
return
|
return
|
||||||
@ -228,10 +229,11 @@ func TestImageScale(t *testing.T) {
|
|||||||
|
|
||||||
for j := 0; j < h*2; j++ {
|
for j := 0; j < h*2; j++ {
|
||||||
for i := 0; i < w*2; i++ {
|
for i := 0; i < w*2; i++ {
|
||||||
c0 := img0.At(i/2, j/2).(color.RGBA)
|
c0 := img0.At(i/scale, j/scale).(color.RGBA)
|
||||||
c1 := img1.At(i, j).(color.RGBA)
|
c1 := img1.At(i, j).(color.RGBA)
|
||||||
if c0 != c1 {
|
if c0 != c1 {
|
||||||
t.Errorf("img0.At(%[1]d, %[2]d) should equal to img1.At(%[3]d, %[4]d) but not: %[5]v vs %[6]v", i/2, j/2, i, j, c0, c1)
|
t.Errorf("img0.At(%[1]d, %[2]d) should equal to img1.At(%[3]d, %[4]d) (with scale %[5]d) but not: %[6]v vs %[7]v", i/2, j/2, i, j, scale, c0, c1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user