From a8897203a9fdfa2b763ead6bd8ea36700e585898 Mon Sep 17 00:00:00 2001 From: Frank Date: Sun, 28 Jan 2024 16:19:16 +0100 Subject: [PATCH] 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. --- wled00/data/index.js | 13 ++++++++++--- wled00/wled.h | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/wled00/data/index.js b/wled00/data/index.js index a5f914b3..3d55d12b 100644 --- a/wled00/data/index.js +++ b/wled00/data/index.js @@ -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; @@ -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); diff --git a/wled00/wled.h b/wled00/wled.h index 8bf3985f..c1581040 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -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_