restorable: Bug fix: Make the image stale when pixels are partly replaced

This commit is contained in:
Hajime Hoshi 2018-03-25 20:39:06 +09:00
parent fc47d2843a
commit 025fd00e6b

View File

@ -133,21 +133,28 @@ func (i *Image) ReplacePixels(pixels []byte, x, y, width, height int) {
i.image.ReplacePixels(pixels, x, y, width, height) i.image.ReplacePixels(pixels, x, y, width, height)
// Copy the pixels so that this works even p is modified just after ReplacePixels. if x == 0 && y == 0 && width == w && height == h {
if i.basePixels == nil { if i.basePixels == nil {
if x == 0 && y == 0 && width == w && height == h {
i.basePixels = make([]byte, 4*w*h) i.basePixels = make([]byte, 4*w*h)
} else {
i.makeStale()
return
} }
copy(i.basePixels, pixels)
i.drawImageHistory = nil
i.stale = false
return
}
if i.basePixels == nil {
i.makeStale()
return
}
if len(i.drawImageHistory) > 0 {
i.makeStale()
return
} }
idx := 4 * (y*w + x) idx := 4 * (y*w + x)
for j := 0; j < height; j++ { for j := 0; j < height; j++ {
copy(i.basePixels[idx:idx+4*width], pixels[4*j*width:4*(j+1)*width]) copy(i.basePixels[idx:idx+4*width], pixels[4*j*width:4*(j+1)*width])
idx += 4 * w idx += 4 * w
} }
i.drawImageHistory = nil
i.stale = false i.stale = false
} }