]> git.lizzy.rs Git - nothing.git/blobdiff - src/color.c
(#545) make match_list match empty tails
[nothing.git] / src / color.c
index 32b46efa4cf463e5700ab06bba52546799a79b47..768ef0ff9689cf9cfe52f68f1377d286126a5a24 100644 (file)
@@ -3,7 +3,7 @@
 
 #include "color.h"
 
-Color color(float r, float g, float b, float a)
+Color rgba(float r, float g, float b, float a)
 {
     const Color result = {
         .r = r,
@@ -15,15 +15,6 @@ Color color(float r, float g, float b, float a)
     return result;
 }
 
-Color color256(Uint8 r, Uint8 g, Uint8 b, Uint8 a)
-{
-    return color(
-        (float) r / 255.0f,
-        (float) g / 255.0f,
-        (float) b / 255.0f,
-        (float) a / 255.0f);
-}
-
 static Uint8 hex2dec_digit(char c)
 {
     if (c >= '0' && c <= '9') {
@@ -46,17 +37,17 @@ static Uint8 parse_color_component(const char *component)
     return (Uint8) (hex2dec_digit(component[0]) * 16 + hex2dec_digit(component[1]));
 }
 
-Color color_from_hexstr(const char *hexstr)
+Color hexstr(const char *hexstr)
 {
     if (strlen(hexstr) != 6) {
-        return color(0.0f, 0.0f, 0.0f, 1.0f);
+        return rgba(0.0f, 0.0f, 0.0f, 1.0f);
     }
 
-    return color256(
-        parse_color_component(hexstr),
-        parse_color_component(hexstr + 2),
-        parse_color_component(hexstr + 4),
-        255);
+    return rgba(
+        parse_color_component(hexstr) / 255.0f,
+        parse_color_component(hexstr + 2) / 255.0f,
+        parse_color_component(hexstr + 4) / 255.0f,
+        1.0f);
 }
 
 SDL_Color color_for_sdl(Color color)
@@ -74,13 +65,13 @@ SDL_Color color_for_sdl(Color color)
 Color color_desaturate(Color c)
 {
     const float k = (c.r + c.g + c.b) / 3.0f;
-    return color(k, k, k, c.a);
+    return rgba(k, k, k, c.a);
 }
 
 Color color_darker(Color c, float d)
 {
-    return color(fmaxf(c.r - d, 0.0f),
-                 fmaxf(c.g - d, 0.0f),
-                 fmaxf(c.b - d, 0.0f),
-                 c.a);
+    return rgba(fmaxf(c.r - d, 0.0f),
+                fmaxf(c.g - d, 0.0f),
+                fmaxf(c.b - d, 0.0f),
+                c.a);
 }