graphics: Avoid calling ReplacePixels unnecessarily

This commit is contained in:
Hajime Hoshi 2017-02-05 02:19:30 +09:00
parent dfa9eef753
commit d7f1165aa3
2 changed files with 7 additions and 7 deletions

View File

@ -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
}

View File

@ -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
}