-
-
Notifications
You must be signed in to change notification settings - Fork 391
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-add Temperture adjustment (#1710)
* Add Temperature adjustment * Add Temperature adjustment - add missing cmake updates * Add missing ENABLE_MDNS guards * Reapply temperature on JSONAPI * Integrate color temperature into RGB transformations * Fix imagestream update * fix cast * Cleanups * Windows Fix * Fix inner loop * Simplify * Reapply default temperature setting * Fix adjustments calculation * Updates
- Loading branch information
Showing
22 changed files
with
374 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#ifndef KELVINTORGB_H | ||
#define KELVINTORGB_H | ||
|
||
#include <cmath> | ||
|
||
#include <utils/ColorRgb.h> | ||
|
||
// Constants | ||
namespace ColorTemperature { | ||
constexpr int MINIMUM {1000}; | ||
constexpr int MAXIMUM {40000}; | ||
constexpr int DEFAULT {6600}; | ||
} | ||
//End of constants | ||
|
||
static ColorRgb getRgbFromTemperature(int temperature) | ||
{ | ||
//Temperature input in Kelvin valid in the range 1000 K to 40000 K. White light = 6600K | ||
temperature = qBound(ColorTemperature::MINIMUM, temperature, ColorTemperature::MAXIMUM); | ||
|
||
// All calculations require temperature / 100, so only do the conversion once. | ||
temperature /= 100; | ||
|
||
// Compute each color in turn. | ||
int red; | ||
int green; | ||
int blue; | ||
|
||
// red | ||
if (temperature <= 66) | ||
{ | ||
red = UINT8_MAX; | ||
} | ||
else | ||
{ | ||
// Note: the R-squared value for this approximation is 0.988. | ||
red = static_cast<int>(329.698727446 * (pow(temperature - 60, -0.1332047592))); | ||
} | ||
|
||
// green | ||
if (temperature <= 66) | ||
{ | ||
// Note: the R-squared value for this approximation is 0.996. | ||
green = static_cast<int>(99.4708025861 * log(temperature) - 161.1195681661); | ||
|
||
} | ||
else | ||
{ | ||
// Note: the R-squared value for this approximation is 0.987. | ||
green = static_cast<int>(288.1221695283 * (pow(temperature - 60, -0.0755148492))); | ||
} | ||
|
||
// blue | ||
if (temperature >= 66) | ||
{ | ||
blue = UINT8_MAX; | ||
} | ||
else if (temperature <= 19) | ||
{ | ||
blue = 0; | ||
} | ||
else | ||
{ | ||
// Note: the R-squared value for this approximation is 0.998. | ||
blue = static_cast<int>(138.5177312231 * log(temperature - 10) - 305.0447927307); | ||
} | ||
|
||
return { | ||
static_cast<uint8_t>(qBound(0, red, static_cast<int>(UINT8_MAX))), | ||
static_cast<uint8_t>(qBound(0, green, static_cast<int>(UINT8_MAX))), | ||
static_cast<uint8_t>(qBound(0, blue, static_cast<int>(UINT8_MAX))), | ||
}; | ||
} | ||
|
||
#endif // KELVINTORGB_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.