summaryrefslogtreecommitdiff
path: root/src/view.rs
diff options
context:
space:
mode:
authorRosyid Haryadi <rosyid_haryadi@protonmail.com>2025-03-01 20:50:10 +0700
committerRosyid Haryadi <rosyid_haryadi@protonmail.com>2025-03-01 20:50:10 +0700
commit8589ed72f4b43f214332aab26959962a7dac4b69 (patch)
treea2b66fadc80bd6b790c442219d70fa6053b2668b /src/view.rs
parent006c0c1f7d622bb2eabbf8b2445cd48d2c493d3b (diff)
upd png exporter
Diffstat (limited to 'src/view.rs')
-rw-r--r--src/view.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/view.rs b/src/view.rs
index 28ce849..bf3a356 100644
--- a/src/view.rs
+++ b/src/view.rs
@@ -22,6 +22,7 @@ impl<'a> View<'a> {
}
pub mod render_viewer {
+ use crate::global::Pixel;
use super::*;
pub fn ppm_exporter(data: &DisplayBuffer) -> Result<String, std::io::Error> {
@@ -39,4 +40,15 @@ pub mod render_viewer {
file.write_all(txt_data.as_bytes())?;
Ok(format!("Output rendered to file {}", file_name))
}
+
+ pub fn png_exporter(data: &DisplayBuffer) -> Result<String, std::io::Error> {
+ let file_name = "output.png";
+ let mut imgbuf = image::ImageBuffer::new(IMG_WIDTH as u32, IMG_HEIGHT as u32);
+ for (x, y, pixel) in imgbuf.enumerate_pixels_mut() {
+ let Pixel{r, g, b} = data[y as usize][x as usize];
+ *pixel = image::Rgb([r, g, b]);
+ }
+ imgbuf.save(file_name).unwrap();
+ Ok(format!("Output rendered to file {}", file_name))
+ }
}