/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_rgb_to_hex.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rbousset +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/14 17:28:58 by rbousset #+# #+# */ /* Updated: 2020/02/14 17:28:58 by rbousset ### ########lyon.fr */ /* */ /* ************************************************************************** */ #include #include uint32_t ft_rgb_to_hex(float dist, t_rgb rgb, t_cub *cl) { uint32_t res; float calc; calc = (dist * 0.1 * cl->mlist.darklvl); calc = (calc >= 255) ? (255) : (calc); calc = (calc < 1) ? (1) : (calc); rgb.r = (rgb.r > 255) ? (255) : (rgb.r); rgb.g = (rgb.g > 255) ? (255) : (rgb.g); rgb.b = (rgb.b > 255) ? (255) : (rgb.b); rgb.r = (rgb.r < 0) ? (0) : (rgb.r); rgb.g = (rgb.g < 0) ? (0) : (rgb.g); rgb.b = (rgb.b < 0) ? (0) : (rgb.b); res = 0; if (calc <= 1) res += ((rgb.r << 16) + (rgb.g << 8) + rgb.b); else res += (((uint8_t)(rgb.r / calc) << 16) + ((uint8_t)(rgb.g / calc) << 8) + (uint8_t)(rgb.b / calc)); return (res); }