diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-04 17:18:11 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-04 17:18:11 +0100 |
commit | eb28d61cae4f320eeab5dfa20b3595d49859b18e (patch) | |
tree | 4b810c667166ca4889ec51bc3582f73a6265e9a7 /src | |
parent | Commit (diff) | |
download | 42-cub3d-eb28d61cae4f320eeab5dfa20b3595d49859b18e.tar.gz 42-cub3d-eb28d61cae4f320eeab5dfa20b3595d49859b18e.tar.bz2 42-cub3d-eb28d61cae4f320eeab5dfa20b3595d49859b18e.tar.xz 42-cub3d-eb28d61cae4f320eeab5dfa20b3595d49859b18e.tar.zst 42-cub3d-eb28d61cae4f320eeab5dfa20b3595d49859b18e.zip |
Weird mallocing
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_save_to_bmp.c | 52 |
1 files changed, 31 insertions, 21 deletions
diff --git a/src/ft_save_to_bmp.c b/src/ft_save_to_bmp.c index 06554ca..27b1469 100644 --- a/src/ft_save_to_bmp.c +++ b/src/ft_save_to_bmp.c @@ -23,34 +23,38 @@ static char if (ft_strrchr(ml->filename, '/')) { - if (!(str = (char*)malloc((ft_strlen(ft_strrchr(ml->filename), '/') - + 1) * sizeof(char)))) + if (!(str = (char*)malloc((ft_strlen(FT_BMP_SAVE_DIR) + ft_strlen(ft_strrchr(ml->filename, '/') + 1) - 3 + 1) * sizeof(char)))) return (NULL); - ft_sprintf(str, "%s", ft_strrchr(ml->filename)); + ft_printf("%lu\n", (ft_strlen(FT_BMP_SAVE_DIR) + ft_strlen((ft_strrchr(ml->filename, '/') + 1)) - 3 + 1)); + ft_sprintf(str, "%s%s.bmp", FT_BMP_SAVE_DIR, + ft_strrchr(ml->filename, '/') + 1); + return (str); } else { - if (!(str = (char*)malloc((ft_strlen(ml->filename) - + 1)* sizeof(char)))) - return (NULL); - ft_sprintf(str, "%s", ft_strrchr(ml->filename)); + /* 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); */ } + /* 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; */ +/* 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); -} +/* (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) @@ -58,11 +62,17 @@ int8_t 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 (ft_convert_image_to_bmp(bmp_file, img, cl) < 0) + 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); } |