soft

package
v1.9.9 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: BSD-3-Clause Imports: 7 Imported by: 0 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 soft is the pure-Go software rasterizer, used for golden tests and headless rendering.

Flutter: Skia's software rasterizer (the CPU backend used in flutter_test goldens).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Render

func Render(scene *ui.Scene, width, height int) (*image.RGBA, error)

Render draws a scene into a new image of width x height pixels, in premultiplied RGBA with a transparent background.

Not everything is supported yet. A layer, an operation or a paint feature that is not returns the error SoftNotImplemented naming it, and no image. What works now: container, transform, offset, clip, opacity and color filter layers and picture layers; every operation, text included; paints with colors, gradients, image shaders, all 29 blend modes, color filters and inverted colors; and SaveLayer with a paint. The blurs, shadows, image filters and the backdrop filter and shader mask layers come with step 2.9, text with 4.x.

Flutter: no counterpart (flutter_test renders with Skia's software backend)

func RenderInto

func RenderInto(dst *image.RGBA, scene *ui.Scene, region image.Rectangle) error

RenderInto draws a scene over the pixels of dst, in premultiplied RGBA, but only inside the region, which is cut to dst. The pixels of the region are changed as Render would change them if they had been transparent before the drawing: the caller clears the region first when it wants the scene alone. Everything the scene draws is clipped to the region as if it were the whole surface, so the pixels in it are those of a drawing of the whole scene. Only a scene with something that reads the pixels outside what it draws (an image filter or a backdrop filter that reaches beyond the region) can differ: a caller that redraws a part of a surface draws the whole of such a scene's reach.

It keeps nothing between calls, and two calls on different images may run at the same time.

Flutter: no counterpart (flutter_test renders with Skia's software backend)

func Stroke

func Stroke(contours []ui.FlatContour, st StrokeStyle) [][]ui.Offset

Stroke turns flattened contours into the polygons that cover their stroke. The polygons all wind the same way, so they are filled together with FillNonZero.

A contour with a single point, after repeated points are removed, draws a dot for round and square caps and nothing for butt caps.

Flutter: no counterpart (Skia's SkStroke)

Types

type FillRule

type FillRule int

FillRule says which points are inside a shape whose outline crosses itself.

Flutter: ui/painting.dart PathFillType

const (
	// FillNonZero fills a point when the outline winds around it a number of
	// times other than zero.
	FillNonZero FillRule = iota
	// FillEvenOdd fills a point when a ray from it crosses the outline an odd
	// number of times.
	FillEvenOdd
)

The fill rules.

type ImageRasterizer

type ImageRasterizer struct{}

ImageRasterizer is the ui.Rasterizer of the software renderer: Picture.ToImage and Scene.ToImage use it to make images in headless tests.

Flutter: no counterpart

func (ImageRasterizer) RasterizeScene

func (ImageRasterizer) RasterizeScene(scene *ui.Scene, width, height int) (*ui.Image, error)

RasterizeScene draws the scene into a new image of width x height pixels.

type Mask

type Mask struct {
	// Rect is the area of the surface the mask covers.
	Rect image.Rectangle
	// Cov holds the coverage of each pixel of Rect, row by row from the top. The
	// renderer's own masks of a fill that covers its rectangle fully have none (At and
	// Sum are not used on them).
	Cov []float32
	// contains filtered or unexported fields
}

Mask is the coverage of a shape over a rectangle of pixels: 0 where the shape does not touch a pixel and 1 where it covers the pixel fully.

Flutter: no counterpart (SkMask)

func ClipMask

func ClipMask(path *ui.Path, m *ui.Matrix4, antiAlias bool, area image.Rectangle) *Mask

ClipMask returns the coverage of a clip shape: the path, filled by its fill type under the transform m, inside the area of the surface. Without antiAlias the coverage is all or nothing, sampled at the pixel centers. It returns nil when nothing is covered.

Flutter: no counterpart (SkClipStack)

func OpMask

func OpMask(op ui.DisplayOp, m *ui.Matrix4, area image.Rectangle) (*Mask, bool)

OpMask returns the coverage of the shape that a drawing operation makes, drawn under the transform m, inside the area of the surface: the same coverage Render paints with, anti-aliased or not as the operation's paint says. It works for the operations that draw a shape from an outline: paths, rectangles, rounded rectangles, superellipses, DRRects, ovals, circles, arcs, lines and points. It returns nil when nothing is covered, and false for any other operation. The operation's mask filter and blend mode do not apply.

This is what the GPU renderer rasterizes into its coverage atlas (SPEC §9.2).

Flutter: no counterpart (SkMask)

func Rasterize

func Rasterize(contours [][]ui.Offset, rule FillRule, clip image.Rectangle) *Mask

Rasterize computes the coverage of the area enclosed by the contours, each of which is closed implicitly, inside the clip rectangle. The coverage of a pixel is the exact area of the pixel the shape covers where only one edge crosses it; with several edges in one pixel it is the area under the fill rule applied to the accumulated winding. It returns nil when nothing is covered. Contours with a point that is not finite are skipped.

Flutter: no counterpart (Skia's SkScan_AntiPath)

func (*Mask) At

func (m *Mask) At(x, y int) float32

At returns the coverage of the pixel at x, y, or 0 outside the mask.

func (*Mask) Sum

func (m *Mask) Sum() float64

Sum returns the total coverage: the area of the shape in pixels.

type StrokeStyle

type StrokeStyle struct {
	// Width is the width of the stroke; it must be greater than 0.
	Width float64
	// Cap is the shape of the ends of open contours; StrokeCapUnspecified is
	// StrokeCapButt.
	Cap ui.StrokeCap
	// Join is the shape of the corners; StrokeJoinUnspecified is
	// StrokeJoinMiter.
	Join ui.StrokeJoin
	// MiterLimit is the longest miter, as a multiple of half the width, that a
	// miter join may have before it becomes a bevel; 0 is Flutter's default, 4.
	MiterLimit float64
	// Scale is how much a transform applied to the result magnifies lengths. It
	// only sets the number of segments used for round joins and caps; 0 is 1.
	Scale float64
}

StrokeStyle describes how a path is stroked. The units are those of the path.

Flutter: ui/painting.dart Paint.strokeWidth

Jump to

Keyboard shortcuts

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