From a1e6c6e5fbaa31857b312e488e71d3d92dc5d47a Mon Sep 17 00:00:00 2001 From: Ivan Li Date: Sun, 2 Apr 2023 18:36:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=81=AF=E6=9D=A1=E6=AE=B5=E9=95=BF?= =?UTF-8?q?=E5=BA=A6=E4=B8=BA0=E6=97=B6=EF=BC=8C=E5=B4=A9=E6=BA=83?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/src/screenshot.rs | 6 ++++++ src/components/led-strip-parts-sorter.tsx | 11 +++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src-tauri/src/screenshot.rs b/src-tauri/src/screenshot.rs index 39e799d..9332566 100644 --- a/src-tauri/src/screenshot.rs +++ b/src-tauri/src/screenshot.rs @@ -82,6 +82,10 @@ impl Screenshot { leds: usize, single_axis_points: usize, ) -> Vec { + if leds == 0 { + return vec![]; + } + let cell_size_x = length as f64 / single_axis_points as f64 / leds as f64; let cell_size_y = width / single_axis_points; @@ -100,6 +104,7 @@ impl Screenshot { .map(|&x| point_y_list.iter().map(move |&y| (x, y))) .flatten() .collect(); + points .chunks(single_axis_points * single_axis_points) .into_iter() @@ -159,6 +164,7 @@ impl Screenshot { let mut b = 0.0; let len = led_points.len() as f64; for (x, y) in led_points { + // log::info!("x: {}, y: {}, bytes_per_row: {}", x, y, bytes_per_row); let position = x * 4 + y * bytes_per_row; b += bitmap[position] as f64; g += bitmap[position + 1] as f64; diff --git a/src/components/led-strip-parts-sorter.tsx b/src/components/led-strip-parts-sorter.tsx index 2751de7..4773852 100644 --- a/src/components/led-strip-parts-sorter.tsx +++ b/src/components/led-strip-parts-sorter.tsx @@ -190,11 +190,12 @@ const SorterResult: Component = () => { let c1 = `rgb(${Math.floor(colors[i * 3] * 0.8)}, ${Math.floor( colors[i * 3 + 1] * 0.8, )}, ${Math.floor(colors[i * 3 + 2] * 0.8)})`; - let c2 = `rgb(${Math.floor(colors[i * 3] * 1.2)}, ${Math.floor( - colors[i * 3 + 1] * 1.2, - )}, ${Math.floor(colors[i * 3 + 2] * 1.2)})`; + let c2 = `rgb(${Math.min(Math.floor(colors[i * 3] * 1.2), 255)}, ${Math.min( + Math.floor(colors[i * 3 + 1] * 1.2), + 255, + )}, ${Math.min(Math.floor(colors[i * 3 + 2] * 1.2), 255)})`; - return `linear-gradient(70deg, ${c1}, ${c2})`; + return `linear-gradient(70deg, ${c1} 10%, ${c2})`; }); console.log(fullLeds); setFullLeds(fullLeds); @@ -220,8 +221,6 @@ const SorterResult: Component = () => { }; export const LedStripPartsSorter: Component = () => { - const context = createContext(); - return (