Documentation
¶
Overview ¶
Package raster provides scanline rasterization for 2D paths. This file implements AlphaRuns for RLE-encoded alpha (coverage) values. Based on tiny-skia's alpha_runs.rs (Android/Skia heritage).
Package raster provides scanline rasterization for 2D paths.
Package raster provides scanline rasterization for 2D paths. This file implements anti-aliased filling using 4x supersampling.
Package raster provides scanline rasterization for 2D paths. This file implements SuperBlitter for anti-aliased rendering via 4x supersampling. Based on tiny-skia's path_aa.rs (Android/Skia heritage).
Index ¶
- Constants
- func CatchOverflow(alpha uint16) uint8
- type AAPixmap
- type AAPixmapAdapter
- type AAPixmapBatch
- type ActiveEdge
- type ActiveEdgeTable
- func (aet *ActiveEdgeTable) Add(edge Edge)
- func (aet *ActiveEdgeTable) AddAtY(edge Edge, y float64)
- func (aet *ActiveEdgeTable) Clear()
- func (aet *ActiveEdgeTable) Edges() []ActiveEdge
- func (aet *ActiveEdgeTable) Remove(y float64)
- func (aet *ActiveEdgeTable) Sort()
- func (aet *ActiveEdgeTable) Update()
- type AlphaRuns
- type Blitter
- type Edge
- type FillRule
- type Pixmap
- type Point
- type RGBA
- type Rasterizer
- type SpanFiller
- type SuperBlitter
Constants ¶
const SupersampleMask = SupersampleScale - 1
SupersampleMask is used to extract subpixel coordinates.
const SupersampleScale = 1 << SupersampleShift
SupersampleScale is the number of subpixels per pixel (4 for 2-bit shift).
const SupersampleShift = 2
SupersampleShift controls supersampling level: 2 means 4x (1 << 2 = 4).
Variables ¶
This section is empty.
Functions ¶
func CatchOverflow ¶ added in v0.19.0
CatchOverflow converts 0-256 to 0-255 safely. Input value 256 maps to 255 (handles overflow from accumulation).
Types ¶
type AAPixmap ¶ added in v0.19.0
type AAPixmap interface {
Pixmap
// BlendPixelAlpha blends a color with the existing pixel using given alpha.
// alpha is in range 0-255.
BlendPixelAlpha(x, y int, c RGBA, alpha uint8)
}
AAPixmap extends Pixmap with alpha-blended pixel writing.
type AAPixmapAdapter ¶ added in v0.19.0
type AAPixmapAdapter struct {
Pixmap Pixmap
}
AAPixmapAdapter wraps a basic Pixmap to provide BlendPixelAlpha for AA rendering. This allows non-AA pixmaps to work with the AA rasterizer.
func (*AAPixmapAdapter) BlendPixelAlpha ¶ added in v0.19.0
func (a *AAPixmapAdapter) BlendPixelAlpha(x, y int, c RGBA, alpha uint8)
BlendPixelAlpha blends a color with the existing pixel using given alpha. This is a simple implementation that uses alpha to modulate the color.
func (*AAPixmapAdapter) Height ¶ added in v0.19.0
func (a *AAPixmapAdapter) Height() int
Height returns the height of the pixmap.
func (*AAPixmapAdapter) SetPixel ¶ added in v0.19.0
func (a *AAPixmapAdapter) SetPixel(x, y int, c RGBA)
SetPixel sets a pixel color.
func (*AAPixmapAdapter) Width ¶ added in v0.19.0
func (a *AAPixmapAdapter) Width() int
Width returns the width of the pixmap.
type AAPixmapBatch ¶ added in v0.19.0
type AAPixmapBatch interface {
AAPixmap
// BlendSpanAlpha blends a solid color over a horizontal span with constant alpha.
// Parameters:
// - x, y: starting pixel coordinates
// - count: number of pixels to blend
// - r, g, b, a: source color (premultiplied alpha, 0-255)
// - alpha: coverage alpha (0-255)
BlendSpanAlpha(x, y, count int, r, g, b, a, alpha uint8)
}
AAPixmapBatch is an optional interface for pixmaps that support batch AA blending. Pixmaps implementing this interface can benefit from SIMD-optimized processing for runs of 16+ pixels with the same coverage alpha.
type ActiveEdge ¶
type ActiveEdge struct {
// contains filtered or unexported fields
}
ActiveEdge is an edge being processed by the rasterizer.
type ActiveEdgeTable ¶
type ActiveEdgeTable struct {
// contains filtered or unexported fields
}
ActiveEdgeTable represents edges active at a scanline.
func NewActiveEdgeTable ¶
func NewActiveEdgeTable() *ActiveEdgeTable
NewActiveEdgeTable creates a new active edge table.
func (*ActiveEdgeTable) Add ¶
func (aet *ActiveEdgeTable) Add(edge Edge)
Add adds an edge to the active edge table.
func (*ActiveEdgeTable) AddAtY ¶ added in v0.19.0
func (aet *ActiveEdgeTable) AddAtY(edge Edge, y float64)
AddAtY adds an edge to the active edge table with x computed for the given y.
func (*ActiveEdgeTable) Edges ¶
func (aet *ActiveEdgeTable) Edges() []ActiveEdge
Edges returns the active edges.
func (*ActiveEdgeTable) Remove ¶
func (aet *ActiveEdgeTable) Remove(y float64)
Remove removes inactive edges for the given scanline.
func (*ActiveEdgeTable) Sort ¶
func (aet *ActiveEdgeTable) Sort()
Sort sorts edges by x coordinate (insertion sort for small lists).
func (*ActiveEdgeTable) Update ¶
func (aet *ActiveEdgeTable) Update()
Update updates x positions for the next scanline.
type AlphaRuns ¶ added in v0.19.0
type AlphaRuns struct {
// contains filtered or unexported fields
}
AlphaRuns stores run-length-encoded alpha (supersampling coverage) values. Sparseness allows independent composition of several paths into the same buffer.
func NewAlphaRuns ¶ added in v0.19.0
NewAlphaRuns creates a new AlphaRuns buffer for the given width.
func (*AlphaRuns) Add ¶ added in v0.19.0
func (ar *AlphaRuns) Add(x int, startAlpha uint8, middleCount int, stopAlpha uint8, maxValue uint8, offsetX int) int
Add inserts a run into the buffer. Parameters:
- x: starting x coordinate
- startAlpha: alpha for first pixel (if non-zero)
- middleCount: number of full-coverage pixels
- stopAlpha: alpha for last pixel (if non-zero)
- maxValue: maximum alpha value for middle pixels
- offsetX: hint for where to start searching in runs array
Returns the new offsetX value for the next call on the same scanline.
func (*AlphaRuns) IsEmpty ¶ added in v0.19.0
IsEmpty returns true if the scanline contains only a single run of alpha 0.
type Blitter ¶ added in v0.19.0
type Blitter interface {
// BlitH blits a horizontal span at supersampled coordinates.
BlitH(x, y uint32, width int)
}
Blitter is an interface for receiving horizontal spans.
type Edge ¶
type Edge struct {
// contains filtered or unexported fields
}
Edge represents a line segment for scanline rasterization.
type FillRule ¶
type FillRule int
FillRule specifies how to determine which areas are inside a path.
type Point ¶
type Point struct {
X, Y float64
}
Point represents a 2D point (internal copy to avoid import cycle).
type RGBA ¶
type RGBA struct {
R, G, B, A float64
}
RGBA represents a color (internal copy to avoid import cycle).
type Rasterizer ¶
type Rasterizer struct {
// contains filtered or unexported fields
}
Rasterizer performs scanline rasterization.
func NewRasterizer ¶
func NewRasterizer(width, height int) *Rasterizer
NewRasterizer creates a new rasterizer for the given dimensions.
func (*Rasterizer) Fill ¶
func (r *Rasterizer) Fill(pixmap Pixmap, points []Point, fillRule FillRule, color RGBA)
Fill rasterizes a filled path onto a pixmap.
type SpanFiller ¶ added in v0.5.0
SpanFiller is an optional interface that pixmaps can implement for optimized span filling.
type SuperBlitter ¶ added in v0.19.0
type SuperBlitter struct {
// contains filtered or unexported fields
}
SuperBlitter accumulates supersampled coverage and blits AA pixels.
func NewSuperBlitter ¶ added in v0.19.0
func NewSuperBlitter( pixmap AAPixmap, color RGBA, boundsLeft, boundsTop, boundsRight, boundsBottom int, clipLeft, clipTop, clipRight, clipBottom int, ) *SuperBlitter
NewSuperBlitter creates a new SuperBlitter for AA rendering. bounds defines the pixel-space bounding box of the path. clipLeft, clipTop, clipRight, clipBottom define the clipping region.
func (*SuperBlitter) BlitH ¶ added in v0.19.0
func (sb *SuperBlitter) BlitH(x, y uint32, width int)
BlitH implements Blitter interface for receiving supersampled spans.
func (*SuperBlitter) Flush ¶ added in v0.19.0
func (sb *SuperBlitter) Flush()
Flush writes the accumulated coverage to the pixmap.