Skip to content

feat: Auto apply lens correction feature (with global settings) - #1557

Open
air01a wants to merge 2 commits into
CyberTimon:mainfrom
air01a:feat/LensAutoCorrection
Open

feat: Auto apply lens correction feature (with global settings)#1557
air01a wants to merge 2 commits into
CyberTimon:mainfrom
air01a:feat/LensAutoCorrection

Conversation

@air01a

@air01a air01a commented Aug 20, 2026

Copy link
Copy Markdown

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

  • Bug fix
  • [ x ] New feature
  • Breaking change
  • Performance improvement
  • Code refactoring
  • Documentation update
  • UI/UX improvement
  • Build/CI or Dependency update

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.

  • Background bulk application (file_management.rs, useAppNavigation.ts)
    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.

  • Sidecar write concurrency fix
    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.

  • Additional bug fix: fixed-lens corrections disappearing after save
    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

  • [ x ] These changes were tested locally by a human and confirmed to work.
  • I haven't added any automated tests to the code because the codebase currently lacks a test suite.

Test Configuration:

  • ubuntun 24.04 / Windows 11
  • Intel i7 with integrated gpu

Checklist

  • [ x ] My code follows the project's code style
  • [ x ] I haven't added unnecessary AI-generated code comments
  • [ x ] My changes generate no new warnings or errors

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:

  • This PR is created by an AI agent
  • [ x ] This PR is mostly AI-generated but edited/merged together by a human
  • This PR was handwritten with AI assistance (spell check, logic suggestions, error resolving)
  • This PR contains only blood, sweat, and coffee (AI-free)

@air01a
air01a requested a review from CyberTimon as a code owner August 20, 2026 06:37
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant