1个不稳定版本

0.1.0 2021年11月9日

#945 in 图像

MIT许可证

81KB
2K SLoC

shh-colour

shh-colour 用于涉及SHT颜色代码的转换。SHT代码是一种直观的、可读的文本格式,用于颜色。请参阅https://omaitzen.com/sht/spec/以获取规范。支持转换为RGB/十六进制以及从文本中解析。

示例

use ::sht_colour::{
    rgb::{HexRGB, RGB},
    Ratio, SHT,
};

let red_sht = "r".parse::<SHT<u8>>().unwrap();
let red_hex = "#F00".parse::<HexRGB<u8>>().unwrap();

// `RGB` is the standard struct for RGB values, from the `rgb` crate.
let red_rgb = <RGB<Ratio<u8>>>::new(
    Ratio::from_integer(1),
    Ratio::from_integer(0),
    Ratio::from_integer(0),
);

// Converting between SHT and HexRGB (with a precision of 1 digit).
assert_eq!(red_sht.to_rgb(1), red_hex);
assert_eq!(red_sht, red_hex.to_sht(1));

// Converting between HexRGB and RGB.
assert_eq!(<RGB<Ratio<u8>>>::from(red_hex), red_rgb);
assert_eq!(red_hex, <HexRGB<u8>>::from(red_rgb));

依赖项

~1.5MB
~32K SLoC