This repository has been archived on 2024-06-03. You can view files and clone it, but cannot push or open issues or pull requests.
x/texture.go

49 lines
1.0 KiB
Go
Raw Normal View History

2023-08-21 04:35:55 +00:00
package x
import "image"
import "git.tebibyte.media/tomo/tomo"
type texture struct {
pix []uint8
stride int
rect image.Rectangle
transparent bool
2023-08-21 04:35:55 +00:00
}
func (backend *Backend) NewTexture (source image.Image) tomo.Texture {
bounds := source.Bounds()
texture := &texture {
pix: make([]uint8, bounds.Dx() * bounds.Dy() * 4),
stride: bounds.Dx(),
rect: bounds.Sub(bounds.Min),
}
index := 0
var point image.Point
for point.Y = bounds.Min.Y; point.Y < bounds.Max.Y; point.Y ++ {
for point.X = bounds.Min.X; point.X < bounds.Max.X; point.X ++ {
r, g, b, a := source.At(point.X, point.Y).RGBA()
texture.pix[index + 0] = uint8(b >> 8)
texture.pix[index + 1] = uint8(g >> 8)
texture.pix[index + 2] = uint8(r >> 8)
texture.pix[index + 3] = uint8(a >> 8)
index += 4
if a != 0xFFFF {
texture.transparent = true
}
2023-08-21 04:35:55 +00:00
}}
return texture
}
func (this *texture) Clip (bounds image.Rectangle) tomo.Texture {
clipped := *this
clipped.rect = bounds
return &clipped
}
func (this *texture) Close () error {
return nil
}