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 { return err } } } err := buf.Flush() if err != nil { return err } return nil }