From efdfdc6ac7ea26df516869475c9925b4286935e3 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sun, 12 Feb 2023 09:35:42 -0800 Subject: [PATCH] Added CIE Lab Gamma Equation (#651) --- keywords.txt | 2 ++ src/internal/NeoEase.h | 12 ++++++++++++ src/internal/NeoGamma.h | 14 ++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/keywords.txt b/keywords.txt index 4e40680..ced944a 100644 --- a/keywords.txt +++ b/keywords.txt @@ -722,6 +722,7 @@ NeoTopology KEYWORD1 NeoRingTopology KEYWORD1 NeoTiles KEYWORD1 NeoMosaic KEYWORD1 +NeoGammaCieLabEquationMethod KEYWORD1 NeoGammaEquationMethod KEYWORD1 NeoGammaTableMethod KEYWORD1 NeoGamma KEYWORD1 @@ -817,6 +818,7 @@ CircularOut KEYWORD2 CircularInOut KEYWORD2 CircularCenter KEYWORD2 Gamma KEYWORD2 +GammaCieLab KEYWORD2 Map KEYWORD2 MapProbe KEYWORD2 getWidth KEYWORD2 diff --git a/src/internal/NeoEase.h b/src/internal/NeoEase.h index d370261..60a36ba 100644 --- a/src/internal/NeoEase.h +++ b/src/internal/NeoEase.h @@ -312,4 +312,16 @@ public: { return pow(unitValue, 1.0f / 0.45f); } + + static float GammaCieLab(float unitValue) + { + if (unitValue <= 0.08f) + { + return unitValue / 9.033f; + } + else + { + return pow((unitValue + 0.16f) / 1.16f, 3.0f); + } + } }; \ No newline at end of file diff --git a/src/internal/NeoGamma.h b/src/internal/NeoGamma.h index d567132..ff3744f 100644 --- a/src/internal/NeoGamma.h +++ b/src/internal/NeoGamma.h @@ -40,6 +40,20 @@ public: } }; +// Alternative equation to provide at least one official model for specific LEDs +class NeoGammaCieLabEquationMethod +{ +public: + static uint8_t Correct(uint8_t value) + { + return static_cast(255.0f * NeoEase::GammaCieLab(value / 255.0f) + 0.5f); + } + static uint16_t Correct(uint16_t value) + { + return static_cast(65535.0f * NeoEase::GammaCieLab(value / 65535.0f) + 0.5f); + } +}; + struct NeoGamma16LowHint { uint8_t pos;