Skip to content

Commit

Permalink
ebiten: refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
hajimehoshi committed Aug 27, 2023
1 parent c4b8378 commit ead3f32
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions image.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ func (i *Image) Fill(clr color.Color) {
cgf = float32(cg) / 0xffff
cbf = float32(cb) / 0xffff
caf = float32(ca) / 0xffff
b := i.Bounds()
x, y := i.adjustPosition(b.Min.X, b.Min.Y)
i.image.Fill(crf, cgf, cbf, caf, image.Rect(x, y, x+b.Dx(), y+b.Dy()))
i.image.Fill(crf, cgf, cbf, caf, i.adjustedBounds())
}

func canSkipMipmap(geom GeoM, filter builtinshader.Filter) bool {
Expand Down Expand Up @@ -172,6 +170,12 @@ func (i *Image) adjustPositionF32(x, y float32) (float32, float32) {
return x, y
}

func (i *Image) adjustedBounds() image.Rectangle {
b := i.Bounds()
x, y := i.adjustPosition(b.Min.X, b.Min.Y)
return image.Rect(x, y, x+b.Dx(), y+b.Dy())
}

func (i *Image) adjustedRegion() graphicsdriver.Region {
b := i.Bounds()
x, y := i.adjustPosition(b.Min.X, b.Min.Y)
Expand Down Expand Up @@ -886,8 +890,7 @@ func (i *Image) ReadPixels(pixels []byte) {
return
}

x, y := i.adjustPosition(b.Min.X, b.Min.Y)
i.image.ReadPixels(pixels, image.Rect(x, y, x+b.Dx(), y+b.Dy()))
i.image.ReadPixels(pixels, i.adjustedBounds())
}

// At returns the color of the image at (x, y).
Expand Down Expand Up @@ -998,12 +1001,10 @@ func (i *Image) WritePixels(pixels []byte) {
return
}

r := i.Bounds()
x, y := i.adjustPosition(r.Min.X, r.Min.Y)
// Do not need to copy pixels here.
// * In internal/mipmap, pixels are copied when necessary.
// * In internal/atlas, pixels are copied to make its paddings.
i.image.WritePixels(pixels, image.Rect(x, y, x+r.Dx(), y+r.Dy()))
i.image.WritePixels(pixels, i.adjustedBounds())
}

// ReplacePixels replaces the pixels of the image.
Expand Down

0 comments on commit ead3f32

Please sign in to comment.