raster

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: Apache-2.0, MIT Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package raster renders display boxes to RGBA images and PNG streams with a pure-Go antialiased vector rasterizer.

Encode and EncodePNG walk the visible display-list commands in paint order. Path templates resolve as At + point*Em, rules fill their placed rectangles, explicit paints override palette roles, and Box.Bounds includes certified overflow. A nil Options uses DefaultOptions.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidBox reports a malformed display box.
	ErrInvalidBox = errors.New("raster: invalid box")
	// ErrInvalidOptions reports an invalid scale, padding, or output size.
	ErrInvalidOptions = errors.New("raster: invalid options")
	// ErrInvalidPath reports a path segment that cannot be rasterized.
	ErrInvalidPath = errors.New("raster: invalid path")
	// ErrInvalidWriter reports a nil PNG destination.
	ErrInvalidWriter = errors.New("raster: invalid writer")
	// ErrImageTooLarge reports dimensions that cannot form an image.RGBA.
	ErrImageTooLarge = errors.New("raster: image too large")
)

Functions

func Encode

func Encode(box *display.Box, options *Options) (*image.RGBA, error)

Encode rasterizes box into a caller-owned RGBA image.

The image includes the complete Box.Bounds, including certified overflow. Each dimension is ceil(boundsDimension*Scale + 2*Padding), with a minimum of one pixel. Box coordinates map to output pixels as (boundsCoordinate-bounds.Min)*Scale + Padding.

func EncodePNG

func EncodePNG(w io.Writer, box *display.Box, options *Options) error

EncodePNG rasterizes box and encodes the result as a PNG stream.

Types

type Options

type Options struct {
	Scale      float32
	Padding    float32
	Background *color.NRGBA
	Palette    Palette
}

Options controls raster output.

Scale is the number of output pixels per host unit and must be finite and positive. Padding is measured in output pixels and must be finite and nonnegative. A nil Background creates a transparent image; a non-nil Background fills the complete image before visible commands are drawn.

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns a transparent one-pixel-per-unit image with eight pixels of padding and conventional black, red, and muted-gray paints.

type Palette

type Palette struct {
	Ink         color.NRGBA
	Error       color.NRGBA
	Placeholder color.NRGBA
}

Palette resolves semantic display paints to concrete colors.

Jump to

Keyboard shortcuts

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