mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 18:52:44 +01:00
restorable: Refactoring
This commit is contained in:
parent
8ae2fef817
commit
349a290aa3
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user