Inlay
Inlay is our shared-edge tracer, behind every preset
(packages/inlay/src/inlay.ts). Like inlaid wood, every piece is cut to fit its
neighbors exactly. It replaced VTracer for flat art in October 2026, for
pixel art soon after, and for photos (Poster) last, once it had a quantized
palette and stacked shapes (VTracer has the numbers).
Why we wrote our own
Section titled “Why we wrote our own”VTracer traces every color region on its own and smooths each outline into curves without knowing where the corners are. On the sample badge that turned straight mountain slopes into slow S-bends and peaks into rounded bumps with two nodes a pixel apart. None of its settings gave straight lines and sharp corners.
The obvious fix, refitting each traced shape, opened a worse problem: hairline gaps. In cut-out mode every edge between two colors is traced twice, once per shape, and two independent fits land a fraction of a pixel apart, so the background shows through. The answer was to trace each edge once.
The steps
Section titled “The steps”1. Label every pixel
Section titled “1. Label every pixel”Each pixel gets the nearest palette color in OKLab (Line art: ink or paper, by one threshold for the whole image, the image’s own Otsu split by default, or a local-mean one for photos of paper). Transparent pixels are left out.
A pixel that sits clearly between two colors (anti-aliasing, JPEG ringing) takes the closest color among its neighbors rather than the closest overall. Otherwise an edge between red and blue grows a one-pixel purple sliver along its whole length.
Two exceptions in flat art (not Poster). A pixel far from every palette color (over 0.05) is first read as a mix of the two colors whose blend explains it, so a gray letter’s pale edge counts as gray and white, not as a light blue. And a pixel whose neighbors are all one color isn’t an edge between two: it’s a stroke too thin to have sure pixels of its own (1.5 px text), and keeps its color rather than taking the paper’s.
2. Clean the map
Section titled “2. Clean the map”- Spurs: a pixel whose eight neighbors are at least seven of one other color takes that color. JPEG noise leaves exactly these single-pixel spurs and nicks where colors meet, and fitted they became bumps and notches.
- Specks: regions smaller than Ignore specks² pixels merge into the nearest color among their neighbors, smallest first (on photos, Poster, the color they share most edge with, of those about as near as the nearest). Lossy compression splits a thin stroke into two shades of its ink, and by shared edge each piece joined the paper it mostly touches, so the stroke dissolved. In flat art a speck at least 0.25 from every color around it (a letter, a dot) is a shape and stays, from an eighth of the speck size up (at least 6 px), so raising the setting still clears it.
- Shades of one color: two palette colors that are nearly the same and blotched into each other, region by region, become whichever is nearer the region’s mean (noise splits one shade between them). On photos (Poster) only clusters under 0.035 apart, and a thin line blotched with a chain of them, as a drawing’s outline is with several near-blacks, takes one color end to end. Colors that meet along a clean edge stay apart.
- Gaps (Line art, and Outline art’s lines;
closeGaps): the ink is thinned to its skeleton, and each line end’s direction and width are measured a few widths back from it. Two ends that point at each other across a gap join, and an end that points at other ink close by reaches it (a T that stops short), painted at the line’s width, shortest gap first. A join must cross exactly one gap (ink, paper, ink), no wider than 1.6 line widths and 5.5 px: a JPEG’s or a faint pen’s breaks are a few pixels on any line, where dashes, and gaps of a width on a heavy line, are drawn. After Fourey, Tschumperlé and Revoy (VMV 2018, GIMP’s line art fill), on the skeleton rather than the ink’s border. - Slivers (flat art): regions under 2 px wide on average merge into a neighbor within 0.12 of their color in OKLab, so a letter stem dark at its edges and lighter down its middle becomes one shape, not a spike-prone strip inside another. A hairline of a color of its own has no neighbor that close and stays.
3. Walk the boundaries
Section titled “3. Walk the boundaries”Regions are 4-connected components of one color. The tracer walks the cracks between differently labeled pixels. Where three or more regions meet (or two meet diagonally) is a junction; each boundary between two junctions is one chain, with one region on each side. Boundaries with no junction (an island inside one color) are closed loops.
4. Fit each chain once
Section titled “4. Fit each chain once”Every chain becomes lines and curves exactly once, by the curve fitter. Nothing about the fit depends on which side it’s viewed from.
In a clean image (nearly every pixel inside a shape exactly its palette color, as in a PNG export), the fitter gets points between pixels instead of the pixel-edge staircase: the anti-aliased pixels either side of an edge say how much of each color they hold, which puts the edge to within a tenth of a pixel. JPEGs and photos skip this, since their noise would move edges.
A line within 1° of horizontal, vertical or 45° is then made exactly that, turning about its middle (or about the chain’s end, which stays put so the edge is still shared), and the nodes beside it move to where the snapped lines meet.
With shapes on, a closed chain (one neighbor all the way round) is first
checked against exact shapes (packages/inlay/src/shapes.ts). The pixel
region’s area, centroid and second moments give the candidate directly: an
ellipse with semi-axes a and b has variances a²/4 and b²/4 along its axes, a
w × h rectangle w²/12 and h²/12, and a rounded rectangle’s corner radius is
what its corners lose from the bounding box’s area. A regular polygon’s size
comes from its area and its turn from the corners the fitter found. The
candidate is kept only if the midpoints of the outline’s pixel edges lie within
0.3 px of it (RMS) and 0.85 px at worst; otherwise the chain is fitted as
usual. Because the chain is shared, both neighbors get the same exact shape.
5. Build the shapes
Section titled “5. Build the shapes”Each region’s outline is its chains joined end to end, reversing the ones it
sees from the other side. Where a region touches itself at a corner, the walk
turns left, which keeps diagonal neighbors as separate shapes. Holes are
wound the opposite way, so the default fill rule cuts them. Each region is one
<path>, largest first.
With stacked on (Illustration and Outline art by default), shapes become
layers instead. Where the boundary between two shapes ends at a third, the
shape whose outline carries straight on is in front and the one whose outline
turns there is behind. Each hidden run of a back shape’s outline is completed
as the circle or corner its visible part implies, or a smooth curve, and kept
only if it stays under the shapes in front. Shapes are painted back to front.
Result: neighboring shapes share the same fitted edge. No gaps, no overlaps, which is also what a vinyl cutter or a screen printer needs. A unit test traces a three-color image and checks the shapes’ areas add up to the whole image to within 0.2%.
Numbers
Section titled “Numbers”On the sample badge, scored at 4× against the clean art (see Measuring quality):
| Wrong pixels | Nodes | Size | |
|---|---|---|---|
| VTracer (previous Logo settings) | 0.86% | 259 | 7.3 KB |
| Shared edges, first version | 0.74% | 167 | 5.0 KB |
| Corners by their sides, round ends | 0.70% | 177 | 5.4 KB |
| Current: + exact shapes | 0.54% | 175 | 5.4 KB |
On a 2048 px image it traces in about 1.3 s, where VTracer took 17.5 s on the same image.
Limits
Section titled “Limits”- A line one pixel wide survives the spur cleanup but loses up to two pixels at each end, because an end pixel looks exactly like a spur. Small images are upscaled first, so this rarely matters.
- Gradients become bands, one region per palette color. Use Poster for photos.
Pixel art
Section titled “Pixel art”Pixel art skips the clean-up and the fitting (pixels: true):
- Palette: the image’s exact colors, most-used first
(
exactPaletteinpackages/inlay/src/palette.ts). Histogram peaks would drop a one-pixel eye for being rare and fold two close shades into one. - No despur: a lone pixel is deliberate.
- No fitting: each boundary is its exact pixel staircase, with straight
runs joined into single lines (
staircase). Every node sits on a pixel corner, with no handles.
On a 16 × 16 test sprite (7 colors, two close skin shades, a one-pixel eye)
both Inlay and VTracer’s pixel mode draw every pixel exactly. Inlay used 240
nodes against VTracer’s 278 and about the same bytes, with 31 paths against 25,
because its shapes are cut out to tile rather than stacked. On a 1024 px
sprite it took 0.2 s against 0.85 s; on a 1024 px photo picked as pixel art
(a worst case), 6.5 s and 12 MB against 27 s and 20 MB.
(apps/app/src/engine/pixel.test.ts checks the sprite on every run.)