diff --git a/television/utils/image.rs b/television/utils/image.rs index 65f0c1a..df366a3 100644 --- a/television/utils/image.rs +++ b/television/utils/image.rs @@ -1,32 +1,38 @@ -use image::DynamicImage; use image::imageops::FilterType; +use image::DynamicImage; -pub const PIXEL: char = '▀' ; +pub const PIXEL: char = '▀'; const FILTER: FilterType = FilterType::Triangle; #[derive(Clone, Debug)] pub struct Image { - pub pixel_grid: Vec> + pub pixel_grid: Vec>, } impl Image { pub fn new(pixel_grid: Vec>) -> Self { - Image { pixel_grid} + Image { pixel_grid } } - pub fn from_dynamic_image(dynamic_image: DynamicImage, height: u32, width: u32) -> Self { - - let image = if dynamic_image.height() > height || dynamic_image.width() > width { - println!("{}", dynamic_image.height()); + pub fn from_dynamic_image( + dynamic_image: DynamicImage, + height: u32, + width: u32, + ) -> Self { + let image = if dynamic_image.height() > height + || dynamic_image.width() > width + { dynamic_image.resize(width, height, FILTER) - }else{ + } else { dynamic_image }; let image = image.into_rgba8(); - let pixel_grid = image.rows() + let pixel_grid = image + .rows() .step_by(2) .zip(image.rows().skip(1).step_by(2)) .map(|(row_1, row_2)| { - row_1.zip(row_2) - .map(|(pixel_1, pixel_2)| + row_1 + .zip(row_2) + .map(|(pixel_1, pixel_2)| { ( ImageColor { r: pixel_1.0[0], @@ -39,18 +45,20 @@ impl Image { g: pixel_2.0[1], b: pixel_2.0[2], a: pixel_1.0[3], - })) - .collect::>() + }, + ) + }) + .collect::>() }) - .collect::>>(); + .collect::>>(); Image::new(pixel_grid) } } #[derive(Clone, Copy, Debug)] -pub struct ImageColor{ +pub struct ImageColor { pub r: u8, pub g: u8, pub b: u8, - pub a: u8 -} \ No newline at end of file + pub a: u8, +}