framebuffer

package module
v0.0.0-...-e5c64e3 Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: MIT Imports: 7 Imported by: 1

README

Foreword

This repository is fork of firelizzard18/framebuffer with module paths fixed so that it can be used in project.

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/d21d3q/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 FbBitField

type FbBitField struct {
	Offset   uint32
	Length   uint32
	MsbRight uint32
}

<linux/fb.h> struct fb_bitfield

Interpretation of offset for color fields: All offsets are from the right, inside a "pixel" value, which is exactly 'bits_per_pixel' wide (means: you can use the offset as right argument to <<). A pixel afterwards is a bit stream and is written to video memory as that unmodified.

For pseudocolor: offset and length should be the same for all color components. Offset specifies the position of the least significant bit of the palette index in a pixel value. Length indicates the number of available palette entries (i.e. # of entries = 1 << length).

type FbFixScreenInfo

type FbFixScreenInfo struct {
	// Screen ID, e.g. "TT Builtin"
	ID [16]byte

	// Frame buffer mem (physical address)
	SMemStart uintptr
	SMemLen   uint32

	// Framebuffer type (see FB_TYPE_*)
	Type uint32

	// "Interleave for interleaved Planes"
	TypeAux uint32

	// ??? (see FB_VISUAL_)
	Visual uint32

	XPanStep  uint16
	YPanStep  uint16
	YWrapStep uint16

	// Length of a line in bytes
	LineLength uint32

	// Memory mapped I/O (physical address)
	MmioStart uintptr
	MmioLen   uint32

	// "Indicate to driver which specific chip/card we have"
	Accel uint32

	// Capabilities (see FB_CAP_*)
	Capabilities uint16
	// contains filtered or unexported fields
}

<linux/fb.h> struct fb_fix_screeninfo

Fixed parameters of a screen

type FbVarScreenInfo

type FbVarScreenInfo struct {
	// Visible resolution
	XRes, YRes uint32

	// Virtual resolution
	XResVirtual, YResVirtual uint32

	// Offset from virtual to visible resolution
	XOffset, YOffset uint32

	// Number of bits per pixel in the buffer
	BitsPerPixel uint32

	// 0 = color, 1 = grayscale, >1 = FOURCC
	Grayscale uint32

	// Pixel format
	Red, Green, Blue, Alpha FbBitField

	// A value other than zero indicates a non-standard pixel format
	NonStd uint32

	// ??? (see FB_ACTIVATE_*)
	Activate uint32

	// Dimensions of picture in mm
	Height, Width uint32

	// Pixel clock in pico seconds
	PixelClock uint32

	// Time from sync to picture
	LeftMargin uint32

	// Time from picture to sync
	RightMargin uint32

	UpperMargin uint32
	LowerMargin uint32

	// Length of horizontal sync
	HSyncLen uint32

	// Length of vertical sync
	VSyncLen uint32

	// ??? (see FB_SYNC_*)
	Sync uint32

	// ??? (see FB_VMODE_*)
	VMode uint32

	// Angle we rotate counter clockwise
	Rotate uint32

	// Color space for FOURCC-based modes
	ColorSpace uint32
	// contains filtered or unexported fields
}

<linux/fb.h> struct fb_fix_screeninfo

Variable parameters of a screen

type FrameBuffer

type FrameBuffer os.File

FrameBuffer is a wrapper around os.File that provides convenience methods for interacting with a frame buffer device.

func OpenFrameBuffer

func OpenFrameBuffer(name string, flags int) (*FrameBuffer, error)

OpenFrameBuffer opens a frame buffer device.

func (*FrameBuffer) File

func (fb *FrameBuffer) File() *os.File

File converts the frame buffer back to a file.

func (*FrameBuffer) FixScreenInfo

func (fb *FrameBuffer) FixScreenInfo() (FbFixScreenInfo, error)

FixScreenInfo returns the fixed properties of the screen.

func (*FrameBuffer) Pixels

func (fb *FrameBuffer) Pixels() ([]byte, error)

Pixels returns a byte slice memory mapped to the frame buffer.

func (*FrameBuffer) VarScreenInfo

func (fb *FrameBuffer) VarScreenInfo() (FbVarScreenInfo, error)

VarScreenInfo returns the variable properties of the screen.

type Image

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

func Open

func Open(name string) (_ *Image, err error)

Open opens the frame buffer device (such as "/dev/fb0") as a drawable image.

func (*Image) At

func (m *Image) At(x, y int) color.Color

At returns the color at the given coordinates.

func (*Image) Bounds

func (m *Image) Bounds() image.Rectangle

Bounds returns the bounds of the frame buffer.

func (*Image) Close

func (m *Image) Close() error

Close closes the frame buffer.

func (*Image) ColorModel

func (m *Image) ColorModel() color.Model

ColorModel returns the color model of the frame buffer.

func (*Image) Height

func (m *Image) Height() int

Height returns the height of the frame buffer.

func (*Image) Set

func (m *Image) Set(x, y int, c color.Color)

Set sets the color at the given coordinates.

func (*Image) Width

func (m *Image) Width() int

Width returns the width of the frame buffer.

type TTY

type TTY os.File

TTY is a wrapper around os.File that provides convenience methods for interacting with a TTY.

func OpenMyTTY

func OpenMyTTY(flags int) (*TTY, error)

OpenMyTTY opens the current process's TTY. Requires procfs mounted at /proc.

func OpenTTY

func OpenTTY(name string, flags int) (*TTY, error)

OpenTTY opens a TTY.

func (*TTY) File

func (d *TTY) File() *os.File

File converts the TTY back to a file.

func (*TTY) GetMode

func (d *TTY) GetMode() (TTYMode, error)

GetMode returns the TTY's current mode.

func (*TTY) GraphicsMode

func (d *TTY) GraphicsMode() error

GraphicsMode puts the TTY in graphics mode.

func (*TTY) SetMode

func (d *TTY) SetMode(mode TTYMode) error

SetMode sets the TTY's mode.

func (*TTY) TextMode

func (d *TTY) TextMode() error

TextMode puts the TTY in text mode.

type TTYMode

type TTYMode int
const (
	TTYTextMode     TTYMode = kKD_TEXT
	TTYGraphicsMode TTYMode = kKD_GRAPHICS
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳