How Libmypaint Powers GIMP Dynamic Brushes

Libmypaint serves as the specialized brush rendering engine behind GIMP's MyPaint Brush tool, enabling natural-media painting behaviors that standard static raster brushes cannot replicate. By separating the mathematical modeling of stroke dynamics from GIMP's core raster pipeline, the library continuously processes hardware input—such as stylus pressure, velocity, tilt, and direction—to dynamically compute changes in brush radius, opacity, hardness, and pigment blending. This architecture allows GIMP to execute expressive, organic brush dynamics in real time with high computational efficiency.

Decoupling Brush Physics from the Host Application

Libmypaint is a headless, standalone C library extracted from the MyPaint digital painting software. Inside GIMP, it acts as a modular subsystem dedicated exclusively to brush physics and state tracking.

Traditional digital brushes in GIMP sample a static 2D mask (dab) spaced at regular geometric intervals along an interpolated vector path. While functional, this method struggles with fluid, naturalistic painting effects. Libmypaint replaces this static paradigm with a dynamic, stateful calculation model. It does not handle the final image compositing directly; instead, it acts as an algorithmic generator that calculates precisely how, where, and with what intensity paint should be deposited on the canvas at any given microsecond.

Continuous Input Processing and Mathematical Modeling

When a user draws a stroke in GIMP using a tablet or mouse, GIMP captures low-level input events and passes them directly to Libmypaint. The library processes several dynamic variables simultaneously:

  • Pressure Dynamics: Scales stroke radius, opacity, and hardness based on continuous non-linear pressure curves.
  • Velocity and Acceleration: Computes stroke speed to simulate physical drag, ink starvation, or edge feathering.
  • Tilt and Direction: Adjusts brush angle and aspect ratio according to stylus orientation, mimicking real-world chisel markers or angled bristle brushes.
  • Jitter and Randomization: Adds controlled procedural noise to mimic paper texture and bristle imperfections.

Libmypaint evaluates these inputs using a multi-parameter configuration file (the brush preset), computing the exact values for each variable at arbitrary time slices along the stroke.

Stateful Stroke Lifecycle and Simulation

Unlike basic brush engines that treat each dab as an isolated stamp, Libmypaint maintains an internal simulation state throughout the duration of a stroke. This state machine manages properties such as:

  • Pigment Loading and Depletion: Tracks how much digital "paint" remains on the brush tip, gradually decreasing opacity and stroke width until the brush is lifted and "re-dipped."
  • Smudge and Color Pickup: Continuously samples underlying canvas data and blends it into the brush's internal pigment buffer, allowing colors to drag, smear, and dilute dynamically across the surface.
  • Stroke Inertia and Tracking: Applies dynamic smoothing algorithms that simulate the weight and resistance of physical tools, smoothing out erratic hand motions without introducing noticeable latency.

Integration with GIMP's GEGL Pipeline

Once Libmypaint calculates the dynamic parameters for a stroke slice—including exact coordinates, radius, aspect ratio, opacity, and color modulation—it hands these calculated dabs back to GIMP. GIMP's core rendering engine, GEGL (Generic Graphical Library), then handles the actual memory allocation, pixel rasterization, color space management, and multi-threaded compositing onto the canvas layers.

By offloading the complex, multi-variable stroke dynamics to Libmypaint, GIMP achieves sophisticated natural-media behavior while keeping its primary rendering engine focused on high-performance pixel operations.