mirror of
https://github.com/arabianq/colorgram-rust.git
synced 2026-04-27 22:21:22 +00:00
small refactoring
This commit is contained in:
+11
-6
@@ -1,4 +1,9 @@
|
|||||||
use image;
|
use image;
|
||||||
|
use std::{
|
||||||
|
error::Error,
|
||||||
|
fmt::{Display, Formatter, Result as fmtResult},
|
||||||
|
path::Path,
|
||||||
|
};
|
||||||
|
|
||||||
pub struct Hsl {
|
pub struct Hsl {
|
||||||
pub h: u8,
|
pub h: u8,
|
||||||
@@ -6,8 +11,8 @@ pub struct Hsl {
|
|||||||
pub l: u8,
|
pub l: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for Hsl {
|
impl Display for Hsl {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
fn fmt(&self, f: &mut Formatter) -> fmtResult {
|
||||||
write!(f, "hsl({}, {}, {})", self.h, self.s, self.l)
|
write!(f, "hsl({}, {}, {})", self.h, self.s, self.l)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,8 +23,8 @@ pub struct Rgb {
|
|||||||
pub b: u8,
|
pub b: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for Rgb {
|
impl Display for Rgb {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
fn fmt(&self, f: &mut Formatter) -> fmtResult {
|
||||||
write!(f, "rgb({}, {}, {})", self.r, self.g, self.b)
|
write!(f, "rgb({}, {}, {})", self.r, self.g, self.b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -73,10 +78,10 @@ fn rgb_to_hsl(rgb: &Rgb) -> Hsl {
|
|||||||
Hsl { h, s, l: l as u8 }
|
Hsl { h, s, l: l as u8 }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn extract<P: AsRef<std::path::Path>>(
|
pub fn extract<P: AsRef<Path>>(
|
||||||
path: P,
|
path: P,
|
||||||
number_of_color: usize,
|
number_of_color: usize,
|
||||||
) -> Result<Vec<Color>, Box<dyn std::error::Error>> {
|
) -> Result<Vec<Color>, Box<dyn Error>> {
|
||||||
let img = image::open(path)?;
|
let img = image::open(path)?;
|
||||||
let img = img.to_rgb8();
|
let img = img.to_rgb8();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user