From 349a290aa37c14eaca32a020b481a854a75e340f Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Tue, 16 Jul 2019 03:08:26 +0900 Subject: [PATCH] restorable: Refactoring --- internal/restorable/image.go | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/internal/restorable/image.go b/internal/restorable/image.go index 795c19150..76947ae06 100644 --- a/internal/restorable/image.go +++ b/internal/restorable/image.go @@ -332,18 +332,12 @@ func (i *Image) ReplacePixels(pixels []byte, x, y, width, height int) { } if x == 0 && y == 0 && width == w && height == h { - if pixels != nil { - if i.basePixels == nil { - i.basePixels = &Pixels{ - length: 4 * w * h, - } + if i.basePixels == nil { + i.basePixels = &Pixels{ + length: 4 * w * h, } - i.basePixels.CopyFrom(pixels, 0) - } else { - // If basePixels is nil, the restored pixels are cleared. - // See restore() implementation. - i.basePixels = nil } + i.basePixels.CopyFrom(pixels, 0) i.drawTrianglesHistory = nil i.stale = false return @@ -358,23 +352,15 @@ func (i *Image) ReplacePixels(pixels []byte, x, y, width, height int) { } idx := 4 * (y*w + x) - if pixels != nil { - if i.basePixels == nil { - i.basePixels = &Pixels{ - length: 4 * w * h, - } - } - for j := 0; j < height; j++ { - i.basePixels.CopyFrom(pixels[4*j*width:4*(j+1)*width], idx) - idx += 4 * w - } - } else if i.basePixels != nil { - zeros := make([]byte, 4*width) - for j := 0; j < height; j++ { - i.basePixels.CopyFrom(zeros, idx) - idx += 4 * w + if i.basePixels == nil { + i.basePixels = &Pixels{ + length: 4 * w * h, } } + for j := 0; j < height; j++ { + i.basePixels.CopyFrom(pixels[4*j*width:4*(j+1)*width], idx) + idx += 4 * w + } } // DrawTriangles draws a given image img to the image.