RapidRAW: Lens Correction (Rust implementation), Geometry Tools & More

Hello everyone,

It has been a little while since I last posted about the AgX integration. In my introduction thread, I mentioned that Lens Correction was high on the roadmap but presented a significant technical hurdle.

I’m happy to report that with the releases of v1.4.9 and v1.4.10, Lens Correction is now fully implemented in RapidRAW.

I wanted to talk a little bit how this was achieved, as I took a slightly different path than just binding a C-library.

Native Lens Correction Implementation

The standard approach for open-source raw editors is to use the liblensfun C library. However, since RapidRAW is built with Rust and Tauri to be lightweight and cross-platform, linking against C libraries can introduce significant headaches regarding compilation and distribution across Windows, macOS, and Linux (dependency hell is real).

Instead of binding the library directly, I decided to implement the logic from scratch in Rust:

  1. Database: The application loads and parses the standard Lensfun XML database directly.
  2. Math: I re-implemented the distortion models (Poly3, PTLens) and the parameter interpolation logic in native Rust.
  3. Pipeline: The warping geometry is calculated and applied on the CPU. This is efficient because the heavy warp calculation only needs to happen once when you actually change a geometry parameter. The resulting “corrected” image is then passed to the GPU shader for the real-time color grading and exposure work.

The Challenge with Masking

One of the biggest challenges during this implementation was making the lens correction play nice with the masking system.

If you draw a linear gradient or a brush mask on an image that is later warped by lens correction, the mask shapes get distorted and no longer align with the subject.

Because I implemented the warping step on the CPU at the start of the pipeline, I was able to solve this by effectively replacing the “loaded” image with the geometry-corrected version before it hits the masking engine. This means that when you are drawing masks or running AI detection, you are operating directly on the corrected coordinate space. The mask coordinates map 1:1 to the image you see on screen, eliminating the need for complex coordinate reverse-mapping in the shader.

Other Recent Developments

Since my last post, I’ve released several other versions. Here is a quick catch-up on what else has landed:

  • Geometry & Warping: A dedicated transform tool (check image below) with dynamic grid lines to fix perspective, rotation, and horizon alignment.
  • Live Previews: A major rewrite of the render loop now allows for real-time visual feedback. You can see changes applied as you drag the sliders, rather than waiting for the mouse release.
  • New Denoising: I’ve replaced the old noise reduction with a BM3D (Block-matching and 3D filtering) implementation for better detail retention.

Feedback

Because the lens correction logic is a “from scratch” implementation, I am very interested to hear how it performs on your gear.

If you have a moment, I’d love for you to download the latest version, try lens correction (under the Crop & Transform panel in the sidebar) on your RAW files, and let me know if the corrections look accurate compared to other software you use.

A note on reporting:
I am happy to discuss the features and general feedback in this thread. However, if you encounter specific bugs, crashes, or start-up issues, please report them via the GitHub Issues section.

Links:

Thanks for the continued support!

Timon

11 Likes

Hello, thanks for this new version. I tried it on an iMac (Intel) and it seems to work fine at first sight.

One thing though, my lens is not auto-detected. RapidRAW says: “Not found, auto-detection depends on EXIF data”. The exif window of RR does not show the used lens.

I can do a manual selection though, and that works fine.

EDIT. And your mask tool is Magic!!

1 Like

that’s neat! Is the lensfun-rs a separate crate that other people can reuse? That’d likely be really helpful.

I use Manjaro. The auto-detection worked, but RR crashed when I clicked on Apply.
Last entries in logfile:

2026-01-28 18:33:31 [INFO] [Attempt 1] Searching for lenses from maker: 'Canon'
2026-01-28 18:33:31 [INFO] [Attempt 1] Success! Found best match: Some(("Canon", "Canon RF 24-240mm F4-6.3 IS USM"))
2026-01-28 18:33:34 [INFO] apply_all_transformations took: 474.193578ms

Hey all, thanks for testing the new version and for the quick feedback.

Glad it’s working on your iMac! Auto-detection relies on the lens being in the EXIF data. If it’s not there, RapidRAW can’t find it, so manual selection is the correct fallback. And thanks, happy you like the masking tool!

That’s a good idea about making it a separate crate. The code is currently integrated directly into the RapidRAW codebase. I’ve never created a crate before, so it’s not high on my to-do list right now, but I’ll keep it in mind for the future.

Sorry to hear about the crash on Manjaro. Could you please create a GitHub issue and provide details about your system/OS there? It’s the best way for me to track and fix bugs like that.

I just wanted to reproduce the error - but now it worked… :crazy_face:
But I will remember GitHub next time!

Hi Timon,

I cannot find lens correction for the compact Canon camera G7X.
Any tips, what to use here?

Cheers,
Jakob

In ART there is a dialog, where I can choose not only lens models but also camera models:

Nikon Z cameras do manufacturer-measured lens correction, so you can compare the embedded JPEGS with RapidRaw renditions.

If your algorithms are correct, you’ll still need to consider the lensfun data. For my 24-70/4 its good, for the 24-200/6.3, not so much…