Module: graphics.backend.software

Source: ./graphics/backend/software.reef


Overview

graphics/backend/software.reef - Pure Reef software rasterizer Part of reef-stdlib graphics module

Implements scanline-based rasterization for path filling and stroking. This is a CPU-only renderer that works on any platform.


Types

Edge

Edge represents one edge of a polygon for scanline rasterization

Fields:

Name Type
y_min int
y_max int
x float
inv_slope float
direction int

Intersection

Intersection point for scanline

Fields:

Name Type
x float
direction int

Functions

fn build_edge_table(p: path.Path, t: transform.Transform): [Edge]

Build edge table from path commands

fn make_edge(x0: float, y0: float, x1: float, y1: float): Edge

Create an edge from two points

fn flatten_quad(edges: [Edge], start_idx: int, max_edges: int, x0: float, y0: float, cx: float, cy: float, x1: float, y1: float): int

Flatten quadratic bezier to line segments

fn flatten_cubic(edges: [Edge], start_idx: int, max_edges: int, x0: float, y0: float, c1x: float, c1y: float, c2x: float, c2y: float, x1: float, y1: float): int

Flatten cubic bezier to line segments

fn find_scanline_intersections(edges: [Edge], edge_count: int, y: int): [Intersection]

Find all x intersections for a given scanline y

fn get_paint_color(pnt: paint.Paint, bounds: core.Rect): core.Color

Get color from paint (simplified - only handles solid colors)

fn point_near_line_segment(px: float, py: float, x0: float, y0: float, x1: float, y1: float, dist: float): bool

Check if point is within distance of line segment

fn fpart(x: float): float

Fractional part of float

fn clamp_to_byte(v: int): uint8

Clamp int to byte range and convert


Procedures

proc rasterize_fill(s: surface.Surface, p: path.Path, pnt: paint.Paint, t: transform.Transform, rule: surface.FillRule)

proc sort_intersections(ints: [Intersection], count: int)

Simple bubble sort for intersections

proc fill_spans_even_odd(s: surface.Surface, y: int, ints: [Intersection], count: int, c: core.Color)

Fill spans using even-odd rule

proc fill_spans_non_zero(s: surface.Surface, y: int, ints: [Intersection], count: int, c: core.Color)

Fill spans using non-zero winding rule

proc fill_span(s: surface.Surface, y: int, x0: int, x1: int, c: core.Color)

Fill a horizontal span

proc rasterize_stroke(s: surface.Surface, p: path.Path, pnt: paint.Paint, style: paint.StrokeStyle, t: transform.Transform)

proc stroke_line(s: surface.Surface, x0: float, y0: float, x1: float, y1: float, width: float, c: core.Color)

Stroke a line segment with given width

proc draw_thick_line(s: surface.Surface, x0: float, y0: float, x1: float, y1: float, width: float, c: core.Color)

Draw a thick line as a filled quad

proc stroke_quad(s: surface.Surface, x0: float, y0: float, cx: float, cy: float, x1: float, y1: float, width: float, c: core.Color)

Stroke a quadratic bezier

proc stroke_cubic(s: surface.Surface, x0: float, y0: float, c1x: float, c1y: float, c2x: float, c2y: float, x1: float, y1: float, width: float, c: core.Color)

Stroke a cubic bezier

proc draw_line(s: surface.Surface, x0: int, y0: int, x1: int, y1: int, c: core.Color)

proc draw_line_aa(s: surface.Surface, x0: float, y0: float, x1: float, y1: float, c: core.Color)

proc plot_aa(s: surface.Surface, x: int, y: int, c: core.Color, brightness: float)

Plot pixel with alpha for anti-aliasing

proc draw_circle(s: surface.Surface, cx: int, cy: int, radius: int, c: core.Color)

proc fill_circle(s: surface.Surface, cx: int, cy: int, radius: int, c: core.Color)

proc draw_ellipse(s: surface.Surface, cx: int, cy: int, rx: int, ry: int, c: core.Color)

proc fill_ellipse(s: surface.Surface, cx: int, cy: int, rx: int, ry: int, c: core.Color)


Generated by reefc doc