Refactor the handling of image color transform parameters
This commit is contained in:
parent
0972f05b6c
commit
8b8d2cbaf7
3 changed files with 22 additions and 25 deletions
28
src/image.rs
28
src/image.rs
|
@ -18,14 +18,20 @@ use smithay_client_toolkit::reexports::client::protocol::wl_shm;
|
|||
|
||||
use crate::wayland::WorkspaceBackground;
|
||||
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
pub enum ColorTransform {
|
||||
// Levels { input_max: u8, input_min: u8, output_max: u8, output_min: u8 },
|
||||
Legacy { brightness: i32, contrast: f32 },
|
||||
None,
|
||||
}
|
||||
|
||||
pub fn workspace_bgs_from_output_image_dir(
|
||||
dir_path: impl AsRef<Path>,
|
||||
slot_pool: &mut SlotPool,
|
||||
format: wl_shm::Format,
|
||||
brightness: i32,
|
||||
contrast: f32,
|
||||
width: u32,
|
||||
height: u32,
|
||||
color_transform: ColorTransform,
|
||||
) -> anyhow::Result<Vec<WorkspaceBackground>> {
|
||||
let mut buffers = Vec::new();
|
||||
let mut resizer = Resizer::new();
|
||||
|
@ -45,11 +51,10 @@ pub fn workspace_bgs_from_output_image_dir(
|
|||
entry_result,
|
||||
slot_pool,
|
||||
format,
|
||||
brightness,
|
||||
contrast,
|
||||
width,
|
||||
height,
|
||||
stride,
|
||||
color_transform,
|
||||
&mut resizer
|
||||
) {
|
||||
Ok(Some(workspace_bg)) => buffers.push(workspace_bg),
|
||||
|
@ -71,11 +76,10 @@ fn workspace_bg_from_file(
|
|||
dir_entry_result: io::Result<DirEntry>,
|
||||
slot_pool: &mut SlotPool,
|
||||
format: wl_shm::Format,
|
||||
brightness: i32,
|
||||
contrast: f32,
|
||||
width: u32,
|
||||
height: u32,
|
||||
stride: usize,
|
||||
color_transform: ColorTransform,
|
||||
resizer: &mut Resizer,
|
||||
) -> anyhow::Result<Option<WorkspaceBackground>> {
|
||||
let entry = dir_entry_result.context("Failed to read direectory")?;
|
||||
|
@ -91,11 +95,6 @@ fn workspace_bg_from_file(
|
|||
stride.try_into().unwrap(),
|
||||
format,
|
||||
).context("Failed to create Wayland shared memory buffer")?;
|
||||
let color_transform = if brightness == 0 && contrast == 0.0 {
|
||||
ColorTransform::None
|
||||
} else {
|
||||
ColorTransform::Legacy { brightness, contrast }
|
||||
};
|
||||
load_wallpaper(
|
||||
&path,
|
||||
&mut canvas[..stride * height as usize],
|
||||
|
@ -109,13 +108,6 @@ fn workspace_bg_from_file(
|
|||
Ok(Some(WorkspaceBackground { workspace_name, buffer }))
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
pub enum ColorTransform {
|
||||
// Levels { input_max: u8, input_min: u8, output_max: u8, output_min: u8 },
|
||||
Legacy { brightness: i32, contrast: f32 },
|
||||
None,
|
||||
}
|
||||
|
||||
fn load_wallpaper(
|
||||
path: &Path,
|
||||
dst: &mut [u8],
|
||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -40,6 +40,7 @@ use smithay_client_toolkit::reexports::protocols
|
|||
use crate::{
|
||||
cli::{Cli, PixelFormat},
|
||||
compositors::{Compositor, ConnectionTask, WorkspaceVisible},
|
||||
image::ColorTransform,
|
||||
poll::{Poll, Waker},
|
||||
signal::SignalPipe,
|
||||
wayland::BackgroundLayer,
|
||||
|
@ -57,8 +58,7 @@ pub struct State {
|
|||
pub pixel_format: Option<wl_shm::Format>,
|
||||
pub background_layers: Vec<BackgroundLayer>,
|
||||
pub compositor_connection_task: ConnectionTask,
|
||||
pub brightness: i32,
|
||||
pub contrast: f32,
|
||||
pub color_transform: ColorTransform,
|
||||
}
|
||||
|
||||
impl State {
|
||||
|
@ -103,6 +103,13 @@ fn run() -> anyhow::Result<()> {
|
|||
|
||||
let cli = Cli::parse();
|
||||
let wallpaper_dir = Path::new(&cli.wallpaper_dir).canonicalize().unwrap();
|
||||
let brightness = cli.brightness.unwrap_or(0);
|
||||
let contrast = cli.contrast.unwrap_or(0.0);
|
||||
let color_transform = if brightness == 0 && contrast == 0.0 {
|
||||
ColorTransform::None
|
||||
} else {
|
||||
ColorTransform::Legacy { brightness, contrast }
|
||||
};
|
||||
|
||||
// ********************************
|
||||
// Initialize wayland client
|
||||
|
@ -145,8 +152,7 @@ fn run() -> anyhow::Result<()> {
|
|||
compositor,
|
||||
tx.clone(), Arc::clone(&waker)
|
||||
),
|
||||
brightness: cli.brightness.unwrap_or(0),
|
||||
contrast: cli.contrast.unwrap_or(0.0),
|
||||
color_transform,
|
||||
};
|
||||
|
||||
event_queue.roundtrip(&mut state).unwrap();
|
||||
|
|
|
@ -276,10 +276,9 @@ logical size: {}x{}, transform: {:?}",
|
|||
&output_wallpaper_dir,
|
||||
&mut shm_slot_pool,
|
||||
pixel_format,
|
||||
self.brightness,
|
||||
self.contrast,
|
||||
width.try_into().unwrap(),
|
||||
height.try_into().unwrap()
|
||||
height.try_into().unwrap(),
|
||||
self.color_transform,
|
||||
) {
|
||||
Ok(workspace_bgs) => {
|
||||
debug!(
|
||||
|
|
Loading…
Add table
Reference in a new issue