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;
|
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(
|
pub fn workspace_bgs_from_output_image_dir(
|
||||||
dir_path: impl AsRef<Path>,
|
dir_path: impl AsRef<Path>,
|
||||||
slot_pool: &mut SlotPool,
|
slot_pool: &mut SlotPool,
|
||||||
format: wl_shm::Format,
|
format: wl_shm::Format,
|
||||||
brightness: i32,
|
|
||||||
contrast: f32,
|
|
||||||
width: u32,
|
width: u32,
|
||||||
height: u32,
|
height: u32,
|
||||||
|
color_transform: ColorTransform,
|
||||||
) -> anyhow::Result<Vec<WorkspaceBackground>> {
|
) -> anyhow::Result<Vec<WorkspaceBackground>> {
|
||||||
let mut buffers = Vec::new();
|
let mut buffers = Vec::new();
|
||||||
let mut resizer = Resizer::new();
|
let mut resizer = Resizer::new();
|
||||||
|
@ -45,11 +51,10 @@ pub fn workspace_bgs_from_output_image_dir(
|
||||||
entry_result,
|
entry_result,
|
||||||
slot_pool,
|
slot_pool,
|
||||||
format,
|
format,
|
||||||
brightness,
|
|
||||||
contrast,
|
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
stride,
|
stride,
|
||||||
|
color_transform,
|
||||||
&mut resizer
|
&mut resizer
|
||||||
) {
|
) {
|
||||||
Ok(Some(workspace_bg)) => buffers.push(workspace_bg),
|
Ok(Some(workspace_bg)) => buffers.push(workspace_bg),
|
||||||
|
@ -71,11 +76,10 @@ fn workspace_bg_from_file(
|
||||||
dir_entry_result: io::Result<DirEntry>,
|
dir_entry_result: io::Result<DirEntry>,
|
||||||
slot_pool: &mut SlotPool,
|
slot_pool: &mut SlotPool,
|
||||||
format: wl_shm::Format,
|
format: wl_shm::Format,
|
||||||
brightness: i32,
|
|
||||||
contrast: f32,
|
|
||||||
width: u32,
|
width: u32,
|
||||||
height: u32,
|
height: u32,
|
||||||
stride: usize,
|
stride: usize,
|
||||||
|
color_transform: ColorTransform,
|
||||||
resizer: &mut Resizer,
|
resizer: &mut Resizer,
|
||||||
) -> anyhow::Result<Option<WorkspaceBackground>> {
|
) -> anyhow::Result<Option<WorkspaceBackground>> {
|
||||||
let entry = dir_entry_result.context("Failed to read direectory")?;
|
let entry = dir_entry_result.context("Failed to read direectory")?;
|
||||||
|
@ -91,11 +95,6 @@ fn workspace_bg_from_file(
|
||||||
stride.try_into().unwrap(),
|
stride.try_into().unwrap(),
|
||||||
format,
|
format,
|
||||||
).context("Failed to create Wayland shared memory buffer")?;
|
).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(
|
load_wallpaper(
|
||||||
&path,
|
&path,
|
||||||
&mut canvas[..stride * height as usize],
|
&mut canvas[..stride * height as usize],
|
||||||
|
@ -109,13 +108,6 @@ fn workspace_bg_from_file(
|
||||||
Ok(Some(WorkspaceBackground { workspace_name, buffer }))
|
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(
|
fn load_wallpaper(
|
||||||
path: &Path,
|
path: &Path,
|
||||||
dst: &mut [u8],
|
dst: &mut [u8],
|
||||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -40,6 +40,7 @@ use smithay_client_toolkit::reexports::protocols
|
||||||
use crate::{
|
use crate::{
|
||||||
cli::{Cli, PixelFormat},
|
cli::{Cli, PixelFormat},
|
||||||
compositors::{Compositor, ConnectionTask, WorkspaceVisible},
|
compositors::{Compositor, ConnectionTask, WorkspaceVisible},
|
||||||
|
image::ColorTransform,
|
||||||
poll::{Poll, Waker},
|
poll::{Poll, Waker},
|
||||||
signal::SignalPipe,
|
signal::SignalPipe,
|
||||||
wayland::BackgroundLayer,
|
wayland::BackgroundLayer,
|
||||||
|
@ -57,8 +58,7 @@ pub struct State {
|
||||||
pub pixel_format: Option<wl_shm::Format>,
|
pub pixel_format: Option<wl_shm::Format>,
|
||||||
pub background_layers: Vec<BackgroundLayer>,
|
pub background_layers: Vec<BackgroundLayer>,
|
||||||
pub compositor_connection_task: ConnectionTask,
|
pub compositor_connection_task: ConnectionTask,
|
||||||
pub brightness: i32,
|
pub color_transform: ColorTransform,
|
||||||
pub contrast: f32,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
|
@ -103,6 +103,13 @@ fn run() -> anyhow::Result<()> {
|
||||||
|
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
let wallpaper_dir = Path::new(&cli.wallpaper_dir).canonicalize().unwrap();
|
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
|
// Initialize wayland client
|
||||||
|
@ -145,8 +152,7 @@ fn run() -> anyhow::Result<()> {
|
||||||
compositor,
|
compositor,
|
||||||
tx.clone(), Arc::clone(&waker)
|
tx.clone(), Arc::clone(&waker)
|
||||||
),
|
),
|
||||||
brightness: cli.brightness.unwrap_or(0),
|
color_transform,
|
||||||
contrast: cli.contrast.unwrap_or(0.0),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
event_queue.roundtrip(&mut state).unwrap();
|
event_queue.roundtrip(&mut state).unwrap();
|
||||||
|
|
|
@ -276,10 +276,9 @@ logical size: {}x{}, transform: {:?}",
|
||||||
&output_wallpaper_dir,
|
&output_wallpaper_dir,
|
||||||
&mut shm_slot_pool,
|
&mut shm_slot_pool,
|
||||||
pixel_format,
|
pixel_format,
|
||||||
self.brightness,
|
|
||||||
self.contrast,
|
|
||||||
width.try_into().unwrap(),
|
width.try_into().unwrap(),
|
||||||
height.try_into().unwrap()
|
height.try_into().unwrap(),
|
||||||
|
self.color_transform,
|
||||||
) {
|
) {
|
||||||
Ok(workspace_bgs) => {
|
Ok(workspace_bgs) => {
|
||||||
debug!(
|
debug!(
|
||||||
|
|
Loading…
Add table
Reference in a new issue