Documentation ¶
Overview ¶
The raster package provides an anti-aliasing 2-D rasterizer.
It is part of the larger Freetype-Go suite of font-related packages, but the raster package is not specific to font rasterization, and can be used standalone without any other Freetype-Go 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 Fix32, cr Capper, jr Joiner)
- type Adder
- type AlphaOverPainter
- type AlphaSrcPainter
- type Capper
- type CapperFunc
- type Fix32
- type Fix64
- type GammaCorrectionPainter
- type Joiner
- type JoinerFunc
- type MonochromePainter
- type Painter
- type PainterFunc
- type Path
- type Point
- func (p Point) Add(q Point) Point
- func (p Point) Dot(q Point) Fix64
- func (p Point) Len() Fix32
- func (p Point) Mul(k Fix32) Point
- func (p Point) Neg() Point
- func (p Point) Norm(length Fix32) Point
- func (p Point) Rot135CCW() Point
- func (p Point) Rot135CW() Point
- func (p Point) Rot45CCW() Point
- func (p Point) Rot45CW() Point
- func (p Point) Rot90CCW() Point
- func (p Point) Rot90CW() Point
- func (p Point) String() string
- func (p Point) Sub(q Point) Point
- type RGBAPainter
- type Rasterizer
- func (r *Rasterizer) Add1(b Point)
- func (r *Rasterizer) Add2(b, c Point)
- func (r *Rasterizer) Add3(b, c, d Point)
- func (r *Rasterizer) AddPath(p Path)
- func (r *Rasterizer) AddStroke(q Path, width Fix32, 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 Point)
- type Span
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Adder ¶
type Adder interface { // Start starts a new curve at the given point. Start(a Point) // Add1 adds a linear segment to the current curve. Add1(b Point) // Add2 adds a quadratic segment to the current curve. Add2(b, c Point) // Add3 adds a cubic segment to the current curve. Add3(b, c, d Point) }
An Adder accumulates points on a curve.
type AlphaOverPainter ¶
An AlphaOverPainter is a Painter that paints Spans onto an image.Alpha using the Over Porter-Duff composition operator.
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 by painting ss onto an image.Alpha.
type AlphaSrcPainter ¶
An AlphaSrcPainter is a Painter that paints Spans onto an image.Alpha using the Src Porter-Duff composition operator.
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 by painting ss onto an image.Alpha.
type Capper ¶
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 Fix32, pivot, n1 Point) }
A Capper signifies how to begin or end a stroked path.
var ButtCapper Capper = CapperFunc(buttCapper)
ButtCapper adds butt caps to a stroked path.
var RoundCapper Capper = CapperFunc(roundCapper)
RoundCapper adds round caps to a stroked path.
var SquareCapper Capper = CapperFunc(squareCapper)
SquareCapper adds square caps to a stroked path.
type CapperFunc ¶
The CapperFunc type adapts an ordinary function to be a Capper.
type GammaCorrectionPainter ¶
type GammaCorrectionPainter struct { // The wrapped Painter. Painter Painter // contains filtered or unexported fields }
A GammaCorrectionPainter wraps another Painter, performing gamma-correction on each Span's alpha value.
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 ¶
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 Fix32, pivot, n0, n1 Point) }
A Joiner signifies how to join interior nodes of a stroked path.
var BevelJoiner Joiner = JoinerFunc(bevelJoiner)
BevelJoiner adds bevel joins to a stroked path.
var RoundJoiner Joiner = JoinerFunc(roundJoiner)
RoundJoiner adds round joins to a stroked path.
type JoinerFunc ¶
The JoinerFunc type adapts an ordinary function to be a Joiner.
type MonochromePainter ¶
type MonochromePainter struct { Painter Painter // contains filtered or unexported fields }
A MonochromePainter wraps another Painter, quantizing each Span's alpha to be either fully opaque or fully transparent.
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 PainterFunc ¶
The PainterFunc type adapts an ordinary function to the Painter interface.
func (PainterFunc) Paint ¶
func (f PainterFunc) Paint(ss []Span, done bool)
Paint just delegates the call to f.
type Path ¶
type Path []Fix32
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 Point ¶
type Point struct {
X, Y Fix32
}
A Point represents a two-dimensional point or vector, in 24.8 fixed point format.
func (Point) Norm ¶
Norm returns the vector p normalized to the given length, or the zero Point if p is degenerate.
func (Point) Rot135CCW ¶
Rot135CCW returns the vector p rotated counter-clockwise by 135 degrees. Note that the Y-axis grows downwards, so {1, 0}.Rot135CCW is {-1/√2, -1/√2}.
func (Point) Rot135CW ¶
Rot135CW returns the vector p rotated clockwise by 135 degrees. Note that the Y-axis grows downwards, so {1, 0}.Rot135CW is {-1/√2, 1/√2}.
func (Point) Rot45CCW ¶
Rot45CCW returns the vector p rotated counter-clockwise by 45 degrees. Note that the Y-axis grows downwards, so {1, 0}.Rot45CCW is {1/√2, -1/√2}.
func (Point) Rot45CW ¶
Rot45CW returns the vector p rotated clockwise by 45 degrees. Note that the Y-axis grows downwards, so {1, 0}.Rot45CW is {1/√2, 1/√2}.
func (Point) Rot90CCW ¶
Rot90CCW returns the vector p rotated counter-clockwise by 90 degrees. Note that the Y-axis grows downwards, so {1, 0}.Rot90CCW is {0, -1}.
func (Point) Rot90CW ¶
Rot90CW returns the vector p rotated clockwise by 90 degrees. Note that the Y-axis grows downwards, so {1, 0}.Rot90CW is {0, 1}.
type RGBAPainter ¶
type RGBAPainter struct { // The image to compose onto. Image *image.RGBA // 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 by painting ss onto an image.RGBA.
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 Point)
Add1 adds a linear segment to the current curve.
func (*Rasterizer) Add2 ¶
func (r *Rasterizer) Add2(b, c Point)
Add2 adds a quadratic segment to the current curve.
func (*Rasterizer) Add3 ¶
func (r *Rasterizer) Add3(b, c, d Point)
Add3 adds a cubic segment to the current curve.
func (*Rasterizer) AddStroke ¶
func (r *Rasterizer) AddStroke(q Path, width Fix32, 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 Fix32 units.
func (*Rasterizer) Start ¶
func (r *Rasterizer) Start(a Point)
Start starts a new curve at the given point.