display

package
v3.6.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2019 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package display implements interfaces for visual output devices. These can be pixel or text based.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Drawer

type Drawer interface {
	conn.Resource

	// ColorModel returns the device native color model.
	ColorModel() color.Model
	// Bounds returns the size of the output device.
	//
	// Generally displays should have Min at {0, 0} but this is not guaranteed in
	// multiple displays setup or when an instance of this interface represents a
	// section of a larger logical display.
	Bounds() image.Rectangle
	// Draw updates the display with this image.
	//
	// Only the pixels within the display boundary are updated. Partial update is
	// supported.
	//
	// Coordinates are top-left 0,0.
	//
	// dstRect aligns the the drawing operation in the display, enabling partial
	// update.
	//
	// srcPts aligns the image at this offset, enabling using a subset of the
	// source image. use image.ZP/image.Point{} to take the image at its origin.
	Draw(dstRect image.Rectangle, src image.Image, srcPts image.Point) error
}

Drawer represents a context to display pixels on an output device. It is a write-only interface.

What Drawer represents can be as varied as a 1 bit OLED display or a strip of LED lights. The implementation keeps a single frame buffer, so that partial updates can be done.

Example
package main

import (
	"image"
	"log"

	"periph.io/x/periph/conn/display"
	"periph.io/x/periph/host"
)

func main() {
	// Make sure periph is initialized.
	if _, err := host.Init(); err != nil {
		log.Fatal(err)
	}

	// Get a display output device, like an apa102 or ssd1306. For example:
	//   s, _ := spireg.Open("")
	//   d, _ := apa102.New(s, &apa102.DefaultOpts)
	var d display.Drawer

	// Get an image. You could load a PNG. Resize it to the device display size.
	img := image.NewNRGBA(d.Bounds())

	// Render the image. The normal use case is:
	// - Use d.Bounds() as the dstRect, to cover the whole screen.
	// - Use image.ZP/image.Point{} as 'srcPts' unless you want to offset inside
	//   the image.
	if err := d.Draw(d.Bounds(), img, image.ZP); err != nil {
		log.Fatal(err)
	}
}
Output:

Directories

Path Synopsis
Package displaytest contains non-hardware devices implementations for testing or emulation purpose.
Package displaytest contains non-hardware devices implementations for testing or emulation purpose.

Jump to

Keyboard shortcuts

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