ebiten: reland: improve anti-alias test

This commit is contained in:
Hajime Hoshi 2023-02-19 21:59:41 +09:00
parent da33f39259
commit f6b48cb57c

View File

@ -3874,7 +3874,8 @@ func TestImageAntiAlias(t *testing.T) {
dst0 := ebiten.NewImage(w, h) dst0 := ebiten.NewImage(w, h)
dst1 := ebiten.NewImage(w, h) dst1 := ebiten.NewImage(w, h)
tmp := ebiten.NewImage(w*bigOffscreenScale, h*bigOffscreenScale) tmp := ebiten.NewImage(w*bigOffscreenScale, h*bigOffscreenScale)
src := ebiten.NewImage(w, h) src := ebiten.NewImage(3, 3)
src.Fill(color.RGBA{R: 0x24, G: 0x3f, B: 0x6a, A: 0x88})
for _, blend := range []ebiten.Blend{ for _, blend := range []ebiten.Blend{
{}, // Default {}, // Default
@ -3885,10 +3886,31 @@ func TestImageAntiAlias(t *testing.T) {
ebiten.BlendXor, ebiten.BlendXor,
ebiten.BlendLighter, ebiten.BlendLighter,
} { } {
dst0.Fill(color.RGBA{R: 0x24, G: 0x3f, B: 0x6a, A: 0x88}) rnd := rand.New(rand.NewSource(0))
dst1.Fill(color.RGBA{R: 0x24, G: 0x3f, B: 0x6a, A: 0x88}) max := func(x, y, z byte) byte {
if x >= y && x >= z {
return x
}
if y >= x && y >= z {
return y
}
return z
}
dstPix := make([]byte, 4*w*h)
for i := 0; i < w*h; i++ {
n := rnd.Int()
r, g, b := byte(n), byte(n>>8), byte(n>>16)
a := max(r, g, b)
dstPix[4*i] = r
dstPix[4*i+1] = g
dstPix[4*i+2] = b
dstPix[4*i+3] = a
}
dst0.WritePixels(dstPix)
dst1.WritePixels(dstPix)
tmp.Clear() tmp.Clear()
src.Fill(color.RGBA{R: 0x85, G: 0xa3, B: 0x08, A: 0xd3})
// Create an actual result. // Create an actual result.
op := &ebiten.DrawTrianglesOptions{} op := &ebiten.DrawTrianglesOptions{}
@ -3898,8 +3920,8 @@ func TestImageAntiAlias(t *testing.T) {
{ {
DstX: w / 4, DstX: w / 4,
DstY: h / 4, DstY: h / 4,
SrcX: 0, SrcX: 1,
SrcY: 0, SrcY: 1,
ColorR: 1, ColorR: 1,
ColorG: 1, ColorG: 1,
ColorB: 1, ColorB: 1,
@ -3908,8 +3930,8 @@ func TestImageAntiAlias(t *testing.T) {
{ {
DstX: 2 * w / 4, DstX: 2 * w / 4,
DstY: h / 4, DstY: h / 4,
SrcX: w, SrcX: 2,
SrcY: 0, SrcY: 1,
ColorR: 1, ColorR: 1,
ColorG: 1, ColorG: 1,
ColorB: 1, ColorB: 1,
@ -3918,8 +3940,8 @@ func TestImageAntiAlias(t *testing.T) {
{ {
DstX: w / 4, DstX: w / 4,
DstY: 2 * h / 4, DstY: 2 * h / 4,
SrcX: 0, SrcX: 1,
SrcY: h, SrcY: 2,
ColorR: 1, ColorR: 1,
ColorG: 1, ColorG: 1,
ColorB: 1, ColorB: 1,
@ -3933,8 +3955,8 @@ func TestImageAntiAlias(t *testing.T) {
{ {
DstX: 2 * w / 4, DstX: 2 * w / 4,
DstY: 3 * h / 4, DstY: 3 * h / 4,
SrcX: 0, SrcX: 1,
SrcY: h, SrcY: 2,
ColorR: 1, ColorR: 1,
ColorG: 1, ColorG: 1,
ColorB: 1, ColorB: 1,
@ -3943,8 +3965,8 @@ func TestImageAntiAlias(t *testing.T) {
{ {
DstX: 3 * w / 4, DstX: 3 * w / 4,
DstY: 2 * h / 4, DstY: 2 * h / 4,
SrcX: w, SrcX: 2,
SrcY: 0, SrcY: 1,
ColorR: 1, ColorR: 1,
ColorG: 1, ColorG: 1,
ColorB: 1, ColorB: 1,
@ -3953,8 +3975,8 @@ func TestImageAntiAlias(t *testing.T) {
{ {
DstX: 3 * w / 4, DstX: 3 * w / 4,
DstY: 3 * h / 4, DstY: 3 * h / 4,
SrcX: w, SrcX: 2,
SrcY: h, SrcY: 2,
ColorR: 1, ColorR: 1,
ColorG: 1, ColorG: 1,
ColorB: 1, ColorB: 1,