Crate tricolor

Crate tricolor 

Source
Expand description

Color conversions and types.

If you want a compact color representation, use Color32Bit. If you want to manipulate RGBA colors use ColorLinear. If you want to manipulate colors in a way closer to how humans think about colors, use ColorHsvaGamma.

§Feature flags

  • extra_debug_asserts — Enable additional checks if debug assertions are enabled (debug builds).
  • extra_asserts — Always enable additional checks.

§Optional dependencies

  • bytemuckbytemuck enables you to cast ecolor types to &[u8].
  • cint (enabled by default)cint enables interoperability with other color libraries.
  • color-hex — Enable the [hex_color] macro.
  • serde — Allow serialization using serde.

Structs§

Color32Bit
This format is used for space-efficient color representation (32 bits).
ColorHsva
Hue, saturation, value, alpha. All in the range [0, 1]. No premultiplied alpha.
ColorHsvaGamma
Like Hsva but with the v value (brightness) being gamma corrected so that it is somewhat perceptually even.
ColorLinear
0-1 linear space RGBA color with premultiplied alpha.

Traits§

NormalizedFloat

Functions§

gamma_from_linear
linear [0, 1] -> gamma [0, 1] (not clamped). Works for numbers outside this range (e.g. negative numbers).
gamma_u8_from_linear_f32
linear [0, 1] -> gamma [0, 255] (clamped). Values outside this range will be clamped to the range.
hsv_from_rgb
All ranges in 0-1, rgb is linear.
linear_f32_from_gamma_u8
gamma [0, 255] -> linear [0, 1].
linear_f32_from_linear_u8
linear [0, 255] -> linear [0, 1]. Useful for alpha-channel.
linear_from_gamma
gamma [0, 1] -> linear [0, 1] (not clamped). Works for numbers outside this range (e.g. negative numbers).
linear_u8_from_linear_f32
linear [0, 1] -> linear [0, 255] (clamped). Useful for alpha-channel.
rgb_from_hsv
All ranges in 0-1, rgb is linear.