mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +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
|
||||
// until the construction.
|
||||
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))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -88,7 +84,6 @@ func newImageImplFromImage(source image.Image, filter Filter) (*imageImpl, error
|
||||
i := &imageImpl{
|
||||
restorable: img,
|
||||
}
|
||||
i.restorable.ReplacePixels(p)
|
||||
runtime.SetFinalizer(i, (*imageImpl).Dispose)
|
||||
return i, nil
|
||||
}
|
||||
|
@ -64,8 +64,13 @@ func NewImageFromImage(source *image.RGBA, width, height int, filter opengl.Filt
|
||||
// TODO: texture should be removed here?
|
||||
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{
|
||||
image: img,
|
||||
basePixels: p,
|
||||
filter: filter,
|
||||
}, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user