normalize_edge_runs
Merge lone one-pixel runs on diagonal pixel-art edges into neighboring runs to even out slope wander, reporting jagged-corner counts before and after while leaving spikes, notches, and intentional steps untouched.
Instructions
Even out the run lengths along a silhouette's diagonals, conservatively.
A hand-drawn diagonal is built from runs of consistent length: a 1:2 slope is two
pixels, two pixels, two pixels, held steady, and broken only on purpose. A generated
one wanders, runs of 3, 1, 2, 1, 4 where a person would have drawn 2, 2, 2, 2, and
that wander is the most recognisable tell in generated pixel art, ahead of both colour
and shading. `assess_sprite` already counts it as `jaggy_corners`, which on a boundary
stepping one way is exactly the number of steps; this is what to do about the count
when the wander is a lone short run. It is not a fix for every jagged-corner reading:
consecutive one-pixel runs are declined, so a sawtooth edge that steps out and back a
pixel at a time can fire that reading and leave this with nothing to merge.
What it changes is narrow on purpose: a run of **exactly one**, with a run of at least
two on either side, stepping the same way on both sides, by exactly one pixel each
time. That run is merged into whichever neighbour lies further out, which paints one
pixel in the colour of the pixel beside it. Everything else is left alone and counted
under `kept`, so a pass that declines to touch something says which rule stopped it:
* `diagonal`: the run sits next to another one-pixel run, so this is a 1:1 diagonal,
already the most even edge there is;
* `feature`: the run is further out, or further in, than both its neighbours. That is a
spike or a notch, a local extremum, and somebody drew it: a horn, a finger, a chip
in the stone;
* `step`: the step either side is more than one pixel, so this is a change of slope;
* `thin`: the edge belongs to something thinner than `min_span`, where adding a pixel
reshapes the feature instead of smoothing its edge;
* `no_gain`: the merge would not lower the jagged-corner count, measured over the four
2x2 windows the one new pixel can change.
Because it only ever adds a pixel, and only ever a value the boundary already held
somewhere else, **the silhouette's extent cannot move and nothing can be eaten**. Both
are checked rather than promised: a plan whose bounding box differs from the
original's is refused and nothing is written.
Args:
min_span: How thick the mass behind an edge has to be before its edge is treated
as an edge, measured as the unbroken run of drawn pixels inward from the
boundary. The default of 3 is the smallest value at which the added pixel is a
minority of what it joins. Raise it to protect thin limbs; 2 is the floor.
layer: The layer whose silhouette is read and written (default: top layer).
frame: Target frame, 1-based.
Returns `jaggy_corners_before` and `jaggy_corners_after` every call, so the claim is in
the result rather than in this docstring, along with `runs_merged` and `by_side`. A
pass with nothing to merge is **refused**, and the refusal carries the tally above: a
silhouette this cannot improve is the normal case for art that was drawn by hand.
Two Aseprite launches, one to read the silhouette and one to paint: the decision about
which runs are stumbles is arithmetic over the whole shape, and the shape is only
knowable with the file open. The read ignores any active selection, because the
geometry is a fact about the whole silhouette, while the write honours it like every
other drawing tool. When the mask refuses some of the planned pixels, the after figure
is withheld rather than reported against a shape that was not painted.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"filename": "<filename>"
},
"name": "normalize_edge_runs"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| frame | No | Default: 1. | |
| layer | No | ||
| filename | Yes | ||
| min_span | No | Default: 3. |