Skip to content

Conversation

@flo269
Copy link

@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 from [1.0–3.0] to [0.1–3.0]; values between 0.1 and 1.0 are now accepted rather than being reset.
    • Updated the gamma value input to allow a minimum of 0.1, matching the new validation and enabling finer calibration.

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 12, 2025

Walkthrough

Expand the acceptable range for gamma correction values by lowering the minimum threshold from 1.0 to 0.1 across validation logic and UI input constraints, allowing values in the range [0.1, 3] instead of [1.0, 3].

Changes

Cohort / File(s) Summary
Gamma correction validation logic
wled00/cfg.cpp, wled00/set.cpp
Lowered the lower-bound check for gammaCorrectVal from 1.0 to 0.1 (<= 1.0f< 0.1f), accepting values in [0.1, 3]; out-of-range values still reset gamma and related flags and trigger gamma table recalculation/fallback.
UI input constraints
wled00/data/settings_leds.htm
Changed the min attribute for the gamma input from 1 to 0.1 to match backend validation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • blazoncek

Pre-merge checks and finishing touches

❌ 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%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ 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 reflects the main change: removing the gamma value lower limit (from 1.0 to 0.1) to enable inverse gamma correction, which is the core objective and change across all modified files.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eeb5144 and 9d55b18.

📒 Files selected for processing (3)
  • wled00/cfg.cpp
  • wled00/data/settings_leds.htm
  • wled00/set.cpp
🚧 Files skipped from review as they are similar to previous changes (3)
  • wled00/data/settings_leds.htm
  • wled00/cfg.cpp
  • wled00/set.cpp

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.

wled00/cfg.cpp Outdated
CJSON(gammaCorrectVal, light["gc"]["val"]); // default 2.2
float light_gc_bri = light["gc"]["bri"];
float light_gc_col = light["gc"]["col"];
if (light_gc_bri > 1.0f) gammaCorrectBri = true;
Copy link
Collaborator

Choose a reason for hiding this comment

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

update this

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
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
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