Skip to content

Commit 93960d2

Browse files
authored
Merge pull request #954 from moschmdt/fix-auto-adjust
Auto adjust image improvements: Overexposure reduction and removes UI thread block
2 parents ae255a9 + fe372ef commit 93960d2

2 files changed

Lines changed: 222 additions & 168 deletions

File tree

src-tauri/src/file_management.rs

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2445,16 +2445,33 @@ pub async fn apply_auto_adjustments_to_paths(
24452445
let enable_xmp_sync = settings.enable_xmp_sync.unwrap_or(false);
24462446
let create_xmp_if_missing = settings.create_xmp_if_missing.unwrap_or(false);
24472447

2448+
let state = app_handle.state::<AppState>();
2449+
let thumb_cache_dir = match resolve_thumbnail_cache_dir(&app_handle) {
2450+
Ok(dir) => dir,
2451+
Err(e) => {
2452+
log::warn!("Unable to initialize thumbnail cache directory: {}", e);
2453+
for path in &paths {
2454+
emit_thumbnail_cache_setup_error(&app_handle, path, &e);
2455+
}
2456+
for _ in 0..paths.len() {
2457+
increment_thumbnail_progress(&state, &app_handle);
2458+
}
2459+
return;
2460+
}
2461+
};
2462+
2463+
let gpu_context = gpu_processing::get_or_init_gpu_context(&state, &app_handle).ok();
2464+
24482465
paths.par_iter().for_each(|path| {
2449-
let result: Result<(), String> = (|| {
2466+
let loaded_image: Option<DynamicImage> = (|| -> Result<DynamicImage, String> {
24502467
let (source_path, sidecar_path) = parse_virtual_path(path);
24512468
let source_path_str = source_path.to_string_lossy().to_string();
24522469

24532470
let file_bytes = fs::read(&source_path).map_err(|e| e.to_string())?;
24542471
let image = image_loader::load_base_image_from_bytes(
24552472
&file_bytes,
24562473
&source_path_str,
2457-
false,
2474+
true,
24582475
highlight_compression,
24592476
linear_mode.clone(),
24602477
None,
@@ -2511,44 +2528,24 @@ pub async fn apply_auto_adjustments_to_paths(
25112528
if enable_xmp_sync {
25122529
sync_metadata_to_xmp(&source_path, &existing_metadata, create_xmp_if_missing);
25132530
}
2514-
Ok(())
2515-
})();
2516-
if let Err(e) = result {
2517-
eprintln!("Failed to apply auto adjustments to {}: {}", path, e);
2518-
}
2519-
});
2520-
2521-
let state = app_handle.state::<AppState>();
2522-
let thumb_cache_dir = match resolve_thumbnail_cache_dir(&app_handle) {
2523-
Ok(dir) => dir,
2524-
Err(e) => {
2525-
log::warn!("Unable to initialize thumbnail cache directory: {}", e);
2526-
for path in &paths {
2527-
emit_thumbnail_cache_setup_error(&app_handle, path, &e);
2528-
}
2529-
for _ in 0..paths.len() {
2530-
increment_thumbnail_progress(&state, &app_handle);
2531-
}
2532-
return;
2533-
}
2534-
};
2531+
Ok(image)
2532+
})()
2533+
.map_err(|e| eprintln!("Failed to apply auto adjustments to {}: {}", path, e))
2534+
.ok();
25352535

2536-
let gpu_context = gpu_processing::get_or_init_gpu_context(&state, &app_handle).ok();
2537-
2538-
paths.par_iter().for_each(|path_str| {
25392536
let result = generate_single_thumbnail_and_cache(
2540-
path_str,
2537+
path,
25412538
&thumb_cache_dir,
25422539
gpu_context.as_ref(),
2543-
None,
2540+
loaded_image.as_ref(),
25442541
true,
25452542
&app_handle,
25462543
);
25472544

25482545
if let Some((thumbnail_data, rating)) = result {
25492546
let _ = app_handle.emit(
25502547
"thumbnail-generated",
2551-
serde_json::json!({ "path": path_str, "data": thumbnail_data, "rating": rating }),
2548+
serde_json::json!({ "path": path, "data": thumbnail_data, "rating": rating }),
25522549
);
25532550
}
25542551

0 commit comments

Comments
 (0)