Pi66

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

← back to log

feat: improve the colors and make them more saturated

author: pixel2175
date: 2025-06-24 03:55
hash: ea41abcecfa83ad743896fb6a194a6639b669e1f

Diffstat:

M

src/get_colors.rs
19 ++++++++++++++++--------------

M

src/main.rs
4 +++---
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
diff --git a/src/get_colors.rs b/src/get_colors.rs
index 10ebe2b..8b83049 100644
--- a/src/get_colors.rs
+++ b/src/get_colors.rs
@@ -7,7 +7,8 @@ use std::collections::HashSet;
 use std::fs::read;
 use std::process::exit;

-fn adjust_rgb(r: u8, g: u8, b: u8, brightness: i8, saturation: i8) -> (u8, u8, u8) {
+fn adjust_rgb(r: u8, g: u8, b: u8, brightness: i16, saturation: i16) -> (u8, u8, u8) {
+    let saturation = saturation + 50;
     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)
@@ -32,15 +33,15 @@ fn to_gray(r: u8, g: u8, b: u8, v: f32) -> (u8, u8, u8) {
     )
 }

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

 pub fn get_colors(
     image_path: &str,
     send: bool,
-    brightness: Option<i8>,
-    saturation: Option<i8>,
+    brightness: Option<i16>,
+    saturation: Option<i16>,
 ) -> (Vec<(u8, u8, u8)>, u8) {
     let core_image = match image::open(image_path) {
         Ok(img) => img,
@@ -120,7 +121,7 @@ pub fn get_colors(
     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 i8 + 1));
+        let variation = generate_variation(base, 10 * (i as i16 + 1));
         collect_rgb.push(variation);
         i += 1;
     }
@@ -141,15 +142,15 @@ pub fn get_colors(
             r,
             g,
             b,
-            brightness.unwrap_or(0) - 15,
-            saturation.unwrap_or(0) + 80,
+            brightness.unwrap_or(0),
+            saturation.unwrap_or(0) + 90,
         );
         done.push((r, g, b));
     }

     let (mut r, mut g, mut b) = collect_rgb[20];
-    (r, g, b) = adjust_rgb(r, g, b, 40, 60);
-    (r, g, b) = to_gray(r, g, b, 0.4);
+    (r, g, b) = adjust_rgb(r, g, b, 40, 80);
+    (r, g, b) = to_gray(r, g, b, 0.55);
     done[7] = (r, g, b);
     done[15] = (r, g, b);
     (done, *alpha)
diff --git a/src/main.rs b/src/main.rs
index a1ee538..0e27c11 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -57,7 +57,7 @@ struct Arg {
         long = "saturation",
         description = "set saturation value (-128 to 127)"
     )]
-    saturation: Option<i8>,
+    saturation: Option<i16>,

     #[argh(
         option,
@@ -65,7 +65,7 @@ struct Arg {
         long = "brightness",
         description = "set brightness value (-128 to 127)"
     )]
-    brightness: Option<i8>,
+    brightness: Option<i16>,

     #[argh(
         switch,