From da7aa9a43b7850dcffe58b08f9f0b285a3e0c313 Mon Sep 17 00:00:00 2001 From: potassium Date: Sun, 26 Jan 2025 05:33:51 +0300 Subject: [PATCH] init --- fb/main.go | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ go.mod | 3 +++ readme | 1 + 3 files changed, 58 insertions(+) create mode 100644 fb/main.go create mode 100644 go.mod create mode 100644 readme diff --git a/fb/main.go b/fb/main.go new file mode 100644 index 0000000..613aa8f --- /dev/null +++ b/fb/main.go @@ -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) + } +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..c804372 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.niplace.ru/XoxJlopeZi4BB/dev + +go 1.23.4 diff --git a/readme b/readme new file mode 100644 index 0000000..9fe57f7 --- /dev/null +++ b/readme @@ -0,0 +1 @@ +tools for working with shitty linux /dev device files