增加QScheme主题样式的生成与导出。
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
use palette::{
|
||||
cam16::{Cam16Jch, Parameters},
|
||||
convert::FromColorUnclamped,
|
||||
Hsl, IsWithinBounds, Srgb,
|
||||
luma::Luma,
|
||||
Hsl, IntoColor, IsWithinBounds, Oklab, Oklch, Srgb,
|
||||
};
|
||||
|
||||
pub fn map_cam16jch_to_srgb(origin: &Cam16Jch<f32>) -> Srgb {
|
||||
@@ -44,3 +45,43 @@ pub fn map_hsl_to_srgb(origin: &Hsl) -> Srgb {
|
||||
pub fn map_hsl_to_srgb_hex(origin: &Hsl) -> String {
|
||||
format!("{:x}", map_hsl_to_srgb(origin).into_format::<u8>())
|
||||
}
|
||||
|
||||
pub fn map_oklch_to_luma(origin: &Oklch) -> Luma {
|
||||
let lab_color: Oklab = (*origin).into_color();
|
||||
let linear_rgb = Srgb::from_linear(lab_color.into_color());
|
||||
let luma_color: Luma = linear_rgb.into_color();
|
||||
luma_color
|
||||
}
|
||||
|
||||
pub fn map_oklch_to_srgb(origin: &Oklch) -> Srgb {
|
||||
Srgb::from_linear::<f32>((*origin).into_color())
|
||||
}
|
||||
|
||||
pub fn map_oklch_to_srgb_hex(origin: &Oklch) -> String {
|
||||
format!("{:x}", map_oklch_to_srgb(origin).into_format::<u8>())
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! parse_to_oklch {
|
||||
($origin: ident) => {
|
||||
palette::Oklch::from_color(
|
||||
palette::Srgb::from_str($origin)
|
||||
.map_err(|_| crate::errors::ColorError::UnrecogniazedRGB($origin.to_string()))?
|
||||
.into_format::<f32>(),
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! parse_option_to_oklch {
|
||||
($origin: ident) => {
|
||||
$origin
|
||||
.map(|color| {
|
||||
let rgb = palette::Srgb::from_str(color)
|
||||
.map_err(|_| crate::errors::ColorError::UnrecogniazedRGB(color.to_string()))?
|
||||
.into_format::<f32>();
|
||||
Ok(palette::Oklch::from_color(rgb))
|
||||
})
|
||||
.transpose()?
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user