This commit is contained in:
2026-08-07 21:41:29 +03:00
parent 729a636b9b
commit cb275b1839
4 changed files with 66 additions and 0 deletions
+2
View File
@@ -1 +1,3 @@
package main
+1
View File
@@ -8,6 +8,7 @@ require (
)
require (
github.com/Shopify/go-lua v0.0.0-20250718183320-1e37f32ad7d0 // indirect
github.com/dbriemann/pixel v0.5.1 // indirect
github.com/go-gl/mathgl v1.2.0 // indirect
)
+2
View File
@@ -1,3 +1,5 @@
github.com/Shopify/go-lua v0.0.0-20250718183320-1e37f32ad7d0 h1:oGlw/+ndlFMn8KWLjEX5nULcDwOC4tJy3Kk1Pm84Cys=
github.com/Shopify/go-lua v0.0.0-20250718183320-1e37f32ad7d0/go.mod h1:M4CxjVc/1Nwka5atBv7G/sb7Ac2BDe3+FxbiT9iVNIQ=
github.com/dbriemann/pixel v0.5.1 h1:9iPqkfolOW2VRu8IzEbUBii9/S5ubMwPTQP7xBGkNX8=
github.com/dbriemann/pixel v0.5.1/go.mod h1:iWjzS4T3euA4FW04ULyz3SCkZB5LyK7pwTR1vyZFv0E=
github.com/go-gl/mathgl v1.2.0 h1:v2eOj/y1B2afDxF6URV1qCYmo1KW08lAMtTbOn3KXCY=
+61
View File
@@ -0,0 +1,61 @@
package fb
import (
"bufio"
"fmt"
"image"
"image/color"
"os"
)
func Resolution() (w int, h int) {
resFile, err := os.Open("/sys/class/graphics/fb0/virtual_size")
if err != nil {
panic(err)
}
r := bufio.NewReader(resFile)
s, err := r.ReadString('\n')
if err != nil {
panic(err)
}
fmt.Sscanf(s, "%d,%d", &w, &h)
return
}
var devfb *os.File
var width, height = Resolution()
func init() {
var err error
devfb, err = os.OpenFile("/dev/fb0", os.O_WRONLY, os.ModePerm)
if err != nil {
panic(err)
}
}
func Bytes(c color.Color) []byte {
r, g, b, a := c.RGBA()
return []byte{byte(b), byte(g), byte(r), byte(a)}
}
func Draw(img image.Image) error {
buf := bufio.NewWriterSize(devfb, 1<<16)
for h := 0; h < height; h++ {
for w := 0; w < width; w++ {
_, err := buf.Write(Bytes(img.At(w, h)))
if err != nil {
return err
}
}
}
err := buf.Flush()
if err != nil {
return err
}
_, err := devfb.Seek(0,0)
if err != nil {
return err
}
return nil
}