Documentation ¶
Overview ¶
Package scan provides an anti-aliasing 2-D rasterizer, which is based on 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 ¶
- type BaseSpanner
- type Cell
- type ImgSpanner
- func (x *ImgSpanner) GetSpanFunc() SpanFunc
- func (x *ImgSpanner) SetColor(c image.Image)
- func (x *ImgSpanner) SetImage(img *image.RGBA)
- func (x *ImgSpanner) SpanColorFunc(yi, xi0, xi1 int, ma uint32)
- func (x *ImgSpanner) SpanColorFuncR(yi, xi0, xi1 int, ma uint32)
- func (x *ImgSpanner) SpanFgColor(yi, xi0, xi1 int, ma uint32)
- func (x *ImgSpanner) SpanFgColorR(yi, xi0, xi1 int, ma uint32)
- type LinkListSpanner
- func (x *LinkListSpanner) AddLink(x0, x1, next, pp int, underColor color.RGBA, alpha uint32) (p int)
- func (x *LinkListSpanner) BlendColor(under color.RGBA, ma uint32) color.RGBA
- func (x *LinkListSpanner) Clear()
- func (x *LinkListSpanner) DrawToImage(img image.Image)
- func (x *LinkListSpanner) GetSpanFunc() SpanFunc
- func (x *LinkListSpanner) SetBgColor(c image.Image)
- func (x *LinkListSpanner) SetBounds(bounds image.Rectangle)
- func (x *LinkListSpanner) SetColor(c image.Image)
- func (x *LinkListSpanner) SpanOver(yi, xi0, xi1 int, ma uint32)
- func (x *LinkListSpanner) SpansToImage(img draw.Image)
- func (x *LinkListSpanner) SpansToPix(pix []uint8, stride int)
- type Scanner
- func (s *Scanner) AreaToAlpha(area int) uint32
- func (s *Scanner) Clear()
- func (s *Scanner) Draw()
- func (s *Scanner) FindCell() int
- func (s *Scanner) GetPathExtent() fixed.Rectangle26_6
- func (s *Scanner) Line(b fixed.Point26_6)
- func (s *Scanner) SaveCell()
- func (s *Scanner) Scan(yi int, x0, y0f, x1, y1f fixed.Int26_6)
- func (s *Scanner) Set(a fixed.Point26_6)
- func (s *Scanner) SetBounds(width, height int)
- func (s *Scanner) SetCell(xi, yi int)
- func (s *Scanner) SetClip(r image.Rectangle)
- func (s *Scanner) SetColor(clr image.Image)
- func (s *Scanner) SetWinding(useNonZeroWinding bool)
- func (s *Scanner) Start(a fixed.Point26_6)
- type SpanCell
- type SpanFunc
- type Spanner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseSpanner ¶
type BaseSpanner struct { // drawing is done with Bounds.Min as the origin Bounds image.Rectangle // Op is how pixels are overlayed Op draw.Op FgColor color.RGBA }
BaseSpanner contains base spanner information extended by ImgSpanner and LinkListSpanner.
type Cell ¶
Cell is part of a linked list (for a given yi co-ordinate) of accumulated area/coverage for the pixel at (xi, yi).
type ImgSpanner ¶
type ImgSpanner struct { BaseSpanner Pix []uint8 Stride int ColorImage image.Image }
ImgSpanner is a Spanner that draws Spans onto an *image.RGBA image. It uses either a color function as a the color source, or a fgColor if colFunc is nil.
func NewImgSpanner ¶
func NewImgSpanner(img *image.RGBA) (x *ImgSpanner)
NewImgSpanner returns an ImgSpanner set to draw to the given *image.RGBA.
func (*ImgSpanner) GetSpanFunc ¶
func (x *ImgSpanner) GetSpanFunc() SpanFunc
GetSpanFunc returns the function that consumes a span described by the parameters. The next four func declarations are all slightly different but in order to reduce code redundancy, this method is used to dispatch the function in the draw method.
func (*ImgSpanner) SetColor ¶
func (x *ImgSpanner) SetColor(c image.Image)
SetColor sets the color of x to the given color image
func (*ImgSpanner) SetImage ¶
func (x *ImgSpanner) SetImage(img *image.RGBA)
SetImage set the *image.RGBA that the ImgSpanner will draw onto.
func (*ImgSpanner) SpanColorFunc ¶
func (x *ImgSpanner) SpanColorFunc(yi, xi0, xi1 int, ma uint32)
SpanColorFunc draws the span using a colorFunc and the Porter-Duff composition operator.
func (*ImgSpanner) SpanColorFuncR ¶
func (x *ImgSpanner) SpanColorFuncR(yi, xi0, xi1 int, ma uint32)
SpanColorFuncR draw the span using a colorFunc and replaces the previous values.
func (*ImgSpanner) SpanFgColor ¶
func (x *ImgSpanner) SpanFgColor(yi, xi0, xi1 int, ma uint32)
SpanFgColor draw the span using the fore ground color and the Porter-Duff composition operator.
func (*ImgSpanner) SpanFgColorR ¶
func (x *ImgSpanner) SpanFgColorR(yi, xi0, xi1 int, ma uint32)
SpanFgColorR draws the span with the fore ground color and replaces the previous values.
type LinkListSpanner ¶
LinkListSpanner is a Spanner that draws Spans onto a draw.Image interface satisfying struct but it is optimized for *image.RGBA. It uses a solid Color only for fg and bg and does not support a color function used by gradients. Spans are accumulated into a set of linked lists, one for every horizontal line in the image. After the spans for the image are accumulated, use the DrawToImage function to write the spans to an image.
func (*LinkListSpanner) BlendColor ¶
func (*LinkListSpanner) DrawToImage ¶
func (x *LinkListSpanner) DrawToImage(img image.Image)
DrawToImage draws the accumulated y spans onto the img
func (*LinkListSpanner) GetSpanFunc ¶
func (x *LinkListSpanner) GetSpanFunc() SpanFunc
GetSpanFunc returns the function that consumes a span described by the parameters.
func (*LinkListSpanner) SetBgColor ¶
func (x *LinkListSpanner) SetBgColor(c image.Image)
SetBgColor sets the background color for blending to the first pixel of the given color
func (*LinkListSpanner) SetBounds ¶
func (x *LinkListSpanner) SetBounds(bounds image.Rectangle)
SetBounds sets the spanner boundaries
func (*LinkListSpanner) SetColor ¶
func (x *LinkListSpanner) SetColor(c image.Image)
SetColor sets the color of x to the first pixel of the given color
func (*LinkListSpanner) SpanOver ¶
func (x *LinkListSpanner) SpanOver(yi, xi0, xi1 int, ma uint32)
SpanOver adds the span into an array of linked lists of spans using the fgColor and Porter-Duff composition ma is the accumulated alpha coverage. This function also assumes usage sorted x inputs for each y and so if inputs for x in y are not monotonically increasing, then lastY should be set to -1.
func (*LinkListSpanner) SpansToImage ¶
func (x *LinkListSpanner) SpansToImage(img draw.Image)
func (*LinkListSpanner) SpansToPix ¶
func (x *LinkListSpanner) SpansToPix(pix []uint8, stride int)
type Scanner ¶
type Scanner struct { // If false, the behavior is to use the even-odd winding fill // rule during Rasterize. UseNonZeroWinding bool // The Width of the Rasterizer. The height is implicit in len(cellIndex). Width int // The current pen position. A fixed.Point26_6 // The current cell and its area/coverage being accumulated. Xi, Yi int Area int Cover int // The clip bounds of the scanner Clip image.Rectangle // The saved cells. Cell []Cell // Linked list of cells, one per row. CellIndex []int // The spanner that we use. Spanner Spanner // The bounds. MinX, MinY, MaxX, MaxY fixed.Int26_6 }
Scanner is a refactored version of the freetype scanner
func NewScanner ¶
NewScanner creates a new Scanner with the given bounds.
func (*Scanner) AreaToAlpha ¶
AreaToAlpha converts an area value to a uint32 alpha value. A completely filled pixel corresponds to an area of 64*64*2, and an alpha of 0xffff. The conversion of area values greater than this depends on the winding rule: even-odd or non-zero.
func (*Scanner) Draw ¶
func (s *Scanner) Draw()
Draw converts r's accumulated curves into Spans for p. The Spans passed to the spanner 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 (*Scanner) FindCell ¶
FindCell returns the index in [Scanner.Cell] for the cell corresponding to (r.xi, r.yi). The cell is created if necessary.
func (*Scanner) GetPathExtent ¶
func (s *Scanner) GetPathExtent() fixed.Rectangle26_6
GetPathExtent returns the bounds of the accumulated path extent
func (*Scanner) SaveCell ¶
func (s *Scanner) SaveCell()
SaveCell saves any accumulated [Scanner.Area] or [Scanner.Cover] for ([Scanner.Xi], [Scanner.Yi]).
func (*Scanner) Scan ¶
Scan accumulates area/coverage for the yi'th scanline, going from x0 to x1 in the horizontal direction (in 26.6 fixed point co-ordinates) and from y0f to y1f fractional vertical units within that scanline.
func (*Scanner) SetBounds ¶
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 (*Scanner) SetClip ¶
SetClip will not affect accumulation of scans, but it will clip drawing of the spans int the Draw func by the clip rectangle.
func (*Scanner) SetWinding ¶
SetWinding set the winding rule for the polygons