增加一个将RGB颜色拆解成分量色单元的函数。
This commit is contained in:
parent
7407133440
commit
09c5a3be78
|
@ -8,6 +8,14 @@ use wasm_bindgen::prelude::*;
|
|||
|
||||
mod errors;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn represent_rgb(color: &str) -> Result<Box<[u8]>, errors::ColorError> {
|
||||
let srgb = Srgb::from_str(color)
|
||||
.map_err(|_| errors::ColorError::UnrecogniazedRGB(color.to_string()))?
|
||||
.into_format::<u8>();
|
||||
Ok(Box::new([srgb.red, srgb.green, srgb.blue]))
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn represent_hsl(color: &str) -> Result<Box<[f32]>, errors::ColorError> {
|
||||
let origin_color = Srgb::from_str(color)
|
||||
|
|
Loading…
Reference in New Issue
Block a user