From d7f1165aa3de82eb75581f547679235adc26cb02 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 5 Feb 2017 02:19:30 +0900 Subject: [PATCH] graphics: Avoid calling ReplacePixels unnecessarily --- imageimpl.go | 5 ----- internal/restorable/image.go | 9 +++++++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/imageimpl.go b/imageimpl.go index 9d5bfa7de..a681e2870 100644 --- a/imageimpl.go +++ b/imageimpl.go @@ -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 } diff --git a/internal/restorable/image.go b/internal/restorable/image.go index f33481198..e0ad009b3 100644 --- a/internal/restorable/image.go +++ b/internal/restorable/image.go @@ -64,9 +64,14 @@ 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, - filter: filter, + image: img, + basePixels: p, + filter: filter, }, nil }