aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock43
-rw-r--r--Cargo.toml2
-rw-r--r--src/niri.rs32
-rw-r--r--src/utils.rs16
4 files changed, 30 insertions, 63 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 45165e94..043d3a1f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -574,12 +574,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961"
[[package]]
-name = "color_quant"
-version = "1.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b"
-
-[[package]]
name = "colorchoice"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1119,20 +1113,6 @@ dependencies = [
]
[[package]]
-name = "image"
-version = "0.24.7"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6f3dfdbdd72063086ff443e297b61695500514b1e41095b6fb9a5ab48a70a711"
-dependencies = [
- "bytemuck",
- "byteorder",
- "color_quant",
- "num-rational",
- "num-traits",
- "png",
-]
-
-[[package]]
name = "indexmap"
version = "2.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1552,7 +1532,6 @@ dependencies = [
"bitflags 2.4.1",
"clap",
"directories",
- "image",
"keyframe",
"knuffel",
"libc",
@@ -1560,6 +1539,7 @@ dependencies = [
"logind-zbus",
"miette",
"pipewire",
+ "png",
"portable-atomic",
"profiling",
"proptest",
@@ -1621,27 +1601,6 @@ dependencies = [
]
[[package]]
-name = "num-integer"
-version = "0.1.45"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
-dependencies = [
- "autocfg",
- "num-traits",
-]
-
-[[package]]
-name = "num-rational"
-version = "0.4.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0"
-dependencies = [
- "autocfg",
- "num-integer",
- "num-traits",
-]
-
-[[package]]
name = "num-traits"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index fed3ad71..a3704ed6 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -14,7 +14,6 @@ async-io = { version = "1.13.0", optional = true }
bitflags = "2.4.1"
clap = { version = "4.4.6", features = ["derive"] }
directories = "5.0.1"
-image = { version = "0.24.7", default-features = false, features = ["png"] }
keyframe = { version = "1.1.1", default-features = false }
knuffel = "3.2.0"
libc = "0.2.149"
@@ -22,6 +21,7 @@ logind-zbus = { version = "3.1.2", optional = true }
log = { version = "0.4.20", features = ["max_level_trace", "release_max_level_debug"] }
miette = "5.10.0"
pipewire = { version = "0.7.2", optional = true }
+png = "0.17.10"
portable-atomic = { version = "1.5.0", default-features = false, features = ["float"] }
profiling = "1.0.11"
sd-notify = "0.4.1"
diff --git a/src/niri.rs b/src/niri.rs
index 2c357f50..9265153b 100644
--- a/src/niri.rs
+++ b/src/niri.rs
@@ -9,7 +9,6 @@ use std::{env, mem, thread};
use _server_decoration::server::org_kde_kwin_server_decoration_manager::Mode as KdeDecorationsMode;
use anyhow::Context;
-use image::ImageFormat;
use smithay::backend::allocator::Fourcc;
use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement};
use smithay::backend::renderer::element::surface::{
@@ -85,7 +84,7 @@ use crate::frame_clock::FrameClock;
use crate::handlers::configure_lock_surface;
use crate::layout::{output_size, Layout, MonitorRenderElement};
use crate::pw_utils::{Cast, PipeWire};
-use crate::utils::{center, get_monotonic_time, make_screenshot_path};
+use crate::utils::{center, get_monotonic_time, make_screenshot_path, write_png_rgba8};
pub const CLEAR_COLOR: [f32; 4] = [0.2, 0.2, 0.2, 1.];
pub const CLEAR_COLOR_LOCKED: [f32; 4] = [0.3, 0.1, 0.1, 1.];
@@ -1881,14 +1880,8 @@ impl Niri {
thread::spawn(move || {
let mut buf = vec![];
- if let Err(err) = image::write_buffer_with_format(
- &mut std::io::Cursor::new(&mut buf),
- &pixels,
- size.w as u32,
- size.h as u32,
- image::ColorType::Rgba8,
- ImageFormat::Png,
- ) {
+ let w = std::io::Cursor::new(&mut buf);
+ if let Err(err) = write_png_rgba8(w, size.w as u32, size.h as u32, &pixels) {
warn!("error encoding screenshot image: {err:?}");
return;
}
@@ -1942,16 +1935,17 @@ impl Niri {
debug!("saving screenshot to {path:?}");
thread::spawn(move || {
- let res = image::save_buffer(
- &path,
- &pixels,
- size.w as u32,
- size.h as u32,
- image::ColorType::Rgba8,
- );
+ let file = match std::fs::File::create(&path) {
+ Ok(file) => file,
+ Err(err) => {
+ warn!("error creating file: {err:?}");
+ return;
+ }
+ };
- if let Err(err) = res {
- warn!("error saving screenshot image: {err:?}");
+ let w = std::io::BufWriter::new(file);
+ if let Err(err) = write_png_rgba8(w, size.w as u32, size.h as u32, &pixels) {
+ warn!("error encoding screenshot image: {err:?}");
return;
}
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)
+}