mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
ebiten: Follow image.RGBA64Image's aim
image.RGBA64Image aims to get 64bit color values efficiently to avoid allocating an original color value and converting it to colorRGBA64. Thus, we should avoid allocating color.RGBA for RGBA64At. Updates #1769
This commit is contained in:
parent
fd58f84deb
commit
ba8ea50d57
39
image.go
39
image.go
@ -691,21 +691,8 @@ func (i *Image) ColorModel() color.Model {
|
||||
//
|
||||
// At can't be called outside the main loop (ebiten.Run's updating function) starts.
|
||||
func (i *Image) At(x, y int) color.Color {
|
||||
if i.isDisposed() {
|
||||
return color.RGBA{}
|
||||
}
|
||||
if !image.Pt(x, y).In(i.Bounds()) {
|
||||
return color.RGBA{}
|
||||
}
|
||||
pix, err := i.mipmap.Pixels(x, y, 1, 1)
|
||||
if err != nil {
|
||||
if panicOnErrorAtImageAt {
|
||||
panic(err)
|
||||
}
|
||||
theUIContext.setError(err)
|
||||
return color.RGBA{}
|
||||
}
|
||||
return color.RGBA{pix[0], pix[1], pix[2], pix[3]}
|
||||
r, g, b, a := i.at(x, y)
|
||||
return color.RGBA{r, g, b, a}
|
||||
}
|
||||
|
||||
// RGBA64At implements image.RGBA64Image's RGBA64At.
|
||||
@ -720,8 +707,26 @@ func (i *Image) At(x, y int) color.Color {
|
||||
//
|
||||
// RGBA64At can't be called outside the main loop (ebiten.Run's updating function) starts.
|
||||
func (i *Image) RGBA64At(x, y int) color.RGBA64 {
|
||||
r, g, b, a := i.At(x, y).(color.RGBA).RGBA()
|
||||
return color.RGBA64{uint16(r), uint16(g), uint16(b), uint16(a)}
|
||||
r, g, b, a := i.at(x, y)
|
||||
return color.RGBA64{uint16(r) * 0x101, uint16(g) * 0x101, uint16(b) * 0x101, uint16(a) * 0x101}
|
||||
}
|
||||
|
||||
func (i *Image) at(x, y int) (r, g, b, a uint8) {
|
||||
if i.isDisposed() {
|
||||
return 0, 0, 0, 0
|
||||
}
|
||||
if !image.Pt(x, y).In(i.Bounds()) {
|
||||
return 0, 0, 0, 0
|
||||
}
|
||||
pix, err := i.mipmap.Pixels(x, y, 1, 1)
|
||||
if err != nil {
|
||||
if panicOnErrorAtImageAt {
|
||||
panic(err)
|
||||
}
|
||||
theUIContext.setError(err)
|
||||
return 0, 0, 0, 0
|
||||
}
|
||||
return pix[0], pix[1], pix[2], pix[3]
|
||||
}
|
||||
|
||||
// Set sets the color at (x, y).
|
||||
|
Loading…
Reference in New Issue
Block a user