Skip to content

Remove gamma value lower limit to enable inverse gamma correction#5187

Merged
DedeHai merged 5 commits intowled:mainfrom
flo269:gamma-inverse-support
Feb 8, 2026
Merged

Remove gamma value lower limit to enable inverse gamma correction#5187
DedeHai merged 5 commits intowled:mainfrom
flo269:gamma-inverse-support

Conversation

@flo269
Copy link
Contributor

@flo269 flo269 commented Dec 12, 2025

Summary

Remove the artificial restriction that prevents gamma values below 1.0, enabling inverse gamma correction.

Motivation

LEDs can appear too dark at low brightness levels. Inverse gamma correction (gamma < 1.0) is needed to brighten the lower end of the brightness curve and make dimmed LEDs more visible.

Currently, gamma values are restricted to > 1.0, which only allows standard gamma correction. This PR removes that limitation.

Changes

  • Update validation in set.cpp and cfg.cpp to allow gamma range 0.1-3.0 (was 1.0-3.0)
  • Update HTML form validation in settings_leds.htm to match (min="0.1")

Technical Details

The NeoGammaWLEDMethod::calcGammaTable() function already supports any gamma value mathematically. This PR simply removes an artificial restriction that prevented values < 1.0.

Testing

Tested on v0.15.3 and latest main - inverse gamma values (< 1.0) now work correctly and improve visibility at low brightness levels.

Summary by CodeRabbit

  • Bug Fixes
    • Expanded valid gamma correction range to accept values from 0.1 to 3.0; values between 0.1 and 1.0 are now preserved rather than being reset.
    • Updated the gamma value input to allow a minimum of 0.1 and adjusted its placeholder to reflect the finer calibration range.

✏️ Tip: You can customize this high-level summary in your review settings.

Allow gamma values from 0.1 to 3.0 instead of restricting to > 1.0.
This enables inverse gamma curves for use cases requiring brightened
mid-tones and compressed highlights.

Changes:
- Update backend validation in set.cpp and cfg.cpp to accept 0.1-3.0
- Update HTML form min value from 1 to 0.1

The calcGammaTable() function already supports any gamma value
mathematically, so this just removes an artificial restriction.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 12, 2025

Walkthrough

Lowered the minimum acceptable gamma correction from 1.0 to 0.1 in validation and UI, so gammaCorrectVal is accepted in [0.1, 3]; out-of-range values still reset gamma flags and trigger gamma-table recalculation/fallback.

Changes

Cohort / File(s) Summary
Gamma validation & runtime handling
wled00/cfg.cpp, wled00/set.cpp
Changed lower-bound check for gammaCorrectVal so values ≥ 0.1 and ≤ 3 are accepted (<= 1.0f< 0.1f logic adjusted); out-of-range values continue to reset gammaCorrectBri/gammaCorrectCol and recalc fallback gamma tables.
Web UI input constraint
wled00/data/settings_leds.htm
Updated gamma input min attribute from 1 to 0.1 and adjusted placeholder from 2.8 to 2.2 to match accepted backend range.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • blazoncek
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main objective of the PR—removing the gamma value lower limit to enable inverse gamma correction values below 1.0. It aligns with the actual changes across all three modified files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@DedeHai
Copy link
Collaborator

DedeHai commented Dec 12, 2025

Did you check both gamma functions create correct tables for the new range?

@DedeHai
Copy link
Collaborator

DedeHai commented Dec 14, 2025

I checked the functions, they do work still.
you also need to update the other lines in the config so it works after a reboot.

Allow gamma values from 0.1 to 3.0 instead of restricting to > 1.0.
This enables inverse gamma curves for use cases requiring brightened
mid-tones and compressed highlights.

Changes:
- Update backend validation in set.cpp and cfg.cpp to accept 0.1-3.0
- Update HTML form min value from 1 to 0.1

The calcGammaTable() function already supports any gamma value
mathematically, so this just removes an artificial restriction.
@flo269 flo269 force-pushed the gamma-inverse-support branch from eeb5144 to 9d55b18 Compare December 23, 2025 10:52
@flo269
Copy link
Contributor Author

flo269 commented Dec 23, 2025

I think I have it figured out - updated lines 511 and 513 to check != 1.0f instead of > 1.0f so gamma correction is enabled for any non-linear value (both below and above 1.0). This should fix the persistence issue after reboot.

@flo269 flo269 requested a review from DedeHai December 24, 2025 11:37
@tablatronix
Copy link

Any more testing needed for this? Seems like a low impact change

@DedeHai DedeHai merged commit 7387baa into wled:main Feb 8, 2026
24 checks passed
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.

3 participants