use image::GenericImageView;
#[derive(Debug)]
pub struct Color {
pub red: u8,
pub blue: u8,
pub green: u8,
pub alpha: u8,
}
#[derive(Debug)]
pub struct Pixel {
pub x: u32,
pub y: u32,
pub color: Color,
}
pub fn get_width(img: &str) -> u32 {
let img = image::open(img).unwrap();
img.width()
}
pub fn get_height(img: &str) -> u32 {
let img = image::open(img).unwrap();
img.width()
}
pub fn load_picture(img: &str, precision: u32) -> Vec<[Pixel; 1]> {
let mut vec_struct = Vec::new();
let img = image::open(img).unwrap();
if precision < 0 || precision > 100 {
panic!("Precision cannot be value {} because it's either under 0%
or above 100%",
precision);
};
for i in 0..(img.height() * precision / 100) {
for j in 0..(img.width() * precision / 100) {
let img_pixel = img.get_pixel(j, i);
let pxl = [
Pixel {
x: i,
y: j,
color: Color {
red: img_pixel[0],
green: img_pixel[1],
blue: img_pixel[2],
alpha: img_pixel[3]
},
},
];
vec_struct.push(pxl);
}
};
vec_struct
}