Skip to main content

Crate dinamika_cpu

Crate dinamika_cpu 

Source
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 another Pixmap on 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 fillable Path; Pixmap::fill_text draws 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 paint module).
  • 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 stroke module).
  • Text layout is minimal. Font places glyphs by their horizontal advance only — no kerning, shaping or bidi (see the text module).

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.
ConicGradient
A conic (sweep) gradient: the color changes by angle around the center.
Font
A parsed TrueType/OpenType font face.
GradientStop
A gradient stop.
LinearGradient
A linear gradient along the segment startend.
Mask
A clipping mask: width × height coverage values 0..=255.
Paint
A fill description: the color source, blend mode and anti-aliasing.
Path
An immutable set of contours.
PathBuilder
A path builder.
Pattern
A texture shader: fills with a Pixmap image with tiling and a transformation. The basis for sprites, backgrounds and patterns.
Pixmap
Bitmap: width × height RGBA pixels, premultiplied alpha.
Point
A point (or vector) in the plane.
PremultipliedColor
A premultiplied floating-point color (RGB already multiplied by alpha).
PremultipliedColorU8
An 8-bit premultiplied RGBA color — the pixel storage format.
RadialGradient
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§

BlendMode
Blend mode of the source and the background.
FillRule
Fill rule.
FilterQuality
Interpolation quality when sampling a Pattern texture.
FontError
An error returned while loading a Font.
LineCap
The shape of the ends of open lines.
LineJoin
The shape of a join between segments.
PathSegment
A contour command.
Shader
A color source.
SpreadMode
How coordinates outside 0..=1 are handled for a gradient.