-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_colors.c
67 lines (61 loc) · 1.83 KB
/
create_colors.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* create_colors.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aboncine <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/22 15:21:37 by aboncine #+# #+# */
/* Updated: 2023/02/23 13:15:55 by aboncine ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
static int ft_create_color_num(char *s, int start)
{
int i;
int num;
char *res;
i = start;
while (s[start] != ',' && s[start] != '\n')
start++;
res = (char *) malloc(sizeof(char) * start - i + 1);
start = i;
i = 0;
while (s[start] != ',' && s[start] != '\n')
{
res[i] = s[start];
i++;
start++;
}
res[i] = '\0';
num = ft_atoi(res);
free(res);
return (num);
}
static unsigned int ft_color_converter(int r, int g, int b)
{
return (r << 16 | g << 8 | b);
}
unsigned int ft_get_rgb(t_cub3d *box, char *s, int start)
{
int i;
int r;
int g;
int b;
i = start;
r = 256;
g = 256;
b = 256;
r = ft_create_color_num(s, i);
while (s[i] != ',')
i++;
i++;
g = ft_create_color_num(s, i);
while (s[i] != ',')
i++;
i++;
b = ft_create_color_num(s, i);
if (r > 255 || g > 255 || b > 255 || r < 0 || g < 0 || b < 0)
ft_print_error_n_free(box, box->map, "Error\nparametri colori errati\n");
return (ft_color_converter(r, g, b));
}