Skip to content

Commit a889720

Browse files
committed
trying to make palette preview look close to real LED colors
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.
1 parent 2277d81 commit a889720

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

wled00/data/index.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,11 @@ function redrawPalPrev()
977977
}
978978
}
979979

980+
// WLEDMM experimental - revert gamma correction in the browser (for palette preview)
981+
function unGamma(val, gamma){
982+
return Math.round(Math.pow(val / 255.0, 1.0/gamma) * 255.0);
983+
}
984+
980985
function genPalPrevCss(id)
981986
{
982987
if (!palettesData) return;
@@ -999,15 +1004,17 @@ function genPalPrevCss(id)
9991004
let r, g, b;
10001005
let index = false;
10011006
if (Array.isArray(e)) {
1007+
// fastLED palettes, with gammas (2.6, 2.2, 2.5) - we revert with slightly reduced values, to better preserve contrast
10021008
index = Math.round(e[0]/255*100);
1003-
r = e[1];
1004-
g = e[2];
1005-
b = e[3];
1009+
r = unGamma(e[1], 2.5);
1010+
g = unGamma(e[2], 2.3);
1011+
b = unGamma(e[3], 2.4);
10061012
} else if (e == 'r') {
10071013
r = Math.random() * 255;
10081014
g = Math.random() * 255;
10091015
b = Math.random() * 255;
10101016
} else {
1017+
// gradient palettes have custom gamma ~2.6 - don't revert, so their look matches the custom colors display
10111018
let i = e[1] - 1;
10121019
var cd = gId('csl').children;
10131020
r = parseInt(cd[i].dataset.r);

wled00/wled.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
// version code in format yymmddb (b = daily build)
11-
#define VERSION 2401260
11+
#define VERSION 2401280
1212

1313
// 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.
1414
#define _MoonModules_WLED_

0 commit comments

Comments
 (0)