Pi66

Home | Repos | About | Blog | Gaza

walrs
pywal but if its Fast-Minimal-Simple
git clone https://git.pi66.xyz/walrs

About | Files | Commits | Refs | License


add saturation & brightness options

Author: pixel
Date: 2025-03-28 15:20
commit: 2465c85f

Stat

M Cargo.lock 2 +1 -1
M Cargo.toml 4 +2 -2
M src/get_colors.rs 12 +6 -6
M src/main.rs 16 +15 -1

Diff

diff --git a/Cargo.lock b/Cargo.lock
index 6f3c594..3327018 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1061,7 +1061,7 @@ checksum = "852e951cb7832cb45cb1169900d19760cfa39b82bc0ea9c0e5a14ae88411c98b"

[[package]] name = "walrs" -version = "1.0.1" +version = "1.0.2" dependencies = [ "clap", "color-thief", diff --git a/Cargo.toml b/Cargo.toml index 86a5f4c..91150a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "walrs" ...

Show all

diff --git a/Cargo.lock b/Cargo.lock
index 6f3c594..3327018 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1061,7 +1061,7 @@ checksum = "852e951cb7832cb45cb1169900d19760cfa39b82bc0ea9c0e5a14ae88411c98b"

[[package]] name = "walrs" -version = "1.0.1" +version = "1.0.2" dependencies = [ "clap", "color-thief", diff --git a/Cargo.toml b/Cargo.toml index 86a5f4c..91150a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "walrs" -version = "1.0.1" +version = "1.0.2" edition = "2024" description = "walrs is a fast color scheme generator." -license = "MIT" +license = "GPL" repository = "https://github.com/pixel2175/walrs"

[dependencies] diff --git a/src/get_colors.rs b/src/get_colors.rs index 1d85e4a..7c27d51 100644 --- a/src/get_colors.rs +++ b/src/get_colors.rs @@ -6,7 +6,7 @@ use std::process::exit; use std::fs::read; use crate::utils::warning;

-fn adjust_rgb(r: u8, g: u8, b: u8, brightness: i16, saturation: i16) -> (u8, u8, u8) { +fn adjust_rgb(r: u8, g: u8, b: u8, brightness: i8, saturation: i8) -> (u8, u8, u8) { let avg = ((r as u16 + g as u16 + b as u16) / 3) as f32;

 let r = ((r as f32 - avg) * (saturation as f32 / 100.0) + avg + brightness as f32).clamp(0.0, 255.0);

@@ -32,11 +32,11 @@ fn to_gray(r: u8, g: u8, b: u8, v: Option<u8>) -> (u8, u8, u8) { } }

-fn generate_variation(color: (u8, u8, u8), offset: i16) -> (u8, u8, u8) { +fn generate_variation(color: (u8, u8, u8), offset: i8) -> (u8, u8, u8) { adjust_rgb(color.0, color.1, color.2, offset, 50) }

-pub fn get_colors(image_path: &str,send:bool) -> (Vec<(u8,u8,u8)>,u8){ +pub fn get_colors(image_path: &str,send:bool,brightness: Option<i8>,saturation: Option<i8> ) -> (Vec<(u8,u8,u8)>,u8){

 let image = match image::open(image&#95;path) {
     Ok(img) =&#62; img,

@@ -80,7 +80,7 @@ pub fn get_colors(image_path: &str,send:bool) -> (Vec<(u8,u8,u8)>,u8){ let mut i = 0; while collect_rgb.len() <= 21 { let base = collect_rgb[i % collect_rgb.len()]; - let variation = generate_variation(base, 10 * (i as i16 + 1)); + let variation = generate_variation(base, 10 * (i as i8 + 1)); collect_rgb.push(variation); i += 1; } @@ -97,12 +97,12 @@ pub fn get_colors(image_path: &str,send:bool) -> (Vec<(u8,u8,u8)>,u8){

 for color in colors{
     let  (mut r, mut g, mut b) = collect&#95;rgb&#91;color&#93;;

- (r,g,b) = adjust_rgb(r, g, b,-10,80); + (r,g,b) = adjust_rgb(r, g, b,brightness.unwrap_or(0),saturation.unwrap_or(0) + 80); done.push((r,g,b)); }

 let (mut r,mut g,mut b) =  collect&#95;rgb&#91;20&#93;;

- (r,g,b) = adjust_rgb(r,g,b,60,-10); + (r,g,b) = adjust_rgb(r,g,b,70,10); (r,g,b) = to_gray(r, g, b, Some(2)); done[7] = (r,g,b); done[15] = (r,g,b); diff --git a/src/main.rs b/src/main.rs index b8bd192..0d95034 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,6 +27,20 @@ struct Arg { /// set quit mode (no output) #[arg(short = 'q', action = ArgAction::SetTrue)] quit: bool, + + + /// specify the saturation value + #[arg(short = 's')] + saturation: Option<i8>, + + + /// specify the brightness value + #[arg(short = 'b')] + brightness: Option<i8>, + + + + }

fn main() { @@ -63,7 +77,7 @@ fn main() { } };

- let palette = get_colors(&image_path, !arg.quit); + let palette = get_colors(&image_path, !arg.quit,arg.brightness,arg.saturation); info("Generate", "generate colors", !arg.quit);

 create&#95;template(palette, &#38;image&#95;path);

// Created by Pi66

// Copyright ©Pi66 2026