This commit is contained in:
potassium 2025-01-26 05:33:51 +03:00
commit da7aa9a43b
3 changed files with 58 additions and 0 deletions

54
fb/main.go Normal file
View File

@ -0,0 +1,54 @@
package fb
import (
"os"
)
var (
devfb *os.File
Width, Height int
)
func resolution() (w int, h int) {
resFile, err := os.File("/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
}
func init() {
Width, Height = resolution()
devfb, err := os.OpenFile("/dev/fb", 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 {
panic(err)
}
}
}
err := buf.Flush()
if err != nil {
panic(err)
}
}

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module git.niplace.ru/XoxJlopeZi4BB/dev
go 1.23.4

1
readme Normal file
View File

@ -0,0 +1 @@
tools for working with shitty linux /dev device files