mirror of
https://github.com/YaLTeR/niri.git
synced 2024-09-11 12:35:58 +03:00
Use png crate directly instead of image
Reduce dependencies a bit.
This commit is contained in:
parent
c6ec36f422
commit
909a45db6f
43
Cargo.lock
generated
43
Cargo.lock
generated
@ -573,12 +573,6 @@ version = "0.5.1"
|
||||
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"
|
||||
@ -1118,20 +1112,6 @@ dependencies = [
|
||||
"objc2",
|
||||
]
|
||||
|
||||
[[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"
|
||||
@ -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",
|
||||
@ -1620,27 +1600,6 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[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"
|
||||
|
@ -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"
|
||||
|
32
src/niri.rs
32
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;
|
||||
}
|
||||
|
||||
|
16
src/utils.rs
16
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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user