pub fn apply_selout(
grid: &[String],
fallback: Option<&str>,
mapping: Option<&HashMap<String, String>>,
) -> Vec<String>Expand description
Apply selective outline (sel-out) transform to a grid.
Selective outline varies the outline color based on adjacent fill pixels, creating softer edges. For each outline pixel (a pixel adjacent to both opaque and transparent pixels), the transform picks a color based on the most common neighboring fill color.
§Arguments
grid- The grid of token rowsfallback- Optional fallback token for pixels where neighbor can’t be determinedmapping- Optional explicit mapping from fill token to outline token. Key “*” serves as the default fallback.
§Returns
A new grid with outline pixels recolored based on neighbors
§Algorithm
- Parse each row into tokens
- For each pixel, check if it’s an “outline” pixel:
- An outline pixel is opaque (not {}) and adjacent to at least one {}
- For outline pixels, find the most common non-transparent neighbor
- Map that neighbor to an outline color using the mapping or by appending “_dark” to the token name