module

CrImage::Util::Selection

Selection and flood fill operations for image editing.

Provides tools for selecting regions based on color similarity and filling areas with new colors.

Class methods

flood_fill(img : RGBA, x : Int32, y : Int32, fill_color : Color::Color, tolerance : Int32 = 10) : Int32

Performs flood fill starting from a seed point.

Fills all connected pixels that are similar to the seed pixel's color within the specified tolerance.

Parameters:

  • img : The image to modify (modified in place)
  • x : Starting X coordinate
  • y : Starting Y coordinate
  • fill_color : Color to fill with
  • tolerance : Maximum color difference to consider "similar" (0-255)

Returns: Number of pixels filled

Source
replace_color(img : Image, target_color : Color::Color, replacement_color : Color::Color, tolerance : Int32 = 10) : RGBA

Replaces all pixels of one color with another.

Parameters:

  • img : Source image
  • target_color : Color to replace
  • replacement_color : New color
  • tolerance : Maximum color difference (0-255)

Returns: New RGBA image with colors replaced

Source
select_by_color(img : Image, x : Int32, y : Int32, tolerance : Int32 = 10, contiguous : Bool = true) : Gray

Creates a selection mask based on color similarity.

Returns a grayscale image where white (255) indicates selected pixels and black (0) indicates unselected pixels.

Parameters:

  • img : Source image
  • x : Seed point X coordinate
  • y : Seed point Y coordinate
  • tolerance : Maximum color difference (0-255)
  • contiguous : If true, only selects connected pixels; if false, selects all similar pixels

Returns: Gray image representing the selection mask

Source