9 个版本
0.3.2 | 2023 年 7 月 25 日 |
---|---|
0.3.1 | 2023 年 4 月 8 日 |
0.3.0 | 2021 年 7 月 31 日 |
0.2.1 | 2019 年 11 月 11 日 |
0.1.5 | 2019 年 4 月 27 日 |
#10 在 多媒体
40,510 每月下载量
用于 27 个包 (4 个直接使用)
2MB
972 行
包含 (WOFF 字体, 290KB) noto-sans-kr-v13-korean-regular.woff, (WOFF 字体, 190KB) docs/doc/FiraSans-Medium.woff, (WOFF 字体, 135KB) docs/doc/FiraSans-Medium.woff2, (WOFF 字体, 185KB) docs/doc/FiraSans-Regular.woff, (WOFF 字体, 130KB) docs/doc/FiraSans-Regular.woff2, (WOFF 字体, 69KB) docs/doc/SourceCodePro-Regular.ttf.woff 以及更多.
deltae
库
一个用于转换颜色和计算 DeltaE (颜色差异) 的 Rust 库。
在此查看文档: Rust API 文档
...或自己编译
cargo doc --open
示例
use std::error::Error;
use deltae::*;
fn main() -> Result<(), Box<dyn Error>>{
// Lab from a string
let lab0: LabValue = "89.73, 1.88, -6.96".parse()?;
// Lab directly from values
let lab1 = LabValue {
l: 95.08,
a: -0.17,
b: -10.81,
}.validate()?; // Validate that the values are in range
// Create your own Lab type
#[derive(Clone, Copy)]
struct MyLab(f32, f32, f32);
// Types that implement Into<LabValue> also implement the Delta trait
impl From<MyLab> for LabValue {
fn from(mylab: MyLab) -> Self {
LabValue { l: mylab.0, a: mylab.1, b: mylab.2 }
}
}
let mylab = MyLab(95.08, -0.17, -10.81);
// Implement DeltaEq for your own types
impl<D: Delta + Copy> DeltaEq<D> for MyLab {}
// Assert that colors are equivalent within a tolerance
assert_delta_eq!(mylab, lab1, DE2000, 0.0, "mylab is not equal to lab1!");
// Calculate DeltaE between two lab values
let de0 = DeltaE::new(lab0, lab1, DE2000);
// Use the Delta trait
let de1 = lab0.delta(lab1, DE2000);
assert_eq!(de0, de1);
// Convert to other color types
let lch0 = LchValue::from(lab0);
let xyz0 = XyzValue::from(lab1);
// If DE2000 is less than 1.0, the colors are considered equivalent
assert!(lch0.delta_eq(lab0, DE2000, 1.0));
assert!(xyz0.delta_eq(lab1, DE2000, 1.0));
// Calculate DeltaE between different color types
let de2 = lch0.delta(xyz0, DE2000);
assert_eq!(de2.round_to(4), de0.round_to(4));
// There is some loss of accuracy in the conversion.
// Usually rounding to 4 decimal places is more than enough.
// Recalculate DeltaE with different method
let de3 = de2.with_method(DE1976);
println!("{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n",
lab0, // [L:89.73, a:1.88, b:-6.96]
lab1, // [L:95.08, a:-0.17, b:-10.81]
lch0, // [L:89.73, c:7.2094383, h:285.11572]
xyz0, // [X:0.84574246, Y:0.8780792, Z:0.8542397]
de0, // 5.316941
de1, // 5.316941
de2, // 5.316937
de3, // 6.902717
);
Ok(())
}
示例
此库附带的一个示例二进制文件是一个命令行应用程序,用于计算 Lab 颜色之间的 Delta E。
用法
deltae 0.2.1
Ryan O'Beirne <[email protected]>
Calculate Delta E between two colors in CIE Lab space.
USAGE:
deltae [OPTIONS] <COLOR0> <COLOR1>
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
-c, --color-type <COLORTYPE> Set color type [default: lab] [possible values: lab, lch, xyz]
-m, --method <METHOD> Set DeltaE method [default: 2000] [possible values: 2000, 1994, 1994T, CMC1, CMC2,
1976]
ARGS:
<COLOR0> Reference color values
<COLOR1> Sample color values
示例
deltae --method=de1976 "89.73, 1.88, -6.96" "95.08, -0.17, -10.81"
安装
git clone https://gitlab.com/ryanobeirne/deltae
cd deltae
cargo install --example=deltae --path=. --force
注意
计算 DE2000、DE1994(图形艺术和纺织品)、DECMC(具有亮度和色度容忍度)和 DE1976。默认为 DE2000。