mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
parent
54da0d9763
commit
c6053bcf14
@ -23,11 +23,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
emptyImage *ebiten.Image
|
emptyImage = ebiten.NewImage(1, 1)
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
emptyImage, _ = ebiten.NewImage(1, 1)
|
|
||||||
emptyImage.Fill(color.White)
|
emptyImage.Fill(color.White)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ func (g *Game) Update() error {
|
|||||||
func (g *Game) Draw(screen *ebiten.Image) {
|
func (g *Game) Draw(screen *ebiten.Image) {
|
||||||
if g.boardImage == nil {
|
if g.boardImage == nil {
|
||||||
w, h := g.board.Size()
|
w, h := g.board.Size()
|
||||||
g.boardImage, _ = ebiten.NewImage(w, h)
|
g.boardImage = ebiten.NewImage(w, h)
|
||||||
}
|
}
|
||||||
screen.Fill(backgroundColor)
|
screen.Fill(backgroundColor)
|
||||||
g.board.Draw(g.boardImage)
|
g.board.Draw(g.boardImage)
|
||||||
|
@ -351,11 +351,10 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
tileImage *ebiten.Image
|
tileImage = ebiten.NewImage(tileSize, tileSize)
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
tileImage, _ = ebiten.NewImage(tileSize, tileSize)
|
|
||||||
tileImage.Fill(color.White)
|
tileImage.Fill(color.White)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,8 +42,8 @@ var (
|
|||||||
|
|
||||||
gophersImage *ebiten.Image
|
gophersImage *ebiten.Image
|
||||||
repeatedGophersImage *ebiten.Image
|
repeatedGophersImage *ebiten.Image
|
||||||
groundImage *ebiten.Image
|
groundImage = ebiten.NewImage(screenWidth*2, screenHeight*2/3+50)
|
||||||
perspectiveGroundImage *ebiten.Image
|
perspectiveGroundImage = ebiten.NewImage(screenWidth*2, screenHeight)
|
||||||
fogImage *ebiten.Image
|
fogImage *ebiten.Image
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -63,12 +63,9 @@ func init() {
|
|||||||
}
|
}
|
||||||
gophersImage, _ = ebiten.NewImageFromImage(img)
|
gophersImage, _ = ebiten.NewImageFromImage(img)
|
||||||
|
|
||||||
groundImage, _ = ebiten.NewImage(screenWidth*2, screenHeight*2/3+50)
|
|
||||||
perspectiveGroundImage, _ = ebiten.NewImage(screenWidth*2, screenHeight)
|
|
||||||
|
|
||||||
const repeat = 5
|
const repeat = 5
|
||||||
w, h := gophersImage.Size()
|
w, h := gophersImage.Size()
|
||||||
repeatedGophersImage, _ = ebiten.NewImage(w*repeat, h*repeat)
|
repeatedGophersImage = ebiten.NewImage(w*repeat, h*repeat)
|
||||||
for j := 0; j < repeat; j++ {
|
for j := 0; j < repeat; j++ {
|
||||||
for i := 0; i < repeat; i++ {
|
for i := 0; i < repeat; i++ {
|
||||||
op := &ebiten.DrawImageOptions{}
|
op := &ebiten.DrawImageOptions{}
|
||||||
|
@ -32,8 +32,8 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
imageGameBG *ebiten.Image
|
imageGameBG *ebiten.Image
|
||||||
imageWindows *ebiten.Image
|
imageWindows = ebiten.NewImage(ScreenWidth, ScreenHeight)
|
||||||
imageGameover *ebiten.Image
|
imageGameover = ebiten.NewImage(ScreenWidth, ScreenHeight)
|
||||||
)
|
)
|
||||||
|
|
||||||
func fieldWindowPosition() (x, y int) {
|
func fieldWindowPosition() (x, y int) {
|
||||||
@ -78,9 +78,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
imageGameBG, _ = ebiten.NewImageFromImage(img)
|
imageGameBG, _ = ebiten.NewImageFromImage(img)
|
||||||
|
|
||||||
// Windows
|
|
||||||
imageWindows, _ = ebiten.NewImage(ScreenWidth, ScreenHeight)
|
|
||||||
|
|
||||||
// Windows: Field
|
// Windows: Field
|
||||||
x, y := fieldWindowPosition()
|
x, y := fieldWindowPosition()
|
||||||
drawWindow(imageWindows, x, y, fieldWidth, fieldHeight)
|
drawWindow(imageWindows, x, y, fieldWidth, fieldHeight)
|
||||||
@ -104,7 +101,6 @@ func init() {
|
|||||||
drawTextBox(imageWindows, "LINES", x, y, textBoxWidth())
|
drawTextBox(imageWindows, "LINES", x, y, textBoxWidth())
|
||||||
|
|
||||||
// Gameover
|
// Gameover
|
||||||
imageGameover, _ = ebiten.NewImage(ScreenWidth, ScreenHeight)
|
|
||||||
imageGameover.Fill(color.NRGBA{0x00, 0x00, 0x00, 0x80})
|
imageGameover.Fill(color.NRGBA{0x00, 0x00, 0x00, 0x80})
|
||||||
y = (ScreenHeight - blockHeight) / 2
|
y = (ScreenHeight - blockHeight) / 2
|
||||||
drawTextWithShadowCenter(imageGameover, "GAME OVER\n\nPRESS SPACE", 0, y, 1, color.White, ScreenWidth)
|
drawTextWithShadowCenter(imageGameover, "GAME OVER\n\nPRESS SPACE", 0, y, 1, color.White, ScreenWidth)
|
||||||
|
@ -19,15 +19,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
transitionFrom *ebiten.Image
|
transitionFrom = ebiten.NewImage(ScreenWidth, ScreenHeight)
|
||||||
transitionTo *ebiten.Image
|
transitionTo = ebiten.NewImage(ScreenWidth, ScreenHeight)
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
transitionFrom, _ = ebiten.NewImage(ScreenWidth, ScreenHeight)
|
|
||||||
transitionTo, _ = ebiten.NewImage(ScreenWidth, ScreenHeight)
|
|
||||||
}
|
|
||||||
|
|
||||||
type Scene interface {
|
type Scene interface {
|
||||||
Update(state *GameState) error
|
Update(state *GameState) error
|
||||||
Draw(screen *ebiten.Image)
|
Draw(screen *ebiten.Image)
|
||||||
|
@ -261,7 +261,7 @@ func main() {
|
|||||||
},
|
},
|
||||||
camera: Camera{ViewPort: f64.Vec2{screenWidth, screenHeight}},
|
camera: Camera{ViewPort: f64.Vec2{screenWidth, screenHeight}},
|
||||||
}
|
}
|
||||||
g.world, _ = ebiten.NewImage(worldWidth, worldHeight)
|
g.world = ebiten.NewImage(worldWidth, worldHeight)
|
||||||
|
|
||||||
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
|
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
|
||||||
ebiten.SetWindowTitle("Tiles (Ebiten Demo)")
|
ebiten.SetWindowTitle("Tiles (Ebiten Demo)")
|
||||||
|
@ -33,11 +33,10 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
dot *ebiten.Image
|
dot = ebiten.NewImage(1, 1)
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
dot, _ = ebiten.NewImage(1, 1)
|
|
||||||
dot.Fill(color.White)
|
dot.Fill(color.White)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
offscreen *ebiten.Image
|
offscreen = ebiten.NewImage(screenWidth, screenHeight)
|
||||||
offscreenPix []byte
|
offscreenPix []byte
|
||||||
palette [maxIt]byte
|
palette [maxIt]byte
|
||||||
)
|
)
|
||||||
@ -69,7 +69,6 @@ func updateOffscreen(centerX, centerY, size float64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
offscreen, _ = ebiten.NewImage(screenWidth, screenHeight)
|
|
||||||
offscreenPix = make([]byte, screenWidth*screenHeight*4)
|
offscreenPix = make([]byte, screenWidth*screenHeight*4)
|
||||||
for i := range palette {
|
for i := range palette {
|
||||||
palette[i] = byte(math.Sqrt(float64(i)/float64(len(palette))) * 0x80)
|
palette[i] = byte(math.Sqrt(float64(i)/float64(len(palette))) * 0x80)
|
||||||
|
@ -36,7 +36,7 @@ const (
|
|||||||
var (
|
var (
|
||||||
bgImage *ebiten.Image
|
bgImage *ebiten.Image
|
||||||
fgImage *ebiten.Image
|
fgImage *ebiten.Image
|
||||||
maskedFgImage *ebiten.Image
|
maskedFgImage = ebiten.NewImage(screenWidth, screenHeight)
|
||||||
spotLightImage *ebiten.Image
|
spotLightImage *ebiten.Image
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -62,8 +62,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
fgImage, _ = ebiten.NewImageFromImage(img)
|
fgImage, _ = ebiten.NewImageFromImage(img)
|
||||||
|
|
||||||
maskedFgImage, _ = ebiten.NewImage(screenWidth, screenHeight)
|
|
||||||
|
|
||||||
// Initialize the spot light image.
|
// Initialize the spot light image.
|
||||||
const r = 64
|
const r = 64
|
||||||
alphas := image.Point{r * 2, r * 2}
|
alphas := image.Point{r * 2, r * 2}
|
||||||
|
@ -81,7 +81,7 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
w, h := gophersImage.Size()
|
w, h := gophersImage.Size()
|
||||||
gophersRenderTarget, _ = ebiten.NewImage(w/mosaicRatio, h/mosaicRatio)
|
gophersRenderTarget = ebiten.NewImage(w/mosaicRatio, h/mosaicRatio)
|
||||||
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
|
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
|
||||||
ebiten.SetWindowTitle("Mosaic (Ebiten Demo)")
|
ebiten.SetWindowTitle("Mosaic (Ebiten Demo)")
|
||||||
if err := ebiten.RunGame(&Game{}); err != nil {
|
if err := ebiten.RunGame(&Game{}); err != nil {
|
||||||
|
@ -34,7 +34,7 @@ const (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
brushImage *ebiten.Image
|
brushImage *ebiten.Image
|
||||||
canvasImage *ebiten.Image
|
canvasImage = ebiten.NewImage(screenWidth, screenHeight)
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -55,7 +55,6 @@ func init() {
|
|||||||
Rect: image.Rect(0, 0, 4, 4),
|
Rect: image.Rect(0, 0, 4, 4),
|
||||||
})
|
})
|
||||||
|
|
||||||
canvasImage, _ = ebiten.NewImage(screenWidth, screenHeight)
|
|
||||||
canvasImage.Fill(color.White)
|
canvasImage.Fill(color.White)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,12 +144,10 @@ func playNote(freq float64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
pianoImage *ebiten.Image
|
pianoImage = ebiten.NewImage(screenWidth, screenHeight)
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
pianoImage, _ = ebiten.NewImage(screenWidth, screenHeight)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
keyWidth = 24
|
keyWidth = 24
|
||||||
y = 48
|
y = 48
|
||||||
|
@ -33,7 +33,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
emptyImage, _ = ebiten.NewImage(16, 16)
|
emptyImage = ebiten.NewImage(16, 16)
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -41,8 +41,8 @@ const (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
bgImage *ebiten.Image
|
bgImage *ebiten.Image
|
||||||
shadowImage *ebiten.Image
|
shadowImage = ebiten.NewImage(screenWidth, screenHeight)
|
||||||
triangleImage *ebiten.Image
|
triangleImage = ebiten.NewImage(screenWidth, screenHeight)
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -60,8 +60,6 @@ func init() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
bgImage, _ = ebiten.NewImageFromImage(img)
|
bgImage, _ = ebiten.NewImageFromImage(img)
|
||||||
shadowImage, _ = ebiten.NewImage(screenWidth, screenHeight)
|
|
||||||
triangleImage, _ = ebiten.NewImage(screenWidth, screenHeight)
|
|
||||||
triangleImage.Fill(color.White)
|
triangleImage.Fill(color.White)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,11 +36,7 @@ func init() {
|
|||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
}
|
}
|
||||||
|
|
||||||
var offscreen *ebiten.Image
|
var offscreen = ebiten.NewImage(screenWidth, screenHeight)
|
||||||
|
|
||||||
func init() {
|
|
||||||
offscreen, _ = ebiten.NewImage(screenWidth, screenHeight)
|
|
||||||
}
|
|
||||||
|
|
||||||
type Game struct {
|
type Game struct {
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
emptyImage, _ = ebiten.NewImage(16, 16)
|
emptyImage = ebiten.NewImage(16, 16)
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -57,7 +57,7 @@ func init() {
|
|||||||
origEbitenImage, _ := ebiten.NewImageFromImage(img)
|
origEbitenImage, _ := ebiten.NewImageFromImage(img)
|
||||||
|
|
||||||
w, h := origEbitenImage.Size()
|
w, h := origEbitenImage.Size()
|
||||||
ebitenImage, _ = ebiten.NewImage(w, h)
|
ebitenImage = ebiten.NewImage(w, h)
|
||||||
|
|
||||||
op := &ebiten.DrawImageOptions{}
|
op := &ebiten.DrawImageOptions{}
|
||||||
op.ColorM.Scale(1, 1, 1, 0.5)
|
op.ColorM.Scale(1, 1, 1, 0.5)
|
||||||
|
@ -59,7 +59,7 @@ func init() {
|
|||||||
origEbitenImage, _ := ebiten.NewImageFromImage(img)
|
origEbitenImage, _ := ebiten.NewImageFromImage(img)
|
||||||
|
|
||||||
w, h := origEbitenImage.Size()
|
w, h := origEbitenImage.Size()
|
||||||
ebitenImage, _ = ebiten.NewImage(w, h)
|
ebitenImage = ebiten.NewImage(w, h)
|
||||||
|
|
||||||
op := &ebiten.DrawImageOptions{}
|
op := &ebiten.DrawImageOptions{}
|
||||||
op.ColorM.Scale(1, 1, 1, 0.5)
|
op.ColorM.Scale(1, 1, 1, 0.5)
|
||||||
|
@ -79,7 +79,7 @@ var (
|
|||||||
}
|
}
|
||||||
selectedPalette = 0
|
selectedPalette = 0
|
||||||
colorCycle = 0
|
colorCycle = 0
|
||||||
canvas *ebiten.Image
|
canvas = ebiten.NewImage(width, height)
|
||||||
auto *automaton
|
auto *automaton
|
||||||
// blocker is an arbitrary color used to prevent the
|
// blocker is an arbitrary color used to prevent the
|
||||||
// squirals from leaving the canvas.
|
// squirals from leaving the canvas.
|
||||||
@ -279,8 +279,6 @@ func setpix(xy vec2, col color.Color) {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
c, _ := ebiten.NewImage(width, height)
|
|
||||||
canvas = c
|
|
||||||
canvas.Fill(background)
|
canvas.Fill(background)
|
||||||
|
|
||||||
auto = &automaton{}
|
auto = &automaton{}
|
||||||
|
@ -358,7 +358,7 @@ func (t *TextBox) Draw(dst *ebiten.Image) {
|
|||||||
}
|
}
|
||||||
if t.contentBuf == nil {
|
if t.contentBuf == nil {
|
||||||
w, h := t.viewSize()
|
w, h := t.viewSize()
|
||||||
t.contentBuf, _ = ebiten.NewImage(w, h)
|
t.contentBuf = ebiten.NewImage(w, h)
|
||||||
}
|
}
|
||||||
|
|
||||||
t.contentBuf.Clear()
|
t.contentBuf.Clear()
|
||||||
|
@ -25,10 +25,9 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
|
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
var pointerImage *ebiten.Image
|
var pointerImage = ebiten.NewImage(4, 4)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
pointerImage, _ = ebiten.NewImage(4, 4)
|
|
||||||
pointerImage.Fill(color.RGBA{0xff, 0, 0, 0xff})
|
pointerImage.Fill(color.RGBA{0xff, 0, 0, 0xff})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
8
image.go
8
image.go
@ -717,13 +717,7 @@ func (i *Image) ReplacePixels(pixels []byte) {
|
|||||||
// NewImage returns an empty image.
|
// NewImage returns an empty image.
|
||||||
//
|
//
|
||||||
// If width or height is less than 1 or more than device-dependent maximum size, NewImage panics.
|
// If width or height is less than 1 or more than device-dependent maximum size, NewImage panics.
|
||||||
//
|
func NewImage(width, height int) *Image {
|
||||||
// Error returned by NewImage is always nil as of 1.5.0.
|
|
||||||
func NewImage(width, height int) (*Image, error) {
|
|
||||||
return newImage(width, height), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func newImage(width, height int) *Image {
|
|
||||||
i := &Image{
|
i := &Image{
|
||||||
mipmap: mipmap.New(width, height),
|
mipmap: mipmap.New(width, height),
|
||||||
bounds: image.Rect(0, 0, width, height),
|
bounds: image.Rect(0, 0, width, height),
|
||||||
|
253
image_test.go
253
image_test.go
@ -123,36 +123,19 @@ func TestImageComposition(t *testing.T) {
|
|||||||
|
|
||||||
w, h := img1.Bounds().Size().X, img1.Bounds().Size().Y
|
w, h := img1.Bounds().Size().X, img1.Bounds().Size().Y
|
||||||
|
|
||||||
img2, err := NewImage(w, h)
|
img2 := NewImage(w, h)
|
||||||
if err != nil {
|
img3 := NewImage(w, h)
|
||||||
t.Fatal(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
img3, err := NewImage(w, h)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
img2.Fill(img2Color)
|
img2.Fill(img2Color)
|
||||||
img3.Fill(img3Color)
|
img3.Fill(img3Color)
|
||||||
img_12_3, err := NewImage(w, h)
|
img_12_3 := NewImage(w, h)
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
img2.DrawImage(img1, nil)
|
img2.DrawImage(img1, nil)
|
||||||
img3.DrawImage(img2, nil)
|
img3.DrawImage(img2, nil)
|
||||||
img_12_3.DrawImage(img3, nil)
|
img_12_3.DrawImage(img3, nil)
|
||||||
|
|
||||||
img2.Fill(img2Color)
|
img2.Fill(img2Color)
|
||||||
img3.Fill(img3Color)
|
img3.Fill(img3Color)
|
||||||
img_1_23, err := NewImage(w, h)
|
img_1_23 := NewImage(w, h)
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
img3.DrawImage(img2, nil)
|
img3.DrawImage(img2, nil)
|
||||||
img3.DrawImage(img1, nil)
|
img3.DrawImage(img1, nil)
|
||||||
img_1_23.DrawImage(img3, nil)
|
img_1_23.DrawImage(img3, nil)
|
||||||
@ -197,11 +180,7 @@ func TestImageScale(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
w, h := img0.Size()
|
w, h := img0.Size()
|
||||||
img1, err := NewImage(w*scale, h*scale)
|
img1 := NewImage(w*scale, h*scale)
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
op := &DrawImageOptions{}
|
op := &DrawImageOptions{}
|
||||||
op.GeoM.Scale(float64(scale), float64(scale))
|
op.GeoM.Scale(float64(scale), float64(scale))
|
||||||
|
|
||||||
@ -226,11 +205,7 @@ func TestImage90DegreeRotate(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
w, h := img0.Size()
|
w, h := img0.Size()
|
||||||
img1, err := NewImage(h, w)
|
img1 := NewImage(h, w)
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
op := &DrawImageOptions{}
|
op := &DrawImageOptions{}
|
||||||
op.GeoM.Rotate(math.Pi / 2)
|
op.GeoM.Rotate(math.Pi / 2)
|
||||||
op.GeoM.Translate(float64(h), 0)
|
op.GeoM.Translate(float64(h), 0)
|
||||||
@ -254,11 +229,7 @@ func TestImageDotByDotInversion(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
w, h := img0.Size()
|
w, h := img0.Size()
|
||||||
img1, err := NewImage(w, h)
|
img1 := NewImage(w, h)
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
op := &DrawImageOptions{}
|
op := &DrawImageOptions{}
|
||||||
op.GeoM.Rotate(math.Pi)
|
op.GeoM.Rotate(math.Pi)
|
||||||
op.GeoM.Translate(float64(w), float64(h))
|
op.GeoM.Translate(float64(w), float64(h))
|
||||||
@ -290,11 +261,7 @@ func TestImageReplacePixels(t *testing.T) {
|
|||||||
draw.Draw(img, img.Bounds(), origImg, image.ZP, draw.Src)
|
draw.Draw(img, img.Bounds(), origImg, image.ZP, draw.Src)
|
||||||
|
|
||||||
size := img.Bounds().Size()
|
size := img.Bounds().Size()
|
||||||
img0, err := NewImage(size.X, size.Y)
|
img0 := NewImage(size.X, size.Y)
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
img0.ReplacePixels(img.Pix)
|
img0.ReplacePixels(img.Pix)
|
||||||
for j := 0; j < img0.Bounds().Size().Y; j++ {
|
for j := 0; j < img0.Bounds().Size().Y; j++ {
|
||||||
@ -334,21 +301,13 @@ func TestImageReplacePixelsNil(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
img, err := NewImage(16, 16)
|
img := NewImage(16, 16)
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
img.Fill(color.White)
|
img.Fill(color.White)
|
||||||
img.ReplacePixels(nil)
|
img.ReplacePixels(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestImageDispose(t *testing.T) {
|
func TestImageDispose(t *testing.T) {
|
||||||
img, err := NewImage(16, 16)
|
img := NewImage(16, 16)
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
img.Fill(color.White)
|
img.Fill(color.White)
|
||||||
img.Dispose()
|
img.Dispose()
|
||||||
|
|
||||||
@ -376,11 +335,7 @@ func TestImageCompositeModeLighter(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
w, h := img0.Size()
|
w, h := img0.Size()
|
||||||
img1, err := NewImage(w, h)
|
img1 := NewImage(w, h)
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
img1.Fill(color.RGBA{0x01, 0x02, 0x03, 0x04})
|
img1.Fill(color.RGBA{0x01, 0x02, 0x03, 0x04})
|
||||||
op := &DrawImageOptions{}
|
op := &DrawImageOptions{}
|
||||||
op.CompositeMode = CompositeModeLighter
|
op.CompositeMode = CompositeModeLighter
|
||||||
@ -453,11 +408,7 @@ func (c *mutableRGBA) RGBA() (r, g, b, a uint32) {
|
|||||||
|
|
||||||
func TestImageFill(t *testing.T) {
|
func TestImageFill(t *testing.T) {
|
||||||
w, h := 10, 10
|
w, h := 10, 10
|
||||||
img, err := NewImage(w, h)
|
img := NewImage(w, h)
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
clr := &mutableRGBA{0x80, 0x80, 0x80, 0x80}
|
clr := &mutableRGBA{0x80, 0x80, 0x80, 0x80}
|
||||||
img.Fill(clr)
|
img.Fill(clr)
|
||||||
clr.r = 0
|
clr.r = 0
|
||||||
@ -475,11 +426,7 @@ func TestImageFill(t *testing.T) {
|
|||||||
// Issue #740
|
// Issue #740
|
||||||
func TestImageClear(t *testing.T) {
|
func TestImageClear(t *testing.T) {
|
||||||
const w, h = 128, 256
|
const w, h = 128, 256
|
||||||
img, err := NewImage(w, h)
|
img := NewImage(w, h)
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
img.Fill(color.White)
|
img.Fill(color.White)
|
||||||
for j := 0; j < h; j++ {
|
for j := 0; j < h; j++ {
|
||||||
for i := 0; i < w; i++ {
|
for i := 0; i < w; i++ {
|
||||||
@ -519,7 +466,7 @@ func TestImageEdge(t *testing.T) {
|
|||||||
img1Width = 32
|
img1Width = 32
|
||||||
img1Height = 32
|
img1Height = 32
|
||||||
)
|
)
|
||||||
img0, _ := NewImage(img0Width, img0Height)
|
img0 := NewImage(img0Width, img0Height)
|
||||||
pixels := make([]uint8, 4*img0Width*img0Height)
|
pixels := make([]uint8, 4*img0Width*img0Height)
|
||||||
for j := 0; j < img0Height; j++ {
|
for j := 0; j < img0Height; j++ {
|
||||||
for i := 0; i < img0Width; i++ {
|
for i := 0; i < img0Width; i++ {
|
||||||
@ -531,7 +478,7 @@ func TestImageEdge(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
img0.ReplacePixels(pixels)
|
img0.ReplacePixels(pixels)
|
||||||
img1, _ := NewImage(img1Width, img1Height)
|
img1 := NewImage(img1Width, img1Height)
|
||||||
red := color.RGBA{0xff, 0, 0, 0xff}
|
red := color.RGBA{0xff, 0, 0, 0xff}
|
||||||
transparent := color.RGBA{0, 0, 0, 0}
|
transparent := color.RGBA{0, 0, 0, 0}
|
||||||
|
|
||||||
@ -651,8 +598,8 @@ func TestImageTooManyFill(t *testing.T) {
|
|||||||
return uint8((17*index + 0x40) % 256)
|
return uint8((17*index + 0x40) % 256)
|
||||||
}
|
}
|
||||||
|
|
||||||
src, _ := NewImage(1, 1)
|
src := NewImage(1, 1)
|
||||||
dst, _ := NewImage(width, 1)
|
dst := NewImage(width, 1)
|
||||||
for i := 0; i < width; i++ {
|
for i := 0; i < width; i++ {
|
||||||
c := indexToColor(i)
|
c := indexToColor(i)
|
||||||
src.Fill(color.RGBA{c, c, c, 0xff})
|
src.Fill(color.RGBA{c, c, c, 0xff})
|
||||||
@ -672,8 +619,8 @@ func TestImageTooManyFill(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkDrawImage(b *testing.B) {
|
func BenchmarkDrawImage(b *testing.B) {
|
||||||
img0, _ := NewImage(16, 16)
|
img0 := NewImage(16, 16)
|
||||||
img1, _ := NewImage(16, 16)
|
img1 := NewImage(16, 16)
|
||||||
op := &DrawImageOptions{}
|
op := &DrawImageOptions{}
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
img0.DrawImage(img1, op)
|
img0.DrawImage(img1, op)
|
||||||
@ -681,7 +628,7 @@ func BenchmarkDrawImage(b *testing.B) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestImageLinearGradiation(t *testing.T) {
|
func TestImageLinearGradiation(t *testing.T) {
|
||||||
img0, _ := NewImage(2, 2)
|
img0 := NewImage(2, 2)
|
||||||
img0.ReplacePixels([]byte{
|
img0.ReplacePixels([]byte{
|
||||||
0xff, 0x00, 0x00, 0xff,
|
0xff, 0x00, 0x00, 0xff,
|
||||||
0x00, 0xff, 0x00, 0xff,
|
0x00, 0xff, 0x00, 0xff,
|
||||||
@ -690,7 +637,7 @@ func TestImageLinearGradiation(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const w, h = 32, 32
|
const w, h = 32, 32
|
||||||
img1, _ := NewImage(w, h)
|
img1 := NewImage(w, h)
|
||||||
op := &DrawImageOptions{}
|
op := &DrawImageOptions{}
|
||||||
op.GeoM.Scale(w, h)
|
op.GeoM.Scale(w, h)
|
||||||
op.GeoM.Translate(-w/4, -h/4)
|
op.GeoM.Translate(-w/4, -h/4)
|
||||||
@ -708,8 +655,8 @@ func TestImageLinearGradiation(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestImageOutside(t *testing.T) {
|
func TestImageOutside(t *testing.T) {
|
||||||
src, _ := NewImage(5, 10) // internal texture size is 8x16.
|
src := NewImage(5, 10) // internal texture size is 8x16.
|
||||||
dst, _ := NewImage(4, 4)
|
dst := NewImage(4, 4)
|
||||||
src.Fill(color.RGBA{0xff, 0, 0, 0xff})
|
src.Fill(color.RGBA{0xff, 0, 0, 0xff})
|
||||||
|
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
@ -750,9 +697,9 @@ func TestImageOutside(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestImageOutsideUpperLeft(t *testing.T) {
|
func TestImageOutsideUpperLeft(t *testing.T) {
|
||||||
src, _ := NewImage(4, 4)
|
src := NewImage(4, 4)
|
||||||
dst1, _ := NewImage(16, 16)
|
dst1 := NewImage(16, 16)
|
||||||
dst2, _ := NewImage(16, 16)
|
dst2 := NewImage(16, 16)
|
||||||
src.Fill(color.RGBA{0xff, 0, 0, 0xff})
|
src.Fill(color.RGBA{0xff, 0, 0, 0xff})
|
||||||
|
|
||||||
op := &DrawImageOptions{}
|
op := &DrawImageOptions{}
|
||||||
@ -779,7 +726,7 @@ func TestImageSize(t *testing.T) {
|
|||||||
w = 17
|
w = 17
|
||||||
h = 31
|
h = 31
|
||||||
)
|
)
|
||||||
img, _ := NewImage(w, h)
|
img := NewImage(w, h)
|
||||||
gotW, gotH := img.Size()
|
gotW, gotH := img.Size()
|
||||||
if gotW != w {
|
if gotW != w {
|
||||||
t.Errorf("got: %d, want: %d", gotW, w)
|
t.Errorf("got: %d, want: %d", gotW, w)
|
||||||
@ -790,8 +737,8 @@ func TestImageSize(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestImageSize1(t *testing.T) {
|
func TestImageSize1(t *testing.T) {
|
||||||
src, _ := NewImage(1, 1)
|
src := NewImage(1, 1)
|
||||||
dst, _ := NewImage(1, 1)
|
dst := NewImage(1, 1)
|
||||||
src.Fill(color.White)
|
src.Fill(color.White)
|
||||||
dst.DrawImage(src, nil)
|
dst.DrawImage(src, nil)
|
||||||
got := src.At(0, 0).(color.RGBA)
|
got := src.At(0, 0).(color.RGBA)
|
||||||
@ -803,8 +750,8 @@ func TestImageSize1(t *testing.T) {
|
|||||||
|
|
||||||
// TODO: Enable this test again. This test fails after #1217 is fixed.
|
// TODO: Enable this test again. This test fails after #1217 is fixed.
|
||||||
func Skip_TestImageSize4096(t *testing.T) {
|
func Skip_TestImageSize4096(t *testing.T) {
|
||||||
src, _ := NewImage(4096, 4096)
|
src := NewImage(4096, 4096)
|
||||||
dst, _ := NewImage(4096, 4096)
|
dst := NewImage(4096, 4096)
|
||||||
pix := make([]byte, 4096*4096*4)
|
pix := make([]byte, 4096*4096*4)
|
||||||
for i := 0; i < 4096; i++ {
|
for i := 0; i < 4096; i++ {
|
||||||
j := 4095
|
j := 4095
|
||||||
@ -849,7 +796,7 @@ func TestImageCopy(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
img0, _ := NewImage(256, 256)
|
img0 := NewImage(256, 256)
|
||||||
img1 := *img0
|
img1 := *img0
|
||||||
img1.Fill(color.Transparent)
|
img1.Fill(color.Transparent)
|
||||||
}
|
}
|
||||||
@ -862,10 +809,10 @@ func TestImageStretch(t *testing.T) {
|
|||||||
|
|
||||||
const w = 16
|
const w = 16
|
||||||
|
|
||||||
dst, _ := NewImage(w, 4096)
|
dst := NewImage(w, 4096)
|
||||||
loop:
|
loop:
|
||||||
for h := 1; h <= 32; h++ {
|
for h := 1; h <= 32; h++ {
|
||||||
src, _ := NewImage(w, h)
|
src := NewImage(w, h)
|
||||||
|
|
||||||
pix := make([]byte, 4*w*h)
|
pix := make([]byte, 4*w*h)
|
||||||
for i := 0; i < w*h; i++ {
|
for i := 0; i < w*h; i++ {
|
||||||
@ -912,9 +859,9 @@ func TestImageSprites(t *testing.T) {
|
|||||||
height = 512
|
height = 512
|
||||||
)
|
)
|
||||||
|
|
||||||
src, _ := NewImage(4, 4)
|
src := NewImage(4, 4)
|
||||||
src.Fill(color.RGBA{0xff, 0xff, 0xff, 0xff})
|
src.Fill(color.RGBA{0xff, 0xff, 0xff, 0xff})
|
||||||
dst, _ := NewImage(width, height)
|
dst := NewImage(width, height)
|
||||||
for j := 0; j < height/4; j++ {
|
for j := 0; j < height/4; j++ {
|
||||||
for i := 0; i < width/4; i++ {
|
for i := 0; i < width/4; i++ {
|
||||||
op := &DrawImageOptions{}
|
op := &DrawImageOptions{}
|
||||||
@ -943,26 +890,26 @@ func Disabled_TestImageMipmap(t *testing.T) {
|
|||||||
}
|
}
|
||||||
w, h := src.Size()
|
w, h := src.Size()
|
||||||
|
|
||||||
l1, _ := NewImage(w/2, h/2)
|
l1 := NewImage(w/2, h/2)
|
||||||
op := &DrawImageOptions{}
|
op := &DrawImageOptions{}
|
||||||
op.GeoM.Scale(1/2.0, 1/2.0)
|
op.GeoM.Scale(1/2.0, 1/2.0)
|
||||||
op.Filter = FilterLinear
|
op.Filter = FilterLinear
|
||||||
l1.DrawImage(src, op)
|
l1.DrawImage(src, op)
|
||||||
|
|
||||||
l1w, l1h := l1.Size()
|
l1w, l1h := l1.Size()
|
||||||
l2, _ := NewImage(l1w/2, l1h/2)
|
l2 := NewImage(l1w/2, l1h/2)
|
||||||
op = &DrawImageOptions{}
|
op = &DrawImageOptions{}
|
||||||
op.GeoM.Scale(1/2.0, 1/2.0)
|
op.GeoM.Scale(1/2.0, 1/2.0)
|
||||||
op.Filter = FilterLinear
|
op.Filter = FilterLinear
|
||||||
l2.DrawImage(l1, op)
|
l2.DrawImage(l1, op)
|
||||||
|
|
||||||
gotDst, _ := NewImage(w, h)
|
gotDst := NewImage(w, h)
|
||||||
op = &DrawImageOptions{}
|
op = &DrawImageOptions{}
|
||||||
op.GeoM.Scale(1/5.0, 1/5.0)
|
op.GeoM.Scale(1/5.0, 1/5.0)
|
||||||
op.Filter = FilterLinear
|
op.Filter = FilterLinear
|
||||||
gotDst.DrawImage(src, op)
|
gotDst.DrawImage(src, op)
|
||||||
|
|
||||||
wantDst, _ := NewImage(w, h)
|
wantDst := NewImage(w, h)
|
||||||
op = &DrawImageOptions{}
|
op = &DrawImageOptions{}
|
||||||
op.GeoM.Scale(4.0/5.0, 4.0/5.0)
|
op.GeoM.Scale(4.0/5.0, 4.0/5.0)
|
||||||
op.Filter = FilterLinear
|
op.Filter = FilterLinear
|
||||||
@ -988,27 +935,27 @@ func Disabled_TestImageMipmapNegativeDet(t *testing.T) {
|
|||||||
}
|
}
|
||||||
w, h := src.Size()
|
w, h := src.Size()
|
||||||
|
|
||||||
l1, _ := NewImage(w/2, h/2)
|
l1 := NewImage(w/2, h/2)
|
||||||
op := &DrawImageOptions{}
|
op := &DrawImageOptions{}
|
||||||
op.GeoM.Scale(1/2.0, 1/2.0)
|
op.GeoM.Scale(1/2.0, 1/2.0)
|
||||||
op.Filter = FilterLinear
|
op.Filter = FilterLinear
|
||||||
l1.DrawImage(src, op)
|
l1.DrawImage(src, op)
|
||||||
|
|
||||||
l1w, l1h := l1.Size()
|
l1w, l1h := l1.Size()
|
||||||
l2, _ := NewImage(l1w/2, l1h/2)
|
l2 := NewImage(l1w/2, l1h/2)
|
||||||
op = &DrawImageOptions{}
|
op = &DrawImageOptions{}
|
||||||
op.GeoM.Scale(1/2.0, 1/2.0)
|
op.GeoM.Scale(1/2.0, 1/2.0)
|
||||||
op.Filter = FilterLinear
|
op.Filter = FilterLinear
|
||||||
l2.DrawImage(l1, op)
|
l2.DrawImage(l1, op)
|
||||||
|
|
||||||
gotDst, _ := NewImage(w, h)
|
gotDst := NewImage(w, h)
|
||||||
op = &DrawImageOptions{}
|
op = &DrawImageOptions{}
|
||||||
op.GeoM.Scale(-1/5.0, -1/5.0)
|
op.GeoM.Scale(-1/5.0, -1/5.0)
|
||||||
op.GeoM.Translate(float64(w), float64(h))
|
op.GeoM.Translate(float64(w), float64(h))
|
||||||
op.Filter = FilterLinear
|
op.Filter = FilterLinear
|
||||||
gotDst.DrawImage(src, op)
|
gotDst.DrawImage(src, op)
|
||||||
|
|
||||||
wantDst, _ := NewImage(w, h)
|
wantDst := NewImage(w, h)
|
||||||
op = &DrawImageOptions{}
|
op = &DrawImageOptions{}
|
||||||
op.GeoM.Scale(-4.0/5.0, -4.0/5.0)
|
op.GeoM.Scale(-4.0/5.0, -4.0/5.0)
|
||||||
op.GeoM.Translate(float64(w), float64(h))
|
op.GeoM.Translate(float64(w), float64(h))
|
||||||
@ -1036,8 +983,8 @@ func Disabled_TestImageMipmapNegativeDet(t *testing.T) {
|
|||||||
|
|
||||||
// Issue #710
|
// Issue #710
|
||||||
func TestImageMipmapColor(t *testing.T) {
|
func TestImageMipmapColor(t *testing.T) {
|
||||||
img0, _ := NewImage(256, 256)
|
img0 := NewImage(256, 256)
|
||||||
img1, _ := NewImage(128, 128)
|
img1 := NewImage(128, 128)
|
||||||
img1.Fill(color.White)
|
img1.Fill(color.White)
|
||||||
|
|
||||||
for i := 0; i < 8; i++ {
|
for i := 0; i < 8; i++ {
|
||||||
@ -1066,9 +1013,9 @@ func TestImageMipmapColor(t *testing.T) {
|
|||||||
|
|
||||||
// Issue #725
|
// Issue #725
|
||||||
func TestImageMiamapAndDrawTriangle(t *testing.T) {
|
func TestImageMiamapAndDrawTriangle(t *testing.T) {
|
||||||
img0, _ := NewImage(32, 32)
|
img0 := NewImage(32, 32)
|
||||||
img1, _ := NewImage(128, 128)
|
img1 := NewImage(128, 128)
|
||||||
img2, _ := NewImage(128, 128)
|
img2 := NewImage(128, 128)
|
||||||
|
|
||||||
// Fill img1 red and create img1's mipmap
|
// Fill img1 red and create img1's mipmap
|
||||||
img1.Fill(color.RGBA{0xff, 0, 0, 0xff})
|
img1.Fill(color.RGBA{0xff, 0, 0, 0xff})
|
||||||
@ -1142,7 +1089,7 @@ func TestImageMiamapAndDrawTriangle(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestImageSubImageAt(t *testing.T) {
|
func TestImageSubImageAt(t *testing.T) {
|
||||||
img, _ := NewImage(16, 16)
|
img := NewImage(16, 16)
|
||||||
img.Fill(color.RGBA{0xff, 0, 0, 0xff})
|
img.Fill(color.RGBA{0xff, 0, 0, 0xff})
|
||||||
|
|
||||||
got := img.SubImage(image.Rect(1, 1, 16, 16)).At(0, 0).(color.RGBA)
|
got := img.SubImage(image.Rect(1, 1, 16, 16)).At(0, 0).(color.RGBA)
|
||||||
@ -1159,7 +1106,7 @@ func TestImageSubImageAt(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestImageSubImageSize(t *testing.T) {
|
func TestImageSubImageSize(t *testing.T) {
|
||||||
img, _ := NewImage(16, 16)
|
img := NewImage(16, 16)
|
||||||
img.Fill(color.RGBA{0xff, 0, 0, 0xff})
|
img.Fill(color.RGBA{0xff, 0, 0, 0xff})
|
||||||
|
|
||||||
got, _ := img.SubImage(image.Rect(1, 1, 16, 16)).(*Image).Size()
|
got, _ := img.SubImage(image.Rect(1, 1, 16, 16)).(*Image).Size()
|
||||||
@ -1171,8 +1118,8 @@ func TestImageSubImageSize(t *testing.T) {
|
|||||||
|
|
||||||
func TestImageDrawImmediately(t *testing.T) {
|
func TestImageDrawImmediately(t *testing.T) {
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
img0, _ := NewImage(w, h)
|
img0 := NewImage(w, h)
|
||||||
img1, _ := NewImage(w, h)
|
img1 := NewImage(w, h)
|
||||||
// Do not manipulate img0 here.
|
// Do not manipulate img0 here.
|
||||||
|
|
||||||
img0.Fill(color.RGBA{0xff, 0, 0, 0xff})
|
img0.Fill(color.RGBA{0xff, 0, 0, 0xff})
|
||||||
@ -1203,8 +1150,8 @@ func TestImageDrawImmediately(t *testing.T) {
|
|||||||
func TestImageLinearFilterGlitch(t *testing.T) {
|
func TestImageLinearFilterGlitch(t *testing.T) {
|
||||||
const w, h = 200, 12
|
const w, h = 200, 12
|
||||||
const scale = 1.2
|
const scale = 1.2
|
||||||
src, _ := NewImage(w, h)
|
src := NewImage(w, h)
|
||||||
dst, _ := NewImage(int(math.Floor(w*scale)), h)
|
dst := NewImage(int(math.Floor(w*scale)), h)
|
||||||
|
|
||||||
pix := make([]byte, 4*w*h)
|
pix := make([]byte, 4*w*h)
|
||||||
for j := 0; j < h; j++ {
|
for j := 0; j < h; j++ {
|
||||||
@ -1252,8 +1199,8 @@ func TestImageLinearFilterGlitch(t *testing.T) {
|
|||||||
// Issue #1212
|
// Issue #1212
|
||||||
func TestImageLinearFilterGlitch2(t *testing.T) {
|
func TestImageLinearFilterGlitch2(t *testing.T) {
|
||||||
const w, h = 100, 100
|
const w, h = 100, 100
|
||||||
src, _ := NewImage(w, h)
|
src := NewImage(w, h)
|
||||||
dst, _ := NewImage(w, h)
|
dst := NewImage(w, h)
|
||||||
|
|
||||||
idx := 0
|
idx := 0
|
||||||
pix := make([]byte, 4*w*h)
|
pix := make([]byte, 4*w*h)
|
||||||
@ -1297,8 +1244,8 @@ func TestImageLinearFilterGlitch2(t *testing.T) {
|
|||||||
|
|
||||||
func TestImageAddressRepeat(t *testing.T) {
|
func TestImageAddressRepeat(t *testing.T) {
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
src, _ := NewImage(w, h)
|
src := NewImage(w, h)
|
||||||
dst, _ := NewImage(w, h)
|
dst := NewImage(w, h)
|
||||||
pix := make([]byte, 4*w*h)
|
pix := make([]byte, 4*w*h)
|
||||||
for j := 0; j < h; j++ {
|
for j := 0; j < h; j++ {
|
||||||
for i := 0; i < w; i++ {
|
for i := 0; i < w; i++ {
|
||||||
@ -1378,7 +1325,7 @@ func TestImageAddressRepeat(t *testing.T) {
|
|||||||
|
|
||||||
func TestImageReplacePixelsAfterClear(t *testing.T) {
|
func TestImageReplacePixelsAfterClear(t *testing.T) {
|
||||||
const w, h = 256, 256
|
const w, h = 256, 256
|
||||||
img, _ := NewImage(w, h)
|
img := NewImage(w, h)
|
||||||
img.ReplacePixels(make([]byte, 4*w*h))
|
img.ReplacePixels(make([]byte, 4*w*h))
|
||||||
// Clear used to call DrawImage to clear the image, which was the cause of crash. It is because after
|
// Clear used to call DrawImage to clear the image, which was the cause of crash. It is because after
|
||||||
// DrawImage is called, ReplacePixels for a region is forbidden.
|
// DrawImage is called, ReplacePixels for a region is forbidden.
|
||||||
@ -1396,7 +1343,7 @@ func TestImageSet(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
img, _ := NewImage(w, h)
|
img := NewImage(w, h)
|
||||||
colors := map[Pt]color.RGBA{
|
colors := map[Pt]color.RGBA{
|
||||||
{1, 2}: {3, 4, 5, 6},
|
{1, 2}: {3, 4, 5, 6},
|
||||||
{7, 8}: {9, 10, 11, 12},
|
{7, 8}: {9, 10, 11, 12},
|
||||||
@ -1428,8 +1375,8 @@ func TestImageSetAndDraw(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
src, _ := NewImage(w, h)
|
src := NewImage(w, h)
|
||||||
dst, _ := NewImage(w, h)
|
dst := NewImage(w, h)
|
||||||
colors := map[Pt]color.RGBA{
|
colors := map[Pt]color.RGBA{
|
||||||
{1, 2}: {3, 4, 5, 6},
|
{1, 2}: {3, 4, 5, 6},
|
||||||
{7, 8}: {9, 10, 11, 12},
|
{7, 8}: {9, 10, 11, 12},
|
||||||
@ -1487,10 +1434,10 @@ func TestImageSetAndDraw(t *testing.T) {
|
|||||||
|
|
||||||
func TestImageAlphaOnBlack(t *testing.T) {
|
func TestImageAlphaOnBlack(t *testing.T) {
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
src0, _ := NewImage(w, h)
|
src0 := NewImage(w, h)
|
||||||
src1, _ := NewImage(w, h)
|
src1 := NewImage(w, h)
|
||||||
dst0, _ := NewImage(w, h)
|
dst0 := NewImage(w, h)
|
||||||
dst1, _ := NewImage(w, h)
|
dst1 := NewImage(w, h)
|
||||||
|
|
||||||
pix0 := make([]byte, 4*w*h)
|
pix0 := make([]byte, 4*w*h)
|
||||||
for j := 0; j < h; j++ {
|
for j := 0; j < h; j++ {
|
||||||
@ -1552,8 +1499,8 @@ func TestImageAlphaOnBlack(t *testing.T) {
|
|||||||
|
|
||||||
func TestImageDrawTrianglesWithSubImage(t *testing.T) {
|
func TestImageDrawTrianglesWithSubImage(t *testing.T) {
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
src, _ := NewImage(w, h)
|
src := NewImage(w, h)
|
||||||
dst, _ := NewImage(w, h)
|
dst := NewImage(w, h)
|
||||||
|
|
||||||
pix := make([]byte, 4*w*h)
|
pix := make([]byte, 4*w*h)
|
||||||
for j := 0; j < h; j++ {
|
for j := 0; j < h; j++ {
|
||||||
@ -1636,7 +1583,7 @@ func TestImageDrawTrianglesWithSubImage(t *testing.T) {
|
|||||||
|
|
||||||
// Issue #823
|
// Issue #823
|
||||||
func TestImageAtAfterDisposingSubImage(t *testing.T) {
|
func TestImageAtAfterDisposingSubImage(t *testing.T) {
|
||||||
img, _ := NewImage(16, 16)
|
img := NewImage(16, 16)
|
||||||
img.Set(0, 0, color.White)
|
img.Set(0, 0, color.White)
|
||||||
img.SubImage(image.Rect(0, 0, 16, 16))
|
img.SubImage(image.Rect(0, 0, 16, 16))
|
||||||
runtime.GC()
|
runtime.GC()
|
||||||
@ -1656,7 +1603,7 @@ func TestImageAtAfterDisposingSubImage(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestImageSubImageSubImage(t *testing.T) {
|
func TestImageSubImageSubImage(t *testing.T) {
|
||||||
img, _ := NewImage(16, 16)
|
img := NewImage(16, 16)
|
||||||
img.Fill(color.White)
|
img.Fill(color.White)
|
||||||
sub0 := img.SubImage(image.Rect(0, 0, 12, 12)).(*Image)
|
sub0 := img.SubImage(image.Rect(0, 0, 12, 12)).(*Image)
|
||||||
sub1 := sub0.SubImage(image.Rect(4, 4, 16, 16)).(*Image)
|
sub1 := sub0.SubImage(image.Rect(4, 4, 16, 16)).(*Image)
|
||||||
@ -1693,8 +1640,8 @@ func TestImageSubImageSubImage(t *testing.T) {
|
|||||||
// Issue #839
|
// Issue #839
|
||||||
func TestImageTooSmallMipmap(t *testing.T) {
|
func TestImageTooSmallMipmap(t *testing.T) {
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
src, _ := NewImage(w, h)
|
src := NewImage(w, h)
|
||||||
dst, _ := NewImage(w, h)
|
dst := NewImage(w, h)
|
||||||
|
|
||||||
src.Fill(color.White)
|
src.Fill(color.White)
|
||||||
op := &DrawImageOptions{}
|
op := &DrawImageOptions{}
|
||||||
@ -1710,8 +1657,8 @@ func TestImageTooSmallMipmap(t *testing.T) {
|
|||||||
|
|
||||||
func TestImageZeroSizedMipmap(t *testing.T) {
|
func TestImageZeroSizedMipmap(t *testing.T) {
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
src, _ := NewImage(w, h)
|
src := NewImage(w, h)
|
||||||
dst, _ := NewImage(w, h)
|
dst := NewImage(w, h)
|
||||||
|
|
||||||
op := &DrawImageOptions{}
|
op := &DrawImageOptions{}
|
||||||
op.Filter = FilterLinear
|
op.Filter = FilterLinear
|
||||||
@ -1725,8 +1672,8 @@ func TestImageFillingAndEdges(t *testing.T) {
|
|||||||
dstw, dsth = 256, 16
|
dstw, dsth = 256, 16
|
||||||
)
|
)
|
||||||
|
|
||||||
src, _ := NewImage(srcw, srch)
|
src := NewImage(srcw, srch)
|
||||||
dst, _ := NewImage(dstw, dsth)
|
dst := NewImage(dstw, dsth)
|
||||||
|
|
||||||
src.Fill(color.White)
|
src.Fill(color.White)
|
||||||
dst.Fill(color.Black)
|
dst.Fill(color.Black)
|
||||||
@ -1752,8 +1699,8 @@ func TestImageFillingAndEdges(t *testing.T) {
|
|||||||
|
|
||||||
func TestImageDrawTrianglesAndMutateArgs(t *testing.T) {
|
func TestImageDrawTrianglesAndMutateArgs(t *testing.T) {
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
dst, _ := NewImage(w, h)
|
dst := NewImage(w, h)
|
||||||
src, _ := NewImage(w, h)
|
src := NewImage(w, h)
|
||||||
clr := color.RGBA{0xff, 0, 0, 0xff}
|
clr := color.RGBA{0xff, 0, 0, 0xff}
|
||||||
src.Fill(clr)
|
src.Fill(clr)
|
||||||
|
|
||||||
@ -1817,7 +1764,7 @@ func TestImageDrawTrianglesAndMutateArgs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestImageReplacePixelsOnSubImage(t *testing.T) {
|
func TestImageReplacePixelsOnSubImage(t *testing.T) {
|
||||||
dst, _ := NewImage(17, 31)
|
dst := NewImage(17, 31)
|
||||||
dst.Fill(color.RGBA{0xff, 0, 0, 0xff})
|
dst.Fill(color.RGBA{0xff, 0, 0, 0xff})
|
||||||
|
|
||||||
pix0 := make([]byte, 4*5*3)
|
pix0 := make([]byte, 4*5*3)
|
||||||
@ -1868,9 +1815,9 @@ func TestImageReplacePixelsOnSubImage(t *testing.T) {
|
|||||||
|
|
||||||
func TestImageDrawTrianglesWithColorM(t *testing.T) {
|
func TestImageDrawTrianglesWithColorM(t *testing.T) {
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
dst0, _ := NewImage(w, h)
|
dst0 := NewImage(w, h)
|
||||||
dst1, _ := NewImage(w, h)
|
dst1 := NewImage(w, h)
|
||||||
src, _ := NewImage(w, h)
|
src := NewImage(w, h)
|
||||||
src.Fill(color.White)
|
src.Fill(color.White)
|
||||||
|
|
||||||
vs0 := []Vertex{
|
vs0 := []Vertex{
|
||||||
@ -1977,7 +1924,7 @@ func TestImageDrawTrianglesWithColorM(t *testing.T) {
|
|||||||
|
|
||||||
// Issue #1137
|
// Issue #1137
|
||||||
func TestImageDrawOver(t *testing.T) {
|
func TestImageDrawOver(t *testing.T) {
|
||||||
dst, _ := NewImage(320, 240)
|
dst := NewImage(320, 240)
|
||||||
src := image.NewUniform(color.RGBA{0xff, 0, 0, 0xff})
|
src := image.NewUniform(color.RGBA{0xff, 0, 0, 0xff})
|
||||||
// This must not cause infinite-loop.
|
// This must not cause infinite-loop.
|
||||||
draw.Draw(dst, dst.Bounds(), src, image.ZP, draw.Over)
|
draw.Draw(dst, dst.Bounds(), src, image.ZP, draw.Over)
|
||||||
@ -1999,8 +1946,8 @@ func TestImageDrawDisposedImage(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
dst, _ := NewImage(16, 16)
|
dst := NewImage(16, 16)
|
||||||
src, _ := NewImage(16, 16)
|
src := NewImage(16, 16)
|
||||||
src.Dispose()
|
src.Dispose()
|
||||||
dst.DrawImage(src, nil)
|
dst.DrawImage(src, nil)
|
||||||
}
|
}
|
||||||
@ -2012,8 +1959,8 @@ func TestImageDrawTrianglesDisposedImage(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
dst, _ := NewImage(16, 16)
|
dst := NewImage(16, 16)
|
||||||
src, _ := NewImage(16, 16)
|
src := NewImage(16, 16)
|
||||||
src.Dispose()
|
src.Dispose()
|
||||||
vs := make([]Vertex, 4)
|
vs := make([]Vertex, 4)
|
||||||
is := []uint16{0, 1, 2, 1, 2, 3}
|
is := []uint16{0, 1, 2, 1, 2, 3}
|
||||||
@ -2022,7 +1969,7 @@ func TestImageDrawTrianglesDisposedImage(t *testing.T) {
|
|||||||
|
|
||||||
// #1137
|
// #1137
|
||||||
func BenchmarkImageDrawOver(b *testing.B) {
|
func BenchmarkImageDrawOver(b *testing.B) {
|
||||||
dst, _ := NewImage(16, 16)
|
dst := NewImage(16, 16)
|
||||||
src := image.NewUniform(color.Black)
|
src := image.NewUniform(color.Black)
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
draw.Draw(dst, dst.Bounds(), src, image.ZP, draw.Over)
|
draw.Draw(dst, dst.Bounds(), src, image.ZP, draw.Over)
|
||||||
@ -2037,7 +1984,7 @@ func TestImageFloatTranslate(t *testing.T) {
|
|||||||
s := s
|
s := s
|
||||||
t.Run(fmt.Sprintf("scale%d", s), func(t *testing.T) {
|
t.Run(fmt.Sprintf("scale%d", s), func(t *testing.T) {
|
||||||
check := func(src *Image) {
|
check := func(src *Image) {
|
||||||
dst, _ := NewImage(w*(s+1), h*(s+1))
|
dst := NewImage(w*(s+1), h*(s+1))
|
||||||
dst.Fill(color.RGBA{0xff, 0, 0, 0xff})
|
dst.Fill(color.RGBA{0xff, 0, 0, 0xff})
|
||||||
|
|
||||||
op := &DrawImageOptions{}
|
op := &DrawImageOptions{}
|
||||||
@ -2061,7 +2008,7 @@ func TestImageFloatTranslate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
t.Run("image", func(t *testing.T) {
|
t.Run("image", func(t *testing.T) {
|
||||||
src, _ := NewImage(w, h)
|
src := NewImage(w, h)
|
||||||
pix := make([]byte, 4*w*h)
|
pix := make([]byte, 4*w*h)
|
||||||
for j := 0; j < h; j++ {
|
for j := 0; j < h; j++ {
|
||||||
for i := 0; i < w; i++ {
|
for i := 0; i < w; i++ {
|
||||||
@ -2074,7 +2021,7 @@ func TestImageFloatTranslate(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("subimage", func(t *testing.T) {
|
t.Run("subimage", func(t *testing.T) {
|
||||||
src, _ := NewImage(w*s, h*s)
|
src := NewImage(w*s, h*s)
|
||||||
pix := make([]byte, 4*(w*s)*(h*s))
|
pix := make([]byte, 4*(w*s)*(h*s))
|
||||||
for j := 0; j < h*s; j++ {
|
for j := 0; j < h*s; j++ {
|
||||||
for i := 0; i < w*s; i++ {
|
for i := 0; i < w*s; i++ {
|
||||||
@ -2092,8 +2039,8 @@ func TestImageFloatTranslate(t *testing.T) {
|
|||||||
// Issue #1213
|
// Issue #1213
|
||||||
func TestImageColorMCopy(t *testing.T) {
|
func TestImageColorMCopy(t *testing.T) {
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
dst, _ := NewImage(w, h)
|
dst := NewImage(w, h)
|
||||||
src, _ := NewImage(w, h)
|
src := NewImage(w, h)
|
||||||
|
|
||||||
for k := 0; k < 256; k++ {
|
for k := 0; k < 256; k++ {
|
||||||
op := &DrawImageOptions{}
|
op := &DrawImageOptions{}
|
||||||
@ -2116,8 +2063,8 @@ func TestImageColorMCopy(t *testing.T) {
|
|||||||
// TODO: Do we have to guarantee this behavior? See #1222
|
// TODO: Do we have to guarantee this behavior? See #1222
|
||||||
func TestImageReplacePixelsAndModifyPixels(t *testing.T) {
|
func TestImageReplacePixelsAndModifyPixels(t *testing.T) {
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
dst, _ := NewImage(w, h)
|
dst := NewImage(w, h)
|
||||||
src, _ := NewImage(w, h)
|
src := NewImage(w, h)
|
||||||
|
|
||||||
pix := make([]byte, 4*w*h)
|
pix := make([]byte, 4*w*h)
|
||||||
for j := 0; j < h; j++ {
|
for j := 0; j < h; j++ {
|
||||||
@ -2159,8 +2106,8 @@ func TestImageReplacePixelsAndModifyPixels(t *testing.T) {
|
|||||||
|
|
||||||
func TestImageCompositeModeMultiply(t *testing.T) {
|
func TestImageCompositeModeMultiply(t *testing.T) {
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
dst, _ := NewImage(w, h)
|
dst := NewImage(w, h)
|
||||||
src, _ := NewImage(w, h)
|
src := NewImage(w, h)
|
||||||
|
|
||||||
dst.Fill(color.RGBA{0x10, 0x20, 0x30, 0x40})
|
dst.Fill(color.RGBA{0x10, 0x20, 0x30, 0x40})
|
||||||
src.Fill(color.RGBA{0x50, 0x60, 0x70, 0x80})
|
src.Fill(color.RGBA{0x50, 0x60, 0x70, 0x80})
|
||||||
@ -2188,8 +2135,8 @@ func TestImageCompositeModeMultiply(t *testing.T) {
|
|||||||
// Issue #1269
|
// Issue #1269
|
||||||
func TestImageZeroTriangle(t *testing.T) {
|
func TestImageZeroTriangle(t *testing.T) {
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
dst, _ := NewImage(w, h)
|
dst := NewImage(w, h)
|
||||||
src, _ := NewImage(1, 1)
|
src := NewImage(1, 1)
|
||||||
|
|
||||||
vs := []Vertex{}
|
vs := []Vertex{}
|
||||||
is := []uint16{}
|
is := []uint16{}
|
||||||
|
@ -87,7 +87,7 @@ type testResult struct {
|
|||||||
|
|
||||||
var testSetBeforeMainResult = func() testResult {
|
var testSetBeforeMainResult = func() testResult {
|
||||||
clr := color.RGBA{1, 2, 3, 4}
|
clr := color.RGBA{1, 2, 3, 4}
|
||||||
img, _ := ebiten.NewImage(16, 16)
|
img := ebiten.NewImage(16, 16)
|
||||||
img.Set(0, 0, clr)
|
img.Set(0, 0, clr)
|
||||||
|
|
||||||
ch := make(chan color.RGBA, 1)
|
ch := make(chan color.RGBA, 1)
|
||||||
@ -114,8 +114,8 @@ func TestSetBeforeMain(t *testing.T) {
|
|||||||
|
|
||||||
var testDrawImageBeforeMainResult = func() testResult {
|
var testDrawImageBeforeMainResult = func() testResult {
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
src, _ := ebiten.NewImage(w, h)
|
src := ebiten.NewImage(w, h)
|
||||||
dst, _ := ebiten.NewImage(w, h)
|
dst := ebiten.NewImage(w, h)
|
||||||
src.Set(0, 0, color.White)
|
src.Set(0, 0, color.White)
|
||||||
dst.DrawImage(src, nil)
|
dst.DrawImage(src, nil)
|
||||||
|
|
||||||
@ -143,8 +143,8 @@ func TestDrawImageBeforeMain(t *testing.T) {
|
|||||||
|
|
||||||
var testDrawTrianglesBeforeMainResult = func() testResult {
|
var testDrawTrianglesBeforeMainResult = func() testResult {
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
src, _ := ebiten.NewImage(w, h)
|
src := ebiten.NewImage(w, h)
|
||||||
dst, _ := ebiten.NewImage(w, h)
|
dst := ebiten.NewImage(w, h)
|
||||||
src.Set(0, 0, color.White)
|
src.Set(0, 0, color.White)
|
||||||
vs := []ebiten.Vertex{
|
vs := []ebiten.Vertex{
|
||||||
{
|
{
|
||||||
@ -204,7 +204,7 @@ func TestDrawTrianglesBeforeMain(t *testing.T) {
|
|||||||
|
|
||||||
var testSetAndFillBeforeMainResult = func() testResult {
|
var testSetAndFillBeforeMainResult = func() testResult {
|
||||||
clr := color.RGBA{1, 2, 3, 4}
|
clr := color.RGBA{1, 2, 3, 4}
|
||||||
img, _ := ebiten.NewImage(16, 16)
|
img := ebiten.NewImage(16, 16)
|
||||||
img.Set(0, 0, clr)
|
img.Set(0, 0, clr)
|
||||||
img.Fill(color.RGBA{5, 6, 7, 8})
|
img.Fill(color.RGBA{5, 6, 7, 8})
|
||||||
img.Set(1, 0, clr)
|
img.Set(1, 0, clr)
|
||||||
@ -233,7 +233,7 @@ func TestSetAndFillBeforeMain(t *testing.T) {
|
|||||||
|
|
||||||
var testSetAndReplacePixelsBeforeMainResult = func() testResult {
|
var testSetAndReplacePixelsBeforeMainResult = func() testResult {
|
||||||
clr := color.RGBA{1, 2, 3, 4}
|
clr := color.RGBA{1, 2, 3, 4}
|
||||||
img, _ := ebiten.NewImage(16, 16)
|
img := ebiten.NewImage(16, 16)
|
||||||
img.Set(0, 0, clr)
|
img.Set(0, 0, clr)
|
||||||
pix := make([]byte, 4*16*16)
|
pix := make([]byte, 4*16*16)
|
||||||
for i := 0; i < len(pix)/4; i++ {
|
for i := 0; i < len(pix)/4; i++ {
|
||||||
@ -268,7 +268,7 @@ func TestSetAndReplacePixelsBeforeMain(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var testReplacePixelsAndModifyBeforeMainResult = func() testResult {
|
var testReplacePixelsAndModifyBeforeMainResult = func() testResult {
|
||||||
img, _ := ebiten.NewImage(16, 16)
|
img := ebiten.NewImage(16, 16)
|
||||||
pix := make([]byte, 4*16*16)
|
pix := make([]byte, 4*16*16)
|
||||||
for i := 0; i < len(pix)/4; i++ {
|
for i := 0; i < len(pix)/4; i++ {
|
||||||
pix[4*i] = 1
|
pix[4*i] = 1
|
||||||
|
@ -25,7 +25,7 @@ import (
|
|||||||
func TestShaderFill(t *testing.T) {
|
func TestShaderFill(t *testing.T) {
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
|
|
||||||
dst, _ := NewImage(w, h)
|
dst := NewImage(w, h)
|
||||||
s, err := NewShader([]byte(`package main
|
s, err := NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
@ -55,7 +55,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
func TestShaderFillWithDrawImage(t *testing.T) {
|
func TestShaderFillWithDrawImage(t *testing.T) {
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
|
|
||||||
dst, _ := NewImage(w, h)
|
dst := NewImage(w, h)
|
||||||
s, err := NewShader([]byte(`package main
|
s, err := NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
@ -66,7 +66,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
src, _ := NewImage(w/2, h/2)
|
src := NewImage(w/2, h/2)
|
||||||
op := &DrawRectShaderOptions{}
|
op := &DrawRectShaderOptions{}
|
||||||
op.Images[0] = src
|
op.Images[0] = src
|
||||||
dst.DrawRectShader(w/2, h/2, s, op)
|
dst.DrawRectShader(w/2, h/2, s, op)
|
||||||
@ -88,7 +88,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
func TestShaderFillWithDrawTriangles(t *testing.T) {
|
func TestShaderFillWithDrawTriangles(t *testing.T) {
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
|
|
||||||
dst, _ := NewImage(w, h)
|
dst := NewImage(w, h)
|
||||||
s, err := NewShader([]byte(`package main
|
s, err := NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
@ -99,7 +99,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
src, _ := NewImage(w/2, h/2)
|
src := NewImage(w/2, h/2)
|
||||||
op := &DrawTrianglesShaderOptions{}
|
op := &DrawTrianglesShaderOptions{}
|
||||||
op.Images[0] = src
|
op.Images[0] = src
|
||||||
|
|
||||||
@ -163,7 +163,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
func TestShaderFunction(t *testing.T) {
|
func TestShaderFunction(t *testing.T) {
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
|
|
||||||
dst, _ := NewImage(w, h)
|
dst := NewImage(w, h)
|
||||||
s, err := NewShader([]byte(`package main
|
s, err := NewShader([]byte(`package main
|
||||||
|
|
||||||
func clr(red float) (float, float, float, float) {
|
func clr(red float) (float, float, float, float) {
|
||||||
@ -523,7 +523,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
func TestShaderUninitializedUniformVariables(t *testing.T) {
|
func TestShaderUninitializedUniformVariables(t *testing.T) {
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
|
|
||||||
dst, _ := NewImage(w, h)
|
dst := NewImage(w, h)
|
||||||
s, err := NewShader([]byte(`package main
|
s, err := NewShader([]byte(`package main
|
||||||
|
|
||||||
var U vec4
|
var U vec4
|
||||||
@ -766,7 +766,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
func TestShaderMatrix(t *testing.T) {
|
func TestShaderMatrix(t *testing.T) {
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
|
|
||||||
dst, _ := NewImage(w, h)
|
dst := NewImage(w, h)
|
||||||
s, err := NewShader([]byte(`package main
|
s, err := NewShader([]byte(`package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
@ -786,7 +786,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
src, _ := NewImage(w, h)
|
src := NewImage(w, h)
|
||||||
op := &DrawRectShaderOptions{}
|
op := &DrawRectShaderOptions{}
|
||||||
op.Images[0] = src
|
op.Images[0] = src
|
||||||
dst.DrawRectShader(w, h, s, op)
|
dst.DrawRectShader(w, h, s, op)
|
||||||
@ -817,7 +817,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
src0, _ := NewImage(w, h)
|
src0 := NewImage(w, h)
|
||||||
pix0 := make([]byte, 4*w*h)
|
pix0 := make([]byte, 4*w*h)
|
||||||
for j := 0; j < h; j++ {
|
for j := 0; j < h; j++ {
|
||||||
for i := 0; i < w; i++ {
|
for i := 0; i < w; i++ {
|
||||||
@ -832,7 +832,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
src0.ReplacePixels(pix0)
|
src0.ReplacePixels(pix0)
|
||||||
src0 = src0.SubImage(image.Rect(2, 3, 10, 11)).(*Image)
|
src0 = src0.SubImage(image.Rect(2, 3, 10, 11)).(*Image)
|
||||||
|
|
||||||
src1, _ := NewImage(w, h)
|
src1 := NewImage(w, h)
|
||||||
pix1 := make([]byte, 4*w*h)
|
pix1 := make([]byte, 4*w*h)
|
||||||
for j := 0; j < h; j++ {
|
for j := 0; j < h; j++ {
|
||||||
for i := 0; i < w; i++ {
|
for i := 0; i < w; i++ {
|
||||||
@ -863,7 +863,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
t.Run("DrawRectShader", func(t *testing.T) {
|
t.Run("DrawRectShader", func(t *testing.T) {
|
||||||
dst, _ := NewImage(w, h)
|
dst := NewImage(w, h)
|
||||||
op := &DrawRectShaderOptions{}
|
op := &DrawRectShaderOptions{}
|
||||||
op.Images[0] = src0
|
op.Images[0] = src0
|
||||||
op.Images[1] = src1
|
op.Images[1] = src1
|
||||||
@ -872,7 +872,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("DrawTrianglesShader", func(t *testing.T) {
|
t.Run("DrawTrianglesShader", func(t *testing.T) {
|
||||||
dst, _ := NewImage(w, h)
|
dst := NewImage(w, h)
|
||||||
vs := []Vertex{
|
vs := []Vertex{
|
||||||
{
|
{
|
||||||
DstX: 0,
|
DstX: 0,
|
||||||
|
@ -34,7 +34,7 @@ func TestMain(m *testing.M) {
|
|||||||
|
|
||||||
func TestTextColor(t *testing.T) {
|
func TestTextColor(t *testing.T) {
|
||||||
clr := color.RGBA{0x80, 0x80, 0x80, 0x80}
|
clr := color.RGBA{0x80, 0x80, 0x80, 0x80}
|
||||||
img, _ := ebiten.NewImage(30, 30)
|
img := ebiten.NewImage(30, 30)
|
||||||
Draw(img, "Hello", bitmapfont.Face, 12, 12, clr)
|
Draw(img, "Hello", bitmapfont.Face, 12, 12, clr)
|
||||||
|
|
||||||
w, h := img.Size()
|
w, h := img.Size()
|
||||||
@ -119,7 +119,7 @@ func (f *testFace) Metrics() font.Metrics {
|
|||||||
|
|
||||||
func TestTextOverlap(t *testing.T) {
|
func TestTextOverlap(t *testing.T) {
|
||||||
f := &testFace{}
|
f := &testFace{}
|
||||||
dst, _ := ebiten.NewImage(testFaceSize*2, testFaceSize)
|
dst := ebiten.NewImage(testFaceSize*2, testFaceSize)
|
||||||
|
|
||||||
// With testFace, 'b' is rendered at the previous position as 0xff.
|
// With testFace, 'b' is rendered at the previous position as 0xff.
|
||||||
// 'a' is rendered at the current position as 0x80.
|
// 'a' is rendered at the current position as 0x80.
|
||||||
|
@ -92,7 +92,7 @@ func (c *uiContext) updateOffscreen() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if c.offscreen == nil {
|
if c.offscreen == nil {
|
||||||
c.offscreen = newImage(sw, sh)
|
c.offscreen = NewImage(sw, sh)
|
||||||
c.offscreen.mipmap.SetVolatile(IsScreenClearedEveryFrame())
|
c.offscreen.mipmap.SetVolatile(IsScreenClearedEveryFrame())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,10 +25,9 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten/v2/vector/internal/triangulate"
|
"github.com/hajimehoshi/ebiten/v2/vector/internal/triangulate"
|
||||||
)
|
)
|
||||||
|
|
||||||
var emptyImage *ebiten.Image
|
var emptyImage = ebiten.NewImage(1, 1)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
emptyImage, _ = ebiten.NewImage(1, 1)
|
|
||||||
emptyImage.Fill(color.White)
|
emptyImage.Fill(color.White)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user