Skip to content

Fix raw highlights clipping #1219

Open
sevahul wants to merge 2 commits into
CyberTimon:mainfrom
sevahul:pr/fix_highlights_clipping
Open

Fix raw highlights clipping #1219
sevahul wants to merge 2 commits into
CyberTimon:mainfrom
sevahul:pr/fix_highlights_clipping

Conversation

@sevahul
Copy link
Copy Markdown

@sevahul sevahul commented May 31, 2026

Description

This PR resolves an issue where high-brightness regions (highlights) in RAW files (such as .NEF) were rendered unnaturally, flattening gradients into white blobs and suffering from "hue twists". It also restores the required HDR headroom (>1.0) so the downstream AgX filmic tonemapper can function correctly without being starved of dynamic range.
In the second commit, a "show original" bug was fixed - the difference is now shown with the selected tone mapper instead of the hard-coded basic one.

Type of Change

  • Bug fix

Changes Made

  • Restored HDR Headroom: Added a temporary whitelevel = u32::MAX override in develop_internal to bypass rawler's automatic hard-clipping. This preserves >1.0 sensor values created by WB/color-matrix calibration for the downstream WGSL shader.
  • Implemented Chromaticity-Preserving Soft-Knee: Replaced the flawed per-channel highlight compression with a smooth, asymptotic soft_knee roll-off mathematical shoulder.
  • Fixed Hue Twist: Highlight compression is now applied to the maximum RGB channel (max_c), and the rest of the channels are scaled proportionally (soft_knee(max_c) / max_c). This preserves the precise RGB ratio, keeping saturated lights true to their color instead of twisting toward white.
  • Unified Processing: Applied the updated soft_knee scaling logic safely across ThreeColor, Monochrome, and FourColor intermediate formats.

Screenshots/Videos

Before (Clipped Highlights & Hue Twist) After (Restored HDR Headroom & Gradients)
fix-before fix-after

Testing

  • I have tested these changes locally and confirmed that they work as expected without issues

Test Configuration:

  • OS: Ubuntu 24.04
  • Hardware: Nvidia RTX 2070, Intel

Checklist

  • My code follows the project's code style
  • I haven't added unnecessary AI-generated code comments
  • My changes generate no new warnings or errors (0 Clippy warnings)

Additional Notes

By combining the HDR pass-through (giving the shader proper linear values) with the proportional chromaticity scalar, RapidRAW now accurately matches or exceeds the highlight volume rendering of natural RAW processors like Shotwell.

AI Disclaimer:

Please state the involvement of AI in this PR:

  • This PR is entirely AI-generated
  • This PR is AI-generated but guided 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)

The AI indeed generated the above=)

@sevahul sevahul marked this pull request as ready for review May 31, 2026 00:11
@sevahul sevahul requested a review from CyberTimon as a code owner May 31, 2026 00:11
At the same time, avoid magneta highlight in the over-exposed regions
@sevahul sevahul force-pushed the pr/fix_highlights_clipping branch from daad08f to 7251b69 Compare May 31, 2026 11:45
@sevahul
Copy link
Copy Markdown
Author

sevahul commented May 31, 2026

UPD:

  1. The original fix introduced a "magneta highlight effect" - now fixed
  2. The current "show original" shows comparison with the "basic" tone mapper. Fix this, it now shows conparison with the selected tone mapper (second commit)

@CyberTimon
Copy link
Copy Markdown
Owner

Hi @sevahul

Thanks for your PR!

Are you aware of this option?
image

In my testing, I could recover much more detail with this slider than with your PR.

Main:
image

Your PR:
image

Kind regards,
Timon

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.

2 participants