aboutsummaryrefslogtreecommitdiff
path: root/src/utils.rs
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2023-10-24 17:49:08 +0400
committerIvan Molodetskikh <yalterz@gmail.com>2023-10-24 17:49:08 +0400
commit909a45db6f7a9ec04e9b45c086a499e5d6f38eb9 (patch)
tree8178024b879cd19726a93531f02728a82a679b3d /src/utils.rs
parentc6ec36f422c0b7e955bddcc7f783a963e313a8a7 (diff)
downloadniri-909a45db6f7a9ec04e9b45c086a499e5d6f38eb9.tar.gz
niri-909a45db6f7a9ec04e9b45c086a499e5d6f38eb9.tar.bz2
niri-909a45db6f7a9ec04e9b45c086a499e5d6f38eb9.zip
Use png crate directly instead of image
Reduce dependencies a bit.
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)
+}