module
Termisu::Color::Conversions
Overview
Color conversion algorithms.
Provides conversion between ANSI-8, ANSI-256, and RGB color modes. All conversion methods are stateless and side-effect free.
Extended Modules
Defined in:
termisu/color/conversions.crConstant Summary
-
ANSI8_PALETTE =
{0 => {0_u8, 0_u8, 0_u8}, 1 => {170_u8, 0_u8, 0_u8}, 2 => {0_u8, 170_u8, 0_u8}, 3 => {170_u8, 85_u8, 0_u8}, 4 => {0_u8, 0_u8, 170_u8}, 5 => {170_u8, 0_u8, 170_u8}, 6 => {0_u8, 170_u8, 170_u8}, 7 => {170_u8, 170_u8, 170_u8}} -
ANSI-8 standard color palette (RGB values)
-
ANSI8_THRESHOLD =
128_u8 -
Threshold for RGB to ANSI-8 color mapping. Values >= 128 are considered "on" for that color channel.
-
BRIGHT_BOOST =
85_u8 -
Brightness boost for bright colors (indices 8-15)
-
CUBE_LEVELS =
[0_u8, 95_u8, 135_u8, 175_u8, 215_u8, 255_u8] -
ANSI-256 color cube structure
-
CUBE_THRESHOLDS =
[48_u8, 115_u8, 155_u8, 195_u8, 235_u8] -
GRAYSCALE_END =
255 -
GRAYSCALE_MAX_THRESHOLD =
247_u8 -
GRAYSCALE_MIN_THRESHOLD =
8_u8 -
RGB to ANSI-256 conversion thresholds
-
GRAYSCALE_OFFSET =
8_u8 -
GRAYSCALE_START =
232 -
Grayscale ramp constants
-
GRAYSCALE_STEP =
10
Instance Method Summary
-
#ansi256_to_rgb(index : Int32) : Tuple(UInt8, UInt8, UInt8)
Converts ANSI-256 color index to RGB components.
-
#ansi8_to_rgb(index : Int32) : Tuple(UInt8, UInt8, UInt8)
Converts ANSI-8 color index to RGB components.
-
#rgb_to_ansi256(r : UInt8, g : UInt8, b : UInt8) : Int32
Converts RGB to nearest ANSI-256 palette color.
-
#rgb_to_ansi8(r : UInt8, g : UInt8, b : UInt8) : Int32
Converts RGB to nearest ANSI-8 color using threshold-based mapping.
Instance Method Detail
Converts ANSI-256 color index to RGB components.
Converts ANSI-8 color index to RGB components.
Converts RGB to nearest ANSI-256 palette color.
Converts RGB to nearest ANSI-8 color using threshold-based mapping.