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
68
69
70
71
72
73
74
75
76
77
78
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_save_to_bmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/29 20:50:35 by rbousset #+# #+# */
/* Updated: 2020/02/29 20:50:37 by rbousset ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
#include <cub3d.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdint.h>
static char
*ft_set_file_name(t_map *ml)
{
char *str;
if (ft_strrchr(ml->filename, '/'))
{
if (!(str = (char*)malloc((ft_strlen(FT_BMP_SAVE_DIR) + ft_strlen(ft_strrchr(ml->filename, '/') + 1) + 1) * sizeof(char))))
return (NULL);
ft_printf("%lu\n", (ft_strlen(FT_BMP_SAVE_DIR) + ft_strlen((ft_strrchr(ml->filename, '/') + 1)) + 1));
ft_sprintf(str, "%s%s", FT_BMP_SAVE_DIR,
ft_strrchr(ml->filename, '/') + 1);
}
else
{
if (!(str = (char*)malloc((ft_strlen(FT_BMP_SAVE_DIR) +
ft_strlen(ml->filename) + 1)* sizeof(char))))
return (NULL);
ft_sprintf(str, "%s%s.bmp", FT_BMP_SAVE_DIR, ml->filename);
}
ft_memcpy(ft_strrchr(str, '.') + 1, "bmp", 3);
return (str);
/* return (NULL); */
}
/* static int8_t */
/* ft_convert_image_to_bmp(t_bmp_file bmp_file, void *img, t_cub *cl) */
/* { */
/* int32_t filelen; */
/* uint8_t *bmp; */
/* (void)img; */
/* (void)bmp_file; */
/* filelen = 54 + 3 * cl->wlist.x_size * cl->wlist.y_size; */
/* if (!(bmp = (uint8_t*)malloc((filelen - 54) * sizeof(uint8_t)))) */
/* return (-1); */
/* ft_memdel((void**)&bmp); */
/* return (0); */
/* } */
int8_t
ft_save_to_bmp(void *img, t_cub *cl)
{
t_bmp_file bmp_file;
t_bmp_info bmp_info;
t_bmp_colors bmp_colors;
char *fname;
(void)img;
bmp_file = ft_init_bmp();
bmp_info = ft_init_bmp_info();
bmp_colors = ft_init_bmp_colors();
if (!(fname = ft_set_file_name(&cl->mlist)))
return (-1);
ft_printf("%s\n", fname);
/* if (ft_convert_image_to_bmp(bmp_file, img, cl) < 0) */
/* return (-1); */
ft_memdel((void**)&fname);
return (0);
}
|