]> git.lizzy.rs Git - nothing.git/blobdiff - src/color.c
Implement chop_background_layer
[nothing.git] / src / color.c
index 12ce6ee9561b1419d2f41199cadc674d00e21a79..eb03f55f928a573b9a11d547e136b1efd5d0fbe4 100644 (file)
@@ -83,6 +83,17 @@ Color hexstr(const char *hexstr)
         1.0f);
 }
 
+Color hexs(String input)
+{
+    if (input.count < 6) return COLOR_BLACK;
+
+    return rgba(
+        parse_color_component(input.data) / 255.0f,
+        parse_color_component(input.data + 2) / 255.0f,
+        parse_color_component(input.data + 4) / 255.0f,
+        1.0f);
+}
+
 SDL_Color color_for_sdl(Color color)
 {
     const SDL_Color result = {
@@ -129,6 +140,12 @@ int color_hex_to_stream(Color color, FILE *stream)
     return fprintf(stream, "%02x%02x%02x", sdl.r, sdl.g, sdl.b);
 }
 
+int color_hex_to_string(Color color, char *buffer, size_t buffer_size)
+{
+    SDL_Color sdl = color_for_sdl(color);
+    return snprintf(buffer, buffer_size, "%02x%02x%02x", sdl.r, sdl.g, sdl.b);
+}
+
 Color rgba_to_hsla(Color color)
 {
     const float max = fmaxf(color.r, fmaxf(color.g, color.b));