Expand description
blend-srgb is a small, #![no_std]-compatible sRGB conversion and
blending library designed for performance.
It provides a small number of helper functions for converting and blending sRGB values:
srgb_to_rgb, which converts a floating-point sRGB component to a floating-point Linear RGB component.rgb_to_srgbwhich does the reverse.srgb8_to_rgb12which converts an 8-bit sRGB component to a 12-bit Linear RGB component.rgb12_to_srgb8which does the reverse.rgb12_to_srgb8_uncheckedwhich does not truncate the input to 12 bits.blend_srgb8_channelwhich blends an sRGB foreground and background color with the provided alpha.blend_srgb8which does the same as above but for (r, g, b) tuples.
Additionally, these functions are designed to be performant enough to be used in software composition pipelines. To facilitate this, a small (4.5k) lookup table is included. The lookup table can be small due to the usage of 12-bit linear values rather than 16-bit. 12 bits are enough to store all 8-bit sRGB values in linear space.
All functions other than srgb_to_rgb and rgb_to_srgb use only
integer operations, and are therefore fully compatible with #![no_std].
To activate #![no_std], just deactivate the std feature. To keep
the floating-point methods, also add the libm feature.
Modulesยง
- blend
- Functions for blending together sRGB colors. These functions use the
conversion functions in
convert, but do not support transparent backgrounds. - convert
- Functions for converting between sRGB and linear space. There are
floating-point (
srgb_to_rgbandrgb_to_srgb) and integer (srgb8_to_rgb12andrgb12_to_srgb8) versions.