This commit is contained in:
2025-03-24 16:56:36 -04:00
parent b7f44d9ac0
commit b62745adec
3 changed files with 17 additions and 85 deletions

View File

@@ -1,5 +1,6 @@
use crate::{grid::Grid, palette::Palette};
use image::RgbImage;
use itertools::multizip;
/// Stores data that is located in grids that is used for image generation
@@ -48,16 +49,6 @@ impl ThinGridData {
.select_nth_unstable_by(index, |a, b| a.partial_cmp(b).unwrap());
sorted[index]
}
pub fn size_of(&self) -> usize {
let mut output: usize = 0;
output += std::mem::size_of_val(&self.width);
output += std::mem::size_of_val(&self.height);
for i in self.data.iter() {
output += std::mem::size_of_val(&i);
}
output
}
}
/// Class for storing data that will be used to create images
@@ -65,29 +56,17 @@ impl ThinGridData {
pub struct ImgData {
pub grids: Vec<ThinGridData>,
pub palette: Palette,
pub iteration: i32,
}
impl ImgData {
pub fn new(in_grids: Vec<ThinGridData>, in_palette: Palette, in_iteration: i32) -> Self {
pub fn new(in_grids: Vec<ThinGridData>, in_palette: Palette) -> Self {
ImgData {
grids: in_grids,
palette: in_palette,
iteration: in_iteration,
}
}
pub fn size_of(&self) -> usize {
let mut output: usize = 0;
output += std::mem::size_of_val(&self.iteration);
output += std::mem::size_of_val(&self.palette);
for grid in self.grids.iter() {
output += grid.size_of();
}
output
}
pub fn save_to_image(&self) {
pub fn to_image(&self) -> RgbImage {
let (width, height) = (self.grids[0].width, self.grids[0].height);
let mut img = image::RgbImage::new(width as u32, height as u32);
@@ -116,8 +95,6 @@ impl ImgData {
img.put_pixel(x as u32, y as u32, image::Rgb([r as u8, g as u8, b as u8]));
}
}
img.save(format!("./tmp/out_{}.png", self.iteration).as_str())
.unwrap();
img
}
}