Skip to content

Commit

Permalink
trying to make palette preview look close to real LED colors
Browse files Browse the repository at this point in the history
FastLED palettes (from palettes.h) use gammas (2.6, 2.2, 2.5). Screens expect un-corrected colors, so we try to revert palette gamma correction in the browser.
  • Loading branch information
softhack007 committed Jan 28, 2024
1 parent 2277d81 commit a889720
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions wled00/data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,11 @@ function redrawPalPrev()
}
}

// WLEDMM experimental - revert gamma correction in the browser (for palette preview)
function unGamma(val, gamma){
return Math.round(Math.pow(val / 255.0, 1.0/gamma) * 255.0);
}

function genPalPrevCss(id)
{
if (!palettesData) return;
Expand All @@ -999,15 +1004,17 @@ function genPalPrevCss(id)
let r, g, b;
let index = false;
if (Array.isArray(e)) {
// fastLED palettes, with gammas (2.6, 2.2, 2.5) - we revert with slightly reduced values, to better preserve contrast
index = Math.round(e[0]/255*100);
r = e[1];
g = e[2];
b = e[3];
r = unGamma(e[1], 2.5);
g = unGamma(e[2], 2.3);
b = unGamma(e[3], 2.4);
} else if (e == 'r') {
r = Math.random() * 255;
g = Math.random() * 255;
b = Math.random() * 255;
} else {
// gradient palettes have custom gamma ~2.6 - don't revert, so their look matches the custom colors display
let i = e[1] - 1;
var cd = gId('csl').children;
r = parseInt(cd[i].dataset.r);
Expand Down
2 changes: 1 addition & 1 deletion wled00/wled.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

// version code in format yymmddb (b = daily build)
#define VERSION 2401260
#define VERSION 2401280

// WLEDMM - you can check for this define in usermods, to only enabled WLEDMM specific code in the "right" fork. Its not defined in AC WLED.
#define _MoonModules_WLED_
Expand Down

0 comments on commit a889720

Please sign in to comment.