struct Foundation::RGB

Overview

An 8bit sRGB color: the base color value for hex parsing and downsampling.

rgb = Foundation::RGB.parse("#FF8800")
rgb.r      # => 255
rgb.g      # => 136
rgb.b      # => 0
rgb.to_hex # => "#ff8800"

Defined in:

foundation/color_space.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(r : UInt8, g : UInt8, b : UInt8) #

[View source]
def self.parse(hex : String) : RGB #

Parses a hex color: "#RGB" (with each nibble doubled) or "#RRGGBB". Case insensitive.

Raises on a malformed hex.


[View source]

Instance Method Detail

def b : UInt8 #

[View source]
def blend(other : RGB, t : Float64) : RGB #

Blends toward other through CIELAB, returning the interpolated sRGB color.

t is the mix fraction clamped to 0.0..1.0, where t == 0.0 returns self and t == 1.0 returns other. Blending in Lab rather than sRGB keeps the gradient perceptually even.


[View source]
def distance(other : RGB) : Float64 #

Compares the Lab representations between self and other. Returns the ΔE76 perceptual distance between the two.


[View source]
def g : UInt8 #

[View source]
def r : UInt8 #

[View source]
def to_hex : String #

Formats string as a lowercase "#RRGGBB" string.


[View source]
def to_lab : Lab #

Linearizes each sRGB channel and converts to CIELAB (with D65 reference white) to return a Lab value.


[View source]