X backend properly converts image data

This commit is contained in:
Sasha Koshka 2024-06-15 23:33:59 -04:00
parent 727a801243
commit e21b57a915

View File

@ -184,8 +184,12 @@ func (this *window) SetIcon (sizes ...canvas.Texture) {
for _, icon := range sizes {
// TODO we use textures now. make this better
width := icon.Bounds().Max.X
height := icon.Bounds().Max.Y
icon, ok := icon.(*xcanvas.Texture)
if !ok { continue }
bounds := icon.Bounds()
width := bounds.Dx()
height := bounds.Dy()
wmIcon := ewmh.WmIcon {
Width: uint(width),
Height: uint(height),
@ -195,18 +199,14 @@ func (this *window) SetIcon (sizes ...canvas.Texture) {
// manually convert image data beacuse of course we have to do
// this
index := 0
for y := 0; y < height; y ++ {
for x := 0; x < width; x ++ {
r, g, b, a := icon.At(x, y).RGBA()
r >>= 8
g >>= 8
b >>= 8
a >>= 8
for y := bounds.Min.Y; y < bounds.Max.Y; y ++ {
for x := bounds.Min.X; x < bounds.Max.X; x ++ {
pixel := icon.BGRAAt(x, y)
wmIcon.Data[index] =
(uint(a) << 24) |
(uint(r) << 16) |
(uint(g) << 8) |
(uint(b) << 0)
(uint(pixel.A) << 24) |
(uint(pixel.R) << 16) |
(uint(pixel.G) << 8) |
(uint(pixel.B) << 0)
index ++
}}