Repository navigation
Fix PQ luminance scaling and HLG display conversion - #22516
Conversation
TurboGit
left a comment
There was a problem hiding this comment.
This works on my side, still I have some comments/changes below.
I found that there is quite some places changed, it seems ok, but if you can by anyway review again on your side and see if some refactoring are possible, please do so.
TIA.
e7d46cb to
548102f
Compare
|
Addressed the nine inline review comments in 548102f.
I reviewed the remaining conversion changes as well. The shared RGB-boundary helpers already remove the duplicated matrix/transfer branches; I kept those rather than adding another abstraction across CPU and OpenCL. Validation after the refactor: full build passed, all 13 CTest tests passed, and all 28 independent HDR CLI cases passed. Actual Apple M5 Pro OpenCL PQ/HLG Rec.2020 import and export also passed. HLG export matches CPU exactly; PQ differs by at most one 16-bit code value. The PR description has been updated with these final-branch GPU checks. |
|
@MaykThewessen : This needs a conflict resolution. TIA. |
Decode and encode built-in HDR profiles at an RGB boundary with a shared CPU/OpenCL transfer implementation. Use 203 nit reference white for PQ and the RGB-dependent HLG OOTF for the nominal 1000 nit display. Keep the gamut matrix and LittleCMS conversion linear to avoid applying a second transfer. Preserve structured HDR signaling for PNG and JPEG XL imports, and add independent transfer and CLI reference tests. Include the shared header in OpenCL installation and cache invalidation. Fixes darktable-org#20562
Skip ICC shaper lookups in the HDR colorin kernels and share the RGB result and return path in the OpenCL transfer helpers. Use explicit branches in the CPU tone-curve helper and clarify the profile switch and multi-line JPEG XL conditions.
548102f to
6f95aa9
Compare
|
On the integration tests there is one important regression due to this change: The diffs: |
The HDR CLI matrix exercised unbound input conversion but not the separate gamut-clipping path. Add independent PQ and HLG cases for Rec2020 and P3, using encoded stimuli with highlights above reference white and near-black samples. Decode the actual PNG samples with the NumPy reference, clip in linear sRGB, and compare the rendered output. Optional OpenCL cases require confirmed GPU execution with no lost events rather than CPU fallback. The HLG clipping checks reject the legacy input decoder. This provides numeric coverage for the HLG behavior behind integration test 0109.
|
Stupid me, the test 0109 is using P3 HLG, so indeed the expected output change :) |
TurboGit
left a comment
There was a problem hiding this comment.
Hard stuff here (at least to me) but looks good and it works as expected. Thanks!
|
ah great |
Summary
PQ imports use 10000 nit normalization where the pixelpipe expects relative reference white, making 203 nit white approximately 49.26 times too dark. HLG imports omit the display OOTF; exports invert the same incorrect mapping. Apply PQ scaling and the RGB-dependent HLG OOTF at an RGB boundary, with a shared CPU/OpenCL implementation and linear gamut/LittleCMS transforms.
PNG imports retain cICP priority over cached ICC profiles and use libpng's native cICP parser where available. JPEG XL imports prefer structured HDR signaling over a synthesized ICC shaper. Adds independent numeric and CLI tests for Rec.2020 and P3, plus release notes.
Checklist
Test instructions
The full macOS arm64 build against upstream
cc66615c96passed. All 14 registered CTest tests passed, including the HDR transfer and DNG hue/saturation tests.Run the independent file regression with NumPy, ImageMagick and fixtures from hdr-test-images:
All 36 cases passed: 28 import/export and ICC/cICP reimport cases, plus PQ/HLG Rec.2020/P3 input with sRGB gamut clipping on CPU and actual Apple M5 Pro OpenCL. The new clipping stimuli include highlights above reference white and near-black samples. Their expected values come from independent decoding of the actual input samples. Maximum normalized error was 0.000712, below the 0.003 tolerance. GPU clipping checks require actual colorin OpenCL execution and successful events with zero lost events. Omit
--clipping-openclfor the 32 CPU cases.Separate Apple M5 Pro PQ/HLG import/export comparisons passed. HLG matched CPU exactly; PQ differed by at most one 16-bit code value.
Full CIE 2000 Delta E checks passed on CPU and GPU for
0001-exposure,0107-colorin-gamma,0108-colorin-clip, and0109-colorin-gamma-and-clip, using the companion HLG reference update. The final history entry in 0109 selects HLG P3, so its old reference captures the incorrect decoder. Restoring that decoder reproduces the old reference; it fails both new independent HLG clipping checks at approximately 0.4266 error. PQ still passes the same negative control. The refreshed reference rejects the old decoder at max Delta E 46.857.The full integration suite, native HDR display rendering, Linux/Wayland runtime, UltraHDR export, and full builds with optional features disabled have not been verified. The colorin/colorout modules compile with OpenCL disabled. CLLI checks were not repeated on this final branch.
The HLG display model remains nominal 1000 nit peak, gamma 1.2 and zero black, with 203 nit reference white. It does not add dynamic adaptation to a physical display.
AI assistance
Implementation, tests and validation were performed with Codex. AI assistance is disclosed here; there are no co-author trailers.
Fixes #20562