Skip to content

Commit b50647f

Browse files
authored
Merge pull request #319 from riccio8/main
Optimization for generating thumbnails
2 parents f63d73e + 8fd2fbc commit b50647f

File tree

7 files changed

+161
-27
lines changed

7 files changed

+161
-27
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.lock

Lines changed: 61 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ tauri-plugin-process = "2"
4242
tauri-plugin-os = "2.3.1"
4343
raw-window-handle = "0.6.2"
4444
os_info = "3"
45+
log = "0.4"
46+
log-panics = {version ="2.1.0", features = ["backtrace"] }
47+
fern = "0.7"
4548
little_exif = "0.6"
4649
chrono = "0.4"
4750
tokenizers = "0.22.0"
@@ -52,6 +55,8 @@ nalgebra = "0.34.0"
5255
rand = "0.9"
5356
tauri-plugin-shell = "2.3.1"
5457
tempfile = "3.22.0"
58+
num_cpus = "1.17.0"
59+
mimalloc = "0.1.48"
5560
image_hasher = "3.0.0"
5661
regex = "1.11.2"
5762

src-tauri/src/file_management.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ use image::codecs::jpeg::JpegEncoder;
1616
use image::{DynamicImage, GenericImageView, ImageBuffer, Luma};
1717
use little_exif::exif_tag::ExifTag;
1818
use little_exif::metadata::Metadata;
19+
use num_cpus;
20+
use rayon::ThreadPoolBuilder;
1921
use rayon::prelude::*;
2022
use serde::{Deserialize, Serialize};
2123
use serde_json::Value;
@@ -613,6 +615,10 @@ pub fn generate_thumbnails_progressive(
613615
.store(false, Ordering::SeqCst);
614616
let cancellation_token = state.thumbnail_cancellation_token.clone();
615617

618+
let pool = ThreadPoolBuilder::new()
619+
.num_threads(num_cpus::get_physical() - 1)
620+
.build()
621+
.unwrap();
616622
let cache_dir = app_handle
617623
.path()
618624
.app_cache_dir()
@@ -626,7 +632,7 @@ pub fn generate_thumbnails_progressive(
626632
let total_count = paths.len();
627633
let completed_count = Arc::new(AtomicUsize::new(0));
628634

629-
thread::spawn(move || {
635+
pool.spawn(move || {
630636
let state = app_handle_clone.state::<AppState>();
631637
let gpu_context = gpu_processing::get_or_init_gpu_context(&state).ok();
632638

src-tauri/src/gpu_processing.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use bytemuck;
44
use image::{DynamicImage, GenericImageView, ImageBuffer, Luma, Rgba};
55
use wgpu::util::{DeviceExt, TextureDataOrder};
66

7-
use crate::{AppState, GpuImageCache};
87
use crate::image_processing::{AllAdjustments, GpuContext};
98
use crate::lut_processing::Lut;
9+
use crate::{AppState, GpuImageCache};
1010

1111
pub fn get_or_init_gpu_context(state: &tauri::State<AppState>) -> Result<GpuContext, String> {
1212
let mut context_lock = state.gpu_context.lock().unwrap();
@@ -450,7 +450,8 @@ pub fn process_and_get_dynamic_image(
450450
let mut cache_lock = state.gpu_image_cache.lock().unwrap();
451451

452452
if let Some(cache) = &*cache_lock {
453-
if cache.transform_hash != transform_hash || cache.width != width || cache.height != height {
453+
if cache.transform_hash != transform_hash || cache.width != width || cache.height != height
454+
{
454455
*cache_lock = None;
455456
}
456457
}
@@ -503,4 +504,4 @@ pub fn process_and_get_dynamic_image(
503504
let img_buf = ImageBuffer::<Rgba<u8>, Vec<u8>>::from_raw(width, height, processed_pixels)
504505
.ok_or("Failed to create image buffer from GPU data")?;
505506
Ok(DynamicImage::ImageRgba8(img_buf))
506-
}
507+
}

src-tauri/src/image_processing.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,11 @@ fn get_global_adjustments_from_json(js_adjustments: &serde_json::Value) -> Globa
553553
SCALES.chromatic_aberration,
554554
None,
555555
),
556-
show_clipping: if js_adjustments["showClipping"].as_bool().unwrap_or(false) { 1 } else { 0 },
556+
show_clipping: if js_adjustments["showClipping"].as_bool().unwrap_or(false) {
557+
1
558+
} else {
559+
0
560+
},
557561
_pad_ca1: 0.0,
558562

559563
enable_negative_conversion: if neg_conv_enabled { 1 } else { 0 },
@@ -1252,4 +1256,4 @@ pub fn calculate_auto_adjustments(
12521256
let results = perform_auto_analysis(&original_image);
12531257

12541258
Ok(auto_results_to_json(&results))
1255-
}
1259+
}

0 commit comments

Comments
 (0)