Opened 3 hours ago

Last modified 70 minutes ago

#19396 assigned enhancement

Add HSP colors to rgb_color

Reported by: nephele Owned by: nephele
Priority: normal Milestone: Unscheduled
Component: Kits/Interface Kit Version: R1/Development
Keywords: Cc: pulkomandy
Blocked By: Blocking:
Platform: All

Description (last modified by nephele)

rgb_color should obtain an API to set it's brightness in addition to how it is now received.

This would require to internally convert to HSP, adopt the passed in Brightness, and convert back to rgb.

example api: rgb_color::SetBrightness(float brightness) (0-1)

HSP system: http://alienryderflex.com/hsp.html

Example problem (With current HSL api):

hsl_color normalViewColor = hsl_color::from_rgb(viewColor);
rgb_color failureColor = ui_color(B_FAILURE_COLOR);
hsl_color newViewColor = hsl_color::from_rgb(failureColor);
if (normalViewColor.lightness < 0.15)
    newViewColor.lightness = 0.15;
else if (normalViewColor.lightness > 0.95)
    newViewColor.lightness = 0.95;
else
    newViewColor.lightness = normalViewColor.lightness;
 
    viewColor = newViewColor.to_rgb();

New api:

rgb_color failureColor = ui_color(B_FAILURE_COLOR);
if (viewColor.Brigthness() < 0.15)
    failureColor.SetBrightness(0.15);
else if (viewColor.Brigthness() > 0.95)
    failureColor.SetBrightness(0.95);
else
    failureColor.SetBrightness(viewColor.Brigthness());

viewColor = failureColor;

Example api with clamp values:

rgb_color failureColor = ui_color(B_FAILURE_COLOR);
failureColor.SetBrightness(viewColor.Brigthness(), 0.15, 0.95);
viewColor = failureColor;

Change History (6)

comment:1 by nephele, 3 hours ago

Description: modified (diff)

comment:2 by nephele, 3 hours ago

Example from AboutSystem:

Current (wrong) code:

fHaikuOrangeColor = mix_color(fTextColor, kIdealHaikuOrange, 191);

Possible current HSL implementation:

hsl_color newOrange = hsl_color::from_rgb(kIdealHaikuOrange);
hsl_color hslTextColor = hsl_color::from_rgb(textColor);
newOrange.lightness = std::clamp(hslTextColor.lightness, 0.15f, 0.85f);
fHaikuOrangeColor = newOrange.to_rgb();

rgb_color HSP api:

rgb_color newOrangeColor = kIdealHaikuOrange;
newOrangeColor.SetBrightness(std::clamp(textColor.Brigthness(), 0.15f, 0.85f));
fHaikuOrangeColor = newOrangeColor;
Last edited 3 hours ago by nephele (previous) (diff)

comment:3 by waddlesplash, 2 hours ago

I don't think it makes sense to add this necessarily, because the brightness would have to be recomputed every time the method was called, so if-else chains like the example here would be inefficient. Better to just make consumers convert to HSL always if they need to do that.

comment:4 by nephele, 75 minutes ago

Re-Reading my example code using SetBrightness(std::clamp(myBrightness), 0.15, 0.85) Makes more sense anyway, so the if-else chain is uneeded. Even without a seperate clamp api.

comment:5 by nephele, 74 minutes ago

Anyway: patch for HSP https://review.haiku-os.org/c/haiku/+/8907 (though not yet how this is described, but I can hook this up to rgb_color SetBrightness)

comment:6 by waddlesplash, 70 minutes ago

rgb_color is a public API, HSL and other colorspaces are currently private APIs, so they can't be directly connected.

Note: See TracTickets for help on using tickets.