Skip to content

Commit

Permalink
Revert "internal/restorable: refactoring"
Browse files Browse the repository at this point in the history
This reverts commit 81e1104.

Updates #3083
  • Loading branch information
hajimehoshi committed Sep 6, 2024
1 parent 3a11b27 commit 868402e
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions internal/restorable/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,7 @@ func clearImage(i *graphicscommand.Image, region image.Rectangle) {

// ClearPixels clears the specified region by WritePixels.
func (i *Image) ClearPixels(region image.Rectangle) {
if region.Dx() <= 0 || region.Dy() <= 0 {
panic("restorable: width/height must be positive")
}
clearImage(i.Image, region.Intersect(image.Rect(0, 0, i.width, i.height)))
i.WritePixels(nil, region)
}

// WritePixels replaces the image pixels with the given pixels slice.
Expand All @@ -106,7 +103,11 @@ func (i *Image) WritePixels(pixels *graphics.ManagedBytes, region image.Rectangl
panic(fmt.Sprintf("restorable: out of range %v", region))
}

i.Image.WritePixels(pixels, region)
if pixels != nil {
i.Image.WritePixels(pixels, region)
} else {
clearImage(i.Image, region)
}
}

// DrawTriangles draws triangles with the given image.
Expand Down

0 comments on commit 868402e

Please sign in to comment.