mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +01:00
ebiten: Remove the filter argument from NewImage and NewImageFromImage
Updates #503
This commit is contained in:
parent
0892ffa4b2
commit
fe97e7b0a5
@ -28,7 +28,7 @@ var (
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
img := assets.CreateTextImage()
|
img := assets.CreateTextImage()
|
||||||
debugPrintTextImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
debugPrintTextImage, _ = ebiten.NewImageFromImage(img)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DebugPrint draws the string str on the image on left top corner.
|
// DebugPrint draws the string str on the image on left top corner.
|
||||||
|
@ -33,7 +33,7 @@ import (
|
|||||||
// Note that this doesn't work on mobiles.
|
// Note that this doesn't work on mobiles.
|
||||||
//
|
//
|
||||||
// For productions, instead of using NewImageFromFile, it is safer to embed your resources, e.g., with github.com/rakyll/statik .
|
// For productions, instead of using NewImageFromFile, it is safer to embed your resources, e.g., with github.com/rakyll/statik .
|
||||||
func NewImageFromFile(path string, filter ebiten.Filter) (*ebiten.Image, image.Image, error) {
|
func NewImageFromFile(path string) (*ebiten.Image, image.Image, error) {
|
||||||
file, err := OpenFile(path)
|
file, err := OpenFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
@ -45,7 +45,7 @@ func NewImageFromFile(path string, filter ebiten.Filter) (*ebiten.Image, image.I
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
img2, err := ebiten.NewImageFromImage(img, filter)
|
img2, err := ebiten.NewImageFromImage(img)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
emptyImage, _ = ebiten.NewImage(1, 1, ebiten.FilterDefault)
|
emptyImage, _ = ebiten.NewImage(1, 1)
|
||||||
_ = emptyImage.Fill(color.White)
|
_ = emptyImage.Fill(color.White)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,8 +25,6 @@ import (
|
|||||||
//
|
//
|
||||||
// Image decoders must be imported when using NewImageFromURL. For example,
|
// Image decoders must be imported when using NewImageFromURL. For example,
|
||||||
// if you want to load a PNG image, you'd need to add `_ "image/png"` to the import section.
|
// if you want to load a PNG image, you'd need to add `_ "image/png"` to the import section.
|
||||||
//
|
|
||||||
// FilterDefault is used at NewImgeFromImage internally.
|
|
||||||
func NewImageFromURL(url string) (*ebiten.Image, error) {
|
func NewImageFromURL(url string) (*ebiten.Image, error) {
|
||||||
res, err := http.Get(url)
|
res, err := http.Get(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -39,6 +37,6 @@ func NewImageFromURL(url string) (*ebiten.Image, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
eimg, _ := ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
eimg, _ := ebiten.NewImageFromImage(img)
|
||||||
return eimg, nil
|
return eimg, nil
|
||||||
}
|
}
|
||||||
|
@ -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, ebiten.FilterDefault)
|
g.boardImage, _ = ebiten.NewImage(w, h)
|
||||||
}
|
}
|
||||||
screen.Fill(backgroundColor)
|
screen.Fill(backgroundColor)
|
||||||
g.board.Draw(g.boardImage)
|
g.board.Draw(g.boardImage)
|
||||||
|
@ -355,7 +355,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
tileImage, _ = ebiten.NewImage(tileSize, tileSize, ebiten.FilterDefault)
|
tileImage, _ = ebiten.NewImage(tileSize, tileSize)
|
||||||
tileImage.Fill(color.White)
|
tileImage.Fill(color.White)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
ebitenImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
ebitenImage, _ = ebiten.NewImageFromImage(img)
|
||||||
|
|
||||||
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
|
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
|
||||||
ebiten.SetWindowTitle("Additive Blending (Ebiten Demo)")
|
ebiten.SetWindowTitle("Additive Blending (Ebiten Demo)")
|
||||||
|
@ -48,7 +48,7 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
ebitenImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
ebitenImage, _ = ebiten.NewImageFromImage(img)
|
||||||
}
|
}
|
||||||
|
|
||||||
func drawRect(screen *ebiten.Image, img *ebiten.Image, x, y, width, height float32, address ebiten.Address, msg string) {
|
func drawRect(screen *ebiten.Image, img *ebiten.Image, x, y, width, height float32, address ebiten.Address, msg string) {
|
||||||
|
@ -61,14 +61,14 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
gophersImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
gophersImage, _ = ebiten.NewImageFromImage(img)
|
||||||
|
|
||||||
groundImage, _ = ebiten.NewImage(screenWidth*2, screenHeight*2/3+50, ebiten.FilterDefault)
|
groundImage, _ = ebiten.NewImage(screenWidth*2, screenHeight*2/3+50)
|
||||||
perspectiveGroundImage, _ = ebiten.NewImage(screenWidth*2, screenHeight, ebiten.FilterDefault)
|
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, ebiten.FilterDefault)
|
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{}
|
||||||
@ -92,7 +92,7 @@ func init() {
|
|||||||
fogRGBA.SetRGBA(i, j, clr)
|
fogRGBA.SetRGBA(i, j, clr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fogImage, _ = ebiten.NewImageFromImage(fogRGBA, ebiten.FilterDefault)
|
fogImage, _ = ebiten.NewImageFromImage(fogRGBA)
|
||||||
}
|
}
|
||||||
|
|
||||||
// player represents the current airship's position.
|
// player represents the current airship's position.
|
||||||
|
@ -91,7 +91,7 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
ebitenImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
ebitenImage, _ = ebiten.NewImageFromImage(img)
|
||||||
|
|
||||||
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
|
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
|
||||||
ebiten.SetWindowTitle("Alpha Blending (Ebiten Demo)")
|
ebiten.SetWindowTitle("Alpha Blending (Ebiten Demo)")
|
||||||
|
@ -77,7 +77,7 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
runnerImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
runnerImage, _ = ebiten.NewImageFromImage(img)
|
||||||
|
|
||||||
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
|
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
|
||||||
ebiten.SetWindowTitle("Animation (Ebiten Demo)")
|
ebiten.SetWindowTitle("Animation (Ebiten Demo)")
|
||||||
|
@ -140,7 +140,7 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
img, _ = ebiten.NewImageFromImage(rawimg, ebiten.FilterDefault)
|
img, _ = ebiten.NewImageFromImage(rawimg)
|
||||||
|
|
||||||
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
|
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
|
||||||
ebiten.SetWindowTitle("Audio Panning Loop (Ebiten Demo)")
|
ebiten.SetWindowTitle("Audio Panning Loop (Ebiten Demo)")
|
||||||
|
@ -76,10 +76,10 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
imageGameBG, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
imageGameBG, _ = ebiten.NewImageFromImage(img)
|
||||||
|
|
||||||
// Windows
|
// Windows
|
||||||
imageWindows, _ = ebiten.NewImage(ScreenWidth, ScreenHeight, ebiten.FilterDefault)
|
imageWindows, _ = ebiten.NewImage(ScreenWidth, ScreenHeight)
|
||||||
|
|
||||||
// Windows: Field
|
// Windows: Field
|
||||||
x, y := fieldWindowPosition()
|
x, y := fieldWindowPosition()
|
||||||
@ -104,7 +104,7 @@ func init() {
|
|||||||
drawTextBox(imageWindows, "LINES", x, y, textBoxWidth())
|
drawTextBox(imageWindows, "LINES", x, y, textBoxWidth())
|
||||||
|
|
||||||
// Gameover
|
// Gameover
|
||||||
imageGameover, _ = ebiten.NewImage(ScreenWidth, ScreenHeight, ebiten.FilterDefault)
|
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)
|
||||||
|
@ -30,7 +30,7 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
imageBlocks, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
imageBlocks, _ = ebiten.NewImageFromImage(img)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,8 +24,8 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
transitionFrom, _ = ebiten.NewImage(ScreenWidth, ScreenHeight, ebiten.FilterDefault)
|
transitionFrom, _ = ebiten.NewImage(ScreenWidth, ScreenHeight)
|
||||||
transitionTo, _ = ebiten.NewImage(ScreenWidth, ScreenHeight, ebiten.FilterDefault)
|
transitionTo, _ = ebiten.NewImage(ScreenWidth, ScreenHeight)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Scene interface {
|
type Scene interface {
|
||||||
|
@ -32,7 +32,7 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
imageBackground, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
imageBackground, _ = ebiten.NewImageFromImage(img)
|
||||||
}
|
}
|
||||||
|
|
||||||
type TitleScene struct {
|
type TitleScene struct {
|
||||||
|
@ -82,7 +82,7 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
gophersImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
gophersImage, _ = ebiten.NewImageFromImage(img)
|
||||||
|
|
||||||
ebiten.SetWindowSize(screenWidth, screenHeight)
|
ebiten.SetWindowSize(screenWidth, screenHeight)
|
||||||
ebiten.SetWindowTitle("Blur (Ebiten Demo)")
|
ebiten.SetWindowTitle("Blur (Ebiten Demo)")
|
||||||
|
@ -65,7 +65,7 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
tilesImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
tilesImage, _ = ebiten.NewImageFromImage(img)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Camera struct {
|
type Camera struct {
|
||||||
@ -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, ebiten.FilterDefault)
|
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)")
|
||||||
|
@ -37,7 +37,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
dot, _ = ebiten.NewImage(1, 1, ebiten.FilterDefault)
|
dot, _ = ebiten.NewImage(1, 1)
|
||||||
dot.Fill(color.White)
|
dot.Fill(color.White)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,11 +144,11 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
gophersImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
gophersImage, _ = ebiten.NewImageFromImage(img)
|
||||||
|
|
||||||
// Extend the shared backend GL texture on purpose.
|
// Extend the shared backend GL texture on purpose.
|
||||||
for i := 0; i < 20; i++ {
|
for i := 0; i < 20; i++ {
|
||||||
eimg, _ := ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
eimg, _ := ebiten.NewImageFromImage(img)
|
||||||
extraImages = append(extraImages, eimg)
|
extraImages = append(extraImages, eimg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,7 +203,7 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
ebitenImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
ebitenImage, _ = ebiten.NewImageFromImage(img)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGame() *Game {
|
func NewGame() *Game {
|
||||||
|
@ -82,7 +82,7 @@ func main() {
|
|||||||
// Specifying filter on NewImage[FromImage] is just for backward compatibility.
|
// Specifying filter on NewImage[FromImage] is just for backward compatibility.
|
||||||
// Now specifying filter at DrawImageOptions is recommended.
|
// Now specifying filter at DrawImageOptions is recommended.
|
||||||
// Specify FilterDefault here, that means to prefer filter specified at DrawImageOptions.
|
// Specify FilterDefault here, that means to prefer filter specified at DrawImageOptions.
|
||||||
ebitenImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
ebitenImage, _ = ebiten.NewImageFromImage(img)
|
||||||
|
|
||||||
ebiten.SetWindowSize(screenWidth, screenHeight)
|
ebiten.SetWindowSize(screenWidth, screenHeight)
|
||||||
ebiten.SetWindowTitle("Filter (Ebiten Demo)")
|
ebiten.SetWindowTitle("Filter (Ebiten Demo)")
|
||||||
|
@ -82,13 +82,13 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
gopherImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
gopherImage, _ = ebiten.NewImageFromImage(img)
|
||||||
|
|
||||||
img, _, err = image.Decode(bytes.NewReader(resources.Tiles_png))
|
img, _, err = image.Decode(bytes.NewReader(resources.Tiles_png))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
tilesImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
tilesImage, _ = ebiten.NewImageFromImage(img)
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -103,7 +103,7 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
ebitenImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
ebitenImage, _ = ebiten.NewImageFromImage(img)
|
||||||
|
|
||||||
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
|
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
|
||||||
ebiten.SetWindowTitle("Flood fill with solid colors (Ebiten Demo)")
|
ebiten.SetWindowTitle("Flood fill with solid colors (Ebiten Demo)")
|
||||||
|
@ -55,7 +55,7 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
gophersImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
gophersImage, _ = ebiten.NewImageFromImage(img)
|
||||||
}
|
}
|
||||||
|
|
||||||
func initFont() {
|
func initFont() {
|
||||||
|
@ -149,7 +149,7 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
gophersImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
gophersImage, _ = ebiten.NewImageFromImage(img)
|
||||||
|
|
||||||
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
|
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
|
||||||
ebiten.SetWindowTitle("HSV (Ebiten Demo)")
|
ebiten.SetWindowTitle("HSV (Ebiten Demo)")
|
||||||
|
@ -75,7 +75,7 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
gophersImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
gophersImage, _ = ebiten.NewImageFromImage(img)
|
||||||
|
|
||||||
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
|
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
|
||||||
ebiten.SetWindowTitle("Hue (Ebiten Demo)")
|
ebiten.SetWindowTitle("Hue (Ebiten Demo)")
|
||||||
|
@ -51,7 +51,7 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
bgImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
bgImage, _ = ebiten.NewImageFromImage(img)
|
||||||
}
|
}
|
||||||
|
|
||||||
type viewport struct {
|
type viewport struct {
|
||||||
|
@ -148,7 +148,7 @@ func keyDisplayNameToKey(name string) ebiten.Key {
|
|||||||
func drawKey(t *ebiten.Image, name string, x, y, width int) {
|
func drawKey(t *ebiten.Image, name string, x, y, width int) {
|
||||||
const height = 16
|
const height = 16
|
||||||
width--
|
width--
|
||||||
img, _ := ebiten.NewImage(width, height, ebiten.FilterDefault)
|
img, _ := ebiten.NewImage(width, height)
|
||||||
p := make([]byte, width*height*4)
|
p := make([]byte, width*height*4)
|
||||||
for j := 0; j < height; j++ {
|
for j := 0; j < height; j++ {
|
||||||
for i := 0; i < width; i++ {
|
for i := 0; i < width; i++ {
|
||||||
@ -196,7 +196,7 @@ func drawKey(t *ebiten.Image, name string, x, y, width int) {
|
|||||||
|
|
||||||
func outputKeyboardImage() (map[ebiten.Key]image.Rectangle, error) {
|
func outputKeyboardImage() (map[ebiten.Key]image.Rectangle, error) {
|
||||||
keyMap := map[ebiten.Key]image.Rectangle{}
|
keyMap := map[ebiten.Key]image.Rectangle{}
|
||||||
img, _ := ebiten.NewImage(320, 240, ebiten.FilterDefault)
|
img, _ := ebiten.NewImage(320, 240)
|
||||||
x, y := 0, 0
|
x, y := 0, 0
|
||||||
for j, line := range keyboardKeys {
|
for j, line := range keyboardKeys {
|
||||||
x = 0
|
x = 0
|
||||||
|
@ -42,7 +42,7 @@ func init() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
keyboardImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
keyboardImage, _ = ebiten.NewImageFromImage(img)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Game struct {
|
type Game struct {
|
||||||
|
@ -69,7 +69,7 @@ func updateOffscreen(centerX, centerY, size float64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
offscreen, _ = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterDefault)
|
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)
|
||||||
|
@ -55,19 +55,19 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
gopher1, _ = ebiten.NewImageFromImage(img1, ebiten.FilterDefault)
|
gopher1, _ = ebiten.NewImageFromImage(img1)
|
||||||
|
|
||||||
img2, _, err := image.Decode(bytes.NewReader(rmascot.Out02_png))
|
img2, _, err := image.Decode(bytes.NewReader(rmascot.Out02_png))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
gopher2, _ = ebiten.NewImageFromImage(img2, ebiten.FilterDefault)
|
gopher2, _ = ebiten.NewImageFromImage(img2)
|
||||||
|
|
||||||
img3, _, err := image.Decode(bytes.NewReader(rmascot.Out03_png))
|
img3, _, err := image.Decode(bytes.NewReader(rmascot.Out03_png))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
gopher3, _ = ebiten.NewImageFromImage(img3, ebiten.FilterDefault)
|
gopher3, _ = ebiten.NewImageFromImage(img3)
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -54,15 +54,15 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
bgImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
bgImage, _ = ebiten.NewImageFromImage(img)
|
||||||
|
|
||||||
img, _, err = image.Decode(bytes.NewReader(images.FiveYears_jpg))
|
img, _, err = image.Decode(bytes.NewReader(images.FiveYears_jpg))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
fgImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
fgImage, _ = ebiten.NewImageFromImage(img)
|
||||||
|
|
||||||
maskedFgImage, _ = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterDefault)
|
maskedFgImage, _ = ebiten.NewImage(screenWidth, screenHeight)
|
||||||
|
|
||||||
// Initialize the spot light image.
|
// Initialize the spot light image.
|
||||||
const r = 64
|
const r = 64
|
||||||
@ -77,7 +77,7 @@ func init() {
|
|||||||
a.SetAlpha(i, j, color.Alpha{b})
|
a.SetAlpha(i, j, color.Alpha{b})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
spotLightImage, _ = ebiten.NewImageFromImage(a, ebiten.FilterDefault)
|
spotLightImage, _ = ebiten.NewImageFromImage(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Game struct {
|
type Game struct {
|
||||||
|
@ -114,7 +114,7 @@ func main() {
|
|||||||
// Specifying filter on NewImage[FromImage] is just for backward compatibility.
|
// Specifying filter on NewImage[FromImage] is just for backward compatibility.
|
||||||
// Now specifying filter at DrawImageOptions is recommended.
|
// Now specifying filter at DrawImageOptions is recommended.
|
||||||
// Specify FilterDefault here, that means to prefer filter specified at DrawImageOptions.
|
// Specify FilterDefault here, that means to prefer filter specified at DrawImageOptions.
|
||||||
gophersImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
gophersImage, _ = ebiten.NewImageFromImage(img)
|
||||||
|
|
||||||
ebiten.SetWindowSize(screenWidth, screenHeight)
|
ebiten.SetWindowSize(screenWidth, screenHeight)
|
||||||
ebiten.SetWindowTitle("Minify (Ebiten Demo)")
|
ebiten.SetWindowTitle("Minify (Ebiten Demo)")
|
||||||
|
@ -52,7 +52,7 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
gophersImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
gophersImage, _ = ebiten.NewImageFromImage(img)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Game struct {
|
type Game struct {
|
||||||
@ -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, ebiten.FilterDefault)
|
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 {
|
||||||
|
@ -53,9 +53,9 @@ func init() {
|
|||||||
Pix: pixels,
|
Pix: pixels,
|
||||||
Stride: 4,
|
Stride: 4,
|
||||||
Rect: image.Rect(0, 0, 4, 4),
|
Rect: image.Rect(0, 0, 4, 4),
|
||||||
}, ebiten.FilterDefault)
|
})
|
||||||
|
|
||||||
canvasImage, _ = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterDefault)
|
canvasImage, _ = ebiten.NewImage(screenWidth, screenHeight)
|
||||||
canvasImage.Fill(color.White)
|
canvasImage.Fill(color.White)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
smokeImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
smokeImage, _ = ebiten.NewImageFromImage(img)
|
||||||
}
|
}
|
||||||
|
|
||||||
type sprite struct {
|
type sprite struct {
|
||||||
|
@ -82,7 +82,7 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
gophersImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
gophersImage, _ = ebiten.NewImageFromImage(img)
|
||||||
|
|
||||||
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
|
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
|
||||||
ebiten.SetWindowTitle("Perspective (Ebiten Demo)")
|
ebiten.SetWindowTitle("Perspective (Ebiten Demo)")
|
||||||
|
@ -156,7 +156,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
pianoImage, _ = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterDefault)
|
pianoImage, _ = ebiten.NewImage(screenWidth, screenHeight)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
keyWidth = 24
|
keyWidth = 24
|
||||||
|
@ -47,25 +47,25 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
rightSprite, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
rightSprite, _ = ebiten.NewImageFromImage(img)
|
||||||
|
|
||||||
img, _, err = image.Decode(bytes.NewReader(rplatformer.Left_png))
|
img, _, err = image.Decode(bytes.NewReader(rplatformer.Left_png))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
leftSprite, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
leftSprite, _ = ebiten.NewImageFromImage(img)
|
||||||
|
|
||||||
img, _, err = image.Decode(bytes.NewReader(rplatformer.MainChar_png))
|
img, _, err = image.Decode(bytes.NewReader(rplatformer.MainChar_png))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
idleSprite, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
idleSprite, _ = ebiten.NewImageFromImage(img)
|
||||||
|
|
||||||
img, _, err = image.Decode(bytes.NewReader(rplatformer.Background_png))
|
img, _, err = image.Decode(bytes.NewReader(rplatformer.Background_png))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
backgroundImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
backgroundImage, _ = ebiten.NewImageFromImage(img)
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -33,7 +33,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
emptyImage, _ = ebiten.NewImage(16, 16, ebiten.FilterDefault)
|
emptyImage, _ = ebiten.NewImage(16, 16)
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -59,9 +59,9 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
bgImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
bgImage, _ = ebiten.NewImageFromImage(img)
|
||||||
shadowImage, _ = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterDefault)
|
shadowImage, _ = ebiten.NewImage(screenWidth, screenHeight)
|
||||||
triangleImage, _ = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterDefault)
|
triangleImage, _ = ebiten.NewImage(screenWidth, screenHeight)
|
||||||
triangleImage.Fill(color.White)
|
triangleImage.Fill(color.White)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
gophersImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
gophersImage, _ = ebiten.NewImageFromImage(img)
|
||||||
|
|
||||||
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
|
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
|
||||||
ebiten.SetWindowTitle("Rotate (Ebiten Demo)")
|
ebiten.SetWindowTitle("Rotate (Ebiten Demo)")
|
||||||
|
@ -39,7 +39,7 @@ func init() {
|
|||||||
var offscreen *ebiten.Image
|
var offscreen *ebiten.Image
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
offscreen, _ = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterDefault)
|
offscreen, _ = ebiten.NewImage(screenWidth, screenHeight)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Game struct {
|
type Game struct {
|
||||||
|
@ -54,7 +54,7 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
gopherImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
gopherImage, _ = ebiten.NewImageFromImage(img)
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -62,7 +62,7 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
gopherBgImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
gopherBgImage, _ = ebiten.NewImageFromImage(img)
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -70,7 +70,7 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
normalImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
normalImage, _ = ebiten.NewImageFromImage(img)
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -78,7 +78,7 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
noiseImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
noiseImage, _ = ebiten.NewImageFromImage(img)
|
||||||
}
|
}
|
||||||
|
|
||||||
var shaderSrcs = [][]byte{
|
var shaderSrcs = [][]byte{
|
||||||
|
@ -32,7 +32,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
emptyImage, _ = ebiten.NewImage(16, 16, ebiten.FilterDefault)
|
emptyImage, _ = ebiten.NewImage(16, 16)
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -54,10 +54,10 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
origEbitenImage, _ := ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
origEbitenImage, _ := ebiten.NewImageFromImage(img)
|
||||||
|
|
||||||
w, h := origEbitenImage.Size()
|
w, h := origEbitenImage.Size()
|
||||||
ebitenImage, _ = ebiten.NewImage(w, h, ebiten.FilterDefault)
|
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)
|
||||||
|
@ -56,10 +56,10 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
origEbitenImage, _ := ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
origEbitenImage, _ := ebiten.NewImageFromImage(img)
|
||||||
|
|
||||||
w, h := origEbitenImage.Size()
|
w, h := origEbitenImage.Size()
|
||||||
ebitenImage, _ = ebiten.NewImage(w, h, ebiten.FilterDefault)
|
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)
|
||||||
|
@ -279,7 +279,7 @@ 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, ebiten.FilterDefault)
|
c, _ := ebiten.NewImage(width, height)
|
||||||
canvas = c
|
canvas = c
|
||||||
canvas.Fill(background)
|
canvas.Fill(background)
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
tilesImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
tilesImage, _ = ebiten.NewImageFromImage(img)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Game struct {
|
type Game struct {
|
||||||
|
@ -58,7 +58,7 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
uiImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
uiImage, _ = ebiten.NewImageFromImage(img)
|
||||||
|
|
||||||
tt, err := opentype.Parse(goregular.TTF)
|
tt, err := opentype.Parse(goregular.TTF)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -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, ebiten.FilterDefault)
|
t.contentBuf, _ = ebiten.NewImage(w, h)
|
||||||
}
|
}
|
||||||
|
|
||||||
t.contentBuf.Clear()
|
t.contentBuf.Clear()
|
||||||
|
@ -28,7 +28,7 @@ import (
|
|||||||
var pointerImage *ebiten.Image
|
var pointerImage *ebiten.Image
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
pointerImage, _ = ebiten.NewImage(4, 4, ebiten.FilterDefault)
|
pointerImage, _ = ebiten.NewImage(4, 4)
|
||||||
pointerImage.Fill(color.RGBA{0xff, 0, 0, 0xff})
|
pointerImage.Fill(color.RGBA{0xff, 0, 0, 0xff})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -349,7 +349,7 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
gophersImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
gophersImage, _ = ebiten.NewImageFromImage(img)
|
||||||
|
|
||||||
ebiten.SetWindowIcon([]image.Image{createRandomIconImage()})
|
ebiten.SetWindowIcon([]image.Image{createRandomIconImage()})
|
||||||
|
|
||||||
|
24
image.go
24
image.go
@ -42,8 +42,6 @@ type Image struct {
|
|||||||
|
|
||||||
bounds image.Rectangle
|
bounds image.Rectangle
|
||||||
original *Image
|
original *Image
|
||||||
|
|
||||||
filter Filter
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) copyCheck() {
|
func (i *Image) copyCheck() {
|
||||||
@ -199,8 +197,6 @@ func (i *Image) DrawImage(img *Image, options *DrawImageOptions) error {
|
|||||||
filter := driver.FilterNearest
|
filter := driver.FilterNearest
|
||||||
if options.Filter != FilterDefault {
|
if options.Filter != FilterDefault {
|
||||||
filter = driver.Filter(options.Filter)
|
filter = driver.Filter(options.Filter)
|
||||||
} else if img.filter != FilterDefault {
|
|
||||||
filter = driver.Filter(img.filter)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
a, b, c, d, tx, ty := options.GeoM.elements32()
|
a, b, c, d, tx, ty := options.GeoM.elements32()
|
||||||
@ -331,8 +327,6 @@ func (i *Image) DrawTriangles(vertices []Vertex, indices []uint16, img *Image, o
|
|||||||
filter := driver.FilterNearest
|
filter := driver.FilterNearest
|
||||||
if options.Filter != FilterDefault {
|
if options.Filter != FilterDefault {
|
||||||
filter = driver.Filter(options.Filter)
|
filter = driver.Filter(options.Filter)
|
||||||
} else if img.filter != FilterDefault {
|
|
||||||
filter = driver.Filter(img.filter)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vs := make([]float32, len(vertices)*graphics.VertexFloatNum)
|
vs := make([]float32, len(vertices)*graphics.VertexFloatNum)
|
||||||
@ -623,7 +617,6 @@ func (i *Image) SubImage(r image.Rectangle) image.Image {
|
|||||||
|
|
||||||
img := &Image{
|
img := &Image{
|
||||||
mipmap: i.mipmap,
|
mipmap: i.mipmap,
|
||||||
filter: i.filter,
|
|
||||||
bounds: r,
|
bounds: r,
|
||||||
original: orig,
|
original: orig,
|
||||||
}
|
}
|
||||||
@ -755,18 +748,14 @@ func (i *Image) ReplacePixels(pixels []byte) error {
|
|||||||
//
|
//
|
||||||
// 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.
|
||||||
//
|
//
|
||||||
// filter argument is just for backward compatibility.
|
|
||||||
// If you are not sure, specify FilterDefault.
|
|
||||||
//
|
|
||||||
// Error returned by NewImage is always nil as of 1.5.0.
|
// Error returned by NewImage is always nil as of 1.5.0.
|
||||||
func NewImage(width, height int, filter Filter) (*Image, error) {
|
func NewImage(width, height int) (*Image, error) {
|
||||||
return newImage(width, height, filter), nil
|
return newImage(width, height), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newImage(width, height int, filter Filter) *Image {
|
func newImage(width, height int) *Image {
|
||||||
i := &Image{
|
i := &Image{
|
||||||
mipmap: mipmap.New(width, height),
|
mipmap: mipmap.New(width, height),
|
||||||
filter: filter,
|
|
||||||
bounds: image.Rect(0, 0, width, height),
|
bounds: image.Rect(0, 0, width, height),
|
||||||
}
|
}
|
||||||
i.addr = i
|
i.addr = i
|
||||||
@ -777,18 +766,14 @@ func newImage(width, height int, filter Filter) *Image {
|
|||||||
//
|
//
|
||||||
// If source's width or height is less than 1 or more than device-dependent maximum size, NewImageFromImage panics.
|
// If source's width or height is less than 1 or more than device-dependent maximum size, NewImageFromImage panics.
|
||||||
//
|
//
|
||||||
// filter argument is just for backward compatibility.
|
|
||||||
// If you are not sure, specify FilterDefault.
|
|
||||||
//
|
|
||||||
// Error returned by NewImageFromImage is always nil as of 1.5.0.
|
// Error returned by NewImageFromImage is always nil as of 1.5.0.
|
||||||
func NewImageFromImage(source image.Image, filter Filter) (*Image, error) {
|
func NewImageFromImage(source image.Image) (*Image, error) {
|
||||||
size := source.Bounds().Size()
|
size := source.Bounds().Size()
|
||||||
|
|
||||||
width, height := size.X, size.Y
|
width, height := size.X, size.Y
|
||||||
|
|
||||||
i := &Image{
|
i := &Image{
|
||||||
mipmap: mipmap.New(width, height),
|
mipmap: mipmap.New(width, height),
|
||||||
filter: filter,
|
|
||||||
bounds: image.Rect(0, 0, width, height),
|
bounds: image.Rect(0, 0, width, height),
|
||||||
}
|
}
|
||||||
i.addr = i
|
i.addr = i
|
||||||
@ -800,7 +785,6 @@ func NewImageFromImage(source image.Image, filter Filter) (*Image, error) {
|
|||||||
func newScreenFramebufferImage(width, height int) *Image {
|
func newScreenFramebufferImage(width, height int) *Image {
|
||||||
i := &Image{
|
i := &Image{
|
||||||
mipmap: mipmap.NewScreenFramebufferMipmap(width, height),
|
mipmap: mipmap.NewScreenFramebufferMipmap(width, height),
|
||||||
filter: FilterDefault,
|
|
||||||
bounds: image.Rect(0, 0, width, height),
|
bounds: image.Rect(0, 0, width, height),
|
||||||
}
|
}
|
||||||
i.addr = i
|
i.addr = i
|
||||||
|
208
image_test.go
208
image_test.go
@ -59,7 +59,7 @@ func openEbitenImage() (*Image, image.Image, error) {
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
eimg, err := NewImageFromImage(img, FilterNearest)
|
eimg, err := NewImageFromImage(img)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
@ -123,13 +123,13 @@ 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, FilterNearest)
|
img2, err := NewImage(w, h)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
img3, err := NewImage(w, h, FilterNearest)
|
img3, err := NewImage(w, h)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
return
|
return
|
||||||
@ -143,7 +143,7 @@ func TestImageComposition(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
img_12_3, err := NewImage(w, h, FilterNearest)
|
img_12_3, err := NewImage(w, h)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
return
|
return
|
||||||
@ -169,7 +169,7 @@ func TestImageComposition(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
img_1_23, err := NewImage(w, h, FilterNearest)
|
img_1_23, err := NewImage(w, h)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
return
|
return
|
||||||
@ -227,7 +227,7 @@ func TestImageScale(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
w, h := img0.Size()
|
w, h := img0.Size()
|
||||||
img1, err := NewImage(w*scale, h*scale, FilterNearest)
|
img1, err := NewImage(w*scale, h*scale)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
return
|
return
|
||||||
@ -259,7 +259,7 @@ func TestImage90DegreeRotate(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
w, h := img0.Size()
|
w, h := img0.Size()
|
||||||
img1, err := NewImage(h, w, FilterNearest)
|
img1, err := NewImage(h, w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
return
|
return
|
||||||
@ -290,7 +290,7 @@ func TestImageDotByDotInversion(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
w, h := img0.Size()
|
w, h := img0.Size()
|
||||||
img1, err := NewImage(w, h, FilterNearest)
|
img1, err := NewImage(w, h)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
return
|
return
|
||||||
@ -316,7 +316,7 @@ func TestImageDotByDotInversion(t *testing.T) {
|
|||||||
|
|
||||||
func TestImageReplacePixels(t *testing.T) {
|
func TestImageReplacePixels(t *testing.T) {
|
||||||
// Create a dummy image so that the shared texture is used and origImg's position is shfited.
|
// Create a dummy image so that the shared texture is used and origImg's position is shfited.
|
||||||
dummyImg, _ := NewImageFromImage(image.NewRGBA(image.Rect(0, 0, 16, 16)), FilterDefault)
|
dummyImg, _ := NewImageFromImage(image.NewRGBA(image.Rect(0, 0, 16, 16)))
|
||||||
defer dummyImg.Dispose()
|
defer dummyImg.Dispose()
|
||||||
|
|
||||||
_, origImg, err := openEbitenImage()
|
_, origImg, err := openEbitenImage()
|
||||||
@ -329,7 +329,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, FilterNearest)
|
img0, err := NewImage(size.X, size.Y)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
return
|
return
|
||||||
@ -379,7 +379,7 @@ func TestImageReplacePixelsNil(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
img, err := NewImage(16, 16, FilterNearest)
|
img, err := NewImage(16, 16)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
return
|
return
|
||||||
@ -389,7 +389,7 @@ func TestImageReplacePixelsNil(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestImageDispose(t *testing.T) {
|
func TestImageDispose(t *testing.T) {
|
||||||
img, err := NewImage(16, 16, FilterNearest)
|
img, err := NewImage(16, 16)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
return
|
return
|
||||||
@ -423,7 +423,7 @@ func TestImageCompositeModeLighter(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
w, h := img0.Size()
|
w, h := img0.Size()
|
||||||
img1, err := NewImage(w, h, FilterNearest)
|
img1, err := NewImage(w, h)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
return
|
return
|
||||||
@ -459,7 +459,7 @@ func TestNewImageFromEbitenImage(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if _, err := NewImageFromImage(img, FilterNearest); err != nil {
|
if _, err := NewImageFromImage(img); err != nil {
|
||||||
t.Errorf("NewImageFromImage returns error: %v", err)
|
t.Errorf("NewImageFromImage returns error: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -472,7 +472,7 @@ func TestNewImageFromSubImage(t *testing.T) {
|
|||||||
}
|
}
|
||||||
w, h := img.Bounds().Dx(), img.Bounds().Dy()
|
w, h := img.Bounds().Dx(), img.Bounds().Dy()
|
||||||
subImg := img.(*image.NRGBA).SubImage(image.Rect(1, 1, w-1, h-1))
|
subImg := img.(*image.NRGBA).SubImage(image.Rect(1, 1, w-1, h-1))
|
||||||
eimg, err := NewImageFromImage(subImg, FilterNearest)
|
eimg, err := NewImageFromImage(subImg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
return
|
return
|
||||||
@ -506,7 +506,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, FilterNearest)
|
img, err := NewImage(w, h)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
return
|
return
|
||||||
@ -531,7 +531,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, FilterNearest)
|
img, err := NewImage(w, h)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
return
|
return
|
||||||
@ -575,7 +575,7 @@ func TestImageEdge(t *testing.T) {
|
|||||||
img1Width = 32
|
img1Width = 32
|
||||||
img1Height = 32
|
img1Height = 32
|
||||||
)
|
)
|
||||||
img0, _ := NewImage(img0Width, img0Height, FilterNearest)
|
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++ {
|
||||||
@ -587,7 +587,7 @@ func TestImageEdge(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
img0.ReplacePixels(pixels)
|
img0.ReplacePixels(pixels)
|
||||||
img1, _ := NewImage(img1Width, img1Height, FilterDefault)
|
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}
|
||||||
|
|
||||||
@ -707,8 +707,8 @@ func TestImageTooManyFill(t *testing.T) {
|
|||||||
return uint8((17*index + 0x40) % 256)
|
return uint8((17*index + 0x40) % 256)
|
||||||
}
|
}
|
||||||
|
|
||||||
src, _ := NewImage(1, 1, FilterNearest)
|
src, _ := NewImage(1, 1)
|
||||||
dst, _ := NewImage(width, 1, FilterNearest)
|
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})
|
||||||
@ -728,8 +728,8 @@ func TestImageTooManyFill(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkDrawImage(b *testing.B) {
|
func BenchmarkDrawImage(b *testing.B) {
|
||||||
img0, _ := NewImage(16, 16, FilterNearest)
|
img0, _ := NewImage(16, 16)
|
||||||
img1, _ := NewImage(16, 16, FilterNearest)
|
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)
|
||||||
@ -737,7 +737,7 @@ func BenchmarkDrawImage(b *testing.B) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestImageLinearGradiation(t *testing.T) {
|
func TestImageLinearGradiation(t *testing.T) {
|
||||||
img0, _ := NewImage(2, 2, FilterNearest)
|
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,
|
||||||
@ -746,7 +746,7 @@ func TestImageLinearGradiation(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const w, h = 32, 32
|
const w, h = 32, 32
|
||||||
img1, _ := NewImage(w, h, FilterNearest)
|
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)
|
||||||
@ -764,8 +764,8 @@ func TestImageLinearGradiation(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestImageOutside(t *testing.T) {
|
func TestImageOutside(t *testing.T) {
|
||||||
src, _ := NewImage(5, 10, FilterNearest) // internal texture size is 8x16.
|
src, _ := NewImage(5, 10) // internal texture size is 8x16.
|
||||||
dst, _ := NewImage(4, 4, FilterNearest)
|
dst, _ := NewImage(4, 4)
|
||||||
src.Fill(color.RGBA{0xff, 0, 0, 0xff})
|
src.Fill(color.RGBA{0xff, 0, 0, 0xff})
|
||||||
|
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
@ -806,9 +806,9 @@ func TestImageOutside(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestImageOutsideUpperLeft(t *testing.T) {
|
func TestImageOutsideUpperLeft(t *testing.T) {
|
||||||
src, _ := NewImage(4, 4, FilterNearest)
|
src, _ := NewImage(4, 4)
|
||||||
dst1, _ := NewImage(16, 16, FilterNearest)
|
dst1, _ := NewImage(16, 16)
|
||||||
dst2, _ := NewImage(16, 16, FilterNearest)
|
dst2, _ := NewImage(16, 16)
|
||||||
src.Fill(color.RGBA{0xff, 0, 0, 0xff})
|
src.Fill(color.RGBA{0xff, 0, 0, 0xff})
|
||||||
|
|
||||||
op := &DrawImageOptions{}
|
op := &DrawImageOptions{}
|
||||||
@ -838,7 +838,7 @@ func TestImageSize(t *testing.T) {
|
|||||||
w = 17
|
w = 17
|
||||||
h = 31
|
h = 31
|
||||||
)
|
)
|
||||||
img, _ := NewImage(w, h, FilterDefault)
|
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)
|
||||||
@ -849,8 +849,8 @@ func TestImageSize(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestImageSize1(t *testing.T) {
|
func TestImageSize1(t *testing.T) {
|
||||||
src, _ := NewImage(1, 1, FilterNearest)
|
src, _ := NewImage(1, 1)
|
||||||
dst, _ := NewImage(1, 1, FilterNearest)
|
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)
|
||||||
@ -862,8 +862,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, FilterNearest)
|
src, _ := NewImage(4096, 4096)
|
||||||
dst, _ := NewImage(4096, 4096, FilterNearest)
|
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
|
||||||
@ -908,7 +908,7 @@ func TestImageCopy(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
img0, _ := NewImage(256, 256, FilterDefault)
|
img0, _ := NewImage(256, 256)
|
||||||
img1 := *img0
|
img1 := *img0
|
||||||
img1.Fill(color.Transparent)
|
img1.Fill(color.Transparent)
|
||||||
}
|
}
|
||||||
@ -921,10 +921,10 @@ func TestImageStretch(t *testing.T) {
|
|||||||
|
|
||||||
const w = 16
|
const w = 16
|
||||||
|
|
||||||
dst, _ := NewImage(w, 4096, FilterDefault)
|
dst, _ := NewImage(w, 4096)
|
||||||
loop:
|
loop:
|
||||||
for h := 1; h <= 32; h++ {
|
for h := 1; h <= 32; h++ {
|
||||||
src, _ := NewImage(w, h, FilterDefault)
|
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++ {
|
||||||
@ -971,9 +971,9 @@ func TestImageSprites(t *testing.T) {
|
|||||||
height = 512
|
height = 512
|
||||||
)
|
)
|
||||||
|
|
||||||
src, _ := NewImage(4, 4, FilterNearest)
|
src, _ := NewImage(4, 4)
|
||||||
src.Fill(color.RGBA{0xff, 0xff, 0xff, 0xff})
|
src.Fill(color.RGBA{0xff, 0xff, 0xff, 0xff})
|
||||||
dst, _ := NewImage(width, height, FilterNearest)
|
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{}
|
||||||
@ -1002,26 +1002,26 @@ func Disabled_TestImageMipmap(t *testing.T) {
|
|||||||
}
|
}
|
||||||
w, h := src.Size()
|
w, h := src.Size()
|
||||||
|
|
||||||
l1, _ := NewImage(w/2, h/2, FilterDefault)
|
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, FilterDefault)
|
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, FilterDefault)
|
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, FilterDefault)
|
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
|
||||||
@ -1047,27 +1047,27 @@ func Disabled_TestImageMipmapNegativeDet(t *testing.T) {
|
|||||||
}
|
}
|
||||||
w, h := src.Size()
|
w, h := src.Size()
|
||||||
|
|
||||||
l1, _ := NewImage(w/2, h/2, FilterDefault)
|
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, FilterDefault)
|
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, FilterDefault)
|
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, FilterDefault)
|
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))
|
||||||
@ -1095,8 +1095,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, FilterDefault)
|
img0, _ := NewImage(256, 256)
|
||||||
img1, _ := NewImage(128, 128, FilterDefault)
|
img1, _ := NewImage(128, 128)
|
||||||
img1.Fill(color.White)
|
img1.Fill(color.White)
|
||||||
|
|
||||||
for i := 0; i < 8; i++ {
|
for i := 0; i < 8; i++ {
|
||||||
@ -1125,9 +1125,9 @@ func TestImageMipmapColor(t *testing.T) {
|
|||||||
|
|
||||||
// Issue #725
|
// Issue #725
|
||||||
func TestImageMiamapAndDrawTriangle(t *testing.T) {
|
func TestImageMiamapAndDrawTriangle(t *testing.T) {
|
||||||
img0, _ := NewImage(32, 32, FilterDefault)
|
img0, _ := NewImage(32, 32)
|
||||||
img1, _ := NewImage(128, 128, FilterDefault)
|
img1, _ := NewImage(128, 128)
|
||||||
img2, _ := NewImage(128, 128, FilterDefault)
|
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})
|
||||||
@ -1201,7 +1201,7 @@ func TestImageMiamapAndDrawTriangle(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestImageSubImageAt(t *testing.T) {
|
func TestImageSubImageAt(t *testing.T) {
|
||||||
img, _ := NewImage(16, 16, FilterDefault)
|
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)
|
||||||
@ -1218,7 +1218,7 @@ func TestImageSubImageAt(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestImageSubImageSize(t *testing.T) {
|
func TestImageSubImageSize(t *testing.T) {
|
||||||
img, _ := NewImage(16, 16, FilterDefault)
|
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()
|
||||||
@ -1230,8 +1230,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, FilterDefault)
|
img0, _ := NewImage(w, h)
|
||||||
img1, _ := NewImage(w, h, FilterDefault)
|
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})
|
||||||
@ -1262,8 +1262,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, FilterDefault)
|
src, _ := NewImage(w, h)
|
||||||
dst, _ := NewImage(int(math.Floor(w*scale)), h, FilterDefault)
|
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++ {
|
||||||
@ -1311,8 +1311,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, FilterDefault)
|
src, _ := NewImage(w, h)
|
||||||
dst, _ := NewImage(w, h, FilterDefault)
|
dst, _ := NewImage(w, h)
|
||||||
|
|
||||||
idx := 0
|
idx := 0
|
||||||
pix := make([]byte, 4*w*h)
|
pix := make([]byte, 4*w*h)
|
||||||
@ -1356,8 +1356,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, FilterDefault)
|
src, _ := NewImage(w, h)
|
||||||
dst, _ := NewImage(w, h, FilterDefault)
|
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++ {
|
||||||
@ -1437,7 +1437,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, FilterDefault)
|
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.
|
||||||
@ -1455,7 +1455,7 @@ func TestImageSet(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
img, _ := NewImage(w, h, FilterDefault)
|
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},
|
||||||
@ -1487,8 +1487,8 @@ func TestImageSetAndDraw(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const w, h = 16, 16
|
const w, h = 16, 16
|
||||||
src, _ := NewImage(w, h, FilterDefault)
|
src, _ := NewImage(w, h)
|
||||||
dst, _ := NewImage(w, h, FilterDefault)
|
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},
|
||||||
@ -1546,10 +1546,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, FilterDefault)
|
src0, _ := NewImage(w, h)
|
||||||
src1, _ := NewImage(w, h, FilterDefault)
|
src1, _ := NewImage(w, h)
|
||||||
dst0, _ := NewImage(w, h, FilterDefault)
|
dst0, _ := NewImage(w, h)
|
||||||
dst1, _ := NewImage(w, h, FilterDefault)
|
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++ {
|
||||||
@ -1611,8 +1611,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, FilterDefault)
|
src, _ := NewImage(w, h)
|
||||||
dst, _ := NewImage(w, h, FilterDefault)
|
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++ {
|
||||||
@ -1695,7 +1695,7 @@ func TestImageDrawTrianglesWithSubImage(t *testing.T) {
|
|||||||
|
|
||||||
// Issue #823
|
// Issue #823
|
||||||
func TestImageAtAfterDisposingSubImage(t *testing.T) {
|
func TestImageAtAfterDisposingSubImage(t *testing.T) {
|
||||||
img, _ := NewImage(16, 16, FilterDefault)
|
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()
|
||||||
@ -1715,7 +1715,7 @@ func TestImageAtAfterDisposingSubImage(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestImageSubImageSubImage(t *testing.T) {
|
func TestImageSubImageSubImage(t *testing.T) {
|
||||||
img, _ := NewImage(16, 16, FilterDefault)
|
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)
|
||||||
@ -1752,8 +1752,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, FilterDefault)
|
src, _ := NewImage(w, h)
|
||||||
dst, _ := NewImage(w, h, FilterDefault)
|
dst, _ := NewImage(w, h)
|
||||||
|
|
||||||
src.Fill(color.White)
|
src.Fill(color.White)
|
||||||
op := &DrawImageOptions{}
|
op := &DrawImageOptions{}
|
||||||
@ -1769,8 +1769,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, FilterDefault)
|
src, _ := NewImage(w, h)
|
||||||
dst, _ := NewImage(w, h, FilterDefault)
|
dst, _ := NewImage(w, h)
|
||||||
|
|
||||||
op := &DrawImageOptions{}
|
op := &DrawImageOptions{}
|
||||||
op.Filter = FilterLinear
|
op.Filter = FilterLinear
|
||||||
@ -1784,8 +1784,8 @@ func TestImageFillingAndEdges(t *testing.T) {
|
|||||||
dstw, dsth = 256, 16
|
dstw, dsth = 256, 16
|
||||||
)
|
)
|
||||||
|
|
||||||
src, _ := NewImage(srcw, srch, FilterDefault)
|
src, _ := NewImage(srcw, srch)
|
||||||
dst, _ := NewImage(dstw, dsth, FilterDefault)
|
dst, _ := NewImage(dstw, dsth)
|
||||||
|
|
||||||
src.Fill(color.White)
|
src.Fill(color.White)
|
||||||
dst.Fill(color.Black)
|
dst.Fill(color.Black)
|
||||||
@ -1811,8 +1811,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, FilterDefault)
|
dst, _ := NewImage(w, h)
|
||||||
src, _ := NewImage(w, h, FilterDefault)
|
src, _ := NewImage(w, h)
|
||||||
clr := color.RGBA{0xff, 0, 0, 0xff}
|
clr := color.RGBA{0xff, 0, 0, 0xff}
|
||||||
src.Fill(clr)
|
src.Fill(clr)
|
||||||
|
|
||||||
@ -1876,7 +1876,7 @@ func TestImageDrawTrianglesAndMutateArgs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestImageReplacePixelsOnSubImage(t *testing.T) {
|
func TestImageReplacePixelsOnSubImage(t *testing.T) {
|
||||||
dst, _ := NewImage(17, 31, FilterDefault)
|
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)
|
||||||
@ -1927,9 +1927,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, FilterDefault)
|
dst0, _ := NewImage(w, h)
|
||||||
dst1, _ := NewImage(w, h, FilterDefault)
|
dst1, _ := NewImage(w, h)
|
||||||
src, _ := NewImage(w, h, FilterDefault)
|
src, _ := NewImage(w, h)
|
||||||
src.Fill(color.White)
|
src.Fill(color.White)
|
||||||
|
|
||||||
vs0 := []Vertex{
|
vs0 := []Vertex{
|
||||||
@ -2036,7 +2036,7 @@ func TestImageDrawTrianglesWithColorM(t *testing.T) {
|
|||||||
|
|
||||||
// Issue #1137
|
// Issue #1137
|
||||||
func TestImageDrawOver(t *testing.T) {
|
func TestImageDrawOver(t *testing.T) {
|
||||||
dst, _ := NewImage(320, 240, FilterDefault)
|
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)
|
||||||
@ -2058,8 +2058,8 @@ func TestImageDrawDisposedImage(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
dst, _ := NewImage(16, 16, FilterNearest)
|
dst, _ := NewImage(16, 16)
|
||||||
src, _ := NewImage(16, 16, FilterNearest)
|
src, _ := NewImage(16, 16)
|
||||||
src.Dispose()
|
src.Dispose()
|
||||||
dst.DrawImage(src, nil)
|
dst.DrawImage(src, nil)
|
||||||
}
|
}
|
||||||
@ -2071,8 +2071,8 @@ func TestImageDrawTrianglesDisposedImage(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
dst, _ := NewImage(16, 16, FilterNearest)
|
dst, _ := NewImage(16, 16)
|
||||||
src, _ := NewImage(16, 16, FilterNearest)
|
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}
|
||||||
@ -2081,7 +2081,7 @@ func TestImageDrawTrianglesDisposedImage(t *testing.T) {
|
|||||||
|
|
||||||
// #1137
|
// #1137
|
||||||
func BenchmarkImageDrawOver(b *testing.B) {
|
func BenchmarkImageDrawOver(b *testing.B) {
|
||||||
dst, _ := NewImage(16, 16, FilterDefault)
|
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)
|
||||||
@ -2096,7 +2096,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), FilterDefault)
|
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{}
|
||||||
@ -2120,7 +2120,7 @@ func TestImageFloatTranslate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
t.Run("image", func(t *testing.T) {
|
t.Run("image", func(t *testing.T) {
|
||||||
src, _ := NewImage(w, h, FilterDefault)
|
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++ {
|
||||||
@ -2133,7 +2133,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, FilterDefault)
|
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++ {
|
||||||
@ -2151,8 +2151,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, FilterDefault)
|
dst, _ := NewImage(w, h)
|
||||||
src, _ := NewImage(w, h, FilterDefault)
|
src, _ := NewImage(w, h)
|
||||||
|
|
||||||
for k := 0; k < 256; k++ {
|
for k := 0; k < 256; k++ {
|
||||||
op := &DrawImageOptions{}
|
op := &DrawImageOptions{}
|
||||||
@ -2175,8 +2175,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, FilterDefault)
|
dst, _ := NewImage(w, h)
|
||||||
src, _ := NewImage(w, h, FilterDefault)
|
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++ {
|
||||||
@ -2218,8 +2218,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, FilterDefault)
|
dst, _ := NewImage(w, h)
|
||||||
src, _ := NewImage(w, h, FilterDefault)
|
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})
|
||||||
@ -2247,8 +2247,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, FilterDefault)
|
dst, _ := NewImage(w, h)
|
||||||
src, _ := NewImage(1, 1, FilterDefault)
|
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, ebiten.FilterDefault)
|
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, ebiten.FilterDefault)
|
src, _ := ebiten.NewImage(w, h)
|
||||||
dst, _ := ebiten.NewImage(w, h, ebiten.FilterDefault)
|
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, ebiten.FilterDefault)
|
src, _ := ebiten.NewImage(w, h)
|
||||||
dst, _ := ebiten.NewImage(w, h, ebiten.FilterDefault)
|
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, ebiten.FilterDefault)
|
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, ebiten.FilterDefault)
|
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, ebiten.FilterDefault)
|
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, FilterDefault)
|
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, FilterDefault)
|
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, FilterDefault)
|
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, FilterDefault)
|
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, FilterDefault)
|
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, FilterDefault)
|
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, FilterDefault)
|
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, FilterDefault)
|
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, FilterDefault)
|
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, FilterDefault)
|
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, FilterDefault)
|
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, FilterDefault)
|
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, FilterDefault)
|
dst, _ := NewImage(w, h)
|
||||||
vs := []Vertex{
|
vs := []Vertex{
|
||||||
{
|
{
|
||||||
DstX: 0,
|
DstX: 0,
|
||||||
|
@ -154,7 +154,7 @@ func getGlyphImages(face font.Face, runes []rune) []*ebiten.Image {
|
|||||||
d.Dot = fixed.Point26_6{X: x, Y: y}
|
d.Dot = fixed.Point26_6{X: x, Y: y}
|
||||||
d.DrawString(string(r))
|
d.DrawString(string(r))
|
||||||
|
|
||||||
img, _ := ebiten.NewImageFromImage(rgba, ebiten.FilterDefault)
|
img, _ := ebiten.NewImageFromImage(rgba)
|
||||||
if _, ok := glyphImageCache[face][r]; !ok {
|
if _, ok := glyphImageCache[face][r]; !ok {
|
||||||
glyphImageCache[face][r] = &glyphImageCacheEntry{
|
glyphImageCache[face][r] = &glyphImageCacheEntry{
|
||||||
image: img,
|
image: img,
|
||||||
|
@ -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, ebiten.FilterNearest)
|
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, ebiten.FilterDefault)
|
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, FilterDefault)
|
c.offscreen = newImage(sw, sh)
|
||||||
c.offscreen.mipmap.SetVolatile(IsScreenClearedEveryFrame())
|
c.offscreen.mipmap.SetVolatile(IsScreenClearedEveryFrame())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ import (
|
|||||||
var emptyImage *ebiten.Image
|
var emptyImage *ebiten.Image
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
emptyImage, _ = ebiten.NewImage(1, 1, ebiten.FilterDefault)
|
emptyImage, _ = ebiten.NewImage(1, 1)
|
||||||
emptyImage.Fill(color.White)
|
emptyImage.Fill(color.White)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user