Expand description
dinamika-cpu — a raster 2D renderer on the CPU.
Creating images, building vector contours, anti-aliased fill and stroke,
gradients and blend modes. The only external dependency is the
png crate for saving frames.
§Main types
Pixmap— a pixel buffer (premultiplied RGBA) and the entry point for drawing. It can composite anotherPixmapon top of itself (Pixmap::draw_pixmap) and decode PNG (Pixmap::decode_png).Path/PathBuilder— vector contours with Bézier curves; there are ready-made rectangle, rounded rectangle, ellipse and circle.Paint— a brush: color/gradient/texture (Shader), blend mode (BlendMode), anti-aliasing.Shader— a color source: solid, linear/radial/conic gradient or texture (Pattern).Stroke— stroke parameters (width, caps, joins, dashes, “hairline”).Mask— a clipping mask (overflow: hidden).Transform— an affine transformation.Font— a TrueType/OpenType face (ttf-parser) that turns text into a fillablePath;Pixmap::fill_textdraws it in one call.
§Example
use dinamika_cpu::*;
let mut pixmap = Pixmap::new(200, 200).unwrap();
pixmap.fill(Color::WHITE);
let path = PathBuilder::from_circle(100.0, 100.0, 80.0).unwrap();
let paint = Paint::from_color(Color::from_rgba8(220, 40, 90, 255));
pixmap.fill_path(&path, &paint, FillRule::NonZero, Transform::identity(), None);
// The ready pixels (premultiplied RGBA) live in `pixmap.data()`.
assert_eq!(pixmap.data().len(), 200 * 200 * 4);§Known limitations
Deliberate trade-offs for the sake of MVP simplicity (details are in the documentation of the respective modules):
- Color is computed in sRGB, not in linear light. Blending and
gradient interpolation operate directly on the gamma components — as in
most 8-bit engines. Gradients are slightly “dirtier”, semi-transparent
edges darken a little (see the
paintmodule). - Stroke width is isotropic. Under non-uniform scaling or shearing the
stroke comes out circular rather than elliptical (see
Pixmap::stroke_path). - Thin AA seams are possible at the junctions of stroke stamps
(segment↔join); acceptable for an MVP (see the
strokemodule). - Text layout is minimal.
Fontplaces glyphs by their horizontal advance only — no kerning, shaping or bidi (see thetextmodule).
Structs§
- Color
- A color in floating-point RGBA format in the range
0.0..=1.0, non-premultiplied alpha. - ColorU8
- An 8-bit non-premultiplied RGBA color.
- Conic
Gradient - A conic (sweep) gradient: the color changes by angle around the center.
- Font
- A parsed TrueType/OpenType font face.
- Gradient
Stop - A gradient stop.
- Linear
Gradient - A linear gradient along the segment
start–end. - Mask
- A clipping mask:
width × heightcoverage values0..=255. - Paint
- A fill description: the color source, blend mode and anti-aliasing.
- Path
- An immutable set of contours.
- Path
Builder - A path builder.
- Pattern
- A texture shader: fills with a
Pixmapimage with tiling and a transformation. The basis for sprites, backgrounds and patterns. - Pixmap
- Bitmap:
width × heightRGBA pixels, premultiplied alpha. - Point
- A point (or vector) in the plane.
- Premultiplied
Color - A premultiplied floating-point color (RGB already multiplied by alpha).
- Premultiplied
Color U8 - An 8-bit premultiplied RGBA color — the pixel storage format.
- Radial
Gradient - A radial gradient around a center.
- Rect
- A rectangle defined by its bounds in floating-point coordinates.
- Stroke
- Stroke parameters.
- Transform
- A 2×3 affine transformation.
Enums§
- Blend
Mode - Blend mode of the source and the background.
- Fill
Rule - Fill rule.
- Filter
Quality - Interpolation quality when sampling a
Patterntexture. - Font
Error - An error returned while loading a
Font. - LineCap
- The shape of the ends of open lines.
- Line
Join - The shape of a join between segments.
- Path
Segment - A contour command.
- Shader
- A color source.
- Spread
Mode - How coordinates outside
0..=1are handled for a gradient.