aboutsummaryrefslogtreecommitdiff
path: root/src/utils.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.rs')
-rw-r--r--src/utils.rs16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/utils.rs b/src/utils.rs
index 55e6bce7..80f5a0a1 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -1,5 +1,5 @@
use std::ffi::OsStr;
-use std::io;
+use std::io::{self, Write};
use std::os::unix::process::CommandExt;
use std::path::PathBuf;
use std::process::{Command, Stdio};
@@ -89,3 +89,17 @@ pub fn spawn(command: impl AsRef<OsStr>, args: impl IntoIterator<Item = impl AsR
}
}
}
+
+pub fn write_png_rgba8(
+ w: impl Write,
+ width: u32,
+ height: u32,
+ pixels: &[u8],
+) -> Result<(), png::EncodingError> {
+ let mut encoder = png::Encoder::new(w, width, height);
+ encoder.set_color(png::ColorType::Rgba);
+ encoder.set_depth(png::BitDepth::Eight);
+
+ let mut writer = encoder.write_header()?;
+ writer.write_image_data(pixels)
+}