/* By: ljiriste <ljiriste@student.42prague.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/14 15:04:18 by ljiriste #+# #+# */
-/* Updated: 2025/01/14 15:13:05 by ljiriste ### ########.fr */
+/* Updated: 2025/01/18 15:54:27 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
return (sign * (whole + decimal));
}
+static char clamp_itoc(int a)
+{
+ if (a < 0)
+ return (0);
+ else if (a > 255)
+ return ((unsigned char)255);
+ else
+ return (a);
+}
+
t_color node_to_linear_rgb(const t_parse_tree_node *rgb_node)
{
const t_parse_tree_node *int_node;
t_color_srgb color;
int_node = ft_cget_node_child(rgb_node, 0);
- color.r = node_to_int(int_node);
+ color.r = clamp_itoc(node_to_int(int_node));
int_node = ft_cget_node_child(rgb_node, 2);
- color.g = node_to_int(int_node);
+ color.g = clamp_itoc(node_to_int(int_node));
int_node = ft_cget_node_child(rgb_node, 4);
- color.b = node_to_int(int_node);
+ color.b = clamp_itoc(node_to_int(int_node));
return (color_srgb_to_lin(color));
}