-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolor_parser.c
56 lines (49 loc) · 1.65 KB
/
color_parser.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* color_parser.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: conguyen <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/14 07:54:06 by conguyen #+# #+# */
/* Updated: 2022/03/21 11:52:06 by conguyen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
static int color_error(void)
{
ft_putstr("Error color Hex\n");
return (0);
}
static int hex_to_dec(char c)
{
if (c >= 65 && c <= 70)
return (c - 55);
else
return (c - 48);
}
static void get_color(char *line, t_fdf *fdf, int x, int len)
{
int power;
power = 0;
fdf->map.color[fdf->map.height][x] = 0;
while (line[--len] != 'x')
{
fdf->map.color[fdf->map.height][x] += hex_to_dec(line[len])
* ((unsigned int)pow(16, (double)power));
power++;
}
}
int check_color_line(char *line, t_fdf *fdf, int x)
{
int c;
c = 1;
if (line[0] != '0' || line[1] != 'x')
return (color_error());
while (line[++c] != '\0')
if (!(line[c] >= 65 && line[c] <= 70)
&& !(line[c] >= 48 && line[c] <= 57))
return (color_error());
get_color(line, fdf, x, c);
return (1);
}