#include <SDL.h>
#include <string.h>
+#include <math.h>
#include "color.h"
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 = {
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));