struct
Foundation::RGB
- Foundation::RGB
- Struct
- Value
- Object
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.crConstructors
- .new(r : UInt8, g : UInt8, b : UInt8)
-
.parse(hex : String) : RGB
Parses a hex color: "#RGB" (with each nibble doubled) or "#RRGGBB".
Instance Method Summary
- #b : UInt8
-
#blend(other : RGB, t : Float64) : RGB
Blends toward other through CIELAB, returning the interpolated sRGB color.
-
#distance(other : RGB) : Float64
Compares the Lab representations between
selfand other. - #g : UInt8
- #r : UInt8
-
#to_hex : String
Formats string as a lowercase "#RRGGBB" string.
-
#to_lab : Lab
Linearizes each sRGB channel and converts to CIELAB (with D65 reference white) to return a
Labvalue.
Constructor Detail
Parses a hex color: "#RGB" (with each nibble doubled) or "#RRGGBB". Case insensitive.
Raises on a malformed hex.
Instance Method Detail
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.
Compares the Lab representations between self and other.
Returns the ΔE76 perceptual distance between the two.
Linearizes each sRGB channel and converts to CIELAB (with D65 reference white) to return a Lab value.