mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 12:08:58 +01:00
graphics: Avoid calling ReplacePixels unnecessarily
This commit is contained in:
parent
dfa9eef753
commit
d7f1165aa3
@ -77,10 +77,6 @@ func newImageImplFromImage(source image.Image, filter Filter) (*imageImpl, error
|
|||||||
// an image is delayed and we can't expect the source image is not modified
|
// an image is delayed and we can't expect the source image is not modified
|
||||||
// until the construction.
|
// until the construction.
|
||||||
rgbaImg := graphics.CopyImage(source)
|
rgbaImg := graphics.CopyImage(source)
|
||||||
p := make([]uint8, 4*w*h)
|
|
||||||
for j := 0; j < h; j++ {
|
|
||||||
copy(p[j*w*4:(j+1)*w*4], rgbaImg.Pix[j*rgbaImg.Stride:])
|
|
||||||
}
|
|
||||||
img, err := restorable.NewImageFromImage(rgbaImg, w, h, glFilter(filter))
|
img, err := restorable.NewImageFromImage(rgbaImg, w, h, glFilter(filter))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -88,7 +84,6 @@ func newImageImplFromImage(source image.Image, filter Filter) (*imageImpl, error
|
|||||||
i := &imageImpl{
|
i := &imageImpl{
|
||||||
restorable: img,
|
restorable: img,
|
||||||
}
|
}
|
||||||
i.restorable.ReplacePixels(p)
|
|
||||||
runtime.SetFinalizer(i, (*imageImpl).Dispose)
|
runtime.SetFinalizer(i, (*imageImpl).Dispose)
|
||||||
return i, nil
|
return i, nil
|
||||||
}
|
}
|
||||||
|
@ -64,8 +64,13 @@ func NewImageFromImage(source *image.RGBA, width, height int, filter opengl.Filt
|
|||||||
// TODO: texture should be removed here?
|
// TODO: texture should be removed here?
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
p := make([]uint8, 4*width*height)
|
||||||
|
for j := 0; j < height; j++ {
|
||||||
|
copy(p[j*width*4:(j+1)*width*4], source.Pix[j*source.Stride:])
|
||||||
|
}
|
||||||
return &Image{
|
return &Image{
|
||||||
image: img,
|
image: img,
|
||||||
|
basePixels: p,
|
||||||
filter: filter,
|
filter: filter,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user