Upgrade tomo version

This commit is contained in:
Sasha Koshka 2023-09-05 17:50:53 -04:00
parent 11a14431be
commit af6aa2c463
4 changed files with 33 additions and 10 deletions

View File

@ -1,6 +1,8 @@
package xcanvas package xcanvas
import "image" import "image"
import "image/color"
import "github.com/jezek/xgbutil/xgraphics"
import "git.tebibyte.media/tomo/tomo/canvas" import "git.tebibyte.media/tomo/tomo/canvas"
// Texture is a read-only image texture that can be quickly written to a canvas. // Texture is a read-only image texture that can be quickly written to a canvas.
@ -40,16 +42,43 @@ func NewTextureFrom (source image.Image) *Texture {
return texture return texture
} }
func (this *Texture) BGRAAt (x, y int) xgraphics.BGRA {
if !(image.Point{ x, y }.In(this.rect)) {
return xgraphics.BGRA { }
}
index := this.PixOffset(x, y)
return xgraphics.BGRA {
B: this.pix[index ],
G: this.pix[index + 1],
R: this.pix[index + 2],
A: this.pix[index + 3],
}
}
func (this *Texture) At (x, y int) color.Color {
return this.BGRAAt(x, y)
}
// Bounds returns the bounding rectangle of this texture. // Bounds returns the bounding rectangle of this texture.
func (this *Texture) Bounds () image.Rectangle { func (this *Texture) Bounds () image.Rectangle {
return this.rect return this.rect
} }
func (this *Texture) ColorModel () color.Model {
return xgraphics.BGRAModel
}
// Opaque reports whether or not the texture is fully opaque. // Opaque reports whether or not the texture is fully opaque.
func (this *Texture) Opaque () bool { func (this *Texture) Opaque () bool {
return !this.transparent return !this.transparent
} }
func (this *Texture) PixOffset (x, y int) int {
x = wrap(x, this.rect.Min.X, this.rect.Max.X)
y = wrap(y, this.rect.Min.Y, this.rect.Max.Y)
return x * 4 + y * this.stride
}
// Close frees the texture from memory. // Close frees the texture from memory.
func (this *Texture) Close () error { func (this *Texture) Close () error {
// i lied we dont actually need to close this, but we will once this // i lied we dont actually need to close this, but we will once this