mirror of
https://github.com/morgan9e/systemd
synced 2026-04-15 08:56:15 +09:00
color-util: make return values of rgb_to_hsv() optional
When we want to tint the bg color we don't care about the hue, we want to set it ourself after all, hence make the arguments optional, so that we don't even have to ask for it.
This commit is contained in:
@@ -11,35 +11,38 @@ void rgb_to_hsv(double r, double g, double b,
|
||||
assert(r >= 0 && r <= 1);
|
||||
assert(g >= 0 && g <= 1);
|
||||
assert(b >= 0 && b <= 1);
|
||||
assert(ret_h);
|
||||
assert(ret_s);
|
||||
assert(ret_v);
|
||||
|
||||
double max_color = fmax(r, fmax(g, b));
|
||||
double min_color = fmin(r, fmin(g, b));
|
||||
double delta = max_color - min_color;
|
||||
|
||||
*ret_v = max_color * 100.0;
|
||||
if (ret_v)
|
||||
*ret_v = max_color * 100.0;
|
||||
|
||||
if (max_color > 0)
|
||||
*ret_s = delta / max_color * 100.0;
|
||||
else {
|
||||
*ret_s = 0;
|
||||
*ret_h = NAN;
|
||||
if (max_color <= 0) {
|
||||
if (ret_s)
|
||||
*ret_s = 0;
|
||||
if (ret_h)
|
||||
*ret_h = NAN;
|
||||
return;
|
||||
}
|
||||
|
||||
if (delta > 0) {
|
||||
if (r >= max_color)
|
||||
*ret_h = 60 * fmod((g - b) / delta, 6);
|
||||
else if (g >= max_color)
|
||||
*ret_h = 60 * (((b - r) / delta) + 2);
|
||||
else if (b >= max_color)
|
||||
*ret_h = 60 * (((r - g) / delta) + 4);
|
||||
if (ret_s)
|
||||
*ret_s = delta / max_color * 100.0;
|
||||
|
||||
*ret_h = fmod(*ret_h, 360);
|
||||
} else
|
||||
*ret_h = NAN;
|
||||
if (ret_h) {
|
||||
if (delta > 0) {
|
||||
if (r >= max_color)
|
||||
*ret_h = 60 * fmod((g - b) / delta, 6);
|
||||
else if (g >= max_color)
|
||||
*ret_h = 60 * (((b - r) / delta) + 2);
|
||||
else if (b >= max_color)
|
||||
*ret_h = 60 * (((r - g) / delta) + 4);
|
||||
|
||||
*ret_h = fmod(*ret_h, 360);
|
||||
} else
|
||||
*ret_h = NAN;
|
||||
}
|
||||
}
|
||||
|
||||
void hsv_to_rgb(double h, double s, double v,
|
||||
|
||||
Reference in New Issue
Block a user