display

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package display defines device-independent monochrome frame and lifecycle contracts. Frames borrow caller-owned storage and never allocate or copy it.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCapabilities  = errors.New("display: invalid capabilities")
	ErrColor         = errors.New("display: invalid color")
	ErrFrameGeometry = errors.New("display: invalid frame geometry")
	ErrPixelBounds   = errors.New("display: pixel outside frame")
	ErrRefreshMode   = errors.New("display: unsupported refresh mode")
)

Functions

This section is empty.

Types

type Capabilities

type Capabilities struct {
	Size              Size
	ColorModel        ColorModel
	RefreshModes      RefreshMode
	WidthAlignment    int
	HeightAlignment   int
	StrideAlignment   int
	RefreshAutoSleeps bool
}

Capabilities describes the logical frame and lifecycle accepted by a Device.

func (Capabilities) FrameStride

func (c Capabilities) FrameStride() (int, error)

FrameStride returns the one packed row stride accepted by the device.

func (Capabilities) Validate

func (c Capabilities) Validate() error

Validate reports whether the capabilities form a usable monochrome contract.

func (Capabilities) ValidateFrame

func (c Capabilities) ValidateFrame(frame Frame, mode RefreshMode) error

ValidateFrame verifies that frame and mode can be consumed by the device.

type Color

type Color uint8

Color is a monochrome pixel value. Packed frames use zero for white and one for black, with the leftmost pixel in the most-significant bit.

const (
	White Color = iota
	Black
)

type ColorModel

type ColorModel uint8

ColorModel identifies a frame's pixel representation.

const (
	Mono1 ColorModel = 1 + iota
)

type Device

type Device interface {
	Capabilities() Capabilities
	Refresh(frame Frame, mode RefreshMode) error
	Sleep() error
}

Device consumes complete frames synchronously. Refresh must not retain or mutate frame storage after it returns. Sleep is idempotent.

type Frame

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

Frame is a mutable view over caller-owned packed monochrome storage. Copies of Frame share the same bytes. The storage must remain stable while Refresh is running and may be reused as soon as Refresh returns.

func NewFrame

func NewFrame(size Size, stride int, pixels []byte) (Frame, error)

NewFrame validates and borrows pixels without copying them.

func (Frame) Bytes

func (f Frame) Bytes() []byte

Bytes returns the borrowed backing storage. Callers must follow Frame's ownership rules and must not resize the slice.

func (Frame) Clear

func (f Frame) Clear(color Color) error

Clear fills all logical and padding bits with color.

func (Frame) Pixel

func (f Frame) Pixel(x, y int) Color

Pixel returns the pixel at x, y. An out-of-bounds coordinate returns White.

func (Frame) SetPixel

func (f Frame) SetPixel(x, y int, color Color) error

SetPixel changes one pixel without allocating.

func (Frame) Size

func (f Frame) Size() Size

Size returns the logical frame size.

func (Frame) Stride

func (f Frame) Stride() int

Stride returns bytes between adjacent rows.

type RefreshMode

type RefreshMode uint8

RefreshMode is both a single refresh request and a capabilities bit.

const (
	RefreshFull RefreshMode = 1 << iota
	RefreshPartial
)

type Size

type Size struct {
	Width  int
	Height int
}

Size is a logical display size in pixels.

Jump to

Keyboard shortcuts

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