package x import "image" import "git.tebibyte.media/tomo/tomo" type texture struct { pix []uint8 stride int rect image.Rectangle transparent bool } 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 } }} 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 } func assertTexture (unknown tomo.Texture) *texture { if tx, ok := unknown.(*texture); ok { return tx } else { panic("foregin texture implementation, i did not make this!") } }