tiny-skia-cpp
A C++20 2D rendering library (port of tiny-skia)
Loading...
Searching...
No Matches
tiny-skia-cpp

A fast, minimal CPU-only 2D rendering library for C++20 — a faithful port of tiny-skia, which implements a subset of Skia's rendering algorithms in Rust.

tiny-skia-cpp brings the same proven rasterization and blending algorithms to C++ with native SIMD acceleration and zero external dependencies.

  • High fidelity — near-pixel-accurate output validated against Rust tiny-skia with tolerance-based golden-image tests
  • Fast — up to 1.9× faster than the Rust implementation with SIMD
  • SIMD accelerated — native backends for x86-64 (AVX2+FMA) and ARM64 (NEON)
  • Tiny & fast to build — minimal codebase, zero external dependencies
  • Embeddable — two static libraries, zero runtime dependencies
  • Skia algorithms — same rasterization, scanline, and blending algorithms as Google's Skia

Performance

Speedup vs Rust tiny-skia on 512×512 px workloads (higher is better):

Workload C++ SIMD (ARM) C++ SIMD (x86) Rust (tiny-skia)
FillRect 1.9× 1.3× 1.0×
FillPath 1.4× 1.2× 1.0×

SIMD speedup over C++ Scalar: up to 2.3× (x86 AVX2) / 1.9× (ARM NEON).

Quick start

using namespace tiny_skia;
// Create a 500×500 RGBA pixmap (transparent black).
auto pixmap = Pixmap::fromSize(500, 500).value();
Canvas canvas(pixmap);
// Build a triangle path.
pb.moveTo(250, 50);
pb.lineTo(450, 400);
pb.lineTo(50, 400);
pb.close();
auto path = pb.finish().value();
// Fill with a semi-transparent green.
Paint paint;
paint.setColorRgba8(0, 200, 80, 180);
canvas.fillPath(path, paint, FillRule::Winding);
// pixmap now contains the rendered triangle.
// Call pixmap.releaseDemultiplied() to get straight-alpha RGBA bytes for PNG encoding.
Drawing surface that operates on a Pixmap or MutablePixmapView.
Builder for constructing immutable Path objects.
Pixel buffers and views for RGBA image data.
Drawing surface backed by a mutable pixel buffer.
Definition Canvas.h:29
Incrementally builds a Path from move/line/quad/cubic/close operations.
Definition PathBuilder.h:20
std::optional< Path > finish()
Builds and returns the immutable Path. Returns nullopt if empty or invalid.
PathBuilder & close()
Closes the current sub-path.
PathBuilder & lineTo(float x, float y)
Adds a line segment to (x, y).
PathBuilder & moveTo(float x, float y)
Begins a new sub-path at (x, y).
Controls how a shape is painted (shader, blend mode, anti-aliasing).
Definition Paint.h:15
void setColorRgba8(std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a)
Sets the shader to a solid color from 8-bit RGBA components.
Definition Paint.h:41

Key types

Type Purpose
tiny_skia::Canvas Drawing surface backed by a Pixmap or MutablePixmapView (fillRect, fillPath, strokePath, drawPixmap, applyMask)
tiny_skia::Pixmap Owned RGBA pixel buffer
tiny_skia::MutablePixmapView Non-owning mutable view into a pixmap
tiny_skia::Path Immutable vector path (lines, quads, cubics)
tiny_skia::PathBuilder Builder for constructing Path objects
tiny_skia::Paint Shader + blend mode + anti-alias settings
tiny_skia::Transform 2D affine transformation matrix
tiny_skia::Mask 8-bit alpha mask for clipping
tiny_skia::Stroke Stroke width, line cap, line join, dash pattern
tiny_skia::Color Floating-point RGBA color [0,1]
tiny_skia::ColorU8 8-bit RGBA color

Shader types

The tiny_skia::Shader variant holds one of:

Examples

Full examples are in the examples/ directory:

  • fill.cpp — basic path filling
  • stroke.cpp — dashed stroke with round caps
  • linear_gradient.cpp — linear gradient shader
  • mask.cpp — alpha mask clipping
  • pattern.cpp — pixmap pattern shader