mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
parent
c1190c4633
commit
92d8562b1d
16
image.go
16
image.go
@ -708,6 +708,22 @@ func (i *Image) At(x, y int) color.Color {
|
|||||||
return color.RGBA{pix[0], pix[1], pix[2], pix[3]}
|
return color.RGBA{pix[0], pix[1], pix[2], pix[3]}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RGBA64At implements image.RGBA64Image's RGBA64At.
|
||||||
|
//
|
||||||
|
// RGBA64At loads pixels from GPU to system memory if necessary, which means
|
||||||
|
// that RGBA64At can be slow.
|
||||||
|
//
|
||||||
|
// RGBA64At always returns a transparent color if the image is disposed.
|
||||||
|
//
|
||||||
|
// Note that an important logic should not rely on values returned by RGBA64At,
|
||||||
|
// since the returned values can include very slight differences between some machines.
|
||||||
|
//
|
||||||
|
// 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)}
|
||||||
|
}
|
||||||
|
|
||||||
// Set sets the color at (x, y).
|
// Set sets the color at (x, y).
|
||||||
//
|
//
|
||||||
// Set loads pixels from GPU to system memory if necessary, which means that Set can be slow.
|
// Set loads pixels from GPU to system memory if necessary, which means that Set can be slow.
|
||||||
|
@ -1582,18 +1582,29 @@ func TestImageAtAfterDisposingSubImage(t *testing.T) {
|
|||||||
img.Set(0, 0, color.White)
|
img.Set(0, 0, color.White)
|
||||||
img.SubImage(image.Rect(0, 0, 16, 16))
|
img.SubImage(image.Rect(0, 0, 16, 16))
|
||||||
runtime.GC()
|
runtime.GC()
|
||||||
got := img.At(0, 0)
|
|
||||||
want := color.RGBA{0xff, 0xff, 0xff, 0xff}
|
want := color.RGBA{0xff, 0xff, 0xff, 0xff}
|
||||||
|
want64 := color.RGBA64{0xffff, 0xffff, 0xffff, 0xffff}
|
||||||
|
got := img.At(0, 0)
|
||||||
if got != want {
|
if got != want {
|
||||||
t.Errorf("got: %v, want: %v", got, want)
|
t.Errorf("At(0,0) got: %v, want: %v", got, want)
|
||||||
|
}
|
||||||
|
got = img.RGBA64At(0, 0)
|
||||||
|
if got != want64 {
|
||||||
|
t.Errorf("RGBA64At(0,0) got: %v, want: %v", got, want)
|
||||||
}
|
}
|
||||||
|
|
||||||
img.Set(0, 1, color.White)
|
img.Set(0, 1, color.White)
|
||||||
sub := img.SubImage(image.Rect(0, 0, 16, 16)).(*Image)
|
sub := img.SubImage(image.Rect(0, 0, 16, 16)).(*Image)
|
||||||
sub.Dispose()
|
sub.Dispose()
|
||||||
|
|
||||||
got = img.At(0, 1)
|
got = img.At(0, 1)
|
||||||
if got != want {
|
if got != want {
|
||||||
t.Errorf("got: %v, want: %v", got, want)
|
t.Errorf("At(0,1) got: %v, want: %v", got, want64)
|
||||||
|
}
|
||||||
|
got = img.RGBA64At(0, 1)
|
||||||
|
if got != want64 {
|
||||||
|
t.Errorf("RGBA64At(0,1) got: %v, want: %v", got, want64)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user