From de5538f83ba2f938259b9289cae33ddc9a73c352 Mon Sep 17 00:00:00 2001
From: lanyeeee <1210347077@qq.com>
Date: Wed, 11 Dec 2024 15:43:34 +0800
Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E5=8E=BB?=
=?UTF-8?q?=E6=B0=B4=E5=8D=B0=E7=AE=97=E6=B3=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src-tauri/src/commands/remove_watermark.rs | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src-tauri/src/commands/remove_watermark.rs b/src-tauri/src/commands/remove_watermark.rs
index 7f3185e..0372eff 100644
--- a/src-tauri/src/commands/remove_watermark.rs
+++ b/src-tauri/src/commands/remove_watermark.rs
@@ -201,9 +201,9 @@ fn remove_image_watermark(black: &RgbImage, white: &RgbImage, img: &mut RgbImage
let [white_r, white_g, white_b] = white.get_pixel(x, y).0;
// 计算去除水印后的像素点值,将f32转换为u8自带clamp功能
let watermark_removed_pixel = Rgb([
- ((img_r as f32 - black_r as f32) / ((white_r - black_r) as f32 / 255.0)) as u8,
- ((img_g as f32 - black_g as f32) / ((white_g - black_g) as f32 / 255.0)) as u8,
- ((img_b as f32 - black_b as f32) / ((white_b - black_b) as f32 / 255.0)) as u8,
+ ((img_r as f64 - black_r as f64) / ((white_r - black_r) as f64 / 255.0)).round() as u8,
+ ((img_g as f64 - black_g as f64) / ((white_g - black_g) as f64 / 255.0)).round() as u8,
+ ((img_b as f64 - black_b as f64) / ((white_b - black_b) as f64 / 255.0)).round() as u8,
]);
// 将去除水印后的像素点值写入到图片缓冲区中
*img_pixel = watermark_removed_pixel;
From db09494f38be4fe71526d56028710cc9e011aa14 Mon Sep 17 00:00:00 2001
From: lanyeeee <1210347077@qq.com>
Date: Wed, 11 Dec 2024 15:44:01 +0800
Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=E7=94=A8`parking=5Flot`=E6=9B=BF?=
=?UTF-8?q?=E6=8D=A2`std`=E9=94=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src-tauri/Cargo.lock | 1 +
src-tauri/Cargo.toml | 1 +
src-tauri/src/commands/generate_background.rs | 11 +++----
src-tauri/src/commands/get_config.rs | 6 ++--
src-tauri/src/commands/remove_watermark.rs | 7 ++--
src-tauri/src/commands/save_config.rs | 6 ++--
src-tauri/src/extensions.rs | 32 -------------------
src-tauri/src/main.rs | 3 +-
8 files changed, 16 insertions(+), 51 deletions(-)
diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock
index 7cb4a78..25ac2e1 100644
--- a/src-tauri/Cargo.lock
+++ b/src-tauri/Cargo.lock
@@ -278,6 +278,7 @@ dependencies = [
"image",
"imagesize",
"jpeg-encoder",
+ "parking_lot",
"path-slash",
"qrcode",
"rayon",
diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml
index 39587ed..8e277ed 100644
--- a/src-tauri/Cargo.toml
+++ b/src-tauri/Cargo.toml
@@ -38,6 +38,7 @@ dirs = { version = "5.0" }
path-slash = { version = "0.2.1" }
tokio = { version = "1", features = ["full"] }
bytes = { version = "1.7.1" }
+parking_lot = { version = "0.12.3", features = ["send_guard"] }
[profile.release]
strip = true # Automatically strip symbols from the binary.
diff --git a/src-tauri/src/commands/generate_background.rs b/src-tauri/src/commands/generate_background.rs
index 9d38109..06a15f7 100644
--- a/src-tauri/src/commands/generate_background.rs
+++ b/src-tauri/src/commands/generate_background.rs
@@ -1,15 +1,14 @@
use std::path::PathBuf;
-use std::sync::Mutex;
use anyhow::Context;
use image::RgbImage;
+use parking_lot::Mutex;
use path_slash::PathBufExt;
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
use tauri::AppHandle;
use walkdir::WalkDir;
use crate::errors::CommandResult;
-use crate::extensions::IgnoreLockPoison;
use crate::types::{CommandResponse, RectData};
use crate::utils;
@@ -45,8 +44,8 @@ pub fn generate_background(
// 用于记录是否找到了黑色背景和白色背景的水印图片
let black_status: Mutex