ctx - interactive vector graphics environment

5 min read Original article ↗

ctx consists of a terminal/compositor, protocol and high performance, portable, low resource software rasterizer for 2D vector graphics, aiming for capability compatibility with HTML5 Canvas' 2D context. It leverages portable C code and auto-vectorization capabilities of modern compilers to target everything from microcontrollers to threaded, color managed RGB and CMYK compositing with 32bit floating point.

ctx-0.1.18.tar.bz2 - 2026-05-23

  • fix to crash in ctx_close_path without a path
  • switch between mask generation and direct rendering based on scanline complexity.
  • Less performance agressive performance/speed tradeoff.

ctx-0.1.16.tar.bz2 - 2026-05-20

  • updated color blind friendly terminal palette
  • x86-64-v4 support
  • fixes to many texture compositing code paths, uncovered with afl+
  • full screen sub-pixel antialiasing (also for raster content)
  • make tile hashing logic not strictly tied to max 32 cells
  • vt: some behavior improvements
  • multi-client: stop propagation of scroll events
  • early bail when drawing images outside bounds
  • add implicit close-path before move-to's in fonts
  • make ctx contexts have floats for width/height APIs
  • implement own inlinable stubs for the few libc functions in use
  • start of drafting async texture/file upload
  • make core rasterizer dispatch an array lookup rather than a switch
  • use a sorted auxiliary linked list for edges rather than quick-sorting arrays
  • micropython: add wasm example
  • speed up complex tiny geometry by simplifying during contour building.
  • higher precision edge slopes

ctx-0.1.14.tar.bz2 - 2025-12-07

  • More type safety
  • Fix to compression, harmonizing across backends
  • fix terminal reflow
  • unix socket server/backend
  • Default terminal palette - with better dichromat contrast.
  • Fix aa rendering in cb backend

ctx-0.1.12.tar.bz2 - 2025-11-08

  • terminal:
    • fix rightmost column of glyphs
    • fix to multiline copy/paste
  • wasm, fix pixel transport for newer emscripten, type correctness across codebase.
  • events: only emit one unichar long text_input sequences, harmonized keyboard modifier state changes across backends.

ctx-0.1.10.tar.bz2 - 2025-08-05

  • less - though still a bit - janky fullscreen switching
  • settings toolkit: overlays, choice and color popup widgets
  • compression moved to parser, now consistent between terminal and stand-alone tcp parser

A motivation behind ctx was having a batteries included portable vector graphics library with a serialization protocol for use in a terminal emulator/UI shell, while also covering the needs of GIMP and GEGL.

Resource usage minimization has benefits in reduced cache trashing, also some microcontroller platforms. Though raster caches might be introduced in some places, it is likely on a higher level than something like a text glyph cache. Through refactorings ctx is now implementing the SDL and KMS/fbdev backends through the same callback interface used for SPI displays on microcontrollers, sharing bugs and features like multi-core rendering, all while being frugal with RAM usage. Ctx is being used for UI rendering in these computing festival/hacker-camp badges: card10, flow3r and tildagon.

Serial full duplex is the foundation of ctx, and future improvements like shared memory should be on top of a serial fallback. ctx employs compression using the previous drawlist as a dictionary, which makes content with groups using transforms efficiently recompress. When used in the ctx terminal special escape codes turn switch from DEC like terminal to ctx terminal for rendering and event handling. The serialization of the rendering model is a superset of SVG path d attribute syntax.

Pixel encodings from 1bit to 32bit per pixel, in grayscale, RGB and CMY are supported.

automatic partial redraws The interactive backends of ctx are tailored towards low latency rendering of UIs where only a part of the screen changes, though the full scene is expected to be redrawn each time. Hashes are computed for tiles in a grid and only changed ones are scheduled as jobs for the rendering thread and the main thread. Users of ctx are still encouraged to minimize redraws and the api calls ctx_queue_draw (ctx); and ctx_needs_redraw (ctx) are provided for keeping things down.

event handling is a place where ctx differs from other vetor engines, during drawing you can listen for pointer interactions with implicit drag grabs, this allows abstracting over multiple input devices/buttons with a mouse+keyboard abstraction. In the event method callback both absolute and local (At time of callback registration) coordinates are provided. Interactive ctx backends drive event delivery, if you are implementing the callback backend for microcontrollers and external displays you are expected to turn hardware events into interaction events. The terminal contains an on-screen keyboard that uses the same API for delivering synthetic events.

auto-vectorization for platform support, the code in ctx is written to touch a minimal amount of pixels while also being friendly to autovectorization on platforms supporting it.

arm32
tested on rp2040 and rpi2
aarch64
tested on a pi, mediatek based chromebook and more
x86-64
Automatic runtime choice of 3 different levels of SIMD support.
tensilica
tested on esp32 and esp32s3
risc-v
tested on esp32c3
wasm
built with emscripten
?
if it is a 32bit or 64bit platform; with a C compiler it probably works.

Desired features specified for HTML5 canvas that are missing:

miter-limit
The stroker is currently always beveling strokes, fixing miter limit would also remove some currently hidden interesecting geometry on other parts of strokes.
focal point of radial gradient
correct result for shadow-blur
the SDF approximation is servicable in some cases but not correct.
filters
most importantly blur, but also brightness(),contrast(),grayscale(),hue-rotate(),invert(),opacity(),saturate(),sepia()
fontKerning
kerning is implemented in some of the font backends - but not ability to toggle on/off
direction
fontStretch
fontVariantCaps
letterSpacing
wordSpacing
textRendering
strokeText

Non HTML5-Canvas features desired, some for SVG capabilities:

stroke to path
for implementing strokeText
text along path baseline
text to path

license and funding

ctx is available under the ISC license, though not required it is appreciated if the ctx logo is shown during boot/in relevant place of settings or information screens. can encourage continued development of ctx and dissimilar technologies by financially supporting me, Øyvind Kolås who is doing independent pro-bono R&D through patreon and similar.