feat: Auto apply lens correction feature (with global settings) - #1557
Open
air01a wants to merge 2 commits into
Open
feat: Auto apply lens correction feature (with global settings)#1557air01a wants to merge 2 commits into
air01a wants to merge 2 commits into
Conversation
Camera-generated JPEGs typically already have the manufacturer's own lens correction (distortion/vignette) baked in, so re-applying ours on top would double-correct. Restrict both the per-image editor auto-apply and the bulk auto_apply_lens_correction_to_paths command to RAW files. The manual Lens button is unaffected and still works on any format.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Automatic lens correction can now be applied automatically to previously unedited photos.
When enabled, the app detects the lens from EXIF data and applies distortion, vignetting, and chromatic aberration corrections.
Fixed-lens cameras are also supported through camera-body and Lensfun profile detection (previously, the camera was not recognized as the profile was based only on lens profile, not camera).
Corrections can be applied in the background when browsing a folder, without opening each photo in the editor.
A new global setting under Settings / Lenses controls the feature and is disabled by default.
Type of Change
Changes Made
New global setting - autoApplyLensCorrection
A new option is available under Settings → Lenses and is disabled by default. The setting has been added to AppSettings on both the Rust (app_settings.rs) and TypeScript (AppProperties.tsx) sides, with a corresponding toggle in SettingsPanel.tsx.
Automatic correction when opening a photo for the first time (useImageLoader.ts)
When automatic lens correction is enabled, opening a photo with no existing edit history automatically detects the lens from its EXIF metadata (autodetect_lens -> get_lens_distortion_params) and applies distortion, vignetting, and chromatic aberration corrections. This initial correction is applied transparently and does not create an undo-history entry.
Fixed-lens camera support (lens_correction.rs, file_management.rs)
Some fixed-lens cameras, such as the Sony RX10 *, do not populate the EXIF LensModel field. Lens detection now handles these cases by falling back to the camera body model and resolving the corresponding Lensfun profile through the camera mount.
This fallback is used consistently wherever lens detection occurs: in the autodetect_lens command, during per-save validation (resolve_lens_params_in_adjustments), and by the new bulk-processing command described below.
A new find_lens_by_camera_mount helper has also been added, together with two Rust unit tests validating the behavior against the actual Lensfun database.
A new auto_apply_lens_correction_to_paths command automatically processes never-edited photos as soon as a folder is listed. Lens profiles are resolved from EXIF metadata and written directly to each photo’s sidecar in the background, without requiring the editor or a full RAW decode. The corresponding thumbnail is then regenerated.
The per-image editor path remains in place intentionally, as it covers scenarios the folder-level bulk pass may miss, including albums, files added later, timing races, and photos opened directly.
A new AppState.sidecar_write_lock now serializes the read-modify-write critical section for the three commands that may update .rrdata sidecars concurrently:
apply_auto_adjustments_to_paths
auto_apply_lens_correction_to_paths
save_metadata_and_update_thumbnail
This prevents concurrent operations—such as bulk Auto Adjust and automatic lens correction—from silently overwriting each other’s changes.
resolve_lens_params_in_adjustments, which re-validates the detected lens on every save when using "auto" mode, previously relied exclusively on the EXIF LensModel field. On fixed-lens cameras where this field is empty, this caused lensMaker and lensModel to be cleared on every save, effectively making the lens correction disappear.
The same camera-mount fallback is now used during save-time validation, ensuring that fixed-lens camera profiles remain correctly resolved and preserved.
Screenshots/Videos
No visual change excepts new switch button on lens profile settings
Testing
Test Configuration:
Checklist
Additional Notes
Started without IA, but IA was necessary to understand races condition problems on auto apply lens correction.
AI Disclaimer:
Please state the involvement of AI in this PR: