rgb_color: Add new APIs: Contrast(), IsLight(), IsDark()
- Remove perceptual_brightness - Change implementation of rgb_color::Brightness() to the previous BPrivate::perceptual_brightness() - Introduce convenience methods Contrast(rgb_color), IsLight() and IsDark() Change-Id: Id677d4a32ce43d73bffecf9baf8cffaafb01a16d Reviewed-on: https://review.haiku-os.org/c/haiku/+/7399 Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
@@ -59,6 +59,28 @@ typedef struct rgb_color {
|
||||
|
||||
int32 Brightness() const;
|
||||
|
||||
inline bool
|
||||
IsDark() const
|
||||
{
|
||||
return Brightness() <= 127;
|
||||
}
|
||||
|
||||
inline bool
|
||||
IsLight() const
|
||||
{
|
||||
return Brightness() > 127;
|
||||
}
|
||||
|
||||
static inline int32
|
||||
Contrast(rgb_color colorA, rgb_color colorB)
|
||||
{
|
||||
int32 contrast = colorA.Brightness() - colorB.Brightness();
|
||||
if (contrast < 0)
|
||||
return -contrast;
|
||||
|
||||
return contrast;
|
||||
}
|
||||
|
||||
inline bool
|
||||
operator==(const rgb_color& other) const
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user