use screenshots::image::{ImageBuffer, Rgba};
#[derive(Default)]
pub struct ImageDimensions {
pub width: u32,
pub height: u32,
}
impl std::fmt::Display for ImageDimensions {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_fmt(format_args!("({}, {})", self.width, self.height))
}
}
pub struct Renderer;
impl Renderer {
pub fn stitch_horizontally(
images: Vec<ImageBuffer<Rgba<u8>, Vec<u8>>>,
) -> ImageBuffer<Rgba<u8>, Vec<u8>> {
let dimensions = images
.iter()
.fold(ImageDimensions::default(), |t, buf| ImageDimensions {
width: t.width + buf.width(),
height: t.height.max(buf.height()),
});
let mut img_buf = ImageBuffer::new(dimensions.width, dimensions.height);
images
.iter()
.fold(ImageDimensions::default(), |offset, buf| {
for (x, y, pixel) in buf.enumerate_pixels() {
img_buf.put_pixel(offset.width + x, y, *pixel);
}
ImageDimensions {
width: offset.width + buf.width(),
height: offset.height,
}
});
img_buf
}
}