framebuffer

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2021 License: MIT Imports: 6 Imported by: 2

README

About

The framebuffer library was created to have an easy way to access the pixels on the screen from the Raspberry Pi. It memory-maps the framebuffer device and provides it as a draw.Image (which is itself an image.Image). This makes it easy to use with Go's image, color and draw packages.

Right now the library only implements the RGB 565 color model, which is the default under Raspbian. Also the OS is assumed to be little endian, also the default for Raspbian.

Usage

To access the framebuffer you have to call Open and pass the device file to it. When you are done, call Close on the returned device. Note that you usually need root access for this so make sure to run your program as a super user.

Once you have a device open you can use it like a Go draw.Image (image.Image).

Here is a simple example that clears the whole screen to a dark magenta:

package main

import (
	"github.com/gonutz/framebuffer"
	"image"
	"image/color"
	"image/draw"
)

func main() {
	fb, err := framebuffer.Open("/dev/fb0")
	if err != nil {
		panic(err)
	}
	defer fb.Close()

	magenta := image.NewUniform(color.RGBA{255, 0, 128, 255})
	draw.Draw(fb, fb.Bounds(), magenta, image.ZP, draw.Src)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Device

type Device struct {
	// contains filtered or unexported fields
}

Device represents the frame buffer. It implements the draw.Image interface.

func Open

func Open(device string) (*Device, error)

Open expects a framebuffer device as its argument (such as "/dev/fb0"). The device will be memory-mapped to a local buffer. Writing to the device changes the screen output. The returned Device implements the draw.Image interface. This means that you can use it to copy to and from other images. The only supported color model for the specified frame buffer is RGB565. After you are done using the Device, call Close on it to unmap the memory and close the framebuffer file.

func (*Device) At

func (d *Device) At(x, y int) color.Color

At implements the image.Image (and draw.Image) interface.

func (*Device) Bounds

func (d *Device) Bounds() image.Rectangle

Bounds implements the image.Image (and draw.Image) interface.

func (*Device) Close

func (d *Device) Close()

Close unmaps the framebuffer memory and closes the device file. Call this function when you are done using the frame buffer.

func (*Device) ColorModel

func (d *Device) ColorModel() color.Model

ColorModel implements the image.Image (and draw.Image) interface.

func (*Device) Set

func (d *Device) Set(x, y int, c color.Color)

Set implements the draw.Image interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL