dinamika-cpu
A raster 2D renderer on the CPU.
The only dependencies are png (saving frames) and
ttf-parser (reading glyph outlines for text).
Features
Pixmap— a pixel buffer in premultiplied RGBA format.Path/PathBuilder— vector contours with straight, quadratic and cubic Bézier curves; ready-made shapes (rectangle, ellipse, circle).Paint/Shader— solid color, linear and radial gradients (withPad/Repeat/Reflectmodes).BlendMode— Porter–Duff modes (SourceOver,Xor,Plus, …) and non-separable ones (Multiply,Screen,Overlay,Darken,Lighten,HardLight).- Fill by
NonZeroandEvenOddrules with anti-aliasing. - Stroke (
Stroke) withButt/Round/Squarecaps andMiter/Round/Beveljoins. Transform— affine transformations (translation, scale, rotation, inversion).- Text (
Font) — TrueType/OpenType glyph outlines viattf-parser, turned into a fillablePath(Font::text_path) or drawn directly withPixmap::fill_text. Minimal horizontal layout: advance widths and\nline breaks, no kerning or shaping.
Architecture
| Module | Purpose |
|---|---|
geom |
Point, Rect, Transform |
color |
non-premultiplied and premultiplied colors, conversions |
path |
contours and flattening of curves into polylines |
paint |
shaders, gradients, blending |
stroke |
building strokes from convex "stamps" |
raster |
anti-aliased rasterizer (cover/area accumulation, as in AGG) |
pixmap |
pixel buffer, fill/stroke, blending |
text |
font loading (ttf-parser), glyph outlines and string layout |
Example
use *;
let mut pixmap = new.unwrap;
pixmap.fill;
let path = from_circle.unwrap;
let paint = from_color;
pixmap.fill_path;
// The ready pixels (premultiplied RGBA) are in `pixmap.data()`.
let pixels = pixmap.data;
Text
use *;
let data = read?;
let font = from_slice?;
let mut pixmap = new.unwrap;
pixmap.fill;
let paint = from_color;
// Baseline origin at (16, 80), em size 48px.
pixmap.fill_text;
The demonstration scene can be rendered with the command:
cargo run -p dinamika