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 )
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 , 3 hours ago
Description: | modified (diff) |
---|
comment:3 by , 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 , 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 , 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 , 70 minutes ago
rgb_color is a public API, HSL and other colorspaces are currently private APIs, so they can't be directly connected.
Example from AboutSystem:
Current (wrong) code:
Possible current HSL implementation:
rgb_color HSP api: