...

Package raster

import "github.com/golang/freetype/raster"
Overview
Index

Overview ▾

Package raster provides an anti-aliasing 2-D rasterizer.

It is part of the larger Freetype suite of font-related packages, but the raster package is not specific to font rasterization, and can be used standalone without any other Freetype package.

Rasterization is done by the same area/coverage accumulation algorithm as the Freetype "smooth" module, and the Anti-Grain Geometry library. A description of the area/coverage algorithm is at http://projects.tuxee.net/cl-vectors/section-the-cl-aa-algorithm

Index ▾

func Stroke(p Adder, q Path, width fixed.Int26_6, cr Capper, jr Joiner)
type Adder
type AlphaOverPainter
    func NewAlphaOverPainter(m *image.Alpha) AlphaOverPainter
    func (r AlphaOverPainter) Paint(ss []Span, done bool)
type AlphaSrcPainter
    func NewAlphaSrcPainter(m *image.Alpha) AlphaSrcPainter
    func (r AlphaSrcPainter) Paint(ss []Span, done bool)
type Capper
type CapperFunc
    func (f CapperFunc) Cap(p Adder, halfWidth fixed.Int26_6, pivot, n1 fixed.Point26_6)
type GammaCorrectionPainter
    func NewGammaCorrectionPainter(p Painter, gamma float64) *GammaCorrectionPainter
    func (g *GammaCorrectionPainter) Paint(ss []Span, done bool)
    func (g *GammaCorrectionPainter) SetGamma(gamma float64)
type Joiner
type JoinerFunc
    func (f JoinerFunc) Join(lhs, rhs Adder, halfWidth fixed.Int26_6, pivot, n0, n1 fixed.Point26_6)
type MonochromePainter
    func NewMonochromePainter(p Painter) *MonochromePainter
    func (m *MonochromePainter) Paint(ss []Span, done bool)
type Painter
type PainterFunc
    func (f PainterFunc) Paint(ss []Span, done bool)
type Path
    func (p *Path) Add1(b fixed.Point26_6)
    func (p *Path) Add2(b, c fixed.Point26_6)
    func (p *Path) Add3(b, c, d fixed.Point26_6)
    func (p *Path) AddPath(q Path)
    func (p *Path) AddStroke(q Path, width fixed.Int26_6, cr Capper, jr Joiner)
    func (p *Path) Clear()
    func (p *Path) Start(a fixed.Point26_6)
    func (p Path) String() string
type RGBAPainter
    func NewRGBAPainter(m *image.RGBA) *RGBAPainter
    func (r *RGBAPainter) Paint(ss []Span, done bool)
    func (r *RGBAPainter) SetColor(c color.Color)
type Rasterizer
    func NewRasterizer(width, height int) *Rasterizer
    func (r *Rasterizer) Add1(b fixed.Point26_6)
    func (r *Rasterizer) Add2(b, c fixed.Point26_6)
    func (r *Rasterizer) Add3(b, c, d fixed.Point26_6)
    func (r *Rasterizer) AddPath(p Path)
    func (r *Rasterizer) AddStroke(q Path, width fixed.Int26_6, cr Capper, jr Joiner)
    func (r *Rasterizer) Clear()
    func (r *Rasterizer) Rasterize(p Painter)
    func (r *Rasterizer) SetBounds(width, height int)
    func (r *Rasterizer) Start(a fixed.Point26_6)
type Span

Package files

geom.go paint.go raster.go stroke.go

func Stroke

func Stroke(p Adder, q Path, width fixed.Int26_6, cr Capper, jr Joiner)

Stroke adds q stroked with the given width to p. The result is typically self-intersecting and should be rasterized with UseNonZeroWinding. cr and jr may be nil, which defaults to a RoundCapper or RoundJoiner.

type Adder

An Adder accumulates points on a curve.

type Adder interface {
    // Start starts a new curve at the given point.
    Start(a fixed.Point26_6)
    // Add1 adds a linear segment to the current curve.
    Add1(b fixed.Point26_6)
    // Add2 adds a quadratic segment to the current curve.
    Add2(b, c fixed.Point26_6)
    // Add3 adds a cubic segment to the current curve.
    Add3(b, c, d fixed.Point26_6)
}

type AlphaOverPainter

An AlphaOverPainter is a Painter that paints Spans onto a *image.Alpha using the Over Porter-Duff composition operator.

type AlphaOverPainter struct {
    Image *image.Alpha
}

func NewAlphaOverPainter

func NewAlphaOverPainter(m *image.Alpha) AlphaOverPainter

NewAlphaOverPainter creates a new AlphaOverPainter for the given image.

func (AlphaOverPainter) Paint

func (r AlphaOverPainter) Paint(ss []Span, done bool)

Paint satisfies the Painter interface.

type AlphaSrcPainter

An AlphaSrcPainter is a Painter that paints Spans onto a *image.Alpha using the Src Porter-Duff composition operator.

type AlphaSrcPainter struct {
    Image *image.Alpha
}

func NewAlphaSrcPainter

func NewAlphaSrcPainter(m *image.Alpha) AlphaSrcPainter

NewAlphaSrcPainter creates a new AlphaSrcPainter for the given image.

func (AlphaSrcPainter) Paint

func (r AlphaSrcPainter) Paint(ss []Span, done bool)

Paint satisfies the Painter interface.

type Capper

A Capper signifies how to begin or end a stroked path.

type Capper interface {
    // Cap adds a cap to p given a pivot point and the normal vector of a
    // terminal segment. The normal's length is half of the stroke width.
    Cap(p Adder, halfWidth fixed.Int26_6, pivot, n1 fixed.Point26_6)
}

ButtCapper adds butt caps to a stroked path.

var ButtCapper Capper = CapperFunc(buttCapper)

RoundCapper adds round caps to a stroked path.

var RoundCapper Capper = CapperFunc(roundCapper)

SquareCapper adds square caps to a stroked path.

var SquareCapper Capper = CapperFunc(squareCapper)

type CapperFunc

The CapperFunc type adapts an ordinary function to be a Capper.

type CapperFunc func(Adder, fixed.Int26_6, fixed.Point26_6, fixed.Point26_6)

func (CapperFunc) Cap

func (f CapperFunc) Cap(p Adder, halfWidth fixed.Int26_6, pivot, n1 fixed.Point26_6)

type GammaCorrectionPainter

A GammaCorrectionPainter wraps another Painter, performing gamma-correction on each Span's alpha value.

type GammaCorrectionPainter struct {
    // Painter is the wrapped Painter.
    Painter Painter
    // contains filtered or unexported fields
}

func NewGammaCorrectionPainter

func NewGammaCorrectionPainter(p Painter, gamma float64) *GammaCorrectionPainter

NewGammaCorrectionPainter creates a new GammaCorrectionPainter that wraps the given Painter.

func (*GammaCorrectionPainter) Paint

func (g *GammaCorrectionPainter) Paint(ss []Span, done bool)

Paint delegates to the wrapped Painter after performing gamma-correction on each Span.

func (*GammaCorrectionPainter) SetGamma

func (g *GammaCorrectionPainter) SetGamma(gamma float64)

SetGamma sets the gamma value.

type Joiner

A Joiner signifies how to join interior nodes of a stroked path.

type Joiner interface {
    // Join adds a join to the two sides of a stroked path given a pivot
    // point and the normal vectors of the trailing and leading segments.
    // Both normals have length equal to half of the stroke width.
    Join(lhs, rhs Adder, halfWidth fixed.Int26_6, pivot, n0, n1 fixed.Point26_6)
}

BevelJoiner adds bevel joins to a stroked path.

var BevelJoiner Joiner = JoinerFunc(bevelJoiner)

RoundJoiner adds round joins to a stroked path.

var RoundJoiner Joiner = JoinerFunc(roundJoiner)

type JoinerFunc

The JoinerFunc type adapts an ordinary function to be a Joiner.

type JoinerFunc func(lhs, rhs Adder, halfWidth fixed.Int26_6, pivot, n0, n1 fixed.Point26_6)

func (JoinerFunc) Join

func (f JoinerFunc) Join(lhs, rhs Adder, halfWidth fixed.Int26_6, pivot, n0, n1 fixed.Point26_6)

type MonochromePainter

A MonochromePainter wraps another Painter, quantizing each Span's alpha to be either fully opaque or fully transparent.

type MonochromePainter struct {
    Painter Painter
    // contains filtered or unexported fields
}

func NewMonochromePainter

func NewMonochromePainter(p Painter) *MonochromePainter

NewMonochromePainter creates a new MonochromePainter that wraps the given Painter.

func (*MonochromePainter) Paint

func (m *MonochromePainter) Paint(ss []Span, done bool)

Paint delegates to the wrapped Painter after quantizing each Span's alpha value and merging adjacent fully opaque Spans.

type Painter

A Painter knows how to paint a batch of Spans. Rasterization may involve Painting multiple batches, and done will be true for the final batch. The Spans' Y values are monotonically increasing during a rasterization. Paint may use all of ss as scratch space during the call.

type Painter interface {
    Paint(ss []Span, done bool)
}

type PainterFunc

The PainterFunc type adapts an ordinary function to the Painter interface.

type PainterFunc func(ss []Span, done bool)

func (PainterFunc) Paint

func (f PainterFunc) Paint(ss []Span, done bool)

Paint just delegates the call to f.

type Path

A Path is a sequence of curves, and a curve is a start point followed by a sequence of linear, quadratic or cubic segments.

type Path []fixed.Int26_6

func (*Path) Add1

func (p *Path) Add1(b fixed.Point26_6)

Add1 adds a linear segment to the current curve.

func (*Path) Add2

func (p *Path) Add2(b, c fixed.Point26_6)

Add2 adds a quadratic segment to the current curve.

func (*Path) Add3

func (p *Path) Add3(b, c, d fixed.Point26_6)

Add3 adds a cubic segment to the current curve.

func (*Path) AddPath

func (p *Path) AddPath(q Path)

AddPath adds the Path q to p.

func (*Path) AddStroke

func (p *Path) AddStroke(q Path, width fixed.Int26_6, cr Capper, jr Joiner)

AddStroke adds a stroked Path.

func (*Path) Clear

func (p *Path) Clear()

Clear cancels any previous calls to p.Start or p.AddXxx.

func (*Path) Start

func (p *Path) Start(a fixed.Point26_6)

Start starts a new curve at the given point.

func (Path) String

func (p Path) String() string

String returns a human-readable representation of a Path.

type RGBAPainter

An RGBAPainter is a Painter that paints Spans onto a *image.RGBA.

type RGBAPainter struct {
    // Image is the image to compose onto.
    Image *image.RGBA
    // Op is the Porter-Duff composition operator.
    Op draw.Op
    // contains filtered or unexported fields
}

func NewRGBAPainter

func NewRGBAPainter(m *image.RGBA) *RGBAPainter

NewRGBAPainter creates a new RGBAPainter for the given image.

func (*RGBAPainter) Paint

func (r *RGBAPainter) Paint(ss []Span, done bool)

Paint satisfies the Painter interface.

func (*RGBAPainter) SetColor

func (r *RGBAPainter) SetColor(c color.Color)

SetColor sets the color to paint the spans.

type Rasterizer

type Rasterizer struct {
    // If false, the default behavior is to use the even-odd winding fill
    // rule during Rasterize.
    UseNonZeroWinding bool
    // An offset (in pixels) to the painted spans.
    Dx, Dy int
    // contains filtered or unexported fields
}

func NewRasterizer

func NewRasterizer(width, height int) *Rasterizer

NewRasterizer creates a new Rasterizer with the given bounds.

func (*Rasterizer) Add1

func (r *Rasterizer) Add1(b fixed.Point26_6)

Add1 adds a linear segment to the current curve.

func (*Rasterizer) Add2

func (r *Rasterizer) Add2(b, c fixed.Point26_6)

Add2 adds a quadratic segment to the current curve.

func (*Rasterizer) Add3

func (r *Rasterizer) Add3(b, c, d fixed.Point26_6)

Add3 adds a cubic segment to the current curve.

func (*Rasterizer) AddPath

func (r *Rasterizer) AddPath(p Path)

AddPath adds the given Path.

func (*Rasterizer) AddStroke

func (r *Rasterizer) AddStroke(q Path, width fixed.Int26_6, cr Capper, jr Joiner)

AddStroke adds a stroked Path.

func (*Rasterizer) Clear

func (r *Rasterizer) Clear()

Clear cancels any previous calls to r.Start or r.AddXxx.

func (*Rasterizer) Rasterize

func (r *Rasterizer) Rasterize(p Painter)

Rasterize converts r's accumulated curves into Spans for p. The Spans passed to p are non-overlapping, and sorted by Y and then X. They all have non-zero width (and 0 <= X0 < X1 <= r.width) and non-zero A, except for the final Span, which has Y, X0, X1 and A all equal to zero.

func (*Rasterizer) SetBounds

func (r *Rasterizer) SetBounds(width, height int)

SetBounds sets the maximum width and height of the rasterized image and calls Clear. The width and height are in pixels, not fixed.Int26_6 units.

func (*Rasterizer) Start

func (r *Rasterizer) Start(a fixed.Point26_6)

Start starts a new curve at the given point.

type Span

A Span is a horizontal segment of pixels with constant alpha. X0 is an inclusive bound and X1 is exclusive, the same as for slices. A fully opaque Span has Alpha == 0xffff.

type Span struct {
    Y, X0, X1 int
    Alpha     uint32
}