Skip to content

lens: use lanczos taps for lanczos3 in the OpenCL metadata correction - #22848

Merged
TurboGit merged 1 commit into
darktable-org:masterfrom
nicknezis:lens-opencl-lanczos3-taps
Oct 31, 2026
Merged

TurboGit merged 1 commit into
darktable-org:masterfrom
nicknezis:lens-opencl-lanczos3-taps

Conversation

@nicknezis

Copy link
Copy Markdown
Contributor

Summary

The OpenCL path of lens correction from embedded metadata picks its interpolation taps in compute_upsampling_taps() (data/kernels/basic.cl). That function handles bicubic and lanczos2, but sends every other mode to the bilinear taps. With lanczos3 as the warp interpolator, OpenCL therefore weighted a 6x6 window with bilinear taps and produced a badly wrong image. The CPU path uses the lanczos taps that lanczos2 and lanczos3 share (src/common/interpolation.c). This PR sends lanczos3 to the lanczos taps too. The code dates from 2bcc293 (4.6).

The preferences dialog only offers bilinear, bicubic and lanczos2 for the warp interpolator, so the bug is reached by setting plugins/lighttable/export/pixel_interpolator_warp=lanczos3 in darktablerc or with --conf. The preferences UI doesn't offer lanczos3 for warping, so maintainers may say the release note isn't needed. If they do, I can drop that commit.

Checklist

  • I have read CONTRIBUTING.md and the coding style.
  • I have not merged master into the topic branch.
  • The pull request is one logical change, and every commit compiles on its own.
  • I ran the relevant tests: integration tests 0145 and 0146, with OpenCL on and off (see below).
  • New user-visible strings use _(), and new preferences are registered in data/darktableconfig.xml.in (this PR adds none).
  • A RELEASE_NOTES.md entry was added, in its own commit.

Test instructions

Run on an Apple M4 Pro under macOS, with the integration test options, --conf plugins/lighttable/export/pixel_interpolator_warp=lanczos3 and OpenCL forced on. OpenCL vs CPU export:

test master this PR
0145-lens-metadata-xtransIV-modversion-6 all 2,795,520 pixels differ, avg dE 31.6, max 81.8 1,407 pixels differ, avg dE 0.0003, max 1.27, at most 1/255
0146-lens-metadata-xtransIV-modversion-7 all 2,795,520 pixels differ, avg dE 31.2, max 78.5 10,598 pixels differ, avg dE 0.0025, max 1.78, at most 1/255
  • The CPU output is unchanged; only the OpenCL kernel is touched.
  • Bilinear, bicubic and lanczos2 take the same branches as before. With the tests' default bicubic, OpenCL on 0145 stays at avg dE 0.004 against expected.png.
  • The same bug shows on Linux with PoCL. Before the fix, 99.99% of the pixels of 0145 differ between OpenCL and the CPU.
  • Not tested: other GPUs. The bug is in which taps get computed, so it shouldn't depend on the device.

AI assistance

Written with Claude Code, which found the fall-through while porting the kernel and ran the tests above. I reviewed the change.

@jenshannoschwalm

Copy link
Copy Markdown
Collaborator

I agree with the usage of lanczos3 it that is found in conf. But as we don't want to be supported due to overshoots which is bad for distorting i would avoid the release note as that might give an unwanted hint.

@TurboGit TurboGit added feature: enhancement current features to improve priority: medium core features are degraded in a way that is still mostly usable, software stutters scope: image processing correcting pixels labels Oct 30, 2026
@TurboGit

Copy link
Copy Markdown
Member

I agree with the fix, and yes we don't need a release notes entry for such very improbably case.

@TurboGit TurboGit added this to the 5.8 milestone Oct 30, 2026
compute_upsampling_taps() picks the taps by the dt_interpolation_type
it is given, and handled bicubic (1) and lanczos2 (2) but sent
everything else to the bilinear taps. With lanczos3 (3) as the warp
interpolator, the embedded metadata correction on OpenCL therefore
weighted a 6x6 window with bilinear taps, while the CPU, through
dt_interpolation_compute_sample(), uses the lanczos taps that lanczos2
and lanczos3 share. In integration tests 0145 and 0146 rendered with
lanczos3, every pixel of the OpenCL export differed from the CPU one,
by an average dE of 31.

Use the lanczos taps for both lanczos widths.
@nicknezis
nicknezis force-pushed the lens-opencl-lanczos3-taps branch from 5c79822 to 87481bd Compare October 30, 2026 23:51
@nicknezis

Copy link
Copy Markdown
Contributor Author

Agreed, release note removed.

@TurboGit TurboGit left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@TurboGit
TurboGit merged commit eb367e5 into darktable-org:master Oct 31, 2026
10 checks passed
nicknezis pushed a commit to nicknezis/darktable that referenced this pull request Oct 31, 2026
The Slang compute_upsampling_taps() copied the OpenCL bug fixed in the
previous commit (darktable-org#22848): lanczos3 got bilinear
taps. Give it the lanczos taps on both paths, and drop the parity test
comment that explained the larger lanczos3 error by that bug.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature: enhancement current features to improve priority: medium core features are degraded in a way that is still mostly usable, software stutters scope: image processing correcting pixels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants