Minimum luminance for backlight in dark scenes (#646)

* Include miminum luminance

* Add luminance minimum

* Add luminance minimum

* fixed missing ;

* Add luminance minimum

* Add luminance minimum check

Check if luminance mimimum is other than default

* Add luminance minimum

* Add luminance minimum

* Add luminance minimum

* Add luminance minimum

* Add luminance minimum

* Safe luminance calculation


Former-commit-id: 35a762b18b473a333155acba7a00894204400076
This commit is contained in:
Funatiq 2016-05-23 00:00:48 +02:00 committed by brindosch
parent e944ce46cd
commit f8b724f9f9
9 changed files with 69 additions and 10 deletions

View File

@ -20,7 +20,7 @@ public:
/// @param saturationGain The used saturation gain
/// @param luminanceGain The used luminance gain
///
HslTransform(double saturationGain, double luminanceGain);
HslTransform(double saturationGain, double luminanceGain, double luminanceMinimum);
///
/// Destructor
@ -55,6 +55,20 @@ public:
///
double getLuminanceGain() const;
///
/// Updates the luminance minimum
///
/// @param luminanceMinimum New luminance minimum
///
void setLuminanceMinimum(double luminanceMinimum);
///
/// Returns the luminance minimum
///
/// @return The current luminance minimum
///
double getLuminanceMinimum() const;
///
/// Apply the transform the the given RGB values.
///
@ -97,4 +111,6 @@ private:
double _saturationGain;
/// The luminance gain
double _luminanceGain;
/// The luminance minimum
double _luminanceMinimum
};

View File

@ -452,8 +452,9 @@ HslTransform * Hyperion::createHslTransform(const Json::Value & hslConfig)
{
const double saturationGain = hslConfig.get("saturationGain", 1.0).asDouble();
const double luminanceGain = hslConfig.get("luminanceGain", 1.0).asDouble();
const double luminanceMinimum = hslConfig.get("luminanceMinimum", 0.0).asDouble();
return new HslTransform(saturationGain, luminanceGain);
return new HslTransform(saturationGain, luminanceGain, luminanceMinimum);
}
RgbChannelTransform* Hyperion::createRgbChannelTransform(const Json::Value& colorConfig)

View File

@ -68,6 +68,11 @@
"type" : "number",
"required" : false,
"minimum" : 0.0
},
"luminanceMinimum" : {
"type" : "number",
"required" : false,
"minimum" : 0.0
}
},
"additionalProperties" : false

View File

@ -455,6 +455,7 @@ void JsonClientConnection::handleServerInfoCommand(const Json::Value &)
transform["valueGain"] = colorTransform->_hsvTransform.getValueGain();
transform["saturationLGain"] = colorTransform->_hslTransform.getSaturationGain();
transform["luminanceGain"] = colorTransform->_hslTransform.getLuminanceGain();
transform["luminanceMinimum"] = colorTransform->_hslTransform.getLuminanceMinimum();
Json::Value & threshold = transform["threshold"];
threshold.append(colorTransform->_rgbRedTransform.getThreshold());
@ -605,6 +606,11 @@ void JsonClientConnection::handleTransformCommand(const Json::Value &message)
colorTransform->_hslTransform.setLuminanceGain(transform["luminanceGain"].asDouble());
}
if (transform.isMember("luminanceMinimum"))
{
colorTransform->_hslTransform.setLuminanceMinimum(transform["luminanceMinimum"].asDouble());
}
if (transform.isMember("threshold"))
{
const Json::Value & values = transform["threshold"];

View File

@ -35,6 +35,11 @@
"required" : false,
"minimum" : 0.0
},
"luminanceMinimum" : {
"type" : "number",
"required" : false,
"minimum" : 0.0
},
"threshold": {
"type": "array",
"required": false,

View File

@ -4,13 +4,15 @@
HslTransform::HslTransform() :
_saturationGain(1.0),
_luminanceGain(1.0)
_luminanceGain(1.0),
_luminanceMinimum(0.0)
{
}
HslTransform::HslTransform(double saturationGain, double luminanceGain) :
HslTransform::HslTransform(double saturationGain, double luminanceGain, double luminanceMinimum) :
_saturationGain(saturationGain),
_luminanceGain(luminanceGain)
_luminanceGain(luminanceGain),
_luminanceMinimum(luminanceMinimum)
{
}
@ -38,9 +40,19 @@ double HslTransform::getLuminanceGain() const
return _luminanceGain;
}
void HslTransform::setLuminanceMinimum(double luminanceMinimum)
{
_luminanceMinimum = luminanceMinimum;
}
double HslTransform::getLuminanceMinimum() const
{
return _luminanceMinimum;
}
void HslTransform::transform(uint8_t & red, uint8_t & green, uint8_t & blue) const
{
if (_saturationGain != 1.0 || _luminanceGain != 1.0)
if (_saturationGain != 1.0 || _luminanceGain != 1.0 || _luminanceMinimum != 0.0)
{
uint16_t hue;
float saturation, luminance;
@ -53,9 +65,11 @@ void HslTransform::transform(uint8_t & red, uint8_t & green, uint8_t & blue) con
saturation = s;
float l = luminance * _luminanceGain;
if (l < _luminanceMinimum)
l = _luminanceMinimum;
if (l > 1.0f)
luminance = 1.0f;
else
else
luminance = l;
hsl2rgb(hue, saturation, luminance, red, green, blue);

View File

@ -192,7 +192,7 @@ void JsonConnection::clearAll()
parseReply(reply);
}
void JsonConnection::setTransform(std::string * transformId, double * saturation, double * value, double * saturationL, double * luminance, ColorTransformValues *threshold, ColorTransformValues *gamma, ColorTransformValues *blacklevel, ColorTransformValues *whitelevel)
void JsonConnection::setTransform(std::string * transformId, double * saturation, double * value, double * saturationL, double * luminance, double * luminanceMin, ColorTransformValues *threshold, ColorTransformValues *gamma, ColorTransformValues *blacklevel, ColorTransformValues *whitelevel)
{
std::cout << "Set color transforms" << std::endl;
@ -225,6 +225,12 @@ void JsonConnection::setTransform(std::string * transformId, double * saturation
{
transform["luminanceGain"] = *luminance;
}
if (luminanceMin != nullptr)
{
transform["luminanceMinimum"] = *luminanceMin;
}
if (threshold != nullptr)
{
Json::Value & v = transform["threshold"];

View File

@ -93,6 +93,7 @@ public:
/// @param value The HSV value gain
/// @param saturationL The HSL saturation gain
/// @param luminance The HSL luminance gain
/// @param luminanceMin The HSL luminance minimum
/// @param threshold The threshold
/// @param gamma The gamma value
/// @param blacklevel The blacklevel
@ -104,6 +105,7 @@ public:
double * value,
double * saturationL,
double * luminance,
double * luminanceMin,
ColorTransformValues * threshold,
ColorTransformValues * gamma,
ColorTransformValues * blacklevel,

View File

@ -71,6 +71,7 @@ int main(int argc, char * argv[])
DoubleParameter & argValue = parameters.add<DoubleParameter> ('v', "value" , "!DEPRECATED! Will be removed soon! Set the HSV value gain of the leds");
DoubleParameter & argSaturationL = parameters.add<DoubleParameter> ('u', "saturationL", "Set the HSL saturation gain of the leds");
DoubleParameter & argLuminance = parameters.add<DoubleParameter> ('m', "luminance" , "Set the HSL luminance gain of the leds");
DoubleParameter & argLuminanceMin = parameters.add<DoubleParameter> ('n', "luminanceMin" , "Set the HSL luminance minimum of the leds (backlight)");
TransformParameter & argGamma = parameters.add<TransformParameter>('g', "gamma" , "Set the gamma of the leds (requires 3 space seperated values)");
TransformParameter & argThreshold = parameters.add<TransformParameter>('t', "threshold" , "Set the threshold of the leds (requires 3 space seperated values between 0.0 and 1.0)");
TransformParameter & argBlacklevel = parameters.add<TransformParameter>('b', "blacklevel", "!DEPRECATED! Will be removed soon! Set the blacklevel of the leds (requires 3 space seperated values which are normally between 0.0 and 1.0)");
@ -103,7 +104,7 @@ int main(int argc, char * argv[])
}
// check if at least one of the available color transforms is set
bool colorTransform = argSaturation.isSet() || argValue.isSet() || argSaturationL.isSet() || argLuminance.isSet() || argThreshold.isSet() || argGamma.isSet() || argBlacklevel.isSet() || argWhitelevel.isSet();
bool colorTransform = argSaturation.isSet() || argValue.isSet() || argSaturationL.isSet() || argLuminance.isSet() || argLuminanceMin.isSet() || argThreshold.isSet() || argGamma.isSet() || argBlacklevel.isSet() || argWhitelevel.isSet();
bool colorAdjust = argRAdjust.isSet() || argGAdjust.isSet() || argBAdjust.isSet();
bool colorModding = colorTransform || colorAdjust || argCorrection.isSet() || argTemperature.isSet();
@ -124,6 +125,7 @@ int main(int argc, char * argv[])
std::cerr << " " << argValue.usageLine() << std::endl;
std::cerr << " " << argSaturationL.usageLine() << std::endl;
std::cerr << " " << argLuminance.usageLine() << std::endl;
std::cerr << " " << argLuminanceMin.usageLine() << std::endl;
std::cerr << " " << argThreshold.usageLine() << std::endl;
std::cerr << " " << argGamma.usageLine() << std::endl;
std::cerr << " " << argBlacklevel.usageLine() << std::endl;
@ -216,7 +218,7 @@ int main(int argc, char * argv[])
if (colorTransform)
{
std::string transId;
double saturation, value, saturationL, luminance;
double saturation, value, saturationL, luminance, luminanceMin;
ColorTransformValues threshold, gamma, blacklevel, whitelevel;
if (argId.isSet()) transId = argId.getValue();
@ -224,6 +226,7 @@ int main(int argc, char * argv[])
if (argValue.isSet()) value = argValue.getValue();
if (argSaturationL.isSet()) saturationL = argSaturationL.getValue();
if (argLuminance.isSet()) luminance = argLuminance.getValue();
if (argLuminanceMin.isSet()) luminanceMin = argLuminanceMin.getValue();
if (argThreshold.isSet()) threshold = argThreshold.getValue();
if (argGamma.isSet()) gamma = argGamma.getValue();
if (argBlacklevel.isSet()) blacklevel = argBlacklevel.getValue();
@ -235,6 +238,7 @@ int main(int argc, char * argv[])
argValue.isSet() ? &value : nullptr,
argSaturationL.isSet() ? &saturationL : nullptr,
argLuminance.isSet() ? &luminance : nullptr,
argLuminanceMin.isSet() ? &luminanceMin : nullptr,
argThreshold.isSet() ? &threshold : nullptr,
argGamma.isSet() ? &gamma : nullptr,
argBlacklevel.isSet() ? &blacklevel : nullptr,