module

CrImage::Util::Channels

Channel operations for extracting, manipulating, and combining color channels.

Provides methods for working with individual R, G, B, A channels as grayscale images, useful for advanced image processing and compositing workflows.

Class methods

combine(red : Gray, green : Gray, blue : Gray, alpha : Gray | Nil = nil) : RGBA

Combines separate channel images into an RGBA image.

Parameters:

  • red : Red channel (Gray image)
  • green : Green channel (Gray image)
  • blue : Blue channel (Gray image)
  • alpha : Alpha channel (Gray image, optional - defaults to opaque)

Returns: Combined RGBA image

Raises: ArgumentError if channel dimensions don't match

Source
extract(src : Image, channel : Symbol) : Gray

Extracts a single channel from an image as a grayscale image.

Parameters:

  • src : Source image
  • channel : Channel to extract (:red, :green, :blue, :alpha)

Returns: Gray image containing the channel values

Source
invert_channel(src : Image, channel : Symbol) : RGBA

Inverts a specific channel.

Parameters:

  • src : Source image
  • channel : Channel to invert (:red, :green, :blue, :alpha)

Returns: New RGBA image with inverted channel

Source
map(src : Image, channel : Symbol, &block : UInt8 -> UInt8) : RGBA

Applies a function to a specific channel.

Parameters:

  • src : Source image
  • channel : Channel to modify (:red, :green, :blue, :alpha)
  • &block : Function that takes channel value (0-255) and returns new value

Returns: New RGBA image with modified channel

Source
multiply_channel(src : Image, channel : Symbol, factor : Float64) : RGBA

Multiplies a channel by a factor.

Parameters:

  • src : Source image
  • channel : Channel to multiply (:red, :green, :blue, :alpha)
  • factor : Multiplication factor (0.0 to any positive value)

Returns: New RGBA image with scaled channel

Source
set_channel(src : Image, channel : Symbol, value : UInt8) : RGBA

Sets a channel to a constant value.

Parameters:

  • src : Source image
  • channel : Channel to set (:red, :green, :blue, :alpha)
  • value : Value to set (0-255)

Returns: New RGBA image with constant channel

Source
split_rgb(src : Image) : Tuple(Gray, Gray, Gray)

Splits an image into its R, G, B channels.

Parameters:

  • src : Source image

Returns: Tuple of (red, green, blue) Gray images

Source
split_rgba(src : Image) : Tuple(Gray, Gray, Gray, Gray)

Splits an image into its R, G, B, A channels.

Parameters:

  • src : Source image

Returns: Tuple of (red, green, blue, alpha) Gray images

Source
swap(src : Image, ch1 : Symbol, ch2 : Symbol) : RGBA

Swaps two channels in an image.

Parameters:

  • src : Source image
  • ch1 : First channel (:red, :green, :blue)
  • ch2 : Second channel (:red, :green, :blue)

Returns: New RGBA image with swapped channels

Source