ebiten: Remove the filter argument from NewImage and NewImageFromImage

Updates #503
This commit is contained in:
Hajime Hoshi 2020-10-05 01:36:40 +09:00
parent 0892ffa4b2
commit fe97e7b0a5
61 changed files with 217 additions and 235 deletions

View File

@ -28,7 +28,7 @@ var (
func init() {
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.

View File

@ -33,7 +33,7 @@ import (
// 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 .
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)
if err != nil {
return nil, nil, err
@ -45,7 +45,7 @@ func NewImageFromFile(path string, filter ebiten.Filter) (*ebiten.Image, image.I
if err != nil {
return nil, nil, err
}
img2, err := ebiten.NewImageFromImage(img, filter)
img2, err := ebiten.NewImageFromImage(img)
if err != nil {
return nil, nil, err
}

View File

@ -27,7 +27,7 @@ var (
)
func init() {
emptyImage, _ = ebiten.NewImage(1, 1, ebiten.FilterDefault)
emptyImage, _ = ebiten.NewImage(1, 1)
_ = emptyImage.Fill(color.White)
}

View File

@ -25,8 +25,6 @@ import (
//
// 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.
//
// FilterDefault is used at NewImgeFromImage internally.
func NewImageFromURL(url string) (*ebiten.Image, error) {
res, err := http.Get(url)
if err != nil {
@ -39,6 +37,6 @@ func NewImageFromURL(url string) (*ebiten.Image, error) {
return nil, err
}
eimg, _ := ebiten.NewImageFromImage(img, ebiten.FilterDefault)
eimg, _ := ebiten.NewImageFromImage(img)
return eimg, nil
}

View File

@ -69,7 +69,7 @@ func (g *Game) Update() error {
func (g *Game) Draw(screen *ebiten.Image) {
if g.boardImage == nil {
w, h := g.board.Size()
g.boardImage, _ = ebiten.NewImage(w, h, ebiten.FilterDefault)
g.boardImage, _ = ebiten.NewImage(w, h)
}
screen.Fill(backgroundColor)
g.board.Draw(g.boardImage)

View File

@ -355,7 +355,7 @@ var (
)
func init() {
tileImage, _ = ebiten.NewImage(tileSize, tileSize, ebiten.FilterDefault)
tileImage, _ = ebiten.NewImage(tileSize, tileSize)
tileImage.Fill(color.White)
}

View File

@ -82,7 +82,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
ebitenImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
ebitenImage, _ = ebiten.NewImageFromImage(img)
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
ebiten.SetWindowTitle("Additive Blending (Ebiten Demo)")

View File

@ -48,7 +48,7 @@ func init() {
if err != nil {
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) {

View File

@ -61,14 +61,14 @@ func init() {
if err != nil {
log.Fatal(err)
}
gophersImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
gophersImage, _ = ebiten.NewImageFromImage(img)
groundImage, _ = ebiten.NewImage(screenWidth*2, screenHeight*2/3+50, ebiten.FilterDefault)
perspectiveGroundImage, _ = ebiten.NewImage(screenWidth*2, screenHeight, ebiten.FilterDefault)
groundImage, _ = ebiten.NewImage(screenWidth*2, screenHeight*2/3+50)
perspectiveGroundImage, _ = ebiten.NewImage(screenWidth*2, screenHeight)
const repeat = 5
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 i := 0; i < repeat; i++ {
op := &ebiten.DrawImageOptions{}
@ -92,7 +92,7 @@ func init() {
fogRGBA.SetRGBA(i, j, clr)
}
}
fogImage, _ = ebiten.NewImageFromImage(fogRGBA, ebiten.FilterDefault)
fogImage, _ = ebiten.NewImageFromImage(fogRGBA)
}
// player represents the current airship's position.

View File

@ -91,7 +91,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
ebitenImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
ebitenImage, _ = ebiten.NewImageFromImage(img)
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
ebiten.SetWindowTitle("Alpha Blending (Ebiten Demo)")

View File

@ -77,7 +77,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
runnerImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
runnerImage, _ = ebiten.NewImageFromImage(img)
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
ebiten.SetWindowTitle("Animation (Ebiten Demo)")

View File

@ -140,7 +140,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
img, _ = ebiten.NewImageFromImage(rawimg, ebiten.FilterDefault)
img, _ = ebiten.NewImageFromImage(rawimg)
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
ebiten.SetWindowTitle("Audio Panning Loop (Ebiten Demo)")

View File

@ -76,10 +76,10 @@ func init() {
if err != nil {
panic(err)
}
imageGameBG, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
imageGameBG, _ = ebiten.NewImageFromImage(img)
// Windows
imageWindows, _ = ebiten.NewImage(ScreenWidth, ScreenHeight, ebiten.FilterDefault)
imageWindows, _ = ebiten.NewImage(ScreenWidth, ScreenHeight)
// Windows: Field
x, y := fieldWindowPosition()
@ -104,7 +104,7 @@ func init() {
drawTextBox(imageWindows, "LINES", x, y, textBoxWidth())
// Gameover
imageGameover, _ = ebiten.NewImage(ScreenWidth, ScreenHeight, ebiten.FilterDefault)
imageGameover, _ = ebiten.NewImage(ScreenWidth, ScreenHeight)
imageGameover.Fill(color.NRGBA{0x00, 0x00, 0x00, 0x80})
y = (ScreenHeight - blockHeight) / 2
drawTextWithShadowCenter(imageGameover, "GAME OVER\n\nPRESS SPACE", 0, y, 1, color.White, ScreenWidth)

View File

@ -30,7 +30,7 @@ func init() {
if err != nil {
panic(err)
}
imageBlocks, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
imageBlocks, _ = ebiten.NewImageFromImage(img)
}

View File

@ -24,8 +24,8 @@ var (
)
func init() {
transitionFrom, _ = ebiten.NewImage(ScreenWidth, ScreenHeight, ebiten.FilterDefault)
transitionTo, _ = ebiten.NewImage(ScreenWidth, ScreenHeight, ebiten.FilterDefault)
transitionFrom, _ = ebiten.NewImage(ScreenWidth, ScreenHeight)
transitionTo, _ = ebiten.NewImage(ScreenWidth, ScreenHeight)
}
type Scene interface {

View File

@ -32,7 +32,7 @@ func init() {
if err != nil {
panic(err)
}
imageBackground, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
imageBackground, _ = ebiten.NewImageFromImage(img)
}
type TitleScene struct {

View File

@ -82,7 +82,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
gophersImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
gophersImage, _ = ebiten.NewImageFromImage(img)
ebiten.SetWindowSize(screenWidth, screenHeight)
ebiten.SetWindowTitle("Blur (Ebiten Demo)")

View File

@ -65,7 +65,7 @@ func init() {
if err != nil {
log.Fatal(err)
}
tilesImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
tilesImage, _ = ebiten.NewImageFromImage(img)
}
type Camera struct {
@ -261,7 +261,7 @@ func main() {
},
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.SetWindowTitle("Tiles (Ebiten Demo)")

View File

@ -37,7 +37,7 @@ var (
)
func init() {
dot, _ = ebiten.NewImage(1, 1, ebiten.FilterDefault)
dot, _ = ebiten.NewImage(1, 1)
dot.Fill(color.White)
}

View File

@ -144,11 +144,11 @@ func main() {
if err != nil {
log.Fatal(err)
}
gophersImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
gophersImage, _ = ebiten.NewImageFromImage(img)
// Extend the shared backend GL texture on purpose.
for i := 0; i < 20; i++ {
eimg, _ := ebiten.NewImageFromImage(img, ebiten.FilterDefault)
eimg, _ := ebiten.NewImageFromImage(img)
extraImages = append(extraImages, eimg)
}

View File

@ -203,7 +203,7 @@ func init() {
if err != nil {
log.Fatal(err)
}
ebitenImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
ebitenImage, _ = ebiten.NewImageFromImage(img)
}
func NewGame() *Game {

View File

@ -82,7 +82,7 @@ func main() {
// Specifying filter on NewImage[FromImage] is just for backward compatibility.
// Now specifying filter at DrawImageOptions is recommended.
// 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.SetWindowTitle("Filter (Ebiten Demo)")

View File

@ -82,13 +82,13 @@ func init() {
if err != nil {
log.Fatal(err)
}
gopherImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
gopherImage, _ = ebiten.NewImageFromImage(img)
img, _, err = image.Decode(bytes.NewReader(resources.Tiles_png))
if err != nil {
log.Fatal(err)
}
tilesImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
tilesImage, _ = ebiten.NewImageFromImage(img)
}
func init() {

View File

@ -103,7 +103,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
ebitenImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
ebitenImage, _ = ebiten.NewImageFromImage(img)
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
ebiten.SetWindowTitle("Flood fill with solid colors (Ebiten Demo)")

View File

@ -55,7 +55,7 @@ func init() {
if err != nil {
log.Fatal(err)
}
gophersImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
gophersImage, _ = ebiten.NewImageFromImage(img)
}
func initFont() {

View File

@ -149,7 +149,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
gophersImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
gophersImage, _ = ebiten.NewImageFromImage(img)
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
ebiten.SetWindowTitle("HSV (Ebiten Demo)")

View File

@ -75,7 +75,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
gophersImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
gophersImage, _ = ebiten.NewImageFromImage(img)
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
ebiten.SetWindowTitle("Hue (Ebiten Demo)")

View File

@ -51,7 +51,7 @@ func init() {
if err != nil {
log.Fatal(err)
}
bgImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
bgImage, _ = ebiten.NewImageFromImage(img)
}
type viewport struct {

View File

@ -148,7 +148,7 @@ func keyDisplayNameToKey(name string) ebiten.Key {
func drawKey(t *ebiten.Image, name string, x, y, width int) {
const height = 16
width--
img, _ := ebiten.NewImage(width, height, ebiten.FilterDefault)
img, _ := ebiten.NewImage(width, height)
p := make([]byte, width*height*4)
for j := 0; j < height; j++ {
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) {
keyMap := map[ebiten.Key]image.Rectangle{}
img, _ := ebiten.NewImage(320, 240, ebiten.FilterDefault)
img, _ := ebiten.NewImage(320, 240)
x, y := 0, 0
for j, line := range keyboardKeys {
x = 0

View File

@ -42,7 +42,7 @@ func init() {
log.Fatal(err)
}
keyboardImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
keyboardImage, _ = ebiten.NewImageFromImage(img)
}
type Game struct {

View File

@ -69,7 +69,7 @@ func updateOffscreen(centerX, centerY, size float64) {
}
func init() {
offscreen, _ = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterDefault)
offscreen, _ = ebiten.NewImage(screenWidth, screenHeight)
offscreenPix = make([]byte, screenWidth*screenHeight*4)
for i := range palette {
palette[i] = byte(math.Sqrt(float64(i)/float64(len(palette))) * 0x80)

View File

@ -55,19 +55,19 @@ func init() {
if err != nil {
log.Fatal(err)
}
gopher1, _ = ebiten.NewImageFromImage(img1, ebiten.FilterDefault)
gopher1, _ = ebiten.NewImageFromImage(img1)
img2, _, err := image.Decode(bytes.NewReader(rmascot.Out02_png))
if err != nil {
log.Fatal(err)
}
gopher2, _ = ebiten.NewImageFromImage(img2, ebiten.FilterDefault)
gopher2, _ = ebiten.NewImageFromImage(img2)
img3, _, err := image.Decode(bytes.NewReader(rmascot.Out03_png))
if err != nil {
log.Fatal(err)
}
gopher3, _ = ebiten.NewImageFromImage(img3, ebiten.FilterDefault)
gopher3, _ = ebiten.NewImageFromImage(img3)
}
func init() {

View File

@ -54,15 +54,15 @@ func init() {
if err != nil {
log.Fatal(err)
}
bgImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
bgImage, _ = ebiten.NewImageFromImage(img)
img, _, err = image.Decode(bytes.NewReader(images.FiveYears_jpg))
if err != nil {
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.
const r = 64
@ -77,7 +77,7 @@ func init() {
a.SetAlpha(i, j, color.Alpha{b})
}
}
spotLightImage, _ = ebiten.NewImageFromImage(a, ebiten.FilterDefault)
spotLightImage, _ = ebiten.NewImageFromImage(a)
}
type Game struct {

View File

@ -114,7 +114,7 @@ func main() {
// Specifying filter on NewImage[FromImage] is just for backward compatibility.
// Now specifying filter at DrawImageOptions is recommended.
// 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.SetWindowTitle("Minify (Ebiten Demo)")

View File

@ -52,7 +52,7 @@ func init() {
if err != nil {
log.Fatal(err)
}
gophersImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
gophersImage, _ = ebiten.NewImageFromImage(img)
}
type Game struct {
@ -81,7 +81,7 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
func main() {
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.SetWindowTitle("Mosaic (Ebiten Demo)")
if err := ebiten.RunGame(&Game{}); err != nil {

View File

@ -53,9 +53,9 @@ func init() {
Pix: pixels,
Stride: 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)
}

View File

@ -58,7 +58,7 @@ func init() {
if err != nil {
log.Fatal(err)
}
smokeImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
smokeImage, _ = ebiten.NewImageFromImage(img)
}
type sprite struct {

View File

@ -82,7 +82,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
gophersImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
gophersImage, _ = ebiten.NewImageFromImage(img)
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
ebiten.SetWindowTitle("Perspective (Ebiten Demo)")

View File

@ -156,7 +156,7 @@ var (
)
func init() {
pianoImage, _ = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterDefault)
pianoImage, _ = ebiten.NewImage(screenWidth, screenHeight)
const (
keyWidth = 24

View File

@ -47,25 +47,25 @@ func init() {
if err != nil {
panic(err)
}
rightSprite, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
rightSprite, _ = ebiten.NewImageFromImage(img)
img, _, err = image.Decode(bytes.NewReader(rplatformer.Left_png))
if err != nil {
panic(err)
}
leftSprite, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
leftSprite, _ = ebiten.NewImageFromImage(img)
img, _, err = image.Decode(bytes.NewReader(rplatformer.MainChar_png))
if err != nil {
panic(err)
}
idleSprite, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
idleSprite, _ = ebiten.NewImageFromImage(img)
img, _, err = image.Decode(bytes.NewReader(rplatformer.Background_png))
if err != nil {
panic(err)
}
backgroundImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
backgroundImage, _ = ebiten.NewImageFromImage(img)
}
const (

View File

@ -33,7 +33,7 @@ const (
)
var (
emptyImage, _ = ebiten.NewImage(16, 16, ebiten.FilterDefault)
emptyImage, _ = ebiten.NewImage(16, 16)
)
func init() {

View File

@ -59,9 +59,9 @@ func init() {
if err != nil {
log.Fatal(err)
}
bgImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
shadowImage, _ = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterDefault)
triangleImage, _ = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterDefault)
bgImage, _ = ebiten.NewImageFromImage(img)
shadowImage, _ = ebiten.NewImage(screenWidth, screenHeight)
triangleImage, _ = ebiten.NewImage(screenWidth, screenHeight)
triangleImage.Fill(color.White)
}

View File

@ -82,7 +82,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
gophersImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
gophersImage, _ = ebiten.NewImageFromImage(img)
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
ebiten.SetWindowTitle("Rotate (Ebiten Demo)")

View File

@ -39,7 +39,7 @@ func init() {
var offscreen *ebiten.Image
func init() {
offscreen, _ = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterDefault)
offscreen, _ = ebiten.NewImage(screenWidth, screenHeight)
}
type Game struct {

View File

@ -54,7 +54,7 @@ func init() {
if err != nil {
log.Fatal(err)
}
gopherImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
gopherImage, _ = ebiten.NewImageFromImage(img)
}
func init() {
@ -62,7 +62,7 @@ func init() {
if err != nil {
log.Fatal(err)
}
gopherBgImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
gopherBgImage, _ = ebiten.NewImageFromImage(img)
}
func init() {
@ -70,7 +70,7 @@ func init() {
if err != nil {
log.Fatal(err)
}
normalImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
normalImage, _ = ebiten.NewImageFromImage(img)
}
func init() {
@ -78,7 +78,7 @@ func init() {
if err != nil {
log.Fatal(err)
}
noiseImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
noiseImage, _ = ebiten.NewImageFromImage(img)
}
var shaderSrcs = [][]byte{

View File

@ -32,7 +32,7 @@ const (
)
var (
emptyImage, _ = ebiten.NewImage(16, 16, ebiten.FilterDefault)
emptyImage, _ = ebiten.NewImage(16, 16)
)
func init() {

View File

@ -54,10 +54,10 @@ func init() {
if err != nil {
log.Fatal(err)
}
origEbitenImage, _ := ebiten.NewImageFromImage(img, ebiten.FilterDefault)
origEbitenImage, _ := ebiten.NewImageFromImage(img)
w, h := origEbitenImage.Size()
ebitenImage, _ = ebiten.NewImage(w, h, ebiten.FilterDefault)
ebitenImage, _ = ebiten.NewImage(w, h)
op := &ebiten.DrawImageOptions{}
op.ColorM.Scale(1, 1, 1, 0.5)

View File

@ -56,10 +56,10 @@ func init() {
if err != nil {
log.Fatal(err)
}
origEbitenImage, _ := ebiten.NewImageFromImage(img, ebiten.FilterDefault)
origEbitenImage, _ := ebiten.NewImageFromImage(img)
w, h := origEbitenImage.Size()
ebitenImage, _ = ebiten.NewImage(w, h, ebiten.FilterDefault)
ebitenImage, _ = ebiten.NewImage(w, h)
op := &ebiten.DrawImageOptions{}
op.ColorM.Scale(1, 1, 1, 0.5)

View File

@ -279,7 +279,7 @@ func setpix(xy vec2, col color.Color) {
func init() {
rand.Seed(time.Now().UnixNano())
c, _ := ebiten.NewImage(width, height, ebiten.FilterDefault)
c, _ := ebiten.NewImage(width, height)
canvas = c
canvas.Fill(background)

View File

@ -56,7 +56,7 @@ func init() {
if err != nil {
log.Fatal(err)
}
tilesImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
tilesImage, _ = ebiten.NewImageFromImage(img)
}
type Game struct {

View File

@ -58,7 +58,7 @@ func init() {
if err != nil {
log.Fatal(err)
}
uiImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
uiImage, _ = ebiten.NewImageFromImage(img)
tt, err := opentype.Parse(goregular.TTF)
if err != nil {
@ -358,7 +358,7 @@ func (t *TextBox) Draw(dst *ebiten.Image) {
}
if t.contentBuf == nil {
w, h := t.viewSize()
t.contentBuf, _ = ebiten.NewImage(w, h, ebiten.FilterDefault)
t.contentBuf, _ = ebiten.NewImage(w, h)
}
t.contentBuf.Clear()

View File

@ -28,7 +28,7 @@ import (
var pointerImage *ebiten.Image
func init() {
pointerImage, _ = ebiten.NewImage(4, 4, ebiten.FilterDefault)
pointerImage, _ = ebiten.NewImage(4, 4)
pointerImage.Fill(color.RGBA{0xff, 0, 0, 0xff})
}

View File

@ -349,7 +349,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
gophersImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
gophersImage, _ = ebiten.NewImageFromImage(img)
ebiten.SetWindowIcon([]image.Image{createRandomIconImage()})

View File

@ -42,8 +42,6 @@ type Image struct {
bounds image.Rectangle
original *Image
filter Filter
}
func (i *Image) copyCheck() {
@ -199,8 +197,6 @@ func (i *Image) DrawImage(img *Image, options *DrawImageOptions) error {
filter := driver.FilterNearest
if options.Filter != FilterDefault {
filter = driver.Filter(options.Filter)
} else if img.filter != FilterDefault {
filter = driver.Filter(img.filter)
}
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
if options.Filter != FilterDefault {
filter = driver.Filter(options.Filter)
} else if img.filter != FilterDefault {
filter = driver.Filter(img.filter)
}
vs := make([]float32, len(vertices)*graphics.VertexFloatNum)
@ -623,7 +617,6 @@ func (i *Image) SubImage(r image.Rectangle) image.Image {
img := &Image{
mipmap: i.mipmap,
filter: i.filter,
bounds: r,
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.
//
// 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.
func NewImage(width, height int, filter Filter) (*Image, error) {
return newImage(width, height, filter), nil
func NewImage(width, height int) (*Image, error) {
return newImage(width, height), nil
}
func newImage(width, height int, filter Filter) *Image {
func newImage(width, height int) *Image {
i := &Image{
mipmap: mipmap.New(width, height),
filter: filter,
bounds: image.Rect(0, 0, width, height),
}
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.
//
// 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.
func NewImageFromImage(source image.Image, filter Filter) (*Image, error) {
func NewImageFromImage(source image.Image) (*Image, error) {
size := source.Bounds().Size()
width, height := size.X, size.Y
i := &Image{
mipmap: mipmap.New(width, height),
filter: filter,
bounds: image.Rect(0, 0, width, height),
}
i.addr = i
@ -800,7 +785,6 @@ func NewImageFromImage(source image.Image, filter Filter) (*Image, error) {
func newScreenFramebufferImage(width, height int) *Image {
i := &Image{
mipmap: mipmap.NewScreenFramebufferMipmap(width, height),
filter: FilterDefault,
bounds: image.Rect(0, 0, width, height),
}
i.addr = i

View File

@ -59,7 +59,7 @@ func openEbitenImage() (*Image, image.Image, error) {
return nil, nil, err
}
eimg, err := NewImageFromImage(img, FilterNearest)
eimg, err := NewImageFromImage(img)
if err != nil {
return nil, nil, err
}
@ -123,13 +123,13 @@ func TestImageComposition(t *testing.T) {
w, h := img1.Bounds().Size().X, img1.Bounds().Size().Y
img2, err := NewImage(w, h, FilterNearest)
img2, err := NewImage(w, h)
if err != nil {
t.Fatal(err)
return
}
img3, err := NewImage(w, h, FilterNearest)
img3, err := NewImage(w, h)
if err != nil {
t.Fatal(err)
return
@ -143,7 +143,7 @@ func TestImageComposition(t *testing.T) {
t.Fatal(err)
return
}
img_12_3, err := NewImage(w, h, FilterNearest)
img_12_3, err := NewImage(w, h)
if err != nil {
t.Fatal(err)
return
@ -169,7 +169,7 @@ func TestImageComposition(t *testing.T) {
t.Fatal(err)
return
}
img_1_23, err := NewImage(w, h, FilterNearest)
img_1_23, err := NewImage(w, h)
if err != nil {
t.Fatal(err)
return
@ -227,7 +227,7 @@ func TestImageScale(t *testing.T) {
return
}
w, h := img0.Size()
img1, err := NewImage(w*scale, h*scale, FilterNearest)
img1, err := NewImage(w*scale, h*scale)
if err != nil {
t.Fatal(err)
return
@ -259,7 +259,7 @@ func TestImage90DegreeRotate(t *testing.T) {
return
}
w, h := img0.Size()
img1, err := NewImage(h, w, FilterNearest)
img1, err := NewImage(h, w)
if err != nil {
t.Fatal(err)
return
@ -290,7 +290,7 @@ func TestImageDotByDotInversion(t *testing.T) {
return
}
w, h := img0.Size()
img1, err := NewImage(w, h, FilterNearest)
img1, err := NewImage(w, h)
if err != nil {
t.Fatal(err)
return
@ -316,7 +316,7 @@ func TestImageDotByDotInversion(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.
dummyImg, _ := NewImageFromImage(image.NewRGBA(image.Rect(0, 0, 16, 16)), FilterDefault)
dummyImg, _ := NewImageFromImage(image.NewRGBA(image.Rect(0, 0, 16, 16)))
defer dummyImg.Dispose()
_, origImg, err := openEbitenImage()
@ -329,7 +329,7 @@ func TestImageReplacePixels(t *testing.T) {
draw.Draw(img, img.Bounds(), origImg, image.ZP, draw.Src)
size := img.Bounds().Size()
img0, err := NewImage(size.X, size.Y, FilterNearest)
img0, err := NewImage(size.X, size.Y)
if err != nil {
t.Fatal(err)
return
@ -379,7 +379,7 @@ func TestImageReplacePixelsNil(t *testing.T) {
}
}()
img, err := NewImage(16, 16, FilterNearest)
img, err := NewImage(16, 16)
if err != nil {
t.Fatal(err)
return
@ -389,7 +389,7 @@ func TestImageReplacePixelsNil(t *testing.T) {
}
func TestImageDispose(t *testing.T) {
img, err := NewImage(16, 16, FilterNearest)
img, err := NewImage(16, 16)
if err != nil {
t.Fatal(err)
return
@ -423,7 +423,7 @@ func TestImageCompositeModeLighter(t *testing.T) {
}
w, h := img0.Size()
img1, err := NewImage(w, h, FilterNearest)
img1, err := NewImage(w, h)
if err != nil {
t.Fatal(err)
return
@ -459,7 +459,7 @@ func TestNewImageFromEbitenImage(t *testing.T) {
t.Fatal(err)
return
}
if _, err := NewImageFromImage(img, FilterNearest); err != nil {
if _, err := NewImageFromImage(img); err != nil {
t.Errorf("NewImageFromImage returns error: %v", err)
}
}
@ -472,7 +472,7 @@ func TestNewImageFromSubImage(t *testing.T) {
}
w, h := img.Bounds().Dx(), img.Bounds().Dy()
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 {
t.Fatal(err)
return
@ -506,7 +506,7 @@ func (c *mutableRGBA) RGBA() (r, g, b, a uint32) {
func TestImageFill(t *testing.T) {
w, h := 10, 10
img, err := NewImage(w, h, FilterNearest)
img, err := NewImage(w, h)
if err != nil {
t.Fatal(err)
return
@ -531,7 +531,7 @@ func TestImageFill(t *testing.T) {
// Issue #740
func TestImageClear(t *testing.T) {
const w, h = 128, 256
img, err := NewImage(w, h, FilterNearest)
img, err := NewImage(w, h)
if err != nil {
t.Fatal(err)
return
@ -575,7 +575,7 @@ func TestImageEdge(t *testing.T) {
img1Width = 32
img1Height = 32
)
img0, _ := NewImage(img0Width, img0Height, FilterNearest)
img0, _ := NewImage(img0Width, img0Height)
pixels := make([]uint8, 4*img0Width*img0Height)
for j := 0; j < img0Height; j++ {
for i := 0; i < img0Width; i++ {
@ -587,7 +587,7 @@ func TestImageEdge(t *testing.T) {
}
}
img0.ReplacePixels(pixels)
img1, _ := NewImage(img1Width, img1Height, FilterDefault)
img1, _ := NewImage(img1Width, img1Height)
red := color.RGBA{0xff, 0, 0, 0xff}
transparent := color.RGBA{0, 0, 0, 0}
@ -707,8 +707,8 @@ func TestImageTooManyFill(t *testing.T) {
return uint8((17*index + 0x40) % 256)
}
src, _ := NewImage(1, 1, FilterNearest)
dst, _ := NewImage(width, 1, FilterNearest)
src, _ := NewImage(1, 1)
dst, _ := NewImage(width, 1)
for i := 0; i < width; i++ {
c := indexToColor(i)
src.Fill(color.RGBA{c, c, c, 0xff})
@ -728,8 +728,8 @@ func TestImageTooManyFill(t *testing.T) {
}
func BenchmarkDrawImage(b *testing.B) {
img0, _ := NewImage(16, 16, FilterNearest)
img1, _ := NewImage(16, 16, FilterNearest)
img0, _ := NewImage(16, 16)
img1, _ := NewImage(16, 16)
op := &DrawImageOptions{}
for i := 0; i < b.N; i++ {
img0.DrawImage(img1, op)
@ -737,7 +737,7 @@ func BenchmarkDrawImage(b *testing.B) {
}
func TestImageLinearGradiation(t *testing.T) {
img0, _ := NewImage(2, 2, FilterNearest)
img0, _ := NewImage(2, 2)
img0.ReplacePixels([]byte{
0xff, 0x00, 0x00, 0xff,
0x00, 0xff, 0x00, 0xff,
@ -746,7 +746,7 @@ func TestImageLinearGradiation(t *testing.T) {
})
const w, h = 32, 32
img1, _ := NewImage(w, h, FilterNearest)
img1, _ := NewImage(w, h)
op := &DrawImageOptions{}
op.GeoM.Scale(w, h)
op.GeoM.Translate(-w/4, -h/4)
@ -764,8 +764,8 @@ func TestImageLinearGradiation(t *testing.T) {
}
func TestImageOutside(t *testing.T) {
src, _ := NewImage(5, 10, FilterNearest) // internal texture size is 8x16.
dst, _ := NewImage(4, 4, FilterNearest)
src, _ := NewImage(5, 10) // internal texture size is 8x16.
dst, _ := NewImage(4, 4)
src.Fill(color.RGBA{0xff, 0, 0, 0xff})
cases := []struct {
@ -806,9 +806,9 @@ func TestImageOutside(t *testing.T) {
}
func TestImageOutsideUpperLeft(t *testing.T) {
src, _ := NewImage(4, 4, FilterNearest)
dst1, _ := NewImage(16, 16, FilterNearest)
dst2, _ := NewImage(16, 16, FilterNearest)
src, _ := NewImage(4, 4)
dst1, _ := NewImage(16, 16)
dst2, _ := NewImage(16, 16)
src.Fill(color.RGBA{0xff, 0, 0, 0xff})
op := &DrawImageOptions{}
@ -838,7 +838,7 @@ func TestImageSize(t *testing.T) {
w = 17
h = 31
)
img, _ := NewImage(w, h, FilterDefault)
img, _ := NewImage(w, h)
gotW, gotH := img.Size()
if gotW != w {
t.Errorf("got: %d, want: %d", gotW, w)
@ -849,8 +849,8 @@ func TestImageSize(t *testing.T) {
}
func TestImageSize1(t *testing.T) {
src, _ := NewImage(1, 1, FilterNearest)
dst, _ := NewImage(1, 1, FilterNearest)
src, _ := NewImage(1, 1)
dst, _ := NewImage(1, 1)
src.Fill(color.White)
dst.DrawImage(src, nil)
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.
func Skip_TestImageSize4096(t *testing.T) {
src, _ := NewImage(4096, 4096, FilterNearest)
dst, _ := NewImage(4096, 4096, FilterNearest)
src, _ := NewImage(4096, 4096)
dst, _ := NewImage(4096, 4096)
pix := make([]byte, 4096*4096*4)
for i := 0; i < 4096; i++ {
j := 4095
@ -908,7 +908,7 @@ func TestImageCopy(t *testing.T) {
}
}()
img0, _ := NewImage(256, 256, FilterDefault)
img0, _ := NewImage(256, 256)
img1 := *img0
img1.Fill(color.Transparent)
}
@ -921,10 +921,10 @@ func TestImageStretch(t *testing.T) {
const w = 16
dst, _ := NewImage(w, 4096, FilterDefault)
dst, _ := NewImage(w, 4096)
loop:
for h := 1; h <= 32; h++ {
src, _ := NewImage(w, h, FilterDefault)
src, _ := NewImage(w, h)
pix := make([]byte, 4*w*h)
for i := 0; i < w*h; i++ {
@ -971,9 +971,9 @@ func TestImageSprites(t *testing.T) {
height = 512
)
src, _ := NewImage(4, 4, FilterNearest)
src, _ := NewImage(4, 4)
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 i := 0; i < width/4; i++ {
op := &DrawImageOptions{}
@ -1002,26 +1002,26 @@ func Disabled_TestImageMipmap(t *testing.T) {
}
w, h := src.Size()
l1, _ := NewImage(w/2, h/2, FilterDefault)
l1, _ := NewImage(w/2, h/2)
op := &DrawImageOptions{}
op.GeoM.Scale(1/2.0, 1/2.0)
op.Filter = FilterLinear
l1.DrawImage(src, op)
l1w, l1h := l1.Size()
l2, _ := NewImage(l1w/2, l1h/2, FilterDefault)
l2, _ := NewImage(l1w/2, l1h/2)
op = &DrawImageOptions{}
op.GeoM.Scale(1/2.0, 1/2.0)
op.Filter = FilterLinear
l2.DrawImage(l1, op)
gotDst, _ := NewImage(w, h, FilterDefault)
gotDst, _ := NewImage(w, h)
op = &DrawImageOptions{}
op.GeoM.Scale(1/5.0, 1/5.0)
op.Filter = FilterLinear
gotDst.DrawImage(src, op)
wantDst, _ := NewImage(w, h, FilterDefault)
wantDst, _ := NewImage(w, h)
op = &DrawImageOptions{}
op.GeoM.Scale(4.0/5.0, 4.0/5.0)
op.Filter = FilterLinear
@ -1047,27 +1047,27 @@ func Disabled_TestImageMipmapNegativeDet(t *testing.T) {
}
w, h := src.Size()
l1, _ := NewImage(w/2, h/2, FilterDefault)
l1, _ := NewImage(w/2, h/2)
op := &DrawImageOptions{}
op.GeoM.Scale(1/2.0, 1/2.0)
op.Filter = FilterLinear
l1.DrawImage(src, op)
l1w, l1h := l1.Size()
l2, _ := NewImage(l1w/2, l1h/2, FilterDefault)
l2, _ := NewImage(l1w/2, l1h/2)
op = &DrawImageOptions{}
op.GeoM.Scale(1/2.0, 1/2.0)
op.Filter = FilterLinear
l2.DrawImage(l1, op)
gotDst, _ := NewImage(w, h, FilterDefault)
gotDst, _ := NewImage(w, h)
op = &DrawImageOptions{}
op.GeoM.Scale(-1/5.0, -1/5.0)
op.GeoM.Translate(float64(w), float64(h))
op.Filter = FilterLinear
gotDst.DrawImage(src, op)
wantDst, _ := NewImage(w, h, FilterDefault)
wantDst, _ := NewImage(w, h)
op = &DrawImageOptions{}
op.GeoM.Scale(-4.0/5.0, -4.0/5.0)
op.GeoM.Translate(float64(w), float64(h))
@ -1095,8 +1095,8 @@ func Disabled_TestImageMipmapNegativeDet(t *testing.T) {
// Issue #710
func TestImageMipmapColor(t *testing.T) {
img0, _ := NewImage(256, 256, FilterDefault)
img1, _ := NewImage(128, 128, FilterDefault)
img0, _ := NewImage(256, 256)
img1, _ := NewImage(128, 128)
img1.Fill(color.White)
for i := 0; i < 8; i++ {
@ -1125,9 +1125,9 @@ func TestImageMipmapColor(t *testing.T) {
// Issue #725
func TestImageMiamapAndDrawTriangle(t *testing.T) {
img0, _ := NewImage(32, 32, FilterDefault)
img1, _ := NewImage(128, 128, FilterDefault)
img2, _ := NewImage(128, 128, FilterDefault)
img0, _ := NewImage(32, 32)
img1, _ := NewImage(128, 128)
img2, _ := NewImage(128, 128)
// Fill img1 red and create img1's mipmap
img1.Fill(color.RGBA{0xff, 0, 0, 0xff})
@ -1201,7 +1201,7 @@ func TestImageMiamapAndDrawTriangle(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})
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) {
img, _ := NewImage(16, 16, FilterDefault)
img, _ := NewImage(16, 16)
img.Fill(color.RGBA{0xff, 0, 0, 0xff})
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) {
const w, h = 16, 16
img0, _ := NewImage(w, h, FilterDefault)
img1, _ := NewImage(w, h, FilterDefault)
img0, _ := NewImage(w, h)
img1, _ := NewImage(w, h)
// Do not manipulate img0 here.
img0.Fill(color.RGBA{0xff, 0, 0, 0xff})
@ -1262,8 +1262,8 @@ func TestImageDrawImmediately(t *testing.T) {
func TestImageLinearFilterGlitch(t *testing.T) {
const w, h = 200, 12
const scale = 1.2
src, _ := NewImage(w, h, FilterDefault)
dst, _ := NewImage(int(math.Floor(w*scale)), h, FilterDefault)
src, _ := NewImage(w, h)
dst, _ := NewImage(int(math.Floor(w*scale)), h)
pix := make([]byte, 4*w*h)
for j := 0; j < h; j++ {
@ -1311,8 +1311,8 @@ func TestImageLinearFilterGlitch(t *testing.T) {
// Issue #1212
func TestImageLinearFilterGlitch2(t *testing.T) {
const w, h = 100, 100
src, _ := NewImage(w, h, FilterDefault)
dst, _ := NewImage(w, h, FilterDefault)
src, _ := NewImage(w, h)
dst, _ := NewImage(w, h)
idx := 0
pix := make([]byte, 4*w*h)
@ -1356,8 +1356,8 @@ func TestImageLinearFilterGlitch2(t *testing.T) {
func TestImageAddressRepeat(t *testing.T) {
const w, h = 16, 16
src, _ := NewImage(w, h, FilterDefault)
dst, _ := NewImage(w, h, FilterDefault)
src, _ := NewImage(w, h)
dst, _ := NewImage(w, h)
pix := make([]byte, 4*w*h)
for j := 0; j < h; j++ {
for i := 0; i < w; i++ {
@ -1437,7 +1437,7 @@ func TestImageAddressRepeat(t *testing.T) {
func TestImageReplacePixelsAfterClear(t *testing.T) {
const w, h = 256, 256
img, _ := NewImage(w, h, FilterDefault)
img, _ := NewImage(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
// DrawImage is called, ReplacePixels for a region is forbidden.
@ -1455,7 +1455,7 @@ func TestImageSet(t *testing.T) {
}
const w, h = 16, 16
img, _ := NewImage(w, h, FilterDefault)
img, _ := NewImage(w, h)
colors := map[Pt]color.RGBA{
{1, 2}: {3, 4, 5, 6},
{7, 8}: {9, 10, 11, 12},
@ -1487,8 +1487,8 @@ func TestImageSetAndDraw(t *testing.T) {
}
const w, h = 16, 16
src, _ := NewImage(w, h, FilterDefault)
dst, _ := NewImage(w, h, FilterDefault)
src, _ := NewImage(w, h)
dst, _ := NewImage(w, h)
colors := map[Pt]color.RGBA{
{1, 2}: {3, 4, 5, 6},
{7, 8}: {9, 10, 11, 12},
@ -1546,10 +1546,10 @@ func TestImageSetAndDraw(t *testing.T) {
func TestImageAlphaOnBlack(t *testing.T) {
const w, h = 16, 16
src0, _ := NewImage(w, h, FilterDefault)
src1, _ := NewImage(w, h, FilterDefault)
dst0, _ := NewImage(w, h, FilterDefault)
dst1, _ := NewImage(w, h, FilterDefault)
src0, _ := NewImage(w, h)
src1, _ := NewImage(w, h)
dst0, _ := NewImage(w, h)
dst1, _ := NewImage(w, h)
pix0 := make([]byte, 4*w*h)
for j := 0; j < h; j++ {
@ -1611,8 +1611,8 @@ func TestImageAlphaOnBlack(t *testing.T) {
func TestImageDrawTrianglesWithSubImage(t *testing.T) {
const w, h = 16, 16
src, _ := NewImage(w, h, FilterDefault)
dst, _ := NewImage(w, h, FilterDefault)
src, _ := NewImage(w, h)
dst, _ := NewImage(w, h)
pix := make([]byte, 4*w*h)
for j := 0; j < h; j++ {
@ -1695,7 +1695,7 @@ func TestImageDrawTrianglesWithSubImage(t *testing.T) {
// Issue #823
func TestImageAtAfterDisposingSubImage(t *testing.T) {
img, _ := NewImage(16, 16, FilterDefault)
img, _ := NewImage(16, 16)
img.Set(0, 0, color.White)
img.SubImage(image.Rect(0, 0, 16, 16))
runtime.GC()
@ -1715,7 +1715,7 @@ func TestImageAtAfterDisposingSubImage(t *testing.T) {
}
func TestImageSubImageSubImage(t *testing.T) {
img, _ := NewImage(16, 16, FilterDefault)
img, _ := NewImage(16, 16)
img.Fill(color.White)
sub0 := img.SubImage(image.Rect(0, 0, 12, 12)).(*Image)
sub1 := sub0.SubImage(image.Rect(4, 4, 16, 16)).(*Image)
@ -1752,8 +1752,8 @@ func TestImageSubImageSubImage(t *testing.T) {
// Issue #839
func TestImageTooSmallMipmap(t *testing.T) {
const w, h = 16, 16
src, _ := NewImage(w, h, FilterDefault)
dst, _ := NewImage(w, h, FilterDefault)
src, _ := NewImage(w, h)
dst, _ := NewImage(w, h)
src.Fill(color.White)
op := &DrawImageOptions{}
@ -1769,8 +1769,8 @@ func TestImageTooSmallMipmap(t *testing.T) {
func TestImageZeroSizedMipmap(t *testing.T) {
const w, h = 16, 16
src, _ := NewImage(w, h, FilterDefault)
dst, _ := NewImage(w, h, FilterDefault)
src, _ := NewImage(w, h)
dst, _ := NewImage(w, h)
op := &DrawImageOptions{}
op.Filter = FilterLinear
@ -1784,8 +1784,8 @@ func TestImageFillingAndEdges(t *testing.T) {
dstw, dsth = 256, 16
)
src, _ := NewImage(srcw, srch, FilterDefault)
dst, _ := NewImage(dstw, dsth, FilterDefault)
src, _ := NewImage(srcw, srch)
dst, _ := NewImage(dstw, dsth)
src.Fill(color.White)
dst.Fill(color.Black)
@ -1811,8 +1811,8 @@ func TestImageFillingAndEdges(t *testing.T) {
func TestImageDrawTrianglesAndMutateArgs(t *testing.T) {
const w, h = 16, 16
dst, _ := NewImage(w, h, FilterDefault)
src, _ := NewImage(w, h, FilterDefault)
dst, _ := NewImage(w, h)
src, _ := NewImage(w, h)
clr := color.RGBA{0xff, 0, 0, 0xff}
src.Fill(clr)
@ -1876,7 +1876,7 @@ func TestImageDrawTrianglesAndMutateArgs(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})
pix0 := make([]byte, 4*5*3)
@ -1927,9 +1927,9 @@ func TestImageReplacePixelsOnSubImage(t *testing.T) {
func TestImageDrawTrianglesWithColorM(t *testing.T) {
const w, h = 16, 16
dst0, _ := NewImage(w, h, FilterDefault)
dst1, _ := NewImage(w, h, FilterDefault)
src, _ := NewImage(w, h, FilterDefault)
dst0, _ := NewImage(w, h)
dst1, _ := NewImage(w, h)
src, _ := NewImage(w, h)
src.Fill(color.White)
vs0 := []Vertex{
@ -2036,7 +2036,7 @@ func TestImageDrawTrianglesWithColorM(t *testing.T) {
// Issue #1137
func TestImageDrawOver(t *testing.T) {
dst, _ := NewImage(320, 240, FilterDefault)
dst, _ := NewImage(320, 240)
src := image.NewUniform(color.RGBA{0xff, 0, 0, 0xff})
// This must not cause infinite-loop.
draw.Draw(dst, dst.Bounds(), src, image.ZP, draw.Over)
@ -2058,8 +2058,8 @@ func TestImageDrawDisposedImage(t *testing.T) {
}
}()
dst, _ := NewImage(16, 16, FilterNearest)
src, _ := NewImage(16, 16, FilterNearest)
dst, _ := NewImage(16, 16)
src, _ := NewImage(16, 16)
src.Dispose()
dst.DrawImage(src, nil)
}
@ -2071,8 +2071,8 @@ func TestImageDrawTrianglesDisposedImage(t *testing.T) {
}
}()
dst, _ := NewImage(16, 16, FilterNearest)
src, _ := NewImage(16, 16, FilterNearest)
dst, _ := NewImage(16, 16)
src, _ := NewImage(16, 16)
src.Dispose()
vs := make([]Vertex, 4)
is := []uint16{0, 1, 2, 1, 2, 3}
@ -2081,7 +2081,7 @@ func TestImageDrawTrianglesDisposedImage(t *testing.T) {
// #1137
func BenchmarkImageDrawOver(b *testing.B) {
dst, _ := NewImage(16, 16, FilterDefault)
dst, _ := NewImage(16, 16)
src := image.NewUniform(color.Black)
for n := 0; n < b.N; n++ {
draw.Draw(dst, dst.Bounds(), src, image.ZP, draw.Over)
@ -2096,7 +2096,7 @@ func TestImageFloatTranslate(t *testing.T) {
s := s
t.Run(fmt.Sprintf("scale%d", s), func(t *testing.T) {
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})
op := &DrawImageOptions{}
@ -2120,7 +2120,7 @@ func TestImageFloatTranslate(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)
for j := 0; j < h; j++ {
for i := 0; i < w; i++ {
@ -2133,7 +2133,7 @@ func TestImageFloatTranslate(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))
for j := 0; j < h*s; j++ {
for i := 0; i < w*s; i++ {
@ -2151,8 +2151,8 @@ func TestImageFloatTranslate(t *testing.T) {
// Issue #1213
func TestImageColorMCopy(t *testing.T) {
const w, h = 16, 16
dst, _ := NewImage(w, h, FilterDefault)
src, _ := NewImage(w, h, FilterDefault)
dst, _ := NewImage(w, h)
src, _ := NewImage(w, h)
for k := 0; k < 256; k++ {
op := &DrawImageOptions{}
@ -2175,8 +2175,8 @@ func TestImageColorMCopy(t *testing.T) {
// TODO: Do we have to guarantee this behavior? See #1222
func TestImageReplacePixelsAndModifyPixels(t *testing.T) {
const w, h = 16, 16
dst, _ := NewImage(w, h, FilterDefault)
src, _ := NewImage(w, h, FilterDefault)
dst, _ := NewImage(w, h)
src, _ := NewImage(w, h)
pix := make([]byte, 4*w*h)
for j := 0; j < h; j++ {
@ -2218,8 +2218,8 @@ func TestImageReplacePixelsAndModifyPixels(t *testing.T) {
func TestImageCompositeModeMultiply(t *testing.T) {
const w, h = 16, 16
dst, _ := NewImage(w, h, FilterDefault)
src, _ := NewImage(w, h, FilterDefault)
dst, _ := NewImage(w, h)
src, _ := NewImage(w, h)
dst.Fill(color.RGBA{0x10, 0x20, 0x30, 0x40})
src.Fill(color.RGBA{0x50, 0x60, 0x70, 0x80})
@ -2247,8 +2247,8 @@ func TestImageCompositeModeMultiply(t *testing.T) {
// Issue #1269
func TestImageZeroTriangle(t *testing.T) {
const w, h = 16, 16
dst, _ := NewImage(w, h, FilterDefault)
src, _ := NewImage(1, 1, FilterDefault)
dst, _ := NewImage(w, h)
src, _ := NewImage(1, 1)
vs := []Vertex{}
is := []uint16{}

View File

@ -87,7 +87,7 @@ type testResult struct {
var testSetBeforeMainResult = func() testResult {
clr := color.RGBA{1, 2, 3, 4}
img, _ := ebiten.NewImage(16, 16, ebiten.FilterDefault)
img, _ := ebiten.NewImage(16, 16)
img.Set(0, 0, clr)
ch := make(chan color.RGBA, 1)
@ -114,8 +114,8 @@ func TestSetBeforeMain(t *testing.T) {
var testDrawImageBeforeMainResult = func() testResult {
const w, h = 16, 16
src, _ := ebiten.NewImage(w, h, ebiten.FilterDefault)
dst, _ := ebiten.NewImage(w, h, ebiten.FilterDefault)
src, _ := ebiten.NewImage(w, h)
dst, _ := ebiten.NewImage(w, h)
src.Set(0, 0, color.White)
dst.DrawImage(src, nil)
@ -143,8 +143,8 @@ func TestDrawImageBeforeMain(t *testing.T) {
var testDrawTrianglesBeforeMainResult = func() testResult {
const w, h = 16, 16
src, _ := ebiten.NewImage(w, h, ebiten.FilterDefault)
dst, _ := ebiten.NewImage(w, h, ebiten.FilterDefault)
src, _ := ebiten.NewImage(w, h)
dst, _ := ebiten.NewImage(w, h)
src.Set(0, 0, color.White)
vs := []ebiten.Vertex{
{
@ -204,7 +204,7 @@ func TestDrawTrianglesBeforeMain(t *testing.T) {
var testSetAndFillBeforeMainResult = func() testResult {
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.Fill(color.RGBA{5, 6, 7, 8})
img.Set(1, 0, clr)
@ -233,7 +233,7 @@ func TestSetAndFillBeforeMain(t *testing.T) {
var testSetAndReplacePixelsBeforeMainResult = func() testResult {
clr := color.RGBA{1, 2, 3, 4}
img, _ := ebiten.NewImage(16, 16, ebiten.FilterDefault)
img, _ := ebiten.NewImage(16, 16)
img.Set(0, 0, clr)
pix := make([]byte, 4*16*16)
for i := 0; i < len(pix)/4; i++ {
@ -268,7 +268,7 @@ func TestSetAndReplacePixelsBeforeMain(t *testing.T) {
}
var testReplacePixelsAndModifyBeforeMainResult = func() testResult {
img, _ := ebiten.NewImage(16, 16, ebiten.FilterDefault)
img, _ := ebiten.NewImage(16, 16)
pix := make([]byte, 4*16*16)
for i := 0; i < len(pix)/4; i++ {
pix[4*i] = 1

View File

@ -25,7 +25,7 @@ import (
func TestShaderFill(t *testing.T) {
const w, h = 16, 16
dst, _ := NewImage(w, h, FilterDefault)
dst, _ := NewImage(w, h)
s, err := NewShader([]byte(`package main
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) {
const w, h = 16, 16
dst, _ := NewImage(w, h, FilterDefault)
dst, _ := NewImage(w, h)
s, err := NewShader([]byte(`package main
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)
}
src, _ := NewImage(w/2, h/2, FilterDefault)
src, _ := NewImage(w/2, h/2)
op := &DrawRectShaderOptions{}
op.Images[0] = src
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) {
const w, h = 16, 16
dst, _ := NewImage(w, h, FilterDefault)
dst, _ := NewImage(w, h)
s, err := NewShader([]byte(`package main
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)
}
src, _ := NewImage(w/2, h/2, FilterDefault)
src, _ := NewImage(w/2, h/2)
op := &DrawTrianglesShaderOptions{}
op.Images[0] = src
@ -163,7 +163,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
func TestShaderFunction(t *testing.T) {
const w, h = 16, 16
dst, _ := NewImage(w, h, FilterDefault)
dst, _ := NewImage(w, h)
s, err := NewShader([]byte(`package main
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) {
const w, h = 16, 16
dst, _ := NewImage(w, h, FilterDefault)
dst, _ := NewImage(w, h)
s, err := NewShader([]byte(`package main
var U vec4
@ -766,7 +766,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
func TestShaderMatrix(t *testing.T) {
const w, h = 16, 16
dst, _ := NewImage(w, h, FilterDefault)
dst, _ := NewImage(w, h)
s, err := NewShader([]byte(`package main
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)
}
src, _ := NewImage(w, h, FilterDefault)
src, _ := NewImage(w, h)
op := &DrawRectShaderOptions{}
op.Images[0] = src
dst.DrawRectShader(w, h, s, op)
@ -817,7 +817,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
t.Fatal(err)
}
src0, _ := NewImage(w, h, FilterDefault)
src0, _ := NewImage(w, h)
pix0 := make([]byte, 4*w*h)
for j := 0; j < h; j++ {
for i := 0; i < w; i++ {
@ -832,7 +832,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
src0.ReplacePixels(pix0)
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)
for j := 0; j < h; j++ {
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) {
dst, _ := NewImage(w, h, FilterDefault)
dst, _ := NewImage(w, h)
op := &DrawRectShaderOptions{}
op.Images[0] = src0
op.Images[1] = src1
@ -872,7 +872,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
})
t.Run("DrawTrianglesShader", func(t *testing.T) {
dst, _ := NewImage(w, h, FilterDefault)
dst, _ := NewImage(w, h)
vs := []Vertex{
{
DstX: 0,

View File

@ -154,7 +154,7 @@ func getGlyphImages(face font.Face, runes []rune) []*ebiten.Image {
d.Dot = fixed.Point26_6{X: x, Y: y}
d.DrawString(string(r))
img, _ := ebiten.NewImageFromImage(rgba, ebiten.FilterDefault)
img, _ := ebiten.NewImageFromImage(rgba)
if _, ok := glyphImageCache[face][r]; !ok {
glyphImageCache[face][r] = &glyphImageCacheEntry{
image: img,

View File

@ -34,7 +34,7 @@ func TestMain(m *testing.M) {
func TestTextColor(t *testing.T) {
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)
w, h := img.Size()
@ -119,7 +119,7 @@ func (f *testFace) Metrics() font.Metrics {
func TestTextOverlap(t *testing.T) {
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.
// 'a' is rendered at the current position as 0x80.

View File

@ -92,7 +92,7 @@ func (c *uiContext) updateOffscreen() {
}
}
if c.offscreen == nil {
c.offscreen = newImage(sw, sh, FilterDefault)
c.offscreen = newImage(sw, sh)
c.offscreen.mipmap.SetVolatile(IsScreenClearedEveryFrame())
}

View File

@ -28,7 +28,7 @@ import (
var emptyImage *ebiten.Image
func init() {
emptyImage, _ = ebiten.NewImage(1, 1, ebiten.FilterDefault)
emptyImage, _ = ebiten.NewImage(1, 1)
emptyImage.Fill(color.White)
}