Skip to main content

apply_selout

Function apply_selout 

Source
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 rows
  • fallback - Optional fallback token for pixels where neighbor can’t be determined
  • mapping - 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

  1. Parse each row into tokens
  2. For each pixel, check if it’s an “outline” pixel:
    • An outline pixel is opaque (not {}) and adjacent to at least one {}
  3. For outline pixels, find the most common non-transparent neighbor
  4. Map that neighbor to an outline color using the mapping or by appending “_dark” to the token name