4个版本 (破坏性)
0.4.0 | 2021年7月16日 |
---|---|
0.3.0 | 2021年7月15日 |
0.2.0 | 2021年7月10日 |
0.1.0 | 2021年7月4日 |
#789 in 图形API
24KB
433 行
inku
由 u32
支持的 RGBA Color
。
示例
type RGBA = inku::Color<inku::RGBA>;
let color = RGBA::new(0x000000ff);
let new_color = color
// Lighten the color by 10%
.lighten(0.1)
// Saturate the color by 30%
.saturate(0.3);
assert_eq!(new_color.to_u32(), 0x201111ff);
// 4 bytes
assert_eq!(4, std::mem::size_of::<RGBA>());
存储格式
由 u32
支持的 RGBA 颜色。
有多种存储格式可供选择,如 ZRGB
和 RGBA
。这些决定了底层 u32
的布局。
type RGBA = inku::Color<inku::RGBA>;
type ZRGB = inku::Color<inku::ZRGB>;
assert_eq!(RGBA::new(0xfacadeff).to_u32(), 0xfacadeff);
// NOTE: The high byte is zeroed out
assert_eq!(ZRGB::new(0xfffacade).to_u32(), 0x00facade);
操作是损坏的
因为我们使用 u32
来表示颜色,所以操作是不可逆的。请考虑以下内容
type RGBA = inku::Color<inku::RGBA>;
let color = RGBA::new(0xfacadeff);
// We convert the RGB values to HSL and desaturated the color
let desaturated_color = color.desaturate(0.1);
assert_eq!(0xf7ccdeff, desaturated_color.to_u32());
// We don't know what our original hue was, so we can't get back to the original color
let resaturated_color = desaturated_color.saturate(0.1);
assert_eq!(0xf9c9ddff, resaturated_color.to_u32());
许可证:MIT OR Apache-2.0
依赖关系
~0–610KB